Skip to content

Commit

Permalink
Workaround for shoulda-mathcers bug
Browse files Browse the repository at this point in the history
Bug in Shoulda-Matchers: returning an error for integer & greater than or equal to validations

Tracking issue: thoughtbot/shoulda-matchers#849 (comment)

Workaround - kept verbose tests in and commented out shoulda-matchers tests until bug is fixed
  • Loading branch information
ckib16 committed Dec 8, 2015
1 parent 323d98a commit 0a65717
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
20 changes: 14 additions & 6 deletions spec/models/location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@
it { should validate_presence_of(:country) }
it { should validate_presence_of(:pascode) }
it { should validate_presence_of(:billets) }
it { should validate_numericality_of(:billets).is_greater_than_or_equal_to(0) }
it { should validate_numericality_of(:billets).only_integer }

# Kept because shoulda-matchers is returning an error for integer
# TODO: Bug in shoulda-matchers, filed issue: https://github.com/thoughtbot/shoulda-matchers/issues/849#issuecomment-162898918
# it { should validate_numericality_of(:billets).is_greater_than_or_equal_to(0) }
# it { should validate_numericality_of(:billets).only_integer }

# Kept these verbose tests because shoulda-matchers is returning an error for integer & grather than or equal to
it "is invalid without billets inputed as an integer" do
pilot = build(:location, billets: 0.1)
pilot.valid?
expect(pilot.errors[:billets]).to include("must be an integer")
location = build(:location, billets: 0.1)
location.valid?
expect(location.errors[:billets]).to include("must be an integer")
end

it "is invalid without billets integer > 0" do
location = build(:location, billets: -1)
location.valid?
expect(location.errors[:billets]).to include("must be greater than or equal to 0")
end

it { should validate_presence_of(:emblem_url) }
Expand Down
16 changes: 12 additions & 4 deletions spec/models/pilot_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,24 @@
it { should validate_presence_of(:name) }
it { should validate_presence_of(:rank) }
it { should validate_presence_of(:hours) }
it { should validate_numericality_of(:hours).only_integer }
it { should validate_numericality_of(:hours).is_greater_than_or_equal_to(0) }

# Kept because shoulda-matchers is returning an error for integer
it "is invalid without an hours inputed as an integer" do
# TODO: Bug in shoulda-matchers, filed issue: https://github.com/thoughtbot/shoulda-matchers/issues/849#issuecomment-162898918
# it { should validate_numericality_of(:hours).only_integer }
# it { should validate_numericality_of(:hours).is_greater_than_or_equal_to(0) }

# Kept these verbose tests because shoulda-matchers is returning an error for integer & grather than or equal to
it "is invalid without hours inputed as an integer" do
pilot = build(:pilot, hours: 0.1)
pilot.valid?
expect(pilot.errors[:hours]).to include("must be an integer")
end

it "is invalid without hours integer > 0" do
pilot = build(:pilot, hours: -1)
pilot.valid?
expect(pilot.errors[:hours]).to include("must be greater than or equal to 0")
end

it { should validate_presence_of(:qualification) }
it { should validate_presence_of(:commision_date) }
it { should validate_presence_of(:adsc) }
Expand Down

0 comments on commit 0a65717

Please sign in to comment.