Skip to content

Commit

Permalink
Add a test for numericality + money columns
Browse files Browse the repository at this point in the history
18b2859 and a0f1221 fixed the numericality matcher so that it no longer
raises CouldNotSetAttributeError when used against numeric columns.
Unfortunately, the issue still existed for money columns.

This is fixed now, but we never explicitly tested for money columns, and
this commit adds that test.
  • Loading branch information
mcmire committed Jan 10, 2016
1 parent e2fc159 commit a559713
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
a virtual attribute defined in an ActiveRecord model (that is, an attribute
that is not present in the database but is defined using `attr_accessor`).

* Add a test for `validate_numericality_of` so that it officially supports money
columns.

### Improvements

* Improve failure messages and descriptions of all matchers across the board so
Expand Down
8 changes: 5 additions & 3 deletions spec/support/unit/helpers/database_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ def database_adapter
Tests::Database.instance.adapter_name
end

def database_supports_uuid_columns?
def postgresql?
database_adapter == :postgresql
end
alias_method :database_supports_array_columns?,
:database_supports_uuid_columns?

alias_method :database_supports_array_columns?, :postgresql?
alias_method :database_supports_uuid_columns?, :postgresql?
alias_method :database_supports_money_columns?, :postgresql?
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ def default_validation_values
expect(record).to validate_numericality
end
end

if database_supports_money_columns?
context 'when the column is a money column' do
it 'accepts (and does not raise an AttributeChangedValueError)' do
record = build_record_validating_numericality(column_type: :money)
expect(record).to validate_numericality
end
end
end
end

context 'and not validating anything' do
Expand Down

0 comments on commit a559713

Please sign in to comment.