shoulda-lotus 0.0.0 → 0.0.3

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: 61ddde979d897fca8e48680fc8e79234c27a0fe0
4
- data.tar.gz: 1060d8b985f0382e3846985a15e391a67514bc47
3
+ metadata.gz: d8a42596ac1614c3d15f72c7ba3dc69f4d129f7f
4
+ data.tar.gz: 5ee02bf7f61a5b4cda9a6528d675b71433fd32cb
5
5
  SHA512:
6
- metadata.gz: 813bf327589a4eae9e95db447d5a962587e13a105858be1a593697010cab601b2787e8c25f9e61a3ff8017034841a7af8cda12679d1e2ec714aa539f5bd802b1
7
- data.tar.gz: a263a116300309a4601d18a0f484b1dc528d32a05c849de4b6eccd341f8fb4523d7df6cb504c63e6b49663f3769046a5f83da8350d0429f53d366b50487e8f1b
6
+ metadata.gz: d1761144e81387b172e85c8b72b2e8598defe3ac1b61794bc3b431eb6d21d7852ef63b3bb4389beb4aeab90d54d4513b5fbaabef3191edfc50f93711971565b2
7
+ data.tar.gz: 6b1e164632a8bcf75d4b78f624ce292dbc44aa6b3ab5145b6b69025846f90601d9c182f98277c87148649406035ca5c2ded8dfebb6b04224f05fca4469a2f90c
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
- --format documentation
1
+ --format progress
2
2
  --color
data/.travis.yml CHANGED
@@ -15,3 +15,5 @@ rvm:
15
15
  - jruby-head
16
16
  - ruby-head
17
17
  before_install: gem install bundler -v 1.10.5
18
+ env:
19
+ - TRAVIS=true
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
- # shoulda-lotus [![Build Status](https://travis-ci.org/mcorp/shoulda-lotus.svg?branch=master)](https://travis-ci.org/mcorp/shoulda-lotus)
1
+ # shoulda-lotus
2
+ [![Gem Version](https://badge.fury.io/rb/shoulda-lotus.svg)](http://badge.fury.io/rb/shoulda-lotus) [![Build Status](https://travis-ci.org/mcorp/shoulda-lotus.svg?branch=master)](https://travis-ci.org/mcorp/shoulda-lotus) [![Code Climate](https://codeclimate.com/github/mcorp/shoulda-lotus/badges/gpa.svg)](https://codeclimate.com/github/mcorp/shoulda-lotus) [![Test Coverage](https://codeclimate.com/github/mcorp/shoulda-lotus/badges/coverage.svg)](https://codeclimate.com/github/mcorp/shoulda-lotus/coverage) [![Dependency Status](https://gemnasium.com/mcorp/shoulda-lotus.svg)](https://gemnasium.com/mcorp/shoulda-lotus)
2
3
 
3
- Making tests easy on the fingers and eyes, but to lotus.
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
- TODO: Write usage instructions here
24
+ ### Entity
24
25
 
25
- ## Development
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
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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
- Bug reports and pull requests are welcome on GitHub at https://github.com/mcorp/shoulda-lotus.
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
@@ -0,0 +1,10 @@
1
+ require 'shoulda/lotus/matchers/allow_value_matcher'
2
+ require 'shoulda/lotus/matchers/validate_length_of_matcher'
3
+ require 'shoulda/lotus/matchers/validate_presence_of_matcher'
4
+
5
+ module Shoulda
6
+ module Lotus
7
+ module Matchers
8
+ end
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  module Shoulda
2
2
  module Lotus
3
- VERSION = '0.0.0'.freeze
3
+ VERSION = '0.0.3'.freeze
4
4
  end
5
5
  end
data/lib/shoulda/lotus.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'shoulda/lotus/version'
2
+ require 'shoulda/lotus/matchers'
2
3
 
3
4
  module Shoulda
4
5
  module Lotus
@@ -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.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-29 00:00:00.000000000 Z
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.6
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.