Browse Source

Fixing trivial rubocop warnings

Paulo Margarido 3 years ago
parent
commit
4dffdec0ac
55 changed files with 146 additions and 399 deletions
  1. 5 0
      .rubocop.yml
  2. 0 260
      .rubocop_todo.yml
  3. 7 2
      lib/active_resource/json_errors.rb
  4. 2 2
      lib/shopify_api/countable.rb
  5. 4 6
      lib/shopify_api/graphql.rb
  6. 10 9
      lib/shopify_api/message_enricher.rb
  7. 0 1
      lib/shopify_api/meta.rb
  8. 1 1
      lib/shopify_api/resources/announcement.rb
  9. 0 1
      lib/shopify_api/resources/assigned_fulfillment_order.rb
  10. 1 1
      lib/shopify_api/resources/cart.rb
  11. 19 5
      lib/shopify_api/resources/comment.rb
  12. 11 3
      lib/shopify_api/resources/fulfillment.rb
  13. 1 1
      lib/shopify_api/resources/image.rb
  14. 0 1
      lib/shopify_api/resources/inventory_level.rb
  15. 0 1
      lib/shopify_api/resources/location.rb
  16. 0 1
      lib/shopify_api/resources/price_rule.rb
  17. 4 3
      lib/shopify_api/resources/product.rb
  18. 1 1
      lib/shopify_api/resources/recurring_application_charge.rb
  19. 0 1
      lib/shopify_api/resources/smart_collection.rb
  20. 3 2
      lib/shopify_api/resources/variant.rb
  21. 3 5
      lib/shopify_api/session.rb
  22. 1 1
      shopify_api.gemspec
  23. 0 1
      test/access_token_test.rb
  24. 0 1
      test/active_resource/json_errors_test.rb
  25. 0 1
      test/api_version_test.rb
  26. 3 5
      test/application_charge_test.rb
  27. 0 2
      test/article_test.rb
  28. 2 2
      test/assigned_fulfillment_order_test.rb
  29. 1 3
      test/base_test.rb
  30. 2 2
      test/carrier_service_test.rb
  31. 1 1
      test/cart_test.rb
  32. 0 1
      test/collection_listing_test.rb
  33. 18 18
      test/collection_test.rb
  34. 1 0
      test/customer_saved_search_test.rb
  35. 0 1
      test/customer_test.rb
  36. 5 4
      test/fulfillment_order_test.rb
  37. 12 12
      test/fulfillment_service_test.rb
  38. 3 3
      test/fulfillment_test.rb
  39. 1 0
      test/gift_card_test.rb
  40. 2 2
      test/inventory_level_test.rb
  41. 0 1
      test/marketing_event_test.rb
  42. 0 1
      test/message_enricher_test.rb
  43. 1 3
      test/meta_test.rb
  44. 6 2
      test/order_test.rb
  45. 2 3
      test/pagination_test.rb
  46. 0 1
      test/product_listing_test.rb
  47. 1 2
      test/recurring_application_charge_test.rb
  48. 0 1
      test/refund_test.rb
  49. 2 2
      test/resource_feedback_test.rb
  50. 3 4
      test/session_test.rb
  51. 0 2
      test/storefront_access_token_test.rb
  52. 0 1
      test/tax_service_test.rb
  53. 4 4
      test/test_helper.rb
  54. 0 2
      test/usage_charge_test.rb
  55. 3 3
      test/user_test.rb

+ 5 - 0
.rubocop.yml

@@ -21,3 +21,8 @@ Lint/UnderscorePrefixedVariableName:
   Exclude:
     # This is an internal attribute and we want to make sure it's called _headers
     - 'lib/shopify_api/resources/base.rb'
+
+Naming/AccessorMethodName:
+  Exclude:
+    # This comes from activesupport, so we can't rename it
+    - 'test/detailed_log_subscriber_test.rb'

+ 0 - 260
.rubocop_todo.yml

@@ -6,196 +6,6 @@
 # Note that changes in the inspected code, or installation of new
 # versions of RuboCop, may require this file to be generated again.
 
