shoulda-lotus 0.0.4 → 0.0.5

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
  SHA1:
3
- metadata.gz: 54b064ad8875c42790c76901ea41644227071bc4
4
- data.tar.gz: 85413d801d4d8056555300361ac7da0a124e8a8d
3
+ metadata.gz: 723616540123072d341e364b0a6a656c03c297b9
4
+ data.tar.gz: 11d7861df93066e92882773e5f9ea58d60e303cc
5
5
  SHA512:
6
- metadata.gz: 26cdd15d98c2cd5bd8ace8ac7f05f281cb18417618e1ddcc2056e1d0f2206e84b20e177cfd6a4c28c68d795177f5e8cab5e6cf38deb9ad5e4c7b661216d1eaad
7
- data.tar.gz: 702ddcd98f91cee3c9fbc3e27c1d6a7439d59ec9f6cd6605c80848bfbd02376920a452bf4696ff5a69a10407373ab796af1e2a1d29518073eec8fab6889f5116
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 validate_length(:name).is_at_least(5).is_at_most(50) }
49
- it { is_expected.to validate_length(:password).is_equal_to(10) }
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
 
@@ -1,5 +1,5 @@
1
1
  module Shoulda
2
2
  module Lotus
3
- VERSION = '0.0.4'.freeze
3
+ VERSION = '0.0.5'.freeze
4
4
  end
5
5
  end
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
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-05 00:00:00.000000000 Z
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: