tagalong 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tagalong/tagger.rb +7 -2
- data/lib/tagalong/version.rb +1 -1
- data/spec/lib/tagalong/tagger_spec.rb +21 -3
- metadata +16 -16
data/lib/tagalong/tagger.rb
CHANGED
@@ -81,7 +81,7 @@ module Tagalong
|
|
81
81
|
return out
|
82
82
|
end
|
83
83
|
|
84
|
-
def tags_matching(search_phrase)
|
84
|
+
def tags_matching(search_phrase, limit = nil)
|
85
85
|
if Tagalong.sunspot_enabled?
|
86
86
|
tmp_tagger_type = self.class.to_s # this is needed because self.class apparently changes inside the Sunspot.search scope.
|
87
87
|
tag_search = Sunspot.search(Tagalong::TagalongTag) do
|
@@ -89,10 +89,15 @@ module Tagalong
|
|
89
89
|
with :tagger_id, self.id
|
90
90
|
with :tagger_type, tmp_tagger_type
|
91
91
|
order_by(:number_of_references, :desc)
|
92
|
+
paginate(:page => 1, :per_page => limit) if limit
|
92
93
|
end
|
93
94
|
tag_search.results.map { |r| { :name => r.name, :number_of_references => r.number_of_references } }
|
94
95
|
else
|
95
|
-
|
96
|
+
if limit
|
97
|
+
self.tagalong_tags.order("number_of_references DESC").where("name like ?", ["%#{search_phrase}%"]).limit(limit).map { |r| { :name => r.name } }
|
98
|
+
else
|
99
|
+
self.tagalong_tags.order("number_of_references DESC").where("name like ?", ["%#{search_phrase}%"]).map { |r| { :name => r.name } }
|
100
|
+
end
|
96
101
|
end
|
97
102
|
end
|
98
103
|
|
data/lib/tagalong/version.rb
CHANGED
@@ -190,6 +190,15 @@ describe "Tagger" do
|
|
190
190
|
{ :name => 'foo bar kitty' }
|
191
191
|
]
|
192
192
|
end
|
193
|
+
|
194
|
+
it "returns a limited number of hashes based on the limit you specified as the secondary command argument" do
|
195
|
+
@user.tagalong_tags.create!(:name => "foo bar kitty", :number_of_references => 1)
|
196
|
+
@user.tagalong_tags.create!(:name => "bar foo house", :number_of_references => 3)
|
197
|
+
@user.tagalong_tags.create!(:name => "hello foo bar town", :number_of_references => 2)
|
198
|
+
@user.tags_matching("foo bar", 1).should == [
|
199
|
+
{ :name => 'hello foo bar town' }
|
200
|
+
]
|
201
|
+
end
|
193
202
|
end
|
194
203
|
|
195
204
|
context "have enabled sunspot", :search => true do
|
@@ -203,9 +212,6 @@ describe "Tagger" do
|
|
203
212
|
@user.tagalong_tags.create!(:name => "bar foo house", :number_of_references => 3)
|
204
213
|
@user.tagalong_tags.create!(:name => "hello foo bar town", :number_of_references => 2)
|
205
214
|
|
206
|
-
# Sunspot.remove_all(Tagalong::TagalongTag)
|
207
|
-
# Sunspot.index!(Tagalong::TagalongTag.all)
|
208
|
-
# Sunspot.commit
|
209
215
|
Tagalong::TagalongTag.reindex
|
210
216
|
|
211
217
|
@user.tags_matching("foo bar").should == [
|
@@ -213,6 +219,18 @@ describe "Tagger" do
|
|
213
219
|
{ :name => 'foo bar kitty', :number_of_references => 1 }
|
214
220
|
]
|
215
221
|
end
|
222
|
+
|
223
|
+
it "returns a limited number of hashes based on the limit specified as the secondary arguement" do
|
224
|
+
@user.tagalong_tags.create!(:name => "foo bar kitty", :number_of_references => 1)
|
225
|
+
@user.tagalong_tags.create!(:name => "bar foo house", :number_of_references => 3)
|
226
|
+
@user.tagalong_tags.create!(:name => "hello foo bar town", :number_of_references => 2)
|
227
|
+
|
228
|
+
Tagalong::TagalongTag.reindex
|
229
|
+
|
230
|
+
@user.tags_matching("foo bar", 1).should == [
|
231
|
+
{ :name => 'hello foo bar town', :number_of_references => 2 }
|
232
|
+
]
|
233
|
+
end
|
216
234
|
end
|
217
235
|
end
|
218
236
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tagalong
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-06-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
17
|
-
requirement: &
|
17
|
+
requirement: &70320501910940 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70320501910940
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: sqlite3
|
28
|
-
requirement: &
|
28
|
+
requirement: &70320501910280 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70320501910280
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &70320501909840 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70320501909840
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rake
|
50
|
-
requirement: &
|
50
|
+
requirement: &70320501909340 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70320501909340
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: sunspot_rails
|
61
|
-
requirement: &
|
61
|
+
requirement: &70320501908900 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70320501908900
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: sunspot_solr
|
72
|
-
requirement: &
|
72
|
+
requirement: &70320501908460 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *70320501908460
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: sunspot_test
|
83
|
-
requirement: &
|
83
|
+
requirement: &70320501907940 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ! '>='
|
@@ -88,7 +88,7 @@ dependencies:
|
|
88
88
|
version: '0'
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *70320501907940
|
92
92
|
description: A Rails tagging plugin that makes sense.
|
93
93
|
email:
|
94
94
|
- cyphactor@gmail.com
|