瀏覽代碼

ShopifyAPI::Session.new no longer throws an ArgumentError when it's missing a url.

Julie Hache 15 年之前
父節點
當前提交
df1da22ab7
共有 2 個文件被更改,包括 8 次插入9 次删除
  1. 2 3
      lib/shopify_api.rb
  2. 6 6
      test/shopify_api_test.rb

+ 2 - 3
lib/shopify_api.rb

@@ -120,7 +120,6 @@ module ShopifyAPI
     end
 
     def initialize(url, token = nil, params = nil)
-      raise ArgumentError, "A valid Shopify shop URL must be provided" if url.blank?
       self.url, self.token = url, token
 
       if params && params[:signature]
@@ -129,7 +128,7 @@ module ShopifyAPI
         end
       end
 
-      self.class.prepare_url(self.url)
+      self.class.prepare_url(self.url) if valid?
     end
     
     def shop
@@ -148,7 +147,7 @@ module ShopifyAPI
     end
 
     def valid?
-      [url, token].all?
+      url.present? && token.present?
     end
 
     private

+ 6 - 6
test/shopify_api_test.rb

@@ -3,19 +3,19 @@ require 'test_helper'
 class ShopifyApiTest < Test::Unit::TestCase
   
   context "Session" do
-    should "raise error when blank shop url is provided" do
-      assert_raise(ArgumentError) { ShopifyAPI::Session.new("") }
+    should "not be valid without a url" do
+      session = ShopifyAPI::Session.new(nil, "any-token")
+      assert_not session.valid?
     end
-
+    
     should "not be valid without token" do
       session = ShopifyAPI::Session.new("testshop.myshopify.com")
       assert_not session.valid?
     end
 
-    should "be valid with any token" do
+    should "be valid with any token and any url" do
       session = ShopifyAPI::Session.new("testshop.myshopify.com", "any-token")
       assert session.valid?
     end
   end
-  
-end
+end