friendly_id4 4.0.0.pre → 4.0.0.pre3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/ABOUT.md +139 -0
- data/Guide.md +405 -0
- data/README.md +65 -47
- data/Rakefile +12 -16
- data/bench.rb +71 -0
- data/friendly_id.gemspec +29 -0
- data/lib/friendly_id.rb +9 -116
- data/lib/friendly_id/base.rb +29 -0
- data/lib/friendly_id/configuration.rb +31 -0
- data/lib/friendly_id/finder_methods.rb +14 -0
- data/lib/friendly_id/history.rb +29 -0
- data/lib/friendly_id/migration.rb +17 -0
- data/lib/friendly_id/model.rb +22 -0
- data/lib/friendly_id/object_utils.rb +27 -0
- data/lib/friendly_id/scoped.rb +24 -2
- data/lib/friendly_id/slug_sequencer.rb +79 -0
- data/lib/friendly_id/slugged.rb +11 -84
- data/lib/friendly_id/version.rb +1 -1
- data/lib/generators/friendly_id_generator.rb +21 -0
- data/test/core_test.rb +23 -56
- data/test/helper.rb +41 -0
- data/test/history_test.rb +46 -0
- data/test/object_utils_test.rb +18 -0
- data/test/scoped_test.rb +30 -49
- data/test/shared.rb +47 -0
- data/test/slugged_test.rb +31 -52
- metadata +56 -22
- data/lib/friendly_id/test.rb +0 -23
- data/lib/friendly_id/test/generic.rb +0 -84
- data/test/test_helper.rb +0 -23
data/lib/friendly_id/test.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# Allow declarative test definitions inside modules.
|
2
|
-
class Module
|
3
|
-
def test(name, &block)
|
4
|
-
define_method("test_#{name.gsub(/[^a-z0-9]/i, "_")}".to_sym, &block)
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
# Use this to create models in your tests, rather than define
|
9
|
-
# a bunch of static models. This allows for much more
|
10
|
-
# flexbile and granular tests.
|
11
|
-
#
|
12
|
-
# @name The table name - make sure it is unique.
|
13
|
-
# @args The args that will be passed to +has_friendly_id+.
|
14
|
-
# @block The block that will be passed to +create_table+.
|
15
|
-
def make_model(name, *args, &block)
|
16
|
-
ActiveRecord::Migration.create_table(name, &block)
|
17
|
-
Class.new(ActiveRecord::Base) do
|
18
|
-
self.table_name = name
|
19
|
-
has_friendly_id(*args)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
require "friendly_id/test/generic"
|
@@ -1,84 +0,0 @@
|
|
1
|
-
module FriendlyId
|
2
|
-
module Test
|
3
|
-
# Tests for any model that implements FriendlyId. Any test that tests model
|
4
|
-
# features should include this module.
|
5
|
-
module Generic
|
6
|
-
|
7
|
-
def teardown
|
8
|
-
klass.delete_all
|
9
|
-
end
|
10
|
-
|
11
|
-
def instance
|
12
|
-
raise NotImplementedError
|
13
|
-
end
|
14
|
-
|
15
|
-
def klass
|
16
|
-
raise NotImplementedError
|
17
|
-
end
|
18
|
-
|
19
|
-
def other_class
|
20
|
-
raise NotImplementedError
|
21
|
-
end
|
22
|
-
|
23
|
-
test "model classes should have a friendly id config" do
|
24
|
-
assert_not_nil klass.friendly_id_config
|
25
|
-
end
|
26
|
-
|
27
|
-
test "finds should respect conditions" do
|
28
|
-
assert_raise ActiveRecord::RecordNotFound do
|
29
|
-
klass.find(instance.friendly_id, :conditions => "1 = 2")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
test "instances should have a friendly id" do
|
34
|
-
assert_not_nil instance.friendly_id
|
35
|
-
end
|
36
|
-
|
37
|
-
test "instances should be findable by their friendly id" do
|
38
|
-
assert_equal instance, klass.find(instance.friendly_id)
|
39
|
-
end
|
40
|
-
|
41
|
-
test "instances should be findable by their numeric id as an integer" do
|
42
|
-
assert_equal instance, klass.find(instance.id.to_i)
|
43
|
-
end
|
44
|
-
|
45
|
-
test "instances should be findable by their numeric id as a string" do
|
46
|
-
assert_equal instance, klass.find(instance.id.to_s)
|
47
|
-
end
|
48
|
-
|
49
|
-
test "instances should be findable by a numeric friendly_id" do
|
50
|
-
instance = klass.create! :name => "206"
|
51
|
-
assert_equal instance, klass.find(instance.friendly_id)
|
52
|
-
end
|
53
|
-
|
54
|
-
test "to_param should return the friendly_id" do
|
55
|
-
assert_equal instance.friendly_id, instance.to_param
|
56
|
-
end
|
57
|
-
|
58
|
-
test "should allow the same friendly_id across models" do
|
59
|
-
other_instance = other_class.create! :name => instance.name
|
60
|
-
assert_equal other_instance.friendly_id, instance.friendly_id
|
61
|
-
end
|
62
|
-
|
63
|
-
test "instances should be findable by themselves" do
|
64
|
-
assert_equal instance, klass.find(instance)
|
65
|
-
end
|
66
|
-
|
67
|
-
test "updating record's other values should not change the friendly_id" do
|
68
|
-
old = instance.friendly_id
|
69
|
-
instance.save
|
70
|
-
assert klass.find(old)
|
71
|
-
end
|
72
|
-
|
73
|
-
test "instances found by a single id should not be read-only" do
|
74
|
-
assert !klass.find(instance.friendly_id).readonly?, "expected instance not to be readonly"
|
75
|
-
end
|
76
|
-
|
77
|
-
test "failing finds with unfriendly_id should raise errors normally" do
|
78
|
-
assert_raise ActiveRecord::RecordNotFound do
|
79
|
-
klass.find(0)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
$VERBOSE = false
|
2
|
-
require "rubygems"
|
3
|
-
require "bundler/setup"
|
4
|
-
require "active_record"
|
5
|
-
require "active_support"
|
6
|
-
require "friendly_id"
|
7
|
-
require "friendly_id/test"
|
8
|
-
require "test/unit"
|
9
|
-
require "mocha"
|
10
|
-
|
11
|
-
ActiveRecord::Migration.verbose = false
|
12
|
-
|
13
|
-
# Change the connection args as you see fit to test against different adapters.
|
14
|
-
ActiveRecord::Base.establish_connection(
|
15
|
-
:adapter => "sqlite3",
|
16
|
-
:database => ":memory:"
|
17
|
-
)
|
18
|
-
|
19
|
-
# If you want to see the ActiveRecord log, invoke the tests using `rake test LOG=true`
|
20
|
-
if ENV["LOG"]
|
21
|
-
require "logger"
|
22
|
-
ActiveRecord::Base.logger = Logger.new($stdout)
|
23
|
-
end
|