Created
September 3, 2010 12:59
-
-
Save coshx/563847 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> 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