mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-11 01:05:01 -04:00
* 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>
114 lines
2.8 KiB
Ruby
114 lines
2.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
describe ForumsController do
|
|
let(:admin) { create(:admin_member) }
|
|
let(:member) { create(:member) }
|
|
let(:forum) { create(:forum) }
|
|
|
|
describe "GET #index" do
|
|
it "returns a success response" do
|
|
get :index
|
|
expect(response).to be_successful
|
|
end
|
|
|
|
it "assigns @forums" do
|
|
forum # create forum
|
|
get :index
|
|
expect(assigns(:forums)).to include(forum)
|
|
end
|
|
end
|
|
|
|
describe "GET #show" do
|
|
it "returns a success response" do
|
|
get :show, params: { id: forum.to_param }
|
|
expect(response).to be_successful
|
|
end
|
|
end
|
|
|
|
context "as an admin" do
|
|
before { sign_in admin }
|
|
|
|
describe "GET #new" do
|
|
it "returns a success response" do
|
|
get :new
|
|
expect(response).to be_successful
|
|
end
|
|
end
|
|
|
|
describe "GET #edit" do
|
|
it "returns a success response" do
|
|
get :edit, params: { id: forum.to_param }
|
|
expect(response).to be_successful
|
|
end
|
|
end
|
|
|
|
describe "POST #create" do
|
|
context "with valid params" do
|
|
let(:valid_attributes) { { name: "New Forum", description: "A new forum", owner_id: admin.id } }
|
|
|
|
it "creates a new Forum" do
|
|
expect {
|
|
post :create, params: { forum: valid_attributes }
|
|
}.to change(Forum, :count).by(1)
|
|
end
|
|
|
|
it "redirects to the created forum" do
|
|
post :create, params: { forum: valid_attributes }
|
|
expect(response).to redirect_to(Forum.last)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "PUT #update" do
|
|
context "with valid params" do
|
|
let(:new_attributes) { { name: "Updated Name" } }
|
|
|
|
it "updates the requested forum" do
|
|
put :update, params: { id: forum.to_param, forum: new_attributes }
|
|
forum.reload
|
|
expect(forum.name).to eq("Updated Name")
|
|
end
|
|
|
|
it "redirects to the forum" do
|
|
put :update, params: { id: forum.to_param, forum: new_attributes }
|
|
expect(response).to redirect_to(forum)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "DELETE #destroy" do
|
|
it "destroys the requested forum" do
|
|
forum # ensure forum exists
|
|
expect {
|
|
delete :destroy, params: { id: forum.to_param }
|
|
}.to change(Forum, :count).by(-1)
|
|
end
|
|
|
|
it "redirects to the forums list" do
|
|
delete :destroy, params: { id: forum.to_param }
|
|
expect(response).to redirect_to(forums_url)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "as a regular member" do
|
|
before { sign_in member }
|
|
|
|
describe "GET #new" do
|
|
it "denies access" do
|
|
get :new
|
|
expect(response).to redirect_to(root_path)
|
|
end
|
|
end
|
|
|
|
describe "POST #create" do
|
|
it "denies access" do
|
|
post :create, params: { forum: { name: "Forbidden" } }
|
|
expect(response).to redirect_to(root_path)
|
|
end
|
|
end
|
|
end
|
|
end
|