C0 code coverage information
Generated on Mon Feb 18 04:30:35 -0500 2008 with rcov 0.8.1.2
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
1 module FixtureReplacementController
2 # I am a Factory which creates ActiveRecord Class instances.
3 # Give me a collection of attributes, and an additional hash,
4 # and I will merge them into a new ActiveRecord Instance (either a new
5 # instance with ActiveRecord::Base#new, or a created one ActiveRecord::Base#create!).
6 class ActiveRecordFactory
7
8 def initialize(attributes, hash={}, original_caller=self)
9 @attributes = attributes
10 @hash_given_to_constructor = hash
11 @caller = original_caller
12 end
13
14 def to_new_instance
15 new_object = @attributes.active_record_class.new
16 assign_values_to_instance new_object
17 return new_object
18 end
19
20 def to_created_instance
21 created_obj = self.to_new_instance
22 created_obj.save!
23 return created_obj
24 end
25
26 protected
27
28 def hash_given_to_constructor
29 @hash_given_to_constructor || Hash.new
30 end
31
32 private
33
34 def assign_values_to_instance(instance_object)
35 all_attributes.each do |key, value|
36 value = evaluate_possible_delayed_proc(value)
37 instance_object.__send__("#{key}=", value)
38 end
39 end
40
41 def find_value_from_delayed_evaluation_proc(value)
42 default_obj, params = value.call
43 value = @caller.__send__("create_#{default_obj.fixture_name}", params)
44 end
45
46 def evaluate_possible_delayed_proc(value)
47 case value
48 when Array
49 value.map! { |element| evaluate_possible_delayed_proc element }
50 when ClassFactory.delayed_evaluation_proc
51 find_value_from_delayed_evaluation_proc(value)
52 else
53 value
54 end
55 end
56
57 def all_attributes
58 @attributes.merge!
59 @all_merged_attributes ||= attributes_hash.merge(self.hash_given_to_constructor)
60 end
61
62 def attributes_hash
63 @attributes.hash
64 end
65
66 end
67 end
Generated using the rcov code coverage analysis tool for Ruby
version 0.8.1.2.