Sha256: 03a2b83411fcf541104ab47fad66ba9df5e478418369334fd263f19abae246fd

Contents?: true

Size: 1.9 KB

Versions: 19

Compression:

Stored size: 1.9 KB

Contents

require 'spec_helper'

describe GnipApi::Apis::PowerTrack::Rules do
  before do
    @api = GnipApi::Apis::PowerTrack::Rules.new(:source => 'source', :label => 'label')
    @rules = [GnipApi::Apis::PowerTrack::Rule.new(:value => 'r1', :tag => 't1'),
              GnipApi::Apis::PowerTrack::Rule.new(:value => 'r2')]
    @json = {:rules => [{:value => 'r1', :tag => 't1'}, {:value => 'r2'}]}.to_json
  end

  describe '#parse_rules' do
    it 'parses json rules to GnipApi::Apis::PowerTrack::Rule objects' do
      parsed = @api.parse_rules(@json)
      expect(parsed.first.class).to eq(GnipApi::Apis::PowerTrack::Rule)
    end
  end

  describe '#construct_rules' do
    it 'constructs valid rules' do
      expect(@api.construct_rules(@rules)).to eq(@json)
    end
  end

  describe '#delete' do
    it 'raises error if no rules passed' do
      expect(Proc.new{@api.delete([])}).to raise_error(GnipApi::Errors::PowerTrack::MissingRules)
    end
  end

  describe '#create' do
    it 'raises error if no rules passed' do
      expect(Proc.new{@api.create([])}).to raise_error(GnipApi::Errors::PowerTrack::MissingRules)
    end
  end

  describe '#list' do
    before do
      expect(@api.adapter).to receive(:get).and_return(@json)
    end

    it 'returns an array' do
      result = @api.list
      expect(result.kind_of?(Array)).to eq(true)
    end
    
    it 'gets 2 rules' do
      result = @api.list
      expect(result.size).to eq(2)
    end

    it 'returns GnipApi::Apis::PowerTrack::Rule objects' do
      result = @api.list
      expect(result.map(&:class).uniq).to eq([GnipApi::Apis::PowerTrack::Rule])
    end

    describe 'rules fetched' do
      before do
        @rules = @api.list
      end
      
      it 'contains expected values' do
        expect(@rules.map(&:value)).to eq(['r1', 'r2'])
      end

      it 'contains expected tags' do
        expect(@rules.map(&:tag)).to eq(['t1', nil])
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
gnip_api-1.1.3 spec/gnip_api/apis/power_track/rules_spec.rb
gnip_api-1.1.2 spec/gnip_api/apis/power_track/rules_spec.rb
gnip_api-1.1.1 spec/gnip_api/apis/power_track/rules_spec.rb
gnip_api-1.1.0 spec/gnip_api/apis/power_track/rules_spec.rb
gnip_api-1.0.6 spec/gnip_api/apis/power_track/rules_spec.rb
gnip_api-1.0.5 spec/gnip_api/apis/power_track/rules_spec.rb
gnip_api-1.0.4 spec/gnip_api/apis/power_track/rules_spec.rb
gnip_api-1.0.3 spec/gnip_api/apis/power_track/rules_spec.rb
gnip_api-1.0.2 spec/gnip_api/apis/power_track/rules_spec.rb
gnip_api-1.0.1 spec/gnip_api/apis/power_track/rules_spec.rb
gnip_api-1.0.0 spec/gnip_api/apis/power_track/rules_spec.rb
gnip_api-0.0.9 spec/gnip_api/apis/power_track/rules_spec.rb
gnip_api-0.0.8 spec/gnip_api/apis/power_track/rules_spec.rb
gnip_api-0.0.7 spec/gnip_api/apis/power_track/rules_spec.rb
gnip_api-0.0.6 spec/gnip_api/apis/power_track/rules_spec.rb
gnip_api-0.0.5 spec/gnip_api/apis/power_track/rules_spec.rb
gnip_api-0.0.4 spec/gnip_api/apis/power_track/rules_spec.rb
gnip_api-0.0.3 spec/gnip_api/apis/power_track/rules_spec.rb
gnip_api-0.0.2 spec/gnip_api/apis/power_track/rules_spec.rb