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

3.x no longer properly checks multiple scope in uniqueness #860

Closed
weppos opened this issue Dec 11, 2015 · 1 comment
Closed

3.x no longer properly checks multiple scope in uniqueness #860

weppos opened this issue Dec 11, 2015 · 1 comment

Comments

@weppos
Copy link

weppos commented Dec 11, 2015

We have the following code in a model

  validates :label, uniqueness: { scope: :account_id, message: "already exists for this account", allow_nil: true }
  validates :label, uniqueness: { scope: :user_id, message: "already exists for this user", allow_nil: true }

And the following spec

  describe "validations" do
    subject { FactoryGirl.build(:access_token) }

    it { FactoryGirl.create(:user_access_token, label: "Existing")
         is_expected.to validate_uniqueness_of(:label).scoped_to(:user_id).with_message("already exists for this user").allow_nil }

    it { FactoryGirl.create(:account_access_token, label: "Existing")
         is_expected.to validate_uniqueness_of(:label).scoped_to(:account_id).with_message("already exists for this account").allow_nil }
  end

With 2.x the spec was passing. With 3.x the spec is no longer passing with this error

     Failure/Error: is_expected.to validate_uniqueness_of(:label).scoped_to(:user_id).with_message("already exists for this user").allow_nil }
       Expected validation to be scoped to [:user_id], but it was scoped to [:account_id].

It looks like 3.x doesn't properly understand multiple uniqueness with different scopes on the same attribute.

@mcmire
Copy link
Collaborator

mcmire commented Dec 14, 2015

Yes, this is a known issue with 3.0. It was already filed as #830, so I'll keep the discussion there.

@mcmire mcmire closed this as completed Dec 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants