friendly_id4 4.0.0.beta5 → 4.0.0.beta6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,6 +12,7 @@ instead of:
12
12
 
13
13
  http://example.com/states/4323454
14
14
 
15
+
15
16
  ## FriendlyId Features
16
17
 
17
18
  FriendlyId offers many advanced features, including: slug history and
@@ -51,8 +52,12 @@ FriendlyId is compatible with Active Record **3.0** and **3.1**.
51
52
 
52
53
  GET http://localhost:3000/users/joe-schmoe
53
54
 
55
+ ## Docs
56
+
57
+ The current docs can be found
58
+ [here](http://rdoc.info/github/norman/friendly_id/a4128af31d85ee29ad8f/frames).
54
59
 
55
- ### Future Compatibility
60
+ ## Future Compatibility
56
61
 
57
62
  FriendlyId will always remain compatible with the current release of Rails, and
58
63
  at least one stable release behind. That means that support for 3.0.x will not be
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ def rubies(&block)
11
11
  end
12
12
 
13
13
  def versions(&block)
14
- ["3.1.0.rc4", "3.0.9"].each do |version|
14
+ ["3.1.0.rc5", "3.0.9"].each do |version|
15
15
  old = ENV["AR"]
16
16
  ENV["AR"] = version
17
17
  yield
@@ -20,9 +20,10 @@ def versions(&block)
20
20
  end
21
21
 
22
22
  def adapters(&block)
23
- ["mysql", "postgres", "sqlite3"].each do |adapter|
23
+ ["mysql", "mysql2", "postgres", "sqlite3"].each do |adapter|
24
24
  old = ENV["DB"]
25
25
  ENV["DB"] = adapter
26
+ ENV["DB_VERSION"] = "~> 0.3.6" if adapter == "mysql2" && ENV["AR"] && ENV["AR"][0..2] >= "3.1"
26
27
  yield
27
28
  ENV["DB"] = old
28
29
  end
@@ -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.beta5"
84
+ VERSION = "4.0.0.beta6"
85
85
 
86
86
  @mutex = Mutex.new
87
87
 
@@ -125,6 +125,8 @@ module FriendlyId
125
125
 
126
126
  # Set global defaults for all models using FriendlyId.
127
127
  #
128
+ # The default defaults are to use the +:reserved+ module and nothing else.
129
+ #
128
130
  # @example
129
131
  # FriendlyId.defaults do |config|
130
132
  # config.base = :name
@@ -133,7 +135,7 @@ module FriendlyId
133
135
  def self.defaults(&block)
134
136
  @mutex.synchronize do
135
137
  @defaults = block if block_given?
138
+ @defaults ||= lambda {|config| config.use :reserved}
136
139
  end
137
- @defaults
138
140
  end
139
141
  end
@@ -13,8 +13,8 @@ module FriendlyId
13
13
  # of {FriendlyId::Configuration} to the block before evaluating other
14
14
  # arguments, so configuration values set in the block may be overwritten by
15
15
  # the arguments. This order was chosen to allow passing the same proc to
16
- # multiple models, while being able to override the values it sets. Here
17
- # is a contrived example:
16
+ # multiple models, while being able to override the values it sets. Here is
17
+ # a contrived example:
18
18
  #
19
19
  # $friendly_id_config_proc = Proc.new do |config|
20
20
  # config.base = :name
@@ -52,6 +52,33 @@ module FriendlyId
52
52
  # between multiple models that can't be well encapsulated by
53
53
  # {FriendlyId.defaults}.
54
54
  #
55
+ # === Order Method Calls in a Block vs Ordering Options
56
+ #
57
+ # When calling this method without a block, you may set the hash options in
58
+ # any order.
59
+ #
60
+ # However, when using block-style invocation, be sure to call
61
+ # FriendlyId::Configuration's {FriendlyId::Configuration#use use} method
62
+ # *prior* to the associated configuration options, because it will include
63
+ # modules into your class, and these modules in turn may add required
64
+ # configuration options to the +@friendly_id_configuraton+'s class:
65
+ #
66
+ # class Person < ActiveRecord::Base
67
+ # friendly_id do |config|
68
+ # # This will work
69
+ # config.use :slugged
70
+ # config.sequence_separator = ":"
71
+ # end
72
+ # end
73
+ #
74
+ # class Person < ActiveRecord::Base
75
+ # friendly_id do |config|
76
+ # # This will fail
77
+ # config.sequence_separator = ":"
78
+ # config.use :slugged
79
+ # end
80
+ # end
81
+ #
55
82
  # @option options [Symbol] :use The name of an addon to use. By default,
56
83
  # FriendlyId provides {FriendlyId::Slugged :slugged},
57
84
  # {FriendlyId::History :history}, {FriendlyId::Reserved :reserved}, and
@@ -94,8 +121,14 @@ module FriendlyId
94
121
  end
95
122
 
96
123
  # Returns the model class's {FriendlyId::Configuration friendly_id_config}.
124
+ # @note In the case of Single Table Inheritance (STI), this method will
125
+ # duplicate the parent class's FriendlyId::Configuration instance on first
126
+ # access. If you're concerned about thread safety, then be sure to invoke
127
+ # {#friendly_id} in your class for each model.
97
128
  def friendly_id_config
98
- @friendly_id_config
129
+ @friendly_id_config or begin
130
+ @friendly_id_config = base_class.friendly_id_config.dup
131
+ end
99
132
  end
100
133
  end
101
134
  end
@@ -42,7 +42,7 @@ record's friendly_id changes, your URL's won't break.
42
42
  has_many :friendly_id_slugs, :as => :sluggable, :dependent => :destroy
43
43
  before_save :build_friendly_id_slug, :if => lambda {|r| r.slug_sequencer.slug_changed?}
44
44
  scope :with_friendly_id, lambda {|id| includes(:friendly_id_slugs).where("friendly_id_slugs.slug = ?", id)}
45
- extend Finder
45
+ extend Finder
46
46
  end
47
47
  end
48
48
 
@@ -0,0 +1,5 @@
1
+ adapter: mysql2
2
+ database: friendly_id_test
3
+ username: root
4
+ hostname: localhost
5
+ encoding: utf8
@@ -10,7 +10,7 @@ end
10
10
  class CoreTest < MiniTest::Unit::TestCase
11
11
 
12
12
  include FriendlyId::Test
13
- include FriendlyId::Test::Shared
13
+ include FriendlyId::Test::Shared::Core
14
14
 
15
15
  def model_class
16
16
  Author
@@ -8,7 +8,7 @@ end
8
8
  class HistoryTest < MiniTest::Unit::TestCase
9
9
 
10
10
  include FriendlyId::Test
11
- include FriendlyId::Test::Shared
11
+ include FriendlyId::Test::Shared::Core
12
12
 
13
13
  def model_class
14
14
  Manual
@@ -32,6 +32,9 @@ module FriendlyId
32
32
 
33
33
  # This will be used to test column name quoting
34
34
  add_column :journalists, "strange name", :string
35
+
36
+ # This will be used to test STI
37
+ add_column :journalists, "type", :string
35
38
  end
36
39
 
37
40
  private
@@ -14,7 +14,7 @@ end
14
14
  class ScopedTest < MiniTest::Unit::TestCase
15
15
 
16
16
  include FriendlyId::Test
17
- include FriendlyId::Test::Shared
17
+ include FriendlyId::Test::Shared::Core
18
18
 
19
19
  def model_class
20
20
  Novel
@@ -2,72 +2,114 @@ module FriendlyId
2
2
  module Test
3
3
  module Shared
4
4
 
5
- test "finds should respect conditions" do
6
- with_instance_of(model_class) do |record|
7
- assert_raises(ActiveRecord::RecordNotFound) do
8
- model_class.where("1 = 2").find record.friendly_id
5
+ module Slugged
6
+ test "configuration should have a sequence_separator" do
7
+ assert !model_class.friendly_id_config.sequence_separator.empty?
8
+ end
9
+
10
+ test "should make a new slug if the friendly_id method value has changed" do
11
+ with_instance_of model_class do |record|
12
+ record.name = "Changed Value"
13
+ record.save!
14
+ assert_equal "changed-value", record.slug
9
15
  end
10
16
  end
11
- end
12
17
 
13
- test "should be findable by friendly id" do
14
- with_instance_of(model_class) {|record| assert model_class.find record.friendly_id}
15
- end
18
+ test "should increment the slug sequence for duplicate friendly ids" do
19
+ with_instance_of model_class do |record|
20
+ record2 = model_class.create! :name => record.name
21
+ assert record2.friendly_id.match(/2\z/)
22
+ end
23
+ end
16
24
 
17
- test "should be findable by id as integer" do
18
- with_instance_of(model_class) {|record| assert model_class.find record.id.to_i}
19
- end
25
+ test "should not add slug sequence on update after other conflicting slugs were added" do
26
+ with_instance_of model_class do |record|
27
+ old = record.friendly_id
28
+ record2 = model_class.create! :name => record.name
29
+ record.save!
30
+ record.reload
31
+ assert_equal old, record.to_param
32
+ end
33
+ end
20
34
 
21
- test "should be findable by id as string" do
22
- with_instance_of(model_class) {|record| assert model_class.find record.id.to_s}
35
+ test "should not increment sequence on save" do
36
+ with_instance_of model_class do |record|
37
+ record2 = model_class.create! :name => record.name
38
+ record2.active = !record2.active
39
+ record2.save!
40
+ assert record2.friendly_id.match(/2\z/)
41
+ end
42
+ end
23
43
  end
24
44
 
25
- test "should be findable by numeric friendly_id" do
26
- with_instance_of(model_class, :name => "206") {|record| assert model_class.find record.friendly_id}
27
- end
45
+ module Core
46
+ test "finds should respect conditions" do
47
+ with_instance_of(model_class) do |record|
48
+ assert_raises(ActiveRecord::RecordNotFound) do
49
+ model_class.where("1 = 2").find record.friendly_id
50
+ end
51
+ end
52
+ end
28
53
 
29
- test "to_param should return the friendly_id" do
30
- with_instance_of(model_class) {|record| assert_equal record.friendly_id, record.to_param}
31
- end
54
+ test "should be findable by friendly id" do
55
+ with_instance_of(model_class) {|record| assert model_class.find record.friendly_id}
56
+ end
32
57
 
33
- test "should be findable by themselves" do
34
- with_instance_of(model_class) {|record| assert_equal record, model_class.find(record)}
35
- end
58
+ test "should be findable by id as integer" do
59
+ with_instance_of(model_class) {|record| assert model_class.find record.id.to_i}
60
+ end
36
61
 
37
- test "updating record's other values should not change the friendly_id" do
38
- with_instance_of model_class do |record|
39
- old = record.friendly_id
40
- record.update_attributes! :active => false
41
- assert model_class.find old
62
+ test "should be findable by id as string" do
63
+ with_instance_of(model_class) {|record| assert model_class.find record.id.to_s}
42
64
  end
43
- end
44
65
 
45
- test "instances found by a single id should not be read-only" do
46
- with_instance_of(model_class) {|record| assert !model_class.find(record.friendly_id).readonly?}
47
- end
66
+ test "should be findable by numeric friendly_id" do
67
+ with_instance_of(model_class, :name => "206") {|record| assert model_class.find record.friendly_id}
68
+ end
48
69
 
49
- test "failing finds with unfriendly_id should raise errors normally" do
50
- assert_raises(ActiveRecord::RecordNotFound) {model_class.find 0}
51
- end
70
+ test "to_param should return the friendly_id" do
71
+ with_instance_of(model_class) {|record| assert_equal record.friendly_id, record.to_param}
72
+ end
52
73
 
53
- test "should return numeric id if the friendly_id is nil" do
54
- with_instance_of(model_class) do |record|
55
- record.expects(:friendly_id).returns(nil)
56
- assert_equal record.id.to_s, record.to_param
74
+ test "should be findable by themselves" do
75
+ with_instance_of(model_class) {|record| assert_equal record, model_class.find(record)}
57
76
  end
58
- end
59
77
 
60
- test "should return numeric id if the friendly_id is an empty string" do
61
- with_instance_of(model_class) do |record|
62
- record.expects(:friendly_id).returns("")
63
- assert_equal record.id.to_s, record.to_param
78
+ test "updating record's other values should not change the friendly_id" do
79
+ with_instance_of model_class do |record|
80
+ old = record.friendly_id
81
+ record.update_attributes! :active => false
82
+ assert model_class.find old
83
+ end
84
+ end
85
+
86
+ test "instances found by a single id should not be read-only" do
87
+ with_instance_of(model_class) {|record| assert !model_class.find(record.friendly_id).readonly?}
64
88
  end
65
- end
66
89
 
67
- test "should return numeric id if the friendly_id is blank" do
68
- with_instance_of(model_class) do |record|
69
- record.expects(:friendly_id).returns(" ")
70
- assert_equal record.id.to_s, record.to_param
90
+ test "failing finds with unfriendly_id should raise errors normally" do
91
+ assert_raises(ActiveRecord::RecordNotFound) {model_class.find 0}
92
+ end
93
+
94
+ test "should return numeric id if the friendly_id is nil" do
95
+ with_instance_of(model_class) do |record|
96
+ record.expects(:friendly_id).returns(nil)
97
+ assert_equal record.id.to_s, record.to_param
98
+ end
99
+ end
100
+
101
+ test "should return numeric id if the friendly_id is an empty string" do
102
+ with_instance_of(model_class) do |record|
103
+ record.expects(:friendly_id).returns("")
104
+ assert_equal record.id.to_s, record.to_param
105
+ end
106
+ end
107
+
108
+ test "should return numeric id if the friendly_id is blank" do
109
+ with_instance_of(model_class) do |record|
110
+ record.expects(:friendly_id).returns(" ")
111
+ assert_equal record.id.to_s, record.to_param
112
+ end
71
113
  end
72
114
  end
73
115
  end
@@ -10,50 +10,12 @@ end
10
10
  class SluggedTest < MiniTest::Unit::TestCase
11
11
 
12
12
  include FriendlyId::Test
13
- include FriendlyId::Test::Shared
13
+ include FriendlyId::Test::Shared::Core
14
+ include FriendlyId::Test::Shared::Slugged
14
15
 
15
16
  def model_class
16
17
  Journalist
17
18
  end
18
-
19
- test "configuration should have a sequence_separator" do
20
- assert !model_class.friendly_id_config.sequence_separator.empty?
21
- end
22
-
23
- test "should make a new slug if the friendly_id method value has changed" do
24
- with_instance_of model_class do |record|
25
- record.name = "Changed Value"
26
- record.save!
27
- assert_equal "changed-value", record.slug
28
- end
29
- end
30
-
31
- test "should increment the slug sequence for duplicate friendly ids" do
32
- with_instance_of model_class do |record|
33
- record2 = model_class.create! :name => record.name
34
- assert record2.friendly_id.match(/2\z/)
35
- end
36
- end
37
-
38
- test "should not add slug sequence on update after other conflicting slugs were added" do
39
- with_instance_of model_class do |record|
40
- old = record.friendly_id
41
- record2 = model_class.create! :name => record.name
42
- record.save!
43
- record.reload
44
- assert_equal old, record.to_param
45
- end
46
- end
47
-
48
- test "should not increment sequence on save" do
49
- with_instance_of model_class do |record|
50
- record2 = model_class.create! :name => record.name
51
- record2.active = !record2.active
52
- record2.save!
53
- assert record2.friendly_id.match(/2\z/)
54
- end
55
- end
56
-
57
19
  end
58
20
 
59
21
  class SlugSequencerTest < MiniTest::Unit::TestCase
@@ -0,0 +1,48 @@
1
+ require File.expand_path("../helper.rb", __FILE__)
2
+
3
+ class StiTest < MiniTest::Unit::TestCase
4
+
5
+ include FriendlyId::Test
6
+ include FriendlyId::Test::Shared::Core
7
+ include FriendlyId::Test::Shared::Slugged
8
+
9
+ class Journalist < ActiveRecord::Base
10
+ extend FriendlyId
11
+ friendly_id :name, :use => :slugged
12
+ end
13
+
14
+ class Editorialist < Journalist
15
+ end
16
+
17
+ def model_class
18
+ Editorialist
19
+ end
20
+
21
+ test "friendly_id should accept a base and a hash with single table inheritance" do
22
+ abstract_klass = Class.new(ActiveRecord::Base) do
23
+ extend FriendlyId
24
+ friendly_id :foo, :use => :slugged, :slug_column => :bar
25
+ end
26
+ klass = Class.new(abstract_klass)
27
+ assert klass < FriendlyId::Slugged
28
+ assert_equal :foo, klass.friendly_id_config.base
29
+ assert_equal :bar, klass.friendly_id_config.slug_column
30
+ end
31
+
32
+
33
+ test "friendly_id should accept a block with single table inheritance" do
34
+ abstract_klass = Class.new(ActiveRecord::Base) do
35
+ extend FriendlyId
36
+ friendly_id :foo do |config|
37
+ config.use :slugged
38
+ config.base = :foo
39
+ config.slug_column = :bar
40
+ end
41
+ end
42
+ klass = Class.new(abstract_klass)
43
+ assert klass < FriendlyId::Slugged
44
+ assert_equal :foo, klass.friendly_id_config.base
45
+ assert_equal :bar, klass.friendly_id_config.slug_column
46
+ end
47
+
48
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly_id4
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.beta5
4
+ version: 4.0.0.beta6
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-06 00:00:00.000000000 -03:00
12
+ date: 2011-08-11 00:00:00.000000000 -03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
- requirement: &70359454075760 !ruby/object:Gem::Requirement
17
+ requirement: &70168979272700 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '3.0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *70359454075760
25
+ version_requirements: *70168979272700
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: sqlite3
28
- requirement: &70359454075180 !ruby/object:Gem::Requirement
28
+ requirement: &70168979272160 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '1.3'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70359454075180
36
+ version_requirements: *70168979272160
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: cutest
39
- requirement: &70359454074720 !ruby/object:Gem::Requirement
39
+ requirement: &70168979271700 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 1.1.2
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70359454074720
47
+ version_requirements: *70168979271700
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: ffaker
50
- requirement: &70359454074320 !ruby/object:Gem::Requirement
50
+ requirement: &70168979271300 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70359454074320
58
+ version_requirements: *70168979271300
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: maruku
61
- requirement: &70359454073860 !ruby/object:Gem::Requirement
61
+ requirement: &70168979270840 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70359454073860
69
+ version_requirements: *70168979270840
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: yard
72
- requirement: &70359454073420 !ruby/object:Gem::Requirement
72
+ requirement: &70168979270420 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70359454073420
80
+ version_requirements: *70168979270420
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: mocha
83
- requirement: &70359454072980 !ruby/object:Gem::Requirement
83
+ requirement: &70168979270000 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,7 +88,7 @@ dependencies:
88
88
  version: '0'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *70359454072980
91
+ version_requirements: *70168979270000
92
92
  description: ! " FriendlyId is the \"Swiss Army bulldozer\" of slugging and permalink
93
93
  plugins\n for Ruby on Rails. It allows you to create pretty URL's and work with\n
94
94
  \ human-friendly strings as if they were numeric ids for ActiveRecord models.\n"
@@ -123,6 +123,7 @@ files:
123
123
  - lib/generators/friendly_id_generator.rb
124
124
  - test/base_test.rb
125
125
  - test/config/mysql.yml
126
+ - test/config/mysql2.yml
126
127
  - test/config/postgres.yml
127
128
  - test/config/sqlite3.yml
128
129
  - test/configuration_test.rb
@@ -135,6 +136,7 @@ files:
135
136
  - test/scoped_test.rb
136
137
  - test/shared.rb
137
138
  - test/slugged_test.rb
139
+ - test/sti_test.rb
138
140
  has_rdoc: true
139
141
  homepage: http://norman.github.com/friendly_id
140
142
  licenses: []