friendly_id 4.0.9 → 4.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e6d39c9619477767af3dc4196211c9499b9dce57
4
+ data.tar.gz: 28b29864ab0e26ec97277cb0c3fb76c76b9d0673
5
+ SHA512:
6
+ metadata.gz: be63c3d6212865cac1859b47b2ba2156850a746deeaa07c2dd4c0e464aeb90c611a3cd6e30194ca1a57578bff56bdaaab3619ab7b1f99d4f5539152e4d760464
7
+ data.tar.gz: 71b8d5387468ecf5fe792eacbe9ce234e796a63ed37695eeb5863018eb50833ea7ed5af5af56ecc42f0808cd09688d28bcb723f1cfd1ee7e7cfda1a79b5fd6ff
data/Changelog.md CHANGED
@@ -6,6 +6,11 @@ suggestions, ideas and improvements to FriendlyId.
6
6
  * Table of Contents
7
7
  {:toc}
8
8
 
9
+ ## 4.0.10 (2013-08-10)
10
+
11
+ * Fixed table prefixes/suffixes being ignored (Jesse Farless)
12
+ * Fixed sequence generation for slugs containing numbers (Adam Carroll)
13
+
9
14
  ## 4.0.9 (2012-10-31)
10
15
 
11
16
  * Fixed support for Rails 3.2.9.rc1
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # FriendlyId
2
2
 
