friendly_id 3.1.1.1 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog.md CHANGED
@@ -6,6 +6,15 @@ suggestions, ideas and improvements to FriendlyId.
6
6
  * Table of Contents
7
7
  {:toc}
8
8
 
9
+ ## 3.1.2 (2010-08-11)
10
+
11
+ * Fixed records being returned read-only. (Thanks Luis Lavena)
12
+ * Don't assume relations are subclasses of ActiveRecord::Base. This fixes using
13
+ FriendlyId with [Static Model](http://github.com/quirkey/static_model). (Thanks
14
+ Luis Lavena)
15
+ * Avoid checking for dependent scopes when no models are using the scopes feature.
16
+
17
+
9
18
  ## 3.1.1 (2010-07-30)
10
19
 
11
20
  * Fixed call to method on nil value for failing unfriendly finds (thanks [jlippiner](http://github.com/jlippiner))
data/Guide.md CHANGED
@@ -159,8 +159,6 @@ accents and other diacritics:
159
159
 
160
160
  There are special options for some languages:
161
161
 
162
- ### German Approximations
163
-
164
162
  class Person < ActiveRecord::Base
165
163
  has_friendly_id :name, :use_slug => true, :approximate_ascii => true,
166
164
  :ascii_approximation_options => :german
@@ -169,15 +167,9 @@ There are special options for some languages:
169
167
  @person.create :name => "Jürgen Müller"
170
168
  @person.friendly_id # will be "juergen-mueller"
171
169
 
172
- ### Spanish Approximations
173
-
174
- class Post < ActiveRecord::Base
175
- has_friendly_id :title, :use_slug => true, :approximate_ascii => true,
176
- :ascii_approximation_options => :spanish
177
- end
178
-
179
- @post.create(:title => "¡Feliz año!")
180
- @post.title # will be "feliz-anno"
170
+ FriendlyId supports whatever languages are supported by
171
+ [Babosa](https://github.com/norman/babosa); at the time of writing, this
172
+ includes German, Spanish and Serbian.
181
173
 
182
174
  ### Unicode Slugs
183
175
 
data/README.md CHANGED
@@ -17,7 +17,7 @@ instead of:
17
17
  FriendlyId offers many advanced features, including: slug history and
18
18
  versioning, scoped slugs, reserved words, custom slug generators, and
19
19
  excellent Unicode support. For complete information on using FriendlyId,
20
- please see the {http://norman.github.com/friendly_id/file.Guide.html FriendlyId Guide}.
20
+ please see the [FriendlyId Guide](http://norman.github.com/friendly_id/file.Guide.html).
21
21
 
22
22
  FriendlyId is compatible with Active Record 2.3.x and 3.0.
23
23
 
@@ -83,4 +83,12 @@ and add a test that reproduces the error you are experiencing.
83
83
 
84
84
  FriendlyId was created by Norman Clarke, Adrian Mugnolo, and Emilio Tagua.
85
85
 
86
+ If you like FriendlyId, please recommend us on Working With Rails:
87
+
88
+ * [http://bit.ly/recommend-norman](http://bit.ly/recommend-norman)
89
+ * [http://bit.ly/recommend-emilio](http://bit.ly/recommend-emilio)
90
+ * [http://bit.ly/recommend-adrian](http://bit.ly/recommend-adrian)
91
+
92
+ Thanks!
93
+
86
94
  Copyright (c) 2008-2010, released under the MIT license.
data/Rakefile CHANGED
@@ -51,11 +51,10 @@ end
51
51
 
52
52
  task :pushdocs do
53
53
  branch = `git branch | grep "*"`.chomp.gsub("* ", "")
54
- sh "git stash"
55
54
  sh "git checkout gh-pages"
55
+ sh "rm -rf FriendlyId ActiveRecord css js *.html"
56
56
  sh "cp -rp doc/* ."
57
57
  sh 'git commit -a -m "Regenerated docs"'
58
58
  sh "git push origin gh-pages"
59
59
  sh "git checkout #{branch}"
60
- sh "git stash apply"
61
60
  end
@@ -34,7 +34,9 @@ module FriendlyId
34
34
  end
35
35
 
36
36
  def child_scopes
37
- @child_scopes ||= associated_friendly_classes.select { |klass| klass.friendly_id_config.scopes_over?(configured_class) }
37
+ @child_scopes ||= associated_friendly_classes.select do |klass|
38
+ klass.friendly_id_config.scopes_over?(configured_class)
39
+ end
38
40
  end
39
41
 
40
42
  def custom_cache_column?
@@ -56,13 +58,10 @@ module FriendlyId
56
58
  end
57
59
 
58
60
  def associated_friendly_classes
59
- configured_class.reflect_on_all_associations.select { |assoc|
60
- assoc &&
61
- !assoc.options[:polymorphic] &&
62
- assoc.klass.uses_friendly_id?
61
+ configured_class.reflect_on_all_associations.compact.select { |assoc|
62
+ !assoc.options[:polymorphic] && assoc.klass.respond_to?(:friendly_id_config)
63
63
  }.map(&:klass)
64
64
  end
65
-
66
65
  end
67
66
  end
68
67
  end
@@ -36,7 +36,7 @@ module FriendlyId
36
36
  parse_ids!
37
37
  scope = some_friendly_scope
38
38
  if use_slugs? && @friendly_ids.present?
39
- scope = scope.scoped(:joins => Slug.table_name.to_sym)
39
+ scope = scope.scoped(:include => :slugs)
40
40
  if fc.scope?
41
41
  scope = scope.scoped(:conditions => {:slugs => {:scope => scope_val}})
42
42
  end
@@ -62,9 +62,8 @@ module FriendlyId
62
62
 
63
63
  def find_one_using_slug
64
64
  name, seq = id.to_s.parse_friendly_id
65
- slugs = Slug.table_name.to_sym
66
- scope = scoped(:conditions => {slugs => {:name => name, :sequence => seq}}, :joins => slugs)
67
- scope = scope.scoped(:conditions => {slugs => {:scope => scope_val}}) if fc.scope?
65
+ scope = scoped(:include => :slugs, :conditions => {:slugs => {:name => name, :sequence => seq}})
66
+ scope = scope.scoped(:conditions => {:slugs => {:scope => scope_val}}) if fc.scope?
68
67
  @result = scope.first(options)
69
68
  assign_status
70
69
  end
@@ -87,7 +87,7 @@ module FriendlyId
87
87
  elsif unfriendly_ids.present?
88
88
  clause = unfriendly
89
89
  end
90
- use_slugs ? joins(:slugs).where(clause) : where(clause)
90
+ use_slugs ? includes(:slugs).where(clause) : where(clause)
91
91
  end
92
92
 
93
93
  def slugged_conditions(ids)
@@ -84,6 +84,7 @@ module FriendlyId
84
84
  # Update the slugs for any model that is using this model as its
85
85
  # FriendlyId scope.
86
86
  def update_dependent_scopes
87
+ return unless friendly_id_config.class.scopes_used?
87
88
  if slugs(true).size > 1 && @new_friendly_id
88
89
  friendly_id_config.child_scopes.each do |klass|
89
90
  Slug.update_all "scope = '#{@new_friendly_id}'", ["sluggable_type = ? AND scope = ?",
@@ -39,8 +39,7 @@ 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 currently be
43
- # +:german+ or +:spanish+.
42
+ # Locale-type options for ASCII approximations.
44
43
  attr_accessor :ascii_approximation_options
45
44
 
46
45
  # The class that's using the configuration.
@@ -65,7 +64,7 @@ module FriendlyId
65
64
  attr_accessor :reserved_words
66
65
 
67
66
  # The method or relation to use as the friendly_id's scope.
68
- attr_accessor :scope
67
+ attr_reader :scope
69
68
 
70
69
  # The string that separates slug names from slug sequences. Defaults to "--".
71
70
  attr_accessor :sequence_separator
@@ -103,6 +102,24 @@ module FriendlyId
103
102
  [method, reserved_message % word] if reserved? word
104
103
  end
105
104
 
105
+ def scope=(scope)
106
+ self.class.scopes_used = true
107
+ @scope = scope
108
+ end
109
+
110
+ # This will be set if FriendlyId's scope feature is used in any model. It is here
111
+ # to provide a way to avoid invoking costly scope lookup methods when the scoped
112
+ # slug feature is not being used by any models.
113
+ def self.scopes_used=(val)
114
+ @scopes_used = !!val
115
+ end
116
+
117
+ # Are scoped slugs being used by any model?
118
+ # @see Configuration.scoped_used=
119
+ def self.scopes_used?
120
+ @scopes_used
121
+ end
122
+
106
123
  %w[approximate_ascii scope strip_non_ascii use_slug].each do |method|
107
124
  class_eval(<<-EOM)
108
125
  def #{method}?
@@ -2,8 +2,8 @@ module FriendlyId
2
2
  module Version
3
3
  MAJOR = 3
4
4
  MINOR = 1
5
- TINY = 1
6
- BUILD = 1
5
+ TINY = 2
6
+ BUILD = nil
7
7
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
8
8
  end
9
9
  end
@@ -113,6 +113,19 @@ module FriendlyId
113
113
  unfriendly_class.find(-1)
114
114
  end
115
115
  end
116
+
117
+ test "instances found by a single id should not be read-only" do
118
+ i = klass.find(instance.friendly_id)
119
+ assert !i.readonly?, "expected instance not to be readonly"
120
+ end
121
+
122
+ test "instances found by an array of ids should not be read-only" do
123
+ second = klass.create!(:name => "second_instance")
124
+ third = klass.create!(:name => "third_instance")
125
+ klass.find([instance.friendly_id, second.friendly_id]).each do |record|
126
+ assert !record.readonly?, "expected instance not to be readonly"
127
+ end
128
+ end
116
129
  end
117
130
  end
118
131
  end
@@ -107,12 +107,20 @@ module FriendlyId
107
107
  assert_match(/scope: badscope/, e.message)
108
108
  end
109
109
  end
110
-
110
+
111
111
  test "should update the sluggable field when a polymorphic relationship exists" do
112
112
  @site.update_attributes(:name => "Uptown Venue")
113
113
  assert_equal "Uptown Venue", @site.name
114
114
  end
115
115
 
116
+ test "should not assume that AR's reflect_on_all_associations with return AR classes" do
117
+ reflections = Resident.reflect_on_all_associations
118
+ reflections << Struct.new("Dummy", :options, :klass).new(:options => [], :klass => Struct)
119
+ Resident.expects(:reflect_on_all_associations).returns(reflections)
120
+ assert_nothing_raised do
121
+ Resident.friendly_id_config.send(:associated_friendly_classes)
122
+ end
123
+ end
116
124
  end
117
125
  end
118
- end
126
+ end
@@ -31,4 +31,3 @@ module FriendlyId
31
31
  end
32
32
  end
33
33
  end
34
-
metadata CHANGED
@@ -5,9 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 3
7
7
  - 1
8
- - 1
9
- - 1
10
- version: 3.1.1.1
8
+ - 2
9
+ version: 3.1.2
11
10
  platform: ruby
12
11
  authors:
13
12
  - Norman Clarke
@@ -17,7 +16,7 @@ autorequire:
17
16
  bindir: bin
18
17
  cert_chain: []
19
18
 
20
- date: 2010-07-30 00:00:00 -03:00
19
+ date: 2010-08-11 00:00:00 -03:00
21
20
  default_executable:
22
21
  dependencies:
23
22
  - !ruby/object:Gem::Dependency