strip_attributes 1.12.0 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8e78767cc587a9037bf167a66d1d90d65f0d4cf0b38e67f160d43c04e66d34c
4
- data.tar.gz: '0348b7b1d3f81c068ce84277fa1da7213560af9f5a927aab0e23c4bdeca2b52f'
3
+ metadata.gz: 2a084a26dc5a486dfdc66bca645db741751cd1df037d433b130755b703bd24dd
4
+ data.tar.gz: 57043d564f688b990865a01394f85d2286a0b6e67796e965a3d298264a6d1ca7
5
5
  SHA512:
6
- metadata.gz: ef6d0002e6b59692efc5f40df76d8af73ec1da8ba1c2ff6887135fdfa4c10628fc635d8adf209872459d2c8bebda3820761a006d086984ef472323ded424e8a4
7
- data.tar.gz: d21ad0b0d749ad52ebb5c03b88476d922b9c2034189f01a92b892ddca33e821d7dea02c5d34a33078ef1c4892e3df55791a7f41d0e0f24a6bbc2a1bed66fddec
6
+ metadata.gz: 969f91697ba28733de84de1bb6f8f0fa512fb45d7d25c30640ce5dd51a5b5e035cee8e58adbf019fafa3d6c3a9e0179bf8734208eff613b197774614a9e4b8b9
7
+ data.tar.gz: bd9dd9e046b01f0281331ed58415a872c401b5d2fc8b3ee963cc88e90993ef89ed33b73ea148c8539e8a198438ff51b6c78d13c370c455dfcf834efb4946f2d0
data/README.md CHANGED
@@ -233,6 +233,7 @@ end
233
233
  ```ruby
234
234
  describe User do
235
235
  it { is_expected.to strip_attribute(:name).collapse_spaces }
236
+ it { is_expected.to strip_attribute(:name).replace_newlines }
236
237
  it { is_expected.to strip_attribute :email }
237
238
  it { is_expected.to strip_attributes(:name, :email) }
238
239
  it { is_expected.not_to strip_attribute :password }
@@ -245,6 +246,7 @@ end
245
246
  ```ruby
246
247
  class UserTest < ActiveSupport::TestCase
247
248
  should strip_attribute(:name).collapse_spaces
249
+ should strip_attribute(:name).replace_newlines
248
250
  should strip_attribute :email
249
251
  should strip_attributes(:name, :email)
250
252
  should_not strip_attribute :password
@@ -260,6 +262,7 @@ describe User do
260
262
 
261
263
  it "should strip attributes" do
262
264
  must strip_attribute(:name).collapse_spaces
265
+ must strip_attribute(:name).replace_newlines
263
266
  must strip_attribute :email
264
267
  must strip_attributes(:name, :email)
265
268
  wont strip_attribute :password
@@ -275,6 +278,7 @@ describe User do
275
278
  subject { User.new }
276
279
 
277
280
  must { strip_attribute(:name).collapse_spaces }
281
+ must { strip_attribute(:name).replace_newlines }
278
282
  must { strip_attribute :email }
279
283
  must { strip_attributes(:name, :email) }
280
284
  wont { strip_attribute :password }
data/Rakefile CHANGED
@@ -6,6 +6,6 @@ desc "Default: run unit tests."
6
6
  task default: :test
7
7
 
8
8
  Rake::TestTask.new(:test) do |t|
9
- t.libs << "lib" << "test"
9
+ t.libs << "test"
10
10
  t.pattern = "test/**/*_test.rb"
11
11
  end
@@ -33,7 +33,7 @@ module StripAttributes
33
33
  @attribute = attribute
34
34
  subject.send("#{@attribute}=", " string ")
35
35
  subject.valid?
36
- subject.send(@attribute) == "string" and collapse_spaces?(subject)
36
+ subject.send(@attribute) == "string" and collapse_spaces?(subject) and replace_newlines?(subject)
37
37
  end
38
38
  end
39
39
 
@@ -42,6 +42,11 @@ module StripAttributes
42
42
  self
43
43
  end
44
44
 
45
+ def replace_newlines
46
+ @options[:replace_newlines] = true
47
+ self
48
+ end
49
+
45
50
  def failure_message # RSpec 3.x
46
51
  "Expected whitespace to be #{expectation} from ##{@attribute}, but it was not"
47
52
  end
