Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add decimal column type to numericality matcher #812

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put a comma after the last parameter of a multiline method call.

)
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put a comma after the last parameter of a multiline method call.

)

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put a comma after the last parameter of a multiline method call.

)

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put a comma after the last parameter of a multiline method call.

)

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put a comma after the last parameter of a multiline method call.

)

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put a comma after the last parameter of a multiline method call.

)

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put a comma after the last parameter of a multiline method call.

)

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put a comma after the last parameter of a multiline method call.

)

expect(record).
to validate_numericality.
is_greater_than(18)
end
end
end

context 'and not validating with greater_than' do
Expand Down