Note that there are some explanatory texts on larger screens.

plurals
  1. POHow come Factory Girl isn't sequencing unique attributes?
    text
    copied!<p>My controller spec fails because Factory Girl seems to be creating non-unique Users even though I sequence the User attributes that need to be unique.</p> <p><strong>The Errors</strong></p> <pre><code> 1) TopicsController POST #create when topic is invalid should render new Failure/Error: let(:invalid_topic) {Factory.build :invalid_topic} ActiveRecord::RecordInvalid:Validation failed: Email has already been taken, Username has already been taken 2) TopicsController POST #create when topic is valid should redirect to show Failure/Error: let(:valid_topic) {Factory.build :topic} ActiveRecord::RecordInvalid: Validation failed: Email has already been taken, Username has already been taken </code></pre> <p><strong>The Controller Spec (RSpec)</strong></p> <pre><code> describe "POST #create" do let(:valid_topic) {Factory.build :topic} let(:invalid_topic) {Factory.build :invalid_topic} context "when topic is invalid" do it "should render new" do post :create, :topic =&gt; invalid_topic response.should render_template(:new) end end context "when topic is valid" do it "should redirect to show" do post :create, :topic =&gt; valid_topic response.should redirect_to(topic_path(assigns(:topic))) end end end </code></pre> <p><strong>The Factories</strong></p> <pre><code>Factory.define :user do |f| f.sequence(:username) { |n| "foo#{n}"} f.password "password" f.password_confirmation { |u| u.password} f.sequence(:email) { |n| "foo#{n}@example.com"} end Factory.define :topic do |f| f.name "test topic" f.association :creator, :factory =&gt; :user f.forum_id 1 end </code></pre> <p><strong>Why isn't Factory Girl sequencing the User attributes when I use <code>Factory.create :topic</code>?</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload