Sha256: 70168b1e7460c0d07f57669dc450e36470eef2885fc43d4f8cb633cb9d1c7f31

Contents?: true

Size: 1.64 KB

Versions: 5

Compression:

Stored size: 1.64 KB

Contents

require File.expand_path('../../test_helper', __FILE__)

module Loquor
  class ApiCall::ShowTest < Minitest::Test

    class NormalResource < Resource
      self.path = '/normal'
    end

    class CachedResource < Resource
      self.path = '/cached'
      self.cache = true
    end

    def test_request_should_not_send_for_nil_id
      show = ApiCall::Show.new(NormalResource, nil)
      Loquor.expects(:get).never
      show.execute
    end

    def test_request_correct_path
      show = ApiCall::Show.new(NormalResource, 42)
      Loquor.expects(:get).with('/normal/42', {cache: nil}).returns({}.to_json)
      show.execute
    end

    def test_request_correct_path_for_cachable_resources
      show = ApiCall::Show.new(CachedResource, 42)
      Loquor.expects(:get).with('/cached/42', {cache: true}).returns({}.to_json)
      show.execute
    end

    def test_should_retry_for_404_if_configured
      Loquor.config.retry_404s = true
      Loquor.expects(:get).twice.raises(RestClient::ResourceNotFound)

      show = ApiCall::Show.new(CachedResource, 42)
      assert_raises(RestClient::ResourceNotFound) do
        show.execute
      end
    end

    def test_should_not_retry_for_404_if_configured
      Loquor.config.retry_404s = false
      Loquor.expects(:get).once.raises(RestClient::ResourceNotFound)

      show = ApiCall::Show.new(CachedResource, 42)
      assert_raises(RestClient::ResourceNotFound) do
        show.execute
      end
    end

    def test_response_is_a_representation
      show = ApiCall::Show.new(Resource, 1)
      Loquor.stubs(get: {foo: 'bar'}.to_json)
      response = show.execute
      assert response.is_a?(Resource)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
loquor-1.13.0 test/api_calls/show_test.rb
loquor-1.12.0 test/api_calls/show_test.rb
loquor-1.11.0 test/api_calls/show_test.rb
loquor-1.10.0 test/api_calls/show_test.rb
loquor-1.9.0 test/api_calls/show_test.rb