lib/test_dummy.rb in test_dummy-0.1.4 vs lib/test_dummy.rb in test_dummy-0.2.0

- old
+ new

@@ -7,10 +7,14 @@ def self.included(base) base.send(:extend, ClassMethods) base.send(:include, InstanceMethods) end + def self.declare(on_class, &block) + on_class.instance_eval(&block) + end + module Support # Combines several sets of parameters together into a single set in order # of lowest priority to highest priority. Supplied list can contain nil # values which will be ignored. Returns a Hash with symbolized keys. def self.combine_attributes(*sets) @@ -116,10 +120,23 @@ # 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("models/dummy/#{name.underscore}.rb", Rails.root) + + if (File.exist?(dummy_path)) + require dummy_path + end + rescue LoadError + false + end + end + model = new(TestDummy::Support.combine_attributes(scoped.scope_for_create, with_attributes)) yield(model) if (block_given?) self.execute_dummy_operation(model, with_attributes) @@ -209,10 +226,10 @@ when 2, -1 block.call(model, with_attributes) when 1 block.call(model) else - block.call + model.instance_eval(&block) end end def dummy_method(name) name = name.to_sym