friendly_id 5.0.1 → 5.0.2

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: 558d42d05561510d3b878d6c55a99eaac461d189
4
- data.tar.gz: b56ebd579507441df27d8aa42e0b837d2ce0fc60
3
+ metadata.gz: 4c3bf1c2fe2200df982e5bad6a9cca5bdaed5c48
4
+ data.tar.gz: b79c9c881c70320e7281014ca3296888b2387caa
5
5
  SHA512:
6
- metadata.gz: 0e11d6d309df06e6177eb24c03af2aff0f3119f5c545b15e8088599d19f62242266e71c01aa69beda1ccb2c4b8a113a651fdb25ab10ef54b856a552284bd02dd
7
- data.tar.gz: 0eef987342060880f7d713948f8f12e04e90efbe89059e34debda4a78026989170538410ba9b981feaaf5df424fa8e475bfe51492049372dae4a023faad385c9
6
+ metadata.gz: 38f17a8c8fd139b9a56fae5d76fa7e798775c9b9beb6c7daeb319b28cb10e173c4bfe5f6735ffb8b43fdc3124622bf478d3874630947004be432761df40574d8
7
+ data.tar.gz: e5cd66308d2e38adccf5797679fa8b35fd47a7ed0cfd076b404fd5d9f2ed137ae108d0b428245b714ebf8b3aaf3b878baa9afb5cfaec210fe339b44eca24914a
data/.travis.yml CHANGED
@@ -10,4 +10,4 @@ gemfile:
10
10
  - gemfiles/Gemfile.rails-stable.rb
11
11
 
12
12
  before_script: 'bundle exec rake db:create db:up'
13
- script: 'bundle exec rake test'
13
+ script: 'COVERAGE=true bundle exec rake test'
data/Changelog.md CHANGED
@@ -3,6 +3,13 @@
3
3
  We would like to think our many {file:Contributors contributors} for
4
4
  suggestions, ideas and improvements to FriendlyId.
5
5
 
