spec/attributes_spec.rb in simple_model-1.2.12 vs spec/attributes_spec.rb in simple_model-1.2.13
- old
+ new
@@ -22,11 +22,11 @@
context '#before_initialize' do
before(:all) do
class TestInit
include SimpleModel::Attributes
- # Do not initalize blank attributes
+ # Do not initialize blank attributes
self.before_initialize = lambda {|obj,attrs| attrs.select{|k,v| !v.blank?}}
has_attribute :far
end
end
@@ -45,11 +45,11 @@
context '#after_initialize' do
before(:all) do
class TestInit
include SimpleModel::Attributes
- # Do not initalize blank attributes
+ # Do not initialize blank attributes
self.after_initialize = lambda { |obj| obj.car = "test" if obj.car.blank?}
has_attribute :car
end
end
@@ -134,11 +134,11 @@
it "should call the method it describe by the default value if it exists" do
@default.attributes[:bar].should eql("bar")
end
- it "should set the defaul to the supplied symbol, if the method does not exist" do
+ it "should set the default to the supplied symbol, if the method does not exist" do
@default.attributes[:fab].should eql(:some_symbol)
end
it "should allow default value to be an empty array" do
@default.my_array.should eql([])
@@ -232,22 +232,22 @@
class MyBase
include SimpleModel::Attributes
has_boolean :bar
has_attribute :str
has_dates :some, :thing, :default => :fetch_date, :allow_blank => false, :initialize => false
-
+ alias_attribute :other, :bar
def fetch_date
Date.today
end
end
class NewerBase < MyBase
has_boolean :foo
has_int :str
end
end
- it "should merge defined attributes when class are inhereted" do
+ it "should merge defined attributes when class are inherited" do
NewerBase.attribute_defined?(:bar).should be_true
n = NewerBase.new
n.respond_to?(:bar_will_change!).should be_true
end
@@ -261,9 +261,14 @@
it "should allow redefining methods in child classes" do
n = NewerBase.new
n.str = '1'
n.str.should eql(1)
+ end
+
+ it "should set attribute from alias" do
+ MyBase.new(:other => true).bar?.should be_true
+ NewerBase.new(:other => true).bar?.should be_true
end
end
after(:all) do
[:OnGet,:TestDefault,:TestInit,:MyBase,:NewerBase].each do |test_klass|