Sha256: 6365396982676a689d905f1545383f2962d0d6dcd71a90db5a8f857bb267e362

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

require 'spec_helper'

describe ActiveRemote::Serialization do
  describe ".serialize_records" do
    let(:records) { [ { :foo => 'bar' } ] }

    subject { Tag.new }

    it "serializes records into active remote objects" do
      Tag.serialize_records(records).each do |record|
        expect(record).to be_a Tag
      end
    end
  end

  describe "#add_errors" do
    let(:error) { Generic::Error.new(:field => 'name', :message => 'Boom!') }
    let(:response) {
      tag = Generic::Remote::Tag.new
      tag.errors << error
      tag
    }

    subject { Tag.new }

    context "when the response has errors" do
      it "adds the errors to the active remote object" do
        subject.add_errors(response.errors)
        expect(subject.errors[:name]).to match_array(['Boom!'])
      end
    end
  end

  describe "#add_errors_from_response" do
    subject { Tag.new }

    context "when the response responds to :errors" do
      let(:error) { Generic::Error.new(:field => 'name', :message => 'Boom!') }
      let(:response) { Generic::Remote::Tag.new(:errors => [ error ]) }

      it "adds errors to the active remote object" do
        subject.better_receive(:add_errors).with(response.errors)
        subject.add_errors_from_response(response)
      end
    end

    context "when the response does not respond to :errors" do
      let(:response_without_errors) { double(:response_without_errors) }

      it "does not add errors" do
        subject.better_not_receive(:add_errors)
        subject.add_errors_from_response(response_without_errors)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_remote-2.2.0 spec/lib/active_remote/serialization_spec.rb