strip_attributes 2.0.0 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbb6ecab9a2bccb06eeea8f6883037a3e1dbec6c5a84631cb06f48d5e77c2951
4
- data.tar.gz: 1071d1c2da5993e200f0961f4fa34abaedea271e6a7609e7a0bb5ab7ff478500
3
+ metadata.gz: 6edf6d84e674dcc78436bec4732122630b57b187744c3e8b57b6eb2ffed615cb
4
+ data.tar.gz: ef1ef5a59f057bda5c4f6df19f8b867d225e80f8db646c4fdb9339e6eff56ff0
5
5
  SHA512:
6
- metadata.gz: b97b24322b1f422a8c06380526323b27eaaf4aaf8da32679a06db83130c5042e0fc2054f9429c61739b536841c6829d3154755f6ba3d86d214d54ff76481f69b
7
- data.tar.gz: ea18ab3064114407e588b3029a8e43ff87a3e3d7bccd50bfbea20d679198ceaf6586f59a64a265146aa0bc99e396ba44cf8f03b1cef619249b1369d87305caff
6
+ metadata.gz: 915da1ef26816ff9d32886d44310ac77b927de8f0a49f67a76605d945779ec32a44ac30e0489e4ac9999757aea15dca2a738eeb69e03430a00fb1725cde2cc8c
7
+ data.tar.gz: f63d3b8dbc5555c787f0f4d5520f10f31f069ac5361dc67dacb4a237061370fc1e0d3e68bed868a3a261c14c4f2e5c340c6c91a2d3bc7a65c2b182e2b56300c5
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # StripAttributes
2
2
 
