gutentag 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d85f0029e162907bb00faea63223b0b8c1207fec
4
- data.tar.gz: fa0aee9f34395cb1af2885da0c70a04427e26da7
3
+ metadata.gz: f6d5be313a5546f19c11c2c5a74b0164665c795e
4
+ data.tar.gz: e9dee9503ecbae393676a9d5d897e79b12876236
5
5
  SHA512:
6
- metadata.gz: 6bd5622a2935365c92ef8bab94768913a194fd34c98f28057beb8369b875d40e0797d525593bf7641daa9f360765d72560dd4998cdb8409d1241a4829cf7b5b7
7
- data.tar.gz: 9b17cb1f4ae54e5205c6eaf8ee514c3e48bca171ee392ca18feb80562c5fdaae381eeeaefe912a537e922251d375fb152aa4b9c848784b53e5fe284a5444d36d
6
+ metadata.gz: 5d353d61f4c35f34c56c4545cac40eef7a6a187da84515bcc99c883de01892a01823f746cedf5e7a1f8b26878023fddef5bb4ae09d48c8e262a761968a4324ca
7
+ data.tar.gz: d22d8a4f863229adeda019d80919f63fe55adf653e0be3cd813190e529474e9d7b86f247909506debead2ad69a5b940d81fc3954fd3752896563d7b4a13be6ff
data/README.md CHANGED
@@ -10,20 +10,24 @@ This was built partly as a proof-of-concept, and partly to see how a tagging gem
10
10
 
11
11
  ## Installation
12
12
 
13
- **Upgrading?** Gutentag has recently switched table names from `tags` and `taggings` to `gutentag_tags` and `gutentag_taggings`, to avoid conflicting with the more generic table names that may exist in Rails apps already. If you already have been using Gutentag, you'll need to create a migration manually that renames these tables:
14
-
15
- rename_table :tags, :gutentag_tags
16
- rename_table :taggings, :gutentag_taggings
17
-
18
13
  Get it into your Gemfile - and don't forget the version constraint!
19
14
 
20
- gem 'gutentag', '~> 0.5.0'
15
+ gem 'gutentag', '~> 0.5.1'
21
16
 
22
17
  Next: your tags get persisted to your database, so let's import and run the migrations to get the tables set up:
23
18
 
24
19
  rake gutentag:install:migrations
25
20
  rake db:migrate
26
21
 
22
+ ## Upgrading
23
+
24
+ Between 0.4.0 and 0.5.0, Gutentag switched table names from `tags` and `taggings` to `gutentag_tags` and `gutentag_taggings`. This has been done to avoid conflicting with the more generic table names that may exist in Rails apps already.
25
+
26
+ If you were using Gutentag 0.4.0 (or older) and now want to upgrade, you'll need to create a migration manually that renames these tables:
27
+
28
+ rename_table :tags, :gutentag_tags
29
+ rename_table :taggings, :gutentag_taggings
30
+
27
31
  ## Usage
28
32
 
29
33
  The first step is easy: add the tag associations to whichever models should have tags (in these examples, the Article model):
@@ -13,7 +13,7 @@ class Gutentag::Tag < ActiveRecord::Base
13
13
  before_validation :normalise_name
14
14
 
15
15
  def self.find_by_name(name)
16
- where(:name => Gutentag::TagName.normalise(name)).first
16
+ where(:name => Gutentag.normaliser.call(name)).first
17
17
  end
18
18
 
19
19
  def self.find_or_create(name)
@@ -23,6 +23,6 @@ class Gutentag::Tag < ActiveRecord::Base
23
23
  private
24
24
 
25
25
  def normalise_name
26
- self.name = Gutentag::TagName.normalise name
26
+ self.name = Gutentag.normaliser.call name
27
27
  end
28
28
  end
data/gutentag.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'gutentag'
4
- s.version = '0.5.0'
4
+ s.version = '0.5.1'
5
5
  s.authors = ['Pat Allan']
6
6
  s.email = ['pat@freelancing-gods.com']
7
7
  s.homepage = 'https://github.com/pat/gutentag'
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.require_paths = ['lib']
15
15
 
