Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add local targets to related list selector #4327

Merged
merged 4 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Rename sdg_related_list to related_sdg_list
To maintain consistency with the current names in the database with fields:
:related_sdg_type and :related_sdg_id
  • Loading branch information
taitus committed Jan 26, 2021
commit 7fa594e3e322084d27cdc6ede4a2be65e3c630e1
4 changes: 2 additions & 2 deletions app/components/sdg/related_list_selector_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="sdg-related-list-selector">
<div class="input-section">
<%= f.label :sdg_related_list %>
<%= f.label :related_sdg_list %>

<ul aria-label="<%= t("sdg.related_list_selector.goal_list") %>">
<% goals.each do |goal| %>
Expand All @@ -10,7 +10,7 @@
<% end %>
</ul>

<%= f.text_field :sdg_related_list,
<%= f.text_field :related_sdg_list,
class: "input",
label: false,
placeholder: t("sdg.related_list_selector.placeholder"),
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/legislation/processes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def allowed_params
:custom_list,
:background_color,
:font_color,
:sdg_related_list,
:related_sdg_list,
translation_params(::Legislation::Process),
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
image_attributes: image_attributes
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/poll/polls_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def load_geozones
end

def poll_params
attributes = [:name, :starts_at, :ends_at, :geozone_restricted, :budget_id, :sdg_related_list,
attributes = [:name, :starts_at, :ends_at, :geozone_restricted, :budget_id, :related_sdg_list,
geozone_ids: [], image_attributes: image_attributes]

params.require(:poll).permit(*attributes, *report_attributes, translation_params(Poll))
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/budgets/investments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def load_investment_votes(investments)

def investment_params
attributes = [:heading_id, :tag_list, :organization_name, :location,
:terms_of_service, :skip_map, :sdg_related_list,
:terms_of_service, :skip_map, :related_sdg_list,
image_attributes: image_attributes,
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
map_location_attributes: [:latitude, :longitude, :zoom]]
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/debates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def disable_recommendations
private

def debate_params
attributes = [:tag_list, :terms_of_service, :sdg_related_list]
attributes = [:tag_list, :terms_of_service, :related_sdg_list]
params.require(:debate).permit(attributes, translation_params(Debate))
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/proposals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def publish

def proposal_params
attributes = [:video_url, :responsible_name, :tag_list, :terms_of_service,
:geozone_id, :skip_map, :sdg_related_list,
:geozone_id, :skip_map, :related_sdg_list,
image_attributes: image_attributes,
documents_attributes: [:id, :title, :attachment, :cached_attachment,
:user_id, :_destroy],
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sdg_management/relations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def edit
end

def update
@record.sdg_related_list = params[@record.class.table_name.singularize][:sdg_related_list]
@record.related_sdg_list = params[@record.class.table_name.singularize][:related_sdg_list]

redirect_to({ action: :index }, notice: update_notice)
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/concerns/sdg/relatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ def sdg_target_list
sdg_targets.sort.map(&:code).join(", ")
end

def sdg_related_list
def related_sdg_list
related_sdgs.sort.map(&:code).join(", ")
taitus marked this conversation as resolved.
Show resolved Hide resolved
end

def sdg_related_list=(codes)
def related_sdg_list=(codes)
target_codes, goal_codes = codes.tr(" ", "").split(",").partition { |code| code.include?(".") }
local_targets_codes, global_targets_codes = target_codes.partition { |code| code.split(".")[2] }
global_targets = global_targets_codes.map { |code| SDG::Target[code] }
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en/activerecord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ en:
attributes:
geozone_id: "Scope of operation"
results_enabled: "Show results"
sdg_related_list: "Sustainable Development Goals and Targets"
related_sdg_list: "Sustainable Development Goals and Targets"
stats_enabled: "Show stats"
advanced_stats_enabled: "Show advanced stats"
name: Name
Expand Down
2 changes: 1 addition & 1 deletion config/locales/es/activerecord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ es:
attributes:
geozone_id: "Ámbito de actuación"
results_enabled: "Mostrar resultados"
sdg_related_list: "Objetivos de Desarrollo Sostenible y Metas"
related_sdg_list: "Objetivos de Desarrollo Sostenible y Metas"
stats_enabled: "Mostrar estadísticas"
advanced_stats_enabled: "Mostrar estadísticas avanzadas"
name: Nombre
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
expect(page).not_to have_css ".sdg-related-list-selector"
end

it "renders sdg_related_list field" do
it "renders related_sdg_list field" do
render_inline component

expect(page).to have_css ".sdg-related-list-selector .input"
Expand Down
26 changes: 13 additions & 13 deletions spec/models/sdg/relatable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@
end
end

describe "#sdg_related_list" do
describe "#related_sdg_list" do
it "orders related list by code" do
relatable.sdg_goals = [SDG::Goal[1], SDG::Goal[3], SDG::Goal[2]]
local_targets = %w[2.2.2 2.2.1 3.1.1].map { |code| create(:sdg_local_target, code: code) }
relatable.sdg_targets = [SDG::Target[2.2], SDG::Target[1.2], SDG::Target[2.1]] + local_targets

expect(relatable.sdg_related_list).to eq "1, 1.2, 2, 2.1, 2.2, 2.2.1, 2.2.2, 3, 3.1.1"
expect(relatable.related_sdg_list).to eq "1, 1.2, 2, 2.1, 2.2, 2.2.1, 2.2.2, 3, 3.1.1"
end
end

Expand All @@ -120,67 +120,67 @@
end
end

describe "#sdg_related_list=" do
describe "#related_sdg_list=" do
it "assigns a single goal" do
relatable.sdg_related_list = "1"
relatable.related_sdg_list = "1"

expect(relatable.reload.sdg_goals).to match_array [SDG::Goal[1]]
end

it "assigns a single target" do
relatable.sdg_related_list = "1.1"
relatable.related_sdg_list = "1.1"

expect(relatable.reload.sdg_goals).to match_array [SDG::Goal[1]]
expect(relatable.reload.sdg_targets).to match_array [SDG::Target[1.1]]
end

it "assigns a single local target" do
relatable.sdg_related_list = local_target.code
relatable.related_sdg_list = local_target.code

expect(relatable.reload.sdg_goals).to match_array [local_target.goal]
expect(relatable.reload.sdg_local_targets).to match_array [local_target]
end

it "assigns multiple targets" do
relatable.sdg_related_list = "1.1,2.3"
relatable.related_sdg_list = "1.1,2.3"

expect(relatable.reload.sdg_goals).to match_array [SDG::Goal[1], SDG::Goal[2]]
expect(relatable.reload.sdg_targets).to match_array [SDG::Target[1.1], SDG::Target[2.3]]
end

it "assigns multiple goals" do
relatable.sdg_related_list = "3,2,1"
relatable.related_sdg_list = "3,2,1"

expect(relatable.reload.sdg_goals).to match_array [SDG::Goal[1], SDG::Goal[2], SDG::Goal[3]]
end

it "assigns multiple local targets" do
relatable.sdg_related_list = "#{local_target.code}, #{another_local_target.code}"
relatable.related_sdg_list = "#{local_target.code}, #{another_local_target.code}"

expect(relatable.reload.sdg_goals).to match_array [local_target.goal, another_local_target.goal]
expect(relatable.reload.sdg_local_targets).to match_array [local_target, another_local_target]
end

it "ignores trailing spaces and spaces between commas" do
relatable.sdg_related_list = " 1.1, 2.3 "
relatable.related_sdg_list = " 1.1, 2.3 "

expect(relatable.reload.sdg_goals).to match_array [SDG::Goal[1], SDG::Goal[2]]
expect(relatable.reload.sdg_targets).to match_array [SDG::Target[1.1], SDG::Target[2.3]]
end

it "assigns goals, targets and local_targets" do
relatable.sdg_related_list = "1.1,3,4,4.1,#{another_local_target.code}"
relatable.related_sdg_list = "1.1,3,4,4.1,#{another_local_target.code}"

expect(relatable.reload.sdg_goals).to match_array [SDG::Goal[1], another_local_target.goal, SDG::Goal[3], SDG::Goal[4]]
expect(relatable.reload.sdg_global_targets).to match_array [SDG::Target[1.1], SDG::Target[4.1]]
expect(relatable.reload.sdg_local_targets).to match_array [another_local_target]
end

it "touches the associated record" do
relatable.sdg_related_list = "1.1, 2.1, 2.2"
relatable.related_sdg_list = "1.1, 2.1, 2.2"

travel(10.seconds) do
relatable.sdg_related_list = "1.1, 2.1, 2.2, 3.1"
relatable.related_sdg_list = "1.1, 2.1, 2.2, 3.1"

expect(relatable.updated_at).to eq Time.current
end
Expand Down