3
3
  [![Gem Version](http://img.shields.io/gem/v/strip_attributes.svg)](https://rubygems.org/gems/strip_attributes)
4
- [![Build Status](https://github.com/rmm5t/strip_attributes/workflows/CI/badge.svg?branch=master)](https://github.com/rmm5t/strip_attributes/actions?query=workflow%3ACI)
4
+ [![Build Status](https://github.com/rmm5t/strip_attributes/workflows/CI/badge.svg)](https://github.com/rmm5t/strip_attributes/actions/workflows/ci.yml)
5
5
  [![Gem Downloads](https://img.shields.io/gem/dt/strip_attributes.svg)](https://rubygems.org/gems/strip_attributes)
6
6
 
7
7
  StripAttributes is an ActiveModel extension that automatically strips all
@@ -236,6 +236,7 @@ describe User do
236
236
  it { is_expected.to strip_attribute(:name).replace_newlines }
237
237
  it { is_expected.to strip_attribute :email }
238
238
  it { is_expected.to strip_attributes(:name, :email) }
239
+ it { is_expected.to strip_attributes(:ticker).using("AAPL") }
239
240
  it { is_expected.not_to strip_attribute :password }
240
241
  it { is_expected.not_to strip_attributes(:password, :encrypted_password) }
241
242
  end
@@ -249,6 +250,7 @@ class UserTest < ActiveSupport::TestCase
249
250
  should strip_attribute(:name).replace_newlines
250
251
  should strip_attribute :email
251
252
  should strip_attributes(:name, :email)
253
+ should strip_attributes(:ticker).using("AAPL")
252
254
  should_not strip_attribute :password
253
255
  should_not strip_attributes(:password, :encrypted_password)
254
256
  end
@@ -265,6 +267,7 @@ describe User do
265
267
  must strip_attribute(:name).replace_newlines
266
268
  must strip_attribute :email
267
269
  must strip_attributes(:name, :email)
270
+ must strip_attributes(:ticker).using("AAPL")
268
271
  wont strip_attribute :password
269
272
  wont strip_attributes(:password, :encrypted_password)
270
273
  end
@@ -281,6 +284,7 @@ describe User do
281
284
  must { strip_attribute(:name).replace_newlines }
282
285
  must { strip_attribute :email }
283
286
  must { strip_attributes(:name, :email) }
287
+ must { strip_attributes(:ticker).using("AAPL") }
284
288
  wont { strip_attribute :password }
285
289
  wont { strip_attributes(:password, :encrypted_password) }
286
290
  end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "strip_attributes"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("rake", "rake")
@@ -1,6 +1,5 @@
1
1
  module StripAttributes
2
2
  module Matchers
3
-
4
3
  # Whitespace is stripped from the beginning and end of the attribute
5
4
  #
6
5
  # RSpec Examples:
@@ -20,7 +19,7 @@ module StripAttributes
20
19
  StripAttributeMatcher.new(attributes)
21
20
  end
22
21
 
23
- alias_method :strip_attributes, :strip_attribute
22
+ alias strip_attributes strip_attribute
24
23
 
25
24
  class StripAttributeMatcher
26
25
  def initialize(attributes)
@@ -31,12 +30,17 @@ module StripAttributes
31
30
  def matches?(subject)
32
31
  @attributes.all? do |attribute|
33
32
  @attribute = attribute
34
- subject.send("#{@attribute}=", " string ")
33
+ subject.send("#{@attribute}=", " #{value} ")
35
34
  subject.valid?
36
- subject.send(@attribute) == "string" and collapse_spaces?(subject) and replace_newlines?(subject)
35
+ subject.send(@attribute) == value and collapse_spaces?(subject) and replace_newlines?(subject)
37
36
  end
38
37
  end
39
38
 
39
+ def using(value)
40
+ @options[:value] = value
41
+ self
42
+ end
43
+
40
44
  def collapse_spaces
41
45
  @options[:collapse_spaces] = true
42
46
  self
@@ -47,44 +51,51 @@ module StripAttributes
47
51
  self
48
52
  end
49
53
 
50
- def failure_message # RSpec 3.x
54
+ # RSpec 3.x
55
+ def failure_message
51
56
  "Expected whitespace to be #{expectation} from ##{@attribute}, but it was not"
52
57
  end
53
- alias_method :failure_message_for_should, :failure_message # RSpec 1.2, 2.x, and minitest-matchers
58
+ alias failure_message_for_should failure_message # RSpec 1.2, 2.x, and minitest-matchers
54
59
 
55
- def failure_message_when_negated # RSpec 3.x
60
+ # RSpec 3.x
61
+ def failure_message_when_negated
56
62
  "Expected whitespace to remain on ##{@attribute}, but it was #{expectation}"
57
63
  end
58
- alias_method :failure_message_for_should_not, :failure_message_when_negated # RSpec 1.2, 2.x, and minitest-matchers
59
- alias_method :negative_failure_message, :failure_message_when_negated # RSpec 1.1
64
+ alias failure_message_for_should_not failure_message_when_negated # RSpec 1.2, 2.x, and minitest-matchers
65
+ alias negative_failure_message failure_message_when_negated # RSpec 1.1
60
66
 
61
67
  def description
62
- "#{expectation(false)} whitespace from #{@attributes.map {|el| "##{el}" }.to_sentence}"
68
+ attrs = @attributes.map { |attr| "##{attr}" }.to_sentence
69
+ "#{expectation(past: false)} whitespace from #{attrs}"
63
70
  end
64
71
 
65
72
  private
66
73
 
74
+ def value
75
+ @options[:value] || "string"
76
+ end
77
+
67
78
  def collapse_spaces?(subject)
68
- return true if !@options[:collapse_spaces]
79
+ return true unless @options[:collapse_spaces]
69
80
 
70
- subject.send("#{@attribute}=", " string string ")
81
+ subject.send("#{@attribute}=", " #{value} #{value} ")
71
82
  subject.valid?
72
- subject.send(@attribute) == "string string"
83
+ subject.send(@attribute) == "#{value} #{value}"
73
84
  end
74
85
 
75
- def expectation(past = true)
86
+ def expectation(past: true)
76
87
  expectation = past ? "stripped" : "strip"
77
88
  expectation += past ? " and collapsed" : " and collapse" if @options[:collapse_spaces]
78
- expectation += past ? " and replaced" : " and replace" if !@options[:replace_newlines]
89
+ expectation += past ? " and replaced" : " and replace" unless @options[:replace_newlines]
79
90
  expectation
80
91
  end
81
92
 
82
93
  def replace_newlines?(subject)
83
- return true if !@options[:replace_newlines]
94
+ return true unless @options[:replace_newlines]
84
95
 
85
- subject.send("#{@attribute}=", "string\nstring")
96
+ subject.send("#{@attribute}=", "#{value}\n#{value}")
86
97
  subject.valid?
87
- subject.send(@attribute) == "string string"
98
+ subject.send(@attribute) == "#{value} #{value}"
88
99
  end
89
100
  end
90
101
  end
@@ -1,3 +1,3 @@
1
1
  module StripAttributes
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1".freeze
3
3
  end
@@ -22,6 +22,13 @@ class SampleMockRecord < Tableless
22
22
  attribute :replaceable
23
23
  attribute :unreplaceable
24
24
  strip_attributes only: [:replaceable], replace_newlines: true
25
+
26
+ attribute :upcased
27
+ strip_attributes only: [:upcased]
28
+
29
+ def upcased=(value)
30
+ super((value.upcase if value))
31
+ end
25
32
  end
26
33
 
27
34
  describe SampleMockRecord do
@@ -57,19 +64,32 @@ describe SampleMockRecord do
57
64
  it "should not replace on other attributes" do
58
65
  wont strip_attribute(:unreplaceable).replace_newlines
59
66
  end
67
+
68
+ it "should not strip normalized attributes missing a custom value" do
69
+ wont strip_attribute(:upcased)
70
+ wont strip_attribute(:upcased).using("fOO")
71
+ end
72
+
73
+ it "should strip normalized attributes using a custom value" do
74
+ must strip_attribute(:upcased).using("BIG")
75
+ end
60
76
  else
61
- must { strip_attribute :stripped1 }
62
- must { strip_attribute :stripped2 }
63
- must { strip_attribute :stripped3 }
64
- wont { strip_attribute :unstripped1 }
65
- wont { strip_attribute :unstripped2 }
66
- wont { strip_attribute :unstripped3 }
67
-
68
- must { strip_attribute(:collapsed).collapse_spaces }
69
- wont { strip_attribute(:uncollapsed).collapse_spaces }
70
-
71
- must { strip_attribute(:replaceable).replace_newlines }
72
- wont { strip_attribute(:unreplaceable).replace_newlines }
77
+ must { strip_attribute :stripped1 }
78
+ must { strip_attribute :stripped2 }
79
+ must { strip_attribute :stripped3 }
80
+ wont { strip_attribute :unstripped1 }
81
+ wont { strip_attribute :unstripped2 }
82
+ wont { strip_attribute :unstripped3 }
83
+
84
+ must { strip_attribute(:collapsed).collapse_spaces }
85
+ wont { strip_attribute(:uncollapsed).collapse_spaces }
86
+
87
+ must { strip_attribute(:replaceable).replace_newlines }
88
+ wont { strip_attribute(:unreplaceable).replace_newlines }
89
+
90
+ wont { strip_attribute(:upcased) }
91
+ wont { strip_attribute(:upcased).using("fOO") }
92
+ must { strip_attribute(:upcased).using("BIG") }
73
93
  end
74
94
 
75
95
  it "should fail when testing for strip on an unstripped attribute" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strip_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan McGeary
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-24 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activemodel
@@ -111,6 +111,8 @@ files:
111
111
  - LICENSE.txt
112
112
  - README.md
113
113
  - Rakefile
114
+ - bin/console
115
+ - bin/rake
114
116
  - lib/strip_attributes.rb
115
117
  - lib/strip_attributes/matchers.rb
116
118
  - lib/strip_attributes/shoulda.rb
@@ -141,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
143
  - !ruby/object:Gem::Version
142
144
  version: '0'
143
145
  requirements: []
144
- rubygems_version: 3.6.3
146
+ rubygems_version: 3.7.1
145
147
  specification_version: 4
146
148
  summary: Whitespace cleanup for ActiveModel attributes
147
149
  test_files: