Sha256: 1dae707212ec02f150d4fa68fd3bbafb97f2cb26326d960b5266e7791d68ac75

Contents?: true

Size: 1.7 KB

Versions: 9

Compression:

Stored size: 1.7 KB

Contents

require 'spec_helper'
require 'rakuten_web_service'

describe RakutenWebService::Books::Game do
  let(:endpoint) { 'https://app.rakuten.co.jp/services/api/BooksGame/Search/20130522' }
  let(:affiliate_id) { 'dummy_affiliate_id' }
  let(:application_id) { 'dummy_application_id' }
  let(:expected_query) do
    {
      :affiliateId => affiliate_id,
      :applicationId => application_id,
      :keyword => 'Ruby'
    }
  end

  before do
    RakutenWebService.configuration do |c|
      c.affiliate_id = affiliate_id
      c.application_id = application_id
    end
  end

  describe '.search' do
    before do
      response = JSON.parse(fixture('books/game_search_with_keyword_Ruby.json'))
      @expected_request = stub_request(:get, endpoint).
        with(:query => expected_query).to_return(:body => response.to_json)
    end

    specify 'call endpoint when accessing results' do
      games = RakutenWebService::Books::Game.search(:keyword => 'Ruby')
      expect(@expected_request).to_not have_been_made

      game = games.first
      expect(@expected_request).to have_been_made.once
      expect(game).to be_a(RWS::Books::Game)
    end
  end

  context 'When using Books::Total.search' do
    let(:game) do
      RWS::Books::Game.new(:jan => '12345')
    end

    before do
      @expected_request = stub_request(:get, endpoint).
        with(:query => { :affiliateId => affiliate_id, :applicationId => application_id, :jan => '12345' }).
        to_return(:body => { :Items => [ { :Item => { :title => 'foo' } } ] }.to_json)
    end

    specify 'retrieves automatically if accessing the value of lack attribute' do
      expect(game.title).to eq('foo')
      expect(@expected_request).to have_been_made.once
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rakuten_web_service-0.6.3 spec/rakuten_web_service/books/game_spec.rb
rakuten_web_service-0.6.2 spec/rakuten_web_service/books/game_spec.rb
rakuten_web_service-0.6.1 spec/rakuten_web_service/books/game_spec.rb
rakuten_web_service-0.6.0 spec/rakuten_web_service/books/game_spec.rb
rakuten_web_service-0.5.0 spec/rakuten_web_service/books/game_spec.rb
rakuten_web_service-0.4.2 spec/rakuten_web_service/books/game_spec.rb
rakuten_web_service-0.4.1 spec/rakuten_web_service/books/game_spec.rb
rakuten_web_service-0.3.1 spec/rakuten_web_service/books/game_spec.rb
rakuten_web_service-0.3.0 spec/rakuten_web_service/books/game_spec.rb