slugs 1.1.0 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.rdoc +9 -5
- data/lib/slugs/active_record/base.rb +33 -36
- data/lib/slugs/active_record/non_translatable.rb +9 -16
- data/lib/slugs/active_record/relation.rb +3 -5
- data/lib/slugs/active_record/translatable.rb +20 -24
- data/lib/slugs/railtie.rb +1 -1
- data/lib/slugs/version.rb +1 -1
- data/test/dummy/app/models/simple.rb +1 -1
- data/test/dummy/app/models/translatable.rb +1 -1
- data/test/dummy/config/application.rb +2 -2
- data/test/dummy/config/database.yml +1 -1
- data/test/dummy/db/migrate/20130819183119_create_translatables.rb +3 -1
- data/test/dummy/db/migrate/20130819183257_create_translatable_translations.rb +1 -1
- data/test/dummy/db/schema.rb +4 -2
- data/test/dummy/log/development.log +52 -0
- data/test/dummy/log/test.log +9900 -0
- data/test/records_test.rb +70 -43
- data/test/test_helper.rb +4 -4
- metadata +33 -23
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/test.sqlite3 +0 -0
data/test/records_test.rb
CHANGED
@@ -2,12 +2,6 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class RecordsTest < ActiveSupport::TestCase
|
4
4
|
|
5
|
-
setup do
|
6
|
-
@without = Without.create(name: 'name')
|
7
|
-
@simple = Simple.create(name: 'name', age: 14)
|
8
|
-
@translatable = Translatable.create(name: 'translatable name', age: 20)
|
9
|
-
end
|
10
|
-
|
11
5
|
test "should not break validation" do
|
12
6
|
assert Without.new.valid?
|
13
7
|
assert Simple.new.valid?
|
@@ -15,64 +9,97 @@ class RecordsTest < ActiveSupport::TestCase
|
|
15
9
|
end
|
16
10
|
|
17
11
|
test "should not break models" do
|
18
|
-
assert_equal 'name',
|
19
|
-
assert_equal
|
20
|
-
assert_equal
|
12
|
+
assert_equal 'name', without.name
|
13
|
+
assert_equal without, Without.find('1')
|
14
|
+
assert_equal without, Without.find(1)
|
21
15
|
end
|
22
16
|
|
23
17
|
test "should create slug" do
|
24
|
-
assert_equal 'name',
|
25
|
-
assert_equal
|
26
|
-
|
27
|
-
assert_equal
|
18
|
+
assert_equal 'name', simple.slug
|
19
|
+
assert_equal simple, Simple.find('name')
|
20
|
+
|
21
|
+
assert_equal 'translatable-name', translatable.slug
|
22
|
+
assert_equal translatable, Translatable.find('translatable-name')
|
28
23
|
end
|
29
24
|
|
30
|
-
test "should
|
31
|
-
|
32
|
-
assert_equal 'new-name',
|
33
|
-
assert_equal
|
34
|
-
|
35
|
-
|
36
|
-
assert_equal
|
25
|
+
test "should update slug" do
|
26
|
+
simple.update name: 'new name'
|
27
|
+
assert_equal 'new-name', simple.slug
|
28
|
+
assert_equal simple, Simple.find('new-name')
|
29
|
+
|
30
|
+
translatable.update name: 'new translatable name'
|
31
|
+
assert_equal 'new-translatable-name', translatable.slug
|
32
|
+
assert_equal translatable, Translatable.find('new-translatable-name')
|
37
33
|
end
|
38
34
|
|
39
35
|
test "should not alter direct assigned slug" do
|
40
|
-
|
41
|
-
assert_equal 'direct slug',
|
42
|
-
assert_equal
|
43
|
-
|
44
|
-
|
45
|
-
assert_equal
|
36
|
+
simple.update slug: 'direct slug'
|
37
|
+
assert_equal 'direct slug', simple.slug
|
38
|
+
assert_equal simple, Simple.find('direct slug')
|
39
|
+
|
40
|
+
translatable.update slug: 'translatable direct slug'
|
41
|
+
assert_equal 'translatable direct slug', translatable.slug
|
42
|
+
assert_equal translatable, Translatable.find('translatable direct slug')
|
43
|
+
end
|
44
|
+
|
45
|
+
test "records should not be readonly" do
|
46
|
+
Simple.create name: 'editable'
|
47
|
+
assert_not Simple.find('editable').readonly?
|
48
|
+
|
49
|
+
Translatable.create name: 'editable'
|
50
|
+
assert_not Translatable.find('editable').readonly?
|
46
51
|
end
|
47
52
|
|
48
53
|
test "should assign index for same slugs" do
|
49
54
|
first = Simple.create(name: 'same', age: 34)
|
50
55
|
assert_equal 'same', first.slug
|
56
|
+
|
57
|
+
Simple.create(name: 'same-larger', age: 10) }
|
58
|
+
20.times { Simple.create(name: 'same', age: 10) }
|
59
|
+
|
51
60
|
second = Simple.create(name: 'same', age: 45)
|
52
|
-
assert_equal 'same-
|
61
|
+
assert_equal 'same-21', second.slug
|
53
62
|
third = Simple.create(name: 'same', age: 234)
|
54
|
-
assert_equal 'same-
|
63
|
+
assert_equal 'same-22', third.slug
|
55
64
|
|
56
|
-
first.
|
57
|
-
assert_equal '
|
58
|
-
second.
|
59
|
-
assert_equal '
|
60
|
-
third.
|
61
|
-
assert_equal 'other
|
65
|
+
first.update name: 'same'
|
66
|
+
assert_equal 'same', first.slug
|
67
|
+
second.update name: 'same'
|
68
|
+
assert_equal 'same-23', second.slug
|
69
|
+
third.update name: 'other'
|
70
|
+
assert_equal 'other', third.slug
|
62
71
|
|
63
72
|
first = Translatable.create(name: 'same', age: 34)
|
64
73
|
assert_equal 'same', first.slug
|
74
|
+
|
75
|
+
Simple.create(name: 'same-larger', age: 10) }
|
76
|
+
20.times { Translatable.create(name: 'same', age: 10) }
|
77
|
+
|
65
78
|
second = Translatable.create(name: 'same', age: 45)
|
66
|
-
assert_equal 'same-
|
79
|
+
assert_equal 'same-21', second.slug
|
67
80
|
third = Translatable.create(name: 'same', age: 234)
|
68
|
-
assert_equal 'same-
|
69
|
-
|
70
|
-
first.
|
71
|
-
assert_equal '
|
72
|
-
second.
|
73
|
-
assert_equal '
|
74
|
-
third.
|
75
|
-
assert_equal 'other
|
81
|
+
assert_equal 'same-22', third.slug
|
82
|
+
|
83
|
+
first.update name: 'same'
|
84
|
+
assert_equal 'same', first.slug
|
85
|
+
second.update name: 'same'
|
86
|
+
assert_equal 'same-23', second.slug
|
87
|
+
third.update name: 'other'
|
88
|
+
assert_equal 'other', third.slug
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def simple
|
94
|
+
@simple ||= Simple.create(name: 'name', age: 14)
|
95
|
+
end
|
96
|
+
|
97
|
+
def without
|
98
|
+
@without ||= Without.create(name: 'name')
|
99
|
+
end
|
100
|
+
|
101
|
+
def translatable
|
102
|
+
@translatable ||= Translatable.create(name: 'translatable name', age: 20)
|
76
103
|
end
|
77
104
|
|
78
105
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Configure Rails Environment
|
2
|
-
ENV[
|
2
|
+
ENV['RAILS_ENV'] = 'test'
|
3
3
|
|
4
|
-
require File.expand_path(
|
5
|
-
require
|
4
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
5
|
+
require 'rails/test_help'
|
6
6
|
|
7
7
|
Rails.backtrace_cleaner.remove_silencers!
|
8
8
|
|
@@ -11,7 +11,7 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
|
11
11
|
|
12
12
|
# Load fixtures from the engine
|
13
13
|
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
14
|
-
ActiveSupport::TestCase.fixture_path = File.expand_path(
|
14
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path('../fixtures', __FILE__)
|
15
15
|
end
|
16
16
|
|
17
17
|
# Load database
|
metadata
CHANGED
@@ -1,60 +1,76 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slugs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Museways
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: translatable_records
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: sqlite3
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- -
|
45
|
+
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
47
|
version: '0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- -
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
description: Inspired in friendly_id but more minimalistic.
|
42
56
|
email:
|
43
|
-
- contact@
|
57
|
+
- contact@museways.com
|
44
58
|
executables: []
|
45
59
|
extensions: []
|
46
60
|
extra_rdoc_files: []
|
47
61
|
files:
|
62
|
+
- MIT-LICENSE
|
63
|
+
- README.rdoc
|
64
|
+
- Rakefile
|
65
|
+
- lib/slugs.rb
|
48
66
|
- lib/slugs/active_record/base.rb
|
49
67
|
- lib/slugs/active_record/non_translatable.rb
|
50
68
|
- lib/slugs/active_record/relation.rb
|
51
69
|
- lib/slugs/active_record/translatable.rb
|
52
70
|
- lib/slugs/railtie.rb
|
53
71
|
- lib/slugs/version.rb
|
54
|
-
-
|
55
|
-
-
|
56
|
-
- Rakefile
|
57
|
-
- README.rdoc
|
72
|
+
- test/dummy/README.rdoc
|
73
|
+
- test/dummy/Rakefile
|
58
74
|
- test/dummy/app/assets/javascripts/application.js
|
59
75
|
- test/dummy/app/assets/stylesheets/application.css
|
60
76
|
- test/dummy/app/controllers/application_controller.rb
|
@@ -67,6 +83,7 @@ files:
|
|
67
83
|
- test/dummy/bin/bundle
|
68
84
|
- test/dummy/bin/rails
|
69
85
|
- test/dummy/bin/rake
|
86
|
+
- test/dummy/config.ru
|
70
87
|
- test/dummy/config/application.rb
|
71
88
|
- test/dummy/config/boot.rb
|
72
89
|
- test/dummy/config/database.yml
|
@@ -83,25 +100,20 @@ files:
|
|
83
100
|
- test/dummy/config/initializers/wrap_parameters.rb
|
84
101
|
- test/dummy/config/locales/en.yml
|
85
102
|
- test/dummy/config/routes.rb
|
86
|
-
- test/dummy/config.ru
|
87
|
-
- test/dummy/db/development.sqlite3
|
88
103
|
- test/dummy/db/migrate/20130819183013_create_simples.rb
|
89
104
|
- test/dummy/db/migrate/20130819183047_create_withouts.rb
|
90
105
|
- test/dummy/db/migrate/20130819183119_create_translatables.rb
|
91
106
|
- test/dummy/db/migrate/20130819183257_create_translatable_translations.rb
|
92
107
|
- test/dummy/db/schema.rb
|
93
|
-
- test/dummy/db/test.sqlite3
|
94
108
|
- test/dummy/log/development.log
|
95
109
|
- test/dummy/log/test.log
|
96
110
|
- test/dummy/public/404.html
|
97
111
|
- test/dummy/public/422.html
|
98
112
|
- test/dummy/public/500.html
|
99
113
|
- test/dummy/public/favicon.ico
|
100
|
-
- test/dummy/Rakefile
|
101
|
-
- test/dummy/README.rdoc
|
102
114
|
- test/records_test.rb
|
103
115
|
- test/test_helper.rb
|
104
|
-
homepage: https://github.com/
|
116
|
+
homepage: https://github.com/museways/slugs
|
105
117
|
licenses:
|
106
118
|
- MIT
|
107
119
|
metadata: {}
|
@@ -111,17 +123,17 @@ require_paths:
|
|
111
123
|
- lib
|
112
124
|
required_ruby_version: !ruby/object:Gem::Requirement
|
113
125
|
requirements:
|
114
|
-
- -
|
126
|
+
- - ">="
|
115
127
|
- !ruby/object:Gem::Version
|
116
128
|
version: '0'
|
117
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
130
|
requirements:
|
119
|
-
- -
|
131
|
+
- - ">="
|
120
132
|
- !ruby/object:Gem::Version
|
121
133
|
version: '0'
|
122
134
|
requirements: []
|
123
135
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.
|
136
|
+
rubygems_version: 2.2.2
|
125
137
|
signing_key:
|
126
138
|
specification_version: 4
|
127
139
|
summary: Slugs for Rails.
|
@@ -155,13 +167,11 @@ test_files:
|
|
155
167
|
- test/dummy/config/locales/en.yml
|
156
168
|
- test/dummy/config/routes.rb
|
157
169
|
- test/dummy/config.ru
|
158
|
-
- test/dummy/db/development.sqlite3
|
159
170
|
- test/dummy/db/migrate/20130819183013_create_simples.rb
|
160
171
|
- test/dummy/db/migrate/20130819183047_create_withouts.rb
|
161
172
|
- test/dummy/db/migrate/20130819183119_create_translatables.rb
|
162
173
|
- test/dummy/db/migrate/20130819183257_create_translatable_translations.rb
|
163
174
|
- test/dummy/db/schema.rb
|
164
|
-
- test/dummy/db/test.sqlite3
|
165
175
|
- test/dummy/log/development.log
|
166
176
|
- test/dummy/log/test.log
|
167
177
|
- test/dummy/public/404.html
|
Binary file
|
data/test/dummy/db/test.sqlite3
DELETED
Binary file
|