Sha256: 36addaacc75208c89055d9e313641b9f628621d0af932a5bd534e300b55cc647

Contents?: true

Size: 1.49 KB

Versions: 7

Compression:

Stored size: 1.49 KB

Contents

# -*- coding: utf-8 -*-
require 'payex'
require 'spec_helper'

describe PayEx::API do
  before {
    PayEx.encryption_key = 'foo'
  }

  it 'should know how to stringify keys' do
    PayEx::API.stringify_keys(a: 1, b: 2).
      should == { 'a' => 1, 'b' => 2 }
  end

  it 'should know how to sign params' do
    param_hash, specs, param_array = {}, {}, []

    for name in 'a'..'z'
      if rand < 0.5
        param_hash[name] = rand
        param_array << param_hash[name]
        specs[name] = { signed: true }
      else
        param_hash[name] = rand
      end
    end

    actual = PayEx::API.sign_params(param_hash, specs)

    to_sign = param_array.join + PayEx.encryption_key
    expected = Digest::MD5.hexdigest(to_sign)

    actual.should == expected
  end

  it 'should know how to add defaults' do
    PayEx::API.parse_param(nil, { default: 2 }).should == 2
  end

  it 'should know how to call default procs' do
    PayEx::API.parse_param(nil, { default: proc { 2 } }).should == 2
  end

  it 'should reject wrong type of value' do
    proc {
      PayEx::API.parse_param('foobar', { format: Integer })
    }.should raise_error PayEx::API::ParamError
  end

  it 'should reject strings based on regular expressions' do
    proc {
      PayEx::API.parse_param('foobar', { format: /^.{,3}$/ })
    }.should raise_error PayEx::API::ParamError
  end

  it 'should stringify keys when parsing params' do
    PayEx::API.parse_params({ a: 1 }, { 'b' => { default: 2 } }).
      should == { 'a' => 1, 'b' => 2 }
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
payex-0.4 spec/api_spec.rb
payex-0.3 spec/api_spec.rb
payex-0.1.2 spec/api_unit_spec.rb
payex-0.1.1 spec/api_unit_spec.rb
payex-0.1.0 spec/api_unit_spec.rb
payex-0.1.0.rc spec/api_unit_spec.rb
payex-0.0.1 spec/api_unit_spec.rb