From 976d6bc4b5c94d13427c06e83829b9b62626b1a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Acu=C3=B1a?= Date: Wed, 21 Oct 2015 17:39:39 -0300 Subject: [PATCH 1/4] Add :decimal column type --- .../matchers/active_model/validate_numericality_of_matcher.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb b/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb index 8d2f85ea9..9d3d0f787 100644 --- a/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +++ b/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb @@ -432,7 +432,7 @@ def failure_message_when_negated end def given_numeric_column? - [:integer, :float].include?(column_type) + [:integer, :float, :decimal].include?(column_type) end private From 87d169890ca55bc60fd00a25ce0cba3d0549047e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Acu=C3=B1a?= Date: Wed, 21 Oct 2015 18:17:55 -0300 Subject: [PATCH 2/4] Add test for decimal column --- .../validate_numericality_of_matcher_spec.rb | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) 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 3ef09039a..c1df6d4a9 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 @@ -150,6 +150,18 @@ def default_validation_values to raise_error(described_class::IneffectiveTestError) end end + + context 'when the column is a decimal column' do + it 'raises an IneffectiveTestError' do + record = build_record_validating_numericality( + column_type: :decimal + ) + assertion = -> { expect(record).to validate_numericality } + + expect(&assertion). + to raise_error(described_class::IneffectiveTestError) + end + end end context 'and not validating anything' do @@ -233,6 +245,17 @@ def default_validation_values expect(record).to validate_numericality.odd end end + + context 'when the column is a decimal column' do + it 'accepts (and does not raise an error)' do + record = build_record_validating_numericality( + column_type: :decimal, + odd: true + ) + + expect(record).to validate_numericality.odd + end + end end context 'and not validating with odd' do @@ -276,6 +299,17 @@ def default_validation_values expect(record).to validate_numericality.even end end + + context 'when the column is a decimal column' do + it 'accepts (and does not raise an error)' do + record = build_record_validating_numericality( + column_type: :decimal, + even: true + ) + + expect(record).to validate_numericality.even + end + end end context 'and not validating with even' do @@ -319,6 +353,17 @@ def default_validation_values expect(record).to validate_numericality.is_less_than_or_equal_to(18) end end + + context 'when the column is a decimal column' do + it 'accepts (and does not raise an error)' do + record = build_record_validating_numericality( + column_type: :decimal, + less_than_or_equal_to: 18 + ) + + expect(record).to validate_numericality.is_less_than_or_equal_to(18) + end + end end context 'and not validating with less_than_or_equal_to' do @@ -366,6 +411,17 @@ def default_validation_values expect(record).to validate_numericality.is_less_than(18) end end + + context 'when the column is a decimal column' do + it 'accepts (and does not raise an error)' do + record = build_record_validating_numericality( + column_type: :decimal, + less_than: 18 + ) + + expect(record).to validate_numericality.is_less_than(18) + end + end end context 'and not validating with less_than' do @@ -411,6 +467,17 @@ def default_validation_values expect(record).to validate_numericality.is_equal_to(18) end end + + context 'when the column is a decimal column' do + it 'accepts (and does not raise an error)' do + record = build_record_validating_numericality( + column_type: :decimal, + equal_to: 18 + ) + + expect(record).to validate_numericality.is_equal_to(18) + end + end end context 'and not validating with equal_to' do @@ -462,6 +529,19 @@ def default_validation_values is_greater_than_or_equal_to(18) end end + + context 'when the column is a decimal column' do + it 'accepts (and does not raise an error)' do + record = build_record_validating_numericality( + column_type: :decimal, + greater_than_or_equal_to: 18 + ) + + expect(record). + to validate_numericality. + is_greater_than_or_equal_to(18) + end + end end context 'not validating with greater_than_or_equal_to' do @@ -513,6 +593,19 @@ def default_validation_values is_greater_than(18) end end + + context 'when the column is a decimal column' do + it 'accepts (and does not raise an error)' do + record = build_record_validating_numericality( + column_type: :decimal, + greater_than: 18 + ) + + expect(record). + to validate_numericality. + is_greater_than(18) + end + end end context 'and not validating with greater_than' do From bb0862eaff404ea45e263f695a23e1c583a396c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Acu=C3=B1a?= Date: Wed, 21 Oct 2015 18:35:37 -0300 Subject: [PATCH 3/4] Add comma after last parameter on multiline methods --- .../validate_numericality_of_matcher_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 c1df6d4a9..47047b2fa 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 @@ -250,7 +250,7 @@ def default_validation_values it 'accepts (and does not raise an error)' do record = build_record_validating_numericality( column_type: :decimal, - odd: true + odd: true, ) expect(record).to validate_numericality.odd @@ -304,7 +304,7 @@ def default_validation_values it 'accepts (and does not raise an error)' do record = build_record_validating_numericality( column_type: :decimal, - even: true + even: true, ) expect(record).to validate_numericality.even @@ -358,7 +358,7 @@ def default_validation_values it 'accepts (and does not raise an error)' do record = build_record_validating_numericality( column_type: :decimal, - less_than_or_equal_to: 18 + less_than_or_equal_to: 18, ) expect(record).to validate_numericality.is_less_than_or_equal_to(18) @@ -416,7 +416,7 @@ def default_validation_values it 'accepts (and does not raise an error)' do record = build_record_validating_numericality( column_type: :decimal, - less_than: 18 + less_than: 18, ) expect(record).to validate_numericality.is_less_than(18) @@ -472,7 +472,7 @@ def default_validation_values it 'accepts (and does not raise an error)' do record = build_record_validating_numericality( column_type: :decimal, - equal_to: 18 + equal_to: 18, ) expect(record).to validate_numericality.is_equal_to(18) @@ -534,7 +534,7 @@ def default_validation_values it 'accepts (and does not raise an error)' do record = build_record_validating_numericality( column_type: :decimal, - greater_than_or_equal_to: 18 + greater_than_or_equal_to: 18, ) expect(record). @@ -598,7 +598,7 @@ def default_validation_values it 'accepts (and does not raise an error)' do record = build_record_validating_numericality( column_type: :decimal, - greater_than: 18 + greater_than: 18, ) expect(record). From 5b79659c56e89d8301176cdd19752df60252d807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Acu=C3=B1a?= Date: Wed, 21 Oct 2015 18:38:14 -0300 Subject: [PATCH 4/4] Add missing comma on multiline method call --- .../active_model/validate_numericality_of_matcher_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 47047b2fa..31d2d8af3 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 @@ -154,7 +154,7 @@ def default_validation_values context 'when the column is a decimal column' do it 'raises an IneffectiveTestError' do record = build_record_validating_numericality( - column_type: :decimal + column_type: :decimal, ) assertion = -> { expect(record).to validate_numericality }