lib/fixture_background/background.rb in fixture_background-0.9.0.2 vs lib/fixture_background/background.rb in fixture_background-0.9.1

- old
+ new

@@ -1,7 +1,33 @@ module FixtureBackground class Background + + class << self + def class_for_test(full_class_name, background_to_use, test_unit_class) + klass = class_by_name(full_class_name) || Object.const_set(full_class_name, Class.new(test_unit_class)) + + if helper_class = test_unit_class.instance_variable_get(:@helper_class) + klass.instance_variable_set(:@helper_class, helper_class) + end + + if controller_class = (test_unit_class.respond_to?(:controller_class) && test_unit_class.controller_class) + klass.controller_class = controller_class + end + + klass.fixture_path = background_to_use.fixture_path + klass.fixtures :all + klass + end + + def class_by_name(class_name) + klass = Module.const_get(class_name) + klass.is_a?(Class) && klass + rescue NameError + return false + end + end + attr_reader :background_block def initialize(full_class_name, test_unit_class, parent, blk) @test_unit_class = test_unit_class @full_class_name = full_class_name @@ -32,12 +58,9 @@ def fixture_path Rails.root.to_s + "/test/backgrounds/#{@full_class_name.underscore}/" end def class_for_test - klass = Kernel.const_set(@full_class_name, Class.new(@test_unit_class)) - klass.fixture_path = fixture_path - klass.fixtures :all - klass + self.class.class_for_test(@full_class_name, self, @test_unit_class) end end end