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 UUID support to validates_uniqueness_of matcher #334

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 @@ -197,6 +197,8 @@ def correct_type_for_column(column)
'0'
elsif column.type == :datetime
DateTime.now
elsif column.type == :uuid
SecureRandom.uuid
else
0
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,41 @@ def validating_uniqueness_with_existing_record(options = {})
end
end

context 'when the scoped attribute is a uuid' do
it 'accepts' do
validating_scoped_uniqueness([:scope1], :uuid, :scope1 => SecureRandom.uuid).
should matcher.scoped_to(:scope1)
end

context 'with an existing record that conflicts with scope.next' do
it 'accepts' do
validating_scoped_uniqueness_with_conflicting_next(:scope1, :uuid, :scope1 => SecureRandom.uuid).
should matcher.scoped_to(:scope1)
end
end

context 'with a nil value' do
it 'accepts' do
validating_scoped_uniqueness([:scope1], :uuid, :scope1 => nil).
should matcher.scoped_to(:scope1)
end
end

context 'when too narrow of a scope is specified' do
it 'rejects' do
validating_scoped_uniqueness([:scope1, :scope2], :uuid, :scope1 => SecureRandom.uuid, :scope2 => SecureRandom.uuid).
should_not matcher.scoped_to(:scope1, :scope2, :other)
end
end

context 'with an existing record that conflicts with scope.next' do
Copy link
Collaborator

Choose a reason for hiding this comment

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

This context shares the same name with a context above. It looks like you copied this from the datetime context, which erroneously duplicates this context. Do you think you can remove this? I'll take care of removing the other one.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually I will just go ahead and take care of removing this for you. Everything else looks fine.

it 'accepts' do
validating_scoped_uniqueness_with_conflicting_next(:scope1, :scope1 => 1).
should matcher.scoped_to(:scope1)
end
end
end

def create_existing_record(attributes = {})
@existing ||= create_record(attributes)
end
Expand Down