Move `NotificationsController#index` test into their own `describe` block
This commit is contained in:
parent
80d8bebe57
commit
0db44949e6
|
@ -3,39 +3,41 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe NotificationsController do
|
||||
subject { get :index, params: { type: :new } }
|
||||
describe "#index" do
|
||||
subject { get :index, params: { type: :new } }
|
||||
|
||||
let(:user) { FactoryBot.create(:user) }
|
||||
let(:user) { FactoryBot.create(:user) }
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
context "user has no notifications" do
|
||||
it "should show an empty list" do
|
||||
subject
|
||||
expect(response).to render_template(:index)
|
||||
|
||||
expect(controller.instance_variable_get(:@notifications)).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context "user has notifications" do
|
||||
let(:other_user) { FactoryBot.create(:user) }
|
||||
let(:another_user) { FactoryBot.create(:user) }
|
||||
let(:question) { FactoryBot.create(:question, user: user) }
|
||||
let!(:answer) { FactoryBot.create(:answer, question: question, user: other_user) }
|
||||
let!(:subscription) { Subscription.create(user: user, answer: answer) }
|
||||
let!(:comment) { FactoryBot.create(:comment, answer: answer, user: other_user) }
|
||||
|
||||
it "should show a list of notifications" do
|
||||
subject
|
||||
expect(response).to render_template(:index)
|
||||
expect(controller.instance_variable_get(:@notifications)).to have_attributes(size: 2)
|
||||
before do
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
it "marks notifications as read" do
|
||||
expect { subject }.to change { Notification.for(user).where(new: true).count }.from(2).to(0)
|
||||
context "user has no notifications" do
|
||||
it "should show an empty list" do
|
||||
subject
|
||||
expect(response).to render_template(:index)
|
||||
|
||||
expect(controller.instance_variable_get(:@notifications)).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context "user has notifications" do
|
||||
let(:other_user) { FactoryBot.create(:user) }
|
||||
let(:another_user) { FactoryBot.create(:user) }
|
||||
let(:question) { FactoryBot.create(:question, user: user) }
|
||||
let!(:answer) { FactoryBot.create(:answer, question: question, user: other_user) }
|
||||
let!(:subscription) { Subscription.create(user: user, answer: answer) }
|
||||
let!(:comment) { FactoryBot.create(:comment, answer: answer, user: other_user) }
|
||||
|
||||
it "should show a list of notifications" do
|
||||
subject
|
||||
expect(response).to render_template(:index)
|
||||
expect(controller.instance_variable_get(:@notifications)).to have_attributes(size: 2)
|
||||
end
|
||||
|
||||
it "marks notifications as read" do
|
||||
expect { subject }.to change { Notification.for(user).where(new: true).count }.from(2).to(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue