Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix rails compatability with type casts.

  • Loading branch information...
commit c9d55c9b171978bc20148429a7cdd6a9820fed3a 1 parent 1f4b0f5
@bryckbost bryckbost authored
View
3  UPGRADES
@@ -1,3 +1,6 @@
+0.8 => ??
+ * [attribute]_before_typecast should become [attribute]_before_type_cast (note the extra _)
+
0.7.6 => 0.8
* Proxy#owner has been removed in favor of Proxy#proxy_owner
* @new instance variable renamed to @_new (you shouldn't be using this anyway)
View
10 lib/mongo_mapper/plugins/keys.rb
@@ -88,8 +88,8 @@ def #{key.name}
read_key(:#{key.name})
end
- def #{key.name}_before_typecast
- read_key_before_typecast(:#{key.name})
+ def #{key.name}_before_type_cast
+ read_key_before_type_cast(:#{key.name})
end
def #{key.name}=(value)
@@ -293,14 +293,14 @@ def read_key(key_name)
end
end
- def read_key_before_typecast(name)
- instance_variable_get(:"@#{name}_before_typecast")
+ def read_key_before_type_cast(name)
+ instance_variable_get(:"@#{name}_before_type_cast")
end
def write_key(name, value)
key = keys[name.to_s]
set_parent_document(key, value)
- instance_variable_set :"@#{name}_before_typecast", value
+ instance_variable_set :"@#{name}_before_type_cast", value
instance_variable_set :"@#{name}", key.set(value)
end
end
View
4 lib/mongo_mapper/plugins/rails.rb
@@ -27,8 +27,8 @@ def read_attribute(name)
self[name]
end
- def read_attribute_before_typecast(name)
- read_key_before_typecast(name)
+ def read_attribute_before_type_cast(name)
+ read_key_before_type_cast(name)
end
def write_attribute(name, value)
View
16 test/unit/test_embedded_document.rb
@@ -158,10 +158,10 @@ class ::OtherChild < ::Parent
@document.new.should respond_to(:foo)
end
- should "create reader before typecast method" do
- @document.new.should_not respond_to(:foo_before_typecast)
+ should "create reader before type cast method" do
+ @document.new.should_not respond_to(:foo_before_type_cast)
@document.key(:foo, String)
- @document.new.should respond_to(:foo_before_typecast)
+ @document.new.should respond_to(:foo_before_type_cast)
end
should "create writer method" do
@@ -339,7 +339,7 @@ def passwd
doc.passwd.should == 'secret'
end
- should "typecast key values" do
+ should "type cast key values" do
doc = @document.new(:name => 1234, :age => '21')
doc.name.should == '1234'
doc.age.should == 21
@@ -463,18 +463,18 @@ def name_and_age
context "reading a key before typcasting" do
should "work for defined keys" do
doc = @document.new(:name => 12)
- doc.name_before_typecast.should == 12
+ doc.name_before_type_cast.should == 12
end
should "raise no method error for undefined keys" do
doc = @document.new
- lambda { doc.foo_before_typecast }.should raise_error(NoMethodError)
+ lambda { doc.foo_before_type_cast }.should raise_error(NoMethodError)
end
should "be accessible for use in a document" do
@document.class_eval do
def untypcasted_name
- read_key_before_typecast(:name)
+ read_key_before_type_cast(:name)
end
end
@@ -496,7 +496,7 @@ def untypcasted_name
lambda { doc.fart = 'poof!' }.should raise_error(NoMethodError)
end
- should "typecast value" do
+ should "type cast value" do
doc = @document.new
doc.name = 1234
doc.name.should == '1234'
View
16 test/unit/test_rails.rb
@@ -33,8 +33,8 @@ def bar=(value)
write_attribute(:foo, value)
end
- def bar_before_typecast
- read_attribute_before_typecast(:foo)
+ def bar_before_type_cast
+ read_attribute_before_type_cast(:foo)
end
def bar
@@ -51,8 +51,8 @@ def bar
@klass.new(:foo => 'Bar').bar.should == 'Bar'
end
- should "be able to read key before typecast with read_attribute_before_typecast" do
- @klass.new(:foo => 21).bar_before_typecast.should == 21
+ should "be able to read key before type cast with read_attribute_before_type_cast" do
+ @klass.new(:foo => 21).bar_before_type_cast.should == 21
@klass.new(:foo => 21).bar.should == '21'
end
@@ -120,8 +120,8 @@ def bar=(value)
write_attribute(:foo, value)
end
- def bar_before_typecast
- read_attribute_before_typecast(:foo)
+ def bar_before_type_cast
+ read_attribute_before_type_cast(:foo)
end
def bar
@@ -138,8 +138,8 @@ def bar
@klass.new(:foo => 'Bar').bar.should == 'Bar'
end
- should "be able to read key before typecast with read_attribute_before_typecast" do
- @klass.new(:foo => 21).bar_before_typecast.should == 21
+ should "be able to read key before type cast with read_attribute_before_type_cast" do
+ @klass.new(:foo => 21).bar_before_type_cast.should == 21
@klass.new(:foo => 21).bar.should == '21'
end
Please sign in to comment.
Something went wrong with that request. Please try again.