friendly_id 3.1.0.pre → 3.1.0

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.
data/Changelog.md CHANGED
@@ -6,15 +6,16 @@ suggestions, ideas and improvements to FriendlyId.
6
6
  * Table of Contents
7
7
  {:toc}
8
8
 
9
- ## 3.1.0 (NOT RELEASED)
9
+ ## 3.1.0 (2010-07-29)
10
10
 
11
11
  * Refactored/simplified Active Record 2 and 3 query code.
12
12
  * Better support for Active Record 3 finds and scopes.
13
13
  * Extract slug handling code into separate gem, [Babosa](http://github.com/norman/babosa).
14
- * :max-length option now uses bytes rather than characters.
14
+ * `:max-length` option now uses bytes rather than characters.
15
15
  * Fix quoting issue that prevented using a domain- or database-qualified column. (thanks James Cropcho)
16
16
  * Support for Active Record 2.2.x dropped; 2.3 or above is now required.
17
17
  * Fixed a few small errors on Postgres.
18
+ * Improved porability for Sequel and in-progress DataMapper adapter.
18
19
 
19
20
  ## 3.0.6 (2010-06-10)
20
21
 
@@ -93,7 +94,7 @@ fork, then this upgrade may causes issues.
93
94
  **Changes:**
94
95
 
95
96
  * Sequence separator can now be configured to something other than "--".
96
- * New option to pass arguments to {FriendlyId::SlugString#approximate_ascii!},
97
+ * New option to pass arguments to `FriendlyId::SlugString#approximate_ascii!`,
97
98
  allowing custom approximations specific to German or Spanish.
98
99
  * FriendlyId now queries against the cached_slug column, which improves performance.
99
100
  * {FriendlyId::SlugString} class added, allowing finer-grained control over
data/Guide.md CHANGED
@@ -6,7 +6,7 @@
6
6
  ## Overview
7
7
 
8
8
  FriendlyId is a Ruby gem which allows you to work with human-friendly strings
9
- as if they were numeric ids for ActiveRecord models. This facilitates replacing
9
+ as if they were numeric ids for Active Record models. This facilitates replacing
10
10
  "unfriendly" URL's like
11
11
 
12
12
  http://example.com/states/4323454
@@ -66,13 +66,13 @@ These features are explained in detail {file:Guide.md#features below}.
66
66
  ## Installation
67
67
 
68
68
  FriendlyId can be installed as a gem, or as a Rails plugin. It is compatible
69
- with Rails 2.2.x, 2.3.x. and 3.0.
69
+ with Rails 2.3.x. and 3.0.
70
70
 
71
71
  ### As a Gem
72
72
 
73
73
  gem install friendly_id
74
74
 
75
- #### Rails 2.2.x - 2.3.x
75
+ #### Rails 2.3.x
76
76
 
77
77
  After installing the gem, add an entry in environment.rb:
78
78
 
@@ -142,9 +142,8 @@ modify the slug text to make it more suitable for use in a URL:
142
142
  @city.create :name => "Viña del Mar"
143
143
  @city.friendly_id # will be "viña-del-mar"
144
144
 
145
- By default, the string is {FriendlyId::SlugString#downcase! downcased} and
146
- {FriendlyId::SlugString#clean! stripped}, {FriendlyId::SlugString#with_dashes! spaces are replaced with dashes},
147
- and {FriendlyId::SlugString#word_chars! non-word characters are removed}.
145
+ By default, the string is downcased and stripped, spaces are replaced with
146
+ dashes, and non-word characters other than "-" are removed.
148
147
 
149
148
  ### Replacing Accented Characters
150
149
 
@@ -361,8 +360,8 @@ Then, redo the slugs:
361
360
 
362
361
  rake friendly_id:redo_slugs MODEL=User
363
362
 
364
- FriendlyId will also query against the cache column if it's available, which
365
- can significantly improve the performance of many queries, particularly when
363
+ FriendlyId will automatically query against the cache column if it's available,
364
+ which significantly improves the performance of many queries, particularly when
366
365
  passing an array of friendly ids to #find.
367
366
 
368
367
  A few warnings when using this feature:
@@ -396,9 +395,13 @@ You can choose to allow `nil` friendly_ids via the `:allow_nil` config option:
396
395
 
397
396
  This works whether the model uses slugs or not.
398
397
 
399
- For slugged models, if the friendly_id text is `nil`, no slug will be created. This can be useful, for example, to only create slugs for published articles and avoid creating many slugs with sequences.
398
+ For slugged models, if the friendly_id text is `nil`, no slug will be created.
399
+ This can be useful, for example, to only create slugs for published articles
400
+ and avoid creating many slugs with sequences.
400
401
 
401
- For models that don't use slugs, this will make FriendlyId skip all its validations when the friendly_id text is `nil`. This can be useful, for example, if you wish to add the friendly_id value in an `:after_save` callback.
402
+ For models that don't use slugs, this will make FriendlyId skip all its
403
+ validations when the friendly_id text is `nil`. This can be useful, for
404
+ example, if you wish to add the friendly_id value in an `:after_save` callback.
402
405
 
403
406
  For non-slugged models, if you simply wish to skip friendly_ids's validations
404
407
  for some reason, you can override the `skip_friendly_id_validations` method.
@@ -489,6 +492,26 @@ slugs older than 45 days.
489
492
 
490
493
  # Misc tips
491
494
 
495
+ ## Default Scopes
496
+
497
+ Whether you're using FriendlyId or not, a good rule of thumb for default scopes
498
+ is to always use your model's table name. Otherwise any time you do a join, you
499
+ risk having queries fail because of duplicate column names - particularly for a
500
+ default scope like this one:
501
+
502
+ default_scope :order => "created_at DESC"
503
+
504
+ Instead, do this:
505
+
506
+ default_scope :order => = "#{quoted_table_name}.created_at DESC"
507
+
508
+ Or even better, unless you're using a custom primary key:
509
+
510
+ default_scope :order => = "#{quoted_table_name}.id DESC"
511
+
512
+ because sorting by a unique integer column is faster than sorting by a date
513
+ column.
514
+
492
515
  ## MySQL 5.0 or less
493
516
 
494
517
  Currently, the default FriendlyId migration will not work with MySQL 5.0 or less
@@ -547,4 +570,4 @@ enabled. But if it is, then your patches would be very welcome!
547
570
  find model using array of ids x1000 | 0.708 | 0.722 | 6.483 | 0.782 |
548
571
  find model using id, then to_param x1000 | 0.506 | 0.645 | 2.644 | 0.637 |
549
572
  ================================================================================================
550
- Total | 1.709 | 1.976 | 10.645 | 2.061 |
573
+ Total | 1.709 | 1.976 | 10.645 | 2.061 |
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  FriendlyId is the "Swiss Army bulldozer" of slugging and permalink plugins for
4
4
  Ruby on Rails. It allows you to create pretty URL's and work with
5
- human-friendly strings as if they were numeric ids for ActiveRecord models.
5
+ human-friendly strings as if they were numeric ids for Active Record models.
6
6
 
7
7
  Using FriendlyId, it's easy to make your application use URL's like:
8
8
 
@@ -19,7 +19,7 @@ versioning, scoped slugs, reserved words, custom slug generators, and
19
19
  excellent Unicode support. For complete information on using FriendlyId,
20
20
  please see the {http://norman.github.com/friendly_id/file.Guide.html FriendlyId Guide}.
21
21
 
22
- FriendlyId is compatible with Rails 2.3.x and 3.0.
22
+ FriendlyId is compatible with Active Record 2.3.x and 3.0.
23
23
 
24
24
  ## Rails Quickstart
25
25
 
@@ -48,6 +48,14 @@ FriendlyId is compatible with Rails 2.3.x and 3.0.
48
48
 
49
49
  GET http://0.0.0.0:3000/users/joe-schmoe
50
50
 
51
+ ## Sequel and DataMapper, too
52
+
53
+ FriendlyId has experimental support for Sequel. Support for Datamapper is
54
+ in progress. To find out more, check out the Github projects:
55
+
56
+ * [http://github.com/norman/friendly_id_sequel](http://github.com/norman/friendly_id_sequel)
57
+ * [http://github.com/myabc/friendly_id_datamapper](http://github.com/myabc/friendly_id_datamapper)
58
+
51
59
  ## Docs, Info and Support
52
60
 
53
61
  * [FriendlyId Guide](http://norman.github.com/friendly_id/file.Guide.html)
data/lib/friendly_id.rb CHANGED
@@ -1,13 +1,5 @@
1
1
  require "babosa"
2
2
  require "forwardable"
3
- require "active_support/core_ext/class/attribute_accessors"
4
- begin
5
- require "active_support/core_ext/object/blank"
6
- rescue MissingSourceFile
7
- # support for ActiveSupport < 2.3.5
8
- require "active_support/core_ext/blank"
9
- end
10
-
11
3
  require "friendly_id/slug_string"
12
4
  require "friendly_id/configuration"
13
5
  require "friendly_id/status"
@@ -63,7 +63,5 @@ module FriendlyId
63
63
  rescue NoMethodError
64
64
  raise "Class '%s' doesn't use FriendlyId" % klass.to_s
65
65
  end
66
-
67
66
  end
68
-
69
67
  end
@@ -39,8 +39,8 @@ module FriendlyId
39
39
  # Strip diacritics from Western characters.
40
40
  attr_accessor :approximate_ascii
41
41
 
42
- # Locale-type options for ASCII approximations. These can be any of the
43
- # values supported by {SlugString#approximate_ascii!}.
42
+ # Locale-type options for ASCII approximations. These currently be
43
+ # +:german+ or +:spanish+.
44
44
  attr_accessor :ascii_approximation_options
45
45
 
46
46
  # The class that's using the configuration.
@@ -86,6 +86,11 @@ module FriendlyId
86
86
  yield self if block_given?
87
87
  end
88
88
 
89
+ # This should be overridden by adapters that implement caching.
90
+ def cache_column?
91
+ false
92
+ end
93
+
89
94
  def reserved_words=(*words)
90
95
  @reserved_words = words.flatten.uniq
91
96
  end
@@ -110,4 +115,4 @@ module FriendlyId
110
115
 
111
116
  end
112
117
 
113
- end
118
+ end
@@ -0,0 +1,5 @@
1
+ begin
2
+ require 'friendly_id_datamapper'
3
+ rescue LoadError
4
+ raise "To use FriendlyId's DataMapper adapter, please `gem install friendly_id_datamapper`"
5
+ end
@@ -5,9 +5,11 @@ module FriendlyId
5
5
  # Experimental Sequel support. See: http://github.com/norman/friendly_id_sequel
6
6
  if app.config.generators.rails[:orm] == :sequel
7
7
  require "friendly_id/sequel"
8
+ # Experimental DataMapper support. See: http://github.com/myabc/friendly_id_datamapper
9
+ elsif app.config.generators.rails[:orm] == :data_mapper
10
+ require 'friendly_id/datamapper'
8
11
  else
9
- # Only Sequel and ActiveRecord are currently supported; AR is the default.
10
- # Want Datamapper support? http://github.com/norman/friendly_id/issues#issue/24
12
+ # AR is the default.
11
13
  require "friendly_id/active_record"
12
14
  end
13
15
  end
@@ -17,4 +19,4 @@ module FriendlyId
17
19
  end
18
20
 
19
21
  end
20
- end
22
+ end
@@ -49,6 +49,22 @@ module FriendlyId
49
49
  return RuntimeError
50
50
  end
51
51
 
52
+ def assert_validation_error
53
+ if validation_exceptions
54
+ assert_raise(*[validation_exceptions].flatten) do
55
+ yield
56
+ end
57
+ else # DataMapper does not raise Validation Errors
58
+ i = yield
59
+ if i.kind_of?(TrueClass) || i.kind_of?(FalseClass)
60
+ assert !i
61
+ else
62
+ instance = i
63
+ assert_not_empty instance.errors
64
+ end
65
+ end
66
+ end
67
+
52
68
  test "models should have a friendly id config" do
53
69
  assert_not_nil klass.friendly_id_config
54
70
  end
@@ -75,29 +91,29 @@ module FriendlyId
75
91
 
76
92
  test "instances should be findable by a numeric friendly_id" do
77
93
  instance = klass.send(create_method, :name => "206")
78
- assert_equal instance, klass.send(find_method, instance.friendly_id)
94
+ assert_equal instance, klass.send(find_method, "206")
79
95
  end
80
96
 
81
97
  test "creation should raise an error if the friendly_id text is reserved" do
82
- assert_raise(*[validation_exceptions].flatten) do
98
+ assert_validation_error do
83
99
  klass.send(create_method, :name => "new")
84
100
  end
85
101
  end
86
102
 
87
103
  test "creation should raise an error if the friendly_id text is an empty string" do
88
- assert_raise(*[validation_exceptions].flatten) do
104
+ assert_validation_error do
89
105
  klass.send(create_method, :name => "")
90
106
  end
91
107
  end
92
108
 
93
109
  test "creation should raise an error if the friendly_id text is a blank string" do
94
- assert_raise(*[validation_exceptions].flatten) do
110
+ assert_validation_error do
95
111
  klass.send(create_method, :name => " ")
96
112
  end
97
113
  end
98
114
 
99
115
  test "creation should raise an error if the friendly_id text is nil and allow_nil is false" do
100
- assert_raise(*[validation_exceptions].flatten) do
116
+ assert_validation_error do
101
117
  klass.send(create_method, :name => nil)
102
118
  end
103
119
  end
@@ -142,7 +158,12 @@ module FriendlyId
142
158
  test "should make a new slug if the friendly_id method value has changed" do
143
159
  instance.name = "Changed title"
144
160
  instance.send save_method
145
- assert_equal 2, instance.slugs(true).size
161
+ slugs = if instance.slugs.respond_to?(:reload)
162
+ instance.slugs.reload
163
+ else
164
+ instance.slugs(true)
165
+ end
166
+ assert_equal 2, slugs.size
146
167
  end
147
168
 
148
169
  test "should be able to reuse an old friendly_id without incrementing the sequence" do
@@ -197,7 +218,7 @@ module FriendlyId
197
218
  instance = klass.send(create_method, :name => "hello")
198
219
  assert instance.friendly_id
199
220
  instance.name = nil
200
- assert_raise(*[validation_exceptions].flatten) do
221
+ assert_validation_error do
201
222
  instance.send(save_method)
202
223
  end
203
224
  end
@@ -300,10 +321,14 @@ module FriendlyId
300
321
 
301
322
  test "should raise an error if the friendly_id text is reserved" do
302
323
  klass.friendly_id_config.stubs(:reserved_words).returns(["JOE"])
303
- assert_raise(*[validation_exceptions].flatten) do
304
- klass.send(create_method, :name => "Joe")
324
+ if validation_exceptions
325
+ assert_raise(*[validation_exceptions].flatten) do
326
+ klass.send(create_method, :name => "Joe")
327
+ end
328
+ else # DataMapper does not raise Validation Errors
329
+ instance = klass.send(create_method, :name => "Joe")
330
+ assert !instance.errors.empty?
305
331
  end
306
-
307
332
  end
308
333
 
309
334
  end
@@ -3,7 +3,7 @@ module FriendlyId
3
3
  MAJOR = 3
4
4
  MINOR = 1
5
5
  TINY = 0
6
- BUILD = "pre"
6
+ BUILD = nil
7
7
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly_id
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: true
4
+ prerelease: false
5
5
  segments:
6
6
  - 3
7
7
  - 1
8
8
  - 0
9
- - pre
10
- version: 3.1.0.pre
9
+ version: 3.1.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Norman Clarke
@@ -17,27 +16,13 @@ autorequire:
17
16
  bindir: bin
18
17
  cert_chain: []
19
18
 
20
- date: 2010-07-15 00:00:00 -03:00
19
+ date: 2010-07-29 00:00:00 -03:00
21
20
  default_executable:
22
21
  dependencies:
23
- - !ruby/object:Gem::Dependency
24
- name: activerecord
25
- prerelease: false
26
- requirement: &id001 !ruby/object:Gem::Requirement
27
- none: false
28
- requirements:
29
- - - ">="
30
- - !ruby/object:Gem::Version
31
- segments:
32
- - 2
33
- - 3
34
- version: "2.3"
35
- type: :runtime
36
- version_requirements: *id001
37
22
  - !ruby/object:Gem::Dependency
38
23
  name: babosa
39
24
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ requirement: &id001 !ruby/object:Gem::Requirement
41
26
  none: false
42
27
  requirements:
43
28
  - - ">="
@@ -48,7 +33,7 @@ dependencies:
48
33
  - 0
49
34
  version: 0.1.0
50
35
  type: :runtime
51
- version_requirements: *id002
36
+ version_requirements: *id001
52
37
  description: " FriendlyId is the \"Swiss Army bulldozer\" of slugging and permalink plugins\n for Ruby on Rails. It allows you to create pretty URL\xE2\x80\x99s and work with\n human-friendly strings as if they were numeric ids for ActiveRecord models.\n"
53
38
  email:
54
39
  - norman@njclarke.com
@@ -70,6 +55,7 @@ files:
70
55
  - lib/friendly_id/active_record_adapter/slugged_model.rb
71
56
  - lib/friendly_id/active_record_adapter/tasks.rb
72
57
  - lib/friendly_id/configuration.rb
58
+ - lib/friendly_id/datamapper.rb
73
59
  - lib/friendly_id/railtie.rb
74
60
  - lib/friendly_id/sequel.rb
75
61
  - lib/friendly_id/slug_string.rb
@@ -136,13 +122,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
122
  required_rubygems_version: !ruby/object:Gem::Requirement
137
123
  none: false
138
124
  requirements:
139
- - - ">"
125
+ - - ">="
140
126
  - !ruby/object:Gem::Version
141
127
  segments:
142
- - 1
143
- - 3
144
- - 1
145
- version: 1.3.1
128
+ - 0
129
+ version: "0"
146
130
  requirements: []
147
131
 
148
132
  rubyforge_project: friendly-id