Return to Snippet

Revision: 9295
at October 28, 2008 23:58 by jnunemaker


Initial Code
#### spec_factory.rb
require 'factory_girl'
 
Factory.sequence :login do |n|
  "bob#{n}" 
end
 
Factory.sequence :email do |n|
  "person#{n}@example.com" 
end
 
Factory.sequence :subdomain do |n|
  "joe#{n}" 
end
 
Factory.sequence :checksum do |n|
  n
end
 
Factory.define :user do |u|
  u.login { |l| l.login = Factory.next(:login) }
  u.password "tester1"
  u.password_confirmation "tester1"
  u.email { |e| e.email = Factory.next(:email) }
end
 
Factory.define :blog do |b|
  b.title "Joe's Blog"
  b.subdomain { |s| s.subdomain = Factory.next(:subdomain) }
  b.association :owner, :factory => :user
  b.association :design
end
 
Factory.define :post do |p|
  p.title "First post!"
  p.body "Woot, my blog is sexy!"
  p.association :blog
  p.association :creator, :factory => :user
end
 
 
# post_spec.rb
 
describe Post do
  before(:each) do
    user = Factory(:user)
    blog = Factory(:blog, :owner => user)
    
    @post = Factory(:post, :creator => user, :blog => blog)
  end
  
  describe "validations" do
 
    it "should be valid" do
      @post.should be_valid
    end
  end
end

Initial URL


Initial Description


Initial Title
factory girl example

Initial Tags


Initial Language
Ruby