Sha256: 2e77b61304fda068bf00b9b33cd0da1525682399f43c98be378b2f22e45e21e4

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

require './lib/exchequer'

describe Exchequer::ErrorMapper do
  def errors_hash
    Hash.new { |hash, key| hash[key] = [] }
  end

  let(:map_errors)  { Exchequer::ErrorMapper.map(source, :to => destination) }
  let(:source)      { double(:errors => errors_hash) }
  let(:destination) { double(:errors => errors_hash) }

  describe '#map_errors' do
    it "transfers credit card expiration year attributes" do
      source.errors[:base] << 'Credit card expiration year: Not valid'

      map_errors

      destination.errors.should == {
        :expiration_year => ['Not valid']
      }
    end

    it "transfers credit card expiration month attributes" do
      source.errors[:base] << 'Credit card expiration month: Not valid'

      map_errors

      destination.errors.should == {
        :expiration_month => ['Not valid']
      }
    end

    it "transfers credit card number attributes" do
      source.errors[:base] << 'Credit card number: Not valid'

      map_errors

      destination.errors.should == {
        :full_number => ['Not valid']
      }
    end

    it "transfers first name attributes" do
      source.errors[:base] << 'First name: Not valid'

      map_errors

      destination.errors.should == {
        :first_name => ['Not valid']
      }
    end

    it "transfers last name attributes" do
      source.errors[:base] << 'Last name: Not valid'

      map_errors

      destination.errors.should == {
        :last_name => ['Not valid']
      }
    end

    it "transfers other errors to base" do
      source.errors[:base] << 'Gateway error'

      map_errors

      destination.errors.should == {
        :base => ['Gateway error']
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
exchequer-0.1.0 spec/exchequer/error_mapper_spec.rb