From 04cd3b460e346ea8546eb873f6f1399faa4dfabe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sun, 3 Nov 2019 12:58:44 +0100 Subject: [PATCH] Audit changes in investment translations Note the user interface could certainly be improved, as it doesn't show which languages have changed. --- .../admin/budget_investment_audits_controller.rb | 2 +- app/models/budget/investment.rb | 5 +++++ app/views/admin/audits/_audits.html.erb | 2 +- config/initializers/routes_hierarchy.rb | 2 +- spec/features/admin/change_log_spec.rb | 8 +++----- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/budget_investment_audits_controller.rb b/app/controllers/admin/budget_investment_audits_controller.rb index ec38952a6..208367220 100644 --- a/app/controllers/admin/budget_investment_audits_controller.rb +++ b/app/controllers/admin/budget_investment_audits_controller.rb @@ -1,7 +1,7 @@ class Admin::BudgetInvestmentAuditsController < Admin::BaseController def show investment = Budget::Investment.find(params[:budget_investment_id]) - @audit = investment.audits.find(params[:id]) + @audit = investment.own_and_associated_audits.find(params[:id]) render "admin/audits/show" end diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index bb94476af..7f0bdb0f5 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -33,6 +33,11 @@ class Budget include Globalizable audited on: [:update, :destroy] + has_associated_audits + translation_class.class_eval do + audited associated_with: :globalized_model, + only: Budget::Investment.translated_attribute_names + end belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :budget_investments belongs_to :heading diff --git a/app/views/admin/audits/_audits.html.erb b/app/views/admin/audits/_audits.html.erb index 672abd93e..dc7bf87b1 100644 --- a/app/views/admin/audits/_audits.html.erb +++ b/app/views/admin/audits/_audits.html.erb @@ -16,7 +16,7 @@ - <% resource.audits.order(:created_at).each do |audit| %> + <% resource.own_and_associated_audits.order(:created_at).each do |audit| %> <% audit.audited_changes.each do |field, (old_value, new_value)| %> <%= audit.id %> diff --git a/config/initializers/routes_hierarchy.rb b/config/initializers/routes_hierarchy.rb index c98f3b123..6223d9e74 100644 --- a/config/initializers/routes_hierarchy.rb +++ b/config/initializers/routes_hierarchy.rb @@ -14,7 +14,7 @@ module ActionDispatch::Routing::UrlFor when "ProgressBar" [*resource_hierarchy_for(resource.progressable), resource] when "Audit" - [*resource_hierarchy_for(resource.auditable), resource] + [*resource_hierarchy_for(resource.associated || resource.auditable), resource] when "Legislation::Annotation" [resource.draft_version.process, resource.draft_version, resource] when "Legislation::Proposal", "Legislation::Question", "Legislation::DraftVersion" diff --git a/spec/features/admin/change_log_spec.rb b/spec/features/admin/change_log_spec.rb index 74636f7c7..963e63554 100644 --- a/spec/features/admin/change_log_spec.rb +++ b/spec/features/admin/change_log_spec.rb @@ -48,11 +48,9 @@ describe "Admin change log" do expect(page).to have_content(budget_investment.heading.name) expect(page).to have_content("There are not changes logged") - budget_investment.update!(title: "test") - - visit admin_budget_budget_investments_path(budget_investment.budget) - - click_link budget_investment.title + click_link "Edit" + fill_in "Title", with: "test" + click_button "Update" expect(page).not_to have_content("There are not changes logged") expect(page).to have_content("Change Log")