rails_legit 0.0.3 → 0.0.4

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: 1cb1c1c1a1f24385f836da4e7305f27d9075bc35
4
- data.tar.gz: 8740159a9cc237ae6b0663d19d02c014136b8a13
3
+ metadata.gz: 3c852a68b77c2ea4bce6f56fc3c2ffe91bac8a66
4
+ data.tar.gz: dd8534eb4250f06e90aa7e4ffe3b6bb7a6ea88d6
5
5
  SHA512:
6
- metadata.gz: 42eca1cf50db6a14d592b47003d4456057ff4a01a73ef95ee460ffc62a7ebf57f7a96cd4d63f9179a047f7cb9b691c84f38504d95190eb2eb65b13fe6efa3d41
7
- data.tar.gz: e86301506150cabf4b2710e31d8245b2d1bbde6f9b0e91ac6d4e6d0fb32d50edcbff988799fb39be3365e8e9cbf5b3a9c6860aadc677991c6c6d39078c61beaa
6
+ metadata.gz: 8dcc98042967c8a2449a777198ba08ca7872a2c1e479115bffb89b9801bad5b77bbf8cb4bad7d6a0ba4d318bf954cf2510d05efd32af4087d2f89382bd8742c6
7
+ data.tar.gz: 52c3c4f9839d3b3e143fdfd278dad849e43e87c2951841f34d9978dcf77afae7b8def34cfbcdbf588dc7de282c3d01af8496be8723955134b7b5ccf2af0f7978
@@ -41,14 +41,6 @@ module RailsLegit
41
41
  end
42
42
  end
43
43
 
44
- def check_validity!
45
- options.keys.each do |key|
46
- unless VALID_COMPARISIONS.member?(key)
47
- raise ArgumentError, "Valid keys for options are #{VALID_COMPARISIONS.join(', ')}"
48
- end
49
- end
50
- end
51
-
52
44
  private
53
45
 
54
46
  def compare_both_arrays(record_array, verification_array, attribute, type_of_comparision, record)
@@ -72,7 +64,7 @@ module RailsLegit
72
64
  end
73
65
 
74
66
  def process_options!
75
- options.each do |k, v|
67
+ options.slice(*VALID_COMPARISIONS).each do |k, v|
76
68
  unless v.is_a?(Proc) || v.is_a?(Symbol) || v.is_a?(Array)
77
69
  raise ArgumentError, "Valid values for options are a Proc or Symbol or an Array"
78
70
  end
@@ -48,16 +48,8 @@ module RailsLegit
48
48
  end
49
49
  end
50
50
 
51
- def check_validity!
52
- options.keys.each do |key|
53
- unless VALID_COMPARISIONS.member?(key)
54
- raise ArgumentError, "Valid keys for options are #{VALID_COMPARISIONS.keys.join(", ")}"
55
- end
56
- end
57
- end
58
-
59
51
  def process_options!
60
- options.each do |k, v|
52
+ options.slice(*VALID_COMPARISIONS.keys).each do |k, v|
61
53
  if v.respond_to?(:to_date)
62
54
  comparisions[k] = v.send(:to_date)
63
55
  elsif v.is_a? Proc
@@ -43,14 +43,6 @@ module RailsLegit
43
43
  end
44
44
  end
45
45
 
46
- def check_validity!
47
- options.keys.each do |key|
48
- unless VALID_COMPARISIONS.member?(key)
49
- raise ArgumentError, "Valid keys for options are #{VALID_COMPARISIONS.join(', ')}"
50
- end
51
- end
52
- end
53
-
54
46
  private
55
47
 
56
48
  def compare_both_arrays(record_hash, verification_array, attribute, type_of_comparision, record)
@@ -69,7 +61,7 @@ module RailsLegit
69
61
  end
70
62
 
71
63
  def process_options!
72
- options.each do |k, v|
64
+ options.slice(*VALID_COMPARISIONS).each do |k, v|
73
65
  unless v.is_a?(Proc) || v.is_a?(Symbol) || v.is_a?(Array)
74
66
  raise ArgumentError, "You need to specify either an Array or a Symbol or a Proc that returns an Array as an option value"
75
67
  end
