Do not raise CouldNotSetAttributeError on decimal columns

This commit is contained in:
Raúl Acuña 2015-10-21 17:39:39 -03:00 committed by Elliot Winkler
parent 7e976f15dd
commit a0f12216fd
2 changed files with 94 additions and 1 deletions

View File

@ -432,7 +432,7 @@ module Shoulda
end
def given_numeric_column?
[:integer, :float].include?(column_type)
[:integer, :float, :decimal].include?(column_type)
end
private

View File

@ -150,6 +150,18 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
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 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
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 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
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 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
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 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
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 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
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 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
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 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
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