shoulda-lotus 0.0.0 → 0.0.3
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/.rspec +1 -1
- data/.travis.yml +2 -0
- data/README.md +30 -7
- data/lib/shoulda/lotus/matchers/allow_value_matcher.rb +40 -0
- data/lib/shoulda/lotus/matchers/validate_length_of_matcher.rb +68 -0
- data/lib/shoulda/lotus/matchers/validate_presence_of_matcher.rb +34 -0
- data/lib/shoulda/lotus/matchers.rb +10 -0
- data/lib/shoulda/lotus/version.rb +1 -1
- data/lib/shoulda/lotus.rb +1 -0
- data/shoulda-lotus.gemspec +3 -0
- metadata +35 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8a42596ac1614c3d15f72c7ba3dc69f4d129f7f
|
4
|
+
data.tar.gz: 5ee02bf7f61a5b4cda9a6528d675b71433fd32cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1761144e81387b172e85c8b72b2e8598defe3ac1b61794bc3b431eb6d21d7852ef63b3bb4389beb4aeab90d54d4513b5fbaabef3191edfc50f93711971565b2
|
7
|
+
data.tar.gz: 6b1e164632a8bcf75d4b78f624ce292dbc44aa6b3ab5145b6b69025846f90601d9c182f98277c87148649406035ca5c2ded8dfebb6b04224f05fca4469a2f90c
|
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
--format
|
1
|
+
--format progress
|
2
2
|
--color
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
# shoulda-lotus
|
1
|
+
# shoulda-lotus
|
2
|
+
[](http://badge.fury.io/rb/shoulda-lotus) [](https://travis-ci.org/mcorp/shoulda-lotus) [](https://codeclimate.com/github/mcorp/shoulda-lotus) [](https://codeclimate.com/github/mcorp/shoulda-lotus/coverage) [](https://gemnasium.com/mcorp/shoulda-lotus)
|
2
3
|
|
3
|
-
Making tests easy on the fingers and eyes, but
|
4
|
+
Making tests easy on the fingers and eyes, but on lotus.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -20,17 +21,39 @@ Or install it yourself as:
|
|
20
21
|
|
21
22
|
## Usage
|
22
23
|
|
23
|
-
|
24
|
+
### Entity
|
24
25
|
|
25
|
-
|
26
|
+
```ruby
|
27
|
+
class Person
|
28
|
+
include Lotus::Validations
|
29
|
+
|
30
|
+
attribute :email, presence: true, format: /@/
|
31
|
+
attribute :name, size: 5..50
|
32
|
+
attribute :password, size: 10
|
33
|
+
end
|
34
|
+
```
|
26
35
|
|
27
|
-
|
36
|
+
### Spec
|
37
|
+
```ruby
|
38
|
+
# allow_value
|
39
|
+
it { is_expected.to allow_value("leo@nospam.org").for(:email) }
|
40
|
+
it { is_expected.to_not allow_value('leo-at-nospam.org').for(:email) }
|
41
|
+
|
42
|
+
# presence
|
43
|
+
it { is_expected.to validate_presence_of(:email) }
|
28
44
|
|
29
|
-
|
45
|
+
# size
|
46
|
+
it { is_expected.to validate_length(:name).is_at_least(5).is_at_most(50) }
|
47
|
+
it { is_expected.to validate_length(:password).is_equal_to(10) }
|
48
|
+
```
|
30
49
|
|
31
50
|
## Contributing
|
32
51
|
|
33
|
-
|
52
|
+
1. Fork it
|
53
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
54
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
55
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
56
|
+
5. Create new Pull Request
|
34
57
|
|
35
58
|
|
36
59
|
## License
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Shoulda
|
2
|
+
module Lotus
|
3
|
+
module Matchers
|
4
|
+
def allow_value(value)
|
5
|
+
AllowValueMatcher.new(value)
|
6
|
+
end
|
7
|
+
|
8
|
+
class AllowValueMatcher
|
9
|
+
def initialize(value)
|
10
|
+
@value = value
|
11
|
+
end
|
12
|
+
|
13
|
+
def matches?(target)
|
14
|
+
@target = target
|
15
|
+
@target.send("#{@attribute}=", @value)
|
16
|
+
@target.valid?
|
17
|
+
|
18
|
+
!(@target.errors.for(@attribute).select { |error| error.attribute == @attribute.to_s && error.validation == :format }.size > 0)
|
19
|
+
end
|
20
|
+
|
21
|
+
def description
|
22
|
+
"allow '#{@value}' to be set to '#{@attribute}'"
|
23
|
+
end
|
24
|
+
|
25
|
+
def failure_message
|
26
|
+
"'#{@value}' is an invalid format for '#{@attribute}'"
|
27
|
+
end
|
28
|
+
|
29
|
+
def failure_message_when_negated
|
30
|
+
"'#{@value}' is a valid format for '#{@attribute}'"
|
31
|
+
end
|
32
|
+
|
33
|
+
def for(attribute)
|
34
|
+
@attribute = attribute
|
35
|
+
self
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Shoulda
|
2
|
+
module Lotus
|
3
|
+
module Matchers
|
4
|
+
def validate_length_of(attribute)
|
5
|
+
ValidateLengthOfMatcher.new(attribute)
|
6
|
+
end
|
7
|
+
|
8
|
+
class ValidateLengthOfMatcher
|
9
|
+
def initialize(attribute)
|
10
|
+
@attribute = attribute
|
11
|
+
end
|
12
|
+
|
13
|
+
def matches?(target)
|
14
|
+
errors = []
|
15
|
+
|
16
|
+
@target = target
|
17
|
+
|
18
|
+
@target.send("#{@attribute}=", '*' * (minimum - 1))
|
19
|
+
@target.valid?
|
20
|
+
errors << (@target.errors.for(@attribute).select { |error| error.attribute == @attribute.to_s && error.validation == :size }.size > 0)
|
21
|
+
|
22
|
+
@target.send("#{@attribute}=", '*' * (maximum + 1))
|
23
|
+
@target.valid?
|
24
|
+
errors << (@target.errors.for(@attribute).select { |error| error.attribute == @attribute.to_s && error.validation == :size }.size > 0)
|
25
|
+
|
26
|
+
errors.all? { |error| error }
|
27
|
+
end
|
28
|
+
|
29
|
+
def description
|
30
|
+
"'#{@attribute}' size between '#{@minimum}..#{@maximum}'"
|
31
|
+
end
|
32
|
+
|
33
|
+
def failure_message
|
34
|
+
"'#{@attribute}' is not between '#{@minimum}..#{@maximum}'"
|
35
|
+
end
|
36
|
+
|
37
|
+
def failure_message_when_negated
|
38
|
+
"'#{@attribute}' is between '#{@minimum}..#{@maximum}'"
|
39
|
+
end
|
40
|
+
|
41
|
+
def is_at_least(minimum)
|
42
|
+
@minimum = minimum
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
def is_at_most(maximum)
|
47
|
+
@maximum = maximum
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
def is_equal_to(limit)
|
52
|
+
@minimum, @maximum = limit
|
53
|
+
self
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def minimum
|
59
|
+
@minimum ||= 1
|
60
|
+
end
|
61
|
+
|
62
|
+
def maximum
|
63
|
+
@maximum ||= 1
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Shoulda
|
2
|
+
module Lotus
|
3
|
+
module Matchers
|
4
|
+
def validate_presence_of(attribute)
|
5
|
+
ValidatePresenceOfMatcher.new(attribute)
|
6
|
+
end
|
7
|
+
|
8
|
+
class ValidatePresenceOfMatcher
|
9
|
+
def initialize(attribute)
|
10
|
+
@attribute = attribute
|
11
|
+
end
|
12
|
+
|
13
|
+
def matches?(target)
|
14
|
+
@target = target
|
15
|
+
@target.valid?
|
16
|
+
|
17
|
+
@target.errors.for(@attribute).select { |error| error.attribute == @attribute.to_s && error.validation == :presence }.size > 0
|
18
|
+
end
|
19
|
+
|
20
|
+
def description
|
21
|
+
"require '#{@attribute}' to be set"
|
22
|
+
end
|
23
|
+
|
24
|
+
def failure_message
|
25
|
+
"'#{@attribute}' is a required attribute"
|
26
|
+
end
|
27
|
+
|
28
|
+
def failure_message_when_negated
|
29
|
+
"'#{@attribute}' is not a required attribute"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/shoulda/lotus.rb
CHANGED
data/shoulda-lotus.gemspec
CHANGED
@@ -21,4 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.10"
|
22
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
23
|
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency 'codeclimate-test-reporter'
|
25
|
+
|
26
|
+
spec.add_dependency 'lotus-validations', '~> 0.3.2'
|
24
27
|
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
|
+
version: 0.0.3
|
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-06-
|
11
|
+
date: 2015-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: codeclimate-test-reporter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: lotus-validations
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.3.2
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.3.2
|
55
83
|
description:
|
56
84
|
email:
|
57
85
|
- vyper@maneh.org
|
@@ -67,6 +95,10 @@ files:
|
|
67
95
|
- README.md
|
68
96
|
- Rakefile
|
69
97
|
- lib/shoulda/lotus.rb
|
98
|
+
- lib/shoulda/lotus/matchers.rb
|
99
|
+
- lib/shoulda/lotus/matchers/allow_value_matcher.rb
|
100
|
+
- lib/shoulda/lotus/matchers/validate_length_of_matcher.rb
|
101
|
+
- lib/shoulda/lotus/matchers/validate_presence_of_matcher.rb
|
70
102
|
- lib/shoulda/lotus/version.rb
|
71
103
|
- shoulda-lotus.gemspec
|
72
104
|
homepage: https://github.com/mcorp/shoulda-lotus
|
@@ -89,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
121
|
version: '0'
|
90
122
|
requirements: []
|
91
123
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.4.
|
124
|
+
rubygems_version: 2.4.8
|
93
125
|
signing_key:
|
94
126
|
specification_version: 4
|
95
127
|
summary: Making tests easy on the fingers and eyes, but on lotus.
|