friendly_id 4.0.0.beta12 → 4.0.0.beta13

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -43,7 +43,7 @@ The current docs can always be found
43
43
 
44
44
  cd my_app
45
45
 
46
- gem "friendly_id", "~> 4.0.0.beta8"
46
+ gem "friendly_id", "~> 4.0.0.beta12"
47
47
 
48
48
  rails generate scaffold user name:string slug:string
49
49
 
@@ -67,7 +67,7 @@ The current docs can always be found
67
67
  # If you're adding FriendlyId to an existing app and need
68
68
  # to generate slugs for existing users, do this from the
69
69
  # console, runner, or add a Rake task:
70
- User.all.map(&:save)
70
+ User.find_each(&:save)
71
71
 
72
72
 
73
73
  ## Benchmarks
data/WhatsNew.md CHANGED
@@ -90,6 +90,6 @@ strings to ASCII. It's very easy to include - just override
90
90
  ...
91
91
 
92
92
  def normalize_friendly_id(text)
93
- text.to_slug.normalize! :transliterate => :russian
93
+ text.to_slug.normalize! :transliterations => :russian
94
94
  end
95
95
  end
@@ -13,8 +13,8 @@ platform :ruby do
13
13
  gem "sqlite3", "~> 1.3.4"
14
14
  end
15
15
 
16
- gem "activerecord", "~> 3.1.0"
16
+ gem "activerecord", "~> 3.1.1"
17
17
  gem "minitest", "~> 2.4.0"
18
18
  gem "mocha", "~> 0.9.12"
19
- gem "railties", "~> 3.1.0"
19
+ gem "railties", "~> 3.1.1"
20
20
  gem "rake"
data/lib/friendly_id.rb CHANGED
@@ -81,7 +81,7 @@ In general, use slugs by default unless you know for sure you don't need them.
81
81
  module FriendlyId
82
82
 
83
83
  # The current version.
84
- VERSION = "4.0.0.beta12"
84
+ VERSION = "4.0.0.beta13"
85
85
 
86
86
  @mutex = Mutex.new
87
87
 
@@ -114,6 +114,7 @@ module FriendlyId
114
114
  #
115
115
  # For examples of this, see the source for {Scoped.included}.
116
116
  def self.extended(model_class)
117
+ return if model_class.respond_to? :friendly_id
117
118
  class << model_class
118
119
  alias relation_without_friendly_id relation
119
120
  end
@@ -83,4 +83,4 @@ current locale:
83
83
  end
84
84
  end
85
85
  end
86
- end
86
+ end
@@ -196,14 +196,15 @@ This functionality was in fact taken from earlier versions of FriendlyId.
196
196
  # slugs to be generated once, and then never updated.
197
197
  def should_generate_new_friendly_id?
198
198
  return true if new_record?
199
- slug_base = send friendly_id_config.base
199
+ slug_base = normalize_friendly_id send(friendly_id_config.base)
200
200
  separator = Regexp.escape friendly_id_config.sequence_separator
