Fix several rubocop warnings
Metrics/LineLength: Line is too long. RSpec/InstanceVariable: Use let instead of an instance variable. Layout/TrailingBlankLines: Final newline missing. Style/StringLiterals: Prefer double-quoted strings.
This commit is contained in:
@@ -3,36 +3,57 @@ 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
|
||||
|
||||
let(:legal_process) { create(:legislation_process, debate_start_date: Date.current - 3.days,
|
||||
debate_end_date: Date.current + 2.days) }
|
||||
let(:question) { create(:legislation_question, process: legal_process, title: "Question 1") }
|
||||
let(:user) { create(:user, :level_two) }
|
||||
let(:unverified_user) { create(:user) }
|
||||
|
||||
it "creates an comment if the comments are open" do
|
||||
sign_in @user
|
||||
sign_in user
|
||||
|
||||
expect do
|
||||
post :create, params: {comment: {commentable_id: @question.id, commentable_type: "Legislation::Question", body: "a comment"}}, xhr: true
|
||||
end.to change { @question.reload.comments_count }.by(1)
|
||||
post :create, xhr: true,
|
||||
params: {
|
||||
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)
|
||||
sign_in user
|
||||
legal_process.update_attribute(:debate_end_date, Date.current - 1.day)
|
||||
|
||||
expect do
|
||||
post :create, params: {comment: {commentable_id: @question.id, commentable_type: "Legislation::Question", body: "a comment"}}, xhr: true
|
||||
end.not_to change { @question.reload.comments_count }
|
||||
post :create, xhr: true,
|
||||
params: {
|
||||
comment: {
|
||||
commentable_id: question.id,
|
||||
commentable_type: "Legislation::Question",
|
||||
body: "a comment"
|
||||
}
|
||||
}
|
||||
end.not_to 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
|
||||
sign_in unverified_user
|
||||
|
||||
expect do
|
||||
post :create, params: {comment: {commentable_id: @question.id, commentable_type: "Legislation::Question", body: "a comment"}}, xhr: true
|
||||
end.not_to change { @question.reload.comments_count }
|
||||
post :create, xhr: true,
|
||||
params: {
|
||||
comment: {
|
||||
commentable_id: question.id,
|
||||
commentable_type: "Legislation::Question",
|
||||
body: "a comment"
|
||||
}
|
||||
}
|
||||
end.not_to change { question.reload.comments_count }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user