From a489a7143c76f3ad7ab3d072a0c8ee440f61bb92 Mon Sep 17 00:00:00 2001 From: Pablo Herrero Date: Fri, 9 Aug 2024 03:45:40 -0300 Subject: [PATCH] Add test for Plugins::DryValidation.inherited --- spec/plugins/dry_validation_spec.rb | 18 ++++++++++++++++++ spec/plugins/sequel_models_spec.rb | 17 ++++++++--------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/spec/plugins/dry_validation_spec.rb b/spec/plugins/dry_validation_spec.rb index ea857ea..be91aba 100644 --- a/spec/plugins/dry_validation_spec.rb +++ b/spec/plugins/dry_validation_spec.rb @@ -174,6 +174,24 @@ class OperationWithAutoWire < Operation .to include(:gender) end end + + context "when called with no block nor contract" do + subject(:opr_class) { Class.new(Operation) { plugin :dry_validation } } + + it 'raises an error' do + expect { opr_class.contract }.to raise_error(ArgumentError, 'Either a contract class or a block must be provided') + end + end + + context 'when the operation is inherited' do + let(:opr_class) { OperationWithAutoWire } + subject(:opr_subclass) { Class.new(OperationWithAutoWire) } + + it "sets 'contract_class' and 'auto_wire' from the superclass", :aggregate_failures do + expect(opr_subclass.auto_wire).to eq(opr_class.auto_wire) + expect(opr_subclass.contract_class).to eq(opr_class.contract_class) + end + end end describe "#call" do diff --git a/spec/plugins/sequel_models_spec.rb b/spec/plugins/sequel_models_spec.rb index 1be2a36..29d4e25 100644 --- a/spec/plugins/sequel_models_spec.rb +++ b/spec/plugins/sequel_models_spec.rb @@ -58,8 +58,6 @@ def chain_operation(state) end end - class SubOperation < MyOperation; end - describe 'DSL' do let(:result) { operation.call(params) } let(:params) { { email: 'asd@fgh.net' } } @@ -274,13 +272,14 @@ class InvalidOperation < MyOperation end context 'when the operation is inherited' do - it "sets 'result_key', 'search_field', 'model_class' and 'model_not_found' from the superclass" do - aggregate_failures do - expect(SubOperation.result_key).to eq(MyOperation.result_key) - expect(SubOperation.search_field).to eq(MyOperation.search_field) - expect(SubOperation.model_class).to eq(MyOperation.model_class) - expect(SubOperation.model_not_found).to eq(MyOperation.model_not_found) - end + let(:opr_class) { MyOperation } + subject(:opr_subclass) { Class.new(opr_class) } + + it "sets 'result_key', 'search_field', 'model_class' and 'model_not_found' from the superclass", :aggregate_failures do + expect(opr_subclass.result_key).to eq(opr_class.result_key) + expect(opr_subclass.search_field).to eq(opr_class.search_field) + expect(opr_subclass.model_class).to eq(opr_class.model_class) + expect(opr_subclass.model_not_found).to eq(opr_class.model_not_found) end end end