-# Offense count: 1
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, IndentOneStep, IndentationWidth.
-# SupportedStyles: case, end
-Layout/CaseIndentation:
-  Exclude:
-    - 'lib/shopify_api/countable.rb'
-
-# Offense count: 9
-# Cop supports --auto-correct.
-Layout/ClosingParenthesisIndentation:
-  Exclude:
-    - 'lib/shopify_api/resources/product.rb'
-    - 'lib/shopify_api/resources/variant.rb'
-    - 'test/application_charge_test.rb'
-    - 'test/assigned_fulfillment_order_test.rb'
-    - 'test/collection_test.rb'
-    - 'test/recurring_application_charge_test.rb'
-
-# Offense count: 6
-# Cop supports --auto-correct.
-# Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines.
-Layout/EmptyLineBetweenDefs:
-  Exclude:
-    - 'lib/shopify_api/resources/comment.rb'
-    - 'lib/shopify_api/resources/fulfillment.rb'
-
-# Offense count: 4
-# Cop supports --auto-correct.
-Layout/EmptyLines:
-  Exclude:
-    - 'test/base_test.rb'
-    - 'test/customer_test.rb'
-    - 'test/meta_test.rb'
-
-# Offense count: 2
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: around, only_before
-Layout/EmptyLinesAroundAccessModifier:
-  Exclude:
-    - 'test/customer_saved_search_test.rb'
-    - 'test/gift_card_test.rb'
-
-# Offense count: 3
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: empty_lines, no_empty_lines
-Layout/EmptyLinesAroundBlockBody:
-  Exclude:
-    - 'test/api_version_test.rb'
-    - 'test/meta_test.rb'
-    - 'test/tax_service_test.rb'
-
-# Offense count: 24
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only
-Layout/EmptyLinesAroundClassBody:
-  Enabled: false
-
-# Offense count: 1
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
-Layout/EmptyLinesAroundModuleBody:
-  Exclude:
-    - 'lib/shopify_api/session.rb'
-
-# Offense count: 1
-# Cop supports --auto-correct.
-# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
-Layout/ExtraSpacing:
-  Exclude:
-    - 'lib/shopify_api/resources/product.rb'
-
-# Offense count: 6
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, IndentationWidth.
-# SupportedStyles: consistent, consistent_relative_to_receiver, special_for_inner_method_call, special_for_inner_method_call_in_parentheses
-Layout/FirstArgumentIndentation:
-  Exclude:
-    - 'test/application_charge_test.rb'
-    - 'test/assigned_fulfillment_order_test.rb'
-    - 'test/collection_test.rb'
-
-# Offense count: 12
-# Cop supports --auto-correct.
-# Configuration parameters: IndentationWidth, EnforcedStyle.
-# SupportedStyles: spaces, tabs
-Layout/IndentationStyle:
-  Exclude:
-    - 'test/fulfillment_service_test.rb'
-
-# Offense count: 4
-# Cop supports --auto-correct.
-# Configuration parameters: Width, IgnoredPatterns.
-Layout/IndentationWidth:
-  Exclude:
-    - 'test/fulfillment_service_test.rb'
-
-# Offense count: 3
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: symmetrical, new_line, same_line
-Layout/MultilineMethodCallBraceLayout:
-  Exclude:
-    - 'lib/shopify_api/resources/product.rb'
-    - 'lib/shopify_api/resources/variant.rb'
-    - 'test/fulfillment_order_test.rb'
-
-# Offense count: 1
-# Cop supports --auto-correct.
-Layout/RescueEnsureAlignment:
-  Exclude:
-    - 'lib/shopify_api/message_enricher.rb'
-
-# Offense count: 7
-# Cop supports --auto-correct.
-Layout/SpaceAfterColon:
-  Exclude:
-    - 'test/order_test.rb'
-
-# Offense count: 6
-# Cop supports --auto-correct.
-Layout/SpaceAfterComma:
-  Exclude:
-    - 'lib/active_resource/json_errors.rb'
-    - 'lib/shopify_api/session.rb'
-    - 'test/base_test.rb'
-    - 'test/fulfillment_order_test.rb'
-    - 'test/session_test.rb'
-
-# Offense count: 6
-# Cop supports --auto-correct.
-# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
-# SupportedStylesForExponentOperator: space, no_space
-Layout/SpaceAroundOperators:
-  Exclude:
-    - 'lib/shopify_api/resources/product.rb'
-    - 'test/pagination_test.rb'
-    - 'test/test_helper.rb'
-
-# Offense count: 4
-# Cop supports --auto-correct.
-Layout/SpaceBeforeComma:
-  Exclude:
-    - 'test/carrier_service_test.rb'
-    - 'test/fulfillment_service_test.rb'
-
-# Offense count: 4
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets.
-# SupportedStyles: space, no_space, compact
-# SupportedStylesForEmptyBrackets: space, no_space
-Layout/SpaceInsideArrayLiteralBrackets:
-  Exclude:
-    - 'test/resource_feedback_test.rb'
-
-# Offense count: 1
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: space, no_space
-Layout/SpaceInsideParens:
-  Exclude:
-    - 'lib/shopify_api/resources/recurring_application_charge.rb'
-
-# Offense count: 4
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: final_newline, final_blank_line
-Layout/TrailingEmptyLines:
-  Exclude:
-    - 'lib/shopify_api/meta.rb'
-    - 'lib/shopify_api/resources/announcement.rb'
-    - 'lib/shopify_api/resources/cart.rb'
-    - 'test/cart_test.rb'
-
-# Offense count: 3
-# Cop supports --auto-correct.
-# Configuration parameters: AllowInHeredoc.
-Layout/TrailingWhitespace:
-  Exclude:
-    - 'test/user_test.rb'
-
-# Offense count: 1
-Naming/AccessorMethodName:
-  Exclude:
-    - 'test/detailed_log_subscriber_test.rb'
-
 # Offense count: 6
 # Configuration parameters: EnforcedStyle.
 # SupportedStyles: snake_case, camelCase
@@ -203,17 +13,6 @@ Naming/VariableName:
   Exclude:
     - 'lib/shopify_api/resources/fulfillment.rb'
 
-# Offense count: 1
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods.
-# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces
-# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
-# FunctionalMethods: let, let!, subject, watch
-# IgnoredMethods: lambda, proc, it
-Style/BlockDelimiters:
-  Exclude:
-    - 'test/inventory_level_test.rb'
-
 # Offense count: 2
 # Cop supports --auto-correct.
 Style/ColonMethodCall:
@@ -235,37 +34,11 @@ Style/CommandLiteral:
 Style/FrozenStringLiteralComment:
   Enabled: false
 
-# Offense count: 1
-# Configuration parameters: AllowIfModifier.
-Style/IfInsideElse:
-  Exclude:
-    - 'lib/shopify_api/graphql.rb'
-
 # Offense count: 1
 Style/MissingRespondToMissing:
   Exclude:
     - 'lib/shopify_api/resources/asset.rb'
 
-# Offense count: 3
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: short, verbose
-Style/PreferredHashMethods:
-  Exclude:
-    - 'test/test_helper.rb'
-
-# Offense count: 1
-# Cop supports --auto-correct.
-Style/RedundantException:
-  Exclude:
-    - 'lib/shopify_api/session.rb'
-
-# Offense count: 2
-# Cop supports --auto-correct.
-Style/RedundantParentheses:
-  Exclude:
-    - 'test/session_test.rb'
-
 # Offense count: 5
 # Cop supports --auto-correct.
 Style/RedundantPercentQ:
@@ -283,20 +56,6 @@ Style/RedundantSelf:
     - 'lib/shopify_api/resources/product.rb'
     - 'lib/shopify_api/resources/recurring_application_charge.rb'
 
-# Offense count: 1
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
-# SupportedStyles: slashes, percent_r, mixed
-Style/RegexpLiteral:
-  Exclude:
-    - 'lib/shopify_api/resources/image.rb'
-
-# Offense count: 1
-# Cop supports --auto-correct.
-Style/RescueModifier:
-  Exclude:
-    - 'lib/active_resource/json_errors.rb'
-
 # Offense count: 1
 # Cop supports --auto-correct.
 # Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods.
