Skip to content

Commit

Permalink
Add (assert|refute)_validates_absense_of
Browse files Browse the repository at this point in the history
  • Loading branch information
jjbohn committed Mar 5, 2014
1 parent 295dca9 commit 71c3cdc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Available methods:
```
#assert_valid
#refute_valid
#assert_validates_absence_of
#refute_validates_absence_of
#assert_validates_presence_of
#refute_validates_presence_of
#assert_validates_uniqueness_of
Expand Down
10 changes: 10 additions & 0 deletions lib/assert_moar/assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ def refute_validates_uniqueness_of(object, property)
"#{object} validates presence of #{property}"
end

def assert_validates_absence_of(object, property)
assert has_validator?(object, property, ::ActiveModel::Validations::AbsenceValidator),
"#{object} does not validate the absence of #{property}"
end

def refute_validates_absence_of(object, property)
refute has_validator?(object, property, ::ActiveModel::Validations::AbsenceValidator),
"#{object} validates absence of #{property}"
end

def assert_valid(object)
assert object.valid?, "Expected object to be valid"
end
Expand Down
11 changes: 11 additions & 0 deletions test/lib/assert_moar/assertions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ def test_refute_uniqueness_of
@tc.refute_validates_uniqueness_of(double, :property)
end

def test_assert_validates_absence_of
validator = ::ActiveModel::Validations::AbsenceValidator
double = ActiveRecordDouble.new(error_map: {property: validator })
@tc.assert_validates_absence_of(double, :property)
end

def test_refute_validates_absense_of
double = ActiveRecordDouble.new()
@tc.refute_validates_absence_of(double, :property)
end

def teardown
assert_equal(@assertion_count, @tc.assertions,
"expected #{@assertion_count} assertions to be fired during the test, not #{@tc.assertions}") if @tc.passed?
Expand Down
1 change: 1 addition & 0 deletions test/support/active_model/validations.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module ActiveModel
module Validations
class AbsenceValidator; end
class PresenceValidator; end
end
end

0 comments on commit 71c3cdc

Please sign in to comment.