diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-26 14:50:18 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-26 14:50:18 -0300 |
commit | f437f1104687e5bb26bf5ce791aee7d9cc0ec62a (patch) | |
tree | cc422be64e95027514920850809a0d1ef788d30e /activerecord/test | |
parent | 8b0753b4f0d0f66b73aac4cd26d6b575edc99fb6 (diff) | |
parent | 3bc314e65830dabd7b1c47ad1fa27be5ace0699f (diff) | |
download | rails-f437f1104687e5bb26bf5ce791aee7d9cc0ec62a.tar.gz rails-f437f1104687e5bb26bf5ce791aee7d9cc0ec62a.tar.bz2 rails-f437f1104687e5bb26bf5ce791aee7d9cc0ec62a.zip |
Merge pull request #15924 from sgrif/sg-write-unknown-column
Move writing unknown column exception to null attribute
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/attribute_methods_test.rb | 9 | ||||
-rw-r--r-- | activerecord/test/cases/primary_keys_test.rb | 12 | ||||
-rw-r--r-- | activerecord/test/models/contact.rb | 1 |
3 files changed, 20 insertions, 2 deletions
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index 7566af920f..2048e0d5ad 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -253,6 +253,15 @@ class AttributeMethodsTest < ActiveRecord::TestCase assert_equal @loaded_fixtures['computers']['workstation'].to_hash, Computer.first.attributes end + def test_attributes_without_primary_key + klass = Class.new(ActiveRecord::Base) do + self.table_name = 'developers_projects' + end + + assert_equal klass.column_names, klass.new.attributes.keys + assert_not klass.new.attributes.key?('id') + end + def test_hashes_not_mangled new_topic = { :title => "New Topic" } new_topic_values = { :title => "AnotherTopic" } diff --git a/activerecord/test/cases/primary_keys_test.rb b/activerecord/test/cases/primary_keys_test.rb index f43483d291..b04df7ce43 100644 --- a/activerecord/test/cases/primary_keys_test.rb +++ b/activerecord/test/cases/primary_keys_test.rb @@ -134,14 +134,22 @@ class PrimaryKeysTest < ActiveRecord::TestCase end def test_primary_key_returns_value_if_it_exists + klass = Class.new(ActiveRecord::Base) do + self.table_name = 'developers' + end + if ActiveRecord::Base.connection.supports_primary_key? - assert_equal 'id', ActiveRecord::Base.connection.primary_key('developers') + assert_equal 'id', klass.primary_key end end def test_primary_key_returns_nil_if_it_does_not_exist + klass = Class.new(ActiveRecord::Base) do + self.table_name = 'developers_projects' + end + if ActiveRecord::Base.connection.supports_primary_key? - assert_nil ActiveRecord::Base.connection.primary_key('developers_projects') + assert_nil klass.primary_key end end diff --git a/activerecord/test/models/contact.rb b/activerecord/test/models/contact.rb index a1cb8d62b6..3ea17c3abf 100644 --- a/activerecord/test/models/contact.rb +++ b/activerecord/test/models/contact.rb @@ -8,6 +8,7 @@ module ContactFakeColumns table_name => 'id' } + column :id, :integer column :name, :string column :age, :integer column :avatar, :binary |