@@ -1,3 +1,3 @@
1
1
  module RailsLegit
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_legit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kashyap
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-20 00:00:00.000000000 Z
11
+ date: 2014-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -74,26 +74,14 @@ executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
- - .gitignore
78
- - .travis.yml
79
- - Gemfile
80
- - LICENSE.txt
81
- - README.md
82
- - Rakefile
83
- - gemfiles/Gemfile.am-3.2
84
77
  - lib/rails_legit.rb
85
78
  - lib/rails_legit/verify_array_validator.rb
86
79
  - lib/rails_legit/verify_date_validator.rb
87
80
  - lib/rails_legit/verify_hash_validator.rb
88
81
  - lib/rails_legit/version.rb
89
- - rails_legit.gemspec
90
- - spec/spec_helper.rb
91
- - spec/support/array.rb
92
- - spec/support/date.rb
93
- - spec/support/hash.rb
94
- - spec/verify_array_validator_spec.rb
95
- - spec/verify_date_validator_spec.rb
96
- - spec/verify_hash_validator_spec.rb
82
+ - Rakefile
83
+ - README.md
84
+ - LICENSE.txt
97
85
  homepage: ''
98
86
  licenses:
99
87
  - MIT
@@ -118,12 +106,5 @@ rubygems_version: 2.0.14
118
106
  signing_key:
119
107
  specification_version: 4
120
108
  summary: Provides a DSL for common validation formats like Date, Array, DateTime etc.
121
- test_files:
122
- - spec/spec_helper.rb
123
- - spec/support/array.rb
124
- - spec/support/date.rb
125
- - spec/support/hash.rb
126
- - spec/verify_array_validator_spec.rb
127
- - spec/verify_date_validator_spec.rb
128
- - spec/verify_hash_validator_spec.rb
109
+ test_files: []
129
110
  has_rdoc:
