Sha256: 8478770dff446baf15e9aaf40ea3a5f4bff248972274bd4f0fc8882502bd4c9b

Contents?: true

Size: 1.46 KB

Versions: 9

Compression:

Stored size: 1.46 KB

Contents

# encoding: utf-8

describe Cieloz::Requisicao do
  let(:_)       { subject.class }
  let(:id)      { "1" }
  let(:versao)  { "1.2.0" }
  let(:opts)    { { root: "requisicao", id: id, versao: versao } }

  let(:dir)     { File.dirname __FILE__ }

  before do
    subject.id = id
    subject.versao = versao
  end

  describe "value attributes" do
    before do
      subject.class_eval do
        attr_accessor :foo

        def attributes
          { foo: @foo }
        end
      end
    end

    let(:foo) { "Informações Extras" }

    it "serializes" do
      subject.foo = foo

      xml = expected_xml(opts) { "<foo>#{foo}</foo>" }
      assert_equal xml, subject.to_xml
    end

    it "ignores nils" do
      subject.foo = nil
      assert_equal expected_xml(opts), subject.to_xml
    end
  end

  describe "complex attributes" do
    let(:ec)  { Cieloz::Configuracao.credenciais }
    let(:xml) { expected_xml(opts) { xml_for :ec, dir, binding } }

    it "serializes" do
      subject.stub :valid?, false do # avoid http request
        subject.submit # @dados_ec is set on submission
      end
      assert_equal xml, subject.to_xml
    end
  end

  describe "request posting" do
    it "sends to test web service" do
      Cieloz::Configuracao.reset!
      VCR.use_cassette 'requisicao_test_request_posting' do
        res = subject.submit

        assert_equal({}, subject.errors.messages)
        refute_nil res.codigo
        refute_nil res.mensagem
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
cieloz-0.0.21 test/unit/requisicao_test.rb
cieloz-0.0.20 test/unit/requisicao_test.rb
cieloz-0.0.19 test/unit/requisicao_test.rb
cieloz-0.0.18 test/unit/requisicao_test.rb
cieloz-0.0.17 test/unit/requisicao_test.rb
cieloz-0.0.16 test/unit/requisicao_test.rb
cieloz-0.0.15 test/unit/requisicao_test.rb
cieloz-0.0.14 test/unit/requisicao_test.rb
cieloz-0.0.13 test/unit/requisicao_test.rb