attribute_normalizer 1.0.0.pre1 → 1.0.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +4 -3
- data/lib/attribute_normalizer/model_inclusions.rb +1 -1
- data/lib/attribute_normalizer/normalizers/blank_normalizer.rb +1 -1
- data/lib/attribute_normalizer/normalizers/squish_normalizer.rb +9 -0
- data/lib/attribute_normalizer/rspec_matcher.rb +4 -0
- data/lib/attribute_normalizer.rb +2 -0
- data/spec/author_spec.rb +4 -0
- data/spec/connection_and_schema.rb +1 -0
- data/spec/models/author.rb +1 -0
- metadata +7 -3
data/README.textile
CHANGED
@@ -68,6 +68,7 @@ p. The following normalizers are already included with the +0.3 version of the g
|
|
68
68
|
* _:blank_ Will return _nil_ on empty strings
|
69
69
|
* _:phone_ Will strip out all non-digit characters and return nil on empty strings
|
70
70
|
* _:strip_ Will strip leading and trailing whitespace.
|
71
|
+
* _:squish_ Will strip leading and trailing whitespace and convert any consecutive spaces to one space each
|
71
72
|
|
72
73
|
p. And lets predefine some normalizers that we may use in other classes/models or that we don't want to clutter up our class/model's readability with.
|
73
74
|
|
@@ -144,16 +145,16 @@ h3. Rails 2
|
|
144
145
|
# ...
|
145
146
|
Spec::Runner.configure do |config|
|
146
147
|
# ...
|
147
|
-
config.include AttributeNormalizer::RSpecMatcher, :type => :
|
148
|
+
config.include AttributeNormalizer::RSpecMatcher, :type => :model
|
148
149
|
end</code></pre>
|
149
150
|
|
150
151
|
h3. Rails 3
|
151
152
|
|
152
153
|
<pre><code># spec/spec_helper.rb
|
153
154
|
# ...
|
154
|
-
|
155
|
+
RSpec.configure do |config|
|
155
156
|
# ...
|
156
|
-
config.include AttributeNormalizer::RSpecMatcher
|
157
|
+
config.include AttributeNormalizer::RSpecMatcher, :type => :model
|
157
158
|
end</code></pre>
|
158
159
|
|
159
160
|
p. _I will gladly take a patch to add a macro to Test::Unit if someone submits it._
|
@@ -21,6 +21,10 @@ module AttributeNormalizer
|
|
21
21
|
"#{@attribute} did not normalize as expected! \"#{@subject.send(@attribute)}\" != #{@to.nil? ? 'nil' : "\"#{@to}\""}"
|
22
22
|
end
|
23
23
|
|
24
|
+
def negative_failure_message
|
25
|
+
"expected #{@attribute} to not be normalized from #{@from.nil? ? 'nil' : "\"#{@from}\""} to #{@to.nil? ? 'nil' : "\"#{@to}\""}"
|
26
|
+
end
|
27
|
+
|
24
28
|
def from(value)
|
25
29
|
@from = value
|
26
30
|
self
|
data/lib/attribute_normalizer.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'attribute_normalizer/normalizers/blank_normalizer'
|
2
2
|
require 'attribute_normalizer/normalizers/phone_normalizer'
|
3
3
|
require 'attribute_normalizer/normalizers/strip_normalizer'
|
4
|
+
require 'attribute_normalizer/normalizers/squish_normalizer'
|
4
5
|
|
5
6
|
module AttributeNormalizer
|
6
7
|
|
@@ -41,6 +42,7 @@ module AttributeNormalizer
|
|
41
42
|
@normalizers[ :blank ] = AttributeNormalizer::Normalizers::BlankNormalizer
|
42
43
|
@normalizers[ :phone ] = AttributeNormalizer::Normalizers::PhoneNormalizer
|
43
44
|
@normalizers[ :strip ] = AttributeNormalizer::Normalizers::StripNormalizer
|
45
|
+
@normalizers[ :squish ] = AttributeNormalizer::Normalizers::SquishNormalizer
|
44
46
|
@default_normalizers = [ :strip, :blank ]
|
45
47
|
@default_attributes = {}
|
46
48
|
end
|
data/spec/author_spec.rb
CHANGED
@@ -12,8 +12,12 @@ describe Author do
|
|
12
12
|
it { should normalize_attribute(:first_name).from(' this ').to('this') }
|
13
13
|
it { should normalize_attribute(:first_name).from(' ').to('') }
|
14
14
|
|
15
|
+
# :squish normalizer
|
16
|
+
it { should normalize_attribute(:nickname).from(' this nickname ').to('this nickname') }
|
17
|
+
|
15
18
|
# :blank normalizer
|
16
19
|
it { should normalize_attribute(:last_name).from('').to(nil) }
|
20
|
+
it { should normalize_attribute(:last_name).from(' ').to(nil) }
|
17
21
|
it { should normalize_attribute(:last_name).from(' this ').to(' this ') }
|
18
22
|
|
19
23
|
# :phone normalizer
|
data/spec/models/author.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attribute_normalizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: -1876988175
|
4
5
|
prerelease: true
|
5
6
|
segments:
|
6
7
|
- 1
|
7
8
|
- 0
|
8
9
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.0.
|
10
|
+
- pre2
|
11
|
+
version: 1.0.0.pre2
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Michael Deering
|
@@ -15,7 +16,7 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date:
|
19
|
+
date: 2011-01-16 00:00:00 -07:00
|
19
20
|
default_executable:
|
20
21
|
dependencies: []
|
21
22
|
|
@@ -37,6 +38,7 @@ files:
|
|
37
38
|
- lib/attribute_normalizer/model_inclusions.rb
|
38
39
|
- lib/attribute_normalizer/normalizers/blank_normalizer.rb
|
39
40
|
- lib/attribute_normalizer/normalizers/phone_normalizer.rb
|
41
|
+
- lib/attribute_normalizer/normalizers/squish_normalizer.rb
|
40
42
|
- lib/attribute_normalizer/normalizers/strip_normalizer.rb
|
41
43
|
- lib/attribute_normalizer/rspec_matcher.rb
|
42
44
|
- rails/init.rb
|
@@ -67,6 +69,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
69
|
requirements:
|
68
70
|
- - ">="
|
69
71
|
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
70
73
|
segments:
|
71
74
|
- 0
|
72
75
|
version: "0"
|
@@ -75,6 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
78
|
requirements:
|
76
79
|
- - ">"
|
77
80
|
- !ruby/object:Gem::Version
|
81
|
+
hash: 25
|
78
82
|
segments:
|
79
83
|
- 1
|
80
84
|
- 3
|