strip_attributes 1.12.0 → 1.14.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: d1206dbea590ab400c94c1ff883cf3152d974b8ce58ff6f7dfaac0b0f7ce3ce1
4
+ data.tar.gz: 1b3a171cebeed352c7589f680314d26c1c2424c0333b68e8a7400731c39e6f69
5
5
  SHA512:
6
- metadata.gz: ef6d0002e6b59692efc5f40df76d8af73ec1da8ba1c2ff6887135fdfa4c10628fc635d8adf209872459d2c8bebda3820761a006d086984ef472323ded424e8a4
7
- data.tar.gz: d21ad0b0d749ad52ebb5c03b88476d922b9c2034189f01a92b892ddca33e821d7dea02c5d34a33078ef1c4892e3df55791a7f41d0e0f24a6bbc2a1bed66fddec
6
+ metadata.gz: 1f11fc77e63c2e534600e10eb24fa6f2b4c1823ffe6169442cc20fac5aba9f0fc7eb4dafcac79e17f3cb6b3913a604e721f25cf88e9aa7061944df756234cbb7
7
+ data.tar.gz: db16a98b6b74993e1badeffce9e8211e71c4eea82861078ec80f0dffb32f7eeabba01989f860692f4b26a22b86bed1301b8bd8534979e8308a0d77e17a441977
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.14.0"
3
3
  end
@@ -83,11 +83,11 @@ module StripAttributes
83
83
  # Necessary because Rails has removed the narrowing of attributes using :only
84
84
  # and :except on Base#attributes
85
85
  def self.narrow(attributes, options = {})
86
- if except = options[:except]
87
- except = Array(except).collect { |attribute| attribute.to_s }
86
+ if options[:except]
87
+ except = Array(options[:except]).map(&:to_s)
88
88
  attributes.except(*except)
89
- elsif only = options[:only]
90
- only = Array(only).collect { |attribute| attribute.to_s }
89
+ elsif options[:only]
90
+ only = Array(options[:only]).map(&:to_s)
91
91
  attributes.slice(*only)
92
92
  else
93
93
  attributes
@@ -95,10 +95,7 @@ module StripAttributes
95
95
  end
96
96
 
97
97
  def self.validate_options(options)
98
- if keys = options.keys
99
- unless (keys - VALID_OPTIONS).empty?
100
- raise ArgumentError, "Options does not specify #{VALID_OPTIONS} (#{options.keys.inspect})"
101
- end
102
- end
98
+ return if (options.keys - VALID_OPTIONS).empty?
99
+ raise ArgumentError, "Options does not specify #{VALID_OPTIONS} (#{options.keys.inspect})"
103
100
  end
104
101
  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.14.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: 2024-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '3.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '8.0'
22
+ version: '9.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '3.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '8.0'
32
+ version: '9.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: active_attr
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -48,22 +48,16 @@ dependencies:
48
48
  name: minitest
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - ">="
51
+ - - "~>"
52
52
  - !ruby/object:Gem::Version
53
53
  version: '5.0'
54
- - - "<"
55
- - !ruby/object:Gem::Version
56
- version: '6.0'
57
54
  type: :development
58
55
  prerelease: false
59
56
  version_requirements: !ruby/object:Gem::Requirement
60
57
  requirements:
61
- - - ">="
58
+ - - "~>"
62
59
  - !ruby/object:Gem::Version
63
60
  version: '5.0'
64
- - - "<"
65
- - !ruby/object:Gem::Version
66
- version: '6.0'
67
61
  - !ruby/object:Gem::Dependency
68
62
  name: minitest-matchers_vaccine
69
63
  requirement: !ruby/object:Gem::Requirement
@@ -129,7 +123,10 @@ files:
129
123
  homepage: https://github.com/rmm5t/strip_attributes
130
124
  licenses:
131
125
  - MIT
132
- metadata: {}
126
+ metadata:
127
+ bug_tracker_uri: https://github.com/rmm5t/strip_attributes/issues
128
+ changelog_uri: https://github.com/rmm5t/strip_attributes/blob/master/CHANGELOG.md
129
+ source_code_uri: https://github.com/rmm5t/strip_attributes
133
130
  post_install_message:
134
131
  rdoc_options: []
135
132
  require_paths:
@@ -145,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
142
  - !ruby/object:Gem::Version
146
143
  version: '0'
147
144
  requirements: []
148
- rubygems_version: 3.1.6
145
+ rubygems_version: 3.5.22
149
146
  signing_key:
150
147
  specification_version: 4
151
148
  summary: Whitespace cleanup for ActiveModel attributes