Files
grecia/spec/controllers/comments_controller_spec.rb
Bertocq 1441de5107 Enable RSpec/HookArgument cop and fix issues
To be consistent about before/after arguments, as `:each` or `:example`
 are same and default scopes, best not to send an argument in those
 scenarios.

Read about cop at http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/HookArgument
2018-01-07 02:07:19 +01:00

39 lines
1.4 KiB
Ruby

require 'rails_helper'
describe CommentsController do
describe 'POST create' do
before do
@process = create(:legislation_process, debate_start_date: Date.current - 3.days, debate_end_date: Date.current + 2.days)
@question = create(:legislation_question, process: @process, title: "Question 1")
@user = create(:user, :level_two)
@unverified_user = create(:user)
end
it 'creates an comment if the comments are open' do
sign_in @user
expect do
xhr :post, :create, comment: {commentable_id: @question.id, commentable_type: "Legislation::Question", body: "a comment"}
end.to change { @question.reload.comments_count }.by(1)
end
it 'does not create a comment if the comments are closed' do
sign_in @user
@process.update_attribute(:debate_end_date, Date.current - 1.day)
expect do
xhr :post, :create, comment: {commentable_id: @question.id, commentable_type: "Legislation::Question", body: "a comment"}
end.to_not change { @question.reload.comments_count }
end
it 'does not create a comment for unverified users when the commentable requires it' do
sign_in @unverified_user
expect do
xhr :post, :create, comment: {commentable_id: @question.id, commentable_type: "Legislation::Question", body: "a comment"}
end.to_not change { @question.reload.comments_count }
end
end
end