Преглед изворни кода

Define `find` rather than `all` for AssignedFulfillmentOrder and FulfillmentOrder

Keith Kim пре 5 година
родитељ
комит
6fc2312813

+ 2 - 2
lib/shopify_api/resources/assigned_fulfillment_order.rb

@@ -1,7 +1,7 @@
 module ShopifyAPI
   class AssignedFulfillmentOrder < Base
-    def self.all(options = {})
-      assigned_fulfillment_orders = super(options)
+    def self.find(scope, *args)
+      assigned_fulfillment_orders = super(scope, *args)
       assigned_fulfillment_orders.map { |afo| FulfillmentOrder.new(afo.attributes) }
     end
   end

+ 9 - 5
lib/shopify_api/resources/fulfillment_order.rb

@@ -1,11 +1,15 @@
 module ShopifyAPI
   class FulfillmentOrder < Base
-    def self.all(options = {})
-      order_id = options.dig(:params, :order_id)
-      raise ShopifyAPI::ValidationException, "'order_id' is required" if order_id.nil? || order_id == ''
+    def self.find(scope, *args)
+      if scope == :all
+        order_id = args.first&.dig(:params, :order_id)
+        raise ShopifyAPI::ValidationException, "'order_id' is required" if order_id.blank?
 
-      order = ::ShopifyAPI::Order.new(id: order_id)
-      order.fulfillment_orders
+        order = ::ShopifyAPI::Order.new(id: order_id)
+        order.fulfillment_orders(args.first[:params].except(:order_id))
+      else
+        super(scope, *args)
+      end
     end
 
     def fulfillments(options = {})

+ 3 - 0
test/fulfillment_order_test.rb

@@ -5,6 +5,9 @@ class FulFillmentOrderTest < Test::Unit::TestCase
     super
     fake "fulfillment_orders/519788021", method: :get,
       body: load_fixture('fulfillment_order')
+
+    fake "orders/450789469/fulfillment_orders", method: :get,
+      body: load_fixture('fulfillment_orders')
   end
 
   context "FulfillmentOrder" do