Skip to content

Instantly share code, notes, and snippets.

@queso
Created October 28, 2008 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save queso/20417 to your computer and use it in GitHub Desktop.
Save queso/20417 to your computer and use it in GitHub Desktop.
#### 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment