diff --git a/spec/controllers/billing_subscriptions_spec.rb b/spec/controllers/billing_subscriptions_spec.rb index e5c99e13..47088338 100644 --- a/spec/controllers/billing_subscriptions_spec.rb +++ b/spec/controllers/billing_subscriptions_spec.rb @@ -20,7 +20,7 @@ describe BillingSubscriptionsController, type: :controller do end describe 'cancellation' do - include_context :open_to_np_admin, :get, :cancellation, nonprofit_id: :__our_np + include_context :open_to_np_admin, :get, :cancellation, nonprofit_id: :__our_np, without_json_view: true end end end diff --git a/spec/controllers/campaigns/supporters_spec.rb b/spec/controllers/campaigns/supporters_spec.rb index 100d280c..20208be3 100644 --- a/spec/controllers/campaigns/supporters_spec.rb +++ b/spec/controllers/campaigns/supporters_spec.rb @@ -9,7 +9,7 @@ describe Campaigns::SupportersController, type: :controller do include_context :shared_user_context describe 'reject unauthorized' do describe 'index' do - include_context :open_to_campaign_editor, :get, :index, nonprofit_id: :__our_np, campaign_id: :__our_campaign + include_context :open_to_campaign_editor, :get, :index, nonprofit_id: :__our_np, campaign_id: :__our_campaign, without_json_view: true end end end diff --git a/spec/controllers/campaigns_spec.rb b/spec/controllers/campaigns_spec.rb index b95770c5..eb02b8bf 100644 --- a/spec/controllers/campaigns_spec.rb +++ b/spec/controllers/campaigns_spec.rb @@ -30,11 +30,11 @@ describe CampaignsController, type: :controller do end describe 'open to all' do describe 'index' do - include_context :open_to_all, :get, :index, nonprofit_id: :__our_np + include_context :open_to_all, :get, :index, nonprofit_id: :__our_np, without_json_view: true end describe 'show' do - include_context :open_to_all, :get, :show, nonprofit_id: :__our_np, id: :__our_campaign + include_context :open_to_all, :get, :show, nonprofit_id: :__our_np, id: :__our_campaign, without_json_view: true end describe 'activities' do @@ -54,7 +54,7 @@ describe CampaignsController, type: :controller do end describe 'peer_to_peer' do - include_context :open_to_all, :get, :peer_to_peer, nonprofit_id: :__our_np + include_context :open_to_all, :get, :peer_to_peer, nonprofit_id: :__our_np, without_json_view: true end end end diff --git a/spec/controllers/events_spec.rb b/spec/controllers/events_spec.rb index 7ae705c8..e24e7e98 100644 --- a/spec/controllers/events_spec.rb +++ b/spec/controllers/events_spec.rb @@ -20,7 +20,7 @@ describe EventsController, type: :controller do include_context :open_to_event_editor, :delete, :soft_delete, nonprofit_id: :__our_np, event_id: :__our_event end describe 'stats' do - include_context :open_to_event_editor, :get, :stats, nonprofit_id: :__our_np, id: :__our_event + include_context :open_to_event_editor, :get, :stats, nonprofit_id: :__our_np, id: :__our_event, without_json_view: true end describe 'name_and_id' do @@ -30,7 +30,7 @@ describe EventsController, type: :controller do describe 'open to all' do describe 'index' do - include_context :open_to_all, :get, :index, nonprofit_id: :__our_np + include_context :open_to_all, :get, :index, nonprofit_id: :__our_np, without_json_view: true end describe 'listings' do @@ -38,7 +38,7 @@ describe EventsController, type: :controller do end describe 'show' do - include_context :open_to_all, :get, :show, nonprofit_id: :__our_np, id: :__our_event + include_context :open_to_all, :get, :show, nonprofit_id: :__our_np, id: :__our_event, without_json_view: true end describe 'activities' do diff --git a/spec/controllers/maps_spec.rb b/spec/controllers/maps_spec.rb index b70595f8..f2712aa5 100644 --- a/spec/controllers/maps_spec.rb +++ b/spec/controllers/maps_spec.rb @@ -9,21 +9,21 @@ describe MapsController, type: :controller do include_context :shared_user_context describe 'rejects unauthorized users' do describe 'all_supporters' do - include_context :open_to_super_admin, :get, :all_supporters + include_context :open_to_super_admin, :get, :all_supporters, without_json_view: true end describe 'all_npo_supporters' do - include_context :open_to_np_associate, :get, :all_npo_supporters, nonprofit_id: :__our_np + include_context :open_to_np_associate, :get, :all_npo_supporters, nonprofit_id: :__our_np, without_json_view: true end describe 'specific_npo_supporters' do - include_context :open_to_np_associate, :get, :specific_npo_supporters, nonprofit_id: :__our_np + include_context :open_to_np_associate, :get, :specific_npo_supporters, nonprofit_id: :__our_np, without_json_view: true end end describe 'open_to_all' do describe 'all_npos' do - include_context :open_to_all, :get, :all_npos, nonprofit_id: :__our_np + include_context :open_to_all, :get, :all_npos, nonprofit_id: :__our_np, without_json_view: true end end end diff --git a/spec/controllers/nonprofits/bank_accounts_spec.rb b/spec/controllers/nonprofits/bank_accounts_spec.rb index f58bc0ca..76db830c 100644 --- a/spec/controllers/nonprofits/bank_accounts_spec.rb +++ b/spec/controllers/nonprofits/bank_accounts_spec.rb @@ -12,7 +12,7 @@ describe Nonprofits::BankAccountsController, type: :controller do end describe 'confirmation' do - include_context :open_to_np_admin, :get, :confirmation, nonprofit_id: :__our_np + include_context :open_to_np_admin, :get, :confirmation, nonprofit_id: :__our_np, without_json_view: true end describe 'confirm' do @@ -20,7 +20,7 @@ describe Nonprofits::BankAccountsController, type: :controller do end describe 'cancellation' do - include_context :open_to_np_admin, :get, :cancellation, nonprofit_id: :__our_np + include_context :open_to_np_admin, :get, :cancellation, nonprofit_id: :__our_np, without_json_view: true end describe 'cancel' do diff --git a/spec/controllers/nonprofits/button_spec.rb b/spec/controllers/nonprofits/button_spec.rb index 683d2e8e..9d859523 100644 --- a/spec/controllers/nonprofits/button_spec.rb +++ b/spec/controllers/nonprofits/button_spec.rb @@ -12,15 +12,15 @@ describe Nonprofits::ButtonController, type: :controller do end describe 'basic' do - include_context :open_to_registered, :get, :basic, nonprofit_id: :__our_np + include_context :open_to_registered, :get, :basic, nonprofit_id: :__our_np, without_json_view: true end describe 'guided' do - include_context :open_to_registered, :get, :guided, nonprofit_id: :__our_np + include_context :open_to_registered, :get, :guided, nonprofit_id: :__our_np, without_json_view: true end describe 'advanced' do - include_context :open_to_registered, :get, :advanced, nonprofit_id: :__our_np + include_context :open_to_registered, :get, :advanced, nonprofit_id: :__our_np, without_json_view: true end end end diff --git a/spec/controllers/nonprofits/cards_spec.rb b/spec/controllers/nonprofits/cards_spec.rb index f0568692..3aee6a58 100644 --- a/spec/controllers/nonprofits/cards_spec.rb +++ b/spec/controllers/nonprofits/cards_spec.rb @@ -8,7 +8,7 @@ describe Nonprofits::CardsController, type: :controller do include_context :shared_user_context describe 'rejects unauthenticated users' do describe 'show' do - include_context :open_to_np_associate, :get, :edit, nonprofit_id: :__our_np + include_context :open_to_np_associate, :get, :edit, nonprofit_id: :__our_np, without_json_view: true end describe 'create' do diff --git a/spec/controllers/nonprofits/custom_field_masters_spec.rb b/spec/controllers/nonprofits/custom_field_masters_spec.rb index 318f4146..a6bb2afc 100644 --- a/spec/controllers/nonprofits/custom_field_masters_spec.rb +++ b/spec/controllers/nonprofits/custom_field_masters_spec.rb @@ -8,7 +8,7 @@ describe Nonprofits::CustomFieldMastersController, type: :controller do include_context :shared_user_context describe 'rejects unauthenticated users' do describe 'get payments' do - include_context :open_to_np_associate, :get, :index, nonprofit_id: :__our_np + include_context :open_to_np_associate, :get, :index, nonprofit_id: :__our_np, without_json_view: true end describe 'create' do diff --git a/spec/controllers/nonprofits/custom_fields_joins_spec.rb b/spec/controllers/nonprofits/custom_fields_joins_spec.rb index b58f1acf..ebbab658 100644 --- a/spec/controllers/nonprofits/custom_fields_joins_spec.rb +++ b/spec/controllers/nonprofits/custom_fields_joins_spec.rb @@ -8,7 +8,7 @@ describe Nonprofits::CustomFieldJoinsController, type: :controller do include_context :shared_user_context describe 'rejects unauthenticated users' do describe 'index' do - include_context :open_to_np_associate, :get, :index, nonprofit_id: :__our_np, supporter_id: 1 + include_context :open_to_np_associate, :get, :index, nonprofit_id: :__our_np, supporter_id: 1, without_json_view: true end describe 'modify' do diff --git a/spec/controllers/nonprofits/payments_spec.rb b/spec/controllers/nonprofits/payments_spec.rb index 7c533242..dad9a4f4 100644 --- a/spec/controllers/nonprofits/payments_spec.rb +++ b/spec/controllers/nonprofits/payments_spec.rb @@ -8,7 +8,7 @@ describe Nonprofits::PaymentsController, type: :controller do include_context :shared_user_context describe 'rejects unauthenticated users' do describe 'get payments' do - include_context :open_to_np_associate, :get, :index, nonprofit_id: :__our_np + include_context :open_to_np_associate, :get, :index, nonprofit_id: :__our_np, without_json_view: true end describe 'export payments' do @@ -16,7 +16,7 @@ describe Nonprofits::PaymentsController, type: :controller do end describe 'show payments' do - include_context :open_to_np_associate, :get, :show, nonprofit_id: :__our_np, id: '1' + include_context :open_to_np_associate, :get, :show, nonprofit_id: :__our_np, id: '1', without_json_view: true end describe 'update' do diff --git a/spec/controllers/nonprofits/payouts_spec.rb b/spec/controllers/nonprofits/payouts_spec.rb index 8060d17c..1160aeab 100644 --- a/spec/controllers/nonprofits/payouts_spec.rb +++ b/spec/controllers/nonprofits/payouts_spec.rb @@ -12,7 +12,7 @@ describe Nonprofits::PayoutsController, type: :controller do end describe 'index' do - include_context :open_to_np_associate, :get, :index, nonprofit_id: :__our_np + include_context :open_to_np_associate, :get, :index, nonprofit_id: :__our_np, without_json_view: true end describe 'show' do diff --git a/spec/controllers/nonprofits/recurring_donations_spec.rb b/spec/controllers/nonprofits/recurring_donations_spec.rb index e3de65a8..f9300cd3 100644 --- a/spec/controllers/nonprofits/recurring_donations_spec.rb +++ b/spec/controllers/nonprofits/recurring_donations_spec.rb @@ -8,7 +8,7 @@ describe Nonprofits::RecurringDonationsController, type: :controller do include_context :shared_user_context describe 'rejects unauthenticated users' do describe 'index' do - include_context :open_to_np_associate, :get, :index, nonprofit_id: :__our_np + include_context :open_to_np_associate, :get, :index, nonprofit_id: :__our_np, without_json_view: true end describe 'export' do @@ -16,7 +16,7 @@ describe Nonprofits::RecurringDonationsController, type: :controller do end describe 'show' do - include_context :open_to_np_associate, :get, :show, nonprofit_id: :__our_np, id: '1' + include_context :open_to_np_associate, :get, :show, nonprofit_id: :__our_np, id: '1', without_json_view: true end describe 'destroy' do diff --git a/spec/controllers/nonprofits/supporters_spec.rb b/spec/controllers/nonprofits/supporters_spec.rb index 70cd8bfa..6b57d812 100644 --- a/spec/controllers/nonprofits/supporters_spec.rb +++ b/spec/controllers/nonprofits/supporters_spec.rb @@ -8,7 +8,7 @@ describe Nonprofits::SupportersController, type: :controller do include_context :shared_user_context describe 'rejects unauthenticated users' do describe 'index' do - include_context :open_to_np_associate, :get, :index, nonprofit_id: :__our_np + include_context :open_to_np_associate, :get, :index, nonprofit_id: :__our_np, without_json_view: true end describe 'index_metrics' do diff --git a/spec/controllers/nonprofits_spec.rb b/spec/controllers/nonprofits_spec.rb index 8b74c98a..54a92096 100644 --- a/spec/controllers/nonprofits_spec.rb +++ b/spec/controllers/nonprofits_spec.rb @@ -13,7 +13,7 @@ describe NonprofitsController, type: :controller do end describe 'dashboard' do - include_context :open_to_np_associate, :get, :dashboard, id: :__our_np + include_context :open_to_np_associate, :get, :dashboard, id: :__our_np, without_json_view: true end describe 'dashboard_metrics' do @@ -47,7 +47,7 @@ describe NonprofitsController, type: :controller do describe 'open to all' do describe 'show' do - include_context :open_to_all, :get, :show, id: :__our_np + include_context :open_to_all, :get, :show, id: :__our_np, without_json_view: true end describe 'create' do @@ -55,11 +55,11 @@ describe NonprofitsController, type: :controller do end describe 'btn' do - include_context :open_to_all, :get, :btn, id: :__our_np + include_context :open_to_all, :get, :btn, id: :__our_np, without_json_view: true end describe 'supporter_form' do - include_context :open_to_all, :get, :supporter_form, id: :__our_np + include_context :open_to_all, :get, :supporter_form, id: :__our_np, without_json_view: true end describe 'custom_supporter' do @@ -67,7 +67,7 @@ describe NonprofitsController, type: :controller do end describe 'donate' do - include_context :open_to_all, :get, :donate, id: :__our_np + include_context :open_to_all, :get, :donate, id: :__our_np, without_json_view: true end describe 'search' do diff --git a/spec/controllers/profiles_spec.rb b/spec/controllers/profiles_spec.rb index e777f38c..624712f3 100644 --- a/spec/controllers/profiles_spec.rb +++ b/spec/controllers/profiles_spec.rb @@ -13,17 +13,17 @@ describe ProfilesController, type: :controller do end describe 'fundraisers' do - include_context :open_to_profile_owner, :get, :fundraisers, id: :__our_profile + include_context :open_to_profile_owner, :get, :fundraisers, id: :__our_profile, without_json_view: true end describe 'donations_history' do - include_context :open_to_profile_owner, :get, :donations_history, id: :__our_profile + include_context :open_to_profile_owner, :get, :donations_history, id: :__our_profile, without_json_view: true end end describe 'open to all' do describe 'show' do - include_context :open_to_all, :get, :show, id: :__our_np + include_context :open_to_all, :get, :show, id: :__our_np, without_json_view: true end end end diff --git a/spec/controllers/recurring_donations_spec.rb b/spec/controllers/recurring_donations_spec.rb index d6d8e966..48e6e33e 100644 --- a/spec/controllers/recurring_donations_spec.rb +++ b/spec/controllers/recurring_donations_spec.rb @@ -9,7 +9,7 @@ describe RecurringDonationsController, type: :controller do include_context :shared_user_context describe 'open to all (note: edit token is checked inside methods)' do describe 'edit' do - include_context :open_to_all, :get, :edit, nonprofit_id: :__our_np, id: '1' + include_context :open_to_all, :get, :edit, nonprofit_id: :__our_np, id: '1', without_json_view: true end describe 'destroy' do diff --git a/spec/controllers/settings_spec.rb b/spec/controllers/settings_spec.rb index 61f42021..58cf5c74 100644 --- a/spec/controllers/settings_spec.rb +++ b/spec/controllers/settings_spec.rb @@ -9,7 +9,7 @@ describe SettingsController, type: :controller do include_context :shared_user_context describe 'rejects unauthorized users' do describe 'index' do - include_context :open_to_registered, :get, :index, nonprofit_id: :__our_np + include_context :open_to_registered, :get, :index, nonprofit_id: :__our_np, without_json_view: true end end end diff --git a/spec/controllers/super_admins_spec.rb b/spec/controllers/super_admins_spec.rb index 418d551b..f452740c 100644 --- a/spec/controllers/super_admins_spec.rb +++ b/spec/controllers/super_admins_spec.rb @@ -21,7 +21,7 @@ describe SuperAdminsController, type: :controller do end describe 'index' do - include_context :open_to_super_admin, :get, :index + include_context :open_to_super_admin, :get, :index, without_json_view: true end end end diff --git a/spec/controllers/support/shared_user_context.rb b/spec/controllers/support/shared_user_context.rb index 5e2c411d..fda9242b 100644 --- a/spec/controllers/support/shared_user_context.rb +++ b/spec/controllers/support/shared_user_context.rb @@ -85,7 +85,8 @@ RSpec.shared_context :shared_user_context do end def accept(user_to_signin, method, action, *args) - without_json_response = %i[cancellation all_npos edit confirmation peer_to_peer advanced guided basic donations_history fundraisers donate supporter_form btn dashboard stats].include?(action) + # TODO: Extract into method args verification + without_json_response = method_has_json_view?(args) request.accept = 'application/json' unless without_json_response sign_in user_to_signin if user_to_signin # allows us to run the helpers but ignore what the controller action does @@ -114,6 +115,17 @@ RSpec.shared_context :shared_user_context do { params: args.reduce({}, :merge) } end + def method_has_json_view?(*args) + args.collect do |items| + if items.kind_of?(Array) + items.each do |k, v| + return k[:without_json_view] if k.kind_of?(Hash) && k[:without_json_view] + end + end + end + return false + end + def fix_args(*args) replacements = { __our_np: nonprofit.id, diff --git a/spec/controllers/tickets_spec.rb b/spec/controllers/tickets_spec.rb index f8121d81..fd79bb3c 100644 --- a/spec/controllers/tickets_spec.rb +++ b/spec/controllers/tickets_spec.rb @@ -9,7 +9,7 @@ describe TicketsController, type: :controller do include_context :shared_user_context describe 'rejects unauthorized users' do describe 'index' do - include_context :open_to_event_editor, :get, :index, nonprofit_id: :__our_np, event_id: :__our_event + include_context :open_to_event_editor, :get, :index, nonprofit_id: :__our_np, event_id: :__our_event, without_json_view: true end describe 'update' do