lib/fixture_background/background.rb in fixture_background-0.9.5 vs lib/fixture_background/background.rb in fixture_background-0.9.6
- old
+ new
@@ -15,13 +15,26 @@
def name
"#{parent_class.name}"
end
EOT
- background_to_use.generate!
+ klass.class_eval <<-EOT
+ cattr_accessor :fixture_background
+ @@background_generated = false
+
+ def initialize(*args)
+ super
+
+ if (background = fixture_background) && !@@background_generated
+ background.generate!
+ @@background_generated = true
+ self.class.fixtures :all
+ end
+ end
+ EOT
+ klass.fixture_background = background_to_use
klass.fixture_path = background_to_use.fixture_path
- klass.fixtures :all
Object.const_set(full_class_name, klass)
end
def class_by_name(class_name)