6
+ ## 5.0.2 (2013-12-10)
7
+
8
+ * Query performance improvements ([#497](https://github.com/norman/friendly_id/pull/497)).
9
+ * Documentation improvements (thanks [John Bachir](https://github.com/jjb)).
10
+ * Minor refactoring of internals (thanks [Gagan Ahwad](https://github.com/gaganawhad)).
11
+ * Set slug to `nil` on call to `dup` to ensure slug is generated ([#483](https://github.com/norman/friendly_id/pull/483)).
12
+
6
13
  ## 5.0.1 (2013-10-27)
7
14
 
8
15
  * Fix compatibility with Rails 4.0.1.rc3 (thanks [Herman verschooten](https://github.com/Hermanverschooten)).
data/README.md CHANGED
@@ -16,13 +16,13 @@ over and over and over again in the issues.
16
16
 
17
17
  **Rails 4**:
18
18
 
19
- The master branch of this repository contains FriendlyId 5, which is compatible
20
- with Rails 4. This version is in beta and will be released soon.
19
+ The master branch of this repository contains FriendlyId 5, the current stable version.
20
+ 5.x is the only version that is compatible with Rails 4.
21
21
 
22
22
  **Rails 3**:
23
23
 
24
24
  If you wish to use this gem with Rails 3.1 or 3.2 you must use FriendlyId 4,
25
- which is the current stable release. Please see the [4.0-stable
25
+ which is the previous stable release. Please see the [4.0-stable
26
26
  branch](https://github.com/norman/friendly_id/tree/4.0-stable).
27
27
 
28
28
  # FriendlyId
@@ -49,7 +49,7 @@ versioning, i18n, scoped slugs, reserved words, and custom slug generators.
49
49
 
50
50
  ### What Changed in Version 5.0
51
51
 
52
- As of version 5.0, FriendlyId uses semantic versioning. Therefore, as you might
52
+ As of version 5.0, FriendlyId uses [semantic versioning](http://semver.org/). Therefore, as you might
53
53
  infer from the version number, 5.0 introduces changes incompatible with 4.0.
54
54
 
55
55
  The most important changes are:
@@ -57,66 +57,61 @@ The most important changes are:
57
57
  * Finders are no longer overridden by default. If you want to do friendly finds,
58
58
  you must do `Model.friendly.find` rather than `Model.find`. You can however
59
59
  restore FriendlyId 4-style finders by using the `:finders` addon:
60
-
61
- friendly_id :foo, use: :slugged # you must do MyClass.friendly.find('bar')
62
- # or...
63
- friendly_id :foo, use: [:slugged, :finders] # you can now do MyClass.find('bar')
64
-
65
-
60
+ ```ruby
61
+ friendly_id :foo, use: :slugged # you must do MyClass.friendly.find('bar')
62
+ # or...
63
+ friendly_id :foo, use: [:slugged, :finders] # you can now do MyClass.find('bar')
64
+ ```
66
65
  * A new "candidates" functionality which makes it easy to set up a list of
67
66
  alternate slugs that can be used to uniquely distinguish records, rather than
68
67
  appending a sequence. For example:
69
68
 
70
- class Restaurant < ActiveRecord::Base
71
- extend FriendlyId
72
- friendly_id :slug_candidates, use: :slugged
73
-
74
- # Try building a slug based on the following fields in
75
- # increasing order of specificity.
76
- def slug_candidates
77
- [
78
- :name,
79
- [:name, :city],
80
- [:name, :street, :city],
81
- [:name, :street_number, :street, :city]
82
- ]
83
- end
84
- end
85
-
69
+ ```ruby
70
+ class Restaurant < ActiveRecord::Base
71
+ extend FriendlyId
72
+ friendly_id :slug_candidates, use: :slugged
73
+
74
+ # Try building a slug based on the following fields in
75
+ # increasing order of specificity.
76
+ def slug_candidates
77
+ [
78
+ :name,
79
+ [:name, :city],
80
+ [:name, :street, :city],
81
+ [:name, :street_number, :street, :city]
82
+ ]
83
+ end
84
+ end
85
+ ```
86
86
  * Now that candidates have been added, FriendlyId no longer uses a numeric
87
87
  sequence to differentiate conflicting slug, but rather a UUID (e.g. something
88
88
  like `2bc08962-b3dd-4f29-b2e6-244710c86106`). This makes the
89
89
  codebase simpler and more reliable when running concurrently, at the expense
90
90
  of uglier ids being generated when there are conflicts.
91
-
92
91
  * The default sequence separator has been changed from two dashes to one dash.
93
-
94
92
  * Slugs are no longer regenerated when a record is saved. If you want to regenerate
95
93
  a slug, you must explicitly set the slug column to nil:
96
94
 
97
- restaurant.friendly_id # joes-diner
98
- restaurant.name = "The Plaza Diner"
99
- restaurant.save!
100
- restaurant.friendly_id # joes-diner
101
- restaurant.slug = nil
102
- restaurant.save!
103
- restaurant.friendly_id # the-plaza-diner
95
+ ```ruby
96
+ restaurant.friendly_id # joes-diner
97
+ restaurant.name = "The Plaza Diner"
98
+ restaurant.save!
99
+ restaurant.friendly_id # joes-diner
100
+ restaurant.slug = nil
101
+ restaurant.save!
102
+ restaurant.friendly_id # the-plaza-diner
103
+ ```
104
104
 
105
105
  You can restore some of the old behavior by overriding the
106
106
  `should_generate_new_friendly_id?` method.
107
-
108
107
  * The `friendly_id` Rails generator now generates an initializer showing you
109
- how to do some commmon global configuration.
110
-
108
+ how to do some common global configuration.
111
109
  * The Globalize plugin has moved to a separate gem (currently in alpha).
112
-
113
110
  * The `:reserved` module no longer includes any default reserved words.
114
111
  Previously it blocked "edit" and "new" everywhere. The default word list has
115
112
  been moved to `config/initializers/friendly_id.rb` and now includes many more
116
113
  words.
117
-
118
114
  * The `:history` and `:scoped` addons can now be used together.
119
-
120
115
  * Since it now requires Rails 4, FriendlyId also now requires Ruby 1.9.3 or
121
116
  higher.
122
117
 
@@ -133,10 +128,12 @@ the new `:scope` column.
133
128
 
134
129
  A migration like this should be sufficient:
135
130
 
136
- add_column :friendly_id_slugs, :scope, :string
137
- remove_index :friendly_id_slugs, [:slug, :sluggable_type]
138
- add_index :friendly_id_slugs, [:slug, :sluggable_type]
139
- add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope], unique: true
131
+ ```ruby
132
+ add_column :friendly_id_slugs, :scope, :string
133
+ remove_index :friendly_id_slugs, [:slug, :sluggable_type]
134
+ add_index :friendly_id_slugs, [:slug, :sluggable_type]
135
+ add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope], unique: true
136
+ ```
140
137
 
141
138
  ## Docs
142
139
 
data/friendly_id.gemspec CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
 
19
19
  s.add_dependency 'activerecord', '~> 4.0.0'
20
20
 
21
+ s.add_development_dependency 'coveralls'
21
22
  s.add_development_dependency 'railties', '~> 4.0.0'
22
23
  s.add_development_dependency 'minitest', '>= 4.4.0'
23
24
  s.add_development_dependency 'mocha', '~> 0.13.3'
@@ -246,5 +246,10 @@ often better and easier to use {FriendlyId::Slugged slugs}.
246
246
  friendly_id.presence.to_param || super
247
247
  end
248
248
  end
249
+
250
+ # Clears slug on duplicate records when calling `dup`.
251
+ def dup
252
+ super.tap { |duplicate| duplicate.slug = nil }
253
+ end
249
254
  end
250
255
  end
@@ -81,7 +81,7 @@ method.
81
81
  include ::FriendlyId::FinderMethods
82
82
 
83
83
  def exists_by_friendly_id?(id)
84
- joins(:slugs).where(arel_table[friendly_id_config.query_field].eq(id).or(slug_history_clause(id))).exists?
84
+ joins(:slugs).where(arel_table[friendly_id_config.query_field].eq(id)).exists? || joins(:slugs).where(slug_history_clause(id)).exists?
85
85
  end
86
86
 
87
87
  private
@@ -121,7 +121,7 @@ an example of one way to set this up:
121
121
  friendly_id_config.scope_columns.sort.map { |column| "#{column}:#{send(column)}" }.join(",")
122
122
  end
123
123
 
124
- def slug_generator
124
+ def scope_for_slug_generator
125
125
  relation = self.class.unscoped.friendly
126
126
  friendly_id_config.scope_columns.each do |column|
127
127
  relation = relation.where(column => send(column))
@@ -130,7 +130,12 @@ an example of one way to set this up:
130
130
  column = self.class.quoted_table_name + '.' + self.class.quoted_primary_key
131
131
  relation = relation.where("#{column} <> ?", send(self.class.primary_key))
132
132
  end
133
- friendly_id_config.slug_generator_class.new(relation)
133
+ relation
134
+ end
135
+ private :scope_for_slug_generator
136
+
137
+ def slug_generator
138
+ friendly_id_config.slug_generator_class.new(scope_for_slug_generator)
134
139
  end
135
140
  private :slug_generator
136
141
 
@@ -1,3 +1,3 @@
1
1
  module FriendlyId
2
- VERSION = "5.0.1"
2
+ VERSION = "5.0.2"
3
3
  end
data/test/helper.rb CHANGED
@@ -1,5 +1,9 @@
1
- require "rubygems"
2
1
  require "bundler/setup"
2
+ if ENV['COVERAGE']
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+ end
6
+
3
7
  require "minitest/unit"
4
8
  require "mocha/setup"
5
9
  require "active_record"
data/test/shared.rb CHANGED
@@ -51,6 +51,13 @@ module FriendlyId
51
51
  end
52
52
  end
53
53
 
54
+ test "should set the slug to nil on dup" do
55
+ with_instance_of model_class do |record|
56
+ record2 = record.dup
57
+ assert_nil record2.slug
58
+ end
59
+ end
60
+
54
61
  test "when validations block save, to_param should return friendly_id rather than nil" do
55
62
  my_model_class = Class.new(model_class)
56
63
  self.class.const_set("Foo", my_model_class)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.1
4
+ version: 5.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Norman Clarke
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-27 00:00:00.000000000 Z
12
+ date: 2013-12-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - ~>
26
26
  - !ruby/object:Gem::Version
27
27
  version: 4.0.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: coveralls
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: railties
30
44
  requirement: !ruby/object:Gem::Requirement