Add the has_many_polymorphs plugin
[cs356-p2-videostore.git] / vendor / plugins / has_many_polymorphs / generators / tagging / templates / tagging_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class TaggingTest < Test::Unit::TestCase
4   fixtures :taggings, :tags, <%= taggable_models[0..1].join(", ") -%>
5
6   def setup
7     @obj1 = <%= model_two %>.find(1)
8     @obj2 = <%= model_two %>.find(2)
9 <% if taggable_models.size > 1 -%>
10     @obj3 = <%= model_one -%>.find(1)
11 <% end -%>
12     @tag1 = Tag.find(1)  
13     @tag2 = Tag.find(2)  
14     @tagging1 = Tagging.find(1)
15   end
16
17   def test_tag_with
18     @obj2.tag_with "dark columbian"
19     assert_equal "columbian dark", @obj2.tag_list
20   end
21   
22 <% if options[:self_referential] -%>  
23   def test_self_referential_tag_with
24     @tag1.tag_with [1, 2]
25     assert @tag1.tags.include?(@tag1)
26     assert !@tag2.tags.include?(@tag1)
27   end
28
29 <% end -%>
30   def test__add_tags
31     @obj1._add_tags "porter longneck"
32     assert Tag.find_by_name("porter").taggables.include?(@obj1)
33     assert Tag.find_by_name("longneck").taggables.include?(@obj1)
34     assert_equal "delicious longneck porter", @obj1.tag_list    
35     
36     @obj1._add_tags [2]
37     assert_equal "delicious longneck porter sexy", @obj1.tag_list        
38   end
39   
40   def test__remove_tags
41     @obj2._remove_tags ["2", @tag1]
42     assert @obj2.tags.empty?
43   end
44   
45   def test_tag_list
46     assert_equal "delicious sexy", @obj2.tag_list
47   end
48     
49   def test_taggable
50     assert_raises(RuntimeError) do 
51       @tagging1.send(:taggable?, true) 
52     end
53     assert !@tagging1.send(:taggable?)
54 <% if taggable_models.size > 1 -%>
55     assert @obj3.send(:taggable?)
56 <% end -%>
57 <% if options[:self_referential] -%>  
58     assert @tag1.send(:taggable?)
59 <% end -%>    
60   end
61     
62 end