diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-12-02 06:03:43 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-12-02 06:03:43 +0000 |
commit | 57b7532b910f9258cad4111db79349d2d63be6d4 (patch) | |
tree | 32da547566c74dba559ae04ed073d1b3d9deb10b /activerecord/test | |
parent | 96c29ab890edaa54840f2cb0c9760b82ef875958 (diff) | |
download | rails-57b7532b910f9258cad4111db79349d2d63be6d4.tar.gz rails-57b7532b910f9258cad4111db79349d2d63be6d4.tar.bz2 rails-57b7532b910f9258cad4111db79349d2d63be6d4.zip |
Work-in progress for providing better join model support and polymorphic associations
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3209 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/aaa_create_tables_test.rb | 5 | ||||
-rw-r--r-- | activerecord/test/associations_interface_test.rb | 17 | ||||
-rw-r--r-- | activerecord/test/fixtures/db_definitions/schema.rb | 13 | ||||
-rw-r--r-- | activerecord/test/fixtures/post.rb | 4 | ||||
-rw-r--r-- | activerecord/test/fixtures/tag.rb | 2 | ||||
-rw-r--r-- | activerecord/test/fixtures/tagging.rb | 4 | ||||
-rw-r--r-- | activerecord/test/fixtures/taggings.yml | 5 | ||||
-rw-r--r-- | activerecord/test/fixtures/tags.yml | 3 |
8 files changed, 52 insertions, 1 deletions
diff --git a/activerecord/test/aaa_create_tables_test.rb b/activerecord/test/aaa_create_tables_test.rb index d49e62561f..eb40913930 100644 --- a/activerecord/test/aaa_create_tables_test.rb +++ b/activerecord/test/aaa_create_tables_test.rb @@ -10,6 +10,11 @@ class CreateTablesTest < Test::Unit::TestCase recreate ActiveRecord::Base assert true end + + def test_load_schema + eval(File.read("#{File.dirname(__FILE__)}/fixtures/db_definitions/schema.rb")) + assert true + end def test_drop_and_create_courses_table recreate Course, '2' diff --git a/activerecord/test/associations_interface_test.rb b/activerecord/test/associations_interface_test.rb new file mode 100644 index 0000000000..5f9447294a --- /dev/null +++ b/activerecord/test/associations_interface_test.rb @@ -0,0 +1,17 @@ +require 'abstract_unit' +require 'fixtures/tag' +require 'fixtures/tagging' +require 'fixtures/post' +require 'fixtures/comment' + +class AssociationsInterfaceTest < Test::Unit::TestCase + fixtures :posts, :comments, :tags, :taggings + + def test_post_having_a_single_tag_through_has_many + assert_equal taggings(:welcome_general), posts(:welcome).taggings.first + end + + def test_post_having_a_single_tag_through_belongs_to + assert_equal posts(:welcome), posts(:welcome).taggings.first.taggable + end +end diff --git a/activerecord/test/fixtures/db_definitions/schema.rb b/activerecord/test/fixtures/db_definitions/schema.rb new file mode 100644 index 0000000000..b839edbac0 --- /dev/null +++ b/activerecord/test/fixtures/db_definitions/schema.rb @@ -0,0 +1,13 @@ +ActiveRecord::Schema.define do + + create_table "taggings", :force => true do |t| + t.column "tag_id", :integer + t.column "taggable_type", :string + t.column "taggable_id", :integer + end + + create_table "tags", :force => true do |t| + t.column "name", :string + end + +end
\ No newline at end of file diff --git a/activerecord/test/fixtures/post.rb b/activerecord/test/fixtures/post.rb index bf44d8a0a5..61249c43e0 100644 --- a/activerecord/test/fixtures/post.rb +++ b/activerecord/test/fixtures/post.rb @@ -19,7 +19,9 @@ class Post < ActiveRecord::Base has_and_belongs_to_many :categories has_and_belongs_to_many :special_categories, :join_table => "categories_posts" - + + has_many :taggings, :as => :taggable + def self.what_are_you 'a post...' end diff --git a/activerecord/test/fixtures/tag.rb b/activerecord/test/fixtures/tag.rb new file mode 100644 index 0000000000..bfd81c69f7 --- /dev/null +++ b/activerecord/test/fixtures/tag.rb @@ -0,0 +1,2 @@ +class Tag < ActiveRecord::Base +end
\ No newline at end of file diff --git a/activerecord/test/fixtures/tagging.rb b/activerecord/test/fixtures/tagging.rb new file mode 100644 index 0000000000..06d0144b5a --- /dev/null +++ b/activerecord/test/fixtures/tagging.rb @@ -0,0 +1,4 @@ +class Tagging < ActiveRecord::Base + belongs_to :tag + belongs_to :taggable, :polymorphic => true +end
\ No newline at end of file diff --git a/activerecord/test/fixtures/taggings.yml b/activerecord/test/fixtures/taggings.yml new file mode 100644 index 0000000000..ca171346f1 --- /dev/null +++ b/activerecord/test/fixtures/taggings.yml @@ -0,0 +1,5 @@ +welcome_general: + id: 1 + tag_id: 1 + taggable_id: 1 + taggable_type: Post diff --git a/activerecord/test/fixtures/tags.yml b/activerecord/test/fixtures/tags.yml new file mode 100644 index 0000000000..2a494089ff --- /dev/null +++ b/activerecord/test/fixtures/tags.yml @@ -0,0 +1,3 @@ +general: + id: 1 + name: General
\ No newline at end of file |