@@ -305,14 +64,6 @@ Style/SafeNavigation:
   Exclude:
     - 'lib/shopify_api/resources/custom_collection.rb'
 
-# Offense count: 8
-# Cop supports --auto-correct.
-# Configuration parameters: AllowIfMethodIsEmpty.
-Style/SingleLineMethods:
-  Exclude:
-    - 'lib/shopify_api/resources/comment.rb'
-    - 'lib/shopify_api/resources/fulfillment.rb'
-
 # Offense count: 2
 # Cop supports --auto-correct.
 # Configuration parameters: EnforcedStyle.
@@ -322,17 +73,6 @@ Style/SpecialGlobalVars:
     - 'lib/shopify_api.rb'
     - 'shopify_api.gemspec'
 
-# Offense count: 7
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyleForMultiline.
-# SupportedStylesForMultiline: comma, consistent_comma, no_comma
-Style/TrailingCommaInArrayLiteral:
-  Exclude:
-    - 'shopify_api.gemspec'
-    - 'test/fulfillment_order_test.rb'
-    - 'test/fulfillment_test.rb'
-    - 'test/meta_test.rb'
-
 # Offense count: 2
 # Cop supports --auto-correct.
 # Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, AllowedMethods.

+ 7 - 2
lib/active_resource/json_errors.rb

@@ -3,7 +3,12 @@ require 'active_resource/base'
 module ActiveResource
   class Errors < ActiveModel::Errors
     def from_json(json, save_cache = false)
-      data = ActiveSupport::JSON.decode(json)['errors'] || {} rescue {}
+      data =
+        begin
+          ActiveSupport::JSON.decode(json)['errors'] || {}
+        rescue
+          {}
+        end
       case data
       when String
         from_string(data, save_cache)
@@ -15,7 +20,7 @@ module ActiveResource
     def from_hash(messages, save_cache = false)
       clear unless save_cache
 
-      messages.each do |key,errors|
+      messages.each do |key, errors|
         errors.each do |error|
           add(key, error)
         end

+ 2 - 2
lib/shopify_api/countable.rb

@@ -4,8 +4,8 @@ module ShopifyAPI
       data = get(:count, options)
 
       count = case data
-        when Hash then data["count"]
-        else data
+      when Hash then data["count"]
+      else data
       end
 
       Integer(count)

+ 4 - 6
lib/shopify_api/graphql.rb

@@ -53,13 +53,11 @@ module ShopifyAPI
 
           if matches
             api_version = ShopifyAPI::ApiVersion.new(handle: matches[1])
+          elsif raise_on_invalid_schema
+            raise InvalidSchema,
+              "Invalid schema file name `#{schema_file}`. Does not match format of: `<version>.json`."
           else
-            if raise_on_invalid_schema
-              raise InvalidSchema,
-                "Invalid schema file name `#{schema_file}`. Does not match format of: `<version>.json`."
-            else
-              next
-            end
+            next
           end
 
           schema = graphql_client.load_schema(schema_file.to_s)

+ 10 - 9
lib/shopify_api/message_enricher.rb

@@ -4,17 +4,18 @@ module ShopifyAPI
       return super unless (400...500).include?(code.to_i)
 
       @_cached_message ||= begin
-        detailed_error = begin
-          parsed_body = JSON.parse(body)
+        detailed_error =
+          begin
+            parsed_body = JSON.parse(body)
 
-          if parsed_body['error']
-            parsed_body['error'].to_s
-          elsif parsed_body['errors']
-            Array(parsed_body['errors']).join('; ')
+            if parsed_body['error']
+              parsed_body['error'].to_s
+            elsif parsed_body['errors']
+              Array(parsed_body['errors']).join('; ')
+            end
+          rescue JSON::ParserError
+            nil
           end
-        rescue JSON::ParserError
-          nil
-        end
 
         detailed_error.present? ? "#{super} (#{detailed_error})" : super
       end

+ 0 - 1
lib/shopify_api/meta.rb

@@ -12,4 +12,3 @@ module ShopifyAPI
     end
   end
 end
-

+ 1 - 1
lib/shopify_api/resources/announcement.rb

@@ -1,4 +1,4 @@
 module ShopifyAPI
   class Announcement < Base
   end
-end
+end

+ 0 - 1
lib/shopify_api/resources/assigned_fulfillment_order.rb

@@ -1,6 +1,5 @@
 module ShopifyAPI
   class AssignedFulfillmentOrder < Base
-
     def initialize(attributes = {}, persisted = false)
       ShopifyAPI::Base.version_validation!(FulfillmentOrder::MINIMUM_VERSION)
       super(attributes, persisted)

+ 1 - 1
lib/shopify_api/resources/cart.rb

@@ -1,4 +1,4 @@
 module ShopifyAPI
   class Cart < Base
   end
-end
+end

+ 19 - 5
lib/shopify_api/resources/comment.rb

@@ -1,9 +1,23 @@
 module ShopifyAPI
   class Comment < Base
-    def remove;   load_attributes_from_response(post(:remove, {}, only_id)); end
-    def spam;     load_attributes_from_response(post(:spam, {}, only_id)); end
-    def approve;  load_attributes_from_response(post(:approve, {}, only_id)); end
-    def restore;  load_attributes_from_response(post(:restore, {}, only_id)); end
-    def not_spam; load_attributes_from_response(post(:not_spam, {}, only_id)); end
+    def remove
+      load_attributes_from_response(post(:remove, {}, only_id))
+    end
+
+    def spam
+      load_attributes_from_response(post(:spam, {}, only_id))
+    end
+
+    def approve
+      load_attributes_from_response(post(:approve, {}, only_id))
+    end
+
+    def restore
+      load_attributes_from_response(post(:restore, {}, only_id))
+    end
+
+    def not_spam
+      load_attributes_from_response(post(:not_spam, {}, only_id))
+    end
   end
 end

+ 11 - 3
lib/shopify_api/resources/fulfillment.rb

