Sha256: 6be87981d1346f49ea7cb63be3b692282576cffe89ea78a4fe9493ebed240531

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

require 'spec_helper'

describe RescueFromDuplicate::Rescuer do
  subject { RescueFromDuplicate::Rescuer.new(:name, scope: :shop_id) }

  context "#matches?" do
    it 'is true when the columns are the same' do
      expect(subject.matches?(["shop_id", "name"])).to be true
    end

    it 'is false when the columns are not the same' do
      expect(subject.matches?(["shop_id", "toto"])).to be false
    end
  end
end

shared_examples 'a model with rescued unique error without validator' do
  describe 'create!' do
    context 'when catching a race condition' do
      before {
        described_class.create!(relation_id: 1, handle: 'toto')
      }

      it 'adds an error on the model' do
        model = described_class.create(relation_id: 1, handle: 'toto')
        expect(model.errors[:handle]).to eq(["handle must be unique for this relation"])
      end
    end
  end
end

describe Sqlite3Model do
  it_behaves_like 'a model with rescued unique error without validator'
end

if defined?(MysqlModel)
  describe MysqlModel do
    it_behaves_like 'a model with rescued unique error without validator'
  end
end

if defined?(PostgresqlModel)
  describe PostgresqlModel do
    it_behaves_like 'a model with rescued unique error without validator'
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activerecord-rescue_from_duplicate-0.0.5 spec/rescuer_spec.rb
activerecord-rescue_from_duplicate-0.0.4 spec/rescuer_spec.rb