Skip to content

Commit

Permalink
Remove default_scope when applying uniqueness validation
Browse files Browse the repository at this point in the history
  • Loading branch information
shioyama committed May 29, 2018
1 parent e0b12e1 commit 710bba5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mobility/active_record/uniqueness_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def validate_each(record, attribute, value)
private

def mobility_scope_relation(record, relation)
[*options[:scope]].inject(relation) do |scoped_relation, scope_item|
[*options[:scope]].inject(relation.unscoped) do |scoped_relation, scope_item|
scoped_relation.__mobility_query_scope__ do |m|
m.__send__(scope_item).eq(record.send(scope_item))
end
Expand Down
8 changes: 8 additions & 0 deletions spec/support/shared_examples/validation_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
@instance2 = model_class.new(attribute1 => "foo")
expect(@instance2).not_to be_valid
end

context "with default_scope defined" do
it "removes default_scope" do
model_class.class_eval { default_scope { none } }
model_class.create(attribute1 => "foo")
expect(model_class.new(attribute1 => "foo")).not_to be_valid
end
end
end

context "with untranslated scope on translated attribute" do
Expand Down

0 comments on commit 710bba5

Please sign in to comment.