2005-12-02 01:03:43 -05:00
|
|
|
require 'abstract_unit'
|
|
|
|
require 'fixtures/tag'
|
|
|
|
require 'fixtures/tagging'
|
|
|
|
require 'fixtures/post'
|
|
|
|
require 'fixtures/comment'
|
2005-12-11 13:06:51 -05:00
|
|
|
require 'fixtures/author'
|
|
|
|
require 'fixtures/category'
|
|
|
|
require 'fixtures/categorization'
|
2005-12-02 01:03:43 -05:00
|
|
|
|
2005-12-02 23:29:55 -05:00
|
|
|
class AssociationsJoinModelTest < Test::Unit::TestCase
|
2005-12-04 00:40:50 -05:00
|
|
|
self.use_transactional_fixtures = false
|
2005-12-11 13:06:51 -05:00
|
|
|
fixtures :posts, :authors, :categories, :categorizations, :comments, :tags, :taggings
|
|
|
|
|
|
|
|
def test_has_many
|
|
|
|
assert_equal categories(:general), authors(:david).categories.first
|
|
|
|
end
|
2005-12-16 18:24:58 -05:00
|
|
|
|
|
|
|
def test_has_many_inherited
|
|
|
|
assert_equal categories(:sti_test), authors(:mary).categories.first
|
|
|
|
end
|
2005-12-02 01:03:43 -05:00
|
|
|
|
2005-12-16 18:24:58 -05:00
|
|
|
def test_inherited_has_many
|
|
|
|
assert_equal authors(:mary), categories(:sti_test).authors.first
|
|
|
|
end
|
|
|
|
|
2005-12-02 23:29:55 -05:00
|
|
|
def test_polymorphic_has_many
|
2005-12-02 01:03:43 -05:00
|
|
|
assert_equal taggings(:welcome_general), posts(:welcome).taggings.first
|
|
|
|
end
|
|
|
|
|
2005-12-02 23:29:55 -05:00
|
|
|
def test_polymorphic_belongs_to
|
2005-12-02 01:03:43 -05:00
|
|
|
assert_equal posts(:welcome), posts(:welcome).taggings.first.taggable
|
|
|
|
end
|
2005-12-02 23:29:55 -05:00
|
|
|
|
|
|
|
def test_polymorphic_has_many_going_through_join_model
|
|
|
|
assert_equal tags(:general), posts(:welcome).tags.first
|
2005-12-16 18:24:58 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_polymorphic_has_many_going_through_join_model_with_inheritance
|
|
|
|
assert_equal tags(:general), posts(:thinking).tags.first
|
|
|
|
end
|
2005-12-20 15:32:47 -05:00
|
|
|
|
2006-01-20 16:51:48 -05:00
|
|
|
def test_polymorphic_has_many_create_model_with_inheritance
|
|
|
|
post = posts(:thinking)
|
|
|
|
assert_instance_of SpecialPost, post
|
|
|
|
|
|
|
|
tagging = tags(:misc).taggings.create(:taggable => post)
|
|
|
|
assert_equal "Post", tagging.taggable_type
|
|
|
|
end
|
|
|
|
|
2005-12-20 15:32:47 -05:00
|
|
|
def test_has_many_with_piggyback
|
2006-01-03 23:17:23 -05:00
|
|
|
assert_equal "2", categories(:sti_test).authors.first.post_id.to_s
|
2005-12-20 15:32:47 -05:00
|
|
|
end
|
2005-12-20 16:20:35 -05:00
|
|
|
|
|
|
|
def test_has_many_find_all
|
|
|
|
assert_equal [categories(:general)], authors(:david).categories.find(:all)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_has_many_find_first
|
|
|
|
assert_equal categories(:general), authors(:david).categories.find(:first)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_has_many_find_conditions
|
|
|
|
assert_equal categories(:general), authors(:david).categories.find(:first, :conditions => "categories.name = 'General'")
|
|
|
|
assert_equal nil, authors(:david).categories.find(:first, :conditions => "categories.name = 'Technology'")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_has_many_class_methods_called_by_method_missing
|
|
|
|
assert_equal categories(:general), authors(:david).categories.find_by_name('General')
|
|
|
|
# assert_equal nil, authors(:david).categories.find_by_name('Technology')
|
|
|
|
end
|
2005-12-16 18:24:58 -05:00
|
|
|
|
2005-12-02 01:03:43 -05:00
|
|
|
end
|