usecasing_validations 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzFjZDA5NDdjYWY1MWU0ZWVhNDc3MmZmNDg4YmUwNjVmZDgwMzBiNw==
4
+ MmY1ZjFjYjY2MDZiYTA4ZWQ2ZTgxZjdmZmNmODU5Njg1ZWEyYjI3Mg==
5
5
  data.tar.gz: !binary |-
6
- MTdmYzQ4MDUxN2VmZDFmZTgyMTM2NDFmYWY0YjAzYjY3OTRkNGFlMQ==
6
+ NzQzOGU3ZWJlY2NkM2U0ZDdjM2M1YjRlZWNjMzM0Yjg1YTVhOTM2Mw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Y2U1NjJhMzRmMGJlYWRmYzE5ZDYyYWM0MjFkOTM5MTIzYzg2MjU1NDRhM2Rl
10
- MDNlNDQ5NDU1ZmQxZWY2MzA5ZTM0NGIxY2NiMjVkZTEwZTBiYTUxNjFiMTgy
11
- ZGUwZTU0ZGY5ZWVhOWE2MzdlZWE1NjJmZWFkNjNiY2FhNTE3ZGU=
9
+ ZDJiYmUxMTY0ODUyZTNkNjQ5NDdjMzkxMzI3ZmE4ZmU4MDg1NGJjMWJmOTQy
10
+ NTVjMjJiMWNhM2Q3MGFhYWUxMzg4ZGIxMGYzYTU3MmJiZjU3YjlmYzk4NzNi
11
+ YzM4MTE2MWM2MjMwYjRhM2ZkYzhjMjkwZDlmN2U0OTg5NGZkOTI=
12
12
  data.tar.gz: !binary |-
13
- MDE0NWMyMWEyZjgyYzkxNTY5YjY4ZGMxZGMxNzc2NGViMTYzYjAxODk5Mjgx
14
- OTFmYjgyMjE3OWJiMTRmNzg5OTQwNDVkNTQ0MjIwZDczMTQ0MjI1YTY4NmQ1
15
- ZmUzMmQ2ODIxZjJhZjNkODdhZWNiOTBhZDFkZjkzMzkwZThlMjc=
13
+ NmQxNWZkMzAyYmZjZjIzMDczYmY4NmViM2Q0YTAwMmFjYjg5ZDBlZTE5NTg1
14
+ MmI1NmRkYjIwY2RjMmZlNTkzMmI4YzY4ZjE5MWY4MzIzYjYwOWI1NzhlMDAw
15
+ NTdjNDk5YWUzY2M3OWU4OTc5YWFhOWI2MTIwMzE1MDliM2NkNmQ=
data/Gemfile CHANGED
@@ -2,3 +2,10 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in usecasing.gemspec
4
4
  gemspec
