aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/attribute_methods_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases/attribute_methods_test.rb')
-rw-r--r--activerecord/test/cases/attribute_methods_test.rb52
1 files changed, 35 insertions, 17 deletions
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb
index 8214815bde..dfacf58da8 100644
--- a/activerecord/test/cases/attribute_methods_test.rb
+++ b/activerecord/test/cases/attribute_methods_test.rb
@@ -8,6 +8,7 @@ require 'models/topic'
require 'models/company'
require 'models/category'
require 'models/reply'
+require 'models/contact'
class AttributeMethodsTest < ActiveRecord::TestCase
fixtures :topics, :developers, :companies, :computers
@@ -105,7 +106,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
def test_read_attributes_before_type_cast
category = Category.new({:name=>"Test categoty", :type => nil})
- category_attrs = {"name"=>"Test categoty", "type" => nil, "categorizations_count" => nil}
+ category_attrs = {"name"=>"Test categoty", "id" => nil, "type" => nil, "categorizations_count" => nil}
assert_equal category_attrs , category.attributes_before_type_cast
end
@@ -116,24 +117,23 @@ class AttributeMethodsTest < ActiveRecord::TestCase
end
end
- unless current_adapter?(:Mysql2Adapter)
- def test_read_attributes_before_type_cast_on_datetime
- developer = Developer.find(:first)
- # Oracle adapter returns Time before type cast
- unless current_adapter?(:OracleAdapter)
- assert_equal developer.created_at.to_s(:db) , developer.attributes_before_type_cast["created_at"].to_s
- else
- assert_equal developer.created_at.to_s(:db) , developer.attributes_before_type_cast["created_at"].to_s(:db)
+ def test_read_attributes_before_type_cast_on_datetime
+ developer = Developer.find(:first)
+ if current_adapter?(:Mysql2Adapter, :OracleAdapter)
+ # Mysql2 and Oracle adapters keep the value in Time instance
+ assert_equal developer.created_at.to_s(:db), developer.attributes_before_type_cast["created_at"].to_s(:db)
+ else
+ assert_equal developer.created_at.to_s(:db), developer.attributes_before_type_cast["created_at"].to_s
+ end
- developer.created_at = "345643456"
- assert_equal developer.created_at_before_type_cast, "345643456"
- assert_equal developer.created_at, nil
+ developer.created_at = "345643456"
- developer.created_at = "2010-03-21 21:23:32"
- assert_equal developer.created_at_before_type_cast.to_s, "2010-03-21 21:23:32"
- assert_equal developer.created_at, Time.parse("2010-03-21 21:23:32")
- end
- end
+ assert_equal developer.created_at_before_type_cast, "345643456"
+ assert_equal developer.created_at, nil
+
+ developer.created_at = "2010-03-21 21:23:32"
+ assert_equal developer.created_at_before_type_cast, "2010-03-21 21:23:32"
+ assert_equal developer.created_at, Time.parse("2010-03-21 21:23:32")
end
def test_hash_content
@@ -247,6 +247,12 @@ class AttributeMethodsTest < ActiveRecord::TestCase
# puts ""
end
+ def test_read_overridden_attribute
+ topic = Topic.new(:title => 'a')
+ def topic.title() 'b' end
+ assert_equal 'a', topic[:title]
+ end
+
def test_query_attribute_string
[nil, "", " "].each do |value|
assert_equal false, Topic.new(:author_name => value).author_name?
@@ -455,6 +461,14 @@ class AttributeMethodsTest < ActiveRecord::TestCase
end
end
+ def test_write_nil_to_time_attributes
+ in_time_zone "Pacific Time (US & Canada)" do
+ record = @target.new
+ record.written_on = nil
+ assert_nil record.written_on
+ end
+ end
+
def test_time_attributes_are_retrieved_in_current_time_zone
in_time_zone "Pacific Time (US & Canada)" do
utc_time = Time.utc(2008, 1, 1)
@@ -596,6 +610,10 @@ class AttributeMethodsTest < ActiveRecord::TestCase
Object.send(:undef_method, :title) # remove test method from object
end
+ def test_list_of_serialized_attributes
+ assert_equal %w(content), Topic.serialized_attributes.keys
+ assert_equal %w(preferences), Contact.serialized_attributes.keys
+ end
private
def cached_columns