easy_tag 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/Rakefile +16 -9
- data/app/models/easy_tag/tag.rb +0 -3
- data/app/models/easy_tag/tag_context.rb +0 -3
- data/lib/easy_tag/taggable.rb +5 -4
- data/lib/easy_tag/tagger.rb +1 -1
- data/lib/easy_tag/version.rb +1 -1
- data/lib/easy_tag.rb +2 -2
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/comment.rb +3 -0
- data/test/dummy/app/models/post.rb +3 -0
- data/test/dummy/app/models/user.rb +3 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +29 -0
- data/test/dummy/config/environments/production.rb +80 -0
- data/test/dummy/config/environments/test.rb +36 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20130113020203_create_users.rb +9 -0
- data/test/dummy/db/migrate/20130113020210_create_posts.rb +9 -0
- data/test/dummy/db/migrate/20130113020220_create_comments.rb +9 -0
- data/test/dummy/db/migrate/20130117032413_easy_tag_migration.rb +34 -0
- data/test/dummy/db/schema.rb +61 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +847 -0
- data/test/dummy/log/test.log +92788 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/test/foo_test.rb +8 -0
- data/test/dummy/test/models/easy_tag/tag_test.rb +72 -0
- data/test/dummy/test/models/easy_tag/taggable_test.rb +214 -0
- data/test/dummy/test/models/easy_tag/tagger_test.rb +58 -0
- data/test/test_helper.rb +30 -0
- data.tar.gz.sig +0 -0
- metadata +134 -22
- metadata.gz.sig +2 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/404.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
54
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
55
|
+
</div>
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
57
|
+
</body>
|
58
|
+
</html>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/422.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>The change you wanted was rejected.</h1>
|
54
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
55
|
+
</div>
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
57
|
+
</body>
|
58
|
+
</html>
|
@@ -0,0 +1,57 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/500.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>We're sorry, but something went wrong.</h1>
|
54
|
+
</div>
|
55
|
+
<p>If you are the application owner check the logs for more information.</p>
|
56
|
+
</body>
|
57
|
+
</html>
|
File without changes
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'database_cleaner'
|
3
|
+
|
4
|
+
def match_array(a, b)
|
5
|
+
a.sort.must_equal(b.sort)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe EasyTag do
|
9
|
+
describe EasyTag::Tag do
|
10
|
+
before :each do
|
11
|
+
DatabaseCleaner.strategy = :transaction
|
12
|
+
DatabaseCleaner.start
|
13
|
+
end
|
14
|
+
|
15
|
+
after :each do
|
16
|
+
DatabaseCleaner.clean
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'compact tag list' do
|
20
|
+
tags = EasyTag::Tag.compact_tag_list('ruby, rails')
|
21
|
+
match_array(tags, ['ruby', 'rails'])
|
22
|
+
|
23
|
+
tags = EasyTag::Tag.compact_tag_list(['ruby', 'rails'])
|
24
|
+
match_array(tags, ['ruby', 'rails'])
|
25
|
+
|
26
|
+
tags = EasyTag::Tag.compact_tag_list('ruby; rails', {:delimiter => ';'})
|
27
|
+
match_array(tags, ['ruby', 'rails'])
|
28
|
+
|
29
|
+
tags = EasyTag::Tag.compact_tag_list('ruby; Rails', {:delimiter => ';', :downcase => true})
|
30
|
+
match_array(tags, ['ruby', 'rails'])
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'can get taggable' do
|
34
|
+
post = Post.create(:name => 'post')
|
35
|
+
comment = Comment.create(:name => 'comment')
|
36
|
+
|
37
|
+
post.set_tags('ruby, jruby')
|
38
|
+
comment.set_tags('jruby, java')
|
39
|
+
|
40
|
+
match_array(EasyTag::Tag.pluck(:name), ['ruby', 'jruby', 'java'])
|
41
|
+
|
42
|
+
tag = EasyTag::Tag.where(:name => 'ruby').first
|
43
|
+
match_array(tag.taggings.collect(&:taggable).collect(&:name), ['post'])
|
44
|
+
|
45
|
+
tag = EasyTag::Tag.where(:name => 'jruby').first
|
46
|
+
match_array(tag.taggings.collect(&:taggable).collect(&:name), ['post', 'comment'])
|
47
|
+
|
48
|
+
post.set_tags('ruby, rvm')
|
49
|
+
tag = EasyTag::Tag.where(:name => 'jruby').first
|
50
|
+
match_array(tag.taggings.collect(&:taggable).collect(&:name), ['comment'])
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'can get tagger' do
|
54
|
+
post = Post.create(:name => 'post')
|
55
|
+
user = User.create(:name => 'bob')
|
56
|
+
|
57
|
+
post.set_tags 'ruby, rvm', :tagger => user
|
58
|
+
post.set_tags 'jruby, java'
|
59
|
+
|
60
|
+
tag = EasyTag::Tag.where(:name => 'ruby').first
|
61
|
+
match_array(tag.taggers.pluck(:name), ['bob'])
|
62
|
+
|
63
|
+
tag = EasyTag::Tag.where(:name => 'java').first
|
64
|
+
tag.taggers.pluck(:name).count.must_equal(0)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'can create tag' do
|
68
|
+
tag = EasyTag::Tag.create(:name => 'tag')
|
69
|
+
tag.wont_be_nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,214 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
def match_array(a, b)
|
4
|
+
a.sort.must_equal(b.sort)
|
5
|
+
end
|
6
|
+
|
7
|
+
# without context and tagger
|
8
|
+
class TaggableTest < ActiveSupport::TestCase
|
9
|
+
test "no context" do
|
10
|
+
post = Post.create(:name => 'post')
|
11
|
+
assert_difference "EasyTag::TagContext.count", 0 do
|
12
|
+
post.set_tags('rails, ruby')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
test "clean old tags" do
|
17
|
+
post = Post.create(:name => 'post')
|
18
|
+
assert_difference "EasyTag::Tag.count", 2 do
|
19
|
+
post.set_tags('rails, ruby')
|
20
|
+
end
|
21
|
+
assert_equal 2, EasyTag::Tagging.count
|
22
|
+
assert_equal 2, post.taggings.count
|
23
|
+
assert_equal post.tags.pluck(:name).sort, ['rails', 'ruby'].sort
|
24
|
+
|
25
|
+
assert_difference "EasyTag::Tag.count", 2 do
|
26
|
+
post.set_tags('java, jruby')
|
27
|
+
end
|
28
|
+
assert_equal 2, EasyTag::Tagging.count
|
29
|
+
assert_equal 2, post.taggings.count
|
30
|
+
assert_equal post.tags.pluck(:name).sort, ['java', 'jruby'].sort
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'set tags' do
|
34
|
+
post = Post.create(:name => 'post')
|
35
|
+
assert_difference "EasyTag::Tag.count", 2 do
|
36
|
+
post.set_tags('rails, ruby')
|
37
|
+
end
|
38
|
+
assert_equal EasyTag::Tag.pluck(:name).sort, ['rails', 'ruby'].sort
|
39
|
+
assert_equal post.tags.pluck(:name).sort, ['rails', 'ruby'].sort
|
40
|
+
|
41
|
+
comment = Comment.create(:name => 'comment')
|
42
|
+
assert_difference "EasyTag::Tag.count", 1 do
|
43
|
+
comment.set_tags(['ruby', 'RVM'])
|
44
|
+
end
|
45
|
+
assert_equal EasyTag::Tag.pluck(:name).sort, ['rails', 'ruby', 'rvm'].sort
|
46
|
+
assert_equal comment.tags.pluck(:name).sort, ['ruby', 'rvm'].sort
|
47
|
+
end
|
48
|
+
|
49
|
+
test 'set tags in downcase' do
|
50
|
+
post = Post.new(:name => 'post')
|
51
|
+
post.set_tags('Rails, RUBY')
|
52
|
+
assert_equal EasyTag::Tag.pluck(:name).sort, ['rails', 'ruby'].sort
|
53
|
+
end
|
54
|
+
|
55
|
+
# with context and without tagger
|
56
|
+
test 'set tags with context and without tagger' do
|
57
|
+
post = Post.create(:name => 'post')
|
58
|
+
assert_difference "EasyTag::TagContext.count", 1 do
|
59
|
+
post.set_tags('rails, ruby', :context => 'ruby')
|
60
|
+
end
|
61
|
+
assert_difference "EasyTag::TagContext.count", 1 do
|
62
|
+
post.set_tags('jruby', :context => 'java')
|
63
|
+
end
|
64
|
+
assert_equal EasyTag::TagContext.pluck(:name).sort, ['ruby', 'java'].sort
|
65
|
+
assert_equal post.tags.pluck(:name).sort, ['rails', 'ruby', 'jruby'].sort
|
66
|
+
assert_equal post.tags.in_context(:ruby).pluck(:name).sort, ['rails', 'ruby'].sort
|
67
|
+
assert_equal post.tags.in_context(:java).pluck(:name).sort, ['jruby']
|
68
|
+
|
69
|
+
comment = Comment.create(:name => 'comment')
|
70
|
+
comment.set_tags(['ruby', 'RVM'], :context => 'ruby')
|
71
|
+
assert_equal EasyTag::TagContext.pluck(:name).sort, ['ruby', 'java'].sort
|
72
|
+
assert_equal comment.tags.pluck(:name).sort, ['ruby', 'rvm'].sort
|
73
|
+
assert_equal comment.tags.in_context(:ruby).pluck(:name).sort, ['ruby', 'rvm'].sort
|
74
|
+
end
|
75
|
+
|
76
|
+
# with context and with tagger
|
77
|
+
test 'set tags with context and with tagger' do
|
78
|
+
post = Post.create(:name => 'post')
|
79
|
+
user = User.create(:name => 'bob')
|
80
|
+
|
81
|
+
assert_difference "EasyTag::Tag.count", 2 do
|
82
|
+
post.set_tags('rails, ruby', :context => 'ruby', :tagger => user)
|
83
|
+
end
|
84
|
+
|
85
|
+
assert_equal user.tags.pluck(:name).sort, ['rails', 'ruby'].sort
|
86
|
+
|
87
|
+
post.set_tags('jruby', :context => 'java')
|
88
|
+
assert_equal user.tags.pluck(:name).sort, ['rails', 'ruby'].sort
|
89
|
+
|
90
|
+
post.set_tags('java', :tagger => user)
|
91
|
+
assert_equal user.tags.pluck(:name).sort, ['rails', 'ruby', 'java'].sort
|
92
|
+
|
93
|
+
assert_equal post.tags.pluck(:name).sort, ['rails', 'ruby', 'jruby', 'java'].sort
|
94
|
+
assert_equal post.tags.in_context(:ruby).pluck(:name).sort, ['rails', 'ruby'].sort
|
95
|
+
assert_equal post.tags.in_context(:java).pluck(:name).sort, ['jruby']
|
96
|
+
assert_equal post.tags.in_context(:ruby).by_tagger(user).pluck(:name).sort, ['rails', 'ruby'].sort
|
97
|
+
assert_equal post.tags.in_context(:java).by_tagger(user).pluck(:name).count, 0
|
98
|
+
assert_equal post.tags.by_tagger(user).pluck(:name).sort, ['rails', 'ruby', 'java'].sort
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe EasyTag do
|
103
|
+
before :each do
|
104
|
+
DatabaseCleaner.strategy = :transaction
|
105
|
+
DatabaseCleaner.start
|
106
|
+
end
|
107
|
+
|
108
|
+
after :each do
|
109
|
+
DatabaseCleaner.clean
|
110
|
+
end
|
111
|
+
|
112
|
+
describe 'taggable with_tags' do
|
113
|
+
it 'return match tags' do
|
114
|
+
post = Post.create(:name => 'post')
|
115
|
+
post.set_tags('rails, ruby')
|
116
|
+
java = Post.create(:name => 'java')
|
117
|
+
java.set_tags('java, jsp')
|
118
|
+
jruby = Post.create(:name => 'jruby')
|
119
|
+
jruby.set_tags('ruby, jruby')
|
120
|
+
comment = Comment.create(:name => 'comment')
|
121
|
+
comment.set_tags('rails, ruby')
|
122
|
+
|
123
|
+
Post.with_tags('ruby').count.must_equal(2)
|
124
|
+
match_array(Post.with_tags('ruby').pluck(:name), ['post', 'jruby'])
|
125
|
+
|
126
|
+
Post.with_tags('java, jruby').count.must_equal(2)
|
127
|
+
match_array(Post.with_tags('java, jruby').pluck(:name), ['java', 'jruby'])
|
128
|
+
|
129
|
+
Post.with_tags('rails, ruby').to_a.count.must_equal(2)
|
130
|
+
match_array(Post.with_tags('rails, ruby').pluck(:name), ['post', 'jruby'])
|
131
|
+
|
132
|
+
Post.with_tags('rails, ruby', {:match => :all}).to_a.count.must_equal(1)
|
133
|
+
match_array(Post.with_tags('rails, ruby', {:match => :all}).pluck(:name), ['post'])
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'return match tags in context and with tagger' do
|
137
|
+
user = User.create(:name => 'bob')
|
138
|
+
post = Post.create(:name => 'post')
|
139
|
+
post.set_tags('rails, ruby', :tagger => user)
|
140
|
+
skill = Post.create(:name => 'skill')
|
141
|
+
skill.set_tags('rails, ruby', :context => :skill)
|
142
|
+
java = Post.create(:name => 'java')
|
143
|
+
java.set_tags('java, jsp')
|
144
|
+
jruby = Post.create(:name => 'jruby')
|
145
|
+
jruby.set_tags('ruby, jruby', :context => :skill, :tagger => user)
|
146
|
+
comment = Comment.create(:name => 'comment')
|
147
|
+
comment.set_tags('rails, ruby')
|
148
|
+
|
149
|
+
match_array(Post.with_tags('rails').pluck(:name), ['post', 'skill'])
|
150
|
+
match_array(Post.with_tags('rails').in_context(:skill).pluck(:name), ['skill'])
|
151
|
+
match_array(Post.with_tags('rails').by_tagger(user).pluck(:name), ['post'])
|
152
|
+
match_array(Post.with_tags('ruby').by_tagger(user).pluck(:name), ['post', 'jruby'])
|
153
|
+
match_array(Post.with_tags('ruby').in_context(:skill).by_tagger(user).pluck(:name), ['jruby'])
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'remove all tags' do
|
158
|
+
post = Post.create(:name => 'post')
|
159
|
+
user = User.create(:name => 'bob')
|
160
|
+
|
161
|
+
post.set_tags('rails, ruby')
|
162
|
+
match_array(post.tags.pluck(:name), ['rails', 'ruby'])
|
163
|
+
|
164
|
+
post.set_tags(nil)
|
165
|
+
post.tags.count.must_equal(0)
|
166
|
+
|
167
|
+
post.set_tags('rails, ruby', :context => 'ruby', :tagger => user)
|
168
|
+
match_array(post.tags.pluck(:name), ['rails', 'ruby'])
|
169
|
+
|
170
|
+
post.set_tags(nil)
|
171
|
+
post.tags.count.must_equal(2)
|
172
|
+
post.set_tags(nil, :context => 'ruby', :tagger => user)
|
173
|
+
post.tags.count.must_equal(0)
|
174
|
+
end
|
175
|
+
|
176
|
+
describe 'Basic' do
|
177
|
+
it 'is taggable' do
|
178
|
+
post = Post.new(:name => 'post')
|
179
|
+
post.is_taggable?.must_equal(true)
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'is not taggable' do
|
183
|
+
user = User.new(:name => 'user')
|
184
|
+
user.is_taggable?.must_equal(false)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe String do
|
189
|
+
it 'turn string into tags' do
|
190
|
+
s = 'ruby, rails, tag'
|
191
|
+
match_array(s.to_tags, ['ruby', 'rails', 'tag'])
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'remove whitespaces' do
|
195
|
+
s = 'ruby , rails, tag '
|
196
|
+
match_array(s.to_tags, ['ruby', 'rails', 'tag'])
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'remove single quote' do
|
200
|
+
s = "'ruby' , 'rails', tag "
|
201
|
+
match_array(s.to_tags, ['ruby', 'rails', 'tag'])
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'remove mixed quote' do
|
205
|
+
s = "\"ruby\" , 'ruby on rails', tag "
|
206
|
+
match_array(s.to_tags, ['ruby', 'ruby on rails', 'tag'])
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'set delimiter' do
|
210
|
+
s = 'ruby; rails; tag'
|
211
|
+
match_array(s.to_tags(';'), ['ruby', 'rails', 'tag'])
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
def match_array(a, b)
|
4
|
+
a.sort.must_equal(b.sort)
|
5
|
+
end
|
6
|
+
|
7
|
+
describe EasyTag do
|
8
|
+
before :each do
|
9
|
+
DatabaseCleaner.strategy = :transaction
|
10
|
+
DatabaseCleaner.start
|
11
|
+
end
|
12
|
+
|
13
|
+
after :each do
|
14
|
+
DatabaseCleaner.clean
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'with context and with tagger' do
|
18
|
+
it 'in context' do
|
19
|
+
post = Post.create(:name => 'post')
|
20
|
+
user = User.create(:name => 'bob')
|
21
|
+
|
22
|
+
post.set_tags('rails, ruby, jruby', :context => 'ruby', :tagger => user)
|
23
|
+
post.set_tags('java, jruby', :context => 'java', :tagger => user)
|
24
|
+
|
25
|
+
match_array(user.tags.in_context('ruby').pluck(:name), ['rails', 'ruby', 'jruby'])
|
26
|
+
match_array(user.tags.in_context('java').pluck(:name), ['java', 'jruby'])
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'get uniq tags' do
|
30
|
+
user = User.create(:name => 'bob')
|
31
|
+
|
32
|
+
post = Post.create(:name => 'post')
|
33
|
+
post.set_tags('ruby', :tagger => user)
|
34
|
+
post.set_tags('ruby', :context => :skill, :tagger => user)
|
35
|
+
|
36
|
+
ruby = Post.create(:name => 'ruby')
|
37
|
+
ruby.set_tags('ruby', :context => :skill, :tagger => user)
|
38
|
+
|
39
|
+
user.tags.count.must_equal(1)
|
40
|
+
match_array(user.tags.pluck(:name), ['ruby'])
|
41
|
+
|
42
|
+
match_array(post.tags.pluck(:name), ['ruby'])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe EasyTag::Tagger do
|
47
|
+
it 'is tagger' do
|
48
|
+
user = User.new(:name => 'post')
|
49
|
+
user.is_tagger?.must_equal(true)
|
50
|
+
EasyTag::Tagger.class_variable_get(:@@tagger_class).must_equal(User)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'is not tagger' do
|
54
|
+
post = Post.new(:name => 'user')
|
55
|
+
post.is_tagger?.must_equal(false)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment", __FILE__)
|
5
|
+
require "rails/test_help"
|
6
|
+
require "minitest/rails"
|
7
|
+
|
8
|
+
Rails.backtrace_cleaner.remove_silencers!
|
9
|
+
|
10
|
+
# Load support files
|
11
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
12
|
+
|
13
|
+
# Load fixtures from the engine
|
14
|
+
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
15
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
16
|
+
end
|
17
|
+
|
18
|
+
# To add Capybara feature tests add `gem "minitest-rails-capybara"`
|
19
|
+
# to the test group in the Gemfile and uncomment the following:
|
20
|
+
# require "minitest/rails/capybara"
|
21
|
+
|
22
|
+
# Uncomment for awesome colorful output
|
23
|
+
# require "minitest/pride"
|
24
|
+
|
25
|
+
#class ActiveSupport::TestCase
|
26
|
+
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
27
|
+
# fixtures :all
|
28
|
+
|
29
|
+
# Add more helper methods to be used by all tests here...
|
30
|
+
#end
|
data.tar.gz.sig
ADDED
Binary file
|