16
16
  s.add_runtime_dependency 'activerecord', '>= 3.2.0'
17
- s.add_development_dependency 'combustion', '~> 0.5.1'
17
+ s.add_development_dependency 'combustion', '0.5.1'
18
18
  s.add_development_dependency 'rspec-rails', '~> 2.13'
19
19
  s.add_development_dependency 'sqlite3', '~> 1.3.7'
20
20
  end
data/lib/gutentag.rb CHANGED
@@ -1,8 +1,15 @@
1
1
  module Gutentag
2
- #
2
+ def self.normaliser
3
+ @normaliser ||= Gutentag::TagName
4
+ end
5
+
6
+ def self.normaliser=(normaliser)
7
+ @normaliser = normaliser
8
+ end
3
9
  end
4
10
 
5
11
  require 'gutentag/active_record'
12
+ require 'gutentag/dirty'
6
13
  require 'gutentag/engine'
7
14
  require 'gutentag/persistence'
8
15
  require 'gutentag/tag_name'
@@ -23,6 +23,8 @@ module Gutentag::ActiveRecord
23
23
  end
24
24
 
25
25
  def tag_names=(names)
26
+ Gutentag::Dirty.call self, names
27
+
26
28
  @tag_names = names
27
29
  end
28
30
  end
@@ -0,0 +1,25 @@
1
+ class Gutentag::Dirty
2
+ def self.call(instance, tag_names)
3
+ new(instance, tag_names).call
4
+ end
5
+
6
+ def initialize(instance, tag_names)
7
+ @instance, @tag_names = instance, tag_names
8
+ end
9
+
10
+ def call
11
+ instance.changed_attributes[:tag_names] = existing if changes.present?
12
+ end
13
+
14
+ private
15
+
16
+ attr_reader :instance, :tag_names
17
+
18
+ def changes
19
+ (existing + tag_names).uniq - (existing & tag_names)
20
+ end
21
+
22
+ def existing
23
+ instance.tag_names
24
+ end
25
+ end
@@ -40,6 +40,6 @@ class Gutentag::Persistence
40
40
  end
41
41
 
42
42
  def normaliser
43
- @normaliser ||= Proc.new { |name| Gutentag::TagName.normalise(name) }
43
+ @normaliser ||= Proc.new { |name| Gutentag.normaliser.call(name) }
44
44
  end
45
45
  end
@@ -1,5 +1,5 @@
1
1
  class Gutentag::TagName
2
- def self.normalise(name)
2
+ def self.call(name)
3
3
  new(name).to_s
4
4
  end
5
5
 
@@ -8,14 +8,42 @@ describe "Managing tags via names" do
8
8
 
9
9
  article.tags << melbourne
10
10
 
11
- article.tag_names.should == ['melbourne']
11
+ expect(article.tag_names).to eq(['melbourne'])
12
12
  end
13
13
 
14
14
  it "adds tags via their names" do
15
15
  article.tag_names << 'melbourne'
16
16
  article.save!
17
17
 
18
- article.tags.collect(&:name).should == ['melbourne']
18
+ expect(article.tags.collect(&:name)).to eq(['melbourne'])
19
+ end
20
+
21
+ it "makes model dirty when changing through tag_names" do
22
+ article.tag_names << 'melbourne'
23
+ article.save!
24
+
25
+ article.tag_names = ['sydney']
26
+
27
+ expect(article.changed_attributes.stringify_keys).
28
+ to eq('tag_names' => ['melbourne'])
29
+ end
30
+
31
+ it "does not make model dirty when changing through tag_names" do
32
+ article.tag_names << 'melbourne'
33
+ article.save!
34
+
35
+ article.tag_names = ['melbourne']
36
+
37
+ expect(article.changed_attributes).to eq({})
38
+ end
39
+
40
+ it "allows for different tag normalisation" do
41
+ Gutentag.normaliser = lambda { |name| name.upcase }
42
+
43
+ tag = Gutentag::Tag.create(:name => 'melbourne')
44
+ expect(tag.name).to eq('MELBOURNE')
45
+
46
+ Gutentag.normaliser = nil
19
47
  end
