Do not raise CouldNotSetAttributeError on decimal columns
This commit is contained in:
parent
7e976f15dd
commit
a0f12216fd
|
@ -432,7 +432,7 @@ module Shoulda
|
||||||
end
|
end
|
||||||
|
|
||||||
def given_numeric_column?
|
def given_numeric_column?
|
||||||
[:integer, :float].include?(column_type)
|
[:integer, :float, :decimal].include?(column_type)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -150,6 +150,18 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
|
||||||
to raise_error(described_class::IneffectiveTestError)
|
to raise_error(described_class::IneffectiveTestError)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
context 'and not validating anything' do
|
context 'and not validating anything' do
|
||||||
|
@ -233,6 +245,17 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
|
||||||
expect(record).to validate_numericality.odd
|
expect(record).to validate_numericality.odd
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
context 'and not validating with odd' do
|
context 'and not validating with odd' do
|
||||||
|
@ -276,6 +299,17 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
|
||||||
expect(record).to validate_numericality.even
|
expect(record).to validate_numericality.even
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
context 'and not validating with even' do
|
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)
|
expect(record).to validate_numericality.is_less_than_or_equal_to(18)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
context 'and not validating with less_than_or_equal_to' do
|
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)
|
expect(record).to validate_numericality.is_less_than(18)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
context 'and not validating with less_than' do
|
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)
|
expect(record).to validate_numericality.is_equal_to(18)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
context 'and not validating with equal_to' do
|
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)
|
is_greater_than_or_equal_to(18)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
context 'not validating with greater_than_or_equal_to' do
|
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)
|
is_greater_than(18)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
context 'and not validating with greater_than' do
|
context 'and not validating with greater_than' do
|
||||||
|
|
Loading…
Reference in New Issue