Sha256: 931b175a9ce9087950fed2f3cab7e9c7760d9918e976729470e5cc0029ad3f6d

Contents?: true

Size: 1.53 KB

Versions: 7

Compression:

Stored size: 1.53 KB

Contents

require 'spec_helper'
require 'rakuten_web_service/ichiba/ranking'

describe RakutenWebService::Ichiba::RankingItem do
  let(:endpoint) { 'https://app.rakuten.co.jp/services/api/IchibaItem/Ranking/20120927' }
  let(:affiliate_id) { 'affiliate_id' }
  let(:application_id) { 'application_id' }
  let(:expected_query) do
    {
      :affiliateId => affiliate_id, :applicationId => application_id
    }
  end

  before do 
    response = JSON.parse(fixture('ichiba/ranking_search.json'))
    @expected_request = stub_request(:get, endpoint).
      with(:query => expected_query).to_return(:body => response.to_json)

    RakutenWebService.configure do |c|
      c.affiliate_id = affiliate_id
      c.application_id = application_id
    end
  end

  describe '.search' do
    let(:expected_json) do
      response = JSON.parse(fixture('ichiba/ranking_search.json'))
      response['Items'][0]['Item']
    end

    before do 
      @ranking_item = RakutenWebService::Ichiba::RankingItem.search({}).first
    end

    subject { @ranking_item }

    specify 'should call the endpoint once' do
      expect(@expected_request).to have_been_made.once
    end
    specify 'should be access by key' do
      expect(subject['itemName']).to eq(expected_json['itemName'])
      expect(subject['item_name']).to eq(expected_json['itemName'])
    end

    describe '#rank' do
      subject { super().rank }
      it { is_expected.to eq(1) }
    end

    describe '#name' do
      subject { super().name }
      it { is_expected.to eq(expected_json['itemName']) }
    end
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rakuten_web_service-1.4.1 spec/rakuten_web_service/ichiba/ranking_spec.rb
rakuten_web_service-1.4.0 spec/rakuten_web_service/ichiba/ranking_spec.rb
rakuten_web_service-1.3.0 spec/rakuten_web_service/ichiba/ranking_spec.rb
rakuten_web_service-1.2.0 spec/rakuten_web_service/ichiba/ranking_spec.rb
rakuten_web_service-1.1.1 spec/rakuten_web_service/ichiba/ranking_spec.rb
rakuten_web_service-1.1.0 spec/rakuten_web_service/ichiba/ranking_spec.rb
rakuten_web_service-1.0.0 spec/rakuten_web_service/ichiba/ranking_spec.rb