Mark relatable as reviewed when updating its relations
Show a notice only once when the user updates the relatable.
This commit is contained in:
@@ -23,7 +23,7 @@ class SDGManagement::RelationsController < SDGManagement::BaseController
|
||||
def update
|
||||
@record.sdg_target_list = params[@record.class.table_name.singularize][:sdg_target_list]
|
||||
|
||||
redirect_to action: :index
|
||||
redirect_to({ action: :index }, notice: update_notice)
|
||||
end
|
||||
|
||||
private
|
||||
@@ -43,4 +43,13 @@ class SDGManagement::RelationsController < SDGManagement::BaseController
|
||||
check_feature_flag(process_name)
|
||||
raise FeatureDisabled, process_name unless Setting["sdg.process.#{process_name}"]
|
||||
end
|
||||
|
||||
def update_notice
|
||||
if @record.sdg_review.present?
|
||||
t("sdg_management.relations.update.notice", relatable: relatable_class.model_name.human)
|
||||
else
|
||||
@record.create_sdg_review!
|
||||
t("sdg_management.relations.update_and_review.notice", relatable: relatable_class.model_name.human)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -39,3 +39,7 @@ en:
|
||||
all: "All"
|
||||
pending_sdg_review: "Pending"
|
||||
sdg_reviewed: "Marked as reviewed"
|
||||
update:
|
||||
notice: "%{relatable} updated successfully"
|
||||
update_and_review:
|
||||
notice: "%{relatable} updated successfully and marked as reviewed"
|
||||
|
||||
@@ -39,3 +39,7 @@ es:
|
||||
all: "Todos"
|
||||
pending_sdg_review: "Pendientes"
|
||||
sdg_reviewed: "Marcados como revisados"
|
||||
update:
|
||||
notice: "%{relatable} actualizado correctamente"
|
||||
update_and_review:
|
||||
notice: "%{relatable} actualizado correctamente y marcado como revisado"
|
||||
|
||||
@@ -190,17 +190,39 @@ describe "SDG Relations", :js do
|
||||
end
|
||||
|
||||
describe "Edit" do
|
||||
scenario "allows changing the targets" do
|
||||
scenario "allows changing the targets and marks the resource as reviewed" do
|
||||
process = create(:legislation_process, title: "SDG process")
|
||||
process.sdg_targets = [SDG::Target["3.3"]]
|
||||
|
||||
visit sdg_management_edit_legislation_process_path(process)
|
||||
fill_in "Targets", with: "1.2, 2.1"
|
||||
fill_in "Targets", with: "1.2, 2.1", fill_options: { clear: :backspace }
|
||||
click_button "Update Process"
|
||||
|
||||
expect(page).to have_content "Process updated successfully and marked as reviewed"
|
||||
|
||||
click_link "Marked as reviewed"
|
||||
|
||||
within("tr", text: "SDG process") do
|
||||
expect(page).to have_css "td", exact_text: "1.2, 2.1"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "does not show the review notice when resource was already reviewed" do
|
||||
debate = create(:sdg_review, relatable: create(:debate, title: "SDG debate")).relatable
|
||||
debate.sdg_targets = [SDG::Target["3.3"]]
|
||||
|
||||
visit sdg_management_edit_debate_path(debate, filter: "sdg_reviewed")
|
||||
fill_in "Targets", with: "1.2, 2.1", fill_options: { clear: :backspace }
|
||||
click_button "Update Debate"
|
||||
|
||||
expect(page).not_to have_content "Debate updated successfully and marked as reviewed"
|
||||
expect(page).to have_content "Debate updated successfully"
|
||||
|
||||
click_link "Marked as reviewed"
|
||||
|
||||
within("tr", text: "SDG debate") do
|
||||
expect(page).to have_css "td", exact_text: "1.2, 2.1"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user