friendly_id 3.1.5 → 3.1.6
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 +11 -0
- data/lib/friendly_id/active_record_adapter/finders.rb +1 -1
- data/lib/friendly_id/active_record_adapter/relation.rb +7 -6
- data/lib/friendly_id/version.rb +1 -1
- data/test/active_record_adapter/ar_test_helper.rb +6 -0
- data/test/active_record_adapter/scoped_model_test.rb +7 -0
- data/test/active_record_adapter/support/models.rb +6 -0
- metadata +9 -11
data/Changelog.md
CHANGED
@@ -6,6 +6,17 @@ suggestions, ideas and improvements to FriendlyId.
|
|
6
6
|
* Table of Contents
|
7
7
|
{:toc}
|
8
8
|
|
9
|
+
## 3.1.6 (2010-09-02)
|
10
|
+
|
11
|
+
* Fix missing sluggable type in AR3 slug query. This was a fairly major oversight, and if you
|
12
|
+
are using 3.1.4 or 3.1.5, you should update right away.
|
13
|
+
* Fix scoped queries when the model has a cached slug column. Bascially, the cached slug
|
14
|
+
is now completely ignored when a scope is configured.
|
15
|
+
|
16
|
+
## 3.1.5 (2010-09-01)
|
17
|
+
|
18
|
+
* Fix invalid empty symbol with 1.8.x.
|
19
|
+
|
9
20
|
## 3.1.4 (2010-09-01)
|
10
21
|
|
11
22
|
* Significantly improve performance of queries using slugs with no cache on AR3.
|
@@ -26,7 +26,7 @@ module FriendlyId
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def find_one
|
29
|
-
return find_one_with_cached_slug if cache_column?
|
29
|
+
return find_one_with_cached_slug if !fc.scope? && cache_column?
|
30
30
|
return find_one_with_slug if use_slugs?
|
31
31
|
@result = scoped(:conditions => ["#{table_name}.#{fc.column} = ?", id]).first(options)
|
32
32
|
assign_status
|
@@ -20,7 +20,7 @@ module FriendlyId
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def find_one
|
23
|
-
if fc.cache_column?
|
23
|
+
if fc.cache_column? && !fc.scope?
|
24
24
|
find_one_with_cached_slug
|
25
25
|
elsif fc.use_slugs?
|
26
26
|
find_one_with_slug
|
@@ -80,7 +80,7 @@ module FriendlyId
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def friendly_records(friendly_ids, unfriendly_ids)
|
83
|
-
use_slugs_table = fc.use_slugs? && (
|
83
|
+
use_slugs_table = fc.use_slugs? && (fc.scope? || !fc.cache_column?)
|
84
84
|
return find_some_using_slug(friendly_ids, unfriendly_ids) if use_slugs_table
|
85
85
|
column = fc.cache_column || fc.column
|
86
86
|
friendly = arel_table[column].in(friendly_ids)
|
@@ -99,18 +99,19 @@ module FriendlyId
|
|
99
99
|
|
100
100
|
def sluggable_ids_for(ids)
|
101
101
|
return [] if ids.empty?
|
102
|
-
fragment = "(slugs.name = %s AND slugs.sequence = %d)"
|
102
|
+
fragment = "(slugs.sluggable_type = %s AND slugs.name = %s AND slugs.sequence = %d)"
|
103
103
|
conditions = ids.inject(nil) do |clause, id|
|
104
104
|
name, seq = id.parse_friendly_id
|
105
|
-
string = fragment % [connection.quote(name), seq]
|
105
|
+
string = fragment % [connection.quote(klass.base_class), connection.quote(name), seq]
|
106
106
|
clause ? clause + " OR #{string}" : string
|
107
107
|
end
|
108
108
|
if fc.scope?
|
109
109
|
scope = connection.quote(friendly_id_scope)
|
110
110
|
conditions = "slugs.scope = %s AND (%s)" % [scope, conditions]
|
111
111
|
end
|
112
|
-
|
113
|
-
|
112
|
+
sql = "SELECT sluggable_id FROM slugs WHERE (%s)" % conditions
|
113
|
+
connection.select_values sql
|
114
|
+
end
|
114
115
|
|
115
116
|
def validate_expected_size!(ids, result)
|
116
117
|
expected_size =
|
data/lib/friendly_id/version.rb
CHANGED
@@ -76,6 +76,12 @@ class Resident < ActiveRecord::Base
|
|
76
76
|
has_friendly_id :name, :use_slug => true, :scope => :country
|
77
77
|
end
|
78
78
|
|
79
|
+
# Like resident, but has a cached slug
|
80
|
+
class Tourist < ActiveRecord::Base
|
81
|
+
belongs_to :country
|
82
|
+
has_friendly_id :name, :use_slug => true, :scope => :country
|
83
|
+
end
|
84
|
+
|
79
85
|
# A slugged model used as a scope
|
80
86
|
class Country < ActiveRecord::Base
|
81
87
|
has_many :people
|
@@ -22,6 +22,13 @@ module FriendlyId
|
|
22
22
|
User.delete_all
|
23
23
|
House.delete_all
|
24
24
|
Slug.delete_all
|
25
|
+
Tourist.delete_all
|
26
|
+
end
|
27
|
+
|
28
|
+
test "should not use cached slug column with scopes" do
|
29
|
+
@tourist = Tourist.create!(:name => "John Smith", :country => @usa)
|
30
|
+
@tourist2 = Tourist.create!(:name => "John Smith", :country => @canada)
|
31
|
+
assert_equal @canada, Tourist.find(@tourist2.friendly_id, :scope => @canada).country
|
25
32
|
end
|
26
33
|
|
27
34
|
test "a slugged model should auto-detect that it is being used as a parent scope" do
|
@@ -73,6 +73,12 @@ class CreateSupportModels < ActiveRecord::Migration
|
|
73
73
|
t.integer :country_id
|
74
74
|
end
|
75
75
|
|
76
|
+
create_table :tourists do |t|
|
77
|
+
t.string :name
|
78
|
+
t.integer :country_id
|
79
|
+
t.string :cached_slug
|
80
|
+
end
|
81
|
+
|
76
82
|
create_table :users do |t|
|
77
83
|
t.string :name
|
78
84
|
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
|
-
hash: 9
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 3
|
8
7
|
- 1
|
9
|
-
-
|
10
|
-
version: 3.1.
|
8
|
+
- 6
|
9
|
+
version: 3.1.6
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Norman Clarke
|
@@ -17,25 +16,24 @@ autorequire:
|
|
17
16
|
bindir: bin
|
18
17
|
cert_chain: []
|
19
18
|
|
20
|
-
date: 2010-09-
|
19
|
+
date: 2010-09-02 00:00:00 -03:00
|
21
20
|
default_executable:
|
22
21
|
dependencies:
|
23
22
|
- !ruby/object:Gem::Dependency
|
24
|
-
prerelease: false
|
25
|
-
type: :runtime
|
26
23
|
name: babosa
|
27
|
-
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
28
25
|
none: false
|
29
26
|
requirements:
|
30
27
|
- - ~>
|
31
28
|
- !ruby/object:Gem::Version
|
32
|
-
hash: 23
|
33
29
|
segments:
|
34
30
|
- 0
|
35
31
|
- 2
|
36
32
|
- 0
|
37
33
|
version: 0.2.0
|
38
|
-
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *id001
|
39
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"
|
40
38
|
email:
|
41
39
|
- norman@njclarke.com
|
@@ -118,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
116
|
requirements:
|
119
117
|
- - ">="
|
120
118
|
- !ruby/object:Gem::Version
|
121
|
-
hash:
|
119
|
+
hash: -182801105258368267
|
122
120
|
segments:
|
123
121
|
- 0
|
124
122
|
version: "0"
|
@@ -127,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
125
|
requirements:
|
128
126
|
- - ">="
|
129
127
|
- !ruby/object:Gem::Version
|
130
|
-
hash:
|
128
|
+
hash: -182801105258368267
|
131
129
|
segments:
|
132
130
|
- 0
|
133
131
|
version: "0"
|