From f25434691828900904ba8946814205f1a22d7356 Mon Sep 17 00:00:00 2001 From: Rezaan Syed Date: Tue, 23 Feb 2021 16:15:15 -0500 Subject: [PATCH] Throw error on bad input --- lib/shopify_api/session.rb | 15 +++++---------- test/session_test.rb | 17 +++++++++-------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/lib/shopify_api/session.rb b/lib/shopify_api/session.rb index b452148dc..61206a4d0 100644 --- a/lib/shopify_api/session.rb +++ b/lib/shopify_api/session.rb @@ -144,16 +144,6 @@ def api_version=(version) end end - def access_scopes=(access_scopes) - return unless access_scopes - - @access_scopes = begin - ShopifyAPI::ApiAccess.new(access_scopes) - rescue - nil - end - end - def valid? domain.present? && token.present? && api_version.is_a?(ApiVersion) end @@ -191,6 +181,11 @@ def state private + def access_scopes=(access_scopes) + return unless access_scopes + @access_scopes = ShopifyAPI::ApiAccess.new(access_scopes) + end + def parameterize(params) URI.escape(params.collect { |k, v| "#{k}=#{v}" }.join('&')) end diff --git a/test/session_test.rb b/test/session_test.rb index 39a2cbe1b..2608ae180 100644 --- a/test/session_test.rb +++ b/test/session_test.rb @@ -103,14 +103,15 @@ def setup assert_equal "read_products", session.access_scopes.to_s end - test "set access_scopes to nil if bad access scopes are provided" do - session = ShopifyAPI::Session.new( - domain: "testshop.myshopify.com", - token: "any-token", - access_scopes: { bad_input: "bad_input" }, - api_version: any_api_version - ) - assert_nil session.access_scopes + test "session instantiation raises error if bad access scopes are provided" do + assert_raises do + ShopifyAPI::Session.new( + domain: "testshop.myshopify.com", + token: "any-token", + access_scopes: { bad_input: "bad_input" }, + api_version: any_api_version + ) + end end test "raise error if params passed but signature omitted" do