diff --git a/Gemfile b/Gemfile index f594da236..3c2539817 100644 --- a/Gemfile +++ b/Gemfile @@ -59,7 +59,7 @@ gem "translator-text", "~> 0.1.0" gem "turbolinks", "~> 5.2.1" gem "turnout", "~> 2.5.0" gem "uglifier", "~> 4.2.0" -gem "view_component", "~> 2.19.1", require: "view_component/engine" +gem "view_component", "~> 2.28.0", require: "view_component/engine" gem "whenever", "~> 1.0.0", require: false gem "wicked_pdf", "~> 2.1.0" gem "wkhtmltopdf-binary", "~> 0.12.4" diff --git a/Gemfile.lock b/Gemfile.lock index 03b2b568b..92ab81c02 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -661,7 +661,7 @@ GEM uniform_notifier (1.14.2) user_agent_parser (2.6.0) uuidtools (2.1.5) - view_component (2.19.1) + view_component (2.28.0) activesupport (>= 5.0.0, < 7.0) warden (1.2.9) rack (>= 2.0.9) @@ -789,7 +789,7 @@ DEPENDENCIES turbolinks (~> 5.2.1) turnout (~> 2.5.0) uglifier (~> 4.2.0) - view_component (~> 2.19.1) + view_component (~> 2.28.0) web-console (~> 3.7.0) webdrivers (~> 4.4.1) whenever (~> 1.0.0) 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..3af6ef138 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.around(:each, :controller, type: :component) do |example| + with_controller_class(example.metadata[:controller]) { example.run } + end + config.before(:each, :show_exceptions) do config = Rails.application.env_config