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.
100 lines
2.2 KiB
Ruby
100 lines
2.2 KiB
Ruby
require "rails_helper"
|
|
|
|
describe ProgressBar do
|
|
let(:progress_bar) { build(:progress_bar) }
|
|
|
|
it_behaves_like "globalizable", :secondary_progress_bar
|
|
|
|
it "is valid" do
|
|
expect(progress_bar).to be_valid
|
|
end
|
|
|
|
it "is valid without a title" do
|
|
progress_bar.title = nil
|
|
|
|
expect(progress_bar).to be_valid
|
|
end
|
|
|
|
it "is not valid with a custom type" do
|
|
expect { progress_bar.kind = "terciary" }.to raise_exception(ArgumentError)
|
|
end
|
|
|
|
it "is not valid without a percentage" do
|
|
progress_bar.percentage = nil
|
|
|
|
expect(progress_bar).not_to be_valid
|
|
end
|
|
|
|
it "is not valid with a non-numeric percentage" do
|
|
progress_bar.percentage = "High"
|
|
|
|
expect(progress_bar).not_to be_valid
|
|
end
|
|
|
|
it "is not valid with a non-integer percentage" do
|
|
progress_bar.percentage = 22.83
|
|
|
|
expect(progress_bar).not_to be_valid
|
|
end
|
|
|
|
it "is not valid with a negative percentage" do
|
|
progress_bar.percentage = -1
|
|
|
|
expect(progress_bar).not_to be_valid
|
|
end
|
|
|
|
it "is not valid with a percentage bigger than 100" do
|
|
progress_bar.percentage = 101
|
|
|
|
expect(progress_bar).not_to be_valid
|
|
end
|
|
|
|
it "is valid with an integer percentage within the limits" do
|
|
progress_bar.percentage = 0
|
|
|
|
expect(progress_bar).to be_valid
|
|
|
|
progress_bar.percentage = 100
|
|
|
|
expect(progress_bar).to be_valid
|
|
|
|
progress_bar.percentage = 83
|
|
|
|
expect(progress_bar).to be_valid
|
|
end
|
|
|
|
it "is not valid without a progressable" do
|
|
progress_bar.progressable = nil
|
|
|
|
expect(progress_bar).not_to be_valid
|
|
end
|
|
|
|
it "cannot have another primary progress bar for the same progressable" do
|
|
progress_bar.save!
|
|
duplicate = build(:progress_bar, progressable: progress_bar.progressable)
|
|
|
|
expect(duplicate).not_to be_valid
|
|
end
|
|
|
|
describe "secondary progress bar" do
|
|
let(:progress_bar) { build(:progress_bar, :secondary) }
|
|
|
|
it "is valid" do
|
|
expect(progress_bar).to be_valid
|
|
end
|
|
|
|
it "is invalid without a title" do
|
|
progress_bar.title = nil
|
|
|
|
expect(progress_bar).not_to be_valid
|
|
end
|
|
|
|
it "can have another secondary progress bar for the same progressable" do
|
|
progress_bar.save!
|
|
duplicate = build(:progress_bar, progressable: progress_bar.progressable)
|
|
|
|
expect(duplicate).to be_valid
|
|
end
|
|
end
|
|
end
|