diff --git a/spec/components/admin/budgets/index_component_spec.rb b/spec/components/admin/budgets/index_component_spec.rb index e55a30cc7..09702ad27 100644 --- a/spec/components/admin/budgets/index_component_spec.rb +++ b/spec/components/admin/budgets/index_component_spec.rb @@ -1,8 +1,7 @@ require "rails_helper" -describe Admin::Budgets::IndexComponent, type: :component do +describe Admin::Budgets::IndexComponent, type: :component, controller: Admin::BudgetsController do before do - allow(ViewComponent::Base).to receive(:test_controller).and_return("Admin::BudgetsController") allow_any_instance_of(Admin::BudgetsController).to receive(:valid_filters).and_return(["all"]) allow_any_instance_of(Admin::BudgetsController).to receive(:current_filter).and_return("all") end diff --git a/spec/components/admin/budgets/table_actions_component_spec.rb b/spec/components/admin/budgets/table_actions_component_spec.rb index 692dd3b64..484a7aae7 100644 --- a/spec/components/admin/budgets/table_actions_component_spec.rb +++ b/spec/components/admin/budgets/table_actions_component_spec.rb @@ -1,13 +1,9 @@ require "rails_helper" -describe Admin::Budgets::TableActionsComponent, type: :component do +describe Admin::Budgets::TableActionsComponent, type: :component, controller: Admin::BaseController do let(:budget) { create(:budget) } let(:component) { Admin::Budgets::TableActionsComponent.new(budget) } - before do - allow(ViewComponent::Base).to receive(:test_controller).and_return("Admin::BaseController") - end - it "renders links to edit and delete budget, manage investments and edit groups and manage ballots" do render_inline component diff --git a/spec/components/admin/poll/officers/officers_component_spec.rb b/spec/components/admin/poll/officers/officers_component_spec.rb index dab2dd04e..0dd3aa944 100644 --- a/spec/components/admin/poll/officers/officers_component_spec.rb +++ b/spec/components/admin/poll/officers/officers_component_spec.rb @@ -1,15 +1,11 @@ require "rails_helper" -describe Admin::Poll::Officers::OfficersComponent, type: :component do +describe Admin::Poll::Officers::OfficersComponent, type: :component, controller: Admin::BaseController do let(:existing_officer) { create(:poll_officer, name: "Old officer") } let(:new_officer) { build(:poll_officer, name: "New officer") } let(:officers) { [existing_officer, new_officer] } let(:component) { Admin::Poll::Officers::OfficersComponent.new(officers) } - before do - allow(ViewComponent::Base).to receive(:test_controller).and_return("Admin::BaseController") - end - it "renders as many rows as officers" do render_inline component diff --git a/spec/components/admin/roles/table_actions_component_spec.rb b/spec/components/admin/roles/table_actions_component_spec.rb index a5bb0cd91..5d08409cf 100644 --- a/spec/components/admin/roles/table_actions_component_spec.rb +++ b/spec/components/admin/roles/table_actions_component_spec.rb @@ -1,12 +1,8 @@ require "rails_helper" -describe Admin::Roles::TableActionsComponent, type: :component do +describe Admin::Roles::TableActionsComponent, type: :component, controller: Admin::BaseController do let(:user) { create(:user) } - before do - allow(ViewComponent::Base).to receive(:test_controller).and_return("Admin::BaseController") - end - it "renders link to add the role for new records" do render_inline Admin::Roles::TableActionsComponent.new(user.build_manager) diff --git a/spec/components/admin/table_actions_component_spec.rb b/spec/components/admin/table_actions_component_spec.rb index a643a6da1..c74d9a575 100644 --- a/spec/components/admin/table_actions_component_spec.rb +++ b/spec/components/admin/table_actions_component_spec.rb @@ -1,12 +1,8 @@ require "rails_helper" -describe Admin::TableActionsComponent, type: :component do +describe Admin::TableActionsComponent, type: :component, controller: Admin::BaseController do let(:record) { create(:banner) } - before do - allow(ViewComponent::Base).to receive(:test_controller).and_return("Admin::BaseController") - end - it "renders links to edit and destroy a record by default" do render_inline Admin::TableActionsComponent.new(record) @@ -71,11 +67,7 @@ describe Admin::TableActionsComponent, type: :component do end context "different namespace" do - before do - allow(ViewComponent::Base).to receive(:test_controller).and_return("SDGManagement::BaseController") - end - - it "generates links to different namespaces" do + it "generates links to different namespaces", controller: SDGManagement::BaseController do render_inline Admin::TableActionsComponent.new(create(:sdg_local_target)) expect(page).to have_css "a", count: 2 diff --git a/spec/components/sdg_management/relations/index_component_spec.rb b/spec/components/sdg_management/relations/index_component_spec.rb index e3de6d5c4..6e9eb90ad 100644 --- a/spec/components/sdg_management/relations/index_component_spec.rb +++ b/spec/components/sdg_management/relations/index_component_spec.rb @@ -1,8 +1,7 @@ require "rails_helper" -describe SDGManagement::Relations::IndexComponent, type: :component do +describe SDGManagement::Relations::IndexComponent, type: :component, controller: SDGManagement::RelationsController do before do - allow(ViewComponent::Base).to receive(:test_controller).and_return("SDGManagement::RelationsController") allow_any_instance_of(SDGManagement::RelationsController).to receive(:valid_filters) .and_return(SDGManagement::RelationsController::FILTERS) allow_any_instance_of(SDGManagement::RelationsController).to receive(:current_filter) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2f53625da..394c5d661 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -80,6 +80,10 @@ RSpec.configure do |config| sign_in(create(:administrator).user) end + config.before(:each, :controller, type: :component) do |example| + allow(ViewComponent::Base).to receive(:test_controller).and_return(example.metadata[:controller].to_s) + end + config.before(:each, :show_exceptions) do config = Rails.application.env_config