g5_integrations_validations 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/g5_integrations_validations.gemspec +27 -0
- data/lib/g5_integrations_validations.rb +11 -0
- data/lib/g5_integrations_validations/centershift_inventory_validations.rb +53 -0
- data/lib/g5_integrations_validations/rate_validations.rb +71 -0
- data/lib/g5_integrations_validations/site_link_inventory_validations.rb +40 -0
- data/lib/g5_integrations_validations/site_link_lead_rent_now_validations.rb +11 -0
- data/lib/g5_integrations_validations/site_link_lead_validations.rb +12 -0
- data/lib/g5_integrations_validations/version.rb +3 -0
- data/lib/g5_integrations_validations/yardi_voyager_lead_validations.rb +21 -0
- data/spec/fixtures/centershift_inventory.rb +19 -0
- data/spec/fixtures/site_link_inventory.rb +17 -0
- data/spec/fixtures/site_link_lead.rb +7 -0
- data/spec/fixtures/site_link_lead_rent_now.rb +7 -0
- data/spec/fixtures/yardi_voyager_lead.rb +13 -0
- data/spec/g5_integrations_validations/centershift_inventory_validations_spec.rb +32 -0
- data/spec/g5_integrations_validations/rate_validations_spec.rb +192 -0
- data/spec/g5_integrations_validations/site_link_inventory_validations_spec.rb +49 -0
- data/spec/g5_integrations_validations/site_link_lead_rent_now_validations_spec.rb +11 -0
- data/spec/g5_integrations_validations/site_link_lead_validations_spec.rb +11 -0
- data/spec/g5_integrations_validations/yardi_voyager_lead_validations_spec.rb +16 -0
- data/spec/spec_helper.rb +8 -0
- metadata +166 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7c653f75343db7fdb1da313ad84a27013054e481
|
4
|
+
data.tar.gz: 59da00eca4f10f9088e1ffe217f6d585337bd492
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2b4a60982200ce9d16f69648f8861efe61b835f24d9bedf1074e3070276fcd0ababddf98389f3546826c92b257c5084fe90a2cce4413326ec8978a58a0aec115
|
7
|
+
data.tar.gz: 15e01b1d0d1e0f11ba8c7c2480a0dcb38f1e7314525ac2baff0bf3aa6e275e536a3c4adfce55be882c7cc9c84e8c249ff2a8ffd9634ab14065cabc4c360221b4
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ramon Tayag
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# G5IntegrationsValidations
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'g5_integrations_validations'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install g5_integrations_validations
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/g5_integrations_validations/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'g5_integrations_validations/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "g5_integrations_validations"
|
8
|
+
spec.version = G5IntegrationsValidations::VERSION
|
9
|
+
spec.authors = ["Ramon Tayag"]
|
10
|
+
spec.email = ["ramon.tayag@gmail.com"]
|
11
|
+
spec.summary = %q{Common validations for G5 Integrations}
|
12
|
+
spec.description = %q{Common validations for G5 Integrations}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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_dependency "activemodel"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "virtus"
|
26
|
+
spec.add_development_dependency "shoulda-matchers", "~> 2.7"
|
27
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "active_model"
|
2
|
+
require "g5_integrations_validations/version"
|
3
|
+
require "g5_integrations_validations/centershift_inventory_validations"
|
4
|
+
require "g5_integrations_validations/site_link_inventory_validations"
|
5
|
+
require "g5_integrations_validations/site_link_lead_validations"
|
6
|
+
require "g5_integrations_validations/site_link_lead_rent_now_validations"
|
7
|
+
require "g5_integrations_validations/rate_validations"
|
8
|
+
require "g5_integrations_validations/yardi_voyager_lead_validations"
|
9
|
+
|
10
|
+
module G5IntegrationsValidations
|
11
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module G5IntegrationsValidations
|
2
|
+
module CentershiftInventoryValidations
|
3
|
+
VALID_RATE_BASES = [
|
4
|
+
"street_rate",
|
5
|
+
"proforma_rate",
|
6
|
+
"rack_rate",
|
7
|
+
"future_rate",
|
8
|
+
"push_rate",
|
9
|
+
"rent_rate",
|
10
|
+
"maximum_rent_rate",
|
11
|
+
"minimum_rent_rate",
|
12
|
+
]
|
13
|
+
VALID_IN_STORE_RATE_BASES = VALID_RATE_BASES + ['calculated_from_web_rate']
|
14
|
+
VALID_WEB_RATE_BASES = VALID_RATE_BASES + ['calculated_from_in_store_rate']
|
15
|
+
CTAS_THRESHOLD_OPTIONS = [
|
16
|
+
"hard_reservation_with_fee",
|
17
|
+
"hard_reservation",
|
18
|
+
"soft_reservation",
|
19
|
+
"quote",
|
20
|
+
]
|
21
|
+
|
22
|
+
extend ActiveSupport::Concern
|
23
|
+
|
24
|
+
included do
|
25
|
+
include ActiveModel::Validations
|
26
|
+
include G5IntegrationsValidations::RateValidations.model(
|
27
|
+
in_store_rate_bases: VALID_IN_STORE_RATE_BASES,
|
28
|
+
web_rate_bases: VALID_WEB_RATE_BASES,
|
29
|
+
)
|
30
|
+
|
31
|
+
validates(
|
32
|
+
:cta_hard_reservation_with_fee_url,
|
33
|
+
:cta_hard_reservation_url,
|
34
|
+
:cta_soft_reservation_url,
|
35
|
+
:cta_quote_url,
|
36
|
+
presence: true
|
37
|
+
)
|
38
|
+
|
39
|
+
validates :unit_availability_threshold, presence: true
|
40
|
+
validates(:unit_availability_cta_in_and_above_threshold, {
|
41
|
+
presence: true,
|
42
|
+
inclusion: {in: CTAS_THRESHOLD_OPTIONS}
|
43
|
+
})
|
44
|
+
validates(:unit_availability_cta_below_threshold, {
|
45
|
+
inclusion: {in: CTAS_THRESHOLD_OPTIONS},
|
46
|
+
allow_blank: true
|
47
|
+
})
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module G5IntegrationsValidations
|
2
|
+
module RateValidations
|
3
|
+
|
4
|
+
def self.model(options={})
|
5
|
+
mod = Module.new do
|
6
|
+
mattr_accessor :g5_integrations_validations_rate_options
|
7
|
+
|
8
|
+
def self.included(base)
|
9
|
+
base.class_attribute :g5_integrations_validations_rate_options
|
10
|
+
base.g5_integrations_validations_rate_options =
|
11
|
+
self.g5_integrations_validations_rate_options
|
12
|
+
base.send :include, RateValidations
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
mod.g5_integrations_validations_rate_options = options
|
17
|
+
|
18
|
+
mod
|
19
|
+
end
|
20
|
+
|
21
|
+
extend ActiveSupport::Concern
|
22
|
+
|
23
|
+
included do
|
24
|
+
include ActiveModel::Validations
|
25
|
+
|
26
|
+
validates(:in_store_rate_percentage, {
|
27
|
+
presence: true,
|
28
|
+
numericality: {greater_than_or_equal_to: 0},
|
29
|
+
if: -> (o) { o.in_store_rate_basis == 'calculated_from_web_rate' },
|
30
|
+
})
|
31
|
+
validates(:web_rate_discount, {
|
32
|
+
numericality: {greater_than_or_equal_to: 0, less_than_or_equal_to: 100},
|
33
|
+
if: -> (o) { o.web_rate_basis == 'calculated_from_in_store_rate' },
|
34
|
+
})
|
35
|
+
validates(:web_rate_basis, {
|
36
|
+
inclusion: {
|
37
|
+
in: g5_integrations_validations_rate_options[:web_rate_bases],
|
38
|
+
allow_blank: true,
|
39
|
+
},
|
40
|
+
})
|
41
|
+
validates(:web_rate_basis, {
|
42
|
+
presence: true,
|
43
|
+
exclusion: {
|
44
|
+
in: %w(calculated_from_in_store_rate),
|
45
|
+
message: "cannot be the in-store rate because the in-store rate is not set or is based on the web rate",
|
46
|
+
},
|
47
|
+
if: -> (o) do
|
48
|
+
o.in_store_rate_basis == 'calculated_from_web_rate' ||
|
49
|
+
o.in_store_rate_basis.nil?
|
50
|
+
end,
|
51
|
+
})
|
52
|
+
validates(:in_store_rate_basis, {
|
53
|
+
presence: true,
|
54
|
+
inclusion: {
|
55
|
+
in: g5_integrations_validations_rate_options[:in_store_rate_bases]
|
56
|
+
},
|
57
|
+
})
|
58
|
+
validates(:in_store_rate_basis, {
|
59
|
+
exclusion: {
|
60
|
+
in: %w(calculated_from_web_rate),
|
61
|
+
message: "cannot be the web rate because the web rate is not set or is based on the in-store rate",
|
62
|
+
},
|
63
|
+
if: -> (o) do
|
64
|
+
o.web_rate_basis == 'calculated_from_in_store_rate' ||
|
65
|
+
o.web_rate_basis.blank?
|
66
|
+
end,
|
67
|
+
})
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module G5IntegrationsValidations::SiteLinkInventoryValidations
|
2
|
+
|
3
|
+
VALID_RATE_BASES = %w(push_rate standard_rate)
|
4
|
+
VALID_IN_STORE_RATE_BASES = VALID_RATE_BASES + ['calculated_from_web_rate']
|
5
|
+
VALID_WEB_RATE_BASES = VALID_RATE_BASES + ['calculated_from_in_store_rate']
|
6
|
+
CTAS_FOR_IN_AND_ABOVE_THRESHOLD = %w(quote reserve)
|
7
|
+
CTAS_FOR_IN_AND_ABOVE_THRESHOLD_WITH_RENT_NOW = ['quote', 'reserve', 'reserve_fee', 'rent_now']
|
8
|
+
CTAS_FOR_BELOW_THRESHOLD = %w(call quote)
|
9
|
+
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
|
12
|
+
included do
|
13
|
+
include ActiveModel::Validations
|
14
|
+
|
15
|
+
include G5IntegrationsValidations::RateValidations.model(
|
16
|
+
in_store_rate_bases: VALID_IN_STORE_RATE_BASES,
|
17
|
+
web_rate_bases: VALID_WEB_RATE_BASES,
|
18
|
+
)
|
19
|
+
|
20
|
+
validates :unit_availability_threshold, presence: true
|
21
|
+
validates(
|
22
|
+
:cta_quote_url,
|
23
|
+
:cta_rent_now_url,
|
24
|
+
presence: true
|
25
|
+
)
|
26
|
+
|
27
|
+
validates_presence_of :cta_reserve_fee_url, :if => lambda { self.cta_reserve_url.blank? }
|
28
|
+
validates_presence_of :cta_reserve_url, :if => lambda { self.cta_reserve_fee_url.blank? }
|
29
|
+
|
30
|
+
validates(:unit_availability_cta_in_and_above_threshold, {
|
31
|
+
presence: true,
|
32
|
+
inclusion: {in: CTAS_FOR_IN_AND_ABOVE_THRESHOLD_WITH_RENT_NOW}
|
33
|
+
})
|
34
|
+
validates(:unit_availability_cta_below_threshold, {
|
35
|
+
inclusion: {in: CTAS_FOR_BELOW_THRESHOLD},
|
36
|
+
allow_blank: true
|
37
|
+
})
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module G5IntegrationsValidations::SiteLinkLeadValidations
|
2
|
+
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
include ActiveModel::Validations
|
7
|
+
VALID_CHARGE_MODES = %w(test charge do_not_charge)
|
8
|
+
|
9
|
+
validates :charge_mode, inclusion: {in: VALID_CHARGE_MODES}
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module G5IntegrationsValidations
|
2
|
+
module YardiVoyagerLeadValidations
|
3
|
+
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include ActiveModel::Validations
|
8
|
+
validates(
|
9
|
+
:api_version,
|
10
|
+
:database,
|
11
|
+
:reasons,
|
12
|
+
:interface_entity,
|
13
|
+
:platform,
|
14
|
+
:server_name,
|
15
|
+
:originating_lead_source,
|
16
|
+
presence: true
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CentershiftInventory
|
2
|
+
|
3
|
+
include G5IntegrationsValidations::CentershiftInventoryValidations
|
4
|
+
include Virtus.model
|
5
|
+
attribute :in_store_rate_basis, String
|
6
|
+
attribute :web_rate_basis, String
|
7
|
+
attribute :unit_availability_threshold, Integer
|
8
|
+
attribute :in_store_rate_percentage, Float
|
9
|
+
attribute :web_rate_discount, Float
|
10
|
+
attribute :cta_hard_reservation_with_fee_url, String
|
11
|
+
attribute :cta_hard_reservation_url, String
|
12
|
+
attribute :cta_soft_reservation_url, String
|
13
|
+
attribute :cta_quote_url, String
|
14
|
+
|
15
|
+
attribute :unit_availability_threshold, Integer
|
16
|
+
attribute :unit_availability_cta_in_and_above_threshold, String
|
17
|
+
attribute :unit_availability_cta_below_threshold, String
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class SiteLinkInventory
|
2
|
+
|
3
|
+
include G5IntegrationsValidations::SiteLinkInventoryValidations
|
4
|
+
include Virtus.model
|
5
|
+
attribute :in_store_rate_basis, String
|
6
|
+
attribute :web_rate_basis, String
|
7
|
+
attribute :unit_availability_threshold, Integer
|
8
|
+
attribute :in_store_rate_percentage, Float
|
9
|
+
attribute :web_rate_discount, Float
|
10
|
+
attribute :cta_reserve_url, String
|
11
|
+
attribute :cta_reserve_fee_url, String
|
12
|
+
attribute :cta_quote_url, String
|
13
|
+
attribute :cta_rent_now_url, String
|
14
|
+
attribute :unit_availability_cta_in_and_above_threshold, String
|
15
|
+
attribute :unit_availability_cta_below_threshold, String
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class YardiVoyagerLead
|
2
|
+
|
3
|
+
include G5IntegrationsValidations::YardiVoyagerLeadValidations
|
4
|
+
include Virtus.model
|
5
|
+
attribute :api_version, String
|
6
|
+
attribute :database, String
|
7
|
+
attribute :reasons, String
|
8
|
+
attribute :interface_entity, String
|
9
|
+
attribute :platform, String
|
10
|
+
attribute :server_name, String
|
11
|
+
attribute :originating_lead_source, String
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module G5IntegrationsValidations
|
4
|
+
describe CentershiftInventoryValidations do
|
5
|
+
|
6
|
+
subject { CentershiftInventory.new }
|
7
|
+
|
8
|
+
it { is_expected.to validate_presence_of(:in_store_rate_basis) }
|
9
|
+
it { is_expected.to validate_presence_of(:web_rate_basis) }
|
10
|
+
it do
|
11
|
+
is_expected.to validate_presence_of(:cta_hard_reservation_with_fee_url)
|
12
|
+
end
|
13
|
+
it { is_expected.to validate_presence_of(:cta_hard_reservation_url) }
|
14
|
+
it { is_expected.to validate_presence_of(:cta_soft_reservation_url) }
|
15
|
+
it { is_expected.to validate_presence_of(:cta_quote_url) }
|
16
|
+
|
17
|
+
it do
|
18
|
+
is_expected.
|
19
|
+
to validate_presence_of(:unit_availability_cta_in_and_above_threshold)
|
20
|
+
end
|
21
|
+
it do
|
22
|
+
is_expected.
|
23
|
+
to validate_inclusion_of(:unit_availability_cta_in_and_above_threshold).
|
24
|
+
in_array(%w(soft_reservation hard_reservation quote))
|
25
|
+
end
|
26
|
+
it do
|
27
|
+
is_expected.
|
28
|
+
to validate_inclusion_of(:unit_availability_cta_below_threshold).
|
29
|
+
in_array(%w(soft_reservation hard_reservation_with_fee hard_reservation quote))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe G5IntegrationsValidations::RateValidations do
|
4
|
+
|
5
|
+
let(:inventory_validations) do
|
6
|
+
G5IntegrationsValidations::SiteLinkInventoryValidations
|
7
|
+
end
|
8
|
+
|
9
|
+
subject do
|
10
|
+
SiteLinkInventory.new(
|
11
|
+
in_store_rate_basis: "standard_rate",
|
12
|
+
web_rate_basis: "push_rate",
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#in_store_rate_percentage" do
|
17
|
+
context "is calculated from web rate" do
|
18
|
+
subject do
|
19
|
+
SiteLinkInventory.new(in_store_rate_basis: 'calculated_from_web_rate')
|
20
|
+
end
|
21
|
+
it { is_expected.to validate_presence_of(:in_store_rate_percentage) }
|
22
|
+
it do
|
23
|
+
is_expected.to validate_numericality_of(:in_store_rate_percentage).
|
24
|
+
is_greater_than_or_equal_to(0)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "is not calculated from web rate" do
|
29
|
+
let(:in_store_rate_basis) do
|
30
|
+
inventory_validations::VALID_IN_STORE_RATE_BASES.reject do |basis|
|
31
|
+
basis == "calculated_from_web_rate"
|
32
|
+
end.sample
|
33
|
+
end
|
34
|
+
subject { SiteLinkInventory.new(in_store_rate_basis: in_store_rate_basis) }
|
35
|
+
it { is_expected.not_to validate_presence_of(:in_store_rate_percentage) }
|
36
|
+
it do
|
37
|
+
is_expected.not_to validate_numericality_of(:in_store_rate_percentage).
|
38
|
+
is_greater_than_or_equal_to(0)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#web_rate_discount" do
|
44
|
+
context "is calculated from in-store rate" do
|
45
|
+
subject do
|
46
|
+
SiteLinkInventory.new(web_rate_basis: 'calculated_from_in_store_rate')
|
47
|
+
end
|
48
|
+
it do
|
49
|
+
is_expected.to validate_numericality_of(:web_rate_discount).
|
50
|
+
is_greater_than_or_equal_to(0).is_less_than_or_equal_to(100)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "is not calculated from in-store rate" do
|
55
|
+
let(:web_rate_basis) do
|
56
|
+
inventory_validations::VALID_WEB_RATE_BASES.reject do |basis|
|
57
|
+
basis == "calculated_from_in_store_rate"
|
58
|
+
end.sample
|
59
|
+
end
|
60
|
+
subject { SiteLinkInventory.new(web_rate_basis: web_rate_basis) }
|
61
|
+
it { is_expected.not_to validate_presence_of(:web_rate_discount) }
|
62
|
+
it do
|
63
|
+
is_expected.not_to validate_inclusion_of(:web_rate_discount).in_range(0..100)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "web rate basis" do
|
69
|
+
context "in_store_rate_basis is not set" do
|
70
|
+
subject { SiteLinkInventory.new(in_store_rate_basis: nil) }
|
71
|
+
it { is_expected.to validate_presence_of(:web_rate_basis) }
|
72
|
+
end
|
73
|
+
|
74
|
+
context "in_store_rate_basis is set" do
|
75
|
+
let(:in_store_rate_basis) do
|
76
|
+
inventory_validations::VALID_IN_STORE_RATE_BASES.reject do |basis|
|
77
|
+
basis == "calculated_from_web_rate"
|
78
|
+
end.sample
|
79
|
+
end
|
80
|
+
subject { SiteLinkInventory.new(in_store_rate_basis: in_store_rate_basis) }
|
81
|
+
it { is_expected.to_not validate_presence_of(:web_rate_basis) }
|
82
|
+
end
|
83
|
+
|
84
|
+
it do
|
85
|
+
is_expected.to validate_inclusion_of(:web_rate_basis).
|
86
|
+
in_array(inventory_validations::VALID_WEB_RATE_BASES).
|
87
|
+
allow_nil(true)
|
88
|
+
end
|
89
|
+
|
90
|
+
context "in_store_rate_basis is calculated_from_web_rate" do
|
91
|
+
subject do
|
92
|
+
SiteLinkInventory.new(in_store_rate_basis: "calculated_from_web_rate")
|
93
|
+
end
|
94
|
+
|
95
|
+
it do
|
96
|
+
is_expected.to validate_exclusion_of(:web_rate_basis).
|
97
|
+
in_array(%w(calculated_from_in_store_rate)).
|
98
|
+
with_message("cannot be the in-store rate because the in-store rate is not set or is based on the web rate")
|
99
|
+
end
|
100
|
+
|
101
|
+
it { is_expected.to validate_presence_of(:web_rate_basis) }
|
102
|
+
end
|
103
|
+
|
104
|
+
context "in_store_rate_basis is nil" do
|
105
|
+
subject { SiteLinkInventory.new(in_store_rate_basis: nil) }
|
106
|
+
|
107
|
+
it do
|
108
|
+
is_expected.to validate_exclusion_of(:web_rate_basis).
|
109
|
+
in_array(%w(calculated_from_in_store_rate)).
|
110
|
+
with_message("cannot be the in-store rate because the in-store rate is not set or is based on the web rate")
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context "in_store_rate_basis is not calculated_from_web_rate" do
|
115
|
+
let(:in_store_rate_basis) do
|
116
|
+
inventory_validations::VALID_IN_STORE_RATE_BASES.reject do |basis|
|
117
|
+
basis == "calculated_from_web_rate"
|
118
|
+
end.sample
|
119
|
+
end
|
120
|
+
subject { SiteLinkInventory.new(in_store_rate_basis: in_store_rate_basis) }
|
121
|
+
|
122
|
+
it do
|
123
|
+
is_expected.to_not validate_exclusion_of(:web_rate_basis).
|
124
|
+
in_array(%w(calculated_from_in_store_rate))
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "in-store rate basis" do
|
130
|
+
it do
|
131
|
+
is_expected.to validate_inclusion_of(:in_store_rate_basis).
|
132
|
+
in_array(inventory_validations::VALID_IN_STORE_RATE_BASES)
|
133
|
+
end
|
134
|
+
|
135
|
+
it { is_expected.to validate_presence_of(:in_store_rate_basis) }
|
136
|
+
|
137
|
+
context "web_rate_basis is calculated_from_in_store_rate" do
|
138
|
+
subject do
|
139
|
+
SiteLinkInventory.new(web_rate_basis: "calculated_from_in_store_rate")
|
140
|
+
end
|
141
|
+
|
142
|
+
it do
|
143
|
+
is_expected.to validate_exclusion_of(:in_store_rate_basis).
|
144
|
+
in_array(%w(calculated_from_web_rate)).
|
145
|
+
with_message("cannot be the web rate because the web rate is not set or is based on the in-store rate")
|
146
|
+
end
|
147
|
+
|
148
|
+
it { is_expected.to validate_presence_of(:in_store_rate_basis) }
|
149
|
+
end
|
150
|
+
|
151
|
+
context "web_rate_basis is nil" do
|
152
|
+
subject { SiteLinkInventory.new(web_rate_basis: nil) }
|
153
|
+
|
154
|
+
it do
|
155
|
+
is_expected.to validate_exclusion_of(:in_store_rate_basis).
|
156
|
+
in_array(%w(calculated_from_web_rate)).
|
157
|
+
with_message("cannot be the web rate because the web rate is not set or is based on the in-store rate")
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context "web_rate_basis is blank" do
|
162
|
+
subject do
|
163
|
+
SiteLinkInventory.new(
|
164
|
+
web_rate_basis: "",
|
165
|
+
in_store_rate_basis: "standard_rate"
|
166
|
+
)
|
167
|
+
end
|
168
|
+
|
169
|
+
it do
|
170
|
+
is_expected.to validate_exclusion_of(:in_store_rate_basis).
|
171
|
+
in_array(%w(calculated_from_web_rate)).
|
172
|
+
with_message("cannot be the web rate because the web rate is not set or is based on the in-store rate")
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context "web_rate_basis is not calculated_from_in_store_rate" do
|
177
|
+
let(:web_rate_basis) do
|
178
|
+
inventory_validations::VALID_WEB_RATE_BASES.reject do |basis|
|
179
|
+
basis == "calculated_from_in_store_rate"
|
180
|
+
end.sample
|
181
|
+
end
|
182
|
+
subject { SiteLinkInventory.new(web_rate_basis: web_rate_basis) }
|
183
|
+
|
184
|
+
it do
|
185
|
+
is_expected.to_not validate_exclusion_of(:in_store_rate_basis).
|
186
|
+
in_array(%w(calculated_from_web_rate))
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe G5IntegrationsValidations::SiteLinkInventoryValidations do
|
4
|
+
|
5
|
+
subject do
|
6
|
+
SiteLinkInventory.new(
|
7
|
+
in_store_rate_basis: "standard_rate",
|
8
|
+
web_rate_basis: "push_rate",
|
9
|
+
)
|
10
|
+
end
|
11
|
+
it { is_expected.to validate_presence_of(:unit_availability_threshold) }
|
12
|
+
|
13
|
+
it { is_expected.to validate_presence_of(:cta_quote_url) }
|
14
|
+
it { is_expected.to validate_presence_of(:cta_rent_now_url) }
|
15
|
+
it { is_expected.to validate_presence_of(:cta_reserve_url) }
|
16
|
+
it { is_expected.to validate_presence_of(:cta_reserve_fee_url) }
|
17
|
+
|
18
|
+
it do
|
19
|
+
is_expected.
|
20
|
+
to validate_presence_of(:unit_availability_cta_in_and_above_threshold)
|
21
|
+
end
|
22
|
+
it do
|
23
|
+
is_expected.
|
24
|
+
to validate_inclusion_of(:unit_availability_cta_in_and_above_threshold).
|
25
|
+
in_array(['quote', 'reserve', 'rent_now'])
|
26
|
+
end
|
27
|
+
it do
|
28
|
+
is_expected.
|
29
|
+
to validate_inclusion_of(:unit_availability_cta_below_threshold).
|
30
|
+
in_array(%w(call quote))
|
31
|
+
end
|
32
|
+
|
33
|
+
context "conditional validations" do
|
34
|
+
context "cta_reserve_fee_url is set" do
|
35
|
+
before {allow(subject).to receive(:cta_reserve_fee_url).and_return("something.com")}
|
36
|
+
it "allows a cta_reserve_url to be nil if cta_reserve_fee_url is not" do
|
37
|
+
is_expected.to_not validate_presence_of(:cta_reserve_url)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "cta_reserve_url is set" do
|
42
|
+
before {allow(subject).to receive(:cta_reserve_url).and_return("something.com")}
|
43
|
+
it "allows a cta_reserve_fee_url to be nil if cta_reserve_url is not" do
|
44
|
+
is_expected.to_not validate_presence_of(:cta_reserve_fee_url)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module G5IntegrationsValidations
|
4
|
+
describe YardiVoyagerLeadValidations do
|
5
|
+
|
6
|
+
subject { YardiVoyagerLead.new }
|
7
|
+
it { is_expected.to validate_presence_of(:api_version) }
|
8
|
+
it { is_expected.to validate_presence_of(:database) }
|
9
|
+
it { is_expected.to validate_presence_of(:reasons) }
|
10
|
+
it { is_expected.to validate_presence_of(:interface_entity) }
|
11
|
+
it { is_expected.to validate_presence_of(:platform) }
|
12
|
+
it { is_expected.to validate_presence_of(:server_name) }
|
13
|
+
it { is_expected.to validate_presence_of(:originating_lead_source) }
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: g5_integrations_validations
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ramon Tayag
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activemodel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
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: rspec
|
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: virtus
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: shoulda-matchers
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.7'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.7'
|
97
|
+
description: Common validations for G5 Integrations
|
98
|
+
email:
|
99
|
+
- ramon.tayag@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- g5_integrations_validations.gemspec
|
110
|
+
- lib/g5_integrations_validations.rb
|
111
|
+
- lib/g5_integrations_validations/centershift_inventory_validations.rb
|
112
|
+
- lib/g5_integrations_validations/rate_validations.rb
|
113
|
+
- lib/g5_integrations_validations/site_link_inventory_validations.rb
|
114
|
+
- lib/g5_integrations_validations/site_link_lead_rent_now_validations.rb
|
115
|
+
- lib/g5_integrations_validations/site_link_lead_validations.rb
|
116
|
+
- lib/g5_integrations_validations/version.rb
|
117
|
+
- lib/g5_integrations_validations/yardi_voyager_lead_validations.rb
|
118
|
+
- spec/fixtures/centershift_inventory.rb
|
119
|
+
- spec/fixtures/site_link_inventory.rb
|
120
|
+
- spec/fixtures/site_link_lead.rb
|
121
|
+
- spec/fixtures/site_link_lead_rent_now.rb
|
122
|
+
- spec/fixtures/yardi_voyager_lead.rb
|
123
|
+
- spec/g5_integrations_validations/centershift_inventory_validations_spec.rb
|
124
|
+
- spec/g5_integrations_validations/rate_validations_spec.rb
|
125
|
+
- spec/g5_integrations_validations/site_link_inventory_validations_spec.rb
|
126
|
+
- spec/g5_integrations_validations/site_link_lead_rent_now_validations_spec.rb
|
127
|
+
- spec/g5_integrations_validations/site_link_lead_validations_spec.rb
|
128
|
+
- spec/g5_integrations_validations/yardi_voyager_lead_validations_spec.rb
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
homepage: ''
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.4.3
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: Common validations for G5 Integrations
|
154
|
+
test_files:
|
155
|
+
- spec/fixtures/centershift_inventory.rb
|
156
|
+
- spec/fixtures/site_link_inventory.rb
|
157
|
+
- spec/fixtures/site_link_lead.rb
|
158
|
+
- spec/fixtures/site_link_lead_rent_now.rb
|
159
|
+
- spec/fixtures/yardi_voyager_lead.rb
|
160
|
+
- spec/g5_integrations_validations/centershift_inventory_validations_spec.rb
|
161
|
+
- spec/g5_integrations_validations/rate_validations_spec.rb
|
162
|
+
- spec/g5_integrations_validations/site_link_inventory_validations_spec.rb
|
163
|
+
- spec/g5_integrations_validations/site_link_lead_rent_now_validations_spec.rb
|
164
|
+
- spec/g5_integrations_validations/site_link_lead_validations_spec.rb
|
165
|
+
- spec/g5_integrations_validations/yardi_voyager_lead_validations_spec.rb
|
166
|
+
- spec/spec_helper.rb
|