has_tags 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d073cf765ae66a310cbe1d9a2e8d26e965479374
4
- data.tar.gz: 51c2a060063fb1f153796cc86b95f252390adeec
3
+ metadata.gz: aa564f912468812fe9593203b9e5c699726b42b7
4
+ data.tar.gz: d9678862c27bbc193e174562c31de35959c83a83
5
5
  SHA512:
6
- metadata.gz: 176ad7c46525c301cc366d8ad8a0132bebfeb4799d152e7263eca976813e600e301c7e6ae2531599ad4aaa5d8de00c708ad1fe6c62c7ef872d2e6a6045291bf5
7
- data.tar.gz: 704a4b62b72c1ca65da8e73659a0c49c2e1f31ca2e4803edf51b0a5e975e919002213662bc0d2720f03fcf483d4e869e19374cc653e07e4095d6a253ed713653
6
+ metadata.gz: bb406ba5cda841342fa0761cb8e7ba04476dcbc6e3720d42b47ba75be8eb47efa09b515931cc441be044645d8c4ad7496084853d0bf5359b8e0c33a0b755f83d
7
+ data.tar.gz: 7ea802c4e3a5f0d27909dc47e2f9cd20ee301dc54b8aaf9b880951f0c0dcb49eaa30bd091399712fe89f6ea6a6f6a119180c5af890057997d34fcdca3df56441
@@ -16,6 +16,8 @@ module HasTags
16
16
  # end
17
17
 
18
18
  def has_tags
19
+ after_save :save_taggings
20
+
19
21
  has_many :taggings, as: :taggable, class_name: "HasTags::Tagging"
20
22
  has_many :tags, through: :taggings, class_name: "HasTags::Tag"
21
23
 
@@ -23,6 +25,14 @@ module HasTags
23
25
  end
24
26
 
25
27
  module InstanceMethods
28
+ def save_taggings
29
+ taggings = HasTags::Tagging.where(taggable_type: self.class.to_s, taggable_id: nil)
30
+ taggings.each do |tagging|
31
+ tagging.taggable_id = self.id
32
+ tagging.save
33
+ end
34
+ end
35
+
26
36
  def tag_list
27
37
  tags.map(&:name).join(", ")
28
38
  end
@@ -35,8 +45,8 @@ module HasTags
35
45
  tag = HasTags::Tag.where(name: name).first_or_create!
36
46
  else
37
47
  tag = HasTags::Tag.where(name: name, context_id: Tag.find_by(name: names[index-1]).id).first_or_create!
38
- end
39
- HasTags::Tagging.where(tag_id: tag.id, taggable: self).first_or_create!
48
+ end
49
+ HasTags::Tagging.where(tag_id: tag.id, taggable_type: self.class.to_s).first_or_create!
40
50
  end
41
51
  end
42
52
  end
@@ -1,3 +1,3 @@
1
1
  module HasTags
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,37 +1,45 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe TaggableModel do
4
- let (:model) { TaggableModel.create(name: "post") }
4
+ #let (:model) { TaggableModel.new(name: "post") }
5
5
 
6
6
  it { should have_many(:taggings) }
7
7
  it { should have_many(:tags) }
8
8
 
9
9
  context "setting tag list" do
10
10
  it "should be able to use two separate tags" do
11
+ model = TaggableModel.new(name: "post")
11
12
  tag_names = "Sports, Food"
12
13
  model.tag_list = tag_names
14
+ model.save
13
15
 
14
16
  expect(model.tags.count).to eq(2)
15
17
  end
16
18
 
17
19
  it "should create a context tag with colon" do
20
+ model = TaggableModel.new(name: "post")
18
21
  tag_names = "Sports:Lacrosse"
19
22
  model.tag_list = tag_names
23
+ model.save
20
24
 
21
25
  expect(HasTags::Tag.last.context.name).to eq("Sports")
22
26
  end
23
-
27
+
24
28
  it "should support multiple nested contexts" do
29
+ model = TaggableModel.new(name: "post")
25
30
  tag_names = "Sports:Lacrosse:Plays"
26
31
  model.tag_list = tag_names
32
+ model.save
27
33
 
28
34
  expect(HasTags::Tag.last.context.name).to eq("Lacrosse")
29
35
  end
30
36
  end
31
37
 
32
38
  it "should retrieve tag list" do
39
+ model = TaggableModel.new(name: "post")
33
40
  tag_names = "Sports:Lacrosse"
34
41
  model.tag_list = tag_names
42
+ model.save
35
43
 
36
44
  expect(model.tag_list).to eq("Sports, Lacrosse")
37
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_tags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garrett Martin