Sha256: 243bedc3a45f0af32846cde3af06b8583f31e0ddaf930349ef3f124efc109fa8

Contents?: true

Size: 1.92 KB

Versions: 8

Compression:

Stored size: 1.92 KB

Contents

require 'test_helper'

module Spyke
  class CustomRequestTest < MiniTest::Test
    def test_custom_get_request_using_class_method
      endpoint = stub_request(:get, 'http://sushi.com/recipes/recent').to_return_json(result: [{ id: 1, title: 'Bread' }])
      recipes = Recipe.get('/recipes/recent')
      assert_equal %w{ Bread }, recipes.map(&:title)
      assert_requested endpoint
    end

    def test_get_request_with_prepended_scope
      skip 'wishlisted'
      endpoint = stub_request(:get, 'http://sushi.com/recipes/recent?status=published')
      Recipe.published.get('/recipes/recent')
      assert_requested endpoint
    end

    def test_get_request_with_appended_scope
      skip 'wishlisted'
      endpoint = stub_request(:get, 'http://sushi.com/recipes/recent?status=published')
      Recipe.get('/recipes/recent').published.to_a
      assert_requested endpoint
    end

    def test_custom_get_request_from_class
      endpoint = stub_request(:get, 'http://sushi.com/recipes/recent').to_return_json(result: [{ id: 1, title: 'Bread' }])
      assert_equal %w{ Bread }, Recipe.get('/recipes/recent').map(&:title)
      assert_requested endpoint
    end

    def test_custom_put_request_from_class
      endpoint = stub_request(:put, 'http://sushi.com/recipes/1/publish')
      Recipe.put('/recipes/1/publish')
      assert_requested endpoint
    end

    def test_custom_put_request_from_instance
      endpoint = stub_request(:put, 'http://sushi.com/recipes/1/publish').to_return_json(result: { id: 1, status: 'published' })
      recipe = Recipe.new(id: 1, status: 'unpublished')
      recipe.put('/recipes/:id/publish')

      assert_equal 'published', recipe.status
      assert_requested endpoint
    end

    def test_custom_put_request_from_instance_with_symbol
      endpoint = stub_request(:put, 'http://sushi.com/recipes/1/draft')
      recipe = Recipe.new(id: 1)
      recipe.put(:draft)
      assert_requested endpoint
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
spyke-1.8.11 test/custom_request_test.rb
spyke-1.8.10 test/custom_request_test.rb
spyke-1.8.9 test/custom_request_test.rb
spyke-1.8.8 test/custom_request_test.rb
spyke-1.8.7 test/custom_request_test.rb
spyke-1.8.6 test/custom_request_test.rb
spyke-1.8.5 test/custom_request_test.rb
spyke-1.8.4 test/custom_request_test.rb