tagalong 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +25 -0
- data/lib/tagalong/exceptions.rb +6 -0
- data/lib/tagalong/sunspot.rb +28 -0
- data/lib/tagalong/tagger.rb +27 -0
- data/lib/tagalong/version.rb +1 -1
- data/lib/tagalong.rb +1 -0
- data/spec/lib/tagalong/sunspot_spec.rb +45 -0
- data/spec/lib/tagalong/tagger_spec.rb +138 -13
- data/spec/spec_helper.rb +12 -41
- data/spec/support/setup_database.rb +46 -0
- data/tagalong.gemspec +3 -0
- metadata +49 -11
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -116,6 +116,18 @@ Takes a Taggable as a value. When passed, it will add **:has_been_tagged** to th
|
|
116
116
|
{ name: 'woot_tag', :has_been_tagged => true }
|
117
117
|
]
|
118
118
|
|
119
|
+
### Search Tagger tags
|
120
|
+
|
121
|
+
A Tagger's tags can be searched for using the `matching_tags` method and a given search phrase as follows:
|
122
|
+
|
123
|
+
@user.matching_tags("cats have")
|
124
|
+
# => [
|
125
|
+
{ name: 'cats have 9 lives', :number_of_references => 42 },
|
126
|
+
{ name: 'what do cats have', :number_of_references => 23 },
|
127
|
+
]
|
128
|
+
|
129
|
+
The above returns an array of hashes representing tags ordered in descending order of their number of references. **Note:** This function by default simply uses the ActiveRecord backend to search for matching tags. However, this method switches to using Sunspot to handle the searching if Sunspot has been enabled for this plugin. For more information please see the **Sunspot** section below.
|
130
|
+
|
119
131
|
### List Taggable tags
|
120
132
|
|
121
133
|
To list Taggable tags, call the `tags` method on a Taggable object. This will return an array of all tags that Taggable is currently tagged with in ascending alphabetical order.
|
@@ -152,12 +164,25 @@ To create a tag on the Tagger object without applying the tag to a Taggable, cal
|
|
152
164
|
|
153
165
|
@user.create_tag("sometag")
|
154
166
|
|
167
|
+
##### Renaming
|
168
|
+
|
169
|
+
To rename a tag that exists on a Tagger object, simply call the `rename_tag` method with the existing tag and new desired name. If the name is already in use, it will raise an ActiveRecord::RecordInvalid error.
|
170
|
+
|
171
|
+
@user.rename_tag("sometag", "another_tag_name")
|
172
|
+
|
155
173
|
##### Deleting
|
156
174
|
|
157
175
|
To delete a tag, call the `delete_tag` method on a Tagger object and hand it the label of the tag you want to delete. This will remove the tag from the Tagger, as well as all Taggables that might be using it.
|
158
176
|
|
159
177
|
@user.delete_tag("sometag")
|
160
178
|
|
179
|
+
### Sunspot
|
180
|
+
|
181
|
+
Tagalong currently supports Sunspot for searching tags. In order to use Sunspot for searching tags a few things need to happen in the client Rails application.
|
182
|
+
|
183
|
+
1. Add Sunspot to your Rails app as you normally would
|
184
|
+
2. Create a Rails initializer file called `tagalong.rb` that contains `Tagalong.enable_sunspot`.
|
185
|
+
|
161
186
|
## Credits
|
162
187
|
|
163
188
|
I just wanted to thank all of the other open source Rails tagging plugins out there. Especially, [acts-as-taggable-on](http://github.com/mbleigh/acts-as-taggable-on), [is_taggable](http://github.com/jamesgolick/is_taggable), and [rocket_tag](http://github.com/bradphelan/rocket_tag). I learned a lot from you all.
|
data/lib/tagalong/exceptions.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
begin
|
2
|
+
require 'sunspot'
|
3
|
+
require 'sunspot/rails'
|
4
|
+
rescue LoadError
|
5
|
+
puts "sunspot would allow you to search tags faster, please 'gem install sunspot'"
|
6
|
+
end
|
7
|
+
|
8
|
+
module Tagalong
|
9
|
+
def self.enable_sunspot
|
10
|
+
Sunspot::Adapters::InstanceAdapter.register(Sunspot::Rails::Adapters::ActiveRecordInstanceAdapter, ActiveRecord::Base)
|
11
|
+
Sunspot::Adapters::DataAccessor.register(Sunspot::Rails::Adapters::ActiveRecordDataAccessor, ActiveRecord::Base)
|
12
|
+
ActiveRecord::Base.module_eval { include(Sunspot::Rails::Searchable) }
|
13
|
+
Tagalong::TagalongTag.searchable do
|
14
|
+
integer :tagger_id
|
15
|
+
integer :number_of_references
|
16
|
+
string :tagger_type
|
17
|
+
text :name
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.sunspot_enabled?
|
22
|
+
Tagalong::TagalongTag.searchable? ? true : false
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.reindex_sunspot
|
26
|
+
Tagalong::TagalongTag.reindex
|
27
|
+
end
|
28
|
+
end
|
data/lib/tagalong/tagger.rb
CHANGED
@@ -21,9 +21,21 @@ module Tagalong
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def create_tag(tag_name)
|
24
|
+
raise Tagalong::TagAlreadyInUse, "A tag already exists with the name '#{tag_name}'" if tagalong_tags.find_by_name(tag_name).present?
|
25
|
+
raise Tagalong::TagCannotBeBlank, "A tag cannot have a blank name" if tag_name.blank?
|
24
26
|
TagalongTag.create!(:tagger_id => self.id, :tagger_type => self.class.to_s, :name => tag_name)
|
25
27
|
end
|
26
28
|
|
29
|
+
def rename_tag(existing_tag, rename_to)
|
30
|
+
if tag = tagalong_tags.find_by_name(existing_tag)
|
31
|
+
tag.name = rename_to
|
32
|
+
raise Tagalong::TagAlreadyInUse, "A tag already exists with the name '#{tag.name}'" unless tag.valid?
|
33
|
+
tag.save!
|
34
|
+
else
|
35
|
+
raise Tagalong::TagNotFound, "Tried to rename a tag that does not exist."
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
27
39
|
def untag(taggable_obj, tag_name)
|
28
40
|
raise Tagalong::TaggableNotPersisted, "Taggable must be persisted to untag it." if !taggable_obj.persisted?
|
29
41
|
tag_manager = Tagalong::TagManager.new(taggable_obj, self)
|
@@ -69,6 +81,21 @@ module Tagalong
|
|
69
81
|
return out
|
70
82
|
end
|
71
83
|
|
84
|
+
def tags_matching(search_phrase)
|
85
|
+
if Tagalong.sunspot_enabled?
|
86
|
+
tmp_tagger_type = self.class.to_s # this is needed because self.class apparently changes inside the Sunspot.search scope.
|
87
|
+
tag_search = Sunspot.search(Tagalong::TagalongTag) do
|
88
|
+
fulltext "\"#{search_phrase}\""
|
89
|
+
with :tagger_id, self.id
|
90
|
+
with :tagger_type, tmp_tagger_type
|
91
|
+
order_by(:number_of_references, :desc)
|
92
|
+
end
|
93
|
+
tag_search.results.map { |r| { :name => r.name, :number_of_references => r.number_of_references } }
|
94
|
+
else
|
95
|
+
self.tagalong_tags.order("number_of_references DESC").where("name like ?", ["%#{search_phrase}%"]).map { |r| { :name => r.name } }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
72
99
|
def taggables_with(name)
|
73
100
|
self.tagalong_tags.where(:name => name).each do |t|
|
74
101
|
return t.taggables
|
data/lib/tagalong/version.rb
CHANGED
data/lib/tagalong.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Tagalong Sunspot Support" do
|
4
|
+
describe "#enable_sunspot" do
|
5
|
+
it "registers ActiveRecord instance adapter" do
|
6
|
+
Sunspot::Adapters::DataAccessor.stub(:register)
|
7
|
+
Sunspot.stub(:setup)
|
8
|
+
Sunspot::Adapters::InstanceAdapter.should_receive(:register).with(Sunspot::Rails::Adapters::ActiveRecordInstanceAdapter, ActiveRecord::Base)
|
9
|
+
Tagalong.enable_sunspot
|
10
|
+
end
|
11
|
+
|
12
|
+
it "registers ActiveRecord data adapter" do
|
13
|
+
Sunspot::Adapters::InstanceAdapter.stub(:register)
|
14
|
+
Sunspot.stub(:setup)
|
15
|
+
Sunspot::Adapters::DataAccessor.should_receive(:register).with(Sunspot::Rails::Adapters::ActiveRecordDataAccessor, ActiveRecord::Base)
|
16
|
+
Tagalong.enable_sunspot
|
17
|
+
end
|
18
|
+
|
19
|
+
it "sets up indexing of the Tagalong::TagalongTag by sunspot" do
|
20
|
+
Sunspot::Adapters::InstanceAdapter.stub(:register)
|
21
|
+
Sunspot::Adapters::DataAccessor.stub(:register)
|
22
|
+
Sunspot.should_receive(:setup).with(Tagalong::TagalongTag)
|
23
|
+
Tagalong.enable_sunspot
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#sunspot_enabled" do
|
28
|
+
it "return false if #enable_sunspot has NOT previously been called" do
|
29
|
+
Tagalong::TagalongTag.stub(:searchable?).and_return(false)
|
30
|
+
Tagalong.sunspot_enabled?.should be_false
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns true if #enable_sunspot has previously been called" do
|
34
|
+
Tagalong.enable_sunspot
|
35
|
+
Tagalong.sunspot_enabled?.should be_true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#reindex_sunspot" do
|
40
|
+
it "reindexes the Sunspot solr index for the supported models" do
|
41
|
+
Tagalong::TagalongTag.should_receive(:reindex)
|
42
|
+
Tagalong.reindex_sunspot
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -5,8 +5,8 @@ require 'spec_helper'
|
|
5
5
|
|
6
6
|
describe "Tagger" do
|
7
7
|
before(:each) do
|
8
|
-
@user = User.create!(:name => "
|
9
|
-
@contact = Contact.create!(:name => "
|
8
|
+
@user = User.create!(:name => "Tagger")
|
9
|
+
@contact = Contact.create!(:name => "Taggable")
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "Integration" do
|
@@ -20,13 +20,61 @@ describe "Tagger" do
|
|
20
20
|
describe "#create_tag" do
|
21
21
|
it "creates a new unassigned tag on the tagger" do
|
22
22
|
@user.create_tag('tag4')
|
23
|
-
@user.
|
23
|
+
@user.tagalong_tags.map { |t| t.name }.should include('tag4')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should not create the tag if the name is already in use" do
|
27
|
+
@user.create_tag('tag4')
|
28
|
+
lambda { @user.create_tag('tag4') }.should raise_error(Tagalong::TagAlreadyInUse)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should raise a cannot be blank error if the name is blank" do
|
32
|
+
lambda { @user.create_tag('') }.should raise_error(Tagalong::TagCannotBeBlank)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#rename_tag" do
|
37
|
+
context "when the tagger owns the tag being renamed" do
|
38
|
+
before(:each) do
|
39
|
+
@user.tagalong_tags.create!(:name => 'tag5')
|
40
|
+
end
|
41
|
+
|
42
|
+
it "changes the name of a tag" do
|
43
|
+
@user.rename_tag('tag5', 'renamedTag5')
|
44
|
+
@user.tagalong_tags.map { |t| t.name }.should == ['renamedTag5']
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should not change the name of the tag if the name is already in use" do
|
48
|
+
@user.tagalong_tags.create!(:name => 'renamedTag5')
|
49
|
+
lambda { @user.rename_tag('tag5', 'renamedTag5') }.should raise_error(Tagalong::TagAlreadyInUse)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should return true if rename was successfull" do
|
53
|
+
@user.rename_tag('tag5', 'renamedTag5').should be_true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when the tagger does not own the tag being renamed" do
|
58
|
+
it "should raise a tag not found error" do
|
59
|
+
lambda { @user.rename_tag('tagDoesntExist', 'renamedTag6') }.should raise_error(Tagalong::TagNotFound)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should not let you update another taggers tag" do
|
63
|
+
@user2 = User.create!(:name => "Tagger 2")
|
64
|
+
@contact2 = Contact.create!(:name => "Taggable 2")
|
65
|
+
@contact2.tagalong_tags.create!(:name => "tag20", :tagger => @user2)
|
66
|
+
lambda { @user.rename_tag('tag20', 'renamedTag20') }.should raise_error(Tagalong::TagNotFound)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should return raise an exception if the tag doesnt exist" do
|
71
|
+
lambda { @user.rename_tag('tagThatDoesntExist', 'something') }.should raise_error(Tagalong::TagNotFound)
|
24
72
|
end
|
25
73
|
end
|
26
74
|
|
27
75
|
describe "#untag" do
|
28
76
|
it "untags the tag from the given taggable object for the tagger" do
|
29
|
-
@contact.tagalong_tags.create!(:name => "bar", :
|
77
|
+
@contact.tagalong_tags.create!(:name => "bar", :tagger => @user)
|
30
78
|
@user.untag(@contact, "bar")
|
31
79
|
@contact.tagalong_tags.map { |r| r.name }.should_not include("bar")
|
32
80
|
end
|
@@ -34,12 +82,12 @@ describe "Tagger" do
|
|
34
82
|
|
35
83
|
describe "#delete_tag" do
|
36
84
|
before(:each) do
|
37
|
-
@
|
85
|
+
@contact.tagalong_tags.create!(:name => "tag1", :tagger => @user)
|
38
86
|
end
|
39
87
|
|
40
88
|
it "should disassociate the tag that belongs to it" do
|
41
89
|
@user.delete_tag('tag1')
|
42
|
-
@user.
|
90
|
+
@user.tagalong_tags.should_not include("tag1")
|
43
91
|
end
|
44
92
|
|
45
93
|
it "should destroy the tag record from the db" do
|
@@ -57,14 +105,14 @@ describe "Tagger" do
|
|
57
105
|
describe "#has_tag?" do
|
58
106
|
context "the tagger has the tag" do
|
59
107
|
before(:each) do
|
60
|
-
@user.
|
108
|
+
@user.tagalong_tags.create!(:name => 'tag5')
|
61
109
|
end
|
62
110
|
|
63
|
-
it {@user.has_tag?('tag5').should be_true}
|
111
|
+
it { @user.has_tag?('tag5').should be_true }
|
64
112
|
end
|
65
113
|
|
66
114
|
context "the tagger does not have the tag" do
|
67
|
-
it {@user.has_tag?('tag99').should be_false}
|
115
|
+
it { @user.has_tag?('tag99').should be_false }
|
68
116
|
end
|
69
117
|
end
|
70
118
|
|
@@ -88,8 +136,8 @@ describe "Tagger" do
|
|
88
136
|
|
89
137
|
describe "#tags_including" do
|
90
138
|
before(:each) do
|
91
|
-
@
|
92
|
-
@
|
139
|
+
@contact.tagalong_tags.create!(:name => "tag1", :number_of_references => 1, :tagger => @user)
|
140
|
+
@contact.tagalong_tags.create!(:name => "tag2", :number_of_references => 1, :tagger => @user)
|
93
141
|
end
|
94
142
|
|
95
143
|
context "without options passed" do
|
@@ -113,7 +161,7 @@ describe "Tagger" do
|
|
113
161
|
context "with a valid taggable passed as has_been_tagged" do
|
114
162
|
it "should return an array of hashes with name and has_been_tagged" do
|
115
163
|
@contact2 = Contact.create!(:name => "My Taggable 2")
|
116
|
-
@
|
164
|
+
@contact2.tagalong_tags.create!(:name => "tag3", :tagger => @user)
|
117
165
|
@user.tags_including(:has_been_tagged => @contact).should == [
|
118
166
|
{:name => 'tag1', :has_been_tagged => true},
|
119
167
|
{:name => 'tag2', :has_been_tagged => true},
|
@@ -123,9 +171,50 @@ describe "Tagger" do
|
|
123
171
|
end
|
124
172
|
end
|
125
173
|
|
174
|
+
describe "#tags_matching" do
|
175
|
+
context "have not enabled sunspot" do
|
176
|
+
before(:each) do
|
177
|
+
Tagalong.stub(:sunspot_enabled?).and_return(false)
|
178
|
+
end
|
179
|
+
|
180
|
+
it "returns an array of hashes representing tags that match the given search phrase ordered by number of references descending" do
|
181
|
+
@user.tagalong_tags.create!(:name => "foo bar kitty", :number_of_references => 1)
|
182
|
+
@user.tagalong_tags.create!(:name => "bar foo house", :number_of_references => 3)
|
183
|
+
@user.tagalong_tags.create!(:name => "hello foo bar town", :number_of_references => 2)
|
184
|
+
@user.tags_matching("foo bar").should == [
|
185
|
+
{ :name => 'hello foo bar town' },
|
186
|
+
{ :name => 'foo bar kitty' }
|
187
|
+
]
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
context "have enabled sunspot", :search => true do
|
192
|
+
before(:each) do
|
193
|
+
Tagalong.enable_sunspot
|
194
|
+
Tagalong.stub(:sunspot_enabled?).and_return(true)
|
195
|
+
end
|
196
|
+
|
197
|
+
it "returns an array of hashes representing tags that match the given search phrase ordered by number of references descending" do
|
198
|
+
@user.tagalong_tags.create!(:name => "foo bar kitty", :number_of_references => 1)
|
199
|
+
@user.tagalong_tags.create!(:name => "bar foo house", :number_of_references => 3)
|
200
|
+
@user.tagalong_tags.create!(:name => "hello foo bar town", :number_of_references => 2)
|
201
|
+
|
202
|
+
# Sunspot.remove_all(Tagalong::TagalongTag)
|
203
|
+
# Sunspot.index!(Tagalong::TagalongTag.all)
|
204
|
+
# Sunspot.commit
|
205
|
+
Tagalong::TagalongTag.reindex
|
206
|
+
|
207
|
+
@user.tags_matching("foo bar").should == [
|
208
|
+
{ :name => 'hello foo bar town', :number_of_references => 2 },
|
209
|
+
{ :name => 'foo bar kitty', :number_of_references => 1 }
|
210
|
+
]
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
126
215
|
describe "#taggables_with" do
|
127
216
|
it "returns a collection of the taggables tagged with the given tag" do
|
128
|
-
@
|
217
|
+
@contact.tagalong_tags.create!(:name => "jackson", :tagger => @user)
|
129
218
|
@user.taggables_with("jackson").should == [@contact]
|
130
219
|
end
|
131
220
|
|
@@ -163,6 +252,42 @@ describe "Tagger" do
|
|
163
252
|
end
|
164
253
|
end
|
165
254
|
|
255
|
+
describe "#rename_tag" do
|
256
|
+
it "should find the tag by its name" do
|
257
|
+
tag = stub('tag', :name => 'tag7')
|
258
|
+
Tagalong::TagalongTag.should_receive(:find_by_name).with('tag7').and_return(tag)
|
259
|
+
tag.stub(:name=)
|
260
|
+
tag.stub(:save!)
|
261
|
+
tag.stub(:valid?).and_return(true)
|
262
|
+
@user.rename_tag('tag7', 'renamedTag7')
|
263
|
+
end
|
264
|
+
|
265
|
+
it "should not save the tag if the Tagger doesn't own it" do
|
266
|
+
Tagalong::TagalongTag.stub(:find_by_name).and_return(false)
|
267
|
+
lambda { @user.rename_tag('tag7', 'renamedTag7') }.should raise_error(Tagalong::TagNotFound)
|
268
|
+
end
|
269
|
+
|
270
|
+
it "should assign and save the new tag name" do
|
271
|
+
tag8 = mock('tag 8', :name => 'tag8')
|
272
|
+
Tagalong::TagalongTag.stub(:find_by_name).and_return(tag8)
|
273
|
+
@user.stub(:has_tag?).and_return(true)
|
274
|
+
tag8.should_receive(:name=).with('renamedTag8')
|
275
|
+
tag8.stub(:valid?).and_return(true)
|
276
|
+
tag8.stub(:save!)
|
277
|
+
@user.rename_tag('tag8', 'renamedTag8')
|
278
|
+
end
|
279
|
+
|
280
|
+
it "should save the tag if the Tagger owns it" do
|
281
|
+
tag9 = mock('tag 9', :name => 'tag9')
|
282
|
+
Tagalong::TagalongTag.stub(:find_by_name).and_return(tag9)
|
283
|
+
@user.stub(:has_tag?).and_return(true)
|
284
|
+
tag9.stub(:name=)
|
285
|
+
tag9.stub(:valid?).and_return(true)
|
286
|
+
tag9.should_receive(:save!)
|
287
|
+
@user.rename_tag('tag9', 'renamedTag9')
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
166
291
|
describe "#has_tag?" do
|
167
292
|
it "should try the list of tags for the tagger" do
|
168
293
|
tags = mock('tags')
|
data/spec/spec_helper.rb
CHANGED
@@ -1,53 +1,24 @@
|
|
1
|
-
require 'logger'
|
2
|
-
|
3
1
|
require 'rubygems'
|
4
2
|
require 'bundler/setup'
|
5
3
|
|
6
4
|
require File.expand_path('../../lib/tagalong', __FILE__)
|
7
5
|
|
8
|
-
|
9
|
-
|
6
|
+
require File.expand_path('spec/support/setup_database')
|
7
|
+
|
8
|
+
require 'sunspot_test/rspec'
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
config = ActiveRecord::Base.configurations[db_name]
|
16
|
-
|
17
|
-
begin
|
18
|
-
ActiveRecord::Base.establish_connection(db_name)
|
19
|
-
ActiveRecord::Base.connection
|
20
|
-
rescue
|
21
|
-
case db_name
|
22
|
-
when /mysql/
|
23
|
-
ActiveRecord::Base.establish_connection(config.merge('database' => nil))
|
24
|
-
ActiveRecord::Base.connection.create_database(config['database'], {:charset => 'utf8', :collation => 'utf8_unicode_ci'})
|
25
|
-
when 'postgresql'
|
26
|
-
ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
|
27
|
-
ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => 'utf8'))
|
10
|
+
module SunspotTest
|
11
|
+
class << self
|
12
|
+
def server
|
13
|
+
@server ||= Sunspot::Solr::Server.new
|
28
14
|
end
|
29
|
-
|
30
|
-
ActiveRecord::Base.establish_connection(config)
|
31
|
-
end
|
32
|
-
|
33
|
-
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
|
34
|
-
ActiveRecord::Base.default_timezone = :utc
|
35
|
-
|
36
|
-
ActiveRecord::Base.silence do
|
37
|
-
ActiveRecord::Migration.verbose = false
|
38
|
-
|
39
|
-
load(File.dirname(__FILE__) + '/schema.rb')
|
40
|
-
load(File.dirname(__FILE__) + '/models.rb')
|
41
15
|
end
|
42
|
-
else
|
43
|
-
raise "Please create #{database_yml} first to configure your database. Take a look at: #{database_yml}.sample"
|
44
16
|
end
|
45
17
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
18
|
+
SunspotTest.solr_startup_timeout = 60
|
19
|
+
|
20
|
+
RSpec.configure do |c|
|
21
|
+
c.before(:each) do
|
22
|
+
clean_database!
|
50
23
|
end
|
51
24
|
end
|
52
|
-
|
53
|
-
clean_database!
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
db_name = ENV['DB'] || 'sqlite3'
|
4
|
+
database_yml = File.expand_path('../../database.yml', __FILE__)
|
5
|
+
|
6
|
+
if File.exists?(database_yml)
|
7
|
+
active_record_configuration = YAML.load_file(database_yml)
|
8
|
+
|
9
|
+
ActiveRecord::Base.configurations = active_record_configuration
|
10
|
+
config = ActiveRecord::Base.configurations[db_name]
|
11
|
+
|
12
|
+
begin
|
13
|
+
ActiveRecord::Base.establish_connection(db_name)
|
14
|
+
ActiveRecord::Base.connection
|
15
|
+
rescue
|
16
|
+
case db_name
|
17
|
+
when /mysql/
|
18
|
+
ActiveRecord::Base.establish_connection(config.merge('database' => nil))
|
19
|
+
ActiveRecord::Base.connection.create_database(config['database'], {:charset => 'utf8', :collation => 'utf8_unicode_ci'})
|
20
|
+
when 'postgresql'
|
21
|
+
ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
|
22
|
+
ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => 'utf8'))
|
23
|
+
end
|
24
|
+
|
25
|
+
ActiveRecord::Base.establish_connection(config)
|
26
|
+
end
|
27
|
+
|
28
|
+
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "/../debug.log"))
|
29
|
+
ActiveRecord::Base.default_timezone = :utc
|
30
|
+
|
31
|
+
ActiveRecord::Base.silence do
|
32
|
+
ActiveRecord::Migration.verbose = false
|
33
|
+
|
34
|
+
load(File.dirname(__FILE__) + '/../schema.rb')
|
35
|
+
load(File.dirname(__FILE__) + '/../models.rb')
|
36
|
+
end
|
37
|
+
else
|
38
|
+
raise "Please create #{database_yml} first to configure your database. Take a look at: #{database_yml}.sample"
|
39
|
+
end
|
40
|
+
|
41
|
+
def clean_database!
|
42
|
+
models = [Tagalong::TagalongTag, Tagalong::TagalongTagging]
|
43
|
+
models.each do |model|
|
44
|
+
ActiveRecord::Base.connection.execute "DELETE FROM #{model.table_name}"
|
45
|
+
end
|
46
|
+
end
|
data/tagalong.gemspec
CHANGED
@@ -19,4 +19,7 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.add_development_dependency "sqlite3"
|
20
20
|
gem.add_development_dependency "rspec"
|
21
21
|
gem.add_development_dependency "rake"
|
22
|
+
gem.add_development_dependency "sunspot_rails"
|
23
|
+
gem.add_development_dependency "sunspot_solr"
|
24
|
+
gem.add_development_dependency "sunspot_test"
|
22
25
|
end
|
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.0
|
4
|
+
version: 0.1.0
|
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-05-
|
13
|
+
date: 2012-05-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
17
|
-
requirement: &
|
17
|
+
requirement: &70166046334400 !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: *70166046334400
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: sqlite3
|
28
|
-
requirement: &
|
28
|
+
requirement: &70166046333780 !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: *70166046333780
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &70166046333320 !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: *70166046333320
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rake
|
50
|
-
requirement: &
|
50
|
+
requirement: &70166046332840 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,7 +55,40 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70166046332840
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: sunspot_rails
|
61
|
+
requirement: &70166046332400 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *70166046332400
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: sunspot_solr
|
72
|
+
requirement: &70166046331960 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *70166046331960
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: sunspot_test
|
83
|
+
requirement: &70166046331440 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: *70166046331440
|
59
92
|
description: A Rails tagging plugin that makes sense.
|
60
93
|
email:
|
61
94
|
- cyphactor@gmail.com
|
@@ -75,6 +108,7 @@ files:
|
|
75
108
|
- lib/generators/tagalong/migration/templates/active_record/migration.rb
|
76
109
|
- lib/tagalong.rb
|
77
110
|
- lib/tagalong/exceptions.rb
|
111
|
+
- lib/tagalong/sunspot.rb
|
78
112
|
- lib/tagalong/tag_manager.rb
|
79
113
|
- lib/tagalong/tagalong_tag.rb
|
80
114
|
- lib/tagalong/tagalong_tagging.rb
|
@@ -83,12 +117,14 @@ files:
|
|
83
117
|
- lib/tagalong/version.rb
|
84
118
|
- spec/database.yml
|
85
119
|
- spec/integration/tag_manager_integration_spec.rb
|
120
|
+
- spec/lib/tagalong/sunspot_spec.rb
|
86
121
|
- spec/lib/tagalong/tag_manager_spec.rb
|
87
122
|
- spec/lib/tagalong/taggable_spec.rb
|
88
123
|
- spec/lib/tagalong/tagger_spec.rb
|
89
124
|
- spec/models.rb
|
90
125
|
- spec/schema.rb
|
91
126
|
- spec/spec_helper.rb
|
127
|
+
- spec/support/setup_database.rb
|
92
128
|
- tagalong.gemspec
|
93
129
|
homepage: http://github.com/cyphactor/tagalong
|
94
130
|
licenses: []
|
@@ -110,16 +146,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
146
|
version: '0'
|
111
147
|
requirements: []
|
112
148
|
rubyforge_project:
|
113
|
-
rubygems_version: 1.8.
|
149
|
+
rubygems_version: 1.8.16
|
114
150
|
signing_key:
|
115
151
|
specification_version: 3
|
116
152
|
summary: A Rails tagging plugin that makes sense.
|
117
153
|
test_files:
|
118
154
|
- spec/database.yml
|
119
155
|
- spec/integration/tag_manager_integration_spec.rb
|
156
|
+
- spec/lib/tagalong/sunspot_spec.rb
|
120
157
|
- spec/lib/tagalong/tag_manager_spec.rb
|
121
158
|
- spec/lib/tagalong/taggable_spec.rb
|
122
159
|
- spec/lib/tagalong/tagger_spec.rb
|
123
160
|
- spec/models.rb
|
124
161
|
- spec/schema.rb
|
125
162
|
- spec/spec_helper.rb
|
163
|
+
- spec/support/setup_database.rb
|