Skip to content
Browse files

Avoid class lookup collisions

  • Loading branch information...
1 parent b269992 commit 762b66c32bf8ae27c72fe17d63c76f4232c14a70 @mhfs mhfs committed Mar 31, 2012
View
2 lib/factory_girl/preload/helpers.rb
@@ -15,7 +15,7 @@ def self.included(base)
class_eval <<-RUBY, __FILE__, __LINE__
def #{method_name}(name)
- factory(name, #{model})
+ factory(name, ::#{model})
end
RUBY
end
View
4 spec/factory_girl/preload_spec.rb
@@ -21,6 +21,10 @@
skills(:ruby).should be_a(Skill)
end
+ it "returns :my factory for Preload model" do
+ preloads(:my).should be_a(Preload)
+ end
+
it "reuses existing factories" do
skills(:ruby).user.should == users(:john)
end
View
2 spec/support/app/app/models/preload.rb
@@ -0,0 +1,2 @@
+class Preload < ActiveRecord::Base
+end
View
5 spec/support/app/db/schema.rb
@@ -2,6 +2,7 @@
begin
drop_table :users
drop_table :skills
+ drop_table :preloads
rescue Exception => e
end
@@ -13,6 +14,10 @@
add_index :users, :email, :unique => true
+ create_table :preloads do |t|
+ t.string :name
+ end
+
create_table :skills do |t|
t.references :user
end
View
5 spec/support/factories.rb
@@ -8,8 +8,13 @@
f.association :user
end
+ factory :preload do |f|
+ f.name "My Preload"
+ end
+
preload do
factory(:john) { create(:user) }
factory(:ruby) { create(:skill, :user => users(:john)) }
+ factory(:my) { create(:preload) }
end
end

0 comments on commit 762b66c

Please sign in to comment.
Something went wrong with that request. Please try again.