Sha256: 350da9466c540cd45ca972e59a00acbe2b0fce8bd76de5da53f809da047531ba

Contents?: true

Size: 1.89 KB

Versions: 32

Compression:

Stored size: 1.89 KB

Contents

require 'test_helper'
require "active_support/log_subscriber/test_helper"

class LogSubscriberTest < Test::Unit::TestCase
  include ActiveSupport::LogSubscriber::TestHelper

  def setup
    super
    @page = { :page => { :id => 1, :title => 'Shopify API' } }.to_json
    @ua_header = "\"User-Agent\"=>\"ShopifyAPI/#{ShopifyAPI::VERSION} ActiveResource/#{ActiveResource::VERSION::STRING} Ruby/#{RUBY_VERSION}\""

    ShopifyAPI::Base.clear_session
    ShopifyAPI::Base.site = "https://this-is-my-test-shop.myshopify.com/admin"

    ActiveResource::LogSubscriber.attach_to :active_resource
    ActiveResource::DetailedLogSubscriber.attach_to :active_resource_detailed
  end

  def set_logger(logger)
    ActiveResource::Base.logger = logger
  end

  test "logging on #find" do
    fake "pages/1", :method => :get, :body => @page

    ShopifyAPI::Page.find(1)

    assert_equal 4, @logger.logged(:info).size
    assert_equal "GET https://this-is-my-test-shop.myshopify.com:443/admin/pages/1.json", @logger.logged(:info)[0]
    assert_match /\-\-\> 200/, @logger.logged(:info)[1]
    assert_equal "Headers: {\"Accept\"=>\"application/json\", #{@ua_header}}", @logger.logged(:info)[2]
    assert_match /Response:\n\{\"page\"\:\{((\"id\"\:1)|(\"title\"\:\"Shopify API\")),((\"id\"\:1)|(\"title\"\:\"Shopify API\"))\}\}/,  @logger.logged(:info)[3]

  end

  test "logging on #find with an error" do
    fake "pages/2", :method => :get, :body => nil, :status => 404

    assert_raises ActiveResource::ResourceNotFound do
      ShopifyAPI::Page.find(2)
    end

    assert_equal 4, @logger.logged(:info).size
    assert_equal "GET https://this-is-my-test-shop.myshopify.com:443/admin/pages/2.json", @logger.logged(:info)[0]
    assert_match /\-\-\> 404/, @logger.logged(:info)[1]
    assert_equal "Headers: {\"Accept\"=>\"application/json\", #{@ua_header}}", @logger.logged(:info)[2]
    assert_equal "Response:", @logger.logged(:info)[3]
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
shopify_api-5.2.0 test/detailed_log_subscriber_test.rb
shopify_api-4.13.0 test/detailed_log_subscriber_test.rb
shopify_api-4.12.0 test/detailed_log_subscriber_test.rb
shopify_api-4.11.0 test/detailed_log_subscriber_test.rb
shopify_api-4.10.0 test/detailed_log_subscriber_test.rb
shopify_api-4.9.1 test/detailed_log_subscriber_test.rb
shopify_api-4.9.0 test/detailed_log_subscriber_test.rb
shopify_api-4.8.0 test/detailed_log_subscriber_test.rb
shopify_api-4.7.1 test/detailed_log_subscriber_test.rb
shopify_api-4.7.0 test/detailed_log_subscriber_test.rb
shopify_api-4.6.0 test/detailed_log_subscriber_test.rb
shopify_api-4.5.0 test/detailed_log_subscriber_test.rb
shopify_api-4.4.0 test/detailed_log_subscriber_test.rb
shopify_api-4.3.9 test/detailed_log_subscriber_test.rb
shopify_api-4.3.8 test/detailed_log_subscriber_test.rb
shopify_api-4.3.7 test/detailed_log_subscriber_test.rb
shopify_api-4.3.6 test/detailed_log_subscriber_test.rb
shopify_api-4.3.5 test/detailed_log_subscriber_test.rb
shopify_api-4.3.4 test/detailed_log_subscriber_test.rb
shopify_api-4.3.3 test/detailed_log_subscriber_test.rb