Sha256: 92e9f620027bf161e2aef3517240364c5b275597f42a7f010b0dc4f7975d6ad9

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require "spec_helper"

require "sequel_mapper/upserted_record"

RSpec.describe SequelMapper::UpsertedRecord do
  subject(:record) {
    SequelMapper::UpsertedRecord.new(namespace, identity, raw_data)
  }

  let(:namespace) { double(:namespace) }

  let(:identity) {
    { id: id }
  }

  let(:raw_data) {
    {
      name: name,
    }
  }

  let(:id) { double(:id) }
  let(:name) { double(:name) }

  describe "#if_upsert" do
    it "invokes the callback" do
      expect { |callback|
        record.if_upsert(&callback)
      }.to yield_with_args(record)
    end
  end

  describe "#==" do
    context "with another record that upserts" do
      let(:comparitor) {
        record.merge({})
      }

      it "is equal" do
        expect(record.==(comparitor)).to be(true)
      end
    end

    context "with another record that does not upsert" do
      let(:comparitor) {
        Class.new(SequelMapper::AbstractRecord) do
          protected
          def operation
            :something_else
          end
        end
      }

      it "is not equal" do
        expect(record.==(comparitor)).to be(false)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sequel_mapper-0.0.3 spec/sequel_mapper/upserted_record_spec.rb