friendly_id4 4.0.0.beta6 → 4.0.0.pre
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/README.md +47 -68
- data/Rakefile +13 -108
- data/lib/friendly_id.rb +97 -117
- data/lib/friendly_id/scoped.rb +17 -116
- data/lib/friendly_id/slugged.rb +89 -183
- data/lib/friendly_id/test.rb +23 -0
- data/lib/friendly_id/test/generic.rb +84 -0
- data/lib/friendly_id/version.rb +9 -0
- data/test/core_test.rb +54 -16
- data/test/scoped_test.rb +39 -35
- data/test/slugged_test.rb +45 -64
- data/test/test_helper.rb +23 -0
- metadata +61 -125
- data/.gemtest +0 -0
- data/.gitignore +0 -11
- data/.yardopts +0 -4
- data/WhatsNew.md +0 -142
- data/bench.rb +0 -63
- data/friendly_id.gemspec +0 -31
- data/lib/friendly_id/base.rb +0 -134
- data/lib/friendly_id/configuration.rb +0 -78
- data/lib/friendly_id/finder_methods.rb +0 -20
- data/lib/friendly_id/history.rb +0 -64
- data/lib/friendly_id/migration.rb +0 -18
- data/lib/friendly_id/model.rb +0 -22
- data/lib/friendly_id/object_utils.rb +0 -40
- data/lib/friendly_id/reserved.rb +0 -46
- data/lib/friendly_id/slug.rb +0 -6
- data/lib/friendly_id/slug_sequencer.rb +0 -82
- data/lib/generators/friendly_id_generator.rb +0 -24
- data/test/base_test.rb +0 -54
- data/test/config/mysql.yml +0 -5
- data/test/config/mysql2.yml +0 -5
- data/test/config/postgres.yml +0 -6
- data/test/config/sqlite3.yml +0 -3
- data/test/configuration_test.rb +0 -27
- data/test/helper.rb +0 -90
- data/test/history_test.rb +0 -55
- data/test/object_utils_test.rb +0 -26
- data/test/reserved_test.rb +0 -26
- data/test/schema.rb +0 -56
- data/test/shared.rb +0 -118
- data/test/sti_test.rb +0 -48
data/test/shared.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
module FriendlyId
|
2
|
-
module Test
|
3
|
-
module Shared
|
4
|
-
|
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
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
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
|
24
|
-
|
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
|
34
|
-
|
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
|
43
|
-
end
|
44
|
-
|
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
|
53
|
-
|
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
|
57
|
-
|
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
|
61
|
-
|
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}
|
64
|
-
end
|
65
|
-
|
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
|
69
|
-
|
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
|
73
|
-
|
74
|
-
test "should be findable by themselves" do
|
75
|
-
with_instance_of(model_class) {|record| assert_equal record, model_class.find(record)}
|
76
|
-
end
|
77
|
-
|
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?}
|
88
|
-
end
|
89
|
-
|
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
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
data/test/sti_test.rb
DELETED
@@ -1,48 +0,0 @@
|
|
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
|