Sha256: d8efbf738720cd2f9a51b39d93380376624c3f014b777cf119880933192d973d
Contents?: true
Size: 1.56 KB
Versions: 3
Compression:
Stored size: 1.56 KB
Contents
# encoding: utf-8 describe ServiceObjects::Helpers::Validations do let(:invalid) { ServiceObjects::Invalid } let(:message_class) { ServiceObjects::Message } let(:messages_module) { ServiceObjects::Helpers::Messages } let(:test_class) { Class.new } let(:validations) { ActiveModel::Validations } before { ServiceObjects::Test = test_class } before { test_class.include described_class } after { ServiceObjects.send :remove_const, :Test } it "includes ActiveModel::Validations" do expect(test_class).to include validations end it "includes ServiceObjects::Helpers::Messages" do expect(test_class).to include messages_module end describe "#validate!" do subject { test_class.new } context "when the service is valid" do it "passes" do expect { subject.validate! }.not_to raise_error end end context "when the service is invalid" do before { subject.errors.add :base, :invalid } before { allow(subject).to receive(:valid?) { false } } it "fails" do expect { subject.validate! }.to raise_error invalid end it "populates #messages from errors" do begin subject.validate! rescue => err message = subject.messages.first end expect(message).to be_kind_of message_class expect(message.type).to eq "error" expect(err.messages).to contain_exactly message end end end # #validate! end # ServiceObjects::Helpers::Validations
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
service_objects-0.1.0 | spec/tests/helpers/validations_spec.rb |
service_objects-0.0.2 | spec/tests/helpers/validations_spec.rb |
service_objects-0.0.1 | spec/tests/helpers/validations_spec.rb |