We were very inconsistent regarding these rules. Personally I prefer no empty lines around blocks, clases, etc... as recommended by the Ruby style guide [1], and they're the default values in rubocop, so those are the settings I'm applying. The exception is the `private` access modifier, since we were leaving empty lines around it most of the time. That's the default rubocop rule as well. Personally I don't have a strong preference about this one. [1] https://rubystyle.guide/#empty-lines-around-bodies
60 lines
2.0 KiB
Ruby
60 lines
2.0 KiB
Ruby
require "rails_helper"
|
|
|
|
describe CommentsController do
|
|
describe "POST create" do
|
|
let(:legal_process) do
|
|
create(:legislation_process, debate_start_date: Date.current - 3.days,
|
|
debate_end_date: Date.current + 2.days)
|
|
end
|
|
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
|
|
|
|
expect do
|
|
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
|
|
legal_process.update_attribute(:debate_end_date, Date.current - 1.day)
|
|
|
|
expect do
|
|
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
|
|
|
|
expect do
|
|
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
|