Skip to content

Commit

Permalink
Do not raise CouldNotSetAttributeError on decimal columns
Browse files Browse the repository at this point in the history
  • Loading branch information
Raúl Acuña authored and mcmire committed Oct 23, 2015
1 parent 7e976f1 commit a0f1221
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a0f1221

Please sign in to comment.