20
48
 
21
49
  it "doesn't complain when adding an existing tag" do
@@ -23,14 +51,14 @@ describe "Managing tags via names" do
23
51
  article.tag_names << 'melbourne'
24
52
  article.save!
25
53
 
26
- article.tags.collect(&:name).should == ['melbourne']
54
+ expect(article.tags.collect(&:name)).to eq(['melbourne'])
27
55
  end
28
56
 
29
57
  it "accepts a completely new set of tags" do
30
58
  article.tag_names = ['portland', 'oregon']
31
59
  article.save!
32
60
 
33
- article.tags.collect(&:name).should == ['portland', 'oregon']
61
+ expect(article.tags.collect(&:name)).to eq(['portland', 'oregon'])
34
62
  end
35
63
 
36
64
  it "does not allow duplication of tags" do
@@ -40,7 +68,7 @@ describe "Managing tags via names" do
40
68
  article.tag_names = ['portland']
41
69
  article.save!
42
70
 
43
- existing.tag_ids.should == article.tag_ids
71
+ expect(existing.tag_ids).to eq(article.tag_ids)
44
72
  end
45
73
 
46
74
  it "appends tag names" do
@@ -48,7 +76,7 @@ describe "Managing tags via names" do
48
76
  article.tag_names += ['oregon', 'ruby']
49
77
  article.save!
50
78
 
51
- article.tags.collect(&:name).should == ['portland', 'oregon', 'ruby']
79
+ expect(article.tags.collect(&:name)).to eq(['portland', 'oregon', 'ruby'])
52
80
  end
53
81
 
54
82
  it "does not repeat appended names that already exist" do
@@ -56,7 +84,7 @@ describe "Managing tags via names" do
56
84
  article.tag_names += ['oregon', 'ruby']
57
85
  article.save!
58
86
 
59
- article.tags.collect(&:name).should == ['portland', 'oregon', 'ruby']
87
+ expect(article.tags.collect(&:name)).to eq(['portland', 'oregon', 'ruby'])
60
88
  end
61
89
 
62
90
  it "removes a single tag name" do
@@ -64,7 +92,7 @@ describe "Managing tags via names" do
64
92
  article.tag_names.delete 'oregon'
65
93
  article.save!
66
94
 
67
- article.tags.collect(&:name).should == ['portland']
95
+ expect(article.tags.collect(&:name)).to eq(['portland'])
68
96
  end
69
97
 
70
98
  it "removes tag names" do
@@ -72,7 +100,7 @@ describe "Managing tags via names" do
72
100
  article.tag_names -= ['oregon', 'ruby']
73
101
  article.save!
74
102
 
75
- article.tags.collect(&:name).should == ['portland']
103
+ expect(article.tags.collect(&:name)).to eq(['portland'])
76
104
  end
77
105
 
78
106
  it "matches tag names ignoring case" do
@@ -80,22 +108,22 @@ describe "Managing tags via names" do
80
108
  article.tag_names += ['Portland']
81
109
  article.save!
82
110
 
83
- article.tags.collect(&:name).should == ['portland']
111
+ expect(article.tags.collect(&:name)).to eq(['portland'])
84
112
 
85
113
  article.tag_names << 'Portland'
86
114
  article.save!
87
115
 
88
- article.tags.collect(&:name).should == ['portland']
116
+ expect(article.tags.collect(&:name)).to eq(['portland'])
89
117
  end
90
118
 
91
119
  it "allows setting of tag names on unpersisted objects" do
92
120
  article = Article.new :tag_names => ['melbourne', 'pancakes']
93
121
  article.save!
94
122
 
95
- article.tag_names.should == ['melbourne', 'pancakes']
123
+ expect(article.tag_names).to eq(['melbourne', 'pancakes'])
96
124
  end
97
125
 
98
126
  it "allows overriding of tag_names=" do
99
- Article.instance_methods(false).should_not include(:tag_names=)
127
+ expect(Article.instance_methods(false)).to_not include(:tag_names=)
100
128
  end
