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.
@@ -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
-
@@ -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