From a559713f96303414551c0bc1767fb11eb19bcc5d Mon Sep 17 00:00:00 2001 From: Elliot Winkler Date: Sat, 9 Jan 2016 23:15:03 -0700 Subject: [PATCH] Add a test for numericality + money columns 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. --- NEWS.md | 3 +++ spec/support/unit/helpers/database_helpers.rb | 8 +++++--- .../validate_numericality_of_matcher_spec.rb | 9 +++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) 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