Add tests for `User#questions` action and cases
This commit is contained in:
parent
6693864fbc
commit
f5f7b0d22b
|
@ -50,15 +50,57 @@ describe UserController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#questions" do
|
describe "#questions" do
|
||||||
|
let!(:question) { FactoryBot.create(:question, user: user, direct: true, author_is_anonymous: false) }
|
||||||
subject { get :questions, params: { username: user.screen_name } }
|
subject { get :questions, params: { username: user.screen_name } }
|
||||||
|
|
||||||
context "user signed in" do
|
it "renders the user/questions template" do
|
||||||
before(:each) { sign_in user }
|
subject
|
||||||
|
expect(assigns(:user)).to eq(user)
|
||||||
|
expect(response).to render_template("user/questions")
|
||||||
|
end
|
||||||
|
|
||||||
it "renders the user/questions template" do
|
context "current user signed in" do
|
||||||
|
before do
|
||||||
|
sign_in user
|
||||||
|
end
|
||||||
|
|
||||||
|
it "renders all questions" do
|
||||||
subject
|
subject
|
||||||
expect(assigns(:user)).to eq(user)
|
expect(assigns(:questions).size).to eq(1)
|
||||||
expect(response).to render_template("user/questions")
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "user signed in" do
|
||||||
|
let(:another_user) { FactoryBot.create :user }
|
||||||
|
|
||||||
|
before do
|
||||||
|
sign_in another_user
|
||||||
|
end
|
||||||
|
|
||||||
|
it "renders no questions" do
|
||||||
|
subject
|
||||||
|
expect(assigns(:questions).size).to eq(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "moderator unmasked" do
|
||||||
|
let(:another_user) { FactoryBot.create :user, roles: ["moderator"] }
|
||||||
|
|
||||||
|
before do
|
||||||
|
sign_in another_user
|
||||||
|
allow_any_instance_of(UserHelper).to receive(:moderation_view?) { true }
|
||||||
|
end
|
||||||
|
|
||||||
|
it "contains all questions" do
|
||||||
|
subject
|
||||||
|
expect(assigns(:questions).size).to eq(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "user not signed in" do
|
||||||
|
it "contains no questions" do
|
||||||
|
subject
|
||||||
|
expect(assigns(:questions).size).to eq(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,5 +5,6 @@ FactoryBot.define do
|
||||||
user { nil }
|
user { nil }
|
||||||
content { Faker::Lorem.sentence }
|
content { Faker::Lorem.sentence }
|
||||||
author_is_anonymous { true }
|
author_is_anonymous { true }
|
||||||
|
direct { true }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue