浏览代码

explicitly define NullVersion methods

Jon G 5 年之前
父节点
当前提交
7d7ae85b17
共有 2 个文件被更改,包括 22 次插入16 次删除
  1. 12 14
      lib/shopify_api/api_version.rb
  2. 10 2
      test/api_version_test.rb

+ 12 - 14
lib/shopify_api/api_version.rb

@@ -112,20 +112,18 @@ module ShopifyAPI
     end
 
     class NullVersion
-      def self.nil?
-        true
-      end
-
-      def self.present?
-        false
-      end
-
-      def self.empty?
-        true
-      end
-
-      def self.method_missing(method_name, *args, &block)
-        raise ApiVersionNotSetError, "You must set ShopifyAPI::Base.api_version before making a request."
+      class << self
+        def stable?
+          raise ApiVersionNotSetError, "You must set ShopifyAPI::Base.api_version before making a request."
+        end
+
+        def construct_api_path(*_path)
+          raise ApiVersionNotSetError, "You must set ShopifyAPI::Base.api_version before making a request."
+        end
+
+        def construct_graphql_path
+          raise ApiVersionNotSetError, "You must set ShopifyAPI::Base.api_version before making a request."
+        end
       end
     end
   end

+ 10 - 2
test/api_version_test.rb

@@ -136,9 +136,17 @@ class ApiVersionTest < Test::Unit::TestCase
     )
   end
 
-  test "NullVersion raises ApiVersionNotSetError for any method call" do
+  test "NullVersion raises ApiVersionNotSetError" do
     assert_raises(ShopifyAPI::ApiVersion::ApiVersionNotSetError) do
-      ShopifyAPI::ApiVersion::NullVersion.anything
+      ShopifyAPI::ApiVersion::NullVersion.construct_api_path(:string)
+    end
+
+    assert_raises(ShopifyAPI::ApiVersion::ApiVersionNotSetError) do
+      ShopifyAPI::ApiVersion::NullVersion.construct_graphql_path
+    end
+
+    assert_raises(ShopifyAPI::ApiVersion::ApiVersionNotSetError) do
+      ShopifyAPI::ApiVersion::NullVersion.stable?
     end
   end