diff --git a/app/components/admin/budgets/table_actions_component.html.erb b/app/components/admin/budgets/table_actions_component.html.erb new file mode 100644 index 000000000..9540163e0 --- /dev/null +++ b/app/components/admin/budgets/table_actions_component.html.erb @@ -0,0 +1,11 @@ +<%= render Admin::TableActionsComponent.new(budget, actions: [:edit], edit_text: t("admin.budgets.index.edit_budget")) do %> + <%= link_to t("admin.budgets.index.budget_investments"), + admin_budget_budget_investments_path(budget_id: budget.id), + class: "button hollow medium" %> + <%= link_to t("admin.budgets.index.edit_groups"), admin_budget_groups_path(budget) %> + <% if budget.poll.present? %> + <%= link_to t("admin.budgets.index.admin_ballots"), admin_poll_booth_assignments_path(budget.poll) %> + <% else %> + <%= link_to_create_budget_poll %> + <% end %> +<% end %> diff --git a/app/components/admin/budgets/table_actions_component.rb b/app/components/admin/budgets/table_actions_component.rb new file mode 100644 index 000000000..75dab1850 --- /dev/null +++ b/app/components/admin/budgets/table_actions_component.rb @@ -0,0 +1,21 @@ +class Admin::Budgets::TableActionsComponent < ApplicationComponent + attr_reader :budget + + def initialize(budget) + @budget = budget + end + + private + + def link_to_create_budget_poll + balloting_phase = budget.phases.find_by(kind: "balloting") + + link_to t("admin.budgets.index.admin_ballots"), + admin_polls_path(poll: { + name: budget.name, + budget_id: budget.id, + starts_at: balloting_phase.starts_at, + ends_at: balloting_phase.ends_at }), + method: :post + end +end diff --git a/app/helpers/budgets_helper.rb b/app/helpers/budgets_helper.rb index d56d6de61..b3a01f7d5 100644 --- a/app/helpers/budgets_helper.rb +++ b/app/helpers/budgets_helper.rb @@ -97,18 +97,6 @@ module BudgetsHelper investment.group.headings.count > 1 end - def link_to_create_budget_poll(budget) - balloting_phase = budget.phases.find_by(kind: "balloting") - - link_to t("admin.budgets.index.admin_ballots"), - admin_polls_path(poll: { - name: budget.name, - budget_id: budget.id, - starts_at: balloting_phase.starts_at, - ends_at: balloting_phase.ends_at }), - method: :post - end - def budget_subnav_items_for(budget) { results: t("budgets.results.link"), diff --git a/app/views/admin/budgets/index.html.erb b/app/views/admin/budgets/index.html.erb index 8f89a02bc..9140973af 100644 --- a/app/views/admin/budgets/index.html.erb +++ b/app/views/admin/budgets/index.html.erb @@ -27,17 +27,7 @@ <%= t("budgets.phase.#{budget.phase}") %> - <%= render Admin::TableActionsComponent.new(budget, actions: [:edit], edit_text: t("admin.budgets.index.edit_budget")) do |actions| %> - <%= actions.link_to t("admin.budgets.index.budget_investments"), - admin_budget_budget_investments_path(budget_id: budget.id), - class: "button hollow medium" %> - <%= actions.link_to t("admin.budgets.index.edit_groups"), admin_budget_groups_path(budget) %> - <% if budget.poll.present? %> - <%= actions.link_to t("admin.budgets.index.admin_ballots"), admin_poll_booth_assignments_path(budget.poll) %> - <% else %> - <%= link_to_create_budget_poll(budget) %> - <% end %> - <% end %> + <%= render Admin::Budgets::TableActionsComponent.new(budget) %> <% end %> diff --git a/spec/components/admin/budgets/table_actions_component_spec.rb b/spec/components/admin/budgets/table_actions_component_spec.rb new file mode 100644 index 000000000..05312853c --- /dev/null +++ b/spec/components/admin/budgets/table_actions_component_spec.rb @@ -0,0 +1,30 @@ +require "rails_helper" + +describe Admin::Budgets::TableActionsComponent, type: :component do + let(:budget) { create(:budget) } + let(:component) { Admin::Budgets::TableActionsComponent.new(budget) } + + it "renders links to edit budget, manage investments and edit groups and manage ballots" do + render_inline component + + expect(page).to have_css "a", count: 4 + expect(page).to have_link "Manage projects", href: /investments/ + expect(page).to have_link "Edit headings groups", href: /groups/ + expect(page).to have_link "Edit budget", href: /edit/ + expect(page).to have_link "Admin ballots" + end + + it "renders link to create new poll for budgets without polls" do + render_inline component + + expect(page).to have_css "a[href*='polls'][data-method='post']", text: "Admin ballots" + end + + it "renders link to manage ballots for budgets with polls" do + budget.poll = create(:poll, budget: budget) + + render_inline component + + expect(page).to have_link "Admin ballots", href: /booth_assignments/ + end +end