much-slug 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/.l.yml +8 -0
- data/.rubocop.yml +3 -0
- data/.ruby-version +1 -0
- data/.t.yml +4 -0
- data/Gemfile +4 -2
- data/README.md +10 -20
- data/lib/much-slug.rb +11 -8
- data/lib/much-slug/activerecord.rb +48 -49
- data/lib/much-slug/has_slug_registry.rb +37 -24
- data/lib/much-slug/slug.rb +17 -15
- data/lib/much-slug/version.rb +3 -1
- data/log/{.gitkeep → .keep} +0 -0
- data/much-slug.gemspec +10 -7
- data/test/helper.rb +4 -11
- data/test/support/factory.rb +4 -3
- data/test/unit/activerecord_tests.rb +161 -126
- data/test/unit/has_slug_registry_tests.rb +43 -48
- data/test/unit/much-slug_tests.rb +7 -8
- data/test/unit/slug_tests.rb +62 -46
- metadata +33 -15
@@ -1,23 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert"
|
2
4
|
require "much-slug"
|
3
5
|
|
4
6
|
module MuchSlug
|
5
7
|
class UnitTests < Assert::Context
|
6
8
|
desc "MuchSlug"
|
7
|
-
|
8
|
-
@module = MuchSlug
|
9
|
-
end
|
10
|
-
subject{ @module }
|
9
|
+
subject{ MuchSlug }
|
11
10
|
|
12
11
|
should have_imeths :default_attribute, :default_preprocessor
|
13
12
|
should have_imeths :default_separator, :default_allow_underscores
|
14
13
|
should have_imeths :update_slugs
|
15
14
|
|
16
15
|
should "know its default settings" do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
assert_that(subject.default_attribute).equals("slug")
|
17
|
+
assert_that(subject.default_preprocessor).equals(:to_s)
|
18
|
+
assert_that(subject.default_separator).equals("-")
|
19
|
+
assert_that(subject.default_allow_underscores).equals(false)
|
21
20
|
end
|
22
21
|
end
|
23
22
|
end
|
data/test/unit/slug_tests.rb
CHANGED
@@ -1,104 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert"
|
2
4
|
require "much-slug/slug"
|
3
5
|
|
4
6
|
module MuchSlug::Slug
|
5
7
|
class UnitTests < Assert::Context
|
6
8
|
desc "MuchSlug::Slug"
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@args = {
|
11
|
-
:preprocessor => @no_op_pp,
|
12
|
-
:separator => @separator
|
13
|
-
}
|
9
|
+
subject{ unit_module }
|
10
|
+
|
11
|
+
let(:unit_module){ MuchSlug::Slug }
|
14
12
|
|
15
|
-
|
13
|
+
let(:no_op_pp){ proc{ |slug| slug } }
|
14
|
+
let(:separator){ "-" }
|
15
|
+
let(:kargs) do
|
16
|
+
{
|
17
|
+
preprocessor: no_op_pp,
|
18
|
+
separator: separator,
|
19
|
+
}
|
16
20
|
end
|
17
|
-
subject{ @module }
|
18
21
|
|
19
22
|
should have_imeths :new
|
20
23
|
|
21
24
|
should "always dup the given string" do
|
22
25
|
string = Factory.string
|
23
|
-
|
26
|
+
assert_that(subject.new(string, **kargs)).is_not(string)
|
24
27
|
end
|
25
28
|
|
26
29
|
should "not change strings that are made up of valid chars" do
|
27
30
|
string = Factory.string
|
28
|
-
|
31
|
+
assert_that(subject.new(string, **kargs)).equals(string)
|
29
32
|
|
30
|
-
string = "#{Factory.string}#{
|
31
|
-
|
33
|
+
string = "#{Factory.string}#{separator}#{Factory.string.upcase}"
|
34
|
+
assert_that(subject.new(string, **kargs)).equals(string)
|
32
35
|
end
|
33
36
|
|
34
37
|
should "turn invalid chars into a separator" do
|
35
|
-
string =
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
string =
|
39
|
+
Array
|
40
|
+
.new(Factory.integer(3)){
|
41
|
+
"#{Factory.string(3)}#{Factory.non_word_chars.sample}"\
|
42
|
+
"#{Factory.string(3)}"
|
43
|
+
}
|
44
|
+
.join(Factory.non_word_chars.sample)
|
45
|
+
assert_that(subject.new(string, **kargs))
|
46
|
+
.equals(string.gsub(/[^\w]+/, separator))
|
39
47
|
end
|
40
48
|
|
41
49
|
should "allow passing a custom preprocessor proc" do
|
42
|
-
string
|
43
|
-
|
44
|
-
|
45
|
-
assert_equal exp, subject.new(string, **args)
|
50
|
+
string = "#{Factory.string}#{separator}#{Factory.string.upcase}"
|
51
|
+
custom_kargs = kargs.merge(preprocessor: :downcase.to_proc)
|
52
|
+
assert_that(subject.new(string, **custom_kargs)).equals(string.downcase)
|
46
53
|
|
47
54
|
preprocessor = proc{ |s| s.gsub(/[A-Z]/, "a") }
|
48
|
-
|
49
|
-
|
50
|
-
|
55
|
+
custom_kargs = kargs.merge(preprocessor: preprocessor)
|
56
|
+
assert_that(subject.new(string, **custom_kargs))
|
57
|
+
.equals(preprocessor.call(string))
|
51
58
|
end
|
52
59
|
|
53
60
|
should "allow passing a custom separator" do
|
54
|
-
separator
|
55
|
-
|
61
|
+
separator = Factory.non_word_chars.sample
|
56
62
|
invalid_char = (Factory.non_word_chars - [separator]).sample
|
63
|
+
|
57
64
|
string = "#{Factory.string}#{invalid_char}#{Factory.string}"
|
58
|
-
|
59
|
-
|
65
|
+
assert_that(subject.new(string, **kargs.merge(separator: separator)))
|
66
|
+
.equals(string.gsub(/[^\w]+/, separator))
|
60
67
|
|
61
68
|
# it won"t change the separator in the strings
|
62
69
|
string = "#{Factory.string}#{separator}#{Factory.string}"
|
63
|
-
|
64
|
-
|
70
|
+
assert_that(subject.new(string, **kargs.merge(separator: separator)))
|
71
|
+
.equals(string)
|
65
72
|
|
66
73
|
# it will change the default separator now
|
67
|
-
string = "#{Factory.string}#{
|
68
|
-
|
69
|
-
|
74
|
+
string = "#{Factory.string}#{separator}#{Factory.string}"
|
75
|
+
assert_that(subject.new(string, **kargs.merge(separator: separator)))
|
76
|
+
.equals(string.gsub(separator, separator))
|
70
77
|
end
|
71
78
|
|
72
79
|
should "change underscores into its separator if not allowed" do
|
73
|
-
string = "#{Factory.string}#{
|
74
|
-
|
80
|
+
string = "#{Factory.string}#{separator}#{Factory.string}"
|
81
|
+
assert_that(subject.new(string, **kargs)).equals(string)
|
75
82
|
|
76
|
-
|
77
|
-
|
83
|
+
custom_kargs = kargs.merge(allow_underscores: false)
|
84
|
+
assert_that(subject.new(string, **custom_kargs))
|
85
|
+
.equals(string.gsub("_", separator))
|
78
86
|
|
79
|
-
|
87
|
+
custom_kargs = kargs.merge(allow_underscores: true)
|
88
|
+
assert_that(subject.new(string, **custom_kargs)).equals(string)
|
80
89
|
end
|
81
90
|
|
82
91
|
should "not allow multiple separators in a row" do
|
83
|
-
string = "#{Factory.string}#{
|
84
|
-
|
92
|
+
string = "#{Factory.string}#{separator}#{separator}#{Factory.string}"
|
93
|
+
assert_that(subject.new(string, **kargs))
|
94
|
+
.equals(string.gsub(/-{2,}/, separator))
|
85
95
|
|
86
96
|
# remove separators that were added from changing invalid chars
|
87
97
|
invalid_chars =
|
88
|
-
|
98
|
+
Array
|
99
|
+
.new(Factory.integer(3) + 1){
|
100
|
+
Factory.non_word_chars.sample
|
101
|
+
}
|
102
|
+
.join
|
89
103
|
string = "#{Factory.string}#{invalid_chars}#{Factory.string}"
|
90
|
-
|
104
|
+
assert_that(subject.new(string, **kargs))
|
105
|
+
.equals(string.gsub(/[^\w]+/, separator))
|
91
106
|
end
|
92
107
|
|
93
108
|
should "remove leading and trailing separators" do
|
94
|
-
string = "-#{Factory.string}#{
|
95
|
-
|
109
|
+
string = "-#{Factory.string}#{separator}#{Factory.string}-"
|
110
|
+
assert_that(subject.new(string, **kargs)).equals(string[1..-2])
|
96
111
|
|
97
112
|
# remove separators that were added from changing invalid chars
|
98
113
|
invalid_char = Factory.non_word_chars.sample
|
99
114
|
string =
|
100
|
-
"#{invalid_char}#{Factory.string}#{
|
101
|
-
|
115
|
+
"#{invalid_char}#{Factory.string}#{separator}"\
|
116
|
+
"#{Factory.string}#{invalid_char}"
|
117
|
+
assert_that(subject.new(string, **kargs)).equals(string[1..-2])
|
102
118
|
end
|
103
119
|
end
|
104
120
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: much-slug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
@@ -9,50 +9,64 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-01-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: ardb
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0.2
|
21
|
-
type: :
|
20
|
+
version: 0.29.2
|
21
|
+
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 0.2
|
27
|
+
version: 0.29.2
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: assert
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 2.
|
34
|
+
version: 2.19.3
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 2.
|
41
|
+
version: 2.19.3
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
43
|
+
name: much-style-guide
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 0.
|
48
|
+
version: 0.6.0
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.
|
55
|
+
version: 0.6.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: much-mixin
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.2.4
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.2.4
|
56
70
|
description: Friendly, human-readable identifiers for database records.
|
57
71
|
email:
|
58
72
|
- kelly@kellyredding.com
|
@@ -62,6 +76,10 @@ extensions: []
|
|
62
76
|
extra_rdoc_files: []
|
63
77
|
files:
|
64
78
|
- ".gitignore"
|
79
|
+
- ".l.yml"
|
80
|
+
- ".rubocop.yml"
|
81
|
+
- ".ruby-version"
|
82
|
+
- ".t.yml"
|
65
83
|
- Gemfile
|
66
84
|
- LICENSE
|
67
85
|
- README.md
|
@@ -70,7 +88,7 @@ files:
|
|
70
88
|
- lib/much-slug/has_slug_registry.rb
|
71
89
|
- lib/much-slug/slug.rb
|
72
90
|
- lib/much-slug/version.rb
|
73
|
-
- log/.
|
91
|
+
- log/.keep
|
74
92
|
- much-slug.gemspec
|
75
93
|
- test/helper.rb
|
76
94
|
- test/support/factory.rb
|
@@ -78,7 +96,6 @@ files:
|
|
78
96
|
- test/unit/has_slug_registry_tests.rb
|
79
97
|
- test/unit/much-slug_tests.rb
|
80
98
|
- test/unit/slug_tests.rb
|
81
|
-
- tmp/.gitkeep
|
82
99
|
homepage: https://github.com/redding/much-slug
|
83
100
|
licenses:
|
84
101
|
- MIT
|
@@ -91,14 +108,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
108
|
requirements:
|
92
109
|
- - "~>"
|
93
110
|
- !ruby/object:Gem::Version
|
94
|
-
version: '2.
|
111
|
+
version: '2.5'
|
95
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
113
|
requirements:
|
97
114
|
- - ">="
|
98
115
|
- !ruby/object:Gem::Version
|
99
116
|
version: '0'
|
100
117
|
requirements: []
|
101
|
-
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.7.6.2
|
102
120
|
signing_key:
|
103
121
|
specification_version: 4
|
104
122
|
summary: Friendly, human-readable identifiers for database records.
|