class ActiveModelTest::BaseTestCase
Public Class Methods
new(attrs = {})
click to toggle source
# File test/unit/integrations/active_model_test.rb, line 31 def initialize(attrs = {}) attrs.each {|attr, value| send("#{attr}=", value)} @changed_attributes = {} end
Protected Class Methods
create()
click to toggle source
# File test/unit/integrations/active_model_test.rb, line 25 def self.create object = new object.save object end
model_attribute(name)
click to toggle source
# File test/unit/integrations/active_model_test.rb, line 17 def self.model_attribute(name) define_method(name) { instance_variable_get("@#{name}") } define_method("#{name}=") do |value| send("#{name}_will_change!") if self.class <= ActiveModel::Dirty && !send("#{name}_changed?") instance_variable_set("@#{name}", value) end end
name()
click to toggle source
# File test/unit/integrations/active_model_test.rb, line 47 def self.name 'ActiveModelTest::Foo' end
Public Instance Methods
default_test()
click to toggle source
# File test/unit/integrations/active_model_test.rb, line 9 def default_test end
Protected Instance Methods
attributes()
click to toggle source
# File test/unit/integrations/active_model_test.rb, line 36 def attributes @attributes ||= {} end
new_model(&block)
click to toggle source
Creates a new ActiveModel model (and the associated table)
# File test/unit/integrations/active_model_test.rb, line 14 def new_model(&block) # Simple ActiveModel superclass parent = Class.new do def self.model_attribute(name) define_method(name) { instance_variable_get("@#{name}") } define_method("#{name}=") do |value| send("#{name}_will_change!") if self.class <= ActiveModel::Dirty && !send("#{name}_changed?") instance_variable_set("@#{name}", value) end end def self.create object = new object.save object end def initialize(attrs = {}) attrs.each {|attr, value| send("#{attr}=", value)} @changed_attributes = {} end def attributes @attributes ||= {} end def save @changed_attributes = {} true end end model = Class.new(parent) do def self.name 'ActiveModelTest::Foo' end model_attribute :state end model.class_eval(&block) if block_given? model end
new_observer(model, &block)
click to toggle source
Creates a new ActiveModel observer
# File test/unit/integrations/active_model_test.rb, line 58 def new_observer(model, &block) observer = Class.new(ActiveModel::Observer) do attr_accessor :notifications def initialize super @notifications = [] end end observer.observe(model) observer.class_eval(&block) if block_given? observer end
save()
click to toggle source
# File test/unit/integrations/active_model_test.rb, line 40 def save @changed_attributes = {} true end