ruby on rails - FactoryGirl + Faker - same data being generated for every object in db seed data -


I use Factorigrl and Fekr to create user objects in your seeds.rb file I am doing, but for some

# users.rb requires 'thug' the factory to FactoryGirl.define: first_name thugs user :: Name.first_name LAST_NAME thugs :: Name.last_name call thugs :: PhoneNumber.cell_phone email thugs :: Internet.email password "password" password_confirmation "password" and end

and in the code seeds.rb file:

# seeds.rb rand (5 .. 11) .times {FactoryGirl.create (: user)}

Error:

ActiveRecord :: RecordInvalid: validation failed: email has already taken

If I use my open console and FactoryGirl.cr I Eate (: user) I get the same result ... the same object is being made up and up even if I just run Faker :: Internet.email several times many e-mails.

Factorial:

  [1] pt (main)> gt; FactoryGirl.create (: Users) ... = & gt; # & Lt; User ID: 3, first_name: "Osvaldo", last_name: "Wunsch", e-mail: "willy@damore.net", phone: "(912)530-4949 x64848", created_at: "2014-07-31 20:57 : 27 ", updated_at:" 2014-07-31 20:57:27 ", encrypted_password:" $ 2 A $ 10 $ mxWC7yLYR0m / Sw8MO6Lyru.xuTHCdCEuM9Orx3LXGApF ... ", reset_password_token: zero, reset_password_sent_at: zero, remember_created_at: zero, SIGN_IN_COUNT: 0, current_sign_in_at: zero, last_sign_in_at: zero, current_sign_in_ip: zero, last_sign_in_ip: zero & gt; [2] Pry (main)> gt; FactoryGirl.create (: user) ... ActiveRecord :: RecordInvalid: Validation failed: Email has already taken  

conning yourself:

  [3] PRI (Main) & gt; Faker :: Internet.email = & gt; "Hobart_purdy@goodwinmills.org" [4] Pry (Main)> Faker :: Internet.email = & gt; "Pierce_brekke@gislasonrolfson.net"  

What am I missing here? Why is one data created every time while using a throwing through a factual?

You have to give a block you want the value re-evaluated for each example.

Try instead

  email Faker :: Internet.email  

...

 < Code> Email {Faker :: Internet.email}  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -