diff options
-rw-r--r-- | activemodel/CHANGELOG.md | 13 | ||||
-rw-r--r-- | activemodel/test/cases/serializers/xml_serialization_test.rb | 2 | ||||
-rw-r--r-- | activerecord/CHANGELOG.md | 8 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/column.rb | 8 | ||||
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/base_test.rb | 12 | ||||
-rw-r--r-- | activerecord/test/cases/inheritance_test.rb | 10 | ||||
-rw-r--r-- | activerecord/test/cases/xml_serialization_test.rb | 12 | ||||
-rw-r--r-- | activerecord/test/fixtures/vegetables.yml | 9 | ||||
-rw-r--r-- | activerecord/test/models/vegetables.rb | 14 | ||||
-rw-r--r-- | activerecord/test/schema/schema.rb | 5 | ||||
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 4 |
12 files changed, 87 insertions, 12 deletions
diff --git a/activemodel/CHANGELOG.md b/activemodel/CHANGELOG.md index 2a3c51172b..d3056e73a2 100644 --- a/activemodel/CHANGELOG.md +++ b/activemodel/CHANGELOG.md @@ -1,3 +1,16 @@ +## Rails 3.2.9 (unreleased) + +* Due to a change in builder, nil values and empty strings now generates + closed tags, so instead of this: + + <pseudonyms nil=\"true\"></pseudonyms> + + It generates this: + + <pseudonyms nil=\"true\"/> + + *Carlos Antonio da Silva* + ## Rails 3.2.8 (Aug 9, 2012) ## * No changes. diff --git a/activemodel/test/cases/serializers/xml_serialization_test.rb b/activemodel/test/cases/serializers/xml_serialization_test.rb index 38aecf51ff..7f14b21cf4 100644 --- a/activemodel/test/cases/serializers/xml_serialization_test.rb +++ b/activemodel/test/cases/serializers/xml_serialization_test.rb @@ -132,7 +132,7 @@ class XmlSerializationTest < ActiveModel::TestCase end test "should serialize nil" do - assert_match %r{<pseudonyms nil=\"true\"></pseudonyms>}, @contact.to_xml(:methods => :pseudonyms) + assert_match %r{<pseudonyms nil=\"true\"/>}, @contact.to_xml(:methods => :pseudonyms) end test "should serialize integer" do diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 12a936ff47..6e6dac5773 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -4,6 +4,14 @@ *Thiago Pradi* +* Fix time column type casting for invalid time string values to correctly return nil. + + *Adam Meehan* + +* Fix `becomes` when using a configured `inheritance_column`. + + *Yves Senn* + * Fix `reset_counters` when there are multiple `belongs_to` association with the same foreign key and one of them have a counter cache. Fixes #5200. diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb index 943f18844d..d38e8464c5 100644 --- a/activerecord/lib/active_record/connection_adapters/column.rb +++ b/activerecord/lib/active_record/connection_adapters/column.rb @@ -150,7 +150,13 @@ module ActiveRecord return string unless string.is_a?(String) return nil if string.empty? - string_to_time "2000-01-01 #{string}" + dummy_time_string = "2000-01-01 #{string}" + + fast_string_to_time(dummy_time_string) || begin + time_hash = Date._parse(dummy_time_string) + return nil if time_hash[:hour].nil? + new_time(*time_hash.values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction)) + end end # convert something to a boolean diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 038355deaa..8a3c3fed7d 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -162,7 +162,7 @@ module ActiveRecord became.instance_variable_set("@new_record", new_record?) became.instance_variable_set("@destroyed", destroyed?) became.instance_variable_set("@errors", errors) - became.type = klass.name unless self.class.descends_from_active_record? + became.send("#{klass.inheritance_column}=", klass.name) unless self.class.descends_from_active_record? became end diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index fc33438569..073e856e5e 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -919,6 +919,18 @@ class BasicsTest < ActiveRecord::TestCase assert_equal Time.local(2000, 1, 1, 5, 42, 0), topic.bonus_time end + def test_attributes_on_dummy_time_with_invalid_time + # Oracle, and Sybase do not have a TIME datatype. + return true if current_adapter?(:OracleAdapter, :SybaseAdapter) + + attributes = { + "bonus_time" => "not a time" + } + topic = Topic.find(1) + topic.attributes = attributes + assert_nil topic.bonus_time + end + def test_boolean b_nil = Boolean.create({ "value" => nil }) nil_id = b_nil.id diff --git a/activerecord/test/cases/inheritance_test.rb b/activerecord/test/cases/inheritance_test.rb index fab858e09c..54c9152c06 100644 --- a/activerecord/test/cases/inheritance_test.rb +++ b/activerecord/test/cases/inheritance_test.rb @@ -2,9 +2,10 @@ require "cases/helper" require 'models/company' require 'models/project' require 'models/subscriber' +require 'models/vegetables' class InheritanceTest < ActiveRecord::TestCase - fixtures :companies, :projects, :subscribers, :accounts + fixtures :companies, :projects, :subscribers, :accounts, :vegetables def test_class_with_store_full_sti_class_returns_full_name old = ActiveRecord::Base.store_full_sti_class @@ -98,6 +99,13 @@ class InheritanceTest < ActiveRecord::TestCase switch_to_default_inheritance_column end + def test_alt_becomes_works_with_sti + vegetable = Vegetable.find(1) + assert_kind_of Vegetable, vegetable + cabbage = vegetable.becomes(Cabbage) + assert_kind_of Cabbage, cabbage + end + def test_inheritance_find_all companies = Company.find(:all, :order => 'id') assert_kind_of Firm, companies[0], "37signals should be a firm" diff --git a/activerecord/test/cases/xml_serialization_test.rb b/activerecord/test/cases/xml_serialization_test.rb index 88751a72f9..33d510499b 100644 --- a/activerecord/test/cases/xml_serialization_test.rb +++ b/activerecord/test/cases/xml_serialization_test.rb @@ -130,18 +130,18 @@ class NilXmlSerializationTest < ActiveRecord::TestCase end def test_should_serialize_string - assert_match %r{<name nil="true"></name>}, @xml + assert_match %r{<name nil="true"/>}, @xml end def test_should_serialize_integer - assert %r{<age (.*)></age>}.match(@xml) + assert %r{<age (.*)/>}.match(@xml) attributes = $1 assert_match %r{nil="true"}, attributes assert_match %r{type="integer"}, attributes end def test_should_serialize_binary - assert %r{<avatar (.*)></avatar>}.match(@xml) + assert %r{<avatar (.*)/>}.match(@xml) attributes = $1 assert_match %r{type="binary"}, attributes assert_match %r{encoding="base64"}, attributes @@ -149,21 +149,21 @@ class NilXmlSerializationTest < ActiveRecord::TestCase end def test_should_serialize_datetime - assert %r{<created-at (.*)></created-at>}.match(@xml) + assert %r{<created-at (.*)/>}.match(@xml) attributes = $1 assert_match %r{nil="true"}, attributes assert_match %r{type="datetime"}, attributes end def test_should_serialize_boolean - assert %r{<awesome (.*)></awesome>}.match(@xml) + assert %r{<awesome (.*)/>}.match(@xml) attributes = $1 assert_match %r{type="boolean"}, attributes assert_match %r{nil="true"}, attributes end def test_should_serialize_yaml - assert_match %r{<preferences nil=\"true\"></preferences>}, @xml + assert_match %r{<preferences nil=\"true\"/>}, @xml end end diff --git a/activerecord/test/fixtures/vegetables.yml b/activerecord/test/fixtures/vegetables.yml new file mode 100644 index 0000000000..82bd607701 --- /dev/null +++ b/activerecord/test/fixtures/vegetables.yml @@ -0,0 +1,9 @@ +first_cucumber: + id: 1 + custom_type: Cucumber + name: 'my cucumber' + +first_cabbage: + id: 2 + custom_type: Cabbage + name: 'my cabbage'
\ No newline at end of file diff --git a/activerecord/test/models/vegetables.rb b/activerecord/test/models/vegetables.rb new file mode 100644 index 0000000000..59cedfd9f5 --- /dev/null +++ b/activerecord/test/models/vegetables.rb @@ -0,0 +1,14 @@ +class Vegetable < ActiveRecord::Base + + validates_presence_of :name + + def self.inheritance_column + 'custom_type' + end +end + +class Cucumber < Vegetable +end + +class Cabbage < Vegetable +end diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index b3ae2abbc4..b8150c50b9 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -179,6 +179,11 @@ ActiveRecord::Schema.define do add_index :companies, [:firm_id, :type, :rating, :ruby_type], :name => "company_index" + create_table :vegetables, :force => true do |t| + t.string :name + t.string :custom_type + end + create_table :computers, :force => true do |t| t.integer :developer, :null => false t.integer :extendedWarranty, :null => false diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 56dfeb68cc..b5eb049ad4 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -614,7 +614,7 @@ class HashToXmlTest < Test::Unit::TestCase assert_equal "<person>", xml.first(8) assert xml.include?(%(<street>Paulina</street>)) assert xml.include?(%(<name>David</name>)) - assert xml.include?(%(<age nil="true"></age>)) + assert xml.include?(%(<age nil="true"/>)) end def test_one_level_with_skipping_types @@ -622,7 +622,7 @@ class HashToXmlTest < Test::Unit::TestCase assert_equal "<person>", xml.first(8) assert xml.include?(%(<street>Paulina</street>)) assert xml.include?(%(<name>David</name>)) - assert xml.include?(%(<age nil="true"></age>)) + assert xml.include?(%(<age nil="true"/>)) end def test_one_level_with_yielding |