Skip to content
Browse files

Make sure Session initialization fails, when no shop is provided in c…

…onstructor. Added test for that. Also added tobi's context ultralite remix ;)
  • Loading branch information...
1 parent e7c7808 commit c7bbe5af1ac616cef87e8ba898142dfb38d8f94a @Soleone Soleone committed Jun 15, 2009
Showing with 24 additions and 12 deletions.
  1. +1 −0 lib/shopify_api.rb
  2. +15 −12 test/shopify_api_test.rb
  3. +8 −0 test/test_helper.rb
View
1 lib/shopify_api.rb
@@ -97,6 +97,7 @@ def self.setup(params)
end
def initialize(url, token = nil)
+ raise ArgumentError.new("You must provide at least a URL to a Shopify store!") if url.blank?
url.gsub!(/https?:\/\//, '') # remove http:// or https://
url = "#{url}.myshopify.com" unless url.include?('.') # extend url to myshopify.com if no host is given
View
27 test/shopify_api_test.rb
@@ -1,18 +1,21 @@
require 'test_helper'
class ShopifyApiTest < Test::Unit::TestCase
- def setup
- @session_no_token = ShopifyAPI::Session.new("testshop.myshopify.com")
- @session = ShopifyAPI::Session.new("testshop.myshopify.com", "any-token")
- end
-
-
- def test_session_not_valid_without_token
- assert_not @session_no_token.valid?
- end
- def test_session_is_valid_with_any_token
- assert @session.valid?
+ context "Session" do
+ test "should raise error when blank shop url is provided" do
+ assert_raise(ArgumentError) { ShopifyAPI::Session.new("") }
+ end
+
+ test "should not be valid without token" do
+ session = ShopifyAPI::Session.new("testshop.myshopify.com")
+ assert_not session.valid?
+ end
+
+ test "should be valid with any token" do
+ session = ShopifyAPI::Session.new("testshop.myshopify.com", "any-token")
+ assert session.valid?
+ end
+
end
-
end
View
8 test/test_helper.rb
@@ -9,6 +9,14 @@
ShopifyAPI::Session.setup(:api_key => "API Test key", :secret => "API Test secret")
class Test::Unit::TestCase
+ def self.test(string, &block)
+ define_method("test:#{string}", &block)
+ end
+
+ def self.context(string)
+ yield
+ end
+
# Custom Assertions
def assert_not(expression)
assert_block("Expected <#{expression}> to be false!") { not expression }

0 comments on commit c7bbe5a

Please sign in to comment.
Something went wrong with that request. Please try again.