@@ -6,9 +6,17 @@ module ShopifyAPI
       @prefix_options[:order_id]
     end
 
-    def cancel; load_attributes_from_response(post(:cancel, {}, only_id)); end
-    def complete; load_attributes_from_response(post(:complete, {}, only_id)); end
-    def open; load_attributes_from_response(post(:open, {}, only_id)); end
+    def cancel
+      load_attributes_from_response(post(:cancel, {}, only_id))
+    end
+
+    def complete
+      load_attributes_from_response(post(:complete, {}, only_id))
+    end
+
+    def open
+      load_attributes_from_response(post(:open, {}, only_id))
+    end
 
     def order_id=(order_id)
       prefix_options[:order_id] = order_id

+ 1 - 1
lib/shopify_api/resources/image.rb

@@ -5,7 +5,7 @@ module ShopifyAPI
     # generate a method for each possible image variant
     [:pico, :icon, :thumb, :small, :compact, :medium, :large, :grande, :original].each do |m|
       reg_exp_match = "/\\1_#{m}.\\2"
-      define_method(m) { src.gsub(/\/(.*)\.(\w{2,4})/, reg_exp_match) }
+      define_method(m) { src.gsub(%r/\/(.*)\.(\w{2,4})/, reg_exp_match) }
     end
 
     def attach_image(data, filename = nil)

+ 0 - 1
lib/shopify_api/resources/inventory_level.rb

@@ -2,7 +2,6 @@
 
 module ShopifyAPI
   class InventoryLevel < Base
-
     # The default path structure in ActiveResource for delete would result in:
     # /admin/api/<version>/inventory_levels/#{ inventory_level.id }.json?#{ params }, but since
     # InventoryLevels are a second class resource made up of a Where and a What

+ 0 - 1
lib/shopify_api/resources/location.rb

@@ -1,6 +1,5 @@
 module ShopifyAPI
   class Location < Base
-
     def inventory_levels
       ShopifyAPI::InventoryLevel.find(:all, from: "#{self.class.prefix}locations/#{id}/inventory_levels.json")
     end

+ 0 - 1
lib/shopify_api/resources/price_rule.rb

@@ -1,6 +1,5 @@
 module ShopifyAPI
   class PriceRule < Base
-
     def discount_codes
       DiscountCode.find(:all, params: { price_rule_id: id })
     end

+ 4 - 3
lib/shopify_api/resources/product.rb

@@ -13,7 +13,7 @@ module ShopifyAPI
     # compute the price range
     def price_range
       prices = variants.collect(&:price).collect(&:to_f)
-      format =  "%0.2f"
+      format = "%0.2f"
       if prices.min != prices.max
         "#{format % prices.min} - #{format % prices.max}"
       else
@@ -45,9 +45,10 @@ module ShopifyAPI
     private
 
     def raise_deprecated_inventory_call(parameter)
-      raise(ShopifyAPI::ValidationException,
+      raise(
+        ShopifyAPI::ValidationException,
         "'#{parameter}' is deprecated - see https://help.shopify.com/en/api/guides/inventory-migration-guide",
-        )
+      )
     end
 
     def allow_inventory_params?

+ 1 - 1
lib/shopify_api/resources/recurring_application_charge.rb

@@ -26,7 +26,7 @@ module ShopifyAPI
 
     def customize(customize_recurring_app_charge_params = {})
       load_attributes_from_response(
-        put(:customize, recurring_application_charge: customize_recurring_app_charge_params )
+        put(:customize, recurring_application_charge: customize_recurring_app_charge_params)
       )
     end
   end

+ 0 - 1
lib/shopify_api/resources/smart_collection.rb

@@ -10,6 +10,5 @@ module ShopifyAPI
     def order(options = {})
       load_attributes_from_response(put(:order, options, only_id))
     end
-
   end
 end

+ 3 - 2
lib/shopify_api/resources/variant.rb

@@ -30,9 +30,10 @@ module ShopifyAPI
     private
 
     def raise_deprecated_inventory_call(parameter)
-      raise(ShopifyAPI::ValidationException,
+      raise(
+        ShopifyAPI::ValidationException,
         "'#{parameter}' is deprecated - see https://help.shopify.com/en/api/guides/inventory-migration-guide",
-        )
+      )
     end
 
     def allow_inventory_params?

+ 3 - 5
lib/shopify_api/session.rb

@@ -2,7 +2,6 @@ require 'openssl'
 require 'rack'
 
 module ShopifyAPI
-
   class ValidationException < StandardError
   end
 
@@ -15,9 +14,8 @@ module ShopifyAPI
     alias_method :url, :domain
 
     class << self
-
       def setup(params)
-        params.each { |k,value| public_send("#{k}=", value) }
+        params.each { |k, value| public_send("#{k}=", value) }
       end
 
       def temp(domain:, token:, api_version: ShopifyAPI::Base.api_version, &block)
@@ -80,7 +78,7 @@ module ShopifyAPI
 
       def encoded_params_for_signature(params)
         params = params.except(:signature, :hmac, :action, :controller)
-        params.map { |k,v| "#{URI.escape(k.to_s, '&=%')}=#{URI.escape(v.to_s, '&%')}" }.sort.join('&')
+        params.map { |k, v| "#{URI.escape(k.to_s, '&=%')}=#{URI.escape(v.to_s, '&%')}" }.sort.join('&')
       end
 
       def extract_current_session
@@ -121,7 +119,7 @@ module ShopifyAPI
         end
         token
       else
-        raise RuntimeError, response.msg
+        raise response.msg
       end
     end
 

+ 1 - 1
shopify_api.gemspec

@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
 
   s.extra_rdoc_files = [
     "LICENSE",
-    "README.md"
+    "README.md",
   ]
   s.files         = `git ls-files`.split("\n")
   s.test_files    = `git ls-files -- {test}/*`.split("\n")

+ 0 - 1
test/access_token_test.rb

@@ -1,7 +1,6 @@
 require 'test_helper'
 
 class AccessTokenTest < Test::Unit::TestCase