3
- [![Build Status](http://travis-ci.org/norman/friendly_id.png)](http://travis-ci.org/norman/friendly_id)
3
+ [![Build Status](https://travis-ci.org/norman/friendly_id.png)](https://travis-ci.org/norman/friendly_id)
4
4
 
5
5
  FriendlyId is the "Swiss Army bulldozer" of slugging and permalink plugins for
6
6
  Ruby on Rails. It allows you to create pretty URLs and work with human-friendly
@@ -27,16 +27,16 @@ FriendlyId is compatible with Active Record **3.0** and higher.
27
27
 
28
28
  FriendlyId 4.x introduces many changes incompatible with 3.x. If you're
29
29
  upgrading, please [read the
30
- docs](http://rubydoc.info/github/norman/friendly_id/master/file/WhatsNew.md) to see what's
30
+ docs](http://rubydoc.info/github/FriendlyId/friendly_id/4.0-stable/file/WhatsNew.md) to see what's
31
31
  new.
32
32
 
33
33
  ## Docs
34
34
 
35
35
  The current docs can always be found
36
- [here](http://rubydoc.info/github/norman/friendly_id/master/frames).
36
+ [here](http://rubydoc.info/github/FriendlyId/friendly_id/4.0-stable/frames).
37
37
 
38
38
  The best place to start is with the
39
- [Guide](http://rubydoc.info/github/norman/friendly_id/master/file/Guide.rdoc),
39
+ [Guide](http://rubydoc.info/github/FriendlyId/friendly_id/4.0-stable/file/Guide.rdoc),
40
40
  which compiles the top-level RDocs into one outlined document.
41
41
 
42
42
  You might also want to watch Ryan Bates's [Railscast on FriendlyId](http://railscasts.com/episodes/314-pretty-urls-with-friendlyid).
@@ -49,7 +49,7 @@ You might also want to watch Ryan Bates's [Railscast on FriendlyId](http://rails
49
49
 
50
50
  cd my_app
51
51
 
52
- gem "friendly_id", "~> 4.0.1"
52
+ gem "friendly_id", "~> 4.0.9" # Note: You MUST use 4.0.9 or greater for Rails 3.2.10+
53
53
 
54
54
  rails generate scaffold user name:string slug:string
55
55
 
@@ -103,7 +103,7 @@ article](http://yourbugreportneedsmore.info/).
103
103
  ## Thanks and Credits
104
104
 
105
105
  FriendlyId was originally created by Norman Clarke and Adrian Mugnolo, with
106
- significant help early in its life by Emilio Tagua. I'm deeply gratful for the
106
+ significant help early in its life by Emilio Tagua. I'm deeply grateful for the
107
107
  generous contributions over the years from [many
108
108
  volunteers](https://github.com/norman/friendly_id/contributors).
109
109
 
data/friendly_id.gemspec CHANGED
@@ -1,7 +1,5 @@
1
1
  # encoding: utf-8
2
- $:.push File.expand_path("../lib", __FILE__)
3
-
4
- require "friendly_id"
2
+ require File.expand_path("../lib/friendly_id/version", __FILE__)
5
3
 
6
4
  Gem::Specification.new do |s|
7
5
  s.name = "friendly_id"
@@ -9,16 +7,17 @@ Gem::Specification.new do |s|
9
7
  s.authors = ["Norman Clarke", "Philip Arndt"]
10
8
  s.email = ["norman@njclarke.com", "parndt@gmail.com"]
11
9
  s.homepage = "http://github.com/norman/friendly_id"
10
+ s.license = 'MIT'
12
11
  s.summary = "A comprehensive slugging and pretty-URL plugin."
13
12
  s.rubyforge_project = "friendly_id"
14
13
  s.files = `git ls-files`.split("\n")
15
14
  s.test_files = `git ls-files -- {test}/*`.split("\n")
16
15
  s.require_paths = ["lib"]
17
16
 
18
- s.add_development_dependency "railties", "~> 3.2.0"
19
- s.add_development_dependency "activerecord", "~> 3.2.0"
20
- s.add_development_dependency "minitest", "3.2.0"
21
- s.add_development_dependency "mocha"
17
+ s.add_development_dependency "railties", ">= 3.0"
18
+ s.add_development_dependency "activerecord", ">= 3.0"
19
+ s.add_development_dependency "minitest", "~> 4.4.0"
20
+ s.add_development_dependency "mocha", "~> 0.13.1"
22
21
  s.add_development_dependency "maruku"
23
22
  s.add_development_dependency "yard"
24
23
  s.add_development_dependency "i18n"
data/lib/friendly_id.rb CHANGED
@@ -44,9 +44,6 @@ with numeric ids:
44
44
  =end
45
45
  module FriendlyId
46
46
 
47
- # The current version.
48
- VERSION = "4.0.9"
49
-
50
47
  @mutex = Mutex.new
51
48
 
52
49
  autoload :History, "friendly_id/history"
@@ -111,4 +108,12 @@ module FriendlyId
111
108
  @defaults ||= lambda {|config| config.use :reserved}
112
109
  end
113
110
  end
111
+
112
+ # Set the ActiveRecord table name prefix to friendly_id_
113
+ #
114
+ # This makes 'slugs' into 'friendly_id_slugs' and also respects any
115
+ # 'global' table_name_prefix set on ActiveRecord::Base.
116
+ def self.table_name_prefix
117
+ "#{ActiveRecord::Base.table_name_prefix}friendly_id_"
118
+ end
114
119
  end
@@ -0,0 +1 @@
1
+ version.rb merge=ours
@@ -127,7 +127,10 @@ method.
127
127
  scope = Slug.where("slug = ? OR slug LIKE ?", normalized, wildcard)
128
128
  scope = scope.where(:sluggable_type => sluggable_class.to_s)
129
129
  scope = scope.where("sluggable_id <> ?", value) unless sluggable.new_record?
130
- scope.order("LENGTH(slug) DESC, slug DESC")
130
+
131
+ length_command = "LENGTH"
132
+ length_command = "LEN" if sluggable.connection.adapter_name =~ /sqlserver/i
133
+ scope.order("#{length_command}(slug) DESC, slug DESC")
131
134
  end
132
135
  end
133
136
  end
@@ -33,6 +33,28 @@ Without :scoped in this case, one of the restaurants would have the slug
33
33
  The value for the +:scope+ option can be the name of a +belongs_to+ relation, or
34
34
  a column.
35
35
 
36
+ Additionally, the +:scope+ option can receive an array of scope values:
37
+
38
+ class Cuisine < ActiveRecord::Base
39
+ extend FriendlyId
40
+ has_many :restaurants
41
+ friendly_id :name, :use => :slugged
42
+ end
43
+
44
+ class City < ActiveRecord::Base
45
+ extend FriendlyId
46
+ has_many :restaurants
47
+ friendly_id :name, :use => :slugged
48
+ end
49
+
50
+ class Restaurant < ActiveRecord::Base
51
+ extend FriendlyId
52
+ belongs_to :city
53
+ friendly_id :name, :use => :scoped, :scope => [:city, :cuisine]
54
+ end
55
+
56
+ All supplied values will be used to determine scope.
57
+
36
58
  === Finding Records by Friendly ID
37
59
 
38
60
  If you are using scopes your friendly ids may not be unique, so a simple find
@@ -3,7 +3,6 @@ module FriendlyId
3
3
  #
4
4
  # @see FriendlyId::History
5
5
  class Slug < ActiveRecord::Base
6
- self.table_name = "friendly_id_slugs"
7
6
  belongs_to :sluggable, :polymorphic => true
8
7
 
9
8
  def to_param
@@ -31,7 +31,8 @@ module FriendlyId
31
31
  end
32
32
 
33
33
  def extract_sequence_from_slug(slug)
34
- slug.split("#{normalized}#{separator}").last.to_i
34
+ split_slug = slug.split("#{normalized}#{separator}")
35
+ split_slug.length > 1 ? split_slug.last.to_i : 1
35
36
  end
36
37
 
37
38
  def column
@@ -59,7 +60,10 @@ module FriendlyId
59
60
  base << "ESCAPE '\\'" if sluggable.connection.adapter_name =~ /sqlite/i
60
61
  scope = sluggable_class.unscoped.where(base, normalized, wildcard)
61
62
  scope = scope.where("#{pkey} <> ?", value) unless sluggable.new_record?
62
- scope = scope.order("LENGTH(#{column}) DESC, #{column} DESC")
63
+
64
+ length_command = "LENGTH"
65
+ length_command = "LEN" if sluggable.connection.adapter_name =~ /sqlserver/i
66
+ scope = scope.order("#{length_command}(#{column}) DESC, #{column} DESC")
63
67
  end
64
68
 
65
69
  def friendly_id_config
@@ -0,0 +1,3 @@
1
+ module FriendlyId
2
+ VERSION = "4.0.10"
3
+ end
data/test/helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "rubygems"
2
2
  require "bundler/setup"
3
3
  require "minitest/unit"
4
- require "mocha"
4
+ require "mocha/setup"
5
5
  require "active_record"
6
6
  require 'active_support/core_ext/time/conversions'
7
7
 
data/test/history_test.rb CHANGED
@@ -132,6 +132,20 @@ class HistoryTest < MiniTest::Unit::TestCase
132
132
  end
133
133
  end
134
134
 
135
+ test 'should name table according to prefix and suffix' do
136
+ transaction do
137
+ begin
138
+ prefix = "prefix_"
139
+ without_prefix = FriendlyId::Slug.table_name
140
+ ActiveRecord::Base.table_name_prefix = prefix
141
+ FriendlyId::Slug.reset_table_name
142
+ assert_equal prefix + without_prefix, FriendlyId::Slug.table_name
143
+ ensure
144
+ ActiveRecord::Base.table_name_prefix = ""
145
+ FriendlyId::Slug.table_name = without_prefix
146
+ end
147
+ end
148
+ end
135
149
  end
136
150
 
137
151
  class HistoryTestWithSti < HistoryTest
@@ -146,4 +160,4 @@ class HistoryTestWithSti < HistoryTest
146
160
  def model_class
147
161
  Editorialist
148
162
  end
149
- end
163
+ end
data/test/slugged_test.rb CHANGED
@@ -129,6 +129,12 @@ class SlugGeneratorTest < MiniTest::Unit::TestCase
129
129
  end
130
130
  end
131
131
 
132
+ test "should correctly sequence slugs that start with numbers" do
133
+ record1 = model_class.create! :name => '24-hour-testing'
134
+ assert_equal '24-hour-testing', record1.slug
135
+ record2 = model_class.create! :name => '24-hour-testing'
136
+ assert_equal '24-hour-testing--2', record2.slug
137
+ end
132
138
  end
133
139
 
134
140
  class SlugSeparatorTest < MiniTest::Unit::TestCase
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.9
5
- prerelease:
4
+ version: 4.0.10
6
5
  platform: ruby
7
6
  authors:
8
7
  - Norman Clarke
@@ -10,176 +9,152 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2012-11-01 00:00:00.000000000 Z
12
+ date: 2013-08-10 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: railties
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ~>
18
+ - - '>='
21
19
  - !ruby/object:Gem::Version
22
- version: 3.2.0
20
+ version: '3.0'
23
21
  type: :development
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ~>
25
+ - - '>='
29
26
  - !ruby/object:Gem::Version
30
- version: 3.2.0
27
+ version: '3.0'
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: activerecord
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ~>
32
+ - - '>='
37
33
  - !ruby/object:Gem::Version
38
- version: 3.2.0
34
+ version: '3.0'
39
35
  type: :development
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ~>
39
+ - - '>='
45
40
  - !ruby/object:Gem::Version
46
- version: 3.2.0
41
+ version: '3.0'
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: minitest
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
- - - '='
46
+ - - ~>
53
47
  - !ruby/object:Gem::Version
54
- version: 3.2.0
48
+ version: 4.4.0
55
49
  type: :development
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
- - - '='
53
+ - - ~>
61
54
  - !ruby/object:Gem::Version
62
- version: 3.2.0
55
+ version: 4.4.0
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: mocha
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
- - - ! '>='
60
+ - - ~>
69
61
  - !ruby/object:Gem::Version
70
- version: '0'
62
+ version: 0.13.1
71
63
  type: :development
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
- - - ! '>='
67
+ - - ~>
77
68
  - !ruby/object:Gem::Version
78
- version: '0'
69
+ version: 0.13.1
79
70
  - !ruby/object:Gem::Dependency
80
71
  name: maruku
81
72
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
73
  requirements:
84
- - - ! '>='
74
+ - - '>='
85
75
  - !ruby/object:Gem::Version
86
76
  version: '0'
87
77
  type: :development
88
78
  prerelease: false
89
79
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
80
  requirements:
92
- - - ! '>='
81
+ - - '>='
93
82
  - !ruby/object:Gem::Version
94
83
  version: '0'
95
84
  - !ruby/object:Gem::Dependency
96
85
  name: yard
97
86
  requirement: !ruby/object:Gem::Requirement
98
- none: false
99
87
  requirements:
100
- - - ! '>='
88
+ - - '>='
101
89
  - !ruby/object:Gem::Version
102
90
  version: '0'
103
91
  type: :development
104
92
  prerelease: false
105
93
  version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
94
  requirements:
108
- - - ! '>='
95
+ - - '>='
109
96
  - !ruby/object:Gem::Version
110
97
  version: '0'
111
98
  - !ruby/object:Gem::Dependency
112
99
  name: i18n
113
100
  requirement: !ruby/object:Gem::Requirement
114
- none: false
115
101
  requirements:
116
- - - ! '>='
102
+ - - '>='
117
103
  - !ruby/object:Gem::Version
118
104
  version: '0'
119
105
  type: :development
120
106
  prerelease: false
121
107
  version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
108
  requirements:
124
- - - ! '>='
109
+ - - '>='
125
110
  - !ruby/object:Gem::Version
126
111
  version: '0'
127
112
  - !ruby/object:Gem::Dependency
128
113
  name: ffaker
129
114
  requirement: !ruby/object:Gem::Requirement
130
- none: false
131
115
  requirements:
132
- - - ! '>='
116
+ - - '>='
133
117
  - !ruby/object:Gem::Version
134
118
  version: '0'
135
119
  type: :development
136
120
  prerelease: false
137
121
  version_requirements: !ruby/object:Gem::Requirement
138
- none: false
139
122
  requirements:
140
- - - ! '>='
123
+ - - '>='
141
124
  - !ruby/object:Gem::Version
142
125
  version: '0'
143
126
  - !ruby/object:Gem::Dependency
144
127
  name: simplecov
145
128
  requirement: !ruby/object:Gem::Requirement
146
- none: false
147
129
  requirements:
148
- - - ! '>='
130
+ - - '>='
149
131
  - !ruby/object:Gem::Version
150
132
  version: '0'
151
133
  type: :development
152
134
  prerelease: false
153
135
  version_requirements: !ruby/object:Gem::Requirement
154
- none: false
155
136
  requirements:
156
- - - ! '>='
137
+ - - '>='
157
138
  - !ruby/object:Gem::Version
158
139
  version: '0'
159
140
  - !ruby/object:Gem::Dependency
160
141
  name: globalize3
161
142
  requirement: !ruby/object:Gem::Requirement
162
- none: false
163
143
  requirements:
164
- - - ! '>='
144
+ - - '>='
165
145
  - !ruby/object:Gem::Version
166
146
  version: '0'
167
147
  type: :development
168
148
  prerelease: false
169
149
  version_requirements: !ruby/object:Gem::Requirement
170
- none: false
171
150
  requirements:
172
- - - ! '>='
151
+ - - '>='
173
152
  - !ruby/object:Gem::Version
174
153
  version: '0'
175
- description: ! 'FriendlyId is the "Swiss Army bulldozer" of slugging and permalink
176
- plugins for
177
-
154
+ description: |
155
+ FriendlyId is the "Swiss Army bulldozer" of slugging and permalink plugins for
178
156
  Ruby on Rails. It allows you to create pretty URLs and work with human-friendly
179
-
180
157
  strings as if they were numeric ids for Active Record models.
181
-
182
- '
183
158
  email:
184
159
  - norman@njclarke.com
185
160
  - parndt@gmail.com
@@ -204,6 +179,7 @@ files:
204
179
  - gemfiles/Gemfile.rails-3.1.rb
205
180
  - gemfiles/Gemfile.rails-3.2.rb
206
181
  - lib/friendly_id.rb
182
+ - lib/friendly_id/.gitattributes
207
183
  - lib/friendly_id/base.rb
208
184
  - lib/friendly_id/configuration.rb
209
185
  - lib/friendly_id/finder_methods.rb
@@ -217,6 +193,7 @@ files:
217
193
  - lib/friendly_id/slug.rb
218
194
  - lib/friendly_id/slug_generator.rb
219
195
  - lib/friendly_id/slugged.rb
196
+ - lib/friendly_id/version.rb
220
197
  - lib/generators/friendly_id_generator.rb
221
198
  - test/base_test.rb
222
199
  - test/compatibility/ancestry/Gemfile
@@ -240,37 +217,33 @@ files:
240
217
  - test/slugged_test.rb
241
218
  - test/sti_test.rb
242
219
  homepage: http://github.com/norman/friendly_id
243
- licenses: []
244
- post_install_message: ! 'NOTE: FriendlyId 4.x breaks compatibility with 3.x. If you''re
245
- upgrading
246
-
220
+ licenses:
221
+ - MIT
222
+ metadata: {}
223
+ post_install_message: |+
224
+ NOTE: FriendlyId 4.x breaks compatibility with 3.x. If you're upgrading
247
225
  from 3.x, please see this document:
248
226
 
249
-
250
227
  http://rubydoc.info/github/norman/friendly_id/master/file/WhatsNew.md
251
228
 
252
-
253
- '
254
229
  rdoc_options: []
255
230
  require_paths:
256
231
  - lib
257
232
  required_ruby_version: !ruby/object:Gem::Requirement
258
- none: false
259
233
  requirements:
260
- - - ! '>='
234
+ - - '>='
261
235
  - !ruby/object:Gem::Version
262
236
  version: '0'
263
237
  required_rubygems_version: !ruby/object:Gem::Requirement
264
- none: false
265
238
  requirements:
266
- - - ! '>='
239
+ - - '>='
267
240
  - !ruby/object:Gem::Version
268
241
  version: '0'
269
242
  requirements: []
270
243
  rubyforge_project: friendly_id
271
- rubygems_version: 1.8.24
244
+ rubygems_version: 2.0.3
272
245
  signing_key:
273
- specification_version: 3
246
+ specification_version: 4
274
247
  summary: A comprehensive slugging and pretty-URL plugin.
275
248
  test_files: []
276
249
  has_rdoc: