diff --git a/NEWS.md b/NEWS.md index 7deefb055..f20d88c0f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/spec/support/unit/helpers/database_helpers.rb b/spec/support/unit/helpers/database_helpers.rb index 93598e54b..f7a267b95 100644 --- a/spec/support/unit/helpers/database_helpers.rb +++ b/spec/support/unit/helpers/database_helpers.rb @@ -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 diff --git a/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb index 0b4cd4fef..2f7fab6e1 100644 --- a/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb @@ -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