aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/aaa_create_tables_test.rb5
-rw-r--r--activerecord/test/associations_interface_test.rb17
-rw-r--r--activerecord/test/fixtures/db_definitions/schema.rb13
-rw-r--r--activerecord/test/fixtures/post.rb4
-rw-r--r--activerecord/test/fixtures/tag.rb2
-rw-r--r--activerecord/test/fixtures/tagging.rb4
-rw-r--r--activerecord/test/fixtures/taggings.yml5
-rw-r--r--activerecord/test/fixtures/tags.yml3
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