shoulda-lotus 0.0.4 → 0.0.5
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 +4 -4
- data/README.md +8 -2
- data/lib/shoulda/lotus/matchers/validate_inclusion_of_matcher.rb +44 -0
- data/lib/shoulda/lotus/matchers.rb +1 -0
- data/lib/shoulda/lotus/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 723616540123072d341e364b0a6a656c03c297b9
|
4
|
+
data.tar.gz: 11d7861df93066e92882773e5f9ea58d60e303cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebc69db52057fe77cc700c3eaddfeb0a064e4ca541778326cb0230959a82bb2eed77868afe7f237ca4f1be73bd3da493df96c5c3a2509bea5d87c73260c5a842
|
7
|
+
data.tar.gz: 2b9ee61080a1743fa2972f224a4a05294c24bc40d957758ef042a7d9fc9a8d1f71d9e882adc4f69b5e6c03ba10675826fd91827e4e2a0891264603392f62566b
|
data/README.md
CHANGED
@@ -32,6 +32,8 @@ class Person
|
|
32
32
|
attribute :password, type: String, size: 10
|
33
33
|
attribute :birthday, type: Date
|
34
34
|
attribute :created_at, type: DateTime
|
35
|
+
attribute :state, type: String, inclusion: %w(PR SC SP)
|
36
|
+
attribute :year, type: Integer, inclusion: 1979..1990
|
35
37
|
end
|
36
38
|
```
|
37
39
|
|
@@ -45,8 +47,8 @@ it { is_expected.to_not allow_value('leo-at-nospam.org').for(:email) }
|
|
45
47
|
it { is_expected.to validate_presence_of(:email) }
|
46
48
|
|
47
49
|
# size
|
48
|
-
it { is_expected.to
|
49
|
-
it { is_expected.to
|
50
|
+
it { is_expected.to validate_length_of(:name).is_at_least(5).is_at_most(50) }
|
51
|
+
it { is_expected.to validate_length_of(:password).is_equal_to(10) }
|
50
52
|
|
51
53
|
# coerces
|
52
54
|
it { is_expected.to coerce_attribute(:email).to(String) }
|
@@ -54,6 +56,10 @@ it { is_expected.to coerce_attribute(:name).to(String) }
|
|
54
56
|
it { is_expected.to coerce_attribute(:password).to(String) }
|
55
57
|
it { is_expected.to coerce_attribute(:birthday).to(Date) }
|
56
58
|
it { is_expected.to coerce_attribute(:created_at).to(DateTime) }
|
59
|
+
|
60
|
+
# inclusion
|
61
|
+
it { is_expected.to validate_inclusion_of(:state).in_array(%w(PR SC SP)) }
|
62
|
+
it { is_expected.to validate_inclusion_of(:year).in_array(1979..1990) }
|
57
63
|
```
|
58
64
|
|
59
65
|
## Contributing
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Shoulda
|
2
|
+
module Lotus
|
3
|
+
module Matchers
|
4
|
+
def validate_inclusion_of(attribute)
|
5
|
+
ValidateInclusionOfMatcher.new(attribute)
|
6
|
+
end
|
7
|
+
|
8
|
+
class ValidateInclusionOfMatcher
|
9
|
+
def initialize(attribute)
|
10
|
+
@attribute = attribute
|
11
|
+
end
|
12
|
+
|
13
|
+
def matches?(target)
|
14
|
+
value = nil
|
15
|
+
|
16
|
+
loop do
|
17
|
+
value = SecureRandom.hex
|
18
|
+
break unless @values.include? value
|
19
|
+
end
|
20
|
+
|
21
|
+
target.send("#{@attribute}=", value)
|
22
|
+
Matcher.new(target, @attribute, :inclusion).matches?
|
23
|
+
end
|
24
|
+
|
25
|
+
def description
|
26
|
+
"inclusion only '#{@values.inspect}' values on '#{@attribute}'"
|
27
|
+
end
|
28
|
+
|
29
|
+
def failure_message
|
30
|
+
"'#{@attribute}' is include only '#{@values.inspect}'"
|
31
|
+
end
|
32
|
+
|
33
|
+
def failure_message_when_negated
|
34
|
+
"'#{@attribute}' is not include only '#{@values.inspect}'"
|
35
|
+
end
|
36
|
+
|
37
|
+
def in_array(values)
|
38
|
+
@values = values
|
39
|
+
self
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'shoulda/lotus/matchers/coerce_attribute_matcher'
|
2
2
|
require 'shoulda/lotus/matchers/allow_value_matcher'
|
3
|
+
require 'shoulda/lotus/matchers/validate_inclusion_of_matcher'
|
3
4
|
require 'shoulda/lotus/matchers/validate_length_of_matcher'
|
4
5
|
require 'shoulda/lotus/matchers/validate_presence_of_matcher'
|
5
6
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoulda-lotus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leonardo Saraiva
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- lib/shoulda/lotus/matchers.rb
|
99
99
|
- lib/shoulda/lotus/matchers/allow_value_matcher.rb
|
100
100
|
- lib/shoulda/lotus/matchers/coerce_attribute_matcher.rb
|
101
|
+
- lib/shoulda/lotus/matchers/validate_inclusion_of_matcher.rb
|
101
102
|
- lib/shoulda/lotus/matchers/validate_length_of_matcher.rb
|
102
103
|
- lib/shoulda/lotus/matchers/validate_presence_of_matcher.rb
|
103
104
|
- lib/shoulda/lotus/version.rb
|
@@ -127,3 +128,4 @@ signing_key:
|
|
127
128
|
specification_version: 4
|
128
129
|
summary: Making tests easy on the fingers and eyes, but on lotus.
|
129
130
|
test_files: []
|
131
|
+
has_rdoc:
|