Skip to content

Instantly share code, notes, and snippets.

@coshx
Created September 3, 2010 12:59
Show Gist options
  • Save coshx/563847 to your computer and use it in GitHub Desktop.
Save coshx/563847 to your computer and use it in GitHub Desktop.
> rails g scaffold User name:string description:string
# factories.rb
Factory.sequence :name do |i|
"Test User #{i}"
end
Factory.define :user do |u|
u.name { Factory.next :name }
u.description 'This is my description'
end
Factory.define :admin, :parent => :user do |u|
u.description{ |user| "admin description #{user.name}" }
end
# user_spec.rb
require 'spec_helper'
describe User do
#self.use_transactional_fixtures = false
context :admin do
it "should have a valid name" do
Factory.create(:admin).name.should =~ /Test User \d+/
end
it "should have a valid description" do
Factory.build(:admin).description.should =~ /admin description Test User \d+/
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment