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

Sequences not returning unique value #238

Closed
laclance opened this issue Jul 24, 2017 · 3 comments
Closed

Sequences not returning unique value #238

laclance opened this issue Jul 24, 2017 · 3 comments

Comments

@laclance
Copy link

My model tests used to pass, I have not changed them and now they fail with "name already exists".
I have looked at and tried many solutions but have not found one that works. Also tried using instance variables in my test and moving instantiation to different blocks, before, it, describe and context.

FactoryGirl.define do
  factory :activity do
    sequence(:name) { |n| "name_#{n}" }
  end
end
RSpec.describe Activity do
  let(:activity) { FactoryGirl.create :activity }

  it "has a valid factory" do
    expect(activity).to be_valid
  end
end

rspec-rails > 3.5
factory_girl_rails > 4.8
ruby > 2.3.3
rails > 4.2.0

@felipegruoso
Copy link

Same error here.. any solution?

@jferris
Copy link
Member

jferris commented Oct 25, 2017

Are you using transactional fixtures or database cleaner to wipe your specs in between runs? The sequences start over each time you run the tests, so if data persists between runs, you'll get duplicates.

@joshuaclayton
Copy link
Contributor

Closing due to inactivity.

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

4 participants