diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-09-03 07:12:18 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-09-03 07:12:18 -0700 |
commit | 30a8f0d5b675d0eddc0af05103f4eb7f95c7caad (patch) | |
tree | f6a04f5841e1b9f0bff04c698fb7b01355df0cce /activerecord/test | |
parent | ebc50c505d3c49b0fac7eccf85da6df751d4023c (diff) | |
parent | 20574956d1ca73b5713bb857870fcd57cd09b35e (diff) | |
download | rails-30a8f0d5b675d0eddc0af05103f4eb7f95c7caad.tar.gz rails-30a8f0d5b675d0eddc0af05103f4eb7f95c7caad.tar.bz2 rails-30a8f0d5b675d0eddc0af05103f4eb7f95c7caad.zip |
Merge pull request #7506 from senny/issue_7503
#becomes works with configured inheritance_column
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/inheritance_test.rb | 10 | ||||
-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 |
4 files changed, 37 insertions, 1 deletions
diff --git a/activerecord/test/cases/inheritance_test.rb b/activerecord/test/cases/inheritance_test.rb index e80259a7f1..cc9a93c16f 100644 --- a/activerecord/test/cases/inheritance_test.rb +++ b/activerecord/test/cases/inheritance_test.rb @@ -5,9 +5,10 @@ require 'models/post' require 'models/project' require 'models/subscriber' require 'models/teapot' +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 @@ -127,6 +128,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.all.merge!(:order => 'id').to_a assert_kind_of Firm, companies[0], "37signals should be a firm" 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 7c45ca27c0..eae7a04157 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -184,6 +184,11 @@ ActiveRecord::Schema.define do add_index :companies, [:firm_id, :type, :rating, :ruby_type], :name => "company_index" add_index :companies, [:firm_id, :type], :name => "company_partial_index", :where => "rating > 10" + 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 |