/
tagger_spec.rb
91 lines (69 loc) · 2.92 KB
/
tagger_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
require File.expand_path('../../spec_helper', __FILE__)
describe "Tagger" do
before(:each) do
clean_database!
@user = TaggableUser.create
@taggable = TaggableModel.create(:name => "Bob Jones")
end
it "should have taggings" do
@user.tag(@taggable, :with=>'ruby,scheme', :on=>:tags)
@user.owned_taggings.size == 2
end
it "should have tags" do
@user.tag(@taggable, :with=>'ruby,scheme', :on=>:tags)
@user.owned_tags.size == 2
end
it "should not overlap tags from different taggers" do
@user2 = TaggableUser.new
lambda{
@user.tag(@taggable, :with => 'ruby, scheme', :on => :tags)
@user2.tag(@taggable, :with => 'java, python, lisp, ruby', :on => :tags)
}.should change(Tagging, :count).by(6)
[@user, @user2, @taggable].each(&:reload)
@user.owned_tags.map(&:name).sort.should == %w(ruby scheme).sort
@user2.owned_tags.map(&:name).sort.should == %w(java python lisp ruby).sort
@taggable.tags_from(@user).sort.should == %w(ruby scheme).sort
@taggable.tags_from(@user2).sort.should == %w(java lisp python ruby).sort
@taggable.all_tags_list.sort.should == %w(ruby scheme java python lisp).sort
@taggable.all_tags_on(:tags).size.should == 5
end
it "should not lose tags from different taggers" do
@user2 = TaggableUser.create
@user2.tag(@taggable, :with => 'java, python, lisp, ruby', :on => :tags)
@user.tag(@taggable, :with => 'ruby, scheme', :on => :tags)
lambda {
@user2.tag(@taggable, :with => 'java, python, lisp', :on => :tags)
}.should change(Tagging, :count).by(-1)
[@user, @user2, @taggable].each(&:reload)
@taggable.tags_from(@user).sort.should == %w(ruby scheme).sort
@taggable.tags_from(@user2).sort.should == %w(java python lisp).sort
@taggable.all_tags_list.sort.should == %w(ruby scheme java python lisp).sort
@taggable.all_tags_on(:tags).length.should == 5
end
it "should not lose tags" do
@user2 = TaggableUser.create
@user.tag(@taggable, :with => 'awesome', :on => :tags)
@user2.tag(@taggable, :with => 'awesome, epic', :on => :tags)
lambda {
@user2.tag(@taggable, :with => 'epic', :on => :tags)
}.should change(Tagging, :count).by(-1)
@taggable.reload
@taggable.all_tags_list.should include('awesome')
@taggable.all_tags_list.should include('epic')
end
it "should not lose tags" do
@taggable.update_attributes(:tag_list => 'ruby')
@user.tag(@taggable, :with => 'ruby, scheme', :on => :tags)
[@taggable, @user].each(&:reload)
@taggable.tag_list.should == %w(ruby)
@taggable.all_tags_list.sort.should == %w(ruby scheme).sort
lambda {
@taggable.update_attributes(:tag_list => "")
}.should change(Tagging, :count).by(-1)
@taggable.tag_list.should == []
@taggable.all_tags_list.sort.should == %w(ruby scheme).sort
end
it "is tagger" do
@user.is_tagger?.should(be_true)
end
end