diff options
Diffstat (limited to 'activerecord/test/models/bulb.rb')
-rw-r--r-- | activerecord/test/models/bulb.rb | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/activerecord/test/models/bulb.rb b/activerecord/test/models/bulb.rb index 643dcefed3..888afc7604 100644 --- a/activerecord/test/models/bulb.rb +++ b/activerecord/test/models/bulb.rb @@ -4,11 +4,38 @@ class Bulb < ActiveRecord::Base attr_protected :car_id, :frickinawesome - attr_reader :scope_after_initialize + attr_reader :scope_after_initialize, :attributes_after_initialize after_initialize :record_scope_after_initialize def record_scope_after_initialize @scope_after_initialize = self.class.scoped end + after_initialize :record_attributes_after_initialize + def record_attributes_after_initialize + @attributes_after_initialize = attributes.dup + end + + def color=(color) + self[:color] = color.upcase + "!" + end + + def self.new(attributes = {}, options = {}, &block) + bulb_type = (attributes || {}).delete(:bulb_type) + + if options && options[:as] == :admin && bulb_type.present? + bulb_class = "#{bulb_type.to_s.camelize}Bulb".constantize + bulb_class.new(attributes, options, &block) + else + super + end + end +end + +class CustomBulb < Bulb + after_initialize :set_awesomeness + + def set_awesomeness + self.frickinawesome = true if name == 'Dude' + end end |