101
129
  end
@@ -7,7 +7,7 @@ describe 'Adding and removing tags' do
7
7
  it "stores new tags" do
8
8
  article.tags << pancakes
9
9
 
10
- article.tags.reload.should == [pancakes]
10
+ expect(article.tags.reload).to eq([pancakes])
11
11
  end
12
12
 
13
13
  it "removes existing tags" do
@@ -15,7 +15,7 @@ describe 'Adding and removing tags' do
15
15
 
16
16
  article.tags.delete pancakes
17
17
 
18
- article.tags.reload.should == []
18
+ expect(article.tags.reload).to eq([])
19
19
  end
20
20
 
21
21
  it "removes taggings when an article is deleted" do
@@ -23,9 +23,9 @@ describe 'Adding and removing tags' do
23
23
 
24
24
  article.destroy
25
25
 
26
- Gutentag::Tagging.where(
26
+ expect(Gutentag::Tagging.where(
27
27
  :taggable_type => 'Article', :taggable_id => article.id
28
- ).count.should be_zero
28
+ ).count).to be_zero
29
29
  end
30
30
 
31
31
  it "removes taggings when a tag is deleted" do
@@ -33,7 +33,7 @@ describe 'Adding and removing tags' do
33
33
 
34
34
  pancakes.destroy
35
35
 
36
- Gutentag::Tagging.where(:tag_id => pancakes.id).count.should be_zero
36
+ expect(Gutentag::Tagging.where(:tag_id => pancakes.id).count).to be_zero
37
37
  end
38
38
 
39
39
  it 'should have a mean tag cloud' do
@@ -41,10 +41,10 @@ describe 'Adding and removing tags' do
41
41
  another_article = Article.create
42
42
 
43
43
  article.tags << pancakes
44
- Gutentag::Tag.by_weight.first.should == pancakes
44
+ expect(Gutentag::Tag.by_weight.first).to eq(pancakes)
45
45
 
46
46
  article.tags << gorillas
47
47
  another_article.tags << gorillas
48
- Gutentag::Tag.by_weight.first.should == gorillas
48
+ expect(Gutentag::Tag.by_weight.first).to eq(gorillas)
49
49
  end
50
50
  end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Gutentag::TagName do
4
- describe '.normalise' do
4
+ describe '.call' do
5
5
  it "downcases the provided name" do
6
- Gutentag::TagName.normalise('Tasty Pancakes').should == 'tasty pancakes'
6
+ expect(Gutentag::TagName.call('Tasty Pancakes')).to eq('tasty pancakes')
7
7
  end
8
8
  end
9
9
  end
@@ -5,17 +5,17 @@ describe Gutentag::Tag do
5
5
  it "returns a tag with the same name" do
6
6
  existing = Gutentag::Tag.create! :name => 'pancakes'
7
7
 
8
- Gutentag::Tag.find_by_name('pancakes').should == existing
8
+ expect(Gutentag::Tag.find_by_name('pancakes')).to eq(existing)
9
9
  end
10
10
 
11
11
  it "returns a tag with the same normalised name" do
12
12
  existing = Gutentag::Tag.create! :name => 'pancakes'
13
13
 
14
- Gutentag::Tag.find_by_name('Pancakes').should == existing
14
+ expect(Gutentag::Tag.find_by_name('Pancakes')).to eq(existing)
15
15
  end
16
16
 
17
17
  it "otherwise returns nil" do
18
- Gutentag::Tag.find_by_name('pancakes').should be_nil
18
+ expect(Gutentag::Tag.find_by_name('pancakes')).to be_nil
19
19
  end
20
20
  end
21
21
 
@@ -23,34 +23,34 @@ describe Gutentag::Tag do
23
23
  it "returns a tag with the same name" do
24
24
  existing = Gutentag::Tag.create! :name => 'pancakes'
25
25
 
26
- Gutentag::Tag.find_or_create('pancakes').should == existing
26
+ expect(Gutentag::Tag.find_or_create('pancakes')).to eq(existing)
27
27
  end
28
28
 
