Simplify changing controllers in component tests
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Admin::Budgets::IndexComponent, type: :component do
|
describe Admin::Budgets::IndexComponent, type: :component, controller: Admin::BudgetsController do
|
||||||
before 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(:valid_filters).and_return(["all"])
|
||||||
allow_any_instance_of(Admin::BudgetsController).to receive(:current_filter).and_return("all")
|
allow_any_instance_of(Admin::BudgetsController).to receive(:current_filter).and_return("all")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
require "rails_helper"
|
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(:budget) { create(:budget) }
|
||||||
let(:component) { Admin::Budgets::TableActionsComponent.new(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
|
it "renders links to edit and delete budget, manage investments and edit groups and manage ballots" do
|
||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
require "rails_helper"
|
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(:existing_officer) { create(:poll_officer, name: "Old officer") }
|
||||||
let(:new_officer) { build(:poll_officer, name: "New officer") }
|
let(:new_officer) { build(:poll_officer, name: "New officer") }
|
||||||
let(:officers) { [existing_officer, new_officer] }
|
let(:officers) { [existing_officer, new_officer] }
|
||||||
let(:component) { Admin::Poll::Officers::OfficersComponent.new(officers) }
|
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
|
it "renders as many rows as officers" do
|
||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Admin::Roles::TableActionsComponent, type: :component do
|
describe Admin::Roles::TableActionsComponent, type: :component, controller: Admin::BaseController do
|
||||||
let(:user) { create(:user) }
|
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
|
it "renders link to add the role for new records" do
|
||||||
render_inline Admin::Roles::TableActionsComponent.new(user.build_manager)
|
render_inline Admin::Roles::TableActionsComponent.new(user.build_manager)
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Admin::TableActionsComponent, type: :component do
|
describe Admin::TableActionsComponent, type: :component, controller: Admin::BaseController do
|
||||||
let(:record) { create(:banner) }
|
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
|
it "renders links to edit and destroy a record by default" do
|
||||||
render_inline Admin::TableActionsComponent.new(record)
|
render_inline Admin::TableActionsComponent.new(record)
|
||||||
|
|
||||||
@@ -71,11 +67,7 @@ describe Admin::TableActionsComponent, type: :component do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "different namespace" do
|
context "different namespace" do
|
||||||
before do
|
it "generates links to different namespaces", controller: SDGManagement::BaseController do
|
||||||
allow(ViewComponent::Base).to receive(:test_controller).and_return("SDGManagement::BaseController")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "generates links to different namespaces" do
|
|
||||||
render_inline Admin::TableActionsComponent.new(create(:sdg_local_target))
|
render_inline Admin::TableActionsComponent.new(create(:sdg_local_target))
|
||||||
|
|
||||||
expect(page).to have_css "a", count: 2
|
expect(page).to have_css "a", count: 2
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe SDGManagement::Relations::IndexComponent, type: :component do
|
describe SDGManagement::Relations::IndexComponent, type: :component, controller: SDGManagement::RelationsController do
|
||||||
before do
|
before do
|
||||||
allow(ViewComponent::Base).to receive(:test_controller).and_return("SDGManagement::RelationsController")
|
|
||||||
allow_any_instance_of(SDGManagement::RelationsController).to receive(:valid_filters)
|
allow_any_instance_of(SDGManagement::RelationsController).to receive(:valid_filters)
|
||||||
.and_return(SDGManagement::RelationsController::FILTERS)
|
.and_return(SDGManagement::RelationsController::FILTERS)
|
||||||
allow_any_instance_of(SDGManagement::RelationsController).to receive(:current_filter)
|
allow_any_instance_of(SDGManagement::RelationsController).to receive(:current_filter)
|
||||||
|
|||||||
@@ -80,6 +80,10 @@ RSpec.configure do |config|
|
|||||||
sign_in(create(:administrator).user)
|
sign_in(create(:administrator).user)
|
||||||
end
|
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.before(:each, :show_exceptions) do
|
||||||
config = Rails.application.env_config
|
config = Rails.application.env_config
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user