-
   def test_delegate_access_token
     fake(
       "access_tokens/delegate.json?delegate_access_scope%5B%5D=write_orders&" \

+ 0 - 1
test/active_resource/json_errors_test.rb

@@ -2,7 +2,6 @@ require 'test_helper'
 
 module ActiveResource
   class JsonErrorsTest < Test::Unit::TestCase
-
     def test_parsing_of_error_json_hash
       @model = ShopifyAPI::Order.new
       @model.errors.from_json({ errors: { name: ['missing'] } }.to_json)

+ 0 - 1
test/api_version_test.rb

@@ -108,7 +108,6 @@ class ApiVersionTest < Test::Unit::TestCase
       }
     )
     silence_warnings do
-
       refute_equal(
         ShopifyAPI::ApiVersion.new(handle: '2019-01'),
         ShopifyAPI::ApiVersion.latest_stable_version

+ 3 - 5
test/application_charge_test.rb

@@ -1,14 +1,13 @@
 require 'test_helper'
 
 class ApplicationChargeTest < Test::Unit::TestCase
-
   def test_application_charge_create
     fake("application_charges", method: :post, status: 201, body: load_fixture('application_charge'))
 
     charge = ShopifyAPI::ApplicationCharge.create(
-        name: "iPod Cleaning",
-        price: 5.00,
-        return_url: "http://google.com"
+      name: "iPod Cleaning",
+      price: 5.00,
+      return_url: "http://google.com"
     )
 
     assert_equal(
@@ -79,5 +78,4 @@ class ApplicationChargeTest < Test::Unit::TestCase
 
     assert(charge.last.activate)
   end
-
 end

+ 0 - 2
test/article_test.rb

@@ -1,7 +1,6 @@
 require 'test_helper'
 
 class ArticleTest < Test::Unit::TestCase
-
   def test_create_article
     fake("blogs/1008414260/articles", method: :post, body: load_fixture('article'))
     article = ShopifyAPI::Article.new(blog_id: 1008414260)
@@ -69,5 +68,4 @@ class ArticleTest < Test::Unit::TestCase
     tags = ShopifyAPI::Article.tags(popular: 1, limit: 1)
     assert_equal(3, tags.length)
   end
-
 end

+ 2 - 2
test/assigned_fulfillment_order_test.rb

@@ -44,7 +44,7 @@ class AssignedFulFillmentOrderTest < Test::Unit::TestCase
           extension: false
 
         assigned_fulfillment_orders = ShopifyAPI::AssignedFulfillmentOrder.all(
-            params: { assigned_status: 'cancellation_requested' }
+          params: { assigned_status: 'cancellation_requested' }
         )
 
         assert_equal 2, assigned_fulfillment_orders.count
@@ -63,7 +63,7 @@ class AssignedFulFillmentOrderTest < Test::Unit::TestCase
           body: @fulfillment_order_fixture, extension: false
 
         assigned_fulfillment_orders = ShopifyAPI::AssignedFulfillmentOrder.all(
-            params: { location_ids: [assigned_location_id] }
+          params: { location_ids: [assigned_location_id] }
         )
 
         assert_equal 2, assigned_fulfillment_orders.count

+ 1 - 3
test/base_test.rb

@@ -42,7 +42,6 @@ class BaseTest < Test::Unit::TestCase
   test '#clear_session should not change the api_version' do
     ShopifyAPI::Base.site = "https://zoo:lion@www.zoo.com"
 
-
     assert_equal("zoo", ShopifyAPI::Base.user)
     assert_equal("lion", ShopifyAPI::Base.password)
 
@@ -51,7 +50,7 @@ class BaseTest < Test::Unit::TestCase
     assert_nil(ShopifyAPI::Base.user)
     assert_nil(ShopifyAPI::Base.password)
     assert_nil(ShopifyAPI::Base.site)
-    assert_equal(ShopifyAPI::Base.api_version,@session1.api_version)
+    assert_equal(ShopifyAPI::Base.api_version, @session1.api_version)
   end
 
   test '#clear_session should clear site and headers from Base' do
@@ -202,7 +201,6 @@ class BaseTest < Test::Unit::TestCase
     assert_equal('The minimum supported version is 2020-01.', exception.message)
   end
 
-
   def clear_header(header)
     [ActiveResource::Base, ShopifyAPI::Base, ShopifyAPI::Product].each do |klass|
       klass.headers.delete(header)

+ 2 - 2
test/carrier_service_test.rb

@@ -5,13 +5,13 @@ class CarrierServiceTest < Test::Unit::TestCase
     fake("carrier_services", method: :post, body: load_fixture('carrier_service'))
     carrier_service = ShopifyAPI::CarrierService.new(name: "Some Postal Service")
     carrier_service.save
-    assert_equal("Some Postal Service" , carrier_service.name)
+    assert_equal("Some Postal Service", carrier_service.name)
   end
 
   test 'find should return the carrier service' do
     fake("carrier_services/123456", method: :get, body: load_fixture('carrier_service'))
     carrier_service = ShopifyAPI::CarrierService.find(123456)
-    assert_equal(123456 , carrier_service.id)
+    assert_equal(123456, carrier_service.id)
     assert_equal("Some Postal Service", carrier_service.name)
   end
 end

+ 1 - 1
test/cart_test.rb

@@ -10,4 +10,4 @@ class CartTest < Test::Unit::TestCase
     assert_equal 1, carts.first.line_items.size
     assert_equal 'test', carts.first.line_items.first.title
   end
-end
+end

+ 0 - 1
test/collection_listing_test.rb

@@ -1,7 +1,6 @@
 require 'test_helper'
 
 class CollectionListingTest < Test::Unit::TestCase
-
   def test_get_collection_listings
     fake("collection_listings", method: :get, status: 201, body: load_fixture('collection_listings'))
 

+ 18 - 18
test/collection_test.rb

@@ -6,23 +6,23 @@ class CollectionTest < Test::Unit::TestCase
     ShopifyAPI::Base.activate_session(available_version)
 
     fake(
-        'collections',
-        url: 'https://shop2.myshopify.com/admin/api/2020-01/collections/1.json',
-        method: :get,
-        status: 200,
-        body: load_fixture('collection'),
-        extension: false
+      'collections',
+      url: 'https://shop2.myshopify.com/admin/api/2020-01/collections/1.json',
+      method: :get,
+      status: 200,
+      body: load_fixture('collection'),
+      extension: false
     )
 
     collection = ShopifyAPI::Collection.find(1)
 
     fake(
-        'products',
-        url: 'https://shop2.myshopify.com/admin/api/2020-01/collections/1/products.json',
-        method: :get,
-        status: 200,
-        body: load_fixture('collection_products'),
-        extension: false
+      'products',
+      url: 'https://shop2.myshopify.com/admin/api/2020-01/collections/1/products.json',
+      method: :get,
+      status: 200,
+      body: load_fixture('collection_products'),
+      extension: false
     )
     assert_equal [632910392, 921728736], collection.products.map(&:id)
   end
@@ -32,12 +32,12 @@ class CollectionTest < Test::Unit::TestCase
     ShopifyAPI::Base.activate_session(old_version)
 
     fake(
-        'collections',
-        url: 'https://shop2.myshopify.com/admin/api/2019-10/collections/1.json',
-        method: :get,
-        status: 200,
-        body: load_fixture('collection'),
-        extension: false
+      'collections',
+      url: 'https://shop2.myshopify.com/admin/api/2019-10/collections/1.json',
+      method: :get,
+      status: 200,
+      body: load_fixture('collection'),
+      extension: false
     )
 
     collection = ShopifyAPI::Collection.find(1)

+ 1 - 0
test/customer_saved_search_test.rb

@@ -28,6 +28,7 @@ class CustomerSavedSearchTest < Test::Unit::TestCase
   end
 
   private
+
   def load_customer_saved_search
     fake('customer_saved_searches/8899730', body: load_fixture('customer_saved_search'))
     @customer_saved_search = ShopifyAPI::CustomerSavedSearch.find(8899730)

+ 0 - 1
test/customer_test.rb

@@ -48,7 +48,6 @@ class CustomerTest < Test::Unit::TestCase
     customer_invite = ActiveSupport::JSON.decode(customer_invite_fixture)
     fake('customers/207119551/send_invite', method: :post, body: customer_invite_fixture)
 
-
     customer_invite_response = @customer.send_invite(ShopifyAPI::CustomerInvite.new(customer_invite['customer_invite']))
 
     assert_equal(customer_invite, ActiveSupport::JSON.decode(WebMock.last_request.body))

+ 5 - 4
test/fulfillment_order_test.rb

@@ -67,7 +67,8 @@ class FulFillmentOrderTest < Test::Unit::TestCase
 
     context "#all" do
       should "be able to list fulfillment orders for an order" do
-        fake('orders',
+        fake(
+          'orders',
           url: "#{@url_prefix}/orders/450789469/fulfillment_orders.json",
           method: :get,
           body: load_fixture('fulfillment_orders')
@@ -125,7 +126,7 @@ class FulFillmentOrderTest < Test::Unit::TestCase
 
         location = location_for_move.location
         assert(location.is_a?(ShopifyAPI::Location))
-        assert_equal(1059367776,location.id)
+        assert_equal(1059367776, location.id)
       end
     end
 
@@ -245,7 +246,7 @@ class FulFillmentOrderTest < Test::Unit::TestCase
         request_body = {
           fulfillment_request: {
             fulfillment_order_line_items: [
-              { id: 1, quantity: 1 }
+              { id: 1, quantity: 1 },
             ],
             message: 'Fulfill this FO, please.',
           },
@@ -297,7 +298,7 @@ class FulFillmentOrderTest < Test::Unit::TestCase
         request_body = {
           fulfillment_request: {
             fulfillment_order_line_items: [
-              { id: 1, quantity: 1 }
+              { id: 1, quantity: 1 },
             ],
             message: 'Fulfill this FO, please.',
           },

+ 12 - 12
test/fulfillment_service_test.rb

@@ -1,17 +1,17 @@
 require 'test_helper'
 
 class FulFillmentServiceTest < Test::Unit::TestCase
-	test 'new should create fulfillment service' do
-		fake("fulfillment_services", method: :post, body: load_fixture('fulfillment_service'))
-		fulfillment_service = ShopifyAPI::FulfillmentService.new(name: "SomeService")
-		fulfillment_service.save
-		assert_equal("SomeService" , fulfillment_service.name)
-	end
+  test 'new should create fulfillment service' do
+    fake("fulfillment_services", method: :post, body: load_fixture('fulfillment_service'))
+    fulfillment_service = ShopifyAPI::FulfillmentService.new(name: "SomeService")
+    fulfillment_service.save
+    assert_equal("SomeService", fulfillment_service.name)
+  end
 
-	test 'find should return the fulfillment service' do
-		fake("fulfillment_services/123456", method: :get, body: load_fixture('fulfillment_service'))
-		fulfillment_service = ShopifyAPI::FulfillmentService.find(123456)
-		assert_equal(123456 , fulfillment_service.id)
-		assert_equal("SomeService", fulfillment_service.name)
-	end
+  test 'find should return the fulfillment service' do
+    fake("fulfillment_services/123456", method: :get, body: load_fixture('fulfillment_service'))
+    fulfillment_service = ShopifyAPI::FulfillmentService.find(123456)
+    assert_equal(123456, fulfillment_service.id)
+    assert_equal("SomeService", fulfillment_service.name)
+  end
 end

+ 3 - 3
test/fulfillment_test.rb

@@ -82,7 +82,7 @@ class FulFillmentTest < Test::Unit::TestCase
             {
               fulfillment_order_id: 3,
               fulfillment_order_line_items: [{ id: 2, quantity: 1 }],
-            }
+            },
           ],
         }
         request_body = { fulfillment: create_fulfillment_attributes }
@@ -114,7 +114,7 @@ class FulFillmentTest < Test::Unit::TestCase
             {
               fulfillment_order_id: 3,
               fulfillment_order_line_items: [{ id: 2, quantity: 1 }],
-            }
+            },
           ],
         }
         request_body = { fulfillment: create_fulfillment_attributes }
@@ -147,7 +147,7 @@ class FulFillmentTest < Test::Unit::TestCase
             {
               fulfillment_order_id: 3,
               fulfillment_order_line_items: [{ id: 2, quantity: 1 }],
-            }
+            },
           ],
         }
         request_body = { fulfillment: create_fulfillment_attributes }

+ 1 - 0
test/gift_card_test.rb

@@ -15,6 +15,7 @@ class GiftCardTest < Test::Unit::TestCase
   end
 
   private
+
   def load_gift_card
     fake('gift_cards/1023670', body: load_fixture('gift_card'))
     @gift_card = ShopifyAPI::GiftCard.find(1023670)

+ 2 - 2
test/inventory_level_test.rb

@@ -19,10 +19,10 @@ class InventoryLevelTest < Test::Unit::TestCase
     inventory_levels = ShopifyAPI::InventoryLevel.find(:all, params: params)
 
     assert(
-      inventory_levels.all? { |item|
+      inventory_levels.all? do |item|
         params[:location_ids].include?(item.location_id) &&
         params[:inventory_item_ids].include?(item.inventory_item_id)
-      },
+      end,
       message: 'Response contained inventory_items or locations not requested.'
     )
   end

+ 0 - 1
test/marketing_event_test.rb

@@ -1,7 +1,6 @@
 require 'test_helper'
 
 class MarketingEventTest < Test::Unit::TestCase
