Extract component for visible to valuators toggling
This commit is contained in:
@@ -42,16 +42,7 @@
|
||||
</td>
|
||||
|
||||
<td data-field="visible_to_valuators">
|
||||
<% if can?(:admin_update, investment) %>
|
||||
<%= form_for [:admin, budget, investment], remote: true, format: :json do |f| %>
|
||||
<%= f.check_box :visible_to_valuators,
|
||||
label: false,
|
||||
class: "js-submit-on-change",
|
||||
id: "budget_investment_visible_to_valuators_#{investment.id}" %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= investment.visible_to_valuators? ? t("shared.yes") : t("shared.no") %>
|
||||
<% end %>
|
||||
<%= render Admin::BudgetInvestments::ToggleVisibleToValuatorsComponent.new(investment) %>
|
||||
</td>
|
||||
|
||||
<td data-field="selected">
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
class Admin::BudgetInvestments::RowComponent < ApplicationComponent
|
||||
attr_reader :investment
|
||||
use_helpers :can?
|
||||
|
||||
def initialize(investment)
|
||||
@investment = investment
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<% if can?(:admin_update, investment) %>
|
||||
<%= form_for [:admin, budget, investment], remote: true, format: :json do |f| %>
|
||||
<%= f.check_box :visible_to_valuators,
|
||||
label: false,
|
||||
class: "js-submit-on-change",
|
||||
id: "budget_investment_visible_to_valuators_#{investment.id}" %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= investment.visible_to_valuators? ? t("shared.yes") : t("shared.no") %>
|
||||
<% end %>
|
||||
@@ -0,0 +1,14 @@
|
||||
class Admin::BudgetInvestments::ToggleVisibleToValuatorsComponent < ApplicationComponent
|
||||
attr_reader :investment
|
||||
use_helpers :can?
|
||||
|
||||
def initialize(investment)
|
||||
@investment = investment
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def budget
|
||||
investment.budget
|
||||
end
|
||||
end
|
||||
@@ -1,9 +0,0 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Admin::BudgetInvestments::RowComponent, :admin do
|
||||
it "uses a JSON request to update visible to valuators" do
|
||||
render_inline Admin::BudgetInvestments::RowComponent.new(create(:budget_investment))
|
||||
|
||||
expect(page).to have_css "form[action$='json'] input[name$='[visible_to_valuators]']"
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Admin::BudgetInvestments::ToggleVisibleToValuatorsComponent, :admin do
|
||||
it "uses a JSON request to update visible to valuators" do
|
||||
render_inline Admin::BudgetInvestments::ToggleVisibleToValuatorsComponent.new(create(:budget_investment))
|
||||
|
||||
expect(page).to have_css "form[action$='json'] input[name$='[visible_to_valuators]']"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user