Sha256: cdad3c776b71eb3e2d10a7257da57084c9fab8acb04a5c8ab87a9fd457758932

Contents?: true

Size: 1.75 KB

Versions: 8

Compression:

Stored size: 1.75 KB

Contents

require 'spec_helper'

describe RWS::Kobo::Genre do
  let(:endpoint) { 'https://app.rakuten.co.jp/services/api/Kobo/GenreSearch/20131010' }
  let(:affiliate_id) { 'dummy_affiliate_id' }
  let(:application_id) { 'dummy_application_id' }
  let(:genre_id) { '101' }
  let(:expected_query) do
    {
      :affiliateId => affiliate_id,
      :applicationId => application_id,
      :koboGenreId => genre_id
    }
  end
  let(:expected_json) do
    JSON.parse(fixture('kobo/genre_search.json'))
  end

  before do
    @expected_request = stub_request(:get, endpoint).
      with(:query => expected_query).
      to_return(:body => expected_json.to_json)

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

  describe '.search' do
    before do
      @genre = RWS::Kobo::Genre.search(:koboGenreId => genre_id).first
    end

    specify 'call the endpoint once' do
      expect(@expected_request).to have_been_made.once
    end
  end

  describe '#search' do
    before do
      stub_request(:get, endpoint).with(:query => expected_query).
        to_return(:body => expected_json.to_json)
    end

    context 'Without arguments' do
      specify 'should call RWS::Kobo::Ebook.search with specifying genre id' do
        expect(RWS::Kobo::Ebook).to receive(:search).with(RWS::Kobo::Genre.genre_id_key => genre_id)

        RWS::Kobo::Genre.root.search
      end
    end
    context 'With arguments' do
      specify 'should call RWS::Kobo::Ebook.search with given arguments and genre id' do
        options = { title: 'Ruby' }
        expect(RWS::Kobo::Ebook).to receive(:search).with(:title => 'Ruby', RWS::Kobo::Genre.genre_id_key => genre_id)

        RWS::Kobo::Genre.root.search(options)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rakuten_web_service-1.4.1 spec/rakuten_web_service/kobo/genre_spec.rb
rakuten_web_service-1.4.0 spec/rakuten_web_service/kobo/genre_spec.rb
rakuten_web_service-1.3.0 spec/rakuten_web_service/kobo/genre_spec.rb
rakuten_web_service-1.2.0 spec/rakuten_web_service/kobo/genre_spec.rb
rakuten_web_service-1.1.1 spec/rakuten_web_service/kobo/genre_spec.rb
rakuten_web_service-1.1.0 spec/rakuten_web_service/kobo/genre_spec.rb
rakuten_web_service-1.0.0 spec/rakuten_web_service/kobo/genre_spec.rb
rakuten_web_service-1.0.0.rc1 spec/rakuten_web_service/kobo/genre_spec.rb