C0 code coverage information
Generated on Mon Feb 18 04:30:36 -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 series of ActiveRecord model attributes.
3 #
4 # My attributes come from the following places:
5 #
6 # * from the class which is specified with :from => :fixture_name
7 # when I was constructed
8 # * from the anonymous function which is passed from into my constructor
9 #
10 class AttributeCollection
11 class << self
12 def instances
13 @instances ||= []
14 end
15
16 def add_instance(instance)
17 @instances ||= []
18 @instances << instance
19 end
20
21 def clear_out_instances!
22 @instances = nil
23 end
24
25 # Finds the fixture by the given name
26 # If there are duplicate fixtures with the same name,
27 # it will find the first one which was specified. It will
28 # return nil if no fixture with the name given was found
29 def find_by_fixture_name(arg)
30 instances.each { |instance| return instance if instance.fixture_name == arg }
31 return nil
32 end
33 end
34
35 def initialize(fixture_name, options={})
36 @fixture_name = fixture_name
37 @attributes_proc = options[:attributes] || lambda { Hash.new }
38 @from = options[:from]
39 @class = options[:class]
40
41 self.class.add_instance(self)
42 end
43
44 attr_reader :fixture_name
45 attr_reader :from
46
47 def active_record_class
48 @class || find_by_fixture_name(@from).active_record_class
49 rescue
50 constantize(fixture_name)
51 end
52
53 def hash
54 return @merged_hash if @merged_hash
55 os = ClassFactory.fake_active_record_instance.new
56 @attributes_proc.call(os)
57 os.to_hash
58 end
59
60 # This merges the :from attributes hash and the attributes from
61 # the anonymous function, overriding any attributes derived from
62 # the :from hash, with the ones given in the anonymous function.
63 def merge!
64 if derived_fixture_is_present?
65 unmerge_hash!
66 @merged_hash = derived_fixtures_hash.merge(hash)
67 end
68 end
69
70 def to_new_class_instance(hash={}, caller=self)
71 ClassFactory.active_record_factory.new(self, hash, caller).to_new_instance
72 end
73
74 def to_created_class_instance(hash={}, caller=self)
75 ClassFactory.active_record_factory.new(self, hash, caller).to_created_instance
76 end
77
78 private
79
80 attr_reader :hash_given
81
82 def unmerge_hash!
83 @merged_hash = nil
84 end
85
86 def derived_fixtures_hash
87 derived_fixture.hash
88 end
89
90 def derived_fixture_is_present?
91 !derived_fixture.nil?
92 end
93
94 def find_by_fixture_name(symbol)
95 self.class.find_by_fixture_name(symbol)
96 end
97
98 def find_derived_fixture
99 find_by_fixture_name(self.from)
100 end
101
102 def derived_fixture
103 @my_fixture ||= find_derived_fixture
104 end
105
106 def constantize(symbol)
107 symbol.to_s.camelize.constantize
108 end
109 end
110 end
Generated using the rcov code coverage analysis tool for Ruby
version 0.8.1.2.