-
   def test_get_marketing_events
     fake("marketing_events", method: :get, body: load_fixture('marketing_events'))
     marketing_events = ShopifyAPI::MarketingEvent.all

+ 0 - 1
test/message_enricher_test.rb

@@ -1,7 +1,6 @@
 require 'test_helper'
 
 class MessageEnricherTest < Test::Unit::TestCase
-
   def test_enriches_initial_message_when_body_contains_error
     response = enriched_response(422, 'InitialMessage', { error: 'My Error' })
 

+ 1 - 3
test/meta_test.rb

@@ -39,11 +39,9 @@ class ApiVersionTest < Test::Unit::TestCase
         "latest_supported": false,
         "display_name": "unstable",
         "supported": false,
-      }
+      },
     ].to_json
 
-
     assert_equal versions, ShopifyAPI::Meta.admin_versions.to_json
-
   end
 end

+ 6 - 2
test/order_test.rb

@@ -6,7 +6,10 @@ class OrderTest < Test::Unit::TestCase
 
   test "create should create order" do
     fake('orders', method: :post, status: 201, body: load_fixture('order'))
-    order = ShopifyAPI::Order.create(line_items: [{ quantity:1, variant_id:39072856 }], financial_status:"authorized")
+    order = ShopifyAPI::Order.create(
+      line_items: [{ quantity: 1, variant_id: 39072856 }],
+      financial_status: "authorized"
+    )
     assert_equal(39072856, order.line_items.first.variant_id)
   end
 
@@ -22,7 +25,8 @@ class OrderTest < Test::Unit::TestCase
     ]
     fake('orders', method: :post, status: 201, body: load_fixture('order_with_properties'))
     order = ShopifyAPI::Order.create(
-      line_items: [{ quantity:1, variant_id:39072856, properties:props }], financial_status:"authorized"
+      line_items: [{ quantity: 1, variant_id: 39072856, properties: props }],
+      financial_status: "authorized"
     )
     assert_equal(39072856, order.line_items.first.variant_id)
   end

+ 2 - 3
test/pagination_test.rb

@@ -16,7 +16,7 @@ class PaginationTest < Test::Unit::TestCase
   end
 
   test "navigates using next and previous link headers with no original params" do
-    link_header ="#{@previous_link_header}, #{@next_link_header}"
+    link_header = "#{@previous_link_header}, #{@next_link_header}"
 
     fake('orders', method: :get, status: 200, api_version: @version, body: load_fixture('orders'), link: link_header)
     orders = ShopifyAPI::Order.all
@@ -229,7 +229,7 @@ class PaginationTest < Test::Unit::TestCase
     @next_link_header = "<https://this-is-my-test-shop.myshopify.com/admin/api/unstable/" \
       "orders.json?page_info=#{@next_page_info}>; rel=\"next\""
 
-    link_header ="#{@previous_link_header}, #{@next_link_header}"
+    link_header = "#{@previous_link_header}, #{@next_link_header}"
 
     fake('orders', method: :get, status: 200, api_version: version, body: load_fixture('orders'), link: link_header)
     orders = ShopifyAPI::Order.all
@@ -286,5 +286,4 @@ class PaginationTest < Test::Unit::TestCase
     next_page = orders.fetch_next_page
     assert_equal(450789469, next_page.first.id)
   end
-
 end

+ 0 - 1
test/product_listing_test.rb

@@ -1,7 +1,6 @@
 require 'test_helper'
 
 class ProductListingTest < Test::Unit::TestCase
-
   def test_get_product_listings
     fake("product_listings", method: :get, status: 201, body: load_fixture('product_listings'))
 

+ 1 - 2
test/recurring_application_charge_test.rb

@@ -1,7 +1,6 @@
 require 'test_helper'
 
 class RecurringApplicationChargeTest < Test::Unit::TestCase
-
   def test_recurring_application_charges_create
     fake(
       "recurring_application_charges", method: :post, status: 201, body: load_fixture('recurring_application_charge')
@@ -17,7 +16,7 @@ class RecurringApplicationChargeTest < Test::Unit::TestCase
       'http://apple.myshopify.com/admin/charges/654381177/confirm_recurring_application_charge?' \
         'signature=BAhpBHkQASc%3D--419fc7424f8c290ac2b21b9004ed223e35b52164',
       charge.confirmation_url
-      )
+    )
   end
 
   def test_get_recurring_application_charges

+ 0 - 1
test/refund_test.rb

@@ -1,7 +1,6 @@
 require 'test_helper'
 
 class RefundTest < Test::Unit::TestCase