5
+
6
+ group :development, :test do
7
+ gem 'pry', require: 'pry'
8
+ gem 'rspec'
9
+ gem 'mocha'
10
+ gem 'rack-test'
11
+ end
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usecasing_validations (0.5.3)
5
- usecasing
4
+ usecasing_validations (0.5.5)
5
+ usecasing (~> 0.1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -17,7 +17,9 @@ GEM
17
17
  coderay (~> 1.0)
18
18
  method_source (~> 0.8)
19
19
  slop (~> 3.4)
20
- rake (10.1.1)
20
+ rack (1.5.2)
21
+ rack-test (0.6.2)
22
+ rack (>= 1.0)
21
23
  rspec (2.14.1)
22
24
  rspec-core (~> 2.14.0)
23
25
  rspec-expectations (~> 2.14.0)
@@ -27,7 +29,7 @@ GEM
27
29
  diff-lcs (>= 1.1.3, < 2.0)
28
30
  rspec-mocks (2.14.4)
29
31
  slop (3.4.7)
30
- usecasing (0.1.4)
32
+ usecasing (0.1.10)
31
33
 
32
34
  PLATFORMS
33
35
  ruby
@@ -35,6 +37,6 @@ PLATFORMS
35
37
  DEPENDENCIES
36
38
  mocha
37
39
  pry
38
- rake
40
+ rack-test
39
41
  rspec
40
42
  usecasing_validations!
@@ -1,6 +1,6 @@
1
1
  module UseCase
2
-
3
- class GroupValidator < Base
2
+
3
+ class GroupValidator < ValidatorBase
4
4
 
5
5
  def perform
6
6
  usecases_vs_results = {}
@@ -10,7 +10,7 @@ module UseCase
10
10
  end
11
11
 
12
12
  usecases_vs_results.each do |usecase_name, result|
13
- failure(usecase_name, :failed) unless result
13
+ call_failure(:unprocessable_entity, usecase_name) unless result
14
14
  end
15
15
  end
16
16
 
@@ -18,9 +18,8 @@ module UseCase
18
18
  group_dependencies.push(*new_dependencies)
19
19
  end
20
20
 
21
-
22
21
  protected ####################### PROTECTED #################
23
-
22
+
24
23
  def context_to_hash
25
24
  context.instance_variable_get('@values')
26
25
  end
@@ -1,9 +1,9 @@
1
1
  module UseCase
2
-
3
- class Validator < Base
2
+
3
+ class Validator < ValidatorBase
4
4
 
5
5
  include UseCaseValidations
6
-
6
+
7
7
  def perform
8
8
  targets = [*target]
9
9
 
@@ -12,7 +12,7 @@ module UseCase
12
12
 
13
13
  elsif targets.empty?
14
14
  all_validations_green = true
15
-
15
+
16
16
  else
17
17
  all_validations_green = targets.map do |object_to_validate|
18
18
  if Helpers._marked_for_destruction?(object_to_validate)
@@ -23,7 +23,7 @@ module UseCase
23
23
  end.all?
24
24
  end
25
25
 
26
- failure(self.class.to_s.downcase.to_sym, :failed) unless all_validations_green
26
+ call_failure(:unprocessable_entity, self.class.to_s.downcase.to_sym) unless all_validations_green
27
27
  end
28
28
 
29
29
  end
@@ -0,0 +1,15 @@
1
+ module UseCase
2
+
3
+ class ValidatorBase < Base
4
+
5
+ def call_failure(status, message = nil)
6
+ if respond_to?(:failure!)
7
+ failure!(status, message)
8
+ else
9
+ failure(status, message)
10
+ end
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -1,3 +1,3 @@
1
1
  module UseCaseValidations
2
- VERSION = "0.5.4"
2
+ VERSION = "0.5.5"
3
3
  end
@@ -15,6 +15,7 @@ require "usecasing_validations/validations/uniqueness"
15
15
 
16
16
 
17
17
  module UseCase
18
+ autoload :ValidatorBase, 'usecasing/validator_base'
18
19
  autoload :Validator, 'usecasing/validator'
19
20
  autoload :GroupValidator, 'usecasing/group_validator'
20
21
  end
@@ -48,7 +49,7 @@ module UseCaseValidations
48
49
 
49
50
  object_to_validate.errors.empty?
50
51
  end
51
-
52
+
52
53
  private ######################## PRIVATE #######################
53
54
 
54
55
  def extend_errors_if_necessary(object_to_validate)
@@ -92,7 +93,7 @@ module UseCaseValidations
92
93
  def validates_with(*args, &block)
93
94
  options = Helpers._extract_options!(args)
94
95
  options[:class] = self
95
-
96
+
96
97
  args.each do |klass|
97
98
  validator = klass.new(options, &block)
98
99
 
@@ -0,0 +1,19 @@
1
+ module HierarchyValidation
2
+
3
+ class Father < UseCase::Validator
4
+
5
+ target :post
6
+
7
+ validates_presence_of :title
8
+
9
+ end
10
+
11
+ class Son < Father
12
+
13
+ target :comments, in: :post
14
+
15
+ validates_presence_of :email
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Testing hierarchy capabilities' do
4
+
5
+ it "HierarchyValidation::Son should be able to inherit Father's validations and alter them" do
6
+ post_for_father = RubyPostWithComments.new([{ title: "title1" }, { email: "fakemail" }])
7
+ post_for_son = post_for_father.dup
8
+
9
+ father_context = HierarchyValidation::Father.perform(post: post_for_father)
10
+ father_context.success?.should == false
11
+
12
+ post_for_father.errors.added?(:title, :blank).should == true
13
+ post_for_father.errors.size.should == 1
14
+
15
+ son_context = HierarchyValidation::Son.perform(post: post_for_son)
16
+ son_context.success?.should == false
17
+
18
+ comment1 = post_for_son.comments[0]
19
+ comment1.errors.added?(:email, :blank).should == true
20
+ comment1.errors.size.should == 1
21
+
22
+ comment2 = post_for_son.comments[1]
23
+ comment2.errors.added?(:title, :blank).should == true
24
+ comment2.errors.size.should == 1
25
+ end
26
+
27
+ end
28
+
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
8
8
  gem.version = UseCaseValidations::VERSION
9
9
  gem.authors = ["João Gonçalves"]
10
10
  gem.email = ["goncalves.joao@gmail.com"]
11
- gem.description = %q{UseCase Gem Extention to add Rails like validations}
12
- gem.summary = %q{UseCase Gem Extention to add Rails like validations}
11
+ gem.description = "UseCase Gem Extention to add Rails like validations"
12
+ gem.summary = "UseCase Gem Extention to add Rails like validations without Rails, only needs Ruby and usecasing gem"
13
13
  gem.homepage = "https://github.com/goncalvesjoao/usecasing-validations"
14
14
  gem.license = "MIT"
15
15
 
@@ -17,13 +17,6 @@ Gem::Specification.new do |gem|
17
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
-
21
- #development dependecy
22
- gem.add_development_dependency "rspec"
23
- gem.add_development_dependency "rake"
24
- gem.add_development_dependency "mocha"
25
- gem.add_development_dependency "pry"
26
-
27
- gem.add_runtime_dependency 'usecasing'
28
20
 
21
+ gem.add_runtime_dependency 'usecasing', "~> 0.1"
29
22
  end
metadata CHANGED
@@ -1,85 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usecasing_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - João Gonçalves
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-22 00:00:00.000000000 Z
11
+ date: 2014-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rspec
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ! '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ! '>='
25
- - !ruby/object:Gem::Version
26
- version: '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: mocha
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ! '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: pry
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
13
  - !ruby/object:Gem::Dependency
70
14
  name: usecasing
71
15
  requirement: !ruby/object:Gem::Requirement
72
16
  requirements:
73
- - - ! '>='
17
+ - - ~>
74
18
  - !ruby/object:Gem::Version
75
- version: '0'
19
+ version: '0.1'
76
20
  type: :runtime
77
21
  prerelease: false
78
22
  version_requirements: !ruby/object:Gem::Requirement
79
23
  requirements:
80
- - - ! '>='
24
+ - - ~>
81
25
  - !ruby/object:Gem::Version
82
- version: '0'
26
+ version: '0.1'
83
27
  description: UseCase Gem Extention to add Rails like validations
84
28
  email:
85
29
  - goncalves.joao@gmail.com
@@ -97,6 +41,7 @@ files:
97
41
  - Rakefile
98
42
  - lib/usecasing/group_validator.rb
99
43
  - lib/usecasing/validator.rb
44
+ - lib/usecasing/validator_base.rb
100
45
  - lib/usecasing_validations.rb
101
46
  - lib/usecasing_validations/custom_validator.rb
102
47
  - lib/usecasing_validations/each_validator.rb
@@ -113,12 +58,14 @@ files:
113
58
  - spec/spec_helper.rb
114
59
  - spec/support/models/ruby_post.rb
115
60
  - spec/support/models/ruby_post_with_comments.rb
61
+ - spec/support/usecases/hierarchy_validation.rb
116
62
  - spec/support/usecases/validate_comments.rb
117
63
  - spec/support/usecases/validate_comments_custom_target.rb
118
64
  - spec/support/usecases/validate_group_validator.rb
119
65
  - spec/support/usecases/validate_post.rb
120
66
  - spec/support/usecases/validate_post_clear_errors.rb
121
67
  - spec/support/usecases/validate_uniq_comments.rb
68
+ - spec/usecasing/hierarchy_spec.rb
122
69
  - spec/usecasing/validate_comments_custom_target_spec.rb
123
70
  - spec/usecasing/validate_comments_spec.rb
124
71
  - spec/usecasing/validate_group_validator_spec.rb
@@ -148,17 +95,20 @@ rubyforge_project:
148
95
  rubygems_version: 2.2.2
149
96
  signing_key:
150
97
  specification_version: 4
151
- summary: UseCase Gem Extention to add Rails like validations
98
+ summary: UseCase Gem Extention to add Rails like validations without Rails, only needs
99
+ Ruby and usecasing gem
152
100
  test_files:
153
101
  - spec/spec_helper.rb
154
102
  - spec/support/models/ruby_post.rb
155
103
  - spec/support/models/ruby_post_with_comments.rb
104
+ - spec/support/usecases/hierarchy_validation.rb
156
105
  - spec/support/usecases/validate_comments.rb
157
106
  - spec/support/usecases/validate_comments_custom_target.rb
158
107
  - spec/support/usecases/validate_group_validator.rb
159
108
  - spec/support/usecases/validate_post.rb
160
109
  - spec/support/usecases/validate_post_clear_errors.rb
161
110
  - spec/support/usecases/validate_uniq_comments.rb
111
+ - spec/usecasing/hierarchy_spec.rb
162
112
  - spec/usecasing/validate_comments_custom_target_spec.rb
163
113
  - spec/usecasing/validate_comments_spec.rb
164
114
  - spec/usecasing/validate_group_validator_spec.rb