diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 1c6b93247c..672e1ce178 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -131,7 +131,7 @@ module Admin response_params = get_stripe_token(params["code"]).params # In case of a problem, need to also issue a request to disconnect the account from Stripe - if !(spree_current_user.owned_enterprises.include? @enterprise) && !(spree_current_user.admin?) + if !(spree_current_user.enterprises.include? @enterprise) && !(spree_current_user.admin?) deauthorize_request_for_stripe_id(response_params["stripe_user_id"]) redirect_to '/unauthorized' and return end diff --git a/spec/controllers/admin/enterprises_controller_spec.rb b/spec/controllers/admin/enterprises_controller_spec.rb index f14f5f6f4b..836f3e0de0 100644 --- a/spec/controllers/admin/enterprises_controller_spec.rb +++ b/spec/controllers/admin/enterprises_controller_spec.rb @@ -147,11 +147,12 @@ module Admin describe "stripe connect" do it "redirects to Stripe" do controller.stub spree_current_user: distributor_manager + Admin::StripeHelper.client.stub id: "abc" spree_get :stripe_connect ['https://connect.stripe.com/oauth/authorize', 'response_type=code', 'state=', - 'client_id='].each{|element| response.location.should match element} + 'client_id=abc'].each{|element| response.location.should match element} end it "returns 500 on callback if the response code is not provided" do @@ -200,7 +201,6 @@ module Admin payload = {enterprise_id: distributor.permalink} params = {state: JWT.encode(payload, Openfoodnetwork::Application.config.secret_token), code: "code"} - expect{spree_get :stripe_connect_callback, params}.to change{StripeAccount.all.length}.by 1 StripeAccount.last.enterprise_id.should eq distributor.id end