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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 101720cc41b943ff7160efeaba7e94f78dc468b7
4
- data.tar.gz: 18ad04099097a8d19155baf4d383627ba7e2a3b1
3
+ metadata.gz: 474b249b6cf16c9aa22f5848f178d1b3b47de4cd
4
+ data.tar.gz: 9b5f035857adc5f9ef62683cbc9caa6d987d1eb7
5
5
  SHA512:
6
- metadata.gz: c12c4b306fd9330d8ed1eb5fe8d0aa494b007082d3cf83ac84b678ac6655d378d2d3f3f3d2ba2c00478ef03f25e3d776cb8ac9609faf7d1fc8ea25f1471236a6
7
- data.tar.gz: 253a548d75cb1292c0e6832a84175359a0c77c7d141e9118588cecd04af4eb7d6bb54fa4367499706a331f6f266af66280e84aac5a25cc097e15db4c1965f0bc
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
@@ -1,35 +1,27 @@
1
- language: ruby
2
- rvm:
3
- - 2.0.0
4
- - 2.1.0
5
- - 2.1.1
6
- - 2.1.2
7
- - 2.1.3
8
- - 2.1.4
9
- - 2.1.5
10
- - 2.1.6
11
- - 2.1.7
12
- - 2.1.8
13
- - 2.2.0
14
- - 2.2.1
15
- - 2.2.2
16
- - 2.2.3
17
- - 2.2.4
18
- - 2.3.0
19
- - rbx-2
20
- - jruby-9000
21
- - jruby-9.0.1.0
22
- - jruby-9.0.3.0
23
- - jruby-head
24
- - ruby-head
25
- matrix:
26
- allow_failures:
27
- - rvm: rbx-2
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'
@@ -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
- ## Usage
23
-
24
- ### Entity
25
-
26
- ```ruby
27
- class Person
28
- include Hanami::Validations
29
-
30
- attribute :email, type: String, presence: true, format: /@/
31
- attribute :name, type: String, size: 5..50
32
- attribute :password, type: String, size: 10
33
- attribute :birthday, type: Date
34
- attribute :created_at, type: DateTime
35
- attribute :state, type: String, inclusion: %w(PR SC SP)
36
- attribute :year, type: Integer, inclusion: 1979..1990
37
- end
38
- ```
39
-
40
- ### Spec
41
- ```ruby
42
- # allow_value
43
- it { is_expected.to allow_value("leo@nospam.org").for(:email) }
44
- it { is_expected.to_not allow_value('leo-at-nospam.org').for(:email) }
45
-
46
- # presence
47
- it { is_expected.to validate_presence_of(:email) }
48
-
49
- # size
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) }
52
-
53
- # coerces
54
- it { is_expected.to coerce_attribute(:email).to(String) }
55
- it { is_expected.to coerce_attribute(:name).to(String) }
56
- it { is_expected.to coerce_attribute(:password).to(String) }
57
- it { is_expected.to coerce_attribute(:birthday).to(Date) }
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) }
63
- ```
64
-
65
- ## Contributing
66
-
67
- 1. Fork it
68
- 2. Create your feature branch (`git checkout -b my-new-feature`)
69
- 3. Commit your changes (`git commit -am 'Add some feature'`)
70
- 4. Push to the branch (`git push origin my-new-feature`)
71
- 5. Create new Pull Request
72
-
73
-
74
- ## License
75
-
76
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
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
@@ -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/coerce_attribute_matcher'
2
- require 'shoulda/hanami/matchers/allow_value_matcher'
3
- require 'shoulda/hanami/matchers/validate_inclusion_of_matcher'
4
- require 'shoulda/hanami/matchers/validate_length_of_matcher'
5
- require 'shoulda/hanami/matchers/validate_presence_of_matcher'
6
-
7
- module Shoulda
8
- module Hanami
9
- module Matchers
10
- class Matcher
11
- def initialize(target, attribute, validation)
12
- @target = target
13
- @attribute = attribute
14
- @validation = validation
15
- end
16
-
17
- def matches?
18
- @target.valid?
19
- @target.errors.for(@attribute).select { |error| error.attribute == @attribute.to_s && error.validation == @validation }.size > 0
20
- end
21
- end
22
- end
23
- end
24
- end
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.send("#{@attribute}=", @value)
15
- !Matcher.new(target, @attribute, :format).matches?
16
- end
17
-
18
- def description
19
- "allow '#{@value}' to be set to '#{@attribute}'"
20
- end
21
-
22
- def failure_message
23
- "'#{@value}' is an invalid format for '#{@attribute}'"
24
- end
25
-
26
- def failure_message_when_negated
27
- "'#{@value}' is a valid format for '#{@attribute}'"
28
- end
29
-
30
- def for(attribute)
31
- @attribute = attribute
32
- self
33
- end
34
- end
35
- end
36
- end
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.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
+ 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.send("#{@attribute}=", '*' * (minimum - 1))
17
- errors << Matcher.new(target, @attribute, :size).matches?
18
-
19
- target.send("#{@attribute}=", '*' * (maximum + 1))
20
- errors << Matcher.new(target, @attribute, :size).matches?
21
-
22
- errors.all? { |error| error }
23
- end
24
-
25
- def description
26
- "'#{@attribute}' size between '#{@minimum}..#{@maximum}'"
27
- end
28
-
29
- def failure_message
30
- "'#{@attribute}' is not between '#{@minimum}..#{@maximum}'"
31
- end
32
-
33
- def failure_message_when_negated
34
- "'#{@attribute}' is between '#{@minimum}..#{@maximum}'"
35
- end
36
-
37
- def is_at_least(minimum)
38
- @minimum = minimum
39
- self
40
- end
41
-
42
- def is_at_most(maximum)
43
- @maximum = maximum
44
- self
45
- end
46
-
47
- def is_equal_to(limit)
48
- @minimum, @maximum = limit
49
- self
50
- end
51
-
52
- private
53
-
54
- def minimum
55
- @minimum ||= 1
56
- end
57
-
58
- def maximum
59
- @maximum ||= 1
60
- end
61
- end
62
- end
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.1.0'.freeze
4
- end
5
- end
1
+ module Shoulda
2
+ module Hanami
3
+ VERSION = '0.2.0'.freeze
4
+ end
5
+ end
@@ -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.5.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.1.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-02-06 00:00:00.000000000 Z
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.5.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.5.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