Sha256: b4a2c8dc0e75e8eafb8b7e7f5f6deea72783f7d3f5315be5f7ac4a492595a7ac

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

require 'spec_helper'

describe AmoCRM::Resources::Base do
  it 'should be loaded' do
    expect(described_class).to be_a Class
  end

  describe 'правильно определяет название модели' do
    let!(:entity_class) { AmoCRM::Entities::Computer = Class.new }
    subject { AmoCRM::Resources::Computers = Class.new described_class }

    it do
      expect(subject.entity_class).to eq entity_class
    end
  end

  describe 'испрвляет на лету xml с плохими символами' do
    let(:xml)    { File.read './spec/fixtures/bad_chars.xml' }
    let(:client) { AmoCRM::Client.new }
    let(:res) { described_class.new client: client }

    before do
      allow(described_class).to receive(:entity_class).and_return AmoCRM::Entities::CustomEntity
    end

    subject { res.send :parse_page, xml }

    it do
      expect{subject}.to_not raise_error 
    end

    context 'ошибка есть если парсинг напрямую' do
      before do
        expect_any_instance_of(described_class).to receive(:parse_content).and_return xml
      end
      it do
        expect{subject}.to raise_error Nokogiri::XML::SyntaxError
      end
    end

  end

  describe 'page' do
    let(:resource) { AmoCRM::Resources::Features.new client: client }

    before do
      stub_rest :Feature
    end

    subject { resource.page }

    it do
      expect(subject).to be_a AmoCRM::Entities::Page
      expect(subject.total).to eq feature_list_items_count
      expect(subject.count).to eq AmoCRM::Entities::Collection::DEFAULT_COUNT
      expect(subject.start).to eq 0
      expect(subject.items.count).to eq feature_list_items_count
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
amo_crm-0.2.2 spec/lib/amocrm/resources/base_spec.rb