Skip to content

Instantly share code, notes, and snippets.

@johnreilly
Created February 8, 2010 17:12
Show Gist options
  • Select an option

  • Save johnreilly/298365 to your computer and use it in GitHub Desktop.

Select an option

Save johnreilly/298365 to your computer and use it in GitHub Desktop.
# Small bug in factory_girl running under rails 3 beta.
# Given a model:
class Thing < ActiveRecord::Base
# has a 'name' attribute
end
# These factory definitions work great.
Factory.define :thing do |thing|
thing.sequence(:name) { |n| "user#{n}" }
end
Factory.define :named_thing, :class => 'thing' do |thing|
thing.sequence(:name) { |n| "named_thing #{n}" }
end
# This one explodes on the 'Thing' constant.
Factory.define :another_named_thing, :class => Thing do |thing|
thing.sequence(:name) { |n| "another_named_thing #{n}" }
end
# % rails server
# /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0.beta/lib/active_support/dependencies.rb:459:in `load_missing_constant': uninitialized constant Thing (NameError)
# from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0.beta/lib/active_support/dependencies.rb:91:in `const_missing'
# from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0.beta/lib/active_support/dependencies.rb:103:in `const_missing'
# from ./test/factories/Thing.rb:9
# from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0.beta/lib/active_support/dependencies.rb:167:in `require'
# from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0.beta/lib/active_support/dependencies.rb:167:in `require'
# from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0.beta/lib/active_support/dependencies.rb:537:in `new_constants_in'
# from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0.beta/lib/active_support/dependencies.rb:167:in `require'
# from /Users/john/.bundle/bundler/gems/factory_girl-511843606ed9fcb0d1005a7b7b4e9598b07eae20-rails3/lib/factory_girl/factory.rb:307:in `find_definitions'
# from /Users/john/.bundle/bundler/gems/factory_girl-511843606ed9fcb0d1005a7b7b4e9598b07eae20-rails3/lib/factory_girl/factory.rb:306:in `each'
# from /Users/john/.bundle/bundler/gems/factory_girl-511843606ed9fcb0d1005a7b7b4e9598b07eae20-rails3/lib/factory_girl/factory.rb:306:in `find_definitions'
# from /Users/john/.bundle/bundler/gems/factory_girl-511843606ed9fcb0d1005a7b7b4e9598b07eae20-rails3/lib/factory_girl/factory.rb:302:in `each'
# from /Users/john/.bundle/bundler/gems/factory_girl-511843606ed9fcb0d1005a7b7b4e9598b07eae20-rails3/lib/factory_girl/factory.rb:302:in `find_definitions'
# from /Users/john/.bundle/bundler/gems/factory_girl-511843606ed9fcb0d1005a7b7b4e9598b07eae20-rails3/lib/factory_girl.rb:34
# from /Library/Ruby/Gems/1.8/gems/bundler-0.9.3/lib/bundler/runtime.rb:26:in `require'
# from /Library/Ruby/Gems/1.8/gems/bundler-0.9.3/lib/bundler/runtime.rb:26:in `require'
# from /Library/Ruby/Gems/1.8/gems/bundler-0.9.3/lib/bundler/runtime.rb:25:in `each'
# from /Library/Ruby/Gems/1.8/gems/bundler-0.9.3/lib/bundler/runtime.rb:25:in `require'
# from /Library/Ruby/Gems/1.8/gems/bundler-0.9.3/lib/bundler/runtime.rb:24:in `each'
# from /Library/Ruby/Gems/1.8/gems/bundler-0.9.3/lib/bundler/runtime.rb:24:in `require'
# from /Library/Ruby/Gems/1.8/gems/bundler-0.9.3/lib/bundler.rb:70:in `require'
# from /Users/john/src/test/r3test/config/application.rb:6
# from /Library/Ruby/Gems/1.8/gems/railties-3.0.0.beta/lib/rails/commands.rb:36:in `require'
# from /Library/Ruby/Gems/1.8/gems/railties-3.0.0.beta/lib/rails/commands.rb:36
# from /Users/john/src/test/r3test/script/rails:10:in `require'
# from /Users/john/src/test/r3test/script/rails:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment