capitalize_attributes 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +10 -8
- data/README.md +60 -0
- data/lib/capitalize_attributes/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90fb96bd3a8b701014b0a9b74e7de51aecf29c3fe81f18df11e72d7ae81c1b80
|
4
|
+
data.tar.gz: 496b4a89d010d565ca83602aabfd471606964ae20c5a88019d2a6de5218397b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13c94f232cc8505a38092c822ea203f4ea84b4cb94fe63de71fc7e66c8716b9a24263e3d3383b3245258d14413c4217bbbd73e47c5b42bcb1ceebac2f4072ab5
|
7
|
+
data.tar.gz: 1539a3ec5092b024248261ba319fbc9f63ca02b0d7978670f0a978e80ab1ceca274b3a3f8ef8e74c88d3e1665ff3cf37f162c8c23649a0d92c543826210be889
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [[0.1.1]] - 2020-10-21
|
10
|
+
### Added
|
11
|
+
- Added testing notes to the README file
|
12
|
+
|
9
13
|
## [[0.1.0]] - 2020-10-21
|
10
14
|
### Added
|
11
15
|
- Initial capitalization logic and spec
|
data/Gemfile.lock
CHANGED
@@ -1,24 +1,25 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
capitalize_attributes (0.1.
|
4
|
+
capitalize_attributes (0.1.1)
|
5
5
|
activemodel (>= 5.0, < 7.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (
|
11
|
-
activesupport (=
|
12
|
-
activesupport (
|
10
|
+
activemodel (6.0.3.2)
|
11
|
+
activesupport (= 6.0.3.2)
|
12
|
+
activesupport (6.0.3.2)
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
14
|
i18n (>= 0.7, < 2)
|
15
15
|
minitest (~> 5.1)
|
16
16
|
tzinfo (~> 1.1)
|
17
|
-
|
17
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
18
|
+
concurrent-ruby (1.1.7)
|
18
19
|
diff-lcs (1.3)
|
19
|
-
i18n (1.
|
20
|
+
i18n (1.8.5)
|
20
21
|
concurrent-ruby (~> 1.0)
|
21
|
-
minitest (5.
|
22
|
+
minitest (5.14.1)
|
22
23
|
rake (12.3.3)
|
23
24
|
rspec (3.8.0)
|
24
25
|
rspec-core (~> 3.8.0)
|
@@ -34,8 +35,9 @@ GEM
|
|
34
35
|
rspec-support (~> 3.8.0)
|
35
36
|
rspec-support (3.8.2)
|
36
37
|
thread_safe (0.3.6)
|
37
|
-
tzinfo (1.2.
|
38
|
+
tzinfo (1.2.7)
|
38
39
|
thread_safe (~> 0.1)
|
40
|
+
zeitwerk (2.4.0)
|
39
41
|
|
40
42
|
PLATFORMS
|
41
43
|
ruby
|
data/README.md
CHANGED
@@ -37,14 +37,74 @@ end
|
|
37
37
|
|
38
38
|
=> record = MyModel.new(first_name: "whisper", last_name: "SHOUT", city: "McCall")
|
39
39
|
=> record.validate
|
40
|
+
|
40
41
|
=> record.first_name
|
41
42
|
#> "Whisper"
|
43
|
+
|
42
44
|
=> record.last_name
|
43
45
|
#> "Shout"
|
46
|
+
|
44
47
|
=> record.city
|
45
48
|
#> "McCall"
|
46
49
|
```
|
47
50
|
|
51
|
+
## Testing
|
52
|
+
|
53
|
+
Capitalize Attributes comes with custom RSpec matchers. To make the matchers available in all your specs,
|
54
|
+
include the following in your `rails_helper` file:
|
55
|
+
```ruby
|
56
|
+
require "capitalize_attributes/matchers"
|
57
|
+
|
58
|
+
RSpec.configure do |config|
|
59
|
+
config.include CapitalizeAttributes::Matchers
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
Within your spec file, use the matchers like this:
|
64
|
+
```ruby
|
65
|
+
RSpec.describe MyModel do
|
66
|
+
it { is_expected.to capitalize_attribute(:first_name) }
|
67
|
+
it { is_expected.to capitalize_attribute(:last_name) }
|
68
|
+
it { is_expected.not_to capitalize_attribute(:password) }
|
69
|
+
end
|
70
|
+
```
|
71
|
+
|
72
|
+
### Testing in conjunction with the `strip_attributes` gem
|
73
|
+
|
74
|
+
The matchers provided with the `strip_attributes` gem are incompatible with this gem. To solve compatibility
|
75
|
+
problems, you can monkey-patch the matchers by placing the following inside your RSpec support folder:
|
76
|
+
```ruby
|
77
|
+
# spec/support/matchers/strip_attributes.rb
|
78
|
+
|
79
|
+
# Monkey patch to get StripAttributes working with Titleizable module
|
80
|
+
module StripAttributes
|
81
|
+
module Matchers
|
82
|
+
class StripAttributeMatcher
|
83
|
+
def matches?(subject)
|
84
|
+
@attributes.all? do |attribute|
|
85
|
+
@attribute = attribute
|
86
|
+
subject.send("#{@attribute}=", " string ")
|
87
|
+
subject.valid?
|
88
|
+
subject.send(@attribute).downcase == "string" and collapse_spaces?(subject)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def collapse_spaces?(subject)
|
95
|
+
return true if !@options[:collapse_spaces]
|
96
|
+
|
97
|
+
subject.send("#{@attribute}=", " string string ")
|
98
|
+
subject.valid?
|
99
|
+
subject.send(@attribute).downcase == "string string"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
```
|
105
|
+
This patch works with `strip_attributes` version 1.11.0. The only changes from the code in that gem
|
106
|
+
are the additions of `.downcase` in lines 10 and 21.
|
107
|
+
|
48
108
|
## Development
|
49
109
|
|
50
110
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capitalize_attributes
|
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
|
- Mark Oveson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|