tram-validators 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +18 -0
- data/.gitignore +9 -0
- data/.rspec +3 -0
- data/.rubocop.yml +27 -0
- data/.travis.yml +14 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +21 -0
- data/README.md +134 -0
- data/Rakefile +6 -0
- data/lib/tram-validators.rb +1 -0
- data/lib/tram/validators.rb +64 -0
- data/lib/tram/validators/consistency_validator.rb +26 -0
- data/lib/tram/validators/contract_validator.rb +14 -0
- data/lib/tram/validators/each_validator.rb +30 -0
- data/lib/tram/validators/outcome_validator.rb +50 -0
- data/lib/tram/validators/reference_validator.rb +14 -0
- data/lib/tram/validators/size_validator.rb +37 -0
- data/lib/tram/validators/validity_validator.rb +27 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/invalid_with_error.rb +10 -0
- data/spec/tram-validators/consistency_validator_spec.rb +131 -0
- data/spec/tram-validators/contract_validator_spec.rb +58 -0
- data/spec/tram-validators/each_validator_spec.rb +35 -0
- data/spec/tram-validators/outcome_validator_spec.rb +27 -0
- data/spec/tram-validators/size_validator_spec.rb +347 -0
- data/spec/tram-validators/validity_validator_spec.rb +58 -0
- data/tram-validators.gemspec +23 -0
- metadata +136 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
RSpec.describe ValidityValidator do
|
2
|
+
before do
|
3
|
+
Test::Foo = Struct.new(:bar) do
|
4
|
+
include ActiveModel::Validations
|
5
|
+
validates :bar, presence: true
|
6
|
+
end
|
7
|
+
|
8
|
+
Test::Subject = Struct.new(:foo) do
|
9
|
+
include ActiveModel::Validations
|
10
|
+
end
|
11
|
+
|
12
|
+
Test::Subject.validates :foo, validity: opts
|
13
|
+
end
|
14
|
+
|
15
|
+
subject { Test::Subject.new(value) }
|
16
|
+
|
17
|
+
context "without key option" do
|
18
|
+
let(:opts) { true }
|
19
|
+
|
20
|
+
context "when value is valid per se" do
|
21
|
+
let(:value) { Test::Foo.new(1) }
|
22
|
+
it { is_expected.to be_valid }
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when value is invalid per se" do
|
26
|
+
let(:value) { Test::Foo.new(nil) }
|
27
|
+
it { is_expected.to be_invalid_with_error :foo }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "with original_keys option" do
|
32
|
+
let(:opts) { { original_keys: true } }
|
33
|
+
|
34
|
+
context "when value is valid per se" do
|
35
|
+
let(:value) { Test::Foo.new(1) }
|
36
|
+
it { is_expected.to be_valid }
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when value is invalid per se" do
|
40
|
+
let(:value) { Test::Foo.new(nil) }
|
41
|
+
it { is_expected.to be_invalid_with_error :bar }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "with nested_keys option" do
|
46
|
+
let(:opts) { { nested_keys: true } }
|
47
|
+
|
48
|
+
context "when value is valid per se" do
|
49
|
+
let(:value) { Test::Foo.new(1) }
|
50
|
+
it { is_expected.to be_valid }
|
51
|
+
end
|
52
|
+
|
53
|
+
context "when value is invalid per se" do
|
54
|
+
let(:value) { Test::Foo.new(nil) }
|
55
|
+
it { is_expected.to be_invalid_with_error "foo[bar]" }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |gem|
|
2
|
+
gem.name = "tram-validators"
|
3
|
+
gem.version = "0.0.1"
|
4
|
+
gem.author = "Andrew Kozin (nepalez)"
|
5
|
+
gem.email = "andrew.kozin@gmail.com"
|
6
|
+
gem.homepage = "https://github.com/tram-rb/tram-validators"
|
7
|
+
gem.summary = "Collection of validators for Rails projects"
|
8
|
+
gem.license = "MIT"
|
9
|
+
gem.description = "The collection supports composability of standalone" \
|
10
|
+
" policy objects, forms etc."
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
13
|
+
gem.test_files = gem.files.grep(/^spec/)
|
14
|
+
gem.extra_rdoc_files = Dir["README.md", "LICENSE", "CHANGELOG.md"]
|
15
|
+
|
16
|
+
gem.required_ruby_version = ">= 2.3"
|
17
|
+
|
18
|
+
gem.add_runtime_dependency "rails", "~> 5.0"
|
19
|
+
|
20
|
+
gem.add_development_dependency "rake"
|
21
|
+
gem.add_development_dependency "rspec", "~> 3.0"
|
22
|
+
gem.add_development_dependency "rubocop", "~> 0.44"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tram-validators
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Kozin (nepalez)
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.44'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.44'
|
69
|
+
description: The collection supports composability of standalone policy objects, forms
|
70
|
+
etc.
|
71
|
+
email: andrew.kozin@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files:
|
75
|
+
- README.md
|
76
|
+
files:
|
77
|
+
- ".codeclimate.yml"
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".rubocop.yml"
|
81
|
+
- ".travis.yml"
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- lib/tram-validators.rb
|
87
|
+
- lib/tram/validators.rb
|
88
|
+
- lib/tram/validators/consistency_validator.rb
|
89
|
+
- lib/tram/validators/contract_validator.rb
|
90
|
+
- lib/tram/validators/each_validator.rb
|
91
|
+
- lib/tram/validators/outcome_validator.rb
|
92
|
+
- lib/tram/validators/reference_validator.rb
|
93
|
+
- lib/tram/validators/size_validator.rb
|
94
|
+
- lib/tram/validators/validity_validator.rb
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
- spec/support/invalid_with_error.rb
|
97
|
+
- spec/tram-validators/consistency_validator_spec.rb
|
98
|
+
- spec/tram-validators/contract_validator_spec.rb
|
99
|
+
- spec/tram-validators/each_validator_spec.rb
|
100
|
+
- spec/tram-validators/outcome_validator_spec.rb
|
101
|
+
- spec/tram-validators/size_validator_spec.rb
|
102
|
+
- spec/tram-validators/validity_validator_spec.rb
|
103
|
+
- tram-validators.gemspec
|
104
|
+
homepage: https://github.com/tram-rb/tram-validators
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '2.3'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.5.2
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Collection of validators for Rails projects
|
128
|
+
test_files:
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
- spec/support/invalid_with_error.rb
|
131
|
+
- spec/tram-validators/consistency_validator_spec.rb
|
132
|
+
- spec/tram-validators/contract_validator_spec.rb
|
133
|
+
- spec/tram-validators/each_validator_spec.rb
|
134
|
+
- spec/tram-validators/outcome_validator_spec.rb
|
135
|
+
- spec/tram-validators/size_validator_spec.rb
|
136
|
+
- spec/tram-validators/validity_validator_spec.rb
|