This method is ambiguous. Sometimes we use it to set invalid data in tests (which can usually be done with `update_column`), and other times we use it instead of `update!`. I'm removing it because, even if sometimes it could make sense to use it, it's too similar to `update_attributes` (which is an alias for `update` and runs validations), making it confusing. However, there's one case where we're still using it: in the ActsAsParanoidAliases module, we need to invoke the callbacks, which `update_column` skips, but tests related to translations fail if we use `update!`. The reason for this is the tests check what happens if we restore a record without restoring its translations. But that will make the record invalid, since there's a validation rule checking it has at least one translation. I'm not blacklisting any other method which skips validations because we know they skip validations and use them anyway (hopefully with care).
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!(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
|