Skip to content

Commit

Permalink
Merge pull request #785 from Vizzuality/backend/LET-1383-change-for-s…
Browse files Browse the repository at this point in the history
…ustainable-tourism

LET-1383 [BE] Change tourism-and-recreation for sustainable-tourism
  • Loading branch information
yulia-bel authored Nov 24, 2023
2 parents 6c6b6c3 + 5b5295b commit 946b310
Show file tree
Hide file tree
Showing 31 changed files with 594 additions and 559 deletions.
4 changes: 2 additions & 2 deletions backend/app/models/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ class Category

TYPES = %w[
sustainable-agrosystems
tourism-and-recreation
sustainable-tourism
forestry-and-agroforestry
non-timber-forest-production
human-capital-and-inclusion
].freeze

COLORS = {
"sustainable-agrosystems": "#E7C343",
"tourism-and-recreation": "#4492E5",
"sustainable-tourism": "#4492E5",
"forestry-and-agroforestry": "#E57D57",
"non-timber-forest-production": "#404B9A",
"human-capital-and-inclusion": "#A0616A"
Expand Down
4 changes: 2 additions & 2 deletions backend/config/locales/zu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ zu:
sustainable-agrosystems:
name: Sustainable Agrosystems
description: Sustainable and regenerative agriculture, fishing, and aquaculture as well as manufacturing of derived subproducts.
tourism-and-recreation:
name: Tourism and Recreation
sustainable-tourism:
name: Sustainable Tourism
description: Accommodation, travel, transportation, hospitality, visitor experiences and eco-tourism projects.
forestry-and-agroforestry:
name: Forestry and Agroforestry
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class ChangeTourismAndRecreationToSustainableTourism < ActiveRecord::Migration[7.0]
def up
Project.where(category: "tourism-and-recreation").update_all(category: "sustainable-tourism")

[Investor, ProjectDeveloper].each do |model|
records_to_upsert = model.where("categories @> ?", "{tourism-and-recreation}")
.map do |record|
new_categories = record.categories.map do |category|
category == "tourism-and-recreation" ? "sustainable-tourism" : category
end

record.attributes.merge(categories: new_categories)
end

model.upsert_all(records_to_upsert, unique_by: :id) unless records_to_upsert.empty?
end
end

def down
Project.where(category: "sustainable-tourism").update_all(category: "tourism-and-recreation")

[Investor, ProjectDeveloper].each do |model|
records_to_upsert = model.where("categories @> ?", "{sustainable-tourism}")
.map do |record|
new_categories = record.categories.map do |category|
category == "sustainable-tourism" ? "tourism-and-recreation" : category
end

record.attributes.merge(categories: new_categories)
end

model.upsert_all(records_to_upsert, unique_by: :id) unless records_to_upsert.empty?
end
end
end
2 changes: 1 addition & 1 deletion backend/db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"investor_type": "investor",
"categories": [
"sustainable-agrosystems",
"tourism-and-recreation"
"sustainable-tourism"
],
"ticket_sizes": [
"small-grants"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"investor_type": "investor",
"categories": [
"sustainable-agrosystems",
"tourism-and-recreation"
"sustainable-tourism"
],
"ticket_sizes": [
"small-grants"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"project_developer_type": "ngo",
"categories": [
"sustainable-agrosystems",
"tourism-and-recreation"
"sustainable-tourism"
],
"impacts": [
"biodiversity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"project_developer_type": "ngo",
"categories": [
"sustainable-agrosystems",
"tourism-and-recreation"
"sustainable-tourism"
],
"impacts": [
"biodiversity",
Expand Down
4 changes: 2 additions & 2 deletions backend/spec/fixtures/snapshots/api/v1/enums.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
}
},
{
"id": "tourism-and-recreation",
"id": "sustainable-tourism",
"type": "category",
"attributes": {
"name": "Tourism and Recreation",
"name": "Sustainable Tourism",
"color": "#4492E5",
"description": "Accommodation, travel, transportation, hospitality, visitor experiences and eco-tourism projects."
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"mission": "Yellow Banana",
"project_developer_type": "ngo",
"categories": [
"tourism-and-recreation"
"sustainable-tourism"
],
"impacts": [
"climate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"mission": "Yellow Banana",
"project_developer_type": "ngo",
"categories": [
"tourism-and-recreation"
"sustainable-tourism"
],
"impacts": [
"climate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@
"mission": "Yellow Banana",
"project_developer_type": "ngo",
"categories": [
"tourism-and-recreation"
"sustainable-tourism"
],
"impacts": [
"climate",
Expand Down
6 changes: 3 additions & 3 deletions backend/spec/models/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,21 +361,21 @@
describe "#category_index" do
before do
create(:project, category: "sustainable-agrosystems")
create(:project, category: "tourism-and-recreation")
create(:project, category: "sustainable-tourism")
create(:project, category: "forestry-and-agroforestry")
end

context "sort" do
it "correctly by category name asc" do
q = Project.ransack
q.sorts = "category_localized asc"
expect(q.result.pluck(:category)).to eq(["forestry-and-agroforestry", "sustainable-agrosystems", "tourism-and-recreation"])
expect(q.result.pluck(:category)).to eq(["forestry-and-agroforestry", "sustainable-agrosystems", "sustainable-tourism"])
end

it "correctly by category name desc" do
q = Project.ransack
q.sorts = "category_localized desc"
expect(q.result.pluck(:category)).to eq(["tourism-and-recreation", "sustainable-agrosystems", "forestry-and-agroforestry"])
expect(q.result.pluck(:category)).to eq(["sustainable-tourism", "sustainable-agrosystems", "forestry-and-agroforestry"])
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions backend/spec/requests/api/v1/accounts/investors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
previously_invested: true,
contact_email: "contact@example.com",
contact_phone: "123456789",
categories: ["sustainable-agrosystems", "tourism-and-recreation"],
categories: ["sustainable-agrosystems", "sustainable-tourism"],
impacts: ["biodiversity", "climate"],
ticket_sizes: ["small-grants"],
instrument_types: ["grant"],
Expand Down Expand Up @@ -202,7 +202,7 @@
previously_invested: true,
contact_email: "contact@example.com",
contact_phone: "123456789",
categories: ["sustainable-agrosystems", "tourism-and-recreation"],
categories: ["sustainable-agrosystems", "sustainable-tourism"],
impacts: ["biodiversity", "climate"],
ticket_sizes: ["small-grants"],
instrument_types: ["grant"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
entity_legal_registration_number: "564823570",
mission: "Mission",
contact_email: "contact@example.com",
categories: ["sustainable-agrosystems", "tourism-and-recreation"],
categories: ["sustainable-agrosystems", "sustainable-tourism"],
impacts: ["biodiversity", "climate"],
priority_landscape_ids: [priority_landscape.id],
locale: :en
Expand Down Expand Up @@ -192,7 +192,7 @@
project_developer_type: "ngo",
entity_legal_registration_number: "564823570",
mission: "Mission",
categories: ["sustainable-agrosystems", "tourism-and-recreation"],
categories: ["sustainable-agrosystems", "sustainable-tourism"],
impacts: ["biodiversity", "climate"],
priority_landscape_ids: [priority_landscape.id],
locale: :en
Expand Down
2 changes: 1 addition & 1 deletion backend/spec/requests/api/v1/project_developers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe "API V1 Project Developers", type: :request do
before_all do
@project_developer = create(:project_developer, :with_involved_projects, mission: "Yellow Banana", number_of_projects: 2, categories: ["tourism-and-recreation"])
@project_developer = create(:project_developer, :with_involved_projects, mission: "Yellow Banana", number_of_projects: 2, categories: ["sustainable-tourism"])
@draft_project = create(:project, :draft, project_developer: @project_developer)
create_list(:project_developer, 6, categories: %w[forestry-and-agroforestry non-timber-forest-production])
@unapproved_project_developer = create(:project_developer, account: create(:account, review_status: :unapproved, users: [create(:user)]))
Expand Down
6 changes: 3 additions & 3 deletions backend/spec/services/api/filterer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
let!(:correct_project) do
create :project, category: "sustainable-agrosystems", sdgs: [1, 2], instrument_types: ["loan"], ticket_size: "scaling"
end
let!(:different_category_project) { create :project, category: "tourism-and-recreation" }
let!(:different_category_project) { create :project, category: "sustainable-tourism" }
let!(:different_sdgs_project) { create :project, sdgs: [4, 5] }
let!(:different_instrument_type_project) { create :project, instrument_types: ["grant"] }
let!(:different_ticket_size_project) { create :project, ticket_size: "prototyping" }
Expand Down Expand Up @@ -134,7 +134,7 @@
let!(:correct_project_developer) do
create :project_developer, categories: ["sustainable-agrosystems"], impacts: ["climate"]
end
let!(:different_category_project_developer) { create :project_developer, categories: ["tourism-and-recreation"] }
let!(:different_category_project_developer) { create :project_developer, categories: ["sustainable-tourism"] }
let!(:different_impact_project_developer) { create :project_developer, impacts: ["water"] }

it "returns only correct project developers" do
Expand Down Expand Up @@ -245,7 +245,7 @@
create :investor, categories: ["sustainable-agrosystems"], sdgs: [1, 2], instrument_types: ["loan"],
ticket_sizes: ["scaling"], impacts: ["climate"]
end
let!(:different_category_investor) { create :investor, categories: ["tourism-and-recreation"] }
let!(:different_category_investor) { create :investor, categories: ["sustainable-tourism"] }
let!(:different_sdgs_investor) { create :investor, sdgs: [4, 5] }
let!(:different_instrument_type_investor) { create :investor, instrument_types: ["grant"] }
let!(:different_ticket_size_investor) { create :investor, ticket_sizes: ["prototyping"] }
Expand Down
4 changes: 2 additions & 2 deletions backend/spec/system/backoffice/investors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
fill_in "Instagram", with: "https://instagram.com/new-profile"
fill_in "Facebook", with: "https://facebook.com/new-profile"
fill_in "Twitter", with: "https://twitter.com/new-profile"
check t("enums.category.tourism-and-recreation.name")
check t("enums.category.sustainable-tourism.name")
uncheck t("enums.category.forestry-and-agroforestry.name")
uncheck t("enums.ticket_size.validation.name")
check t("enums.ticket_size.small-grants.name")
Expand Down Expand Up @@ -306,7 +306,7 @@
expect(approved_investor.account.facebook).to eq("https://facebook.com/new-profile")
expect(approved_investor.account.twitter).to eq("https://twitter.com/new-profile")
expect(approved_investor.previously_invested).to eq(false)
expect(approved_investor.categories.sort).to eq(%w[non-timber-forest-production tourism-and-recreation])
expect(approved_investor.categories.sort).to eq(%w[non-timber-forest-production sustainable-tourism])
expect(approved_investor.ticket_sizes.sort).to eq(%w[scaling small-grants])
expect(approved_investor.instrument_types).to eq(%w[loan])
expect(approved_investor.sdgs.sort).to eq([1, 2, 3])
Expand Down
4 changes: 2 additions & 2 deletions backend/spec/system/backoffice/project_developers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@
fill_in "Instagram", with: "https://instagram.com/new-profile"
fill_in "Facebook", with: "https://facebook.com/new-profile"
fill_in "Twitter", with: "https://twitter.com/new-profile"
check t("enums.category.tourism-and-recreation.name")
check t("enums.category.sustainable-tourism.name")
uncheck t("enums.category.forestry-and-agroforestry.name")
check t("enums.impact.community.name")
uncheck t("enums.impact.water.name")
Expand All @@ -267,7 +267,7 @@
expect(approved_pd.account.instagram).to eq("https://instagram.com/new-profile")
expect(approved_pd.account.facebook).to eq("https://facebook.com/new-profile")
expect(approved_pd.account.twitter).to eq("https://twitter.com/new-profile")
expect(approved_pd.categories.sort).to eq(%w[non-timber-forest-production tourism-and-recreation])
expect(approved_pd.categories.sort).to eq(%w[non-timber-forest-production sustainable-tourism])
expect(approved_pd.impacts).to eq(%w[community])
expect(approved_pd.priority_landscape_ids.sort).to eq([priority_landscape.id])
end
Expand Down
Loading

0 comments on commit 946b310

Please sign in to comment.