-
   test '#create should create a refund' do
     fake("orders/450789469/refunds", method: :post, status: 201, body: load_fixture('refund'))
     refund = ShopifyAPI::Refund.create(

+ 2 - 2
test/resource_feedback_test.rb

@@ -1,6 +1,6 @@
 class ResourceFeedbackTest < Test::Unit::TestCase
   def test_get_resource_feedback
-    body = { resource_feedback: [ { resource_type: 'Shop' } ] }.to_json
+    body = { resource_feedback: [{ resource_type: 'Shop' }] }.to_json
     fake('resource_feedback', method: :get, body: body)
     resource_feedback = ShopifyAPI::ResourceFeedback.find(:all)
     assert_equal('Shop', resource_feedback.first.resource_type)
@@ -14,7 +14,7 @@ class ResourceFeedbackTest < Test::Unit::TestCase
   end
 
   def test_get_resource_feedback_with_product_id
-    body = { resource_feedback: [ { resource_type: 'Product' } ] }.to_json
+    body = { resource_feedback: [{ resource_type: 'Product' }] }.to_json
     fake('products/42/resource_feedback', method: :get, body: body)
     resource_feedback = ShopifyAPI::ResourceFeedback.find(:all, params: { product_id: 42 })
     assert_equal('Product', resource_feedback.first.resource_type)

+ 3 - 4
test/session_test.rb

@@ -2,7 +2,6 @@ require 'test_helper'
 require 'timecop'
 
 class SessionTest < Test::Unit::TestCase
-
   def setup
     super
     ShopifyAPI::Session.secret = 'secret'
@@ -232,7 +231,7 @@ class SessionTest < Test::Unit::TestCase
       token: 'any-token',
       api_version: any_api_version
     )
-    scope = ["write_products","write_customers"]
+    scope = ["write_products", "write_customers"]
     permission_url = session.create_permission_url(scope, "http://my_redirect_uri.com")
     assert_equal(
       "https://localhost.myshopify.com/admin/oauth/authorize?client_id=My_test_key&" \
@@ -332,7 +331,7 @@ class SessionTest < Test::Unit::TestCase
     params = { code: 'any-code', timestamp: Time.now }
     assert(session.request_token(params.merge(hmac: generate_signature(params))))
 
-    assert_equal(({ "foo" => "example" }), session.extra)
+    assert_equal({ "foo" => "example" }, session.extra)
   end
 
   test "expires_in is automatically converted in expires_at" do
@@ -350,7 +349,7 @@ class SessionTest < Test::Unit::TestCase
       assert(session.request_token(params.merge(hmac: generate_signature(params))))
 
       expires_at = Time.now.utc + 86393
-      assert_equal(({ "expires_at" => expires_at.to_i }), session.extra)
+      assert_equal({ "expires_at" => expires_at.to_i }, session.extra)
       assert(session.expires_at.is_a?(Time))
       assert_equal(expires_at.to_i, session.expires_at.to_i)
       assert_equal(86393, session.expires_in)

+ 0 - 2
test/storefront_access_token_test.rb

@@ -1,7 +1,6 @@
 require 'test_helper'
 
 class StorefrontAccessTokenTest < Test::Unit::TestCase
-
   def test_create_storefront_access_token
     fake("storefront_access_tokens", method: :post, body: load_fixture('storefront_access_token'))
     storefront_access_token = ShopifyAPI::StorefrontAccessToken.create(title: 'Test')
@@ -27,5 +26,4 @@ class StorefrontAccessTokenTest < Test::Unit::TestCase
     assert_equal('Test 1', tokens.first.title)
     assert_equal('Test 2', tokens.last.title)
   end
-
 end

+ 0 - 1
test/tax_service_test.rb

@@ -7,6 +7,5 @@ class TaxServiceTest < Test::Unit::TestCase
       '{"tax_service":{"name":"My Tax Service","url":"https://mytaxservice.com"}}',
       WebMock.last_request.body
     )
-
   end
 end

+ 4 - 4
test/test_helper.rb

@@ -93,14 +93,14 @@ module Test
       end
 
       def fake(endpoint, options = {})
-        request_body = options.has_key?(:request_body) ? options.delete(:request_body) : nil
-        body   = options.has_key?(:body) ? options.delete(:body) : load_fixture(endpoint)
+        request_body = options.key?(:request_body) ? options.delete(:request_body) : nil
+        body = options.key?(:body) ? options.delete(:body) : load_fixture(endpoint)
         format = options.delete(:format) || :json
         method = options.delete(:method) || :get
         api_version = options.delete(:api_version) || ShopifyAPI::ApiVersion.find_version('2019-01')
-        extension = ".#{options.delete(:extension)||'json'}" unless options[:extension]==false
+        extension = ".#{options.delete(:extension) || 'json'}" unless options[:extension] == false
         status = options.delete(:status) || 200
-        url = if options.has_key?(:url)
+        url = if options.key?(:url)
           options[:url]
         else
           "https://this-is-my-test-shop.myshopify.com#{api_version.construct_api_path("#{endpoint}#{extension}")}"

+ 0 - 2
test/usage_charge_test.rb

@@ -1,7 +1,6 @@
 require 'test_helper'
 
 class UsageChargeTest < Test::Unit::TestCase
-
   def test_create_usage_charges
     fake("recurring_application_charges/654381177/usage_charges", method: :post, body: load_fixture('usage_charge'))
 
@@ -22,5 +21,4 @@ class UsageChargeTest < Test::Unit::TestCase
 
     assert_equal("1000 emails", usage_charge.description)
   end
-
 end

+ 3 - 3
test/user_test.rb

@@ -3,14 +3,14 @@ require 'test_helper'
 class UserTest < Test::Unit::TestCase
   test 'get should get a user' do
     fake 'users/799407056', method: :get, status: 200, body: load_fixture('user')
-    
+
     user = ShopifyAPI::User.find(799407056)
     assert_equal 799407056, user.id
   end
-  
+
   test 'get should get all users' do
     fake 'users', method: :get, status: 200, body: load_fixture('users')
-    
+
     users = ShopifyAPI::User.all
     assert_equal 799407056, users.first.id
   end