data/.gitignore DELETED
@@ -1,18 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- vendor/
@@ -1,11 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.0
6
- gemfile:
7
- - Gemfile
8
- - gemfiles/Gemfile.am-3.2
9
-
10
- script:
11
- - bundle exec rspec spec
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in rails-legit.gemspec
4
- gemspec
@@ -1,6 +0,0 @@
1
- # -*- ruby -*-
2
-
3
- source "http://rubygems.org"
4
-
5
- gemspec path: '..'
6
- gem 'activemodel', "~> 3.2"
@@ -1,25 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'rails_legit/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "rails_legit"
8
- spec.version = RailsLegit::VERSION
9
- spec.authors = ["Kashyap"]
10
- spec.email = ["kashyap.kmbc@gmail.com"]
11
- spec.description = %q{Provides a DSL for common validation formats like Date, Array, DateTime etc.}
12
- spec.summary = %q{Provides a DSL for common validation formats like Date, Array, DateTime etc.}
13
- spec.homepage = ""
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec"
24
- spec.add_dependency "activemodel", "> 3.0"
25
- end
@@ -1,21 +0,0 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # Require this file using `require "spec_helper"` to ensure that it is only
4
- # loaded once.
5
- #
6
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
-
8
- require File.expand_path("../../lib/rails_legit.rb", __FILE__)
9
- #Dir["spec/support/**/*.rb"].each { |f| require File.expand_path(f) }
10
-
11
- RSpec.configure do |config|
12
- config.treat_symbols_as_metadata_keys_with_true_values = true
13
- config.run_all_when_everything_filtered = true
14
- config.filter_run :focus
15
-
16
- # Run specs in random order to surface order dependencies. If you find an
17
- # order dependency and want to debug it, you can fix the order by providing
18
- # the seed, which is printed after each run.
19
- # --seed 1234
20
- config.order = 'random'
21
- end
@@ -1,89 +0,0 @@
1
- require "active_model"
2
-
3
- # Setup Classes
4
-
5
- class NoOptionsSingleAttribute
6
- include ActiveModel::Validations
7
- include RailsLegit
8
-
9
- validates :array, verify_array: true
10
-
11
- attr_accessor :array
12
- def initialize(array)
13
- @array = array
14
- end
15
- end
16
-
17
- class BaseRecord
18
- include ActiveModel::Validations
19
- include RailsLegit
20
-
21
- attr_accessor :array, :anotherarray
22
-
23
- def initialize(array, anotherarray)
24
- @array = array
25
- @anotherarray = anotherarray
26
- end
27
- end
28
-
29
- class NoOptionsMultipleAttributes < BaseRecord
30
- validates :array, :anotherarray, verify_array: true
31
- end
32
-
33
- class MultipleAttributesInOptionArray < BaseRecord
34
- validates :array, :anotherarray, verify_array: { in: [1, 2, 3, 4] }
35
- end
36
-
37
- class MultipleAttributesNotInOptionArray < BaseRecord
38
- validates :array, :anotherarray, verify_array: { not_in: [1, 2, 3, 4] }
39
- end
40
-
41
- class MultipleAttributesInOptionProc < BaseRecord
42
- validates :array, :anotherarray, verify_array: { in: ->{ [1, 2, 3, 4] } }
43
- end
44
-
45
- class MultipleAttributesNotInOptionProc < BaseRecord
46
- validates :array, :anotherarray, verify_array: { not_in: ->{ [1, 2, 3, 4] } }
47
- end
48
-
49
- class MultipleAttributesInOptionSymbol < BaseRecord
50
- validates :array, :anotherarray, verify_array: { in: :some_other_array }
51
-
52
- private
53
-
54
- def some_other_array
55
- [1, 2, 3, 4]
56
- end
57
- end
58
-
59
- class MultipleAttributesNotInOptionSymbol < BaseRecord
60
- validates :array, :anotherarray, verify_array: { not_in: :some_other_array }
61
-
62
- private
63
-
64
- def some_other_array
65
- [1, 2, 3, 4]
66
- end
67
- end
68
-
69
- class MultipleAttributesBothOptionsSymbol < BaseRecord
70
- validates :array, :anotherarray, verify_array: { in: :some_array, not_in: :some_other_array }
71
-
72
- private
73
-
74
- def some_array
75
- [1, 2, 3, 4]
76
- end
77
-
78
- def some_other_array
79
- [5, 6, 7, 8]
80
- end
81
- end
82
-
83
- class MultipleAttributesBothOptionsProc < BaseRecord
84
- validates :array, :anotherarray, verify_array: { in: ->{ [1, 2, 3, 4] }, not_in: ->{ [5, 6, 7, 8] } }
85
- end
86
-
87
- class MultipleAttributesBothOptionsArray < BaseRecord
88
- validates :array, :anotherarray, verify_array: { in: [1, 2, 3, 4], not_in: [5, 6, 7, 8] }
89
- end
@@ -1,98 +0,0 @@
1
- require "active_model"
2
- require "active_support/core_ext/string/conversions"
3
-
4
- shared_examples "basic date validations" do
5
-
6
- context "Invalid Date" do
7
- let(:date) { "Invalid Date" }
8
- it { should be_invalid }
9
- end
10
-
11
- context "Valid Date as a String" do
12
- let(:date) { "21 December 2013" }
13
- it { should be_valid }
14
- end
15
-
16
- context "Valid Date as a Date object" do
17
- let(:date) { Date.today }
18
- it { should be_valid }
19
- end
20
-
21
- context "Valid Date as a DateTime object" do
22
- let(:date) { DateTime.now }
23
- it { should be_valid }
24
- end
25
-
26
- context "Valid Date as a Time object" do
27
- let(:date) { Time.now }
28
- it { should be_valid }
29
- end
30
- end
31
-
32
- # Setup Classes
33
-
34
- class TestRecordWithNoExtraOptions
35
- include ActiveModel::Validations
36
- include RailsLegit
37
-
38
- validates :date, verify_date: true
39
-
40
- attr_accessor :date
41
- def initialize(date)
42
- @date = date
43
- end
44
- end
45
-
46
- class TestRecordWithNoExtraOptionsMultipleAttributes
47
- include ActiveModel::Validations
48
- include RailsLegit
49
-
50
- validates :date, :anotherdate, verify_date: true
51
-
52
- attr_accessor :date, :anotherdate
53
- def initialize(date, anotherdate)
54
- @date = date
55
- @anotherdate = anotherdate
56
- end
57
- end
58
-
59
- class TestRecordWithMultipleAttributesBeforeOption
60
- include ActiveModel::Validations
61
- include RailsLegit
62
-
63
- validates :date, :anotherdate, verify_date: { before: :before_date }
64
-
65
- attr_accessor :date, :anotherdate, :before_date
66
- def initialize(date, anotherdate, before_date)
67
- @date = date
68
- @anotherdate = anotherdate
69
- @before_date = before_date
70
- end
71
- end
72
-
73
- class TestRecordWithMultipleAttributesBeforeOptionCurrentSymbol
74
- include ActiveModel::Validations
75
- include RailsLegit
76
-
77
- validates :date, :anotherdate, verify_date: { before: :today }
78
-
79
- attr_accessor :date, :anotherdate, :before_date
80
- def initialize(date, anotherdate, before_date)
81
- @date = date
82
- @anotherdate = anotherdate
83
- @before_date = before_date
84
- end
85
- end
86
-
87
- class TestRecordWithMultipleAttributesBeforeOptionProc
88
- include ActiveModel::Validations
89
- include RailsLegit
90
-
91
- validates :date, :anotherdate, verify_date: { before: ->{ Date.today + 1 } }
92
-
93
- attr_accessor :date, :anotherdate
94
- def initialize(date, anotherdate)
95
- @date = date
96
- @anotherdate = anotherdate
97
- end
98
- end
@@ -1,90 +0,0 @@
1
- require "active_model"
2
-
3
- # Setup Classes
4
-
5
- class NoExtraOptionsHash
6
- include ActiveModel::Validations
7
- include RailsLegit
8
-
9
- validates :hash, verify_hash: true
10
-
11
- attr_accessor :hash
12
- def initialize(hash)
13
- @hash = hash
14
- end
15
- end
16
-
17
- class BaseRecordHashValidator
18
- include ActiveModel::Validations
19
- include RailsLegit
20
-
21
-
22
- attr_accessor :hash, :anotherhash
23
- def initialize(hash, anotherhash)
24
- @hash = hash
25
- @anotherhash = anotherhash
26
- end
27
-
28
- end
29
-
30
- class NoOptionsMultipleAttributesHash < BaseRecordHashValidator
31
- validates :hash, :anotherhash, verify_hash: true
32
- end
33
-
34
- class MultipleAttributesKeysOptionSymbol < BaseRecordHashValidator
35
- validates :hash, :anotherhash, verify_hash: { keys: :some_other_array }
36
-
37
- private
38
-
39
- def some_other_array
40
- [:one, :two, :three, :four, :five]
41
- end
42
- end
43
-
44
- class MultipleAttributesValuesOptionSymbol < BaseRecordHashValidator
45
- validates :hash, :anotherhash, verify_hash: { values: :some_other_array }
46
-
47
- private
48
-
49
- def some_other_array
50
- [1, 2, 3, 4, 5]
51
- end
52
- end
53
-
54
- class MultipleAttributesKeysOptionArray < BaseRecordHashValidator
55
- validates :hash, :anotherhash, verify_hash: { keys: [:one, :two, :three, :four] }
56
- end
57
-
58
- class MultipleAttributesValuesOptionArray < BaseRecordHashValidator
59
- validates :hash, :anotherhash, verify_hash: { values: [1, 2, 3, 4] }
60
- end
61
-
62
- class MultipleAttributesKeysOptionProc < BaseRecordHashValidator
63
- validates :hash, :anotherhash, verify_hash: { keys: ->{ [:one, :two, :three, :four] } }
64
- end
65
-
66
- class MultipleAttributesValuesOptionProc < BaseRecordHashValidator
67
- validates :hash, :anotherhash, verify_hash: { values: ->{ [1, 2, 3, 4] } }
68
- end
69
-
70
- class MultipleAttributesKeysValuesOptionProc < BaseRecordHashValidator
71
- validates :hash, :anotherhash, verify_hash: { keys: ->{ [:one, :two, :three, :four] }, values: ->{ [1, 2, 3, 4] } }
72
- end
73
-
74
- class MultipleAttributesKeysValuesOptionArray < BaseRecordHashValidator
75
- validates :hash, :anotherhash, verify_hash: { keys: [:one, :two, :three, :four], values: [1, 2, 3, 4] }
76
- end
77
-
78
- class MultipleAttributesKeysValuesOptionSymbol < BaseRecordHashValidator
79
- validates :hash, :anotherhash, verify_hash: { keys: :some_array, values: :some_other_array }
80
-
81
- def some_array
82
- [:one, :two, :three, :four]
83
- end
84
-
85
- private
86
-
87
- def some_other_array
88
- [1, 2, 3, 4]
89
- end
90
- end
@@ -1,186 +0,0 @@
1
- require "spec_helper"
2
- require "support/array"
3
-
4
- describe RailsLegit::VerifyArrayValidator do
5
- subject { record }
6
-
7
- describe "No Extra Options provided" do
8
- let(:record) { NoOptionsSingleAttribute.new(array) }
9
-
10
- context "Valid Array" do
11
- let(:array) { [1, 2, 3] }
12
- it { should be_valid }
13
- end
14
-
15
- context "Invalid Array" do
16
- let(:array) { "Invalid Array" }
17
-
18
- it { should_not be_valid }
19
- it "should attach error on appropriate method" do
20
- record.valid?
21
- expect(record.errors[:array]).to include("Not an Array")
22
- end
23
- end
24
- end
25
-
26
- describe "No Extra Options provided and multiple attributes" do
27
- let(:record) { NoOptionsMultipleAttributes.new(array, anotherarray) }
28
- let(:anotherarray) { [1, 2, 3] }
29
-
30
- context "Valid Array" do
31
- let(:array) { [1, 2, 3] }
32
- it { should be_valid }
33
- end
34
-
35
- context "Invalid Array on comparision method" do
36
- let(:anotherarray) { "Invalid Array" }
37
- let(:array) { [1, 2, 3] }
38
-
39
- it { should_not be_valid }
40
- it "should attach error on appropriate method" do
41
- record.valid?
42
- expect(record.errors[:anotherarray]).to include("Not an Array")
43
- end
44
- end
45
- end
46
-
47
- describe "Multiple attributes, Valid case" do
48
- let(:array) { [1, 2, 3] }
49
- let(:anotherarray) { [4, 3] }
50
-
51
- context "In validator" do
52
- context "comparision object is a Proc" do
53
- let(:record) { MultipleAttributesInOptionProc.new(array, anotherarray) }
54
-
55
- it { should be_valid }
56
- end
57
-
58
- context "comparision object is a Symbol" do
59
- let(:record) { MultipleAttributesInOptionSymbol.new(array, anotherarray) }
60
-
61
- it { should be_valid }
62
- end
63
-
64
- context "comparision object is Array" do
65
- let(:record) { MultipleAttributesInOptionArray.new(array, anotherarray) }
66
-
67
- it { should be_valid }
68
- end
69
- end
70
-
71
- context "NotIn validator" do
72
- context "comparision object is a Proc" do
73
- let(:record) { MultipleAttributesNotInOptionProc.new(array, anotherarray) }
74
-
75
- it { should_not be_valid }
76
- end
77
-
78
- context "comparision object is a Symbol" do
79
- let(:record) { MultipleAttributesNotInOptionSymbol.new(array, anotherarray) }
80
-
81
- it { should_not be_valid }
82
- end
83
-
84
- context "comparision object is Array" do
85
- let(:record) { MultipleAttributesNotInOptionArray.new(array, anotherarray) }
86
-
87
- it { should_not be_valid }
88
- end
89
- end
90
- end
91
-
92
- describe "Multiple attributes, Invalid case" do
93
- let(:array) { [4, 1, 5] }
94
- let(:anotherarray) { [8, 9] }
95
-
96
- context "In validator" do
97
- context "comparision object is a Proc" do
98
- let(:record) { MultipleAttributesInOptionProc.new(array, anotherarray) }
99
-
100
- it { should_not be_valid }
101
- end
102
-
103
- context "comparision object is a Symbol" do
104
- let(:record) { MultipleAttributesInOptionSymbol.new(array, anotherarray) }
105
-
106
- it { should_not be_valid }
107
- end
108
-
109
- context "comparision object is Array" do
110
- let(:record) { MultipleAttributesInOptionArray.new(array, anotherarray) }
111
-
112
- it { should_not be_valid }
113
- end
114
- end
115
-
116
- context "NotIn validator" do
117
- context "comparision object is a Proc" do
118
- let(:record) { MultipleAttributesNotInOptionProc.new(array, anotherarray) }
119
-
120
- it { should be_valid }
121
- end
122
-
123
- context "comparision object is a Symbol" do
124
- let(:record) { MultipleAttributesNotInOptionSymbol.new(array, anotherarray) }
125
-
126
- it { should be_valid }
127
- end
128
-
129
- context "comparision object is Array" do
130
- let(:record) { MultipleAttributesNotInOptionArray.new(array, anotherarray) }
131
-
132
- it { should be_valid }
133
- end
134
- end
135
- end
136
-
137
- describe "Both Options, Valid case" do
138
- let(:array) { [1, 2] }
139
- let(:anotherarray) { [1, 2, 3, 4] }
140
-
141
- context "In validator" do
142
- context "comparision against Proc" do
143
- let(:record) { MultipleAttributesBothOptionsProc.new(array, anotherarray) }
144
-
145
- it { should be_valid }
146
- end
147
-
148
- context "comparision against Symbol" do
149
- let(:record) { MultipleAttributesBothOptionsSymbol.new(array, anotherarray) }
150
-
151
- it { should be_valid }
152
- end
153
-
154
- context "comparision against Array" do
155
- let(:record) { MultipleAttributesBothOptionsArray.new(array, anotherarray) }
156
-
157
- it { should be_valid }
158
- end
159
- end
160
- end
161
-
162
- describe "Both Options, Invalid case" do
163
- let(:array) { [5, 6] }
164
- let(:anotherarray) { [3, 4] }
165
-
166
- context "In validator" do
167
- context "comparision against Proc" do
168
- let(:record) { MultipleAttributesBothOptionsProc.new(array, anotherarray) }
169
-
170
- it { should_not be_valid }
171
- end
172
-
173
- context "comparision against Symbol" do
174
- let(:record) { MultipleAttributesBothOptionsSymbol.new(array, anotherarray) }
175
-
176
- it { should_not be_valid }
177
- end
178
-
179
- context "comparision against Array" do
180
- let(:record) { MultipleAttributesBothOptionsArray.new(array, anotherarray) }
181
-
182
- it { should_not be_valid }
183
- end
184
- end
185
- end
186
- end
@@ -1,93 +0,0 @@
1
- require "spec_helper"
2
- require "support/date"
3
-
4
- describe RailsLegit::VerifyDateValidator do
5
- describe "No Extra Options provided" do
6
- let(:record) { TestRecordWithNoExtraOptions.new(date) }
7
- subject { record }
8
-
9
- include_examples "basic date validations"
10
-
11
- context "Invalid Date" do
12
- let(:date) { "Invalid Date" }
13
-
14
- it "should attach error on appropriate method" do
15
- record.valid?
16
- expect(record.errors[:date]).to include("Invalid Date Format")
17
- end
18
- end
19
- end
20
-
21
- describe "No Extra Options provided and multiple attributes" do
22
- let(:record) { TestRecordWithNoExtraOptionsMultipleAttributes.new(date, anotherdate) }
23
- let(:anotherdate) { Date.today }
24
- subject { record }
25
-
26
- include_examples "basic date validations"
27
-
28
- context "Invalid Date on comparision method" do
29
- let(:anotherdate) { "Invalid Date" }
30
- let(:date) { Date.today }
31
-
32
- it "should attach error on appropirate method" do
33
- record.valid?
34
- expect(record.errors[:anotherdate]).to include("Invalid Date Format")
35
- end
36
- end
37
- end
38
-
39
- describe "Before option, multiple attributes" do
40
- let(:date) { "12 december 1900" }
41
- subject { record }
42
-
43
- context "Dates in the past" do
44
- let(:anotherdate) { Date.today - 1 }
45
-
46
- context "comparision object is a Proc" do
47
- let(:record) { TestRecordWithMultipleAttributesBeforeOptionProc.new(date, anotherdate) }
48
- it { should be_valid }
49
- end
50
-
51
- context "comparision object is a Symbol" do
52
- let(:before_date) { Date.today + 1 }
53
- let(:record) { TestRecordWithMultipleAttributesBeforeOption.new(date, anotherdate, before_date) }
54
-
55
- it { should be_valid }
56
- end
57
-
58
- context "comparision object is :current" do
59
- let(:before_date) { :current }
60
- let(:record) { TestRecordWithMultipleAttributesBeforeOptionCurrentSymbol.new(date, anotherdate, before_date) }
61
-
62
- it { should be_valid }
63
- end
64
- end
65
-
66
- context "Dates in the future" do
67
- let(:anotherdate) { Date.today + 100 }
68
-
69
- context "comparision object is a Proc" do
70
- let(:record) { TestRecordWithMultipleAttributesBeforeOptionProc.new(date, anotherdate) }
71
- it { should be_invalid }
72
-
73
- it "should attach error to the correct attribute" do
74
- record.valid?
75
- message = "Occurs before #{Date.today + 1}"
76
- expect(record.errors[:anotherdate]).to include(message)
77
- end
78
- end
79
-
80
- context "comparision object is a Symbol" do
81
- let(:before_date) { Date.today + 1 }
82
- let(:record) { TestRecordWithMultipleAttributesBeforeOption.new(date, anotherdate, before_date) }
83
-
84
- it { should be_invalid }
85
-
86
- it "should attach error to the correct attribute" do
87
- record.valid?
88
- expect(record.errors[:anotherdate]).to include("Occurs before Before date")
89
- end
90
- end
91
- end
92
- end
93
- end
@@ -1,186 +0,0 @@
1
- require "spec_helper"
2
- require "support/hash"
3
-
4
- describe RailsLegit::VerifyHashValidator do
5
- describe "No Extra Options provided" do
6
- let(:record) { NoExtraOptionsHash.new(hash) }
7
- subject { record }
8
-
9
- context "Valid Hash" do
10
- let(:hash) { { one: 1, two: 2, three: 3, four: 4 } }
11
- it { should be_valid }
12
- end
13
-
14
- context "Invalid Hash" do
15
- let(:hash) { "Invalid Hash" }
16
-
17
- it { should_not be_valid }
18
- it "should attach error on appropriate method" do
19
- record.valid?
20
- expect(record.errors[:hash]).to include("Not a Hash")
21
- end
22
- end
23
- end
24
-
25
- describe "No Extra Options provided and multiple attributes" do
26
- let(:record) { NoOptionsMultipleAttributesHash.new(hash, anotherhash) }
27
- let(:anotherhash) { {one: 1, two: 2} }
28
- subject { record }
29
-
30
- context "Valid Hash" do
31
- let(:hash) { {one: 1, two: 2, three: 3} }
32
- it { should be_valid }
33
- end
34
-
35
- context "Invalid Hash on comparision method" do
36
- let(:anotherhash) { "Invalid Hash" }
37
- let(:hash) { { one: 1, two: 2, three: 3 } }
38
-
39
- it { should_not be_valid }
40
- it "should attach error on appropriate method" do
41
- record.valid?
42
- expect(record.errors[:anotherhash]).to include("Not a Hash")
43
- end
44
- end
45
- end
46
-
47
- describe "Individual Keys and Values options, Multiple attributes, Valid case" do
48
- let(:hash) { { one: 1, two: 2, three: 3 } }
49
- let(:anotherhash) { { four: 4, three: 3 } }
50
- subject { record }
51
-
52
- context "Keys as the option" do
53
- context "comparision object is a Proc" do
54
- let(:record) { MultipleAttributesKeysOptionProc.new(hash, anotherhash) }
55
-
56
- it { should be_valid }
57
- end
58
-
59
- context "comparision object is a Symbol" do
60
- let(:record) { MultipleAttributesKeysOptionSymbol.new(hash, anotherhash) }
61
-
62
- it { should be_valid }
63
- end
64
-
65
- context "comparision object is Array" do
66
- let(:record) { MultipleAttributesKeysOptionArray.new(hash, anotherhash) }
67
-
68
- it { should be_valid }
69
- end
70
- end
71
-
72
- context "Values as the option" do
73
- context "comparision object is a Proc" do
74
- let(:record) { MultipleAttributesValuesOptionProc.new(hash, anotherhash) }
75
-
76
- it { should be_valid }
77
- end
78
-
79
- context "comparision object is a Symbol" do
80
- let(:record) { MultipleAttributesValuesOptionSymbol.new(hash, anotherhash) }
81
-
82
- it { should be_valid }
83
- end
84
-
85
- context "comparision object is Array" do
86
- let(:record) { MultipleAttributesValuesOptionArray.new(hash, anotherhash) }
87
-
88
- it { should be_valid }
89
- end
90
- end
91
- end
92
-
93
- describe "Individual Keys and Values options, Multiple attributes, Invalid case" do
94
- let(:hash) { { seven: 7, eight: 8, nine: 9 } }
95
- let(:anotherhash) { { ten: 10, eleven: 11 } }
96
- subject { record }
97
-
98
- context "Keys as the option" do
99
- context "comparision object is a Proc" do
100
- let(:record) { MultipleAttributesKeysOptionProc.new(hash, anotherhash) }
101
-
102
- it { should_not be_valid }
103
- end
104
-
105
- context "comparision object is a Symbol" do
106
- let(:record) { MultipleAttributesKeysOptionSymbol.new(hash, anotherhash) }
107
-
108
- it { should_not be_valid }
109
- end
110
-
111
- context "comparision object is Array" do
112
- let(:record) { MultipleAttributesKeysOptionArray.new(hash, anotherhash) }
113
-
114
- it { should_not be_valid }
115
- end
116
- end
117
-
118
- context "Values as the option" do
119
- context "comparision object is a Proc" do
120
- let(:record) { MultipleAttributesValuesOptionProc.new(hash, anotherhash) }
121
-
122
- it { should_not be_valid }
123
- end
124
-
125
- context "comparision object is a Symbol" do
126
- let(:record) { MultipleAttributesValuesOptionSymbol.new(hash, anotherhash) }
127
-
128
- it { should_not be_valid }
129
- end
130
-
131
- context "comparision object is Array" do
132
- let(:record) { MultipleAttributesValuesOptionArray.new(hash, anotherhash) }
133
-
134
- it { should_not be_valid }
135
- end
136
- end
137
- end
138
-
139
- describe "Both Keys and Values options, Multiple attributes, Valid case" do
140
- let(:hash) { { one: 1, two: 2, three: 3 } }
141
- let(:anotherhash) { { four: 4, three: 3 } }
142
- subject { record }
143
-
144
- context "comparision object is a Proc" do
145
- let(:record) { MultipleAttributesKeysValuesOptionProc.new(hash, anotherhash) }
146
-
147
- it { should be_valid }
148
- end
149
-
150
- context "comparision object is a Symbol" do
151
- let(:record) { MultipleAttributesKeysValuesOptionSymbol.new(hash, anotherhash) }
152
-
153
- it { should be_valid }
154
- end
155
-
156
- context "comparision object is Array" do
157
- let(:record) { MultipleAttributesKeysValuesOptionArray.new(hash, anotherhash) }
158
-
159
- it { should be_valid }
160
- end
161
- end
162
-
163
- describe "Both Keys and Values options, Multiple attributes, Invalid case" do
164
- let(:hash) { { five: 5, six: 6, seven: 7 } }
165
- let(:anotherhash) { { nine: 9, ten: 10 } }
166
- subject { record }
167
-
168
- context "comparision object is a Proc" do
169
- let(:record) { MultipleAttributesKeysValuesOptionProc.new(hash, anotherhash) }
170
-
171
- it { should_not be_valid }
172
- end
173
-
174
- context "comparision object is a Symbol" do
175
- let(:record) { MultipleAttributesKeysValuesOptionSymbol.new(hash, anotherhash) }
176
-
177
- it { should_not be_valid }
178
- end
179
-
180
- context "comparision object is Array" do
181
- let(:record) { MultipleAttributesKeysValuesOptionArray.new(hash, anotherhash) }
182
-
183
- it { should_not be_valid }
184
- end
185
- end
186
- end