Skip to content

Commit

Permalink
Fixes test suite to run with newer Minitest
Browse files Browse the repository at this point in the history
Fixes order cancellation API calls

Parameters being sent to the orders API were being
attached to the query string instead of added to the body.

As a result their truthiness was being lost and all calls to
cancel an order would result in an email being delivered to
the customer.

Ensures consistent state for tests

There was an intermittent bug that would come up in some
tests because the ShopifyAPI::Session.secret wasn't set.
  • Loading branch information
Chris Saunders committed Jun 1, 2015
1 parent 7af53e1 commit 79dda56
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 163 deletions.
2 changes: 1 addition & 1 deletion lib/shopify_api/resources/order.rb
Expand Up @@ -7,7 +7,7 @@ def close; load_attributes_from_response(post(:close, {}, only_id)); end
def open; load_attributes_from_response(post(:open, {}, only_id)); end

def cancel(options = {})
load_attributes_from_response(post(:cancel, options, only_id))
load_attributes_from_response(post(:cancel, {}, options.to_json))
end

def transactions
Expand Down
2 changes: 1 addition & 1 deletion lib/shopify_api/version.rb
@@ -1,3 +1,3 @@
module ShopifyAPI
VERSION = "4.0.3"
VERSION = "4.0.4"
end
2 changes: 1 addition & 1 deletion test/detailed_log_subscriber_test.rb
Expand Up @@ -36,7 +36,7 @@ def set_logger(logger)
test "logging on #find with an error" do
fake "pages/2", :method => :get, :body => nil, :status => 404

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

Expand Down
2 changes: 1 addition & 1 deletion test/limits_test.rb
Expand Up @@ -30,7 +30,7 @@ def setup
should "raise error when header doesn't exist" do
@header_hash = {}
ShopifyAPI::Base.connection.expects(:response).at_least(1).returns(@header_hash)
assert_raise ShopifyAPI::Limits::LimitUnavailable do
assert_raises ShopifyAPI::Limits::LimitUnavailable do
ShopifyAPI.credit_left
end
end
Expand Down
8 changes: 8 additions & 0 deletions test/order_test.rb
Expand Up @@ -35,5 +35,13 @@ class OrderTest < Test::Unit::TestCase
order = ShopifyAPI::Order.find(450789469)
assert order.destroy
end

test "cancel an order with params" do
fake 'orders/450789469', :method => :get, :status => 200, :body => load_fixture('order')
fake 'orders/450789469/cancel', :method => :post, :body => load_fixture('order')
order = ShopifyAPI::Order.find(450789469)
order.cancel(email: false, restock: true)
assert_request_body({'email' => false, 'restock' => true}.to_json)
end
end

319 changes: 163 additions & 156 deletions test/session_test.rb

Large diffs are not rendered by default.

26 changes: 23 additions & 3 deletions test/test_helper.rb
@@ -1,5 +1,5 @@
require 'rubygems'
require 'test/unit'
require 'minitest/autorun'
require 'fakeweb'
require 'mocha/setup'

Expand All @@ -10,8 +10,12 @@
FakeWeb.allow_net_connect = false

# setup ShopifyAPI with fake api_key and secret
module Test
module Unit
end
end

class Test::Unit::TestCase
class Test::Unit::TestCase < Minitest::Unit::TestCase
def self.test(string, &block)
define_method("test:#{string}", &block)
end
Expand Down Expand Up @@ -46,13 +50,29 @@ def teardown

# Custom Assertions
def assert_not(expression)
assert_block("Expected <#{expression}> to be false!") { not expression }
refute expression, "Expected <#{expression}> to be false!"
end

def assert_nothing_raised
yield
end

def assert_not_includes(array, value)
refute array.include?(value)
end

def assert_includes(array, value)
assert array.include?(value)
end

def load_fixture(name, format=:json)
File.read(File.dirname(__FILE__) + "/fixtures/#{name}.#{format}")
end

def assert_request_body(expected)
assert_equal expected, FakeWeb.last_request.body
end

def fake(endpoint, options={})
body = options.has_key?(:body) ? options.delete(:body) : load_fixture(endpoint)
format = options.delete(:format) || :json
Expand Down

0 comments on commit 79dda56

Please sign in to comment.