Use acts_as_taggable for investment valuation tags
We were manually doing the same thing, generating inconsistent results, since the method `valuation_tag_list` was using the `valuation` context, when actually the expected behavior would be to use the `valuation_tag` context.
This commit is contained in:
@@ -110,7 +110,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def load_tags
|
def load_tags
|
||||||
@tags = Budget::Investment.tags_on(:valuation).order(:name).distinct
|
@tags = Budget::Investment.tags_on(:valuation_tags).order(:name).distinct
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_ballot
|
def load_ballot
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ module BudgetsHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def investment_tags_select_options(budget)
|
def investment_tags_select_options(budget)
|
||||||
tags = budget.investments.tags_on(:valuation).order(:name).pluck(:name)
|
tags = budget.investments.tags_on(:valuation_tags).order(:name).pluck(:name)
|
||||||
tags = tags.concat budget.budget_valuation_tags.split(",") if budget.budget_valuation_tags.present?
|
tags = tags.concat budget.budget_valuation_tags.split(",") if budget.budget_valuation_tags.present?
|
||||||
tags.uniq
|
tags.uniq
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class Budget
|
|||||||
include Mappable
|
include Mappable
|
||||||
include Documentable
|
include Documentable
|
||||||
|
|
||||||
|
acts_as_taggable_on :valuation_tags
|
||||||
acts_as_votable
|
acts_as_votable
|
||||||
acts_as_paranoid column: :hidden_at
|
acts_as_paranoid column: :hidden_at
|
||||||
include ActsAsParanoidAliases
|
include ActsAsParanoidAliases
|
||||||
@@ -383,14 +384,6 @@ class Budget
|
|||||||
self.valuator_groups.map(&:name).compact.join(", ").presence
|
self.valuator_groups.map(&:name).compact.join(", ").presence
|
||||||
end
|
end
|
||||||
|
|
||||||
def valuation_tag_list
|
|
||||||
tag_list_on(:valuation)
|
|
||||||
end
|
|
||||||
|
|
||||||
def valuation_tag_list=(tags)
|
|
||||||
set_tag_list_on(:valuation, tags)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.with_milestone_status_id(status_id)
|
def self.with_milestone_status_id(status_id)
|
||||||
includes(milestones: :translations).select do |investment|
|
includes(milestones: :translations).select do |investment|
|
||||||
investment.milestone_status_id == status_id.to_i
|
investment.milestone_status_id == status_id.to_i
|
||||||
|
|||||||
2
app/models/tagging.rb
Normal file
2
app/models/tagging.rb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
class Tagging < ActsAsTaggableOn::Tagging
|
||||||
|
end
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
<p id="tags">
|
<p id="tags">
|
||||||
<strong><%= t("admin.budget_investments.show.tags") %>:</strong>
|
<strong><%= t("admin.budget_investments.show.tags") %>:</strong>
|
||||||
|
|
||||||
<%= @investment.tags_on(:valuation).pluck(:name).sort.join(", ") %>
|
<%= @investment.valuation_tags.pluck(:name).sort.join(", ") %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p id="assigned_valuator_groups">
|
<p id="assigned_valuator_groups">
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace :consul do
|
|||||||
|
|
||||||
desc "Runs tasks needed to upgrade from 1.0.0 to 1.1.0"
|
desc "Runs tasks needed to upgrade from 1.0.0 to 1.1.0"
|
||||||
task "execute_release_1.1.0_tasks": [
|
task "execute_release_1.1.0_tasks": [
|
||||||
"budgets:set_original_heading_id"
|
"budgets:set_original_heading_id",
|
||||||
|
"migrations:valuation_taggings"
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|||||||
7
lib/tasks/migrations.rake
Normal file
7
lib/tasks/migrations.rake
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace :migrations do
|
||||||
|
desc "Migrates context of valuation taggings"
|
||||||
|
task valuation_taggings: :environment do
|
||||||
|
ApplicationLogger.new.info "Updating valuation taggings context"
|
||||||
|
Tagging.where(context: "valuation").update_all(context: "valuation_tags")
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -19,7 +19,7 @@ FactoryBot.define do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :tagging, class: "ActsAsTaggableOn::Tagging" do
|
factory :tagging do
|
||||||
context { "tags" }
|
context { "tags" }
|
||||||
association :taggable, factory: :proposal
|
association :taggable, factory: :proposal
|
||||||
tag
|
tag
|
||||||
|
|||||||
@@ -510,8 +510,8 @@ describe "Admin budget investments" do
|
|||||||
investment1 = create(:budget_investment, budget: budget, tag_list: "Education")
|
investment1 = create(:budget_investment, budget: budget, tag_list: "Education")
|
||||||
investment2 = create(:budget_investment, budget: budget, tag_list: "Health")
|
investment2 = create(:budget_investment, budget: budget, tag_list: "Health")
|
||||||
|
|
||||||
investment1.set_tag_list_on(:valuation, "Teachers")
|
investment1.set_tag_list_on(:valuation_tags, "Teachers")
|
||||||
investment2.set_tag_list_on(:valuation, "Hospitals")
|
investment2.set_tag_list_on(:valuation_tags, "Hospitals")
|
||||||
|
|
||||||
investment1.save!
|
investment1.save!
|
||||||
investment2.save!
|
investment2.save!
|
||||||
@@ -526,8 +526,8 @@ describe "Admin budget investments" do
|
|||||||
investment1 = create(:budget_investment, budget: budget, tag_list: "Roads")
|
investment1 = create(:budget_investment, budget: budget, tag_list: "Roads")
|
||||||
investment2 = create(:budget_investment, budget: new_budget, tag_list: "Accessibility")
|
investment2 = create(:budget_investment, budget: new_budget, tag_list: "Accessibility")
|
||||||
|
|
||||||
investment1.set_tag_list_on(:valuation, "Roads")
|
investment1.set_tag_list_on(:valuation_tags, "Roads")
|
||||||
investment2.set_tag_list_on(:valuation, "Accessibility")
|
investment2.set_tag_list_on(:valuation_tags, "Accessibility")
|
||||||
|
|
||||||
investment1.save!
|
investment1.save!
|
||||||
investment2.save!
|
investment2.save!
|
||||||
@@ -1192,7 +1192,7 @@ describe "Admin budget investments" do
|
|||||||
|
|
||||||
scenario "Adds existing valuation tags", :js do
|
scenario "Adds existing valuation tags", :js do
|
||||||
budget_investment1 = create(:budget_investment)
|
budget_investment1 = create(:budget_investment)
|
||||||
budget_investment1.set_tag_list_on(:valuation, "Education, Health")
|
budget_investment1.set_tag_list_on(:valuation_tags, "Education, Health")
|
||||||
budget_investment1.save!
|
budget_investment1.save!
|
||||||
|
|
||||||
budget_investment2 = create(:budget_investment)
|
budget_investment2 = create(:budget_investment)
|
||||||
@@ -1230,7 +1230,7 @@ describe "Admin budget investments" do
|
|||||||
|
|
||||||
scenario "Changes valuation and user generated tags" do
|
scenario "Changes valuation and user generated tags" do
|
||||||
budget_investment = create(:budget_investment, tag_list: "Park")
|
budget_investment = create(:budget_investment, tag_list: "Park")
|
||||||
budget_investment.set_tag_list_on(:valuation, "Education")
|
budget_investment.set_tag_list_on(:valuation_tags, "Education")
|
||||||
budget_investment.save!
|
budget_investment.save!
|
||||||
|
|
||||||
visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment)
|
visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment)
|
||||||
@@ -1671,7 +1671,7 @@ describe "Admin budget investments" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Keeps the valuation tags", :js do
|
scenario "Keeps the valuation tags", :js do
|
||||||
investment1.set_tag_list_on(:valuation, %w[Possimpible Truthiness])
|
investment1.set_tag_list_on(:valuation_tags, %w[Possimpible Truthiness])
|
||||||
investment1.save!
|
investment1.save!
|
||||||
|
|
||||||
visit admin_budget_budget_investments_path(budget)
|
visit admin_budget_budget_investments_path(budget)
|
||||||
|
|||||||
@@ -334,7 +334,7 @@ describe "Tags" do
|
|||||||
|
|
||||||
scenario "Valuators do not see user tags" do
|
scenario "Valuators do not see user tags" do
|
||||||
investment = create(:budget_investment, heading: heading, tag_list: "Park")
|
investment = create(:budget_investment, heading: heading, tag_list: "Park")
|
||||||
investment.set_tag_list_on(:valuation, "Education")
|
investment.set_tag_list_on(:valuation_tags, "Education")
|
||||||
investment.save!
|
investment.save!
|
||||||
|
|
||||||
login_as(admin)
|
login_as(admin)
|
||||||
|
|||||||
22
spec/lib/tasks/migrations_spec.rb
Normal file
22
spec/lib/tasks/migrations_spec.rb
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe "Migration tasks" do
|
||||||
|
let(:run_rake_task) do
|
||||||
|
Rake::Task["migrations:valuation_taggings"].reenable
|
||||||
|
Rake.application.invoke_task("migrations:valuation_taggings")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "updates taggings" do
|
||||||
|
valuation_tagging = create(:tagging, context: "valuation")
|
||||||
|
another_valuation_tagging = create(:tagging, context: "valuation")
|
||||||
|
valuation_tags_tagging = create(:tagging, context: "valuation_tags")
|
||||||
|
tags_tagging = create(:tagging)
|
||||||
|
|
||||||
|
run_rake_task
|
||||||
|
|
||||||
|
expect(valuation_tagging.reload.context).to eq "valuation_tags"
|
||||||
|
expect(another_valuation_tagging.reload.context).to eq "valuation_tags"
|
||||||
|
expect(valuation_tags_tagging.reload.context).to eq "valuation_tags"
|
||||||
|
expect(tags_tagging.reload.context).to eq "tags"
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user