@@ -70,8 +75,17 @@ module StripAttributes
70
75
  def expectation(past = true)
71
76
  expectation = past ? "stripped" : "strip"
72
77
  expectation += past ? " and collapsed" : " and collapse" if @options[:collapse_spaces]
78
+ expectation += past ? " and replaced" : " and replace" if !@options[:replace_newlines]
73
79
  expectation
74
80
  end
81
+
82
+ def replace_newlines?(subject)
83
+ return true if !@options[:replace_newlines]
84
+
85
+ subject.send("#{@attribute}=", "string\nstring")
86
+ subject.valid?
87
+ subject.send(@attribute) == "string string"
88
+ end
75
89
  end
76
90
  end
77
91
  end
@@ -1,3 +1,3 @@
1
1
  module StripAttributes
2
- VERSION = "1.12.0"
2
+ VERSION = "1.13.0"
3
3
  end
@@ -18,6 +18,10 @@ class SampleMockRecord < Tableless
18
18
  attribute :collapsed
19
19
  attribute :uncollapsed
20
20
  strip_attributes only: [:collapsed], collapse_spaces: true
21
+
22
+ attribute :replaceable
23
+ attribute :unreplaceable
24
+ strip_attributes only: [:replaceable], replace_newlines: true
21
25
  end
22
26
 
23
27
  describe SampleMockRecord do
@@ -45,6 +49,14 @@ describe SampleMockRecord do
45
49
  it "should not collapse other attributes" do
46
50
  wont strip_attribute(:uncollapsed).collapse_spaces
47
51
  end
52
+
53
+ it "should replace replaceable attributes" do
54
+ must strip_attribute(:replaceable).replace_newlines
55
+ end
56
+
57
+ it "should not replace on other attributes" do
58
+ wont strip_attribute(:unreplaceable).replace_newlines
59
+ end
48
60
  else
49
61
  must { strip_attribute :stripped1 }
50
62
  must { strip_attribute :stripped2 }
@@ -55,6 +67,9 @@ describe SampleMockRecord do
55
67
 
56
68
  must { strip_attribute(:collapsed).collapse_spaces }
57
69
  wont { strip_attribute(:uncollapsed).collapse_spaces }
70
+
71
+ must { strip_attribute(:replaceable).replace_newlines }
72
+ wont { strip_attribute(:unreplaceable).replace_newlines }
58
73
  end
59
74
 
60
75
  it "should fail when testing for strip on an unstripped attribute" do
@@ -93,6 +108,24 @@ describe SampleMockRecord do
93
108
  end
94
109
  end
95
110
 
111
+ it "should fail when testing for replacement on an unreplaceable attribute" do
112
+ begin
113
+ assert_must replace_newlines(:unreplaceable)
114
+ assert false
115
+ rescue
116
+ assert true
117
+ end
118
+ end
119
+
120
+ it "should fail when testing for no replacement on a replaceable attribute" do
121
+ begin
122
+ assert_wont replace_newlines(:replaceable)
123
+ assert false
124
+ rescue
125
+ assert true
126
+ end
127
+ end
128
+
96
129
  it "should take a list of arguments" do
97
130
  must strip_attribute(:stripped1, :stripped2, :stripped3)
98
131
  wont strip_attribute(:unstripped1, :unstripped2, :unstripped3)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strip_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.0
4
+ version: 1.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan McGeary
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-20 00:00:00.000000000 Z
11
+ date: 2022-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -129,7 +129,10 @@ files:
129
129
  homepage: https://github.com/rmm5t/strip_attributes
130
130
  licenses:
131
131
  - MIT
132
- metadata: {}
132
+ metadata:
133
+ bug_tracker_uri: https://github.com/rmm5t/strip_attributes/issues
134
+ changelog_uri: https://github.com/rmm5t/strip_attributes/blob/master/CHANGELOG.md
135
+ source_code_uri: https://github.com/rmm5t/strip_attributes
133
136
  post_install_message:
134
137
  rdoc_options: []
135
138
  require_paths:
@@ -145,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
148
  - !ruby/object:Gem::Version
146
149
  version: '0'
147
150
  requirements: []
148
- rubygems_version: 3.1.6
151
+ rubygems_version: 3.3.12
149
152
  signing_key:
150
153
  specification_version: 4
151
154
  summary: Whitespace cleanup for ActiveModel attributes