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

validate_after_scope_change? use compact before retrieving max #677

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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 @@ -386,7 +386,7 @@ def validate_after_scope_change?
else
all_records = @subject.class.all
@options[:scopes].all? do |scope|
previous_value = all_records.map(&scope).max
previous_value = all_records.map(&scope).compact.max

next_value =
if previous_value.blank?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,21 @@
end
end

context 'when the scope_to is used and existing records contain nil values on scoped attribute' do

Choose a reason for hiding this comment

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

Line is too long. [100/80]

it 'still works' do
model = define_model_validating_uniqueness(
scopes: [name: :scope1])

Choose a reason for hiding this comment

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

Indent the first parameter one step more than the previous line.


create_record_from(model, attribute_name: 'uniq 1', scope1: 'uniq 1')
create_record_from(model, attribute_name: 'rec with nil desc', scope1: nil)

Choose a reason for hiding this comment

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

Line is too long. [81/80]

record = build_record_from(model, attribute_name: 'this should be ok', scope1: 'this should be ok')

Choose a reason for hiding this comment

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

Line is too long. [105/80]


expect(record).
to validate_uniqueness.
scoped_to(:scope1)
end
end

let(:model_attributes) { {} }

def default_attribute
Expand Down