Apply Rails/SaveBang rubocop rule

Having exceptions is better than having silent bugs.

There are a few methods I've kept the same way they were.

The `RelatedContentScore#score_with_opposite` method is a bit peculiar:
it creates scores for both itself and the opposite related content,
which means the opposite related content will try to create the same
scores as well.

We've already got a test to check `Budget::Ballot#add_investment` when
creating a line fails ("Edge case voting a non-elegible investment").

Finally, the method `User#send_oauth_confirmation_instructions` doesn't
update the record when the email address isn't already present, leading
to the test "Try to register with the email of an already existing user,
when an unconfirmed email was provided by oauth" fo fail if we raise an
exception for an invalid user. That's because updating a user's email
doesn't update the database automatically, but instead a confirmation
email is sent.

There are also a few false positives for classes which don't have bang
methods (like the GraphQL classes) or destroying attachments.

For these reasons, I'm adding the rule with a "Refactor" severity,
meaning it's a rule we can break if necessary.
This commit is contained in:
Javi Martín
2019-10-20 03:54:56 +02:00
parent 777fb55399
commit 7ca55c44e0
167 changed files with 645 additions and 645 deletions

View File

@@ -19,64 +19,64 @@ describe Setting do
describe "#prefix" do
it "returns the prefix of its key" do
expect(Setting.create(key: "prefix.key_name").prefix).to eq "prefix"
expect(Setting.create!(key: "prefix.key_name").prefix).to eq "prefix"
end
it "returns the whole key for a non prefixed key" do
expect(Setting.create(key: "key_name").prefix).to eq "key_name"
expect(Setting.create!(key: "key_name").prefix).to eq "key_name"
end
end
describe "#type" do
it "returns the key prefix for 'process' settings" do
process_setting = Setting.create(key: "process.whatever")
process_setting = Setting.create!(key: "process.whatever")
expect(process_setting.type).to eq "process"
end
it "returns the key prefix for 'feature' settings" do
feature_setting = Setting.create(key: "feature.whatever")
feature_setting = Setting.create!(key: "feature.whatever")
expect(feature_setting.type).to eq "feature"
end
it "returns the key prefix for 'map' settings" do
map_setting = Setting.create(key: "map.whatever")
map_setting = Setting.create!(key: "map.whatever")
expect(map_setting.type).to eq "map"
end
it "returns the key prefix for 'html' settings" do
html_setting = Setting.create(key: "html.whatever")
html_setting = Setting.create!(key: "html.whatever")
expect(html_setting.type).to eq "html"
end
it "returns the key prefix for 'homepage' settings" do
homepage_setting = Setting.create(key: "homepage.whatever")
homepage_setting = Setting.create!(key: "homepage.whatever")
expect(homepage_setting.type).to eq "homepage"
end
it "returns the key prefix for 'remote_census.general' settings" do
remote_census_general_setting = Setting.create(key: "remote_census.general.whatever")
remote_census_general_setting = Setting.create!(key: "remote_census.general.whatever")
expect(remote_census_general_setting.type).to eq "remote_census.general"
end
it "returns the key prefix for 'remote_census_request' settings" do
remote_census_request_setting = Setting.create(key: "remote_census.request.whatever")
remote_census_request_setting = Setting.create!(key: "remote_census.request.whatever")
expect(remote_census_request_setting.type).to eq "remote_census.request"
end
it "returns the key prefix for 'remote_census_response' settings" do
remote_census_response_setting = Setting.create(key: "remote_census.response.whatever")
remote_census_response_setting = Setting.create!(key: "remote_census.response.whatever")
expect(remote_census_response_setting.type).to eq "remote_census.response"
end
it "returns 'configuration' for the rest of the settings" do
configuration_setting = Setting.create(key: "whatever")
configuration_setting = Setting.create!(key: "whatever")
expect(configuration_setting.type).to eq "configuration"
end
end
describe "#enabled?" do
it "is true if value is present" do
setting = Setting.create(key: "feature.whatever", value: 1)
setting = Setting.create!(key: "feature.whatever", value: 1)
expect(setting.enabled?).to eq true
setting.value = "true"
@@ -87,7 +87,7 @@ describe Setting do
end
it "is false if value is blank" do
setting = Setting.create(key: "feature.whatever")
setting = Setting.create!(key: "feature.whatever")
expect(setting.enabled?).to eq false
setting.value = ""
@@ -97,18 +97,18 @@ describe Setting do
describe "#content_type?" do
it "returns true if the last part of the key is content_types" do
expect(Setting.create(key: "key_name.content_types").content_type?).to be true
expect(Setting.create!(key: "key_name.content_types").content_type?).to be true
end
it "returns false if the last part of the key is not content_types" do
expect(Setting.create(key: "key_name.whatever").content_type?).to be false
expect(Setting.create!(key: "key_name.whatever").content_type?).to be false
end
end
describe "#content_type_group" do
it "returns the group for content_types settings" do
images = Setting.create(key: "update.images.content_types")
documents = Setting.create(key: "update.documents.content_types")
images = Setting.create!(key: "update.images.content_types")
documents = Setting.create!(key: "update.documents.content_types")
expect(images.content_type_group).to eq "images"
expect(documents.content_type_group).to eq "documents"