201
201
  slug_base != current_friendly_id.try(:sub, /#{separator}[\d]*\z/, '')
202
202
  end
203
203
 
204
204
  # Sets the slug.
205
+ # FIXME: This method sucks and the logic is pretty dubious.
205
206
  def set_slug(normalized_slug = nil)
206
- if should_generate_new_friendly_id?
207
+ if normalized_slug || should_generate_new_friendly_id?
207
208
  normalized_slug ||= normalize_friendly_id send(friendly_id_config.base)
208
209
  generator = friendly_id_config.slug_generator_class.new self, normalized_slug
209
210
  send "#{friendly_id_config.slug_column}=", generator.generate
data/test/helper.rb CHANGED
@@ -39,7 +39,7 @@ module FriendlyId
39
39
 
40
40
  def with_instance_of(*args)
41
41
  model_class = args.shift
42
- args[0] ||= {:name => "a"}
42
+ args[0] ||= {:name => "a b c"}
43
43
  transaction { yield model_class.create!(*args) }
44
44
  end
45
45
 
data/test/i18n_test.rb CHANGED
@@ -53,7 +53,7 @@ class I18nTest < MiniTest::Unit::TestCase
53
53
  journalist = Journalist.create!(:name => "John Smith")
54
54
  journalist.set_friendly_id("Juan Fulano", :es)
55
55
  journalist.save!
56
- assert_equal "john-smith", journalist.to_param
56
+ assert_equal "juan-fulano", journalist.slug_es
57
57
  I18n.with_locale(:es) do
58
58
  assert_equal "juan-fulano", journalist.to_param
59
59
  end
@@ -75,6 +75,24 @@ class I18nTest < MiniTest::Unit::TestCase
75
75
  end
76
76
  end
77
77
 
78
+ class RegressionTest < MiniTest::Unit::TestCase
79
+ include FriendlyId::Test
80
+
81
+ test "should not overwrite slugs on update_attributes" do
82
+ transaction do
83
+ journalist = Journalist.create!(:name => "John Smith")
84
+ journalist.set_friendly_id("Juan Fulano", :es)
85
+ journalist.save!
86
+ assert_equal "john-smith", journalist.to_param
87
+ journalist.update_attributes :name => "Johnny Smith"
88
+ assert_equal "johnny-smith", journalist.to_param
89
+ I18n.with_locale(:es) do
90
+ assert_equal "juan-fulano", journalist.to_param
91
+ end
92
+ end
93
+ end
94
+ end
95
+
78
96
  class ConfigurationTest < MiniTest::Unit::TestCase
79
97
  test "should add locale to slug column for a non-default locale" do
80
98
  I18n.with_locale :es do
@@ -98,4 +116,4 @@ class I18nTest < MiniTest::Unit::TestCase
98
116
  end
99
117
  end
100
118
  end
101
- end
119
+ end
data/test/slugged_test.rb CHANGED
@@ -28,6 +28,37 @@ class SluggedTest < MiniTest::Unit::TestCase
28
28
  end
29
29
  end
30
30
 
31
+ test "should allow validations on the slug" do
32
+ model_class = Class.new(ActiveRecord::Base) do
33
+ self.table_name = "articles"
34
+ extend FriendlyId
35
+ friendly_id :name, :use => :slugged
36
+ validates_length_of :slug, :maximum => 1
37
+ def self.name
38
+ "Article"
39
+ end
40
+ end
41
+ instance = model_class.new :name => "hello"
42
+ refute instance.valid?
43
+ end
44
+
45
+ test "should not break validates_uniqueness_of" do
46
+ model_class = Class.new(ActiveRecord::Base) do
47
+ self.table_name = "articles"
48
+ extend FriendlyId
49
+ friendly_id :name, :use => :slugged
50
+ validates_uniqueness_of :name
51
+ def self.name
52
+ "Article"
53
+ end
54
+ end
55
+ instance = model_class.create :name => "hello"
56
+ instance2 = model_class.create :name => "hello"
57
+ assert instance.valid?
58
+ refute instance2.valid?
59
+ end
60
+
61
+
31
62
  end
32
63
 
33
64
  class SlugGeneratorTest < MiniTest::Unit::TestCase
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: 4.0.0.beta12
4
+ version: 4.0.0.beta13
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-13 00:00:00.000000000 Z
12
+ date: 2011-10-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
16
- requirement: &70173663525760 !ruby/object:Gem::Requirement
16
+ requirement: &70219708818280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70173663525760
24
+ version_requirements: *70219708818280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activerecord
27
- requirement: &70173663524880 !ruby/object:Gem::Requirement
27
+ requirement: &70219708817420 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.1.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70173663524880
35
+ version_requirements: *70219708817420
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sqlite3
38
- requirement: &70173663524340 !ruby/object:Gem::Requirement
38
+ requirement: &70219708816820 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.3.4
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70173663524340
46
+ version_requirements: *70219708816820
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: minitest
49
- requirement: &70173663523820 !ruby/object:Gem::Requirement
49
+ requirement: &70219708815960 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.4.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70173663523820
57
+ version_requirements: *70219708815960
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: mocha
60
- requirement: &70173663523340 !ruby/object:Gem::Requirement
60
+ requirement: &70219708804840 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.9.12
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70173663523340
68
+ version_requirements: *70219708804840
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: ffaker
71
- requirement: &70173663522820 !ruby/object:Gem::Requirement
71
+ requirement: &70219708804320 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.8.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70173663522820
79
+ version_requirements: *70219708804320
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: maruku
82
- requirement: &70173663522180 !ruby/object:Gem::Requirement
82
+ requirement: &70219708803840 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 0.6.0
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70173663522180
90
+ version_requirements: *70219708803840
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: yard
93
- requirement: &70173663521720 !ruby/object:Gem::Requirement
93
+ requirement: &70219708803380 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 0.7.2
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70173663521720
101
+ version_requirements: *70219708803380
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: i18n
104
- requirement: &70173663521180 !ruby/object:Gem::Requirement
104
+ requirement: &70219708802920 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 0.6.0
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70173663521180
112
+ version_requirements: *70219708802920
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: simplecov
115
- requirement: &70173663520740 !ruby/object:Gem::Requirement
115
+ requirement: &70219708802520 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,7 +120,7 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *70173663520740
123
+ version_requirements: *70219708802520
124
124
  description: ! 'FriendlyId is the "Swiss Army bulldozer" of slugging and permalink
125
125
  plugins for
126
126
 
@@ -210,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
210
  version: 1.3.1
211
211
  requirements: []
212
212
  rubyforge_project: friendly_id
213
- rubygems_version: 1.8.6
213
+ rubygems_version: 1.8.5
214
214
  signing_key:
215
215
  specification_version: 3
216
216
  summary: A comprehensive slugging and pretty-URL plugin.