Files
growstuff/spec/requests/forums_spec.rb
Daniel O'Connor 2aa697a6d6 Add comprehensive test coverage for forums (#4561)
* Add comprehensive test coverage for forums

- Added `spec/controllers/forums_controller_spec.rb` to test all CRUD actions and authorization for guest, member, and admin roles.
- Added `spec/features/forums_spec.rb` to cover user-facing features such as browsing forums and creating posts from within a forum.
- Updated `spec/requests/forums_spec.rb` to cover basic request flow and JSON response formats.

Note: Tests were verified for content and logic but execution in the sandbox environment was blocked by missing infrastructure (PostgreSQL and Elasticsearch).

Co-authored-by: CloCkWeRX <365751+CloCkWeRX@users.noreply.github.com>

* Fix specs

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
2026-04-26 14:18:28 +09:30

56 lines
1.6 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
describe "Forums" do
let(:admin) { create(:admin_member) }
let(:forum) { create(:forum) }
describe "GET /forums" do
it "returns a successful response" do
get forums_path
expect(response).to have_http_status(:ok)
end
it "returns JSON when requested" do
get forums_path(format: :json)
expect(response).to have_http_status(:ok)
expect(response.content_type).to include("application/json")
end
end
describe "GET /forums/:id" do
it "returns a successful response" do
get forum_path(forum)
expect(response).to have_http_status(:ok)
end
it "returns JSON when requested" do
get forum_path(forum, format: :json)
expect(response).to have_http_status(:ok)
expect(response.content_type).to include("application/json")
end
end
describe "POST /forums" do
context "as an admin" do
before { sign_in admin }
it "creates a new forum" do
expect {
post forums_path, params: { forum: { name: "New Request Forum", description: "Desc", owner_id: admin.id } }
}.to change(Forum, :count).by(1)
expect(response).to redirect_to(forum_path(Forum.last))
end
end
context "as a guest" do
it "redirects to sign in or denies access" do
post forums_path, params: { forum: { name: "New Request Forum", description: "Desc" } }
# Depending on CanCan/Devise setup, it might be a redirect to login or root
expect(response).to redirect_to(new_member_session_path).or redirect_to(root_path)
end
end
end
end