shoulda-hanami 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +9 -9
- data/.rspec +2 -2
- data/.travis.yml +27 -35
- data/.yardopts +7 -7
- data/Gemfile +8 -8
- data/LICENSE.txt +21 -21
- data/README.md +81 -76
- data/Rakefile +6 -6
- data/lib/shoulda/hanami.rb +7 -7
- data/lib/shoulda/hanami/matchers.rb +31 -24
- data/lib/shoulda/hanami/matchers/allow_value_matcher.rb +36 -37
- data/lib/shoulda/hanami/matchers/validate_inclusion_of_matcher.rb +43 -44
- data/lib/shoulda/hanami/matchers/validate_length_of_matcher.rb +62 -64
- data/lib/shoulda/hanami/matchers/validate_presence_of_matcher.rb +31 -31
- data/lib/shoulda/hanami/version.rb +5 -5
- data/shoulda-hanami.gemspec +26 -26
- metadata +4 -5
- data/lib/shoulda/hanami/matchers/coerce_attribute_matcher.rb +0 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 474b249b6cf16c9aa22f5848f178d1b3b47de4cd
|
4
|
+
data.tar.gz: 9b5f035857adc5f9ef62683cbc9caa6d987d1eb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c43e19c7dea3516c89a8ea654bba6aa4fa8e87b49af1ae60356cfe76a26f909c684fbe3c540e69cb5bf32e9c3ae3209cf35b32a0053851080149275efb343f4
|
7
|
+
data.tar.gz: 8db933704e25b18ef8c1fecd9a04fa6854331a85fb75451341849ca3bcec52653055585c267c55ffe19a5140879ff3133831bacfd421f09379099adf561d030b
|
data/.gitignore
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/Gemfile.lock
|
4
|
-
/_yardoc/
|
5
|
-
/coverage/
|
6
|
-
/doc/
|
7
|
-
/pkg/
|
8
|
-
/spec/reports/
|
9
|
-
/tmp/
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
--format progress
|
2
|
-
--color
|
1
|
+
--format progress
|
2
|
+
--color
|
data/.travis.yml
CHANGED
@@ -1,35 +1,27 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.
|
4
|
-
- 2.1
|
5
|
-
- 2.
|
6
|
-
- 2.
|
7
|
-
- 2.
|
8
|
-
- 2.
|
9
|
-
- 2.
|
10
|
-
- 2.1
|
11
|
-
- 2
|
12
|
-
-
|
13
|
-
-
|
14
|
-
-
|
15
|
-
-
|
16
|
-
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
- rvm: jruby-head
|
29
|
-
- rvm: ruby-head
|
30
|
-
- rvm: jruby-9000
|
31
|
-
- rvm: jruby-9.0.1.0
|
32
|
-
- rvm: jruby-9.0.3.0
|
33
|
-
before_install: gem install bundler -v 1.10.5
|
34
|
-
env:
|
35
|
-
- TRAVIS=true
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.2.0
|
4
|
+
- 2.2.1
|
5
|
+
- 2.2.2
|
6
|
+
- 2.2.3
|
7
|
+
- 2.2.4
|
8
|
+
- 2.2.5
|
9
|
+
- 2.3.0
|
10
|
+
- 2.3.1
|
11
|
+
- rbx-2
|
12
|
+
- jruby-9000
|
13
|
+
- jruby-9.0.1.0
|
14
|
+
- jruby-9.0.3.0
|
15
|
+
- jruby-head
|
16
|
+
- ruby-head
|
17
|
+
matrix:
|
18
|
+
allow_failures:
|
19
|
+
- rvm: rbx-2
|
20
|
+
- rvm: jruby-head
|
21
|
+
- rvm: ruby-head
|
22
|
+
- rvm: jruby-9000
|
23
|
+
- rvm: jruby-9.0.1.0
|
24
|
+
- rvm: jruby-9.0.3.0
|
25
|
+
before_install: gem install bundler -v 1.10.5
|
26
|
+
env:
|
27
|
+
- TRAVIS=true
|
data/.yardopts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
--no-private
|
2
|
-
--protected
|
3
|
-
--readme README.md
|
4
|
-
--files LICENSE.txt
|
5
|
-
--markup markdown
|
6
|
-
--hide-tag return
|
7
|
-
--hide-tag param
|
1
|
+
--no-private
|
2
|
+
--protected
|
3
|
+
--readme README.md
|
4
|
+
--files LICENSE.txt
|
5
|
+
--markup markdown
|
6
|
+
--hide-tag return
|
7
|
+
--hide-tag param
|
data/Gemfile
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
gemspec
|
4
|
-
gem 'codeclimate-test-reporter'
|
5
|
-
|
6
|
-
# documentation
|
7
|
-
gem 'inch'
|
8
|
-
gem 'yard'
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
gem 'codeclimate-test-reporter'
|
5
|
+
|
6
|
+
# documentation
|
7
|
+
gem 'inch'
|
8
|
+
gem 'yard'
|
data/LICENSE.txt
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2015 Leonardo Saraiva
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Leonardo Saraiva
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,76 +1,81 @@
|
|
1
|
-
# shoulda-hanami
|
2
|
-
[![Gem Version](https://badge.fury.io/rb/shoulda-hanami.svg)](http://badge.fury.io/rb/shoulda-hanami) [![Build Status](https://travis-ci.org/mcorp/shoulda-hanami.svg?branch=master)](https://travis-ci.org/mcorp/shoulda-hanami) [![Code Climate](https://codeclimate.com/github/mcorp/shoulda-hanami/badges/gpa.svg)](https://codeclimate.com/github/mcorp/shoulda-hanami) [![Test Coverage](https://codeclimate.com/github/mcorp/shoulda-hanami/badges/coverage.svg)](https://codeclimate.com/github/mcorp/shoulda-hanami/coverage) [![Dependency Status](https://gemnasium.com/mcorp/shoulda-hanami.svg)](https://gemnasium.com/mcorp/shoulda-hanami) [![Inline docs](http://inch-ci.org/github/mcorp/shoulda-hanami.svg?branch=master)](http://inch-ci.org/github/mcorp/shoulda-hanami)
|
3
|
-
|
4
|
-
Making tests easy on the fingers and eyes, but on hanami.
|
5
|
-
|
6
|
-
## Installation
|
7
|
-
|
8
|
-
Add this line to your application's Gemfile:
|
9
|
-
|
10
|
-
```ruby
|
11
|
-
gem 'shoulda-hanami'
|
12
|
-
```
|
13
|
-
|
14
|
-
And then execute:
|
15
|
-
|
16
|
-
$ bundle
|
17
|
-
|
18
|
-
Or install it yourself as:
|
19
|
-
|
20
|
-
$ gem install shoulda-hanami
|
21
|
-
|
22
|
-
##
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
```ruby
|
27
|
-
|
28
|
-
include Hanami::
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
it { is_expected.to
|
56
|
-
it { is_expected.
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
it { is_expected.to
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
1
|
+
# shoulda-hanami
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/shoulda-hanami.svg)](http://badge.fury.io/rb/shoulda-hanami) [![Build Status](https://travis-ci.org/mcorp/shoulda-hanami.svg?branch=master)](https://travis-ci.org/mcorp/shoulda-hanami) [![Code Climate](https://codeclimate.com/github/mcorp/shoulda-hanami/badges/gpa.svg)](https://codeclimate.com/github/mcorp/shoulda-hanami) [![Test Coverage](https://codeclimate.com/github/mcorp/shoulda-hanami/badges/coverage.svg)](https://codeclimate.com/github/mcorp/shoulda-hanami/coverage) [![Dependency Status](https://gemnasium.com/mcorp/shoulda-hanami.svg)](https://gemnasium.com/mcorp/shoulda-hanami) [![Inline docs](http://inch-ci.org/github/mcorp/shoulda-hanami.svg?branch=master)](http://inch-ci.org/github/mcorp/shoulda-hanami)
|
3
|
+
|
4
|
+
Making tests easy on the fingers and eyes, but on hanami.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'shoulda-hanami'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install shoulda-hanami
|
21
|
+
|
22
|
+
## Configure
|
23
|
+
|
24
|
+
Create file `spec/support/shoulda_hanami.rb` with:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
RSpec.configure do |config|
|
28
|
+
config.include Shoulda::Hanami::Matchers
|
29
|
+
end
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
### Entity
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
class Person
|
39
|
+
include Hanami::Validations
|
40
|
+
|
41
|
+
validations do
|
42
|
+
required(:email) { format?(/@/) }
|
43
|
+
required(:name) { size?(5..50) }
|
44
|
+
required(:password) { size?(10) }
|
45
|
+
required(:state) { included_in?(%w(PR SC SP)) }
|
46
|
+
required(:year) { included_in?(1979..1990) }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
### Spec
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
# allow_value
|
55
|
+
it { is_expected.to allow_value("leo@nospam.org").for(:email) }
|
56
|
+
it { is_expected.to_not allow_value('leo-at-nospam.org').for(:email) }
|
57
|
+
|
58
|
+
# presence
|
59
|
+
it { is_expected.to validate_presence_of(:email) }
|
60
|
+
|
61
|
+
# size
|
62
|
+
it { is_expected.to validate_length_of(:name).is_at_least(5).is_at_most(50) }
|
63
|
+
it { is_expected.to validate_length_of(:password).is_equal_to(10) }
|
64
|
+
|
65
|
+
# inclusion
|
66
|
+
it { is_expected.to validate_inclusion_of(:state).in_array(%w(PR SC SP)) }
|
67
|
+
it { is_expected.to validate_inclusion_of(:year).in_array(1979..1990) }
|
68
|
+
```
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
1. Fork it
|
73
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
74
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
75
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
76
|
+
5. Create new Pull Request
|
77
|
+
|
78
|
+
|
79
|
+
## License
|
80
|
+
|
81
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require 'bundler/gem_tasks'
|
2
|
-
require 'rspec/core/rake_task'
|
3
|
-
|
4
|
-
RSpec::Core::RakeTask.new(:spec)
|
5
|
-
|
6
|
-
task default: :spec
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
task default: :spec
|
data/lib/shoulda/hanami.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require 'shoulda/hanami/version'
|
2
|
-
require 'shoulda/hanami/matchers'
|
3
|
-
|
4
|
-
module Shoulda
|
5
|
-
module Hanami
|
6
|
-
end
|
7
|
-
end
|
1
|
+
require 'shoulda/hanami/version'
|
2
|
+
require 'shoulda/hanami/matchers'
|
3
|
+
|
4
|
+
module Shoulda
|
5
|
+
module Hanami
|
6
|
+
end
|
7
|
+
end
|
@@ -1,24 +1,31 @@
|
|
1
|
-
require 'shoulda/hanami/matchers/
|
2
|
-
require 'shoulda/hanami/matchers/
|
3
|
-
require 'shoulda/hanami/matchers/
|
4
|
-
require 'shoulda/hanami/matchers/
|
5
|
-
|
6
|
-
|
7
|
-
module
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
def
|
18
|
-
@target
|
19
|
-
@
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
1
|
+
require 'shoulda/hanami/matchers/allow_value_matcher'
|
2
|
+
require 'shoulda/hanami/matchers/validate_inclusion_of_matcher'
|
3
|
+
require 'shoulda/hanami/matchers/validate_length_of_matcher'
|
4
|
+
require 'shoulda/hanami/matchers/validate_presence_of_matcher'
|
5
|
+
|
6
|
+
module Shoulda
|
7
|
+
module Hanami
|
8
|
+
module Matchers
|
9
|
+
class Matcher
|
10
|
+
ERRORS = {
|
11
|
+
format: 'is in invalid format',
|
12
|
+
inclusion: 'must be one of:',
|
13
|
+
size: 'length must be',
|
14
|
+
presence: 'must be filled'
|
15
|
+
}
|
16
|
+
|
17
|
+
def initialize(target, attribute, validation)
|
18
|
+
@target = target
|
19
|
+
@attribute = attribute
|
20
|
+
@validation = validation
|
21
|
+
end
|
22
|
+
|
23
|
+
def matches?
|
24
|
+
result = @target.validate
|
25
|
+
result.failure? &&
|
26
|
+
result.messages.fetch(@attribute).select { |msg| msg.include?(ERRORS[@validation]) }.size > 0
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,37 +1,36 @@
|
|
1
|
-
module Shoulda
|
2
|
-
module Hanami
|
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.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
1
|
+
module Shoulda
|
2
|
+
module Hanami
|
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
|
+
!Matcher.new(target.class.new(@attribute => @value), @attribute, :format).matches?
|
15
|
+
end
|
16
|
+
|
17
|
+
def description
|
18
|
+
"allow '#{@value}' to be set to '#{@attribute}'"
|
19
|
+
end
|
20
|
+
|
21
|
+
def failure_message
|
22
|
+
"'#{@value}' is an invalid format for '#{@attribute}'"
|
23
|
+
end
|
24
|
+
|
25
|
+
def failure_message_when_negated
|
26
|
+
"'#{@value}' is a valid format for '#{@attribute}'"
|
27
|
+
end
|
28
|
+
|
29
|
+
def for(attribute)
|
30
|
+
@attribute = attribute
|
31
|
+
self
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,44 +1,43 @@
|
|
1
|
-
module Shoulda
|
2
|
-
module Hanami
|
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.
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
1
|
+
module Shoulda
|
2
|
+
module Hanami
|
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
|
+
Matcher.new(target.class.new(@attribute => value), @attribute, :inclusion).matches?
|
22
|
+
end
|
23
|
+
|
24
|
+
def description
|
25
|
+
"inclusion only '#{@values.inspect}' values on '#{@attribute}'"
|
26
|
+
end
|
27
|
+
|
28
|
+
def failure_message
|
29
|
+
"'#{@attribute}' is include only '#{@values.inspect}'"
|
30
|
+
end
|
31
|
+
|
32
|
+
def failure_message_when_negated
|
33
|
+
"'#{@attribute}' is not include only '#{@values.inspect}'"
|
34
|
+
end
|
35
|
+
|
36
|
+
def in_array(values)
|
37
|
+
@values = values
|
38
|
+
self
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,64 +1,62 @@
|
|
1
|
-
module Shoulda
|
2
|
-
module Hanami
|
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.
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
errors
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
64
|
-
end
|
1
|
+
module Shoulda
|
2
|
+
module Hanami
|
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
|
+
errors << Matcher.new(target.class.new(@attribute => '*' * (minimum - 1)), @attribute, :size).matches?
|
17
|
+
|
18
|
+
errors << Matcher.new(target.class.new(@attribute => '*' * (maximum + 1)), @attribute, :size).matches?
|
19
|
+
|
20
|
+
errors.all? { |error| error }
|
21
|
+
end
|
22
|
+
|
23
|
+
def description
|
24
|
+
"'#{@attribute}' size between '#{@minimum}..#{@maximum}'"
|
25
|
+
end
|
26
|
+
|
27
|
+
def failure_message
|
28
|
+
"'#{@attribute}' is not between '#{@minimum}..#{@maximum}'"
|
29
|
+
end
|
30
|
+
|
31
|
+
def failure_message_when_negated
|
32
|
+
"'#{@attribute}' is between '#{@minimum}..#{@maximum}'"
|
33
|
+
end
|
34
|
+
|
35
|
+
def is_at_least(minimum)
|
36
|
+
@minimum = minimum
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def is_at_most(maximum)
|
41
|
+
@maximum = maximum
|
42
|
+
self
|
43
|
+
end
|
44
|
+
|
45
|
+
def is_equal_to(limit)
|
46
|
+
@minimum, @maximum = limit
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def minimum
|
53
|
+
@minimum ||= 1
|
54
|
+
end
|
55
|
+
|
56
|
+
def maximum
|
57
|
+
@maximum ||= 1
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -1,31 +1,31 @@
|
|
1
|
-
module Shoulda
|
2
|
-
module Hanami
|
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
|
-
Matcher.new(target, @attribute, :presence).matches?
|
15
|
-
end
|
16
|
-
|
17
|
-
def description
|
18
|
-
"require '#{@attribute}' to be set"
|
19
|
-
end
|
20
|
-
|
21
|
-
def failure_message
|
22
|
-
"'#{@attribute}' is a required attribute"
|
23
|
-
end
|
24
|
-
|
25
|
-
def failure_message_when_negated
|
26
|
-
"'#{@attribute}' is not a required attribute"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
1
|
+
module Shoulda
|
2
|
+
module Hanami
|
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
|
+
Matcher.new(target.class.new(@attribute => nil), @attribute, :presence).matches?
|
15
|
+
end
|
16
|
+
|
17
|
+
def description
|
18
|
+
"require '#{@attribute}' to be set"
|
19
|
+
end
|
20
|
+
|
21
|
+
def failure_message
|
22
|
+
"'#{@attribute}' is a required attribute"
|
23
|
+
end
|
24
|
+
|
25
|
+
def failure_message_when_negated
|
26
|
+
"'#{@attribute}' is not a required attribute"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module Shoulda
|
2
|
-
module Hanami
|
3
|
-
VERSION = '0.
|
4
|
-
end
|
5
|
-
end
|
1
|
+
module Shoulda
|
2
|
+
module Hanami
|
3
|
+
VERSION = '0.2.0'.freeze
|
4
|
+
end
|
5
|
+
end
|
data/shoulda-hanami.gemspec
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'shoulda/hanami/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = 'shoulda-hanami'
|
8
|
-
spec.version = Shoulda::Hanami::VERSION
|
9
|
-
spec.authors = ['Leonardo Saraiva']
|
10
|
-
spec.email = ['vyper@maneh.org']
|
11
|
-
|
12
|
-
spec.summary = %q{Making tests easy on the fingers and eyes, but on hanami.}
|
13
|
-
spec.homepage = 'https://github.com/mcorp/shoulda-hanami'
|
14
|
-
spec.license = 'MIT'
|
15
|
-
|
16
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
-
spec.bindir = 'exe'
|
18
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
-
spec.require_paths = ['lib']
|
20
|
-
|
21
|
-
spec.add_development_dependency 'bundler', '~> 1.10'
|
22
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
-
spec.add_development_dependency 'rspec', '~> 3.4.0'
|
24
|
-
|
25
|
-
spec.add_dependency 'hanami-validations', '~> 0.
|
26
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'shoulda/hanami/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'shoulda-hanami'
|
8
|
+
spec.version = Shoulda::Hanami::VERSION
|
9
|
+
spec.authors = ['Leonardo Saraiva']
|
10
|
+
spec.email = ['vyper@maneh.org']
|
11
|
+
|
12
|
+
spec.summary = %q{Making tests easy on the fingers and eyes, but on hanami.}
|
13
|
+
spec.homepage = 'https://github.com/mcorp/shoulda-hanami'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.4.0'
|
24
|
+
|
25
|
+
spec.add_dependency 'hanami-validations', '~> 0.6.0'
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoulda-hanami
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leonardo Saraiva
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
61
|
+
version: 0.6.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
68
|
+
version: 0.6.0
|
69
69
|
description:
|
70
70
|
email:
|
71
71
|
- vyper@maneh.org
|
@@ -84,7 +84,6 @@ files:
|
|
84
84
|
- lib/shoulda/hanami.rb
|
85
85
|
- lib/shoulda/hanami/matchers.rb
|
86
86
|
- lib/shoulda/hanami/matchers/allow_value_matcher.rb
|
87
|
-
- lib/shoulda/hanami/matchers/coerce_attribute_matcher.rb
|
88
87
|
- lib/shoulda/hanami/matchers/validate_inclusion_of_matcher.rb
|
89
88
|
- lib/shoulda/hanami/matchers/validate_length_of_matcher.rb
|
90
89
|
- lib/shoulda/hanami/matchers/validate_presence_of_matcher.rb
|
@@ -1,53 +0,0 @@
|
|
1
|
-
module Shoulda
|
2
|
-
module Hanami
|
3
|
-
module Matchers
|
4
|
-
def coerce_attribute(attribute)
|
5
|
-
CoerceAttributeMatcher.new(attribute)
|
6
|
-
end
|
7
|
-
|
8
|
-
class CoerceAttributeMatcher
|
9
|
-
TYPES = {
|
10
|
-
'Array' => [1, [1]],
|
11
|
-
'BigDecimal' => ['x', nil],
|
12
|
-
'Boolean' => ['0303', false],
|
13
|
-
'Date' => [false, nil],
|
14
|
-
'DateTime' => ['x', nil],
|
15
|
-
'Float' => ['x', nil],
|
16
|
-
'Hash' => ['ç', nil],
|
17
|
-
'Integer' => ['x', nil],
|
18
|
-
'Pathname' => [true, nil],
|
19
|
-
'Set' => [nil, Set.new],
|
20
|
-
'String' => [1, '1'],
|
21
|
-
'Symbol' => [Hash.new, nil],
|
22
|
-
'Time' => ['uy', nil],
|
23
|
-
}
|
24
|
-
|
25
|
-
def initialize(attribute)
|
26
|
-
@attribute = attribute
|
27
|
-
end
|
28
|
-
|
29
|
-
def matches?(target)
|
30
|
-
target.send("#{@attribute}=", TYPES[@type.to_s].first)
|
31
|
-
target.send(@attribute) == TYPES[@type.to_s].last
|
32
|
-
end
|
33
|
-
|
34
|
-
def description
|
35
|
-
"coerce '#{@attribute}' to '#{@type}'"
|
36
|
-
end
|
37
|
-
|
38
|
-
def failure_message
|
39
|
-
"does coerce '#{@attribute}' to '#{@type}'"
|
40
|
-
end
|
41
|
-
|
42
|
-
def failure_message_when_negated
|
43
|
-
"does not coerce '#{@attribute}' to '#{@type}'"
|
44
|
-
end
|
45
|
-
|
46
|
-
def to(type)
|
47
|
-
@type = type
|
48
|
-
self
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|