Browse Source
* intermediate_rent_product_name validation * add wrapper method * include in case log * review changesroutes-to-csv
Dushan
3 years ago
committed by
GitHub
5 changed files with 55 additions and 0 deletions
@ -0,0 +1,13 @@ |
|||||||
|
module Validations::SetupValidations |
||||||
|
def validate_intermediate_rent_product_name(record) |
||||||
|
if intermediate_product_rent_type?(record) && record.intermediate_rent_product_name.blank? |
||||||
|
record.errors.add :intermediate_rent_product_name, I18n.t("validations.setup.intermediate_rent_product_name.blank") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
private |
||||||
|
|
||||||
|
def intermediate_product_rent_type?(record) |
||||||
|
record.rent_type == 5 |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,33 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe Validations::SetupValidations do |
||||||
|
subject(:setup_validator) { setup_validator_class.new } |
||||||
|
|
||||||
|
let(:setup_validator_class) { Class.new { include Validations::SetupValidations } } |
||||||
|
let(:record) { FactoryBot.create(:case_log) } |
||||||
|
|
||||||
|
describe "#validate_intermediate_rent_product_name" do |
||||||
|
it "adds an error when the intermediate rent product name is not provided but the rent type was given as other intermediate rent product" do |
||||||
|
record.rent_type = 5 |
||||||
|
record.intermediate_rent_product_name = nil |
||||||
|
setup_validator.validate_intermediate_rent_product_name(record) |
||||||
|
expect(record.errors["intermediate_rent_product_name"]) |
||||||
|
.to include(match I18n.t("validations.setup.intermediate_rent_product_name.blank")) |
||||||
|
end |
||||||
|
|
||||||
|
it "adds an error when the intermediate rent product name is blank but the rent type was given as other intermediate rent product" do |
||||||
|
record.rent_type = 5 |
||||||
|
record.intermediate_rent_product_name = "" |
||||||
|
setup_validator.validate_intermediate_rent_product_name(record) |
||||||
|
expect(record.errors["intermediate_rent_product_name"]) |
||||||
|
.to include(match I18n.t("validations.setup.intermediate_rent_product_name.blank")) |
||||||
|
end |
||||||
|
|
||||||
|
it "Does not add an error when the intermediate rent product name is provided and the rent type was given as other intermediate rent product" do |
||||||
|
record.rent_type = 5 |
||||||
|
record.intermediate_rent_product_name = "Example" |
||||||
|
setup_validator.validate_intermediate_rent_product_name(record) |
||||||
|
expect(record.errors["intermediate_rent_product_name"]).to be_empty |
||||||
|
end |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue