gutentag 2.2.1 → 2.3.0

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
  SHA256:
3
- metadata.gz: 506e53c384365bbd56d66a31a5a6956955d4098c31dd9bda30c5fe4d9f6822f7
4
- data.tar.gz: e905db1b576c5ee5cd52a834b776232b7f3339d62f8517d9d9262f7c840151c1
3
+ metadata.gz: 06163432b93d4590113c493220800afa305a1f982aaa52384648aad8f1646213
4
+ data.tar.gz: 4cec16fcaa7b11d5a47e45533c956f42762c65235f11819bdae36d5b485181c4
5
5
  SHA512:
6
- metadata.gz: a0039255e81ca547cfe1fa5ea9591b4edaedff4982835dbe4faf1788e5661b61d2ed25622242f641b3226b8d494a7c3ff54ca34e21859418b319a7aa701c8d78
7
- data.tar.gz: 38d36b39b9d935cc32f1e0cdc80267d0d7e347d3c747b02f6270000beae2fe4bb60206f8ef5ccab8f3179c6cdeb6983fc3c3079f3b8452b843373c98b24b704c
6
+ metadata.gz: 3c08959b80eddd4cbaad7587a0aed5e5942089aa1107a800e62fab91d81099f6801c0b8a89f8627507fe0489907441f0d92b2c7e45d3f8d30b02456f4d8fc942
7
+ data.tar.gz: d38bfaef36f64adbaa59049b8cac7a5d4183a119dd496a92aceaaffbad059af1f7e5a74d6597273756d307b798555d95bbdb79785e178089fb52e3396c368d69
@@ -2,6 +2,16 @@
2
2
 
3
3
  All notable changes to this project (at least, from v0.5.0 onwards) will be documented in this file.
4
4
 
5
+ ## 2.3.0 - 2018-03-19
6
+
7
+ ### Changed
8
+
9
+ * Filter out blank tag names when provided via `tag_names=` (as discussed in [#51](https://github.com/pat/gutentag/issues/51)).
10
+
11
+ ### Fixed
12
+
13
+ * Tag validations logic fails gracefully when the database server cannot be reached.
14
+
5
15
  ## 2.2.1 - 2018-03-06
6
16
 
7
17
  ### Fixed
data/README.md CHANGED
@@ -80,7 +80,7 @@ These are the versions the test suite runs against. It's possible it may work on
80
80
  Get it into your Gemfile - and don't forget the version constraint!
81
81
 
82
82
  ```Ruby
83
- gem 'gutentag', '~> 2.2.1'
83
+ gem 'gutentag', '~> 2.3'
84
84
  ```
85
85
 
86
86
  Next: your tags get persisted to your database, so let's import and run the migrations to get the tables set up:
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "gutentag"
6
- s.version = "2.2.1"
6
+ s.version = "2.3.0"
7
7
  s.authors = ["Pat Allan"]
8
8
  s.email = ["pat@freelancing-gods.com"]
9
9
  s.homepage = "https://github.com/pat/gutentag"
@@ -33,6 +33,7 @@ require "gutentag/change_state"
33
33
  require "gutentag/dirty"
34
34
  require "gutentag/persistence"
35
35
  require "gutentag/remove_unused"
36
+ require "gutentag/tag_names"
36
37
  require "gutentag/tag_validations"
37
38
  require "gutentag/tagged_with"
38
39
 
@@ -30,7 +30,7 @@ module Gutentag::ActiveRecord::InstanceMethods
30
30
  # tracking doesn't think the original value was nil.
31
31
  @attributes.write_from_database "tag_names", []
32
32
 
33
- super
33
+ super Gutentag::TagNames.call(names)
34
34
  end
35
35
 
36
36
  private
@@ -14,6 +14,8 @@ module Gutentag::ActiveRecord::InstanceMethods
14
14
  end
15
15
 
16
16
  def tag_names=(names)
17
+ names = Gutentag::TagNames.call(names)
18
+
17
19
  Gutentag.dirtier.call self, names if Gutentag.dirtier
18
20
 
19
21
  @tag_names = names
@@ -22,6 +22,10 @@ module Gutentag::ActiveRecord::InstanceMethods
22
22
  super
23
23
  end
24
24
 
25
+ def tag_names=(names)
26
+ super Gutentag::TagNames.call(names)
27
+ end
28
+
25
29
  private
26
30
 
27
31
  def persist_tags
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gutentag::TagNames
4
+ def self.call(names)
5
+ return nil if names.nil?
6
+
7
+ names.reject(&:blank?)
8
+ end
9
+ end
@@ -1,10 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_model/errors"
4
+ require "active_record/errors"
5
+
3
6
  class Gutentag::TagValidations
4
7
  DEFAULTS = {
5
8
  :presence => true,
6
9
  :uniqueness => {:case_sensitive => false}
7
10
  }.freeze
11
+ DATABASE_ERROR_CLASSES = lambda {
12
+ classes = []
13
+ if ActiveRecord::VERSION::STRING.to_f > 4.0
14
+ classes << ActiveRecord::NoDatabaseError
15
+ end
16
+ classes << Mysql2::Error if defined?(::Mysql2)
17
+ classes << PG::ConnectionBad if defined?(::PG)
18
+ classes
19
+ }.call.freeze
8
20
 
9
21
  def self.call(klass)
10
22
  new(klass).call
@@ -15,7 +27,7 @@ class Gutentag::TagValidations
15
27
  end
16
28
 
17
29
  def call
18
- klass.validates :name, validation_options
30
+ klass.validates :name, validation_options.dup
19
31
  end
20
32
 
21
33
  private
@@ -24,7 +36,7 @@ class Gutentag::TagValidations
24
36
 
25
37
  def add_length_validation?
26
38
  klass.table_exists? && limit.present?
27
- rescue ActiveRecord::NoDatabaseError
39
+ rescue *DATABASE_ERROR_CLASSES
28
40
  false
29
41
  end
30
42
 
@@ -116,4 +116,11 @@ describe "Managing tags via names" do
116
116
 
117
117
  expect(Article.find(article.id).tag_names).to eq(["melbourne"])
118
118
  end
119
+
120
+ it "ignores blank tags" do
121
+ article = Article.new :tag_names => ["", "melbourne"]
122
+ article.save!
123
+
124
+ expect(article.tag_names).to eq(%w[ melbourne ])
125
+ end
119
126
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gutentag
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-05 00:00:00.000000000 Z
11
+ date: 2018-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -155,6 +155,7 @@ files:
155
155
  - lib/gutentag/engine.rb
156
156
  - lib/gutentag/persistence.rb
157
157
  - lib/gutentag/remove_unused.rb
158
+ - lib/gutentag/tag_names.rb
158
159
  - lib/gutentag/tag_validations.rb
159
160
  - lib/gutentag/tagged_with.rb
160
161
  - lib/gutentag/tagged_with/id_query.rb