context_validations 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73cdca917a7c501806a934a2a078dee76089ce0e
4
- data.tar.gz: 28a7ab80f6cadfc68e930a3c605f8d5228c08fef
3
+ metadata.gz: 4c10225e24879cbd621f483a0b9dd7991a0e766c
4
+ data.tar.gz: 6a063c5a6db544b10699d27dfeaace99a201508a
5
5
  SHA512:
6
- metadata.gz: b0178c54af6220b49ce4cd14366827130c6dcad234a2bb2f44af889224b14ae55adcdf29c697d25820ec4808f93a12b232f23de5d81a664bf461484a645c6da2
7
- data.tar.gz: e05af07a17649aef1991cfc013851f8a945e0d7ef1093d464c7a898a6ad233488fbd083a15ad118b6759fa27602de97749528a77c480cb8b19e300c16a1e8845
6
+ metadata.gz: 8f87ef1b8678c4f028dbfc8c1112ad16bdff61aad0762d535920e94be5097e31d1d2d41bbd00a03ec11812f73013a0961c13357165246bf8981ae619e40d0ffa
7
+ data.tar.gz: 931c8c469b30d6e50bba0ff68d94dec5d3d0c91d16f19f3aae28ae9809e2f41b54674391e6d177244d7386f76c18953cdc0e835ef3190925301eb0f2e3562074
@@ -16,12 +16,12 @@ Gem::Specification.new do |spec|
16
16
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
17
  spec.require_paths = ['lib']
18
18
 
19
- spec.add_dependency 'activesupport'
19
+ spec.add_dependency 'activesupport', '~> 4.1'
20
20
 
21
21
  spec.add_development_dependency 'bundler', '~> 1.3'
22
22
  spec.add_development_dependency 'rake'
23
23
  spec.add_development_dependency 'minitest'
24
24
  spec.add_development_dependency 'm'
25
- spec.add_development_dependency 'activerecord'
25
+ spec.add_development_dependency 'activerecord', '~> 4.1'
26
26
  spec.add_development_dependency 'sqlite3'
27
27
  end
@@ -53,7 +53,7 @@ module ContextValidations::Controller
53
53
  key = "#{key.to_s.camelize}Validator"
54
54
  namespace = defined?(ActiveRecord) ? ActiveRecord::Base : ActiveModel::Validations
55
55
  klass = key.include?('::') ? key.constantize : namespace.const_get(key)
56
- validator = klass.new(defaults.merge(_parse_validates_options(options)))
56
+ validator = { class: klass, options: defaults.merge(_parse_validates_options(options)) }
57
57
  validators << validator
58
58
  end
59
59
  validators
@@ -22,7 +22,10 @@ module ContextValidations::Model
22
22
  #
23
23
  # @param [[ActiveMode::Validations::Validator]]
24
24
  def validations=(validations)
25
- @validations = validations.flatten
25
+ @validations = validations.flatten.map do |validator|
26
+ validator[:options][:class] = self.class
27
+ validator[:class].new(validator[:options])
28
+ end
26
29
  end
27
30
 
28
31
  protected
@@ -1,3 +1,3 @@
1
1
  module ContextValidations
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -21,7 +21,11 @@ describe 'Model' do
21
21
  end
22
22
 
23
23
  it 'accepts validations set onto the instance' do
24
- validations = [ActiveModel::Validations::PresenceValidator.new(:attributes => [:first_name]), ActiveModel::Validations::FormatValidator.new(:attributes => [:email], :with => EmailFormat), ActiveRecord::Validations::UniquenessValidator.new(:attributes => [:email])]
24
+ validations = [
25
+ {class: ActiveModel::Validations::PresenceValidator, options: { :attributes => [:first_name] }},
26
+ {class: ActiveModel::Validations::FormatValidator, options: { :attributes => [:email], :with => EmailFormat }},
27
+ {class: ActiveRecord::Validations::UniquenessValidator, options: { :attributes => [:email] }}
28
+ ]
25
29
  @user.validations = validations
26
30
  @user.valid?.must_equal false
27
31
  @user.errors.count.must_equal 2
@@ -29,10 +33,10 @@ describe 'Model' do
29
33
 
30
34
  it 'respect conditional validations set onto the instance' do
31
35
  validations = [
32
- ActiveModel::Validations::PresenceValidator.new(:attributes => [:first_name], :if => :can_validate?),
33
- ActiveModel::Validations::PresenceValidator.new(:attributes => [:first_name], :if => Proc.new { |model| model.can_validate? }),
34
- ActiveModel::Validations::PresenceValidator.new(:attributes => [:first_name], :unless => :cannot_validate?),
35
- ActiveModel::Validations::PresenceValidator.new(:attributes => [:first_name], :unless => Proc.new { |model| model.cannot_validate? })
36
+ {class: ActiveModel::Validations::PresenceValidator, options: { :attributes => [:first_name], :if => :can_validate? }},
37
+ {class: ActiveModel::Validations::PresenceValidator, options: { :attributes => [:first_name], :if => Proc.new { |model| model.can_validate? }}},
38
+ {class: ActiveModel::Validations::PresenceValidator, options: { :attributes => [:first_name], :unless => :cannot_validate? }},
39
+ {class: ActiveModel::Validations::PresenceValidator, options: { :attributes => [:first_name], :unless => Proc.new { |model| model.cannot_validate? }}}
36
40
  ]
37
41
  def @user.can_validate?
38
42
  false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: context_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Cardarella
@@ -14,16 +14,16 @@ dependencies:
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '4.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '4.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: activerecord
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ~>
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '4.1'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ~>
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '4.1'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: sqlite3
99
99
  requirement: !ruby/object:Gem::Requirement