Class FixtureReplacement::AttributeBuilder

  1. lib/fixture_replacement/attribute_builder.rb (view online)
Parent: Object

Attributes

fixture_name [R]
from [R]

Public class methods

add_instance (instance)
[show source]
    # File lib/fixture_replacement/attribute_builder.rb, line 16
16:       def add_instance(instance)
17:         instances << instance
18:       end
clear_out_instances! ()
[show source]
    # File lib/fixture_replacement/attribute_builder.rb, line 20
20:       def clear_out_instances!
21:         @instances = nil
22:       end
find_by_fixture_name (arg)
[show source]
    # File lib/fixture_replacement/attribute_builder.rb, line 24
24:       def find_by_fixture_name(arg)
25:         instances.detect { |instance| instance.fixture_name == arg }
26:       end
instances ()
[show source]
    # File lib/fixture_replacement/attribute_builder.rb, line 12
12:       def instances
13:         @instances ||= []
14:       end
new (fixture_name, options={}, &block)
[show source]
    # File lib/fixture_replacement/attribute_builder.rb, line 29
29:     def initialize(fixture_name, options={}, &block)
30:       options.symbolize_keys!
31: 
32:       check_valid_keys(options, [:from, :class])
33: 
34:       @fixture_name    = fixture_name.to_sym
35:       @attributes_proc = block || lambda {}
36:       @from            = options[:from].to_sym if options.has_key?(:from)
37:       @class           = options[:class]
38: 
39:       self.class.add_instance(self)
40:     end
validate_instances! ()
[show source]
    # File lib/fixture_replacement/attribute_builder.rb, line 4
 4:       def validate_instances!
 5:         instances.each do |fixture|
 6:           fixture.validate!
 7:         end
 8: 
 9:         true
10:       end

Public instance methods

active_record_class ()
[show source]
    # File lib/fixture_replacement/attribute_builder.rb, line 45
45:     def active_record_class
46:       @active_record_class ||= find_active_record_class
47:     end
instantiate (hash_to_merge = {}, instance = active_record_class.new)
[show source]
    # File lib/fixture_replacement/attribute_builder.rb, line 49
49:     def instantiate(hash_to_merge = {}, instance = active_record_class.new)
50:       returning instance do
51:         instantiate_parent_fixture(instance)
52:         call_attribute_body(instance, hash_to_merge)
53:         add_given_keys(instance, hash_to_merge)
54:       end
55:     end
validate! ()
[show source]
    # File lib/fixture_replacement/attribute_builder.rb, line 57
57:     def validate!
58:       new_instance = instantiate
59: 
60:       unless new_instance.valid?
61:         errors = "new_#{fixture_name} is not valid! - Errors: "
62:         errors << new_instance.errors.map { |key, value| "[#{key}: #{value}]"}.join(", ")
63:         raise InvalidInstance, errors
64:       end
65:     end