Sha256: c4266d0ef7cf68935941fffa4dbd49323f724acc56d2bc5c5e98a5f2aa065442

Contents?: true

Size: 1.08 KB

Versions: 15

Compression:

Stored size: 1.08 KB

Contents

require 'test_helper'

module Spyke
  class FallbacksTest < MiniTest::Test
    def setup
      stub_request(:get, "http://sushi.com/recipes/1").to_timeout
      stub_request(:get, "http://sushi.com/recipes?published=true").to_timeout
    end

    def test_find_with_default_fallback
      assert_raises ResourceNotFound do
        Recipe.with_fallback.find(1)
      end
    end

    def test_find_with_custom_fallback
      dummy_recipe = Recipe.new(title: "Dummy Recipe")

      result = Recipe.with_fallback(dummy_recipe).find(1)

      assert_equal "Dummy Recipe", result.title
    end

    def test_find_one_with_default_fallback
      recipe = Recipe.with_fallback.where(id: 1).find_one

      assert_nil recipe
    end

    def test_find_some_with_default_fallback
      assert_equal [], Recipe.where(published: true).with_fallback.all.to_a
    end

    def test_find_some_with_custom_fallback
      dummy_result = [Recipe.new(title: "Dummy Recipe")]

      result = Recipe.where(published: true).with_fallback(dummy_result).all

      assert_equal "Dummy Recipe", result.first.title
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
spyke-6.1.2 test/fallbacks_test.rb
spyke-6.1.1 test/fallbacks_test.rb
spyke-6.1.0 test/fallbacks_test.rb
spyke-6.0.0 test/fallbacks_test.rb
spyke-5.4.3 test/fallbacks_test.rb
spyke-5.4.2 test/fallbacks_test.rb
spyke-5.4.1 test/fallbacks_test.rb
spyke-5.4.0 test/fallbacks_test.rb
spyke-5.3.4 test/fallbacks_test.rb
spyke-5.3.3 test/fallbacks_test.rb
spyke-5.3.2 test/fallbacks_test.rb
spyke-5.3.1 test/fallbacks_test.rb
spyke-5.3.0 test/fallbacks_test.rb
spyke-5.2.0 test/fallbacks_test.rb
spyke-5.1.0 test/fallbacks_test.rb