lib/test_dummy.rb in test_dummy-0.2.2 vs lib/test_dummy.rb in test_dummy-0.2.3

- old
+ new

@@ -120,22 +120,11 @@ # Builds a dummy model with some parameters set as supplied. The # new model is provided to the optional block for manipulation before # the dummy operation is completed. Returns a dummy model which has not # been saved. def build_dummy(with_attributes = nil) - unless (defined?(@_dummy_module)) - @_dummy_module = - begin - dummy_path = File.expand_path("test/dummy/#{name.underscore}.rb", Rails.root) - - if (File.exist?(dummy_path)) - require dummy_path - end - rescue LoadError - false - end - end + load_dummy_declaration! model = new(TestDummy::Support.combine_attributes(scoped.scope_for_create, with_attributes)) yield(model) if (block_given?) @@ -201,10 +190,12 @@ end # This performs the dummy operation on a model with an optional set # of parameters. def execute_dummy_operation(model, with_attributes = nil) + load_dummy_declaration! + return model unless (@test_dummy_order) @test_dummy_order.each do |name| if (reflection = reflect_on_association(name)) unless ((with_attributes and with_attributes.key?(name.to_sym)) or model.send(name).present?) @@ -219,9 +210,24 @@ model end protected + def load_dummy_declaration! + return if (defined?(@_dummy_module)) + + @_dummy_module = + begin + dummy_path = File.expand_path("test/dummy/#{name.underscore}.rb", Rails.root) + + if (File.exist?(dummy_path)) + require dummy_path + end + rescue LoadError + false + end + end + def dummy_method_call(model, with_attributes, block) case (block.arity) when 2, -1 block.call(model, with_attributes) when 1