29
29
  it "returns a tag with the same normalised name" do
30
30
  existing = Gutentag::Tag.create! :name => 'pancakes'
31
31
 
32
- Gutentag::Tag.find_or_create('Pancakes').should == existing
32
+ expect(Gutentag::Tag.find_or_create('Pancakes')).to eq(existing)
33
33
  end
34
34
 
35
35
  it "creates a new tag if no matches exist" do
36
- Gutentag::Tag.find_or_create('pancakes').should be_persisted
36
+ expect(Gutentag::Tag.find_or_create('pancakes')).to be_persisted
37
37
  end
38
38
  end
39
39
 
40
40
  describe '#name' do
41
41
  before :each do
42
- Gutentag::TagName.stub :normalise => 'waffles'
42
+ allow(Gutentag::TagName).to receive(:call).and_return('waffles')
43
43
  end
44
44
 
45
45
  it "normalises the provided name" do
46
- Gutentag::TagName.should_receive(:normalise).with('Pancakes').
46
+ expect(Gutentag::TagName).to receive(:call).with('Pancakes').
47
47
  and_return('waffles')
48
48
 
49
49
  Gutentag::Tag.create!(:name => 'Pancakes')
50
50
  end
51
51
 
52
52
  it "saves the normalised name" do
53
- Gutentag::Tag.create!(:name => 'Pancakes').name.should == 'waffles'
53
+ expect(Gutentag::Tag.create!(:name => 'Pancakes').name).to eq('waffles')
54
54
  end
55
55
  end
56
56
 
@@ -58,7 +58,8 @@ describe Gutentag::Tag do
58
58
  it "ignores case when enforcing uniqueness" do
59
59
  Gutentag::Tag.create! :name => 'pancakes'
60
60
 
61
- Gutentag::Tag.create(:name => 'Pancakes').should have(1).error_on(:name)
61
+ tag = Gutentag::Tag.create(:name => 'Pancakes')
62
+ expect(tag.errors[:name].length).to eq(1)
62
63
  end
63
64
  end
64
65
  end
@@ -14,7 +14,9 @@ describe Gutentag::Tagging do
14
14
  tagging = Gutentag::Tagging.new
15
15
  tagging.tag = tag
16
16
  tagging.taggable = taggable
17
- tagging.should have(1).error_on(:tag_id)
17
+
18
+ tagging.valid?
19
+ expect(tagging.errors[:tag_id].length).to eq(1)
18
20
  end
19
21
  end
20
22
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gutentag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-10 00:00:00.000000000 Z
11
+ date: 2014-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: combustion
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - '='
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.5.1
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - '='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.5.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '2.13'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.13'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: 1.3.7
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 1.3.7
69
69
  description: A good, simple, solid tagging extension for ActiveRecord
@@ -73,8 +73,8 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - .gitignore
77
- - .travis.yml
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
78
  - Gemfile
79
79
  - LICENCE
80
80
  - README.md
@@ -87,6 +87,7 @@ files:
87
87
  - gutentag.gemspec
88
88
  - lib/gutentag.rb
89
89
  - lib/gutentag/active_record.rb
90
+ - lib/gutentag/dirty.rb
90
91
  - lib/gutentag/engine.rb
91
92
  - lib/gutentag/persistence.rb
92
93
  - lib/gutentag/tag_name.rb
@@ -110,17 +111,17 @@ require_paths:
110
111
  - lib
111
112
  required_ruby_version: !ruby/object:Gem::Requirement
112
113
  requirements:
113
- - - '>='
114
+ - - ">="
114
115
  - !ruby/object:Gem::Version
115
116
  version: '0'
116
117
  required_rubygems_version: !ruby/object:Gem::Requirement
117
118
  requirements:
118
- - - '>='
119
+ - - ">="
119
120
  - !ruby/object:Gem::Version
120
121
  version: '0'
121
122
  requirements: []
122
123
  rubyforge_project:
123
- rubygems_version: 2.1.0
124
+ rubygems_version: 2.3.0
124
125
  signing_key:
125
126
  specification_version: 4
126
127
  summary: Good Tags