From 357b3406ed1d0a531b2b48f2de1e982339726d97 Mon Sep 17 00:00:00 2001 From: Papaya Labs Date: Thu, 13 Sep 2018 15:33:24 -0500 Subject: [PATCH 01/64] Hide Featured section on Home Page if there are no cards --- app/views/welcome/index.html.erb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index e2ae116e1..367392a27 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -20,9 +20,11 @@
-
- <%= render "cards" %> -
+ <% if @cards.any? %> +
+ <%= render "cards" %> +
+ <% end %>
<%= render "processes" %> From f7c10de6274bab6232273dde7ed0713cd5883277 Mon Sep 17 00:00:00 2001 From: Papaya Labs Date: Tue, 18 Sep 2018 15:16:31 -0500 Subject: [PATCH 02/64] Fix indentation and include specs --- app/views/welcome/index.html.erb | 4 ++-- spec/features/home_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 367392a27..b8ee72235 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -20,11 +20,11 @@
- <% if @cards.any? %> + <% if @cards.any? %>
<%= render "cards" %>
- <% end %> + <% end %>
<%= render "processes" %> diff --git a/spec/features/home_spec.rb b/spec/features/home_spec.rb index 7f90f54c1..7f8f1eb46 100644 --- a/spec/features/home_spec.rb +++ b/spec/features/home_spec.rb @@ -143,4 +143,24 @@ feature "Home" do "/html/body/div[@class='wrapper ']/comment()[contains(.,'ie-callout')]" end end + + + scenario 'if there are cards, the "featured" title will render' do + card = create(:widget_card, + title: "Card text", + description: "Card description", + link_text: "Link text", + link_url: "consul.dev" + ) + + visit root_path + + expect(page).to have_css(".title", text: "Featured") + end + + scenario 'if there are no cards, the "featured" title will not render' do + visit root_path + + expect(page).not_to have_css(".title", text: "Featured") + end end From 64adf6dd0eca7c69672d3e46a6b24a5f24eb3069 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Wed, 7 Nov 2018 05:27:12 +0000 Subject: [PATCH 03/64] Bump database_cleaner from 1.6.2 to 1.7.0 Bumps [database_cleaner](https://github.com/DatabaseCleaner/database_cleaner) from 1.6.2 to 1.7.0. - [Release notes](https://github.com/DatabaseCleaner/database_cleaner/releases) - [Changelog](https://github.com/DatabaseCleaner/database_cleaner/blob/master/History.rdoc) - [Commits](https://github.com/DatabaseCleaner/database_cleaner/compare/v1.6.2...v1.7.0) Signed-off-by: dependabot[bot] --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index d5a9c62bf..95bce1187 100644 --- a/Gemfile +++ b/Gemfile @@ -77,7 +77,7 @@ end group :test do gem 'capybara', '~> 2.17.0' gem 'coveralls', '~> 0.8.22', require: false - gem 'database_cleaner', '~> 1.6.1' + gem 'database_cleaner', '~> 1.7.0' gem 'email_spec', '~> 2.1.0' gem 'rspec-rails', '~> 3.8' gem 'selenium-webdriver', '~> 3.10' diff --git a/Gemfile.lock b/Gemfile.lock index 38645a09c..8cb39a70d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -123,7 +123,7 @@ GEM crass (1.0.4) daemons (1.2.6) dalli (2.7.6) - database_cleaner (1.6.2) + database_cleaner (1.7.0) debug_inspector (0.0.3) delayed_job (4.1.5) activesupport (>= 3.0, < 5.3) @@ -512,7 +512,7 @@ DEPENDENCIES coveralls (~> 0.8.22) daemons (~> 1.2.4) dalli (~> 2.7.6) - database_cleaner (~> 1.6.1) + database_cleaner (~> 1.7.0) delayed_job_active_record (~> 4.1.3) devise (~> 3.5.7) devise-async (~> 0.10.2) From 9af8741191412f24e4fe212e10d05d98724e07a4 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Thu, 8 Nov 2018 12:11:38 +0100 Subject: [PATCH 04/64] improve visualization for small resolution --- app/views/admin/homepage/show.html.erb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/views/admin/homepage/show.html.erb b/app/views/admin/homepage/show.html.erb index f3a82b623..b931feff5 100644 --- a/app/views/admin/homepage/show.html.erb +++ b/app/views/admin/homepage/show.html.erb @@ -45,8 +45,6 @@

<%= t("settings.#{@recommendations.key}") %>

-
- <%= render "setting", setting: @recommendations %> -
+ <%= render "setting", setting: @recommendations %>
From 06f07b1139299c0d41e1d20e16c30d6e96e0b338 Mon Sep 17 00:00:00 2001 From: Matheus Miranda Date: Thu, 8 Nov 2018 09:27:03 -0200 Subject: [PATCH 05/64] Add map to sidebar on Heading's page Signed-off-by: Matheus Miranda --- app/assets/stylesheets/layout.scss | 1 + .../admin/budget_headings_controller.rb | 2 +- .../budgets/investments_controller.rb | 24 +- app/models/budget/heading.rb | 4 + .../admin/budgets/_heading_form.html.erb | 25 ++- app/views/budgets/index.html.erb | 2 +- app/views/budgets/investments/_map.html.erb | 8 + .../budgets/investments/_sidebar.html.erb | 1 + config/locales/en/admin.yml | 2 + config/routes/budget.rb | 1 + db/dev_seeds/budgets.rb | 20 +- ...20181109111037_add_location_to_headings.rb | 6 + db/schema.rb | 38 ++-- ...grate_spending_proposals_to_investments.rb | 4 +- spec/factories/budgets.rb | 2 + spec/features/admin/budgets_spec.rb | 2 + spec/features/budgets/investments_spec.rb | 84 ++++++- spec/features/tags/budget_investments_spec.rb | 2 +- spec/models/budget/heading_spec.rb | 210 ++++++++++++++++++ 19 files changed, 397 insertions(+), 41 deletions(-) create mode 100644 app/views/budgets/investments/_map.html.erb create mode 100644 db/migrate/20181109111037_add_location_to_headings.rb diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index d19ccd525..00502081d 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -819,6 +819,7 @@ footer { .categories a, .geozone a, .sidebar-links a, +.sidebar-map a, .tags span { background: #ececec; border-radius: rem-calc(6); diff --git a/app/controllers/admin/budget_headings_controller.rb b/app/controllers/admin/budget_headings_controller.rb index 902f256b5..538e9a76a 100644 --- a/app/controllers/admin/budget_headings_controller.rb +++ b/app/controllers/admin/budget_headings_controller.rb @@ -33,7 +33,7 @@ class Admin::BudgetHeadingsController < Admin::BaseController private def budget_heading_params - params.require(:budget_heading).permit(:name, :price, :population) + params.require(:budget_heading).permit(:name, :price, :population, :latitude, :longitude) end end diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb index ca2bf7dc4..4a9e327d7 100644 --- a/app/controllers/budgets/investments_controller.rb +++ b/app/controllers/budgets/investments_controller.rb @@ -1,5 +1,7 @@ module Budgets class InvestmentsController < ApplicationController + OSM_DISTRICT_LEVEL_ZOOM = 12 + include FeatureFlags include CommentableActions include FlagActions @@ -32,13 +34,17 @@ module Budgets respond_to :html, :js def index - if @budget.finished? - @investments = investments.winners.page(params[:page]).per(10).for_render - else - @investments = investments.page(params[:page]).per(10).for_render - end + all_investments = if @budget.finished? + investments.winners + else + investments + end + + @investments = all_investments.page(params[:page]).per(10).for_render @investment_ids = @investments.pluck(:id) + @investments_map_coordinates = MapLocation.where(investment_id: all_investments).map { |l| l.json_data } + load_investment_votes(@investments) @tag_cloud = tag_cloud end @@ -142,6 +148,7 @@ module Budgets if params[:heading_id].present? @heading = @budget.headings.find(params[:heading_id]) @assigned_heading = @ballot.try(:heading_for_group, @heading.try(:group)) + load_map end end @@ -167,6 +174,13 @@ module Budgets end end + def load_map + @map_location = MapLocation.new + @map_location.zoom = OSM_DISTRICT_LEVEL_ZOOM + @map_location.latitude = @heading.latitude.to_f + @map_location.longitude = @heading.longitude.to_f + end + end end diff --git a/app/models/budget/heading.rb b/app/models/budget/heading.rb index 4818eaeed..2d68ebe51 100644 --- a/app/models/budget/heading.rb +++ b/app/models/budget/heading.rb @@ -11,6 +11,10 @@ class Budget validates :price, presence: true validates :slug, presence: true, format: /\A[a-z0-9\-_]+\z/ validates :population, numericality: { greater_than: 0 }, allow_nil: true + validates :latitude, length: { maximum: 22, minimum: 1 }, presence: true, \ + format: /\A(-|\+)?([1-8]?\d(?:\.\d{1,})?|90(?:\.0{1,6})?)\z/ + validates :longitude, length: { maximum: 22, minimum: 1}, presence: true, \ + format: /\A(-|\+)?((?:1[0-7]|[1-9])?\d(?:\.\d{1,})?|180(?:\.0{1,})?)\z/ delegate :budget, :budget_id, to: :group, allow_nil: true diff --git a/app/views/admin/budgets/_heading_form.html.erb b/app/views/admin/budgets/_heading_form.html.erb index 5c50e21a8..019485cdf 100644 --- a/app/views/admin/budgets/_heading_form.html.erb +++ b/app/views/admin/budgets/_heading_form.html.erb @@ -1,28 +1,25 @@ <%= form_for [:admin, budget, group, heading], remote: true do |f| %> <%= render 'shared/errors', resource: heading %> - <%= f.text_field :name, - label: false, + label: t("admin.budgets.form.heading"), maxlength: 50, placeholder: t("admin.budgets.form.heading") %>
- <%= f.text_field :price, - label: false, + label: t("admin.budgets.form.amount"), maxlength: 8, placeholder: t("admin.budgets.form.amount") %>
-

<%= t("admin.budgets.form.population_help_text") %>

<%= f.text_field :population, - label: false, + label: t("admin.budgets.form.population"), maxlength: 8, placeholder: t("admin.budgets.form.population"), data: {toggle_focus: "population-info"}, @@ -34,6 +31,22 @@
+
+
+ <%= f.text_field :latitude, + label: t("admin.budgets.form.latitude"), + maxlength: 22, + placeholder: "latitude" %> +
+
+
+
+ <%= f.text_field :longitude, + label: t("admin.budgets.form.longitude"), + maxlength: 22, + placeholder: "longitude" %> +
+
<%= f.submit t("admin.budgets.form.save_heading"), class: "button success" %> <% end %> diff --git a/app/views/budgets/index.html.erb b/app/views/budgets/index.html.erb index bc236377f..9b0dd66f9 100644 --- a/app/views/budgets/index.html.erb +++ b/app/views/budgets/index.html.erb @@ -88,7 +88,7 @@
<% unless current_budget.informing? %> -
+

<%= t("budgets.index.map") %>

<%= render_map(nil, "budgets", false, nil, @budgets_coordinates) %>
diff --git a/app/views/budgets/investments/_map.html.erb b/app/views/budgets/investments/_map.html.erb new file mode 100644 index 000000000..af04ef639 --- /dev/null +++ b/app/views/budgets/investments/_map.html.erb @@ -0,0 +1,8 @@ + +
+ + diff --git a/app/views/budgets/investments/_sidebar.html.erb b/app/views/budgets/investments/_sidebar.html.erb index c020c8bbe..f78f3f1fa 100644 --- a/app/views/budgets/investments/_sidebar.html.erb +++ b/app/views/budgets/investments/_sidebar.html.erb @@ -21,6 +21,7 @@

<% end %> +<%= render 'budgets/investments/map' %> <%= render "shared/tag_cloud", taggable: 'budget/investment' %> <%= render 'budgets/investments/categories' %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index e1281fb32..66c9e6451 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -131,6 +131,8 @@ en: population_info: "Budget Heading population field is used for Statistic purposes at the end of the Budget to show for each Heading that represents an area with population what percentage voted. The field is optional so you can leave it empty if it doesn't apply." max_votable_headings: "Maximum number of headings in which a user can vote" current_of_max_headings: "%{current} of %{max}" + latitude: Latitude + longitude: Longitude winners: calculate: Calculate Winner Investments calculated: Winners being calculated, it may take a minute. diff --git a/config/routes/budget.rb b/config/routes/budget.rb index 475d5496a..0159b946a 100644 --- a/config/routes/budget.rb +++ b/config/routes/budget.rb @@ -25,3 +25,4 @@ scope '/participatory_budget' do end get 'investments/:id/json_data', action: :json_data, controller: 'budgets/investments' +get '/budgets/:budget_id/investments/:id/json_data', action: :json_data, controller: 'budgets/investments' diff --git a/db/dev_seeds/budgets.rb b/db/dev_seeds/budgets.rb index 6a44b977c..0c35dcf9b 100644 --- a/db/dev_seeds/budgets.rb +++ b/db/dev_seeds/budgets.rb @@ -40,21 +40,31 @@ section "Creating Budgets" do city_group = budget.groups.create!(name: I18n.t('seeds.budgets.groups.all_city')) city_group.headings.create!(name: I18n.t('seeds.budgets.groups.all_city'), price: 1000000, - population: 1000000) + population: 1000000, + latitude: '-40.123241', + longitude: '25.123249') districts_group = budget.groups.create!(name: I18n.t('seeds.budgets.groups.districts')) districts_group.headings.create!(name: I18n.t('seeds.geozones.north_district'), price: rand(5..10) * 100000, - population: 350000) + population: 350000, + latitude: '15.234521', + longitude: '-15.234234') districts_group.headings.create!(name: I18n.t('seeds.geozones.west_district'), price: rand(5..10) * 100000, - population: 300000) + population: 300000, + latitude: '14.125125', + longitude: '65.123124') districts_group.headings.create!(name: I18n.t('seeds.geozones.east_district'), price: rand(5..10) * 100000, - population: 200000) + population: 200000, + latitude: '23.234234', + longitude: '-47.134124') districts_group.headings.create!(name: I18n.t('seeds.geozones.central_district'), price: rand(5..10) * 100000, - population: 150000) + population: 150000, + latitude: '-26.133213', + longitude: '-10.123231') end end diff --git a/db/migrate/20181109111037_add_location_to_headings.rb b/db/migrate/20181109111037_add_location_to_headings.rb new file mode 100644 index 000000000..973cdf38e --- /dev/null +++ b/db/migrate/20181109111037_add_location_to_headings.rb @@ -0,0 +1,6 @@ +class AddLocationToHeadings < ActiveRecord::Migration + def change + add_column :budget_headings, :latitude, :text + add_column :budget_headings, :longitude, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index ea0b1bbbd..4a3185efd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180924071722) do +ActiveRecord::Schema.define(version: 20181109111037) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -156,6 +156,8 @@ ActiveRecord::Schema.define(version: 20180924071722) do t.integer "price", limit: 8 t.integer "population" t.string "slug" + t.text "latitude" + t.text "longitude" end add_index "budget_headings", ["group_id"], name: "index_budget_headings_on_group_id", using: :btree @@ -580,7 +582,7 @@ ActiveRecord::Schema.define(version: 20180924071722) do t.string "locale", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.text "title" + t.string "title" t.text "changelog" t.text "body" t.text "body_html" @@ -1163,17 +1165,17 @@ ActiveRecord::Schema.define(version: 20180924071722) do add_index "site_customization_images", ["name"], name: "index_site_customization_images_on_name", unique: true, using: :btree create_table "site_customization_page_translations", force: :cascade do |t| - t.integer "site_customization_page_id", null: false - t.string "locale", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "title" - t.string "subtitle" - t.text "content" - end + t.integer "site_customization_page_id", null: false + t.string "locale", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "title" + t.string "subtitle" + t.text "content" + end - add_index "site_customization_page_translations", ["locale"], name: "index_site_customization_page_translations_on_locale", using: :btree - add_index "site_customization_page_translations", ["site_customization_page_id"], name: "index_7fa0f9505738cb31a31f11fb2f4c4531fed7178b", using: :btree + add_index "site_customization_page_translations", ["locale"], name: "index_site_customization_page_translations_on_locale", using: :btree + add_index "site_customization_page_translations", ["site_customization_page_id"], name: "index_7fa0f9505738cb31a31f11fb2f4c4531fed7178b", using: :btree create_table "site_customization_pages", force: :cascade do |t| t.string "slug", null: false @@ -1418,6 +1420,12 @@ ActiveRecord::Schema.define(version: 20180924071722) do add_index "votes", ["votable_id", "votable_type", "vote_scope"], name: "index_votes_on_votable_id_and_votable_type_and_vote_scope", using: :btree add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope", using: :btree + create_table "web_sections", force: :cascade do |t| + t.text "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "widget_card_translations", force: :cascade do |t| t.integer "widget_card_id", null: false t.string "locale", null: false @@ -1450,12 +1458,6 @@ ActiveRecord::Schema.define(version: 20180924071722) do t.datetime "updated_at", null: false end - create_table "web_sections", force: :cascade do |t| - t.text "name" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - add_foreign_key "administrators", "users" add_foreign_key "annotations", "legacy_legislations" add_foreign_key "annotations", "users" diff --git a/lib/migrate_spending_proposals_to_investments.rb b/lib/migrate_spending_proposals_to_investments.rb index 908be8cc5..1f3fe1f39 100644 --- a/lib/migrate_spending_proposals_to_investments.rb +++ b/lib/migrate_spending_proposals_to_investments.rb @@ -8,10 +8,10 @@ class MigrateSpendingProposalsToInvestments if sp.geozone_id.present? group = budget.groups.find_or_create_by!(name: "Barrios") - heading = group.headings.find_or_create_by!(name: sp.geozone.name, price: 10000000) + heading = group.headings.find_or_create_by!(name: sp.geozone.name, price: 10000000, latitude: '40.416775', longitude: '-3.703790') else group = budget.groups.find_or_create_by!(name: "Toda la ciudad") - heading = group.headings.find_or_create_by!(name: "Toda la ciudad", price: 10000000) + heading = group.headings.find_or_create_by!(name: "Toda la ciudad", price: 10000000, latitude: '40.416775', longitude: '-3.703790') end feasibility = case sp.feasible diff --git a/spec/factories/budgets.rb b/spec/factories/budgets.rb index d713302fd..1b633077f 100644 --- a/spec/factories/budgets.rb +++ b/spec/factories/budgets.rb @@ -78,6 +78,8 @@ FactoryBot.define do sequence(:name) { |n| "Heading #{n}" } price 1000000 population 1234 + latitude '-25.172741' + longitude '40.127241' trait :drafting_budget do association :group, factory: [:budget_group, :drafting_budget] diff --git a/spec/features/admin/budgets_spec.rb b/spec/features/admin/budgets_spec.rb index dbad0494d..3ab17c18f 100644 --- a/spec/features/admin/budgets_spec.rb +++ b/spec/features/admin/budgets_spec.rb @@ -276,6 +276,8 @@ feature 'Admin budgets' do fill_in 'budget_heading_name', with: 'District 9 reconstruction' fill_in 'budget_heading_price', with: '6785' fill_in 'budget_heading_population', with: '100500' + fill_in 'budget_heading_latitude', with: '40.416775' + fill_in 'budget_heading_longitude', with: '-3.703790' click_button 'Save heading' end diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index 5a9798133..8ba4a6888 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -1436,10 +1436,10 @@ feature 'Budget Investments' do user = create(:user, :level_two) global_group = create(:budget_group, budget: budget, name: 'Global Group') - global_heading = create(:budget_heading, group: global_group, name: 'Global Heading') + global_heading = create(:budget_heading, group: global_group, name: 'Global Heading', latitude: -43.145412, longitude: 12.009423) carabanchel_heading = create(:budget_heading, group: group, name: "Carabanchel") - new_york_heading = create(:budget_heading, group: group, name: "New York") + new_york_heading = create(:budget_heading, group: group, name: "New York", latitude: -43.223412, longitude: 12.009423) sp1 = create(:budget_investment, :selected, price: 1, heading: global_heading) sp2 = create(:budget_investment, :selected, price: 10, heading: global_heading) @@ -1682,4 +1682,84 @@ feature 'Budget Investments' do expect(Flag.flagged?(user, investment)).not_to be end + context 'sidebar map' do + scenario "Display 6 investment's markers on sidebar map", :js do + investment1 = create(:budget_investment, heading: heading) + investment2 = create(:budget_investment, heading: heading) + investment3 = create(:budget_investment, heading: heading) + investment4 = create(:budget_investment, heading: heading) + investment5 = create(:budget_investment, heading: heading) + investment6 = create(:budget_investment, heading: heading) + + create(:map_location, longitude: 40.1231, latitude: -3.636, investment: investment1) + create(:map_location, longitude: 40.1232, latitude: -3.635, investment: investment2) + create(:map_location, longitude: 40.1233, latitude: -3.634, investment: investment3) + create(:map_location, longitude: 40.1234, latitude: -3.633, investment: investment4) + create(:map_location, longitude: 40.1235, latitude: -3.632, investment: investment5) + create(:map_location, longitude: 40.1236, latitude: -3.631, investment: investment6) + + visit budget_investments_path(budget, heading_id: heading.id) + + within ".map_location" do + expect(page).to have_css(".map-icon", count: 6, visible: false) + end + end + + scenario "Display 2 investment's markers on sidebar map", :js do + investment1 = create(:budget_investment, heading: heading) + investment2 = create(:budget_investment, heading: heading) + + create(:map_location, longitude: 40.1281, latitude: -3.656, investment: investment1) + create(:map_location, longitude: 40.1292, latitude: -3.665, investment: investment2) + + visit budget_investments_path(budget, heading_id: heading.id) + + within ".map_location" do + expect(page).to have_css(".map-icon", count: 2, visible: false) + end + end + + scenario "Display only investment's related to the current heading", :js do + heading_2 = create(:budget_heading, name: "Madrid", group: group) + + investment1 = create(:budget_investment, heading: heading) + investment2 = create(:budget_investment, heading: heading) + investment3 = create(:budget_investment, heading: heading) + investment4 = create(:budget_investment, heading: heading) + investment5 = create(:budget_investment, heading: heading_2) + investment6 = create(:budget_investment, heading: heading_2) + + create(:map_location, longitude: 40.1231, latitude: -3.636, investment: investment1) + create(:map_location, longitude: 40.1232, latitude: -3.685, investment: investment2) + create(:map_location, longitude: 40.1233, latitude: -3.664, investment: investment3) + create(:map_location, longitude: 40.1234, latitude: -3.673, investment: investment4) + create(:map_location, longitude: 40.1235, latitude: -3.672, investment: investment5) + create(:map_location, longitude: 40.1236, latitude: -3.621, investment: investment6) + + visit budget_investments_path(budget, heading_id: heading.id) + + within ".map_location" do + expect(page).to have_css(".map-icon", count: 4, visible: false) + end + end + + scenario "Do not display investment's, since they're all related to other heading", :js do + heading_2 = create(:budget_heading, name: "Madrid", group: group) + + investment1 = create(:budget_investment, heading: heading_2) + investment2 = create(:budget_investment, heading: heading_2) + investment3 = create(:budget_investment, heading: heading_2) + + create(:map_location, longitude: 40.1255, latitude: -3.644, investment: investment1) + create(:map_location, longitude: 40.1258, latitude: -3.637, investment: investment2) + create(:map_location, longitude: 40.1251, latitude: -3.649, investment: investment3) + + visit budget_investments_path(budget, heading_id: heading.id) + + within ".map_location" do + expect(page).to have_css(".map-icon", count: 0, visible: false) + end + end + end + end diff --git a/spec/features/tags/budget_investments_spec.rb b/spec/features/tags/budget_investments_spec.rb index 8719275ef..855ad934f 100644 --- a/spec/features/tags/budget_investments_spec.rb +++ b/spec/features/tags/budget_investments_spec.rb @@ -5,7 +5,7 @@ feature 'Tags' do let(:author) { create(:user, :level_two, username: 'Isabel') } let(:budget) { create(:budget, name: "Big Budget") } let(:group) { create(:budget_group, name: "Health", budget: budget) } - let!(:heading) { create(:budget_heading, name: "More hospitals", group: group) } + let!(:heading) { create(:budget_heading, name: "More hospitals", group: group, latitude: '40.416775', longitude: '-3.703790') } let!(:tag_medio_ambiente) { create(:tag, :category, name: 'Medio Ambiente') } let!(:tag_economia) { create(:tag, :category, name: 'Economía') } let(:admin) { create(:administrator).user } diff --git a/spec/models/budget/heading_spec.rb b/spec/models/budget/heading_spec.rb index b2a09cb55..edd96a8b8 100644 --- a/spec/models/budget/heading_spec.rb +++ b/spec/models/budget/heading_spec.rb @@ -44,6 +44,216 @@ describe Budget::Heading do end end + describe "save latitude" do + it "Doesn't allow latitude == nil" do + expect(build(:budget_heading, group: group, name: 'Latitude is nil', population: 12412512, latitude: nil, longitude: '12.123412')).not_to be_valid + end + + it "Doesn't allow latitude == ''" do + expect(build(:budget_heading, group: group, name: 'Latitude is an empty string', population: 12412512, latitude: '', longitude: '12.123412')).not_to be_valid + end + + it "Doesn't allow latitude < -90" do + heading = create(:budget_heading, group: group, name: 'Latitude is < -90') + + heading.latitude = '-90.127491' + expect(heading).not_to be_valid + + heading.latitude = '-91.723491' + expect(heading).not_to be_valid + + heading.latitude = '-108.127412' + expect(heading).not_to be_valid + + heading.latitude = '-1100.888491' + expect(heading).not_to be_valid + end + + it "Doesn't allow latitude > 90" do + heading = create(:budget_heading, group: group, name: 'Latitude is > 90') + + heading.latitude = '90.127491' + expect(heading).not_to be_valid + + heading.latitude = '97.723491' + expect(heading).not_to be_valid + + heading.latitude = '119.127412' + expect(heading).not_to be_valid + + heading.latitude = '1200.888491' + expect(heading).not_to be_valid + + heading.latitude = '+128.888491' + expect(heading).not_to be_valid + + heading.latitude = '+255.888491' + expect(heading).not_to be_valid + end + + it "Doesn't allow latitude length > 22" do + heading = create(:budget_heading, group: group, name: 'Latitude length is > 22') + + heading.latitude = '10.12749112312418238128213' + expect(heading).not_to be_valid + + heading.latitude = '7.7234941211121231231241' + expect(heading).not_to be_valid + + heading.latitude = '9.1274124111241248688995' + expect(heading).not_to be_valid + + heading.latitude = '+12.8884911231238684445311' + expect(heading).not_to be_valid + end + + it "Allows latitude inside [-90,90] interval" do + heading = create(:budget_heading, group: group, name: 'Latitude is inside [-90,90] interval') + + heading.latitude = '90' + expect(heading).to be_valid + + heading.latitude = '-90' + expect(heading).to be_valid + + heading.latitude = '-90.000' + expect(heading).to be_valid + + heading.latitude = '-90.00000' + expect(heading).to be_valid + + heading.latitude = '90.000' + expect(heading).to be_valid + + heading.latitude = '90.00000' + expect(heading).to be_valid + + heading.latitude = '-80.123451' + expect(heading).to be_valid + + heading.latitude = '+65.888491' + expect(heading).to be_valid + + heading.latitude = '80.144812' + expect(heading).to be_valid + + heading.latitude = '17.417412' + expect(heading).to be_valid + + heading.latitude = '-21.000054' + expect(heading).to be_valid + + heading.latitude = '+80.888491' + expect(heading).to be_valid + end + end + + + describe "save longitude" do + it "Doesn't allow longitude == nil" do + expect(build(:budget_heading, group: group, name: 'Longitude is nil', population: 12412512, latitude: '12.123412', longitude: nil)).not_to be_valid + end + + it "Doesn't allow longitude == ''" do + expect(build(:budget_heading, group: group, name: 'Longitude is an empty string', population: 12412512, latitude: '12.127412', longitude: '')).not_to be_valid + end + + it "Doesn't allow longitude < -180" do + heading = create(:budget_heading, group: group, name: 'Longitude is < -180') + + heading.longitude = '-180.127491' + expect(heading).not_to be_valid + + heading.longitude = '-181.723491' + expect(heading).not_to be_valid + + heading.longitude = '-188.127412' + expect(heading).not_to be_valid + + heading.longitude = '-1100.888491' + expect(heading).not_to be_valid + end + + it "Doesn't allow longitude > 180" do + heading = create(:budget_heading, group: group, name: 'Longitude is > 180') + + heading.longitude = '190.127491' + expect(heading).not_to be_valid + + heading.longitude = '197.723491' + expect(heading).not_to be_valid + + heading.longitude = '+207.723491' + expect(heading).not_to be_valid + + heading.longitude = '300.723491' + expect(heading).not_to be_valid + + heading.longitude = '189.127412' + expect(heading).not_to be_valid + + heading.longitude = '1200.888491' + expect(heading).not_to be_valid + end + + it "Doesn't allow longitude length > 23" do + heading = create(:budget_heading, group: group, name: 'Longitude length is > 23') + + heading.longitude = '50.1274911123124112312418238128213' + expect(heading).not_to be_valid + + heading.longitude = '53.73412349178811231241' + expect(heading).not_to be_valid + + heading.longitude = '+20.1274124124124123121435' + expect(heading).not_to be_valid + + heading.longitude = '10.88849112312312311232123311' + expect(heading).not_to be_valid + end + + it "Allows longitude inside [-180,180] interval" do + heading = create(:budget_heading, group: group, name: 'Longitude is inside [-180,180] interval') + + heading.longitude = '180' + expect(heading).to be_valid + + heading.longitude = '-180' + expect(heading).to be_valid + + heading.longitude = '-180.000' + expect(heading).to be_valid + + heading.longitude = '-180.00000' + expect(heading).to be_valid + + heading.longitude = '180.000' + expect(heading).to be_valid + + heading.longitude = '180.00000' + expect(heading).to be_valid + + heading.longitude = '+75.00000' + expect(heading).to be_valid + + heading.longitude = '+15.023321' + expect(heading).to be_valid + + heading.longitude = '-80.123451' + expect(heading).to be_valid + + heading.longitude = '80.144812' + expect(heading).to be_valid + + heading.longitude = '17.417412' + expect(heading).to be_valid + + heading.longitude = '-21.000054' + expect(heading).to be_valid + end + end + + describe "heading" do it "can be deleted if no budget's investments associated" do heading1 = create(:budget_heading, group: group, name: 'name') From c563f731899643ae28a286ed2d1aef125ec0e53d Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Fri, 23 Nov 2018 18:15:47 +0100 Subject: [PATCH 06/64] create officer assignments in order Make sure we create the Poll::OfficerAssignments in the same order the booth_assignments where previously created. So the spec "Poll::Shift officer_assignments creates and destroy corresponding officer_assignments does" not fail. --- app/models/poll/shift.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/poll/shift.rb b/app/models/poll/shift.rb index e3cfd2280..d9803f237 100644 --- a/app/models/poll/shift.rb +++ b/app/models/poll/shift.rb @@ -24,7 +24,7 @@ class Poll end def create_officer_assignments - booth.booth_assignments.each do |booth_assignment| + booth.booth_assignments.order(:id).each do |booth_assignment| attrs = { officer_id: officer_id, date: date, From eefe09e6919cef2fc26aace7421c908b51ceedb3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Tue, 27 Nov 2018 22:54:32 +0000 Subject: [PATCH 07/64] [Security] Bump rails from 4.2.10 to 4.2.11 Bumps [rails](https://github.com/rails/rails) from 4.2.10 to 4.2.11. **This update includes security fixes.** - [Release notes](https://github.com/rails/rails/releases) - [Commits](https://github.com/rails/rails/compare/v4.2.10...v4.2.11) Signed-off-by: dependabot[bot] --- Gemfile | 2 +- Gemfile.lock | 64 ++++++++++++++++++++++++++-------------------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/Gemfile b/Gemfile index fcf8adac1..f5b7149e9 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -gem 'rails', '4.2.10' +gem 'rails', '4.2.11' gem 'acts-as-taggable-on', '~> 5.0.0' gem 'acts_as_votable', '~> 0.11.1' diff --git a/Gemfile.lock b/Gemfile.lock index 5673a6c29..d2c095a2f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,36 +2,36 @@ GEM remote: https://rubygems.org/ remote: https://rails-assets.org/ specs: - actionmailer (4.2.10) - actionpack (= 4.2.10) - actionview (= 4.2.10) - activejob (= 4.2.10) + actionmailer (4.2.11) + actionpack (= 4.2.11) + actionview (= 4.2.11) + activejob (= 4.2.11) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.10) - actionview (= 4.2.10) - activesupport (= 4.2.10) + actionpack (4.2.11) + actionview (= 4.2.11) + activesupport (= 4.2.11) rack (~> 1.6) rack-test (~> 0.6.2) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.10) - activesupport (= 4.2.10) + actionview (4.2.11) + activesupport (= 4.2.11) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (4.2.10) - activesupport (= 4.2.10) + activejob (4.2.11) + activesupport (= 4.2.11) globalid (>= 0.3.0) - activemodel (4.2.10) - activesupport (= 4.2.10) + activemodel (4.2.11) + activesupport (= 4.2.11) builder (~> 3.1) - activerecord (4.2.10) - activemodel (= 4.2.10) - activesupport (= 4.2.10) + activerecord (4.2.11) + activemodel (= 4.2.11) + activesupport (= 4.2.11) arel (~> 6.0) - activesupport (4.2.10) + activesupport (4.2.11) i18n (~> 0.7) minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) @@ -113,7 +113,7 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.1.1) + concurrent-ruby (1.1.3) coveralls (0.8.22) json (>= 1.8, < 3) simplecov (~> 0.16.1) @@ -247,7 +247,7 @@ GEM loofah (2.2.3) crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.7.0) + mail (2.7.1) mini_mime (>= 0.1.1) mdl (0.5.0) kramdown (~> 1.12, >= 1.12.0) @@ -327,16 +327,16 @@ GEM rack rack-test (0.6.3) rack (>= 1.0) - rails (4.2.10) - actionmailer (= 4.2.10) - actionpack (= 4.2.10) - actionview (= 4.2.10) - activejob (= 4.2.10) - activemodel (= 4.2.10) - activerecord (= 4.2.10) - activesupport (= 4.2.10) + rails (4.2.11) + actionmailer (= 4.2.11) + actionpack (= 4.2.11) + actionview (= 4.2.11) + activejob (= 4.2.11) + activemodel (= 4.2.11) + activerecord (= 4.2.11) + activesupport (= 4.2.11) bundler (>= 1.3.0, < 2.0) - railties (= 4.2.10) + railties (= 4.2.11) sprockets-rails rails-assets-leaflet (1.1.0) rails-assets-markdown-it (8.2.2) @@ -348,9 +348,9 @@ GEM rails-deprecated_sanitizer (>= 1.0.1) rails-html-sanitizer (1.0.4) loofah (~> 2.2, >= 2.2.2) - railties (4.2.10) - actionpack (= 4.2.10) - activesupport (= 4.2.10) + railties (4.2.11) + actionpack (= 4.2.11) + activesupport (= 4.2.11) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rainbow (3.0.0) @@ -548,7 +548,7 @@ DEPENDENCIES pg (~> 0.21.0) pg_search (~> 2.0.1) quiet_assets (~> 1.1.0) - rails (= 4.2.10) + rails (= 4.2.11) rails-assets-leaflet! rails-assets-markdown-it (~> 8.2.1)! redcarpet (~> 3.4.0) From 56df8050dff5ac33ec52efb838229abd03ca073d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 28 Nov 2018 13:11:53 +0100 Subject: [PATCH 08/64] Use `@cards.each` instead of `@cards.find_each` Using `find_each` ignores the scope order we set in `Widget::Card.body`, and since we don't expect to have thousands of cards, using batches isn't necessary. This way we remove the "WARN Scoped order and limit are ignored, it's forced to be batch order and batch size" message we were getting in the specs. --- app/views/welcome/_cards.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/welcome/_cards.html.erb b/app/views/welcome/_cards.html.erb index d579e6e75..8a42521c4 100644 --- a/app/views/welcome/_cards.html.erb +++ b/app/views/welcome/_cards.html.erb @@ -1,7 +1,7 @@

<%= t("welcome.cards.title") %>

- <% @cards.find_each do |card| %> + <% @cards.each do |card| %> <%= render "card", card: card %> <% end %>
From 2f860236a547420daf15c6cc6689e4c0e08c82a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 29 Aug 2018 23:42:09 +0200 Subject: [PATCH 09/64] Reset page driver after every spec using it There were some issues because some specs directly used the driver but didn't reset it after the test. --- spec/features/home_spec.rb | 4 ++-- spec/spec_helper.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/spec/features/home_spec.rb b/spec/features/home_spec.rb index 7f90f54c1..c24066e79 100644 --- a/spec/features/home_spec.rb +++ b/spec/features/home_spec.rb @@ -112,7 +112,7 @@ feature "Home" do end feature 'IE alert' do - scenario 'IE visitors are presented with an alert until they close it' do + scenario 'IE visitors are presented with an alert until they close it', :page_driver do # Selenium API does not include page request/response inspection methods # so we must use Capybara::RackTest driver to set the browser's headers Capybara.current_session.driver.header( @@ -133,7 +133,7 @@ feature "Home" do expect(page.driver.request.cookies['ie_alert_closed']).to eq('true') end - scenario 'non-IE visitors are not bothered with IE alerts' do + scenario 'non-IE visitors are not bothered with IE alerts', :page_driver do visit root_path expect(page).not_to have_xpath(ie_alert_box_xpath, visible: false) expect(page.driver.request.cookies['ie_alert_closed']).to be_nil diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d845190ed..98ffd6f31 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -60,6 +60,10 @@ RSpec.configure do |config| end end + config.after(:each, :page_driver) do + page.driver.reset! + end + config.before(:each, type: :feature) do Capybara.reset_sessions! end From b153f5f902b55abd4e04a85ce3b7259ec9b5fad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 29 Aug 2018 23:45:46 +0200 Subject: [PATCH 10/64] Remove redundant Capybara actions Resetting sessions and driver is automatically done by requiring 'capybara/rspec', as shown by the (lack of) that configuration for RSpec in the Capybara README, manual testing of those settings, and Capybara's code itself. --- spec/spec_helper.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 98ffd6f31..ffa111bfb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -64,10 +64,6 @@ RSpec.configure do |config| page.driver.reset! end - config.before(:each, type: :feature) do - Capybara.reset_sessions! - end - config.before do DatabaseCleaner.start end From dc65c0cdb144ab250fa868586d9ffbd65d0990a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 30 Nov 2018 14:06:33 +0100 Subject: [PATCH 11/64] Fix space differences with Madrid's fork --- spec/spec_helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ffa111bfb..c7b723b4d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,7 +6,7 @@ require 'knapsack_pro' Dir["./spec/models/concerns/*.rb"].each { |f| require f } Dir["./spec/support/**/*.rb"].sort.each { |f| require f } -Dir["./spec/shared/**/*.rb"].sort.each { |f| require f } +Dir["./spec/shared/**/*.rb"].sort.each { |f| require f } RSpec.configure do |config| config.use_transactional_fixtures = false @@ -19,6 +19,7 @@ RSpec.configure do |config| config.include(EmailSpec::Matchers) config.include(CommonActions) config.include(ActiveSupport::Testing::TimeHelpers) + config.before(:suite) do DatabaseCleaner.clean_with :truncation end From 81f516efd778cff9d822e39844432237617eb884 Mon Sep 17 00:00:00 2001 From: Marko Lovic Date: Mon, 16 Jul 2018 13:13:30 +0200 Subject: [PATCH 12/64] Change BudgetInvestmentStatus to Milestone::Status Generalize the BudgetInvestmentStatus model to Milestone::Status so it is not specific to budget investments, but can be used for any entity which has milestones. This is in preparation to make the Milestone model polymorphic and usable by entities other than budget investments. --- ...budget_investment_milestones_controller.rb | 2 +- ...er.rb => milestone_statuses_controller.rb} | 18 ++-- .../budgets/executions_controller.rb | 2 +- app/models/budget/investment/milestone.rb | 2 +- .../investment => milestone}/status.rb | 2 +- app/views/admin/_menu.html.erb | 2 +- .../_form.html.erb | 2 +- .../budget_investment_statuses/edit.html.erb | 5 - .../budget_investment_statuses/new.html.erb | 5 - .../_form.html.erb | 0 .../admin/milestone_statuses/edit.html.erb | 5 + .../index.html.erb | 8 +- .../admin/milestone_statuses/new.html.erb | 5 + config/locales/en/activerecord.yml | 6 +- config/locales/en/admin.yml | 16 ++-- config/locales/es/activerecord.yml | 6 +- config/locales/es/admin.yml | 16 ++-- config/routes/admin.rb | 2 +- db/dev_seeds/budgets.rb | 12 +-- ...vestment_statuses_to_milestone_statuses.rb | 12 +++ db/schema.rb | 10 ++ spec/factories/budgets.rb | 8 +- .../budget_investment_milestones_spec.rb | 2 +- .../admin/budget_investment_statuses_spec.rb | 95 ------------------- .../features/admin/milestone_statuses_spec.rb | 95 +++++++++++++++++++ spec/features/budgets/executions_spec.rb | 10 +- .../investment => milestone}/status_spec.rb | 4 +- 27 files changed, 187 insertions(+), 165 deletions(-) rename app/controllers/admin/{budget_investment_statuses_controller.rb => milestone_statuses_controller.rb} (52%) rename app/models/{budget/investment => milestone}/status.rb (65%) delete mode 100644 app/views/admin/budget_investment_statuses/edit.html.erb delete mode 100644 app/views/admin/budget_investment_statuses/new.html.erb rename app/views/admin/{budget_investment_statuses => milestone_statuses}/_form.html.erb (100%) create mode 100644 app/views/admin/milestone_statuses/edit.html.erb rename app/views/admin/{budget_investment_statuses => milestone_statuses}/index.html.erb (80%) create mode 100644 app/views/admin/milestone_statuses/new.html.erb create mode 100644 db/migrate/20180713103402_change_budget_investment_statuses_to_milestone_statuses.rb delete mode 100644 spec/features/admin/budget_investment_statuses_spec.rb create mode 100644 spec/features/admin/milestone_statuses_spec.rb rename spec/models/{budget/investment => milestone}/status_spec.rb (71%) diff --git a/app/controllers/admin/budget_investment_milestones_controller.rb b/app/controllers/admin/budget_investment_milestones_controller.rb index f63fee025..504f559b1 100644 --- a/app/controllers/admin/budget_investment_milestones_controller.rb +++ b/app/controllers/admin/budget_investment_milestones_controller.rb @@ -70,7 +70,7 @@ class Admin::BudgetInvestmentMilestonesController < Admin::BaseController end def load_statuses - @statuses = Budget::Investment::Status.all + @statuses = Milestone::Status.all end end diff --git a/app/controllers/admin/budget_investment_statuses_controller.rb b/app/controllers/admin/milestone_statuses_controller.rb similarity index 52% rename from app/controllers/admin/budget_investment_statuses_controller.rb rename to app/controllers/admin/milestone_statuses_controller.rb index c3d7a4e16..18c573ab3 100644 --- a/app/controllers/admin/budget_investment_statuses_controller.rb +++ b/app/controllers/admin/milestone_statuses_controller.rb @@ -1,20 +1,20 @@ -class Admin::BudgetInvestmentStatusesController < Admin::BaseController +class Admin::MilestoneStatusesController < Admin::BaseController before_action :load_status, only: [:edit, :update, :destroy] def index - @statuses = Budget::Investment::Status.all + @statuses = Milestone::Status.all end def new - @status = Budget::Investment::Status.new + @status = Milestone::Status.new end def create - @status = Budget::Investment::Status.new(status_params) + @status = Milestone::Status.new(status_params) if @status.save - redirect_to admin_budget_investment_statuses_path, + redirect_to admin_milestone_statuses_path, notice: t('admin.statuses.create.notice') else render :new @@ -26,7 +26,7 @@ class Admin::BudgetInvestmentStatusesController < Admin::BaseController def update if @status.update(status_params) - redirect_to admin_budget_investment_statuses_path, + redirect_to admin_milestone_statuses_path, notice: t('admin.statuses.update.notice') else render :edit @@ -35,17 +35,17 @@ class Admin::BudgetInvestmentStatusesController < Admin::BaseController def destroy @status.destroy - redirect_to admin_budget_investment_statuses_path, + redirect_to admin_milestone_statuses_path, notice: t('admin.statuses.delete.notice') end private def load_status - @status = Budget::Investment::Status.find(params[:id]) + @status = Milestone::Status.find(params[:id]) end def status_params - params.require(:budget_investment_status).permit([:name, :description]) + params.require(:milestone_status).permit([:name, :description]) end end diff --git a/app/controllers/budgets/executions_controller.rb b/app/controllers/budgets/executions_controller.rb index b321c4377..e17763090 100644 --- a/app/controllers/budgets/executions_controller.rb +++ b/app/controllers/budgets/executions_controller.rb @@ -6,7 +6,7 @@ module Budgets def show authorize! :read_executions, @budget - @statuses = ::Budget::Investment::Status.all + @statuses = Milestone::Status.all if params[:status].present? @investments_by_heading = @budget.investments.winners diff --git a/app/models/budget/investment/milestone.rb b/app/models/budget/investment/milestone.rb index f59705ede..fe0e30ea5 100644 --- a/app/models/budget/investment/milestone.rb +++ b/app/models/budget/investment/milestone.rb @@ -11,7 +11,7 @@ class Budget include Globalizable belongs_to :investment - belongs_to :status, class_name: 'Budget::Investment::Status' + belongs_to :status, class_name: 'Milestone::Status' validates :investment, presence: true validates :publication_date, presence: true diff --git a/app/models/budget/investment/status.rb b/app/models/milestone/status.rb similarity index 65% rename from app/models/budget/investment/status.rb rename to app/models/milestone/status.rb index df2b991ba..51b03427d 100644 --- a/app/models/budget/investment/status.rb +++ b/app/models/milestone/status.rb @@ -1,4 +1,4 @@ -class Budget::Investment::Status < ActiveRecord::Base +class Milestone::Status < ActiveRecord::Base acts_as_paranoid column: :hidden_at has_many :milestones diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 911bc0713..902c8261e 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -57,7 +57,7 @@ <% if feature?(:budgets) %>
  • "> + controller_name == "milestone_statuses" %>"> <%= link_to admin_budgets_path do %> <%= t("admin.menu.budgets") %> diff --git a/app/views/admin/budget_investment_milestones/_form.html.erb b/app/views/admin/budget_investment_milestones/_form.html.erb index 8b335e29a..e827be608 100644 --- a/app/views/admin/budget_investment_milestones/_form.html.erb +++ b/app/views/admin/budget_investment_milestones/_form.html.erb @@ -8,7 +8,7 @@ { include_blank: @statuses.any? ? '' : t('admin.milestones.form.no_statuses_defined') }, { disabled: @statuses.blank? } %> <%= link_to t('admin.milestones.form.admin_statuses'), - admin_budget_investment_statuses_path %> + admin_milestone_statuses_path %>
  • <%= f.translatable_fields do |translations_form| %> diff --git a/app/views/admin/budget_investment_statuses/edit.html.erb b/app/views/admin/budget_investment_statuses/edit.html.erb deleted file mode 100644 index e54bfcb08..000000000 --- a/app/views/admin/budget_investment_statuses/edit.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -<%= back_link_to admin_budget_investment_statuses_path %> - -

    <%= t("admin.statuses.edit.title") %>

    - -<%= render '/admin/budget_investment_statuses/form' %> diff --git a/app/views/admin/budget_investment_statuses/new.html.erb b/app/views/admin/budget_investment_statuses/new.html.erb deleted file mode 100644 index 336b41238..000000000 --- a/app/views/admin/budget_investment_statuses/new.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -<%= back_link_to admin_budget_investment_statuses_path %> - -

    <%= t("admin.statuses.new.title") %>

    - -<%= render '/admin/budget_investment_statuses/form' %> diff --git a/app/views/admin/budget_investment_statuses/_form.html.erb b/app/views/admin/milestone_statuses/_form.html.erb similarity index 100% rename from app/views/admin/budget_investment_statuses/_form.html.erb rename to app/views/admin/milestone_statuses/_form.html.erb diff --git a/app/views/admin/milestone_statuses/edit.html.erb b/app/views/admin/milestone_statuses/edit.html.erb new file mode 100644 index 000000000..78df3f184 --- /dev/null +++ b/app/views/admin/milestone_statuses/edit.html.erb @@ -0,0 +1,5 @@ +<%= back_link_to admin_milestone_statuses_path %> + +

    <%= t("admin.statuses.edit.title") %>

    + +<%= render '/admin/milestone_statuses/form' %> diff --git a/app/views/admin/budget_investment_statuses/index.html.erb b/app/views/admin/milestone_statuses/index.html.erb similarity index 80% rename from app/views/admin/budget_investment_statuses/index.html.erb rename to app/views/admin/milestone_statuses/index.html.erb index f41a730cc..45c1e96a9 100644 --- a/app/views/admin/budget_investment_statuses/index.html.erb +++ b/app/views/admin/milestone_statuses/index.html.erb @@ -1,7 +1,7 @@

    <%= t("admin.statuses.index.title") %>

    <%= link_to t("admin.statuses.index.new_status"), - new_admin_budget_investment_status_path, + new_admin_milestone_status_path, class: "button float-right margin-right" %> <% if @statuses.any? %> @@ -15,7 +15,7 @@ <% @statuses.each do |status| %> - + <%= status.name %> @@ -24,10 +24,10 @@ <%= link_to t("admin.statuses.index.edit"), - edit_admin_budget_investment_status_path(status), + edit_admin_milestone_status_path(status), method: :get, class: "button hollow" %> <%= link_to t("admin.statuses.index.delete"), - admin_budget_investment_status_path(status), + admin_milestone_status_path(status), method: :delete, class: "button hollow alert" %> diff --git a/app/views/admin/milestone_statuses/new.html.erb b/app/views/admin/milestone_statuses/new.html.erb new file mode 100644 index 000000000..6ab1f841c --- /dev/null +++ b/app/views/admin/milestone_statuses/new.html.erb @@ -0,0 +1,5 @@ +<%= back_link_to admin_milestone_statuses_path %> + +

    <%= t("admin.statuses.new.title") %>

    + +<%= render '/admin/milestone_statuses/form' %> diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 0ed4a9872..67f746d1d 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -13,9 +13,9 @@ en: budget/investment/milestone: one: "milestone" other: "milestones" - budget/investment/status: - one: "Investment status" - other: "Investment statuses" + milestone/status: + one: "Milestone Status" + other: "Milestone Statuses" comment: one: "Comment" other: "Comments" diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 6ee435c55..666cfec65 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -286,24 +286,24 @@ en: notice: Milestone successfully deleted statuses: index: - title: Investment statuses - empty_statuses: There are no investment statuses created - new_status: Create new investment status + title: Milestone statuses + empty_statuses: There are no milestone statuses created + new_status: Create new milestone status table_name: Name table_description: Description table_actions: Actions delete: Delete edit: Edit edit: - title: Edit investment status + title: Edit milestone status update: - notice: Investment status updated successfully + notice: Milestone status updated successfully new: - title: Create investment status + title: Create milestone status create: - notice: Investment status created successfully + notice: Milestone status created successfully delete: - notice: Investment status deleted successfully + notice: Milestone status deleted successfully comments: index: filter: Filter diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index 15bbb35bf..43e10a41e 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -13,9 +13,9 @@ es: budget/investment/milestone: one: "hito" other: "hitos" - budget/investment/status: - one: "Estado del proyecto" - other: "Estados del proyecto" + milestone/status: + one: "Estado de seguimiento" + other: "Estados de seguimiento" comment: one: "Comentario" other: "Comentarios" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index b16f85bd8..f5a82ff58 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -286,24 +286,24 @@ es: notice: Hito borrado correctamente statuses: index: - title: Estados de proyectos - empty_statuses: Aún no se ha creado ningún estado de proyecto - new_status: Crear nuevo estado de proyecto + title: Estados de seguimiento + empty_statuses: Aún no se ha creado ningún estado de seguimiento + new_status: Crear nuevo estado de seguimiento table_name: Nombre table_description: Descripción table_actions: Acciones delete: Borrar edit: Editar edit: - title: Editar estado de proyecto + title: Editar estado de seguimiento update: - notice: Estado de proyecto editado correctamente + notice: Estado de seguimiento editado correctamente new: - title: Crear estado de proyecto + title: Crear estado de seguimiento create: - notice: Estado de proyecto creado correctamente + notice: Estado de seguimiento creado correctamente delete: - notice: Estado de proyecto eliminado correctamente + notice: Estado de seguimiento eliminado correctamente comments: index: filter: Filtro diff --git a/config/routes/admin.rb b/config/routes/admin.rb index e65ec688a..a1374751e 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -69,7 +69,7 @@ namespace :admin do resources :budget_phases, only: [:edit, :update] end - resources :budget_investment_statuses, only: [:index, :new, :create, :update, :edit, :destroy] + resources :milestone_statuses, only: [:index, :new, :create, :update, :edit, :destroy] resources :signature_sheets, only: [:index, :new, :create, :show] diff --git a/db/dev_seeds/budgets.rb b/db/dev_seeds/budgets.rb index 6a44b977c..685392900 100644 --- a/db/dev_seeds/budgets.rb +++ b/db/dev_seeds/budgets.rb @@ -139,16 +139,16 @@ section "Creating Valuation Assignments" do end end -section "Creating default Investment Milestone Statuses" do - Budget::Investment::Status.create(name: I18n.t('seeds.budgets.statuses.studying_project')) - Budget::Investment::Status.create(name: I18n.t('seeds.budgets.statuses.bidding')) - Budget::Investment::Status.create(name: I18n.t('seeds.budgets.statuses.executing_project')) - Budget::Investment::Status.create(name: I18n.t('seeds.budgets.statuses.executed')) +section "Creating default Milestone Statuses" do + Milestone::Status.create(name: I18n.t('seeds.budgets.statuses.studying_project')) + Milestone::Status.create(name: I18n.t('seeds.budgets.statuses.bidding')) + Milestone::Status.create(name: I18n.t('seeds.budgets.statuses.executing_project')) + Milestone::Status.create(name: I18n.t('seeds.budgets.statuses.executed')) end section "Creating investment milestones" do Budget::Investment.find_each do |investment| - milestone = Budget::Investment::Milestone.new(investment_id: investment.id, publication_date: Date.tomorrow) + milestone = Budget::Investment::Milestone.new(investment_id: investment.id, publication_date: Date.tomorrow, status_id: Milestone::Status.all.sample) I18n.available_locales.map do |locale| Globalize.with_locale(locale) do milestone.description = "Description for locale #{locale}" diff --git a/db/migrate/20180713103402_change_budget_investment_statuses_to_milestone_statuses.rb b/db/migrate/20180713103402_change_budget_investment_statuses_to_milestone_statuses.rb new file mode 100644 index 000000000..05deae5a7 --- /dev/null +++ b/db/migrate/20180713103402_change_budget_investment_statuses_to_milestone_statuses.rb @@ -0,0 +1,12 @@ +class ChangeBudgetInvestmentStatusesToMilestoneStatuses < ActiveRecord::Migration + def change + create_table :milestone_statuses do |t| + t.string :name + t.text :description + t.datetime :hidden_at, index: true + + t.timestamps null: false + end + end +end + diff --git a/db/schema.rb b/db/schema.rb index d30f35716..b2079bfa0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -781,6 +781,16 @@ ActiveRecord::Schema.define(version: 20181016204729) do add_index "map_locations", ["investment_id"], name: "index_map_locations_on_investment_id", using: :btree add_index "map_locations", ["proposal_id"], name: "index_map_locations_on_proposal_id", using: :btree + create_table "milestone_statuses", force: :cascade do |t| + t.string "name" + t.text "description" + t.datetime "hidden_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "milestone_statuses", ["hidden_at"], name: "index_milestone_statuses_on_hidden_at", using: :btree + create_table "moderators", force: :cascade do |t| t.integer "user_id" end diff --git a/spec/factories/budgets.rb b/spec/factories/budgets.rb index d713302fd..eda20c8c5 100644 --- a/spec/factories/budgets.rb +++ b/spec/factories/budgets.rb @@ -193,14 +193,14 @@ FactoryBot.define do reason "unfeasible" end - factory :budget_investment_status, class: 'Budget::Investment::Status' do - sequence(:name) { |n| "Budget investment status #{n} name" } - sequence(:description) { |n| "Budget investment status #{n} description" } + factory :milestone_status, class: 'Milestone::Status' do + sequence(:name) { |n| "Milestone status #{n} name" } + sequence(:description) { |n| "Milestone status #{n} description" } end factory :budget_investment_milestone, class: 'Budget::Investment::Milestone' do association :investment, factory: :budget_investment - association :status, factory: :budget_investment_status + association :status, factory: :milestone_status sequence(:title) { |n| "Budget investment milestone #{n} title" } description 'Milestone description' publication_date { Date.current } diff --git a/spec/features/admin/budget_investment_milestones_spec.rb b/spec/features/admin/budget_investment_milestones_spec.rb index 35ed69089..2f1241a19 100644 --- a/spec/features/admin/budget_investment_milestones_spec.rb +++ b/spec/features/admin/budget_investment_milestones_spec.rb @@ -41,7 +41,7 @@ feature 'Admin budget investment milestones' do context "New" do scenario "Add milestone" do - status = create(:budget_investment_status) + status = create(:milestone_status) visit admin_budget_budget_investment_path(@investment.budget, @investment) click_link 'Create new milestone' diff --git a/spec/features/admin/budget_investment_statuses_spec.rb b/spec/features/admin/budget_investment_statuses_spec.rb deleted file mode 100644 index 196dc2eee..000000000 --- a/spec/features/admin/budget_investment_statuses_spec.rb +++ /dev/null @@ -1,95 +0,0 @@ -require 'rails_helper' - -feature 'Admin budget investment statuses' do - - background do - admin = create(:administrator) - login_as(admin.user) - end - - context "Index" do - scenario 'Displaying only not hidden statuses' do - status1 = create(:budget_investment_status) - status2 = create(:budget_investment_status) - - status1.destroy - - visit admin_budget_investment_statuses_path - - expect(page).not_to have_content status1.name - expect(page).not_to have_content status1.description - - expect(page).to have_content status2.name - expect(page).to have_content status2.description - end - - scenario 'Displaying no statuses text' do - visit admin_budget_investment_statuses_path - - expect(page).to have_content("There are no investment statuses created") - end - end - - context "New" do - scenario "Create status" do - visit admin_budget_investment_statuses_path - - click_link 'Create new investment status' - - fill_in 'budget_investment_status_name', with: 'New status name' - fill_in 'budget_investment_status_description', with: 'This status description' - click_button 'Create Investment status' - - expect(page).to have_content 'New status name' - expect(page).to have_content 'This status description' - end - - scenario "Show validation errors in status form" do - visit admin_budget_investment_statuses_path - - click_link 'Create new investment status' - - fill_in 'budget_investment_status_description', with: 'This status description' - click_button 'Create Investment status' - - within "#new_budget_investment_status" do - expect(page).to have_content "can't be blank", count: 1 - end - end - end - - context "Edit" do - scenario "Change name and description" do - status = create(:budget_investment_status) - - visit admin_budget_investment_statuses_path - - within("#budget_investment_status_#{status.id}") do - click_link "Edit" - end - - fill_in 'budget_investment_status_name', with: 'Other status name' - fill_in 'budget_investment_status_description', with: 'Other status description' - click_button 'Update Investment status' - - expect(page).to have_content 'Other status name' - expect(page).to have_content 'Other status description' - end - end - - context "Delete" do - scenario "Hides status" do - status = create(:budget_investment_status) - - visit admin_budget_investment_statuses_path - - within("#budget_investment_status_#{status.id}") do - click_link "Delete" - end - - expect(page).not_to have_content status.name - expect(page).not_to have_content status.description - end - end - -end diff --git a/spec/features/admin/milestone_statuses_spec.rb b/spec/features/admin/milestone_statuses_spec.rb new file mode 100644 index 000000000..e928ce453 --- /dev/null +++ b/spec/features/admin/milestone_statuses_spec.rb @@ -0,0 +1,95 @@ +require 'rails_helper' + +feature 'Admin milestone statuses' do + + background do + admin = create(:administrator) + login_as(admin.user) + end + + context "Index" do + scenario 'Displaying only not hidden statuses' do + status1 = create(:milestone_status) + status2 = create(:milestone_status) + + status1.destroy + + visit admin_milestone_statuses_path + + expect(page).not_to have_content status1.name + expect(page).not_to have_content status1.description + + expect(page).to have_content status2.name + expect(page).to have_content status2.description + end + + scenario 'Displaying no statuses text' do + visit admin_milestone_statuses_path + + expect(page).to have_content("There are no milestone statuses created") + end + end + + context "New" do + scenario "Create status" do + visit admin_milestone_statuses_path + + click_link 'Create new milestone status' + + fill_in 'milestone_status_name', with: 'New status name' + fill_in 'milestone_status_description', with: 'This status description' + click_button 'Create Milestone Status' + + expect(page).to have_content 'New status name' + expect(page).to have_content 'This status description' + end + + scenario "Show validation errors in status form" do + visit admin_milestone_statuses_path + + click_link 'Create new milestone status' + + fill_in 'milestone_status_description', with: 'This status description' + click_button 'Create Milestone Status' + + within "#new_milestone_status" do + expect(page).to have_content "can't be blank", count: 1 + end + end + end + + context "Edit" do + scenario "Change name and description" do + status = create(:milestone_status) + + visit admin_milestone_statuses_path + + within("#milestone_status_#{status.id}") do + click_link "Edit" + end + + fill_in 'milestone_status_name', with: 'Other status name' + fill_in 'milestone_status_description', with: 'Other status description' + click_button 'Update Milestone Status' + + expect(page).to have_content 'Other status name' + expect(page).to have_content 'Other status description' + end + end + + context "Delete" do + scenario "Hides status" do + status = create(:milestone_status) + + visit admin_milestone_statuses_path + + within("#milestone_status_#{status.id}") do + click_link "Delete" + end + + expect(page).not_to have_content status.name + expect(page).not_to have_content status.description + end + end + +end diff --git a/spec/features/budgets/executions_spec.rb b/spec/features/budgets/executions_spec.rb index 9627cb793..20d5d29fa 100644 --- a/spec/features/budgets/executions_spec.rb +++ b/spec/features/budgets/executions_spec.rb @@ -46,7 +46,7 @@ feature 'Executions' do end scenario "Show message when there are no winning investments with the selected status", :js do - create(:budget_investment_status, name: I18n.t('seeds.budgets.statuses.executed')) + create(:milestone_status, name: I18n.t('seeds.budgets.statuses.executed')) visit budget_path(budget) @@ -129,8 +129,8 @@ feature 'Executions' do context 'Filters' do - let!(:status1) { create(:budget_investment_status, name: I18n.t('seeds.budgets.statuses.studying_project')) } - let!(:status2) { create(:budget_investment_status, name: I18n.t('seeds.budgets.statuses.bidding')) } + let!(:status1) { create(:milestone_status, name: I18n.t('seeds.budgets.statuses.studying_project')) } + let!(:status2) { create(:milestone_status, name: I18n.t('seeds.budgets.statuses.bidding')) } scenario 'Filters select with counter are shown' do create(:budget_investment_milestone, investment: investment1, @@ -154,7 +154,7 @@ feature 'Executions' do scenario 'by milestone status', :js do create(:budget_investment_milestone, investment: investment1, status: status1) create(:budget_investment_milestone, investment: investment2, status: status2) - create(:budget_investment_status, name: I18n.t('seeds.budgets.statuses.executing_project')) + create(:milestone_status, name: I18n.t('seeds.budgets.statuses.executing_project')) visit budget_path(budget) @@ -260,7 +260,7 @@ feature 'Executions' do context 'No milestones' do scenario 'Milestone not yet published' do - status = create(:budget_investment_status) + status = create(:milestone_status) unpublished_milestone = create(:budget_investment_milestone, investment: investment1, status: status, publication_date: Date.tomorrow) diff --git a/spec/models/budget/investment/status_spec.rb b/spec/models/milestone/status_spec.rb similarity index 71% rename from spec/models/budget/investment/status_spec.rb rename to spec/models/milestone/status_spec.rb index 36d472a76..7e530a995 100644 --- a/spec/models/budget/investment/status_spec.rb +++ b/spec/models/milestone/status_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' -describe Budget::Investment::Status do +describe Milestone::Status do describe "Validations" do - let(:status) { build(:budget_investment_status) } + let(:status) { build(:milestone_status) } it "is valid" do expect(status).to be_valid From c0f6fa182f136a602e3a94e7c3fa76764ddd9190 Mon Sep 17 00:00:00 2001 From: Marko Lovic Date: Mon, 16 Jul 2018 15:00:56 +0200 Subject: [PATCH 13/64] Make Milestones general, and not specific to Budget Investments Generalize the Budget::Investment::Milestone model to a polymorphic Milestone model so it can be used for entities other than Budget::Investment. --- ...budget_investment_milestones_controller.rb | 16 ++--- app/models/budget/investment.rb | 3 +- app/models/budget/investment/milestone.rb | 35 ---------- app/models/concerns/milestoneable.rb | 7 ++ app/models/milestone.rb | 31 ++++++++ .../_form.html.erb | 2 +- .../budget_investments/_milestones.html.erb | 4 +- .../admin/budget_investments/show.html.erb | 2 +- config/initializers/routes_hierarchy.rb | 4 +- config/locales/en/activerecord.yml | 2 +- config/locales/es/activerecord.yml | 2 +- config/routes/admin.rb | 2 +- db/dev_seeds/budgets.rb | 2 +- ..._make_investment_milestones_polymorphic.rb | 27 +++++++ db/schema.rb | 25 +++++++ lib/tasks/globalize.rake | 2 +- spec/factories/budgets.rb | 4 +- .../budget_investment_milestones_spec.rb | 22 +++--- spec/features/budgets/executions_spec.rb | 70 +++++++++---------- spec/features/budgets/investments_spec.rb | 14 ++-- spec/lib/tasks/globalize_spec.rb | 2 +- .../{budget/investment => }/milestone_spec.rb | 18 ++--- spec/shared/features/translatable.rb | 2 +- 23 files changed, 176 insertions(+), 122 deletions(-) delete mode 100644 app/models/budget/investment/milestone.rb create mode 100644 app/models/concerns/milestoneable.rb create mode 100644 app/models/milestone.rb create mode 100644 db/migrate/20180713124501_make_investment_milestones_polymorphic.rb rename spec/models/{budget/investment => }/milestone_spec.rb (77%) diff --git a/app/controllers/admin/budget_investment_milestones_controller.rb b/app/controllers/admin/budget_investment_milestones_controller.rb index 504f559b1..23ef679cc 100644 --- a/app/controllers/admin/budget_investment_milestones_controller.rb +++ b/app/controllers/admin/budget_investment_milestones_controller.rb @@ -2,19 +2,19 @@ class Admin::BudgetInvestmentMilestonesController < Admin::BaseController include Translatable before_action :load_budget_investment, only: [:index, :new, :create, :edit, :update, :destroy] - before_action :load_budget_investment_milestone, only: [:edit, :update, :destroy] + before_action :load_milestone, only: [:edit, :update, :destroy] before_action :load_statuses, only: [:index, :new, :create, :edit, :update] def index end def new - @milestone = Budget::Investment::Milestone.new + @milestone = Milestone.new end def create - @milestone = Budget::Investment::Milestone.new(milestone_params) - @milestone.investment = @investment + @milestone = Milestone.new(milestone_params) + @milestone.milestoneable = @investment if @milestone.save redirect_to admin_budget_budget_investment_path(@investment.budget, @investment), notice: t('admin.milestones.create.notice') @@ -47,22 +47,22 @@ class Admin::BudgetInvestmentMilestonesController < Admin::BaseController image_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy] documents_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy] attributes = [:publication_date, :budget_investment_id, :status_id, - translation_params(Budget::Investment::Milestone), + translation_params(Milestone), image_attributes: image_attributes, documents_attributes: documents_attributes] - params.require(:budget_investment_milestone).permit(*attributes) + params.require(:milestone).permit(*attributes) end def load_budget_investment @investment = Budget::Investment.find(params[:budget_investment_id]) end - def load_budget_investment_milestone + def load_milestone @milestone = get_milestone end def get_milestone - Budget::Investment::Milestone.find(params[:id]) + Milestone.find(params[:id]) end def resource diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 486e65052..4143300eb 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -24,6 +24,7 @@ class Budget include Notifiable include Filterable include Flaggable + include Milestoneable belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' belongs_to :heading @@ -40,8 +41,6 @@ class Budget has_many :comments, -> {where(valuation: false)}, as: :commentable, class_name: 'Comment' has_many :valuations, -> {where(valuation: true)}, as: :commentable, class_name: 'Comment' - has_many :milestones - validates :title, presence: true validates :author, presence: true validates :description, presence: true diff --git a/app/models/budget/investment/milestone.rb b/app/models/budget/investment/milestone.rb deleted file mode 100644 index fe0e30ea5..000000000 --- a/app/models/budget/investment/milestone.rb +++ /dev/null @@ -1,35 +0,0 @@ -class Budget - class Investment - class Milestone < ActiveRecord::Base - include Imageable - include Documentable - documentable max_documents_allowed: 3, - max_file_size: 3.megabytes, - accepted_content_types: [ "application/pdf" ] - - translates :title, :description, touch: true - include Globalizable - - belongs_to :investment - belongs_to :status, class_name: 'Milestone::Status' - - validates :investment, presence: true - validates :publication_date, presence: true - validate :description_or_status_present? - - scope :order_by_publication_date, -> { order(publication_date: :asc, created_at: :asc) } - scope :published, -> { where("publication_date <= ?", Date.current) } - scope :with_status, -> { where("status_id IS NOT NULL") } - - def self.title_max_length - 80 - end - - def description_or_status_present? - unless description.present? || status_id.present? - errors.add(:description) - end - end - end - end -end diff --git a/app/models/concerns/milestoneable.rb b/app/models/concerns/milestoneable.rb new file mode 100644 index 000000000..7bae4a61a --- /dev/null +++ b/app/models/concerns/milestoneable.rb @@ -0,0 +1,7 @@ +module Milestoneable + extend ActiveSupport::Concern + + included do + has_many :milestones, as: :milestoneable, dependent: :destroy + end +end diff --git a/app/models/milestone.rb b/app/models/milestone.rb new file mode 100644 index 000000000..1b4790040 --- /dev/null +++ b/app/models/milestone.rb @@ -0,0 +1,31 @@ +class Milestone < ActiveRecord::Base + include Imageable + include Documentable + documentable max_documents_allowed: 3, + max_file_size: 3.megabytes, + accepted_content_types: [ "application/pdf" ] + + translates :title, :description, touch: true + include Globalizable + + belongs_to :milestoneable, polymorphic: true + belongs_to :status + + validates :milestoneable, presence: true + validates :publication_date, presence: true + validate :description_or_status_present? + + scope :order_by_publication_date, -> { order(publication_date: :asc, created_at: :asc) } + scope :published, -> { where("publication_date <= ?", Date.current) } + scope :with_status, -> { where("status_id IS NOT NULL") } + + def self.title_max_length + 80 + end + + def description_or_status_present? + unless description.present? || status_id.present? + errors.add(:description) + end + end +end diff --git a/app/views/admin/budget_investment_milestones/_form.html.erb b/app/views/admin/budget_investment_milestones/_form.html.erb index e827be608..c62ba3521 100644 --- a/app/views/admin/budget_investment_milestones/_form.html.erb +++ b/app/views/admin/budget_investment_milestones/_form.html.erb @@ -13,7 +13,7 @@ <%= f.translatable_fields do |translations_form| %> <%= translations_form.hidden_field :title, value: l(Time.current, format: :datetime), - maxlength: Budget::Investment::Milestone.title_max_length %> + maxlength: Milestone.title_max_length %> <%= translations_form.text_area :description, rows: 5, diff --git a/app/views/admin/budget_investments/_milestones.html.erb b/app/views/admin/budget_investments/_milestones.html.erb index 757fb97e4..20a870d71 100644 --- a/app/views/admin/budget_investments/_milestones.html.erb +++ b/app/views/admin/budget_investments/_milestones.html.erb @@ -18,7 +18,7 @@ <%= milestone.id %> <%= link_to milestone.title, - edit_admin_budget_budget_investment_budget_investment_milestone_path(@investment.budget, + edit_admin_budget_budget_investment_milestone_path(@investment.budget, @investment, milestone) %> @@ -46,7 +46,7 @@ <%= link_to t("admin.milestones.index.delete"), - admin_budget_budget_investment_budget_investment_milestone_path(@investment.budget, + admin_budget_budget_investment_milestone_path(@investment.budget, @investment, milestone), method: :delete, diff --git a/app/views/admin/budget_investments/show.html.erb b/app/views/admin/budget_investments/show.html.erb index f9e7dc88e..cb44745a1 100644 --- a/app/views/admin/budget_investments/show.html.erb +++ b/app/views/admin/budget_investments/show.html.erb @@ -63,6 +63,6 @@

    <%= link_to t("admin.budget_investments.show.new_milestone"), - new_admin_budget_budget_investment_budget_investment_milestone_path(@budget, @investment), + new_admin_budget_budget_investment_milestone_path(@budget, @investment), class: "button hollow" %>

    diff --git a/config/initializers/routes_hierarchy.rb b/config/initializers/routes_hierarchy.rb index f06acf5c9..e9892ef38 100644 --- a/config/initializers/routes_hierarchy.rb +++ b/config/initializers/routes_hierarchy.rb @@ -7,8 +7,8 @@ module ActionDispatch::Routing::UrlFor case resource.class.name when "Budget::Investment" [resource.budget, resource] - when "Budget::Investment::Milestone" - [resource.investment.budget, resource.investment, resource] + when "Milestone" + [resource.milestoneable.budget, resource.milestoneable, resource] when "Legislation::Annotation" [resource.draft_version.process, resource.draft_version, resource] when "Legislation::Proposal", "Legislation::Question", "Legislation::DraftVersion" diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 67f746d1d..90f10a931 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -10,7 +10,7 @@ en: budget/investment: one: "Investment" other: "Investments" - budget/investment/milestone: + milestone: one: "milestone" other: "milestones" milestone/status: diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index 43e10a41e..e90dc7191 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -10,7 +10,7 @@ es: budget/investment: one: "Proyecto de gasto" other: "Proyectos de gasto" - budget/investment/milestone: + milestone: one: "hito" other: "hitos" milestone/status: diff --git a/config/routes/admin.rb b/config/routes/admin.rb index a1374751e..4bd607803 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -62,7 +62,7 @@ namespace :admin do end resources :budget_investments, only: [:index, :show, :edit, :update] do - resources :budget_investment_milestones + resources :milestones, controller: 'budget_investment_milestones' member { patch :toggle_selection } end diff --git a/db/dev_seeds/budgets.rb b/db/dev_seeds/budgets.rb index 685392900..07f30758f 100644 --- a/db/dev_seeds/budgets.rb +++ b/db/dev_seeds/budgets.rb @@ -148,7 +148,7 @@ end section "Creating investment milestones" do Budget::Investment.find_each do |investment| - milestone = Budget::Investment::Milestone.new(investment_id: investment.id, publication_date: Date.tomorrow, status_id: Milestone::Status.all.sample) + milestone = investment.milestones.build(publication_date: Date.tomorrow, status_id: Milestone::Status.all.sample) I18n.available_locales.map do |locale| Globalize.with_locale(locale) do milestone.description = "Description for locale #{locale}" diff --git a/db/migrate/20180713124501_make_investment_milestones_polymorphic.rb b/db/migrate/20180713124501_make_investment_milestones_polymorphic.rb new file mode 100644 index 000000000..9d8ce901e --- /dev/null +++ b/db/migrate/20180713124501_make_investment_milestones_polymorphic.rb @@ -0,0 +1,27 @@ +class MakeInvestmentMilestonesPolymorphic < ActiveRecord::Migration + def change + create_table :milestones do |t| + t.references :milestoneable, polymorphic: true + t.string "title", limit: 80 + t.text "description" + t.datetime "publication_date" + + t.references :status, index: true + + t.timestamps null: false + end + + reversible do |change| + change.up do + Milestone.create_translation_table!({ + title: :string, + description: :text + }) + end + + change.down do + Milestone.drop_translation_table! + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index b2079bfa0..174e2a82c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -791,6 +791,31 @@ ActiveRecord::Schema.define(version: 20181016204729) do add_index "milestone_statuses", ["hidden_at"], name: "index_milestone_statuses_on_hidden_at", using: :btree + create_table "milestone_translations", force: :cascade do |t| + t.integer "milestone_id", null: false + t.string "locale", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "title" + t.text "description" + end + + add_index "milestone_translations", ["locale"], name: "index_milestone_translations_on_locale", using: :btree + add_index "milestone_translations", ["milestone_id"], name: "index_milestone_translations_on_milestone_id", using: :btree + + create_table "milestones", force: :cascade do |t| + t.integer "milestoneable_id" + t.string "milestoneable_type" + t.string "title", limit: 80 + t.text "description" + t.datetime "publication_date" + t.integer "status_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "milestones", ["status_id"], name: "index_milestones_on_status_id", using: :btree + create_table "moderators", force: :cascade do |t| t.integer "user_id" end diff --git a/lib/tasks/globalize.rake b/lib/tasks/globalize.rake index 51a23042e..5197b0b1d 100644 --- a/lib/tasks/globalize.rake +++ b/lib/tasks/globalize.rake @@ -3,7 +3,7 @@ namespace :globalize do [ AdminNotification, Banner, - Budget::Investment::Milestone, + Milestone, I18nContent, Legislation::DraftVersion, Legislation::Process, diff --git a/spec/factories/budgets.rb b/spec/factories/budgets.rb index eda20c8c5..0a8ea699b 100644 --- a/spec/factories/budgets.rb +++ b/spec/factories/budgets.rb @@ -198,8 +198,8 @@ FactoryBot.define do sequence(:description) { |n| "Milestone status #{n} description" } end - factory :budget_investment_milestone, class: 'Budget::Investment::Milestone' do - association :investment, factory: :budget_investment + factory :milestone, class: 'Milestone' do + association :milestoneable, factory: :budget_investment association :status, factory: :milestone_status sequence(:title) { |n| "Budget investment milestone #{n} title" } description 'Milestone description' diff --git a/spec/features/admin/budget_investment_milestones_spec.rb b/spec/features/admin/budget_investment_milestones_spec.rb index 2f1241a19..eaae5a55e 100644 --- a/spec/features/admin/budget_investment_milestones_spec.rb +++ b/spec/features/admin/budget_investment_milestones_spec.rb @@ -10,13 +10,13 @@ feature 'Admin budget investment milestones' do end it_behaves_like "translatable", - "budget_investment_milestone", - "edit_admin_budget_budget_investment_budget_investment_milestone_path", + "milestone", + "edit_admin_budget_budget_investment_milestone_path", %w[description] context "Index" do scenario 'Displaying milestones' do - milestone = create(:budget_investment_milestone, investment: @investment) + milestone = create(:milestone, milestoneable: @investment) create(:image, imageable: milestone) document = create(:document, documentable: milestone) @@ -46,9 +46,9 @@ feature 'Admin budget investment milestones' do click_link 'Create new milestone' - select status.name, from: 'budget_investment_milestone_status_id' + select status.name, from: 'milestone_status_id' fill_in 'Description', with: 'New description milestone' - fill_in 'budget_investment_milestone_publication_date', with: Date.current + fill_in 'milestone_publication_date', with: Date.current click_button 'Create milestone' @@ -61,7 +61,7 @@ feature 'Admin budget investment milestones' do visit admin_budget_budget_investment_path(@investment.budget, @investment) click_link 'Create new milestone' - expect(find("#budget_investment_milestone_status_id").disabled?).to be true + expect(find("#milestone_status_id").disabled?).to be true end scenario "Show validation errors on milestone form" do @@ -73,7 +73,7 @@ feature 'Admin budget investment milestones' do click_button 'Create milestone' - within "#new_budget_investment_milestone" do + within "#new_milestone" do expect(page).to have_content "can't be blank", count: 1 expect(page).to have_content 'New description milestone' end @@ -82,7 +82,7 @@ feature 'Admin budget investment milestones' do context "Edit" do scenario "Change title, description and document names" do - milestone = create(:budget_investment_milestone, investment: @investment) + milestone = create(:milestone, milestoneable: @investment) create(:image, imageable: milestone) document = create(:document, documentable: milestone) @@ -94,8 +94,8 @@ feature 'Admin budget investment milestones' do expect(page).to have_css("img[alt='#{milestone.image.title}']") fill_in 'Description', with: 'Changed description' - fill_in 'budget_investment_milestone_publication_date', with: Date.current - fill_in 'budget_investment_milestone_documents_attributes_0_title', with: 'New document title' + fill_in 'milestone_publication_date', with: Date.current + fill_in 'milestone_documents_attributes_0_title', with: 'New document title' click_button 'Update milestone' @@ -108,7 +108,7 @@ feature 'Admin budget investment milestones' do context "Delete" do scenario "Remove milestone" do - milestone = create(:budget_investment_milestone, investment: @investment, title: "Title will it remove") + milestone = create(:milestone, milestoneable: @investment, title: "Title will it remove") visit admin_budget_budget_investment_path(@investment.budget, @investment) diff --git a/spec/features/budgets/executions_spec.rb b/spec/features/budgets/executions_spec.rb index 20d5d29fa..3fc8d87a5 100644 --- a/spec/features/budgets/executions_spec.rb +++ b/spec/features/budgets/executions_spec.rb @@ -12,7 +12,7 @@ feature 'Executions' do let!(:investment3) { create(:budget_investment, :incompatible, heading: heading) } scenario 'only displays investments with milestones' do - create(:budget_investment_milestone, investment: investment1) + create(:milestone, milestoneable: investment1) visit budget_path(budget) click_link 'See results' @@ -28,7 +28,7 @@ feature 'Executions' do end scenario "Do not display headings with no winning investments for selected status" do - create(:budget_investment_milestone, investment: investment1) + create(:milestone, milestoneable: investment1) empty_group = create(:budget_group, budget: budget) empty_heading = create(:budget_heading, group: empty_group, price: 1000) @@ -63,7 +63,7 @@ feature 'Executions' do context 'Images' do scenario 'renders milestone image if available' do - milestone1 = create(:budget_investment_milestone, investment: investment1) + milestone1 = create(:milestone, milestoneable: investment1) create(:image, imageable: milestone1) visit budget_path(budget) @@ -76,7 +76,7 @@ feature 'Executions' do end scenario 'renders investment image if no milestone image is available' do - create(:budget_investment_milestone, investment: investment2) + create(:milestone, milestoneable: investment2) create(:image, imageable: investment2) visit budget_path(budget) @@ -89,7 +89,7 @@ feature 'Executions' do end scenario 'renders default image if no milestone nor investment images are available' do - create(:budget_investment_milestone, investment: investment4) + create(:milestone, milestoneable: investment4) visit budget_path(budget) @@ -101,17 +101,17 @@ feature 'Executions' do end scenario "renders last milestone's image if investment has multiple milestones with images associated" do - milestone1 = create(:budget_investment_milestone, investment: investment1, - publication_date: Date.yesterday) + milestone1 = create(:milestone, milestoneable: investment1, + publication_date: Date.yesterday) - milestone2 = create(:budget_investment_milestone, investment: investment1, - publication_date: Date.yesterday) + milestone2 = create(:milestone, milestoneable: investment1, + publication_date: Date.yesterday) - milestone3 = create(:budget_investment_milestone, investment: investment1, - publication_date: Date.yesterday) + milestone3 = create(:milestone, milestoneable: investment1, + publication_date: Date.yesterday) - milestone4 = create(:budget_investment_milestone, investment: investment1, - publication_date: Date.yesterday) + milestone4 = create(:milestone, milestoneable: investment1, + publication_date: Date.yesterday) create(:image, imageable: milestone2, title: 'Image for first milestone with image') create(:image, imageable: milestone3, title: 'Image for second milestone with image') @@ -133,13 +133,13 @@ feature 'Executions' do let!(:status2) { create(:milestone_status, name: I18n.t('seeds.budgets.statuses.bidding')) } scenario 'Filters select with counter are shown' do - create(:budget_investment_milestone, investment: investment1, - publication_date: Date.yesterday, - status: status1) + create(:milestone, milestoneable: investment1, + publication_date: Date.yesterday, + status: status1) - create(:budget_investment_milestone, investment: investment2, - publication_date: Date.yesterday, - status: status2) + create(:milestone, milestoneable: investment2, + publication_date: Date.yesterday, + status: status2) visit budget_path(budget) @@ -152,8 +152,8 @@ feature 'Executions' do end scenario 'by milestone status', :js do - create(:budget_investment_milestone, investment: investment1, status: status1) - create(:budget_investment_milestone, investment: investment2, status: status2) + create(:milestone, milestoneable: investment1, status: status1) + create(:milestone, milestoneable: investment2, status: status2) create(:milestone_status, name: I18n.t('seeds.budgets.statuses.executing_project')) visit budget_path(budget) @@ -181,13 +181,13 @@ feature 'Executions' do end scenario 'are based on latest milestone status', :js do - create(:budget_investment_milestone, investment: investment1, - publication_date: 1.month.ago, - status: status1) + create(:milestone, milestoneable: investment1, + publication_date: 1.month.ago, + status: status1) - create(:budget_investment_milestone, investment: investment1, - publication_date: Date.yesterday, - status: status2) + create(:milestone, milestoneable: investment1, + publication_date: Date.yesterday, + status: status2) visit budget_path(budget) click_link 'See results' @@ -201,13 +201,13 @@ feature 'Executions' do end scenario 'milestones with future dates are not shown', :js do - create(:budget_investment_milestone, investment: investment1, - publication_date: Date.yesterday, - status: status1) + create(:milestone, milestoneable: investment1, + publication_date: Date.yesterday, + status: status1) - create(:budget_investment_milestone, investment: investment1, - publication_date: Date.tomorrow, - status: status2) + create(:milestone, milestoneable: investment1, + publication_date: Date.tomorrow, + status: status2) visit budget_path(budget) click_link 'See results' @@ -226,7 +226,7 @@ feature 'Executions' do def create_heading_with_investment_with_milestone(group:, name:) heading = create(:budget_heading, group: group, name: name) investment = create(:budget_investment, :winner, heading: heading) - milestone = create(:budget_investment_milestone, investment: investment) + milestone = create(:milestone, milestoneable: investment) heading end @@ -261,7 +261,7 @@ feature 'Executions' do scenario 'Milestone not yet published' do status = create(:milestone_status) - unpublished_milestone = create(:budget_investment_milestone, investment: investment1, + unpublished_milestone = create(:milestone, milestoneable: investment1, status: status, publication_date: Date.tomorrow) visit budget_executions_path(budget, status: status.id) diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index e918e9f52..fd01acfb2 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -1121,13 +1121,13 @@ feature 'Budget Investments' do scenario "Show milestones", :js do user = create(:user) investment = create(:budget_investment) - create(:budget_investment_milestone, investment: investment, - description_en: "Last milestone with a link to https://consul.dev", - description_es: "Último hito con el link https://consul.dev", - publication_date: Date.tomorrow) - first_milestone = create(:budget_investment_milestone, investment: investment, - description: "First milestone", - publication_date: Date.yesterday) + create(:milestone, milestoneable: investment, + description_en: "Last milestone with a link to https://consul.dev", + description_es: "Último hito con el link https://consul.dev", + publication_date: Date.tomorrow) + first_milestone = create(:milestone, milestoneable: investment, + description: "First milestone", + publication_date: Date.yesterday) image = create(:image, imageable: first_milestone) document = create(:document, documentable: first_milestone) diff --git a/spec/lib/tasks/globalize_spec.rb b/spec/lib/tasks/globalize_spec.rb index b685bb95e..04e2f8cee 100644 --- a/spec/lib/tasks/globalize_spec.rb +++ b/spec/lib/tasks/globalize_spec.rb @@ -151,7 +151,7 @@ describe "Globalize tasks" do before { I18n.locale = :"pt-BR" } let!(:milestone) do - create(:budget_investment_milestone).tap do |milestone| + create(:milestone).tap do |milestone| milestone.translations.delete_all milestone.update_column(:title, "Português") milestone.reload diff --git a/spec/models/budget/investment/milestone_spec.rb b/spec/models/milestone_spec.rb similarity index 77% rename from spec/models/budget/investment/milestone_spec.rb rename to spec/models/milestone_spec.rb index 45d4e7c0b..35f175aea 100644 --- a/spec/models/budget/investment/milestone_spec.rb +++ b/spec/models/milestone_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' -describe Budget::Investment::Milestone do +describe Milestone do describe "Validations" do - let(:milestone) { build(:budget_investment_milestone) } + let(:milestone) { build(:milestone) } it "is valid" do expect(milestone).to be_valid @@ -25,8 +25,8 @@ describe Budget::Investment::Milestone do expect(milestone).to be_valid end - it "is not valid without an investment" do - milestone.investment_id = nil + it "is not valid without a milestoneable" do + milestone.milestoneable_id = nil expect(milestone).not_to be_valid end @@ -48,7 +48,7 @@ describe Budget::Investment::Milestone do end describe "#description_or_status_present?" do - let(:milestone) { build(:budget_investment_milestone) } + let(:milestone) { build(:milestone) } it "is not valid when status is removed and there's no description" do milestone.update(description: nil) @@ -71,14 +71,14 @@ describe Budget::Investment::Milestone do describe ".published" do it "uses the application's time zone date", :with_different_time_zone do - published_in_local_time_zone = create(:budget_investment_milestone, + published_in_local_time_zone = create(:milestone, publication_date: Date.today) - published_in_application_time_zone = create(:budget_investment_milestone, + published_in_application_time_zone = create(:milestone, publication_date: Date.current) - expect(Budget::Investment::Milestone.published).to include(published_in_application_time_zone) - expect(Budget::Investment::Milestone.published).not_to include(published_in_local_time_zone) + expect(Milestone.published).to include(published_in_application_time_zone) + expect(Milestone.published).not_to include(published_in_local_time_zone) end end end diff --git a/spec/shared/features/translatable.rb b/spec/shared/features/translatable.rb index bd485334a..4994ab1d5 100644 --- a/spec/shared/features/translatable.rb +++ b/spec/shared/features/translatable.rb @@ -317,7 +317,7 @@ end # even share the same colour. def update_button_text case translatable_class.name - when "Budget::Investment::Milestone" + when "Milestone" "Update milestone" when "AdminNotification" "Update notification" From 4c3dadf1fbb4bd5abbffcfdb2f506e8eea9953b6 Mon Sep 17 00:00:00 2001 From: Marko Lovic Date: Wed, 18 Jul 2018 12:27:10 +0200 Subject: [PATCH 14/64] Add Rake task to migrate milestone data to new tables --- .../migrate_milestones_and_statuses.rake | 92 +++++++++++++ spec/lib/tasks/milestones_spec.rb | 121 ++++++++++++++++++ 2 files changed, 213 insertions(+) create mode 100644 lib/tasks/migrate_milestones_and_statuses.rake create mode 100644 spec/lib/tasks/milestones_spec.rb diff --git a/lib/tasks/migrate_milestones_and_statuses.rake b/lib/tasks/migrate_milestones_and_statuses.rake new file mode 100644 index 000000000..a16b9479e --- /dev/null +++ b/lib/tasks/migrate_milestones_and_statuses.rake @@ -0,0 +1,92 @@ +namespace :milestones do + + def generate_table_migration_sql(new_table:, old_table:, columns:) + from_cols = ['id', *columns.keys] + to_cols = ['id', *columns.values] + <<~SQL + INSERT INTO #{new_table} (#{to_cols.join(', ')}) + SELECT #{from_cols.join(', ')} FROM #{old_table}; + SQL + end + + def migrate_table!(new_table:, old_table:, columns:) + puts "Migrating data from '#{old_table}' to '#{new_table}'..." + result = ActiveRecord::Base.connection.execute( + generate_table_migration_sql(old_table: old_table, + new_table: new_table, + columns: columns) + + ) + puts "#{result.cmd_tuples} rows affected" + end + + def populate_column!(table:, column:, value:) + puts "Populating column '#{column}' from table '#{table}' with '#{value}'..." + result = ActiveRecord::Base.connection.execute( + "UPDATE #{table} SET #{column} = '#{value}';" + ) + puts "#{result.cmd_tuples} rows affected" + end + + def count_rows(table) + ActiveRecord::Base.connection.query("SELECT COUNT(*) FROM #{table};")[0][0].to_i + end + + desc "Migrate milestones and milestone status data after making the model polymorphic" + task migrate: :environment do + # This script copies all milestone-related data from the old tables to + # the new ones (preserving all primary keys). All 3 of the new tables + # must be empty. + # + # To clear the new tables to test this script: + # + # DELETE FROM milestone_statuses; + # DELETE FROM milestones; + # DELETE FROM milestone_translations; + # + + start = Time.now + + ActiveRecord::Base.transaction do + migrate_table! old_table: 'budget_investment_statuses', + new_table: 'milestone_statuses', + columns: {'name' => 'name', + 'description' => 'description', + 'hidden_at' => 'hidden_at', + 'created_at' => 'created_at', + 'updated_at' => 'updated_at'} + + migrate_table! old_table: 'budget_investment_milestones', + new_table: 'milestones', + columns: {'investment_id' => 'milestoneable_id', + 'title' => 'title', + 'description' => 'description', + 'created_at' => 'created_at', + 'updated_at' => 'updated_at', + 'publication_date' => 'publication_date', + 'status_id' => 'status_id'} + + populate_column! table: 'milestones', + column: 'milestoneable_type', + value: 'Budget::Investment' + + migrate_table! old_table: 'budget_investment_milestone_translations', + new_table: 'milestone_translations', + columns: {'budget_investment_milestone_id' => 'milestone_id', + 'locale' => 'locale', + 'created_at' => 'created_at', + 'updated_at' => 'updated_at', + 'title' => 'title', + 'description' => 'description'} + + puts "Verifying that all rows were copied..." + unless count_rows('milestones') == count_rows('budget_investment_milestones') && + count_rows('milestone_statuses') == count_rows('budget_investment_statuses') && + count_rows('milestone_translations') == count_rows('budget_investment_milestone_translations') + raise "Number of rows of old and new tables do not match! Rolling back transaction..." + end + end + + puts "Finished in %.3f seconds" % (Time.now - start) + end +end diff --git a/spec/lib/tasks/milestones_spec.rb b/spec/lib/tasks/milestones_spec.rb new file mode 100644 index 000000000..5feb6206b --- /dev/null +++ b/spec/lib/tasks/milestones_spec.rb @@ -0,0 +1,121 @@ +require "rails_helper" +require "rake" + +describe "Milestones tasks" do + before do + Rake.application.rake_require "tasks/migrate_milestones_and_statuses" + Rake::Task.define_task(:environment) + end + + describe "#migrate" do + let :run_rake_task do + Rake::Task["milestones:migrate"].reenable + Rake.application.invoke_task "milestones:migrate" + end + + let!(:investment) { create(:budget_investment) } + + before do + ActiveRecord::Base.connection.execute( + "INSERT INTO budget_investment_statuses " + + "(name, description, hidden_at, created_at, updated_at) " + + "VALUES ('open', 'Good', NULL, '#{Time.current - 1.day}', '#{Time.current}');" + ) + + status_id = ActiveRecord::Base.connection.execute( + "SELECT MAX(id) FROM budget_investment_statuses;" + ).to_a.first["max"] + + milestone_attributes = { + investment_id: investment.id, + title: "First", + description: "Interesting", + publication_date: Date.yesterday, + status_id: status_id, + created_at: Time.current - 1.day, + updated_at: Time.current + } + + ActiveRecord::Base.connection.execute( + "INSERT INTO budget_investment_milestones " + + "(#{milestone_attributes.keys.join(", ")}) " + + "VALUES (#{milestone_attributes.values.map { |value| "'#{value}'"}.join(", ")})" + ) + end + + it "migrates statuses" do + run_rake_task + + expect(Milestone::Status.count).to be 1 + + status = Milestone::Status.first + expect(status.name).to eq "open" + expect(status.description).to eq "Good" + expect(status.hidden_at).to be nil + expect(status.created_at.to_date).to eq Date.yesterday + expect(status.updated_at.to_date).to eq Date.today + end + + it "migrates milestones" do + run_rake_task + + expect(Milestone.count).to be 1 + + milestone = Milestone.first + expect(milestone.milestoneable_id).to eq investment.id + expect(milestone.milestoneable_type).to eq "Budget::Investment" + expect(milestone.title).to eq "First" + expect(milestone.description).to eq "Interesting" + expect(milestone.publication_date).to eq Date.yesterday + expect(milestone.status_id).to eq Milestone::Status.first.id + expect(milestone.created_at.to_date).to eq Date.yesterday + expect(milestone.updated_at.to_date).to eq Date.today + end + + context "Statuses had been deleted" do + before do + ActiveRecord::Base.connection.execute( + "INSERT INTO budget_investment_statuses " + + "(name, description, hidden_at, created_at, updated_at) " + + "VALUES ('deleted', 'Del', NULL, '#{Time.current - 1.day}', '#{Time.current}');" + ) + + ActiveRecord::Base.connection.execute( + "DELETE FROM budget_investment_statuses WHERE name='deleted'" + ) + + ActiveRecord::Base.connection.execute( + "INSERT INTO budget_investment_statuses " + + "(name, description, hidden_at, created_at, updated_at) " + + "VALUES ('new', 'New', NULL, '#{Time.current - 1.day}', '#{Time.current}');" + ) + + status_id = ActiveRecord::Base.connection.execute( + "SELECT MAX(id) FROM budget_investment_statuses;" + ).to_a.first["max"] + + milestone_attributes = { + investment_id: investment.id, + title: "Last", + description: "Different", + publication_date: Date.yesterday, + status_id: status_id, + created_at: Time.current - 1.day, + updated_at: Time.current + } + + ActiveRecord::Base.connection.execute( + "INSERT INTO budget_investment_milestones " + + "(#{milestone_attributes.keys.join(", ")}) " + + "VALUES (#{milestone_attributes.values.map { |value| "'#{value}'"}.join(", ")})" + ) + end + + it "migrates the status id correctly" do + run_rake_task + + expect(Milestone.last.status_id).to eq Milestone::Status.last.id + end + end + end +end From 9a093d5f8a86953c12785bc60e560e88cec2ab52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 7 Nov 2018 11:24:32 +0100 Subject: [PATCH 15/64] Use `let` instead of instance variables --- .../budget_investment_milestones_spec.rb | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/spec/features/admin/budget_investment_milestones_spec.rb b/spec/features/admin/budget_investment_milestones_spec.rb index eaae5a55e..28b05ff03 100644 --- a/spec/features/admin/budget_investment_milestones_spec.rb +++ b/spec/features/admin/budget_investment_milestones_spec.rb @@ -5,10 +5,10 @@ feature 'Admin budget investment milestones' do background do admin = create(:administrator) login_as(admin.user) - - @investment = create(:budget_investment) end + let!(:investment) { create(:budget_investment) } + it_behaves_like "translatable", "milestone", "edit_admin_budget_budget_investment_milestone_path", @@ -16,11 +16,11 @@ feature 'Admin budget investment milestones' do context "Index" do scenario 'Displaying milestones' do - milestone = create(:milestone, milestoneable: @investment) + milestone = create(:milestone, milestoneable: investment) create(:image, imageable: milestone) document = create(:document, documentable: milestone) - visit admin_budget_budget_investment_path(@investment.budget, @investment) + visit admin_budget_budget_investment_path(investment.budget, investment) expect(page).to have_content("Milestone") expect(page).to have_content(milestone.title) @@ -32,7 +32,7 @@ feature 'Admin budget investment milestones' do end scenario 'Displaying no_milestones text' do - visit admin_budget_budget_investment_path(@investment.budget, @investment) + visit admin_budget_budget_investment_path(investment.budget, investment) expect(page).to have_content("Milestone") expect(page).to have_content("Don't have defined milestones") @@ -42,7 +42,7 @@ feature 'Admin budget investment milestones' do context "New" do scenario "Add milestone" do status = create(:milestone_status) - visit admin_budget_budget_investment_path(@investment.budget, @investment) + visit admin_budget_budget_investment_path(investment.budget, investment) click_link 'Create new milestone' @@ -58,14 +58,14 @@ feature 'Admin budget investment milestones' do end scenario "Status select is disabled if there are no statuses available" do - visit admin_budget_budget_investment_path(@investment.budget, @investment) + visit admin_budget_budget_investment_path(investment.budget, investment) click_link 'Create new milestone' expect(find("#milestone_status_id").disabled?).to be true end scenario "Show validation errors on milestone form" do - visit admin_budget_budget_investment_path(@investment.budget, @investment) + visit admin_budget_budget_investment_path(investment.budget, investment) click_link 'Create new milestone' @@ -82,11 +82,11 @@ feature 'Admin budget investment milestones' do context "Edit" do scenario "Change title, description and document names" do - milestone = create(:milestone, milestoneable: @investment) + milestone = create(:milestone, milestoneable: investment) create(:image, imageable: milestone) document = create(:document, documentable: milestone) - visit admin_budget_budget_investment_path(@investment.budget, @investment) + visit admin_budget_budget_investment_path(investment.budget, investment) expect(page).to have_link document.title click_link milestone.title @@ -108,9 +108,9 @@ feature 'Admin budget investment milestones' do context "Delete" do scenario "Remove milestone" do - milestone = create(:milestone, milestoneable: @investment, title: "Title will it remove") + milestone = create(:milestone, milestoneable: investment, title: "Title will it remove") - visit admin_budget_budget_investment_path(@investment.budget, @investment) + visit admin_budget_budget_investment_path(investment.budget, investment) click_link "Delete milestone" From a6adc0b5ab45b843b56cac13bf8124954ef8f14d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 7 Nov 2018 11:28:16 +0100 Subject: [PATCH 16/64] Reduce `I18n.t` usage in spec We also make the line shorter so rubocop doesn't complain. --- spec/features/budgets/executions_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/budgets/executions_spec.rb b/spec/features/budgets/executions_spec.rb index 3fc8d87a5..226d01cfe 100644 --- a/spec/features/budgets/executions_spec.rb +++ b/spec/features/budgets/executions_spec.rb @@ -129,8 +129,8 @@ feature 'Executions' do context 'Filters' do - let!(:status1) { create(:milestone_status, name: I18n.t('seeds.budgets.statuses.studying_project')) } - let!(:status2) { create(:milestone_status, name: I18n.t('seeds.budgets.statuses.bidding')) } + let!(:status1) { create(:milestone_status, name: "Studying the project") } + let!(:status2) { create(:milestone_status, name: "Bidding") } scenario 'Filters select with counter are shown' do create(:milestone, milestoneable: investment1, From cb891f21d409d6253a8cb361ab2c8c28bb4706a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 7 Nov 2018 14:10:05 +0100 Subject: [PATCH 17/64] Simplify count_rows check We had a line which was too long according to rubocop, and simplifying the code makes the line shorter. --- lib/tasks/migrate_milestones_and_statuses.rake | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/tasks/migrate_milestones_and_statuses.rake b/lib/tasks/migrate_milestones_and_statuses.rake index a16b9479e..e46db0a20 100644 --- a/lib/tasks/migrate_milestones_and_statuses.rake +++ b/lib/tasks/migrate_milestones_and_statuses.rake @@ -80,10 +80,15 @@ namespace :milestones do 'description' => 'description'} puts "Verifying that all rows were copied..." - unless count_rows('milestones') == count_rows('budget_investment_milestones') && - count_rows('milestone_statuses') == count_rows('budget_investment_statuses') && - count_rows('milestone_translations') == count_rows('budget_investment_milestone_translations') - raise "Number of rows of old and new tables do not match! Rolling back transaction..." + + { + "budget_investment_milestones" => "milestones", + "budget_investment_statuses" => "milestone_statuses", + "budget_investment_milestone_translations" => "milestone_translations" + }.each do |original_table, migrated_table| + unless count_rows(original_table) == count_rows(migrated_table) + raise "Number of rows of old and new tables do not match! Rolling back transaction..." + end end end From 1a5b73a0bd51cc411402667e1db79ba94950e0e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 8 Nov 2018 14:19:29 +0100 Subject: [PATCH 18/64] Don't load tasks several times in specs Calling `load_tasks` in several files made rails load the tasks several times, and so they were executed several times when called. Since the milestone migration can't be executed twice in a row (it would fail with duplicated ID records), loading the tasks several times made the milestone migrations task specs fail. --- spec/lib/tasks/communities_spec.rb | 6 ------ spec/lib/tasks/dev_seed_spec.rb | 3 --- spec/lib/tasks/globalize_spec.rb | 6 ------ spec/lib/tasks/map_location_spec.rb | 2 -- spec/lib/tasks/milestones_spec.rb | 6 ------ spec/lib/tasks/settings_spec.rb | 6 ------ spec/lib/tasks/sitemap_spec.rb | 3 --- spec/rails_helper.rb | 1 + 8 files changed, 1 insertion(+), 32 deletions(-) diff --git a/spec/lib/tasks/communities_spec.rb b/spec/lib/tasks/communities_spec.rb index 3a8819147..3c3d17682 100644 --- a/spec/lib/tasks/communities_spec.rb +++ b/spec/lib/tasks/communities_spec.rb @@ -1,15 +1,9 @@ require 'rails_helper' -require 'rake' describe 'Communities Rake' do describe '#associate_community' do - before do - Rake.application.rake_require "tasks/communities" - Rake::Task.define_task(:environment) - end - let :run_rake_task do Rake::Task['communities:associate_community'].reenable Rake.application.invoke_task 'communities:associate_community' diff --git a/spec/lib/tasks/dev_seed_spec.rb b/spec/lib/tasks/dev_seed_spec.rb index d3e69f4b9..0bd63035e 100644 --- a/spec/lib/tasks/dev_seed_spec.rb +++ b/spec/lib/tasks/dev_seed_spec.rb @@ -1,7 +1,4 @@ -require 'rake' require 'rails_helper' -Rake::Task.define_task(:environment) -Rake.application.rake_require('tasks/db') describe 'rake db:dev_seed' do let :run_rake_task do diff --git a/spec/lib/tasks/globalize_spec.rb b/spec/lib/tasks/globalize_spec.rb index 04e2f8cee..26a24dd8a 100644 --- a/spec/lib/tasks/globalize_spec.rb +++ b/spec/lib/tasks/globalize_spec.rb @@ -1,15 +1,9 @@ require "rails_helper" -require "rake" describe "Globalize tasks" do describe "#migrate_data" do - before do - Rake.application.rake_require "tasks/globalize" - Rake::Task.define_task(:environment) - end - let :run_rake_task do Rake::Task["globalize:migrate_data"].reenable Rake.application.invoke_task "globalize:migrate_data" diff --git a/spec/lib/tasks/map_location_spec.rb b/spec/lib/tasks/map_location_spec.rb index 8ef004bda..42cae9241 100644 --- a/spec/lib/tasks/map_location_spec.rb +++ b/spec/lib/tasks/map_location_spec.rb @@ -1,6 +1,4 @@ -require 'rake' require 'rails_helper' -Rails.application.load_tasks describe 'rake map_locations:destroy' do before do diff --git a/spec/lib/tasks/milestones_spec.rb b/spec/lib/tasks/milestones_spec.rb index 5feb6206b..97d3c6b5c 100644 --- a/spec/lib/tasks/milestones_spec.rb +++ b/spec/lib/tasks/milestones_spec.rb @@ -1,12 +1,6 @@ require "rails_helper" -require "rake" describe "Milestones tasks" do - before do - Rake.application.rake_require "tasks/migrate_milestones_and_statuses" - Rake::Task.define_task(:environment) - end - describe "#migrate" do let :run_rake_task do Rake::Task["milestones:migrate"].reenable diff --git a/spec/lib/tasks/settings_spec.rb b/spec/lib/tasks/settings_spec.rb index 4008cf784..22cee28e1 100644 --- a/spec/lib/tasks/settings_spec.rb +++ b/spec/lib/tasks/settings_spec.rb @@ -1,15 +1,9 @@ require 'rails_helper' -require 'rake' describe 'Settings Rake' do describe '#per_page_code_migration' do - before do - Rake.application.rake_require "tasks/settings" - Rake::Task.define_task(:environment) - end - let :run_rake_task do Rake::Task['settings:per_page_code_migration'].reenable Rake.application.invoke_task 'settings:per_page_code_migration' diff --git a/spec/lib/tasks/sitemap_spec.rb b/spec/lib/tasks/sitemap_spec.rb index 01dd3f430..bfe6954a6 100644 --- a/spec/lib/tasks/sitemap_spec.rb +++ b/spec/lib/tasks/sitemap_spec.rb @@ -1,7 +1,4 @@ -require 'rake' require 'rails_helper' -Rails.application.load_tasks -Rake::Task.define_task(:environment) feature 'rake sitemap:create' do before do diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 1385490c8..c90695dca 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -12,6 +12,7 @@ require 'capybara/rails' require 'capybara/rspec' require 'selenium/webdriver' +Rails.application.load_tasks I18n.default_locale = :en include Warden::Test::Helpers From 4a7f479d219b9c2e6d5108c8fa59817533af6879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 16 Nov 2018 11:52:35 +0100 Subject: [PATCH 19/64] Remove obsolete model usage We'd rather keep the table so future data migrations work smoothly, so we change the migration in order to create the translation table without using models. --- ...20180323190027_add_translate_milestones.rb | 19 ++++++++----------- db/schema.rb | 7 ++----- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/db/migrate/20180323190027_add_translate_milestones.rb b/db/migrate/20180323190027_add_translate_milestones.rb index 6767d8e84..afc8db9af 100644 --- a/db/migrate/20180323190027_add_translate_milestones.rb +++ b/db/migrate/20180323190027_add_translate_milestones.rb @@ -1,15 +1,12 @@ class AddTranslateMilestones < ActiveRecord::Migration - def self.up - Budget::Investment::Milestone.create_translation_table!( - { - title: :string, - description: :text - }, - { migrate_data: true } - ) - end + def change + create_table :budget_investment_milestone_translations do |t| + t.integer :budget_investment_milestone_id, null: false + t.string :locale, null: false + t.string :title + t.text :description - def self.down - Budget::Investment::Milestone.drop_translation_table! + t.timestamps null: false + end end end diff --git a/db/schema.rb b/db/schema.rb index 174e2a82c..368049987 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -163,15 +163,12 @@ ActiveRecord::Schema.define(version: 20181016204729) do create_table "budget_investment_milestone_translations", force: :cascade do |t| t.integer "budget_investment_milestone_id", null: false t.string "locale", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false t.string "title" t.text "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - add_index "budget_investment_milestone_translations", ["budget_investment_milestone_id"], name: "index_6770e7675fe296cf87aa0fd90492c141b5269e0b", using: :btree - add_index "budget_investment_milestone_translations", ["locale"], name: "index_budget_investment_milestone_translations_on_locale", using: :btree - create_table "budget_investment_milestones", force: :cascade do |t| t.integer "investment_id" t.string "title", limit: 80 From 87b073cbca333426b3b11ef8a7633809278d0715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 16 Nov 2018 11:57:25 +0100 Subject: [PATCH 20/64] Migrate milestones images and documents --- .../migrate_milestones_and_statuses.rake | 5 ++++ spec/lib/tasks/milestones_spec.rb | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/tasks/migrate_milestones_and_statuses.rake b/lib/tasks/migrate_milestones_and_statuses.rake index e46db0a20..789e3d57e 100644 --- a/lib/tasks/migrate_milestones_and_statuses.rake +++ b/lib/tasks/migrate_milestones_and_statuses.rake @@ -79,6 +79,11 @@ namespace :milestones do 'title' => 'title', 'description' => 'description'} + Image.where(imageable_type: "Budget::Investment::Milestone"). + update_all(imageable_type: "Milestone") + Document.where(documentable_type: "Budget::Investment::Milestone"). + update_all(documentable_type: "Milestone") + puts "Verifying that all rows were copied..." { diff --git a/spec/lib/tasks/milestones_spec.rb b/spec/lib/tasks/milestones_spec.rb index 97d3c6b5c..b1693ccf5 100644 --- a/spec/lib/tasks/milestones_spec.rb +++ b/spec/lib/tasks/milestones_spec.rb @@ -66,6 +66,33 @@ describe "Milestones tasks" do expect(milestone.updated_at.to_date).to eq Date.today end + context "Milestone has images and documents" do + let(:milestone_id) do + ActiveRecord::Base.connection.execute( + "SELECT MAX(id) FROM budget_investment_milestones;" + ).to_a.first["max"] + end + + let!(:image) do + create(:image, imageable_id: milestone_id).tap do |image| + image.update_column(:imageable_type, "Budget::Investment::Milestone") + end + end + + let!(:document) do + create(:document, documentable_id: milestone_id).tap do |document| + document.update_column(:documentable_type, "Budget::Investment::Milestone") + end + end + + it "migrates images and documents" do + run_rake_task + + expect(Milestone.last.image).to eq image + expect(Milestone.last.documents).to eq [document] + end + end + context "Statuses had been deleted" do before do ActiveRecord::Base.connection.execute( From d3882df4376dde5ecff2c9ddb1478369702ceb7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 19 Nov 2018 18:42:38 +0100 Subject: [PATCH 21/64] Fix milestones migration not updating ID sequence When we insert a record in PostgreSQL and we specify the ID, the internal ID sequence for that table isn't updated. In order to keep the original IDs so we didn't break any foreign keys, we specified the IDs when copying the table, resulting in a table having its ID sequence with a value of an existing record. When trying to insert a new record, we got a `PG::UniqueViolation` exception. Updating the sequence after the data migration might not be the most elegant solution, but it's easy to do and it's already been tested on a production environment. --- lib/tasks/migrate_milestones_and_statuses.rake | 4 ++++ spec/lib/tasks/milestones_spec.rb | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/lib/tasks/migrate_milestones_and_statuses.rake b/lib/tasks/migrate_milestones_and_statuses.rake index 789e3d57e..d01418e6b 100644 --- a/lib/tasks/migrate_milestones_and_statuses.rake +++ b/lib/tasks/migrate_milestones_and_statuses.rake @@ -91,6 +91,10 @@ namespace :milestones do "budget_investment_statuses" => "milestone_statuses", "budget_investment_milestone_translations" => "milestone_translations" }.each do |original_table, migrated_table| + ActiveRecord::Base.connection.execute( + "select setval('#{migrated_table}_id_seq', (select max(id) from #{migrated_table}));" + ) + unless count_rows(original_table) == count_rows(migrated_table) raise "Number of rows of old and new tables do not match! Rolling back transaction..." end diff --git a/spec/lib/tasks/milestones_spec.rb b/spec/lib/tasks/milestones_spec.rb index b1693ccf5..56507d02b 100644 --- a/spec/lib/tasks/milestones_spec.rb +++ b/spec/lib/tasks/milestones_spec.rb @@ -66,6 +66,11 @@ describe "Milestones tasks" do expect(milestone.updated_at.to_date).to eq Date.today end + it "Updates the primary key sequence correctly" do + run_rake_task + expect { create(:milestone) }.not_to raise_exception + end + context "Milestone has images and documents" do let(:milestone_id) do ActiveRecord::Base.connection.execute( From f6689cc69d77a8dbde8625f6c7d06015df9dd1e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 21 Nov 2018 20:20:40 +0100 Subject: [PATCH 22/64] Update obsolete milestones I18n keys --- config/locales/en/activerecord.yml | 4 ++-- config/locales/es/activerecord.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 90f10a931..5fdff28dd 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -131,12 +131,12 @@ en: organization_name: "If you are proposing in the name of a collective/organization, or on behalf of more people, write its name" image: "Proposal descriptive image" image_title: "Image title" - budget/investment/milestone: + milestone: status_id: "Current investment status (optional)" title: "Title" description: "Description (optional if there's an status assigned)" publication_date: "Publication date" - budget/investment/status: + milestone/status: name: "Name" description: "Description (optional)" budget/heading: diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index e90dc7191..722fd6724 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -131,12 +131,12 @@ es: organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre" image: "Imagen descriptiva del proyecto de gasto" image_title: "Título de la imagen" - budget/investment/milestone: + milestone: status_id: "Estado actual del proyecto (opcional)" title: "Título" description: "Descripción (opcional si hay un estado asignado)" publication_date: "Fecha de publicación" - budget/investment/status: + milestone/status: name: "Nombre" description: "Descripción (opcional)" budget/heading: From f240977ed03cca2ce851daecf1c28ff8b5a61b11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 21 Nov 2018 20:22:20 +0100 Subject: [PATCH 23/64] Update milestone I18n keys for all languages --- config/locales/ar/activerecord.yml | 4 ++-- config/locales/ast/activerecord.yml | 2 +- config/locales/ca/activerecord.yml | 2 +- config/locales/de-DE/activerecord.yml | 8 ++++---- config/locales/en-US/activerecord.yml | 4 ++-- config/locales/es-AR/activerecord.yml | 8 ++++---- config/locales/es-BO/activerecord.yml | 4 ++-- config/locales/es-CL/activerecord.yml | 8 ++++---- config/locales/es-CO/activerecord.yml | 4 ++-- config/locales/es-CR/activerecord.yml | 4 ++-- config/locales/es-DO/activerecord.yml | 4 ++-- config/locales/es-EC/activerecord.yml | 4 ++-- config/locales/es-GT/activerecord.yml | 4 ++-- config/locales/es-HN/activerecord.yml | 4 ++-- config/locales/es-MX/activerecord.yml | 8 ++++---- config/locales/es-NI/activerecord.yml | 4 ++-- config/locales/es-PA/activerecord.yml | 4 ++-- config/locales/es-PE/activerecord.yml | 4 ++-- config/locales/es-PR/activerecord.yml | 4 ++-- config/locales/es-PY/activerecord.yml | 4 ++-- config/locales/es-SV/activerecord.yml | 4 ++-- config/locales/es-UY/activerecord.yml | 4 ++-- config/locales/es-VE/activerecord.yml | 4 ++-- config/locales/fa-IR/activerecord.yml | 4 ++-- config/locales/fr/activerecord.yml | 8 ++++---- config/locales/gl/activerecord.yml | 8 ++++---- config/locales/id-ID/activerecord.yml | 4 ++-- config/locales/it/activerecord.yml | 8 ++++---- config/locales/nl/activerecord.yml | 6 +++--- config/locales/pl-PL/activerecord.yml | 8 ++++---- config/locales/pt-BR/activerecord.yml | 8 ++++---- config/locales/ru/activerecord.yml | 4 ++-- config/locales/sq-AL/activerecord.yml | 8 ++++---- config/locales/sv-SE/activerecord.yml | 8 ++++---- config/locales/tr-TR/activerecord.yml | 2 +- config/locales/val/activerecord.yml | 8 ++++---- config/locales/zh-CN/activerecord.yml | 8 ++++---- config/locales/zh-TW/activerecord.yml | 8 ++++---- 38 files changed, 102 insertions(+), 102 deletions(-) diff --git a/config/locales/ar/activerecord.yml b/config/locales/ar/activerecord.yml index 1c4d69c01..5f1ba2c00 100644 --- a/config/locales/ar/activerecord.yml +++ b/config/locales/ar/activerecord.yml @@ -86,12 +86,12 @@ ar: organization_name: "إذا كنت تقترح بإسم جماعي/منظمة, أو نيابة عن أشخاص آخرين, اكتب إسمها" image: "اقتراح صورة وصفية" image_title: "عنوان الصورة" - budget/investment/milestone: + milestone: status_id: "حالة الإستثمار الحالية (إختياري)" title: "العنوان" description: "الوصف (إختياري ان كان هناك حالة معينة)" publication_date: "تاريخ النشر" - budget/investment/status: + milestone/status: name: "الاسم" description: "الوصف (إختياري)" budget/heading: diff --git a/config/locales/ast/activerecord.yml b/config/locales/ast/activerecord.yml index 46ea2c973..07e57bfd2 100644 --- a/config/locales/ast/activerecord.yml +++ b/config/locales/ast/activerecord.yml @@ -7,7 +7,7 @@ ast: budget/investment: one: "Proyectu de inversión" other: "Proyectos d'inversión" - budget/investment/milestone: + milestone: one: "finxu" other: "finxos" comment: diff --git a/config/locales/ca/activerecord.yml b/config/locales/ca/activerecord.yml index 99c24dddd..121f343fa 100644 --- a/config/locales/ca/activerecord.yml +++ b/config/locales/ca/activerecord.yml @@ -10,7 +10,7 @@ ca: budget/investment: one: "Proposta d'inversió" other: "Propostes d'inversió" - budget/investment/milestone: + milestone: one: "fita" other: "fites" comment: diff --git a/config/locales/de-DE/activerecord.yml b/config/locales/de-DE/activerecord.yml index 0b61727e9..8032a3aff 100644 --- a/config/locales/de-DE/activerecord.yml +++ b/config/locales/de-DE/activerecord.yml @@ -10,10 +10,10 @@ de: budget/investment: one: "Ausgabenvorschlag" other: "Ausgabenvorschläge" - budget/investment/milestone: + milestone: one: "Meilenstein" other: "Meilensteine" - budget/investment/status: + milestone/status: one: "Status des Ausgabenvorschlags" other: "Status der Ausgabenvorschläge" comment: @@ -131,12 +131,12 @@ de: organization_name: "Wenn Sie einen Vorschlag im Namen einer Gruppe, Organisation oder mehreren Personen einreichen, nennen Sie bitte dessen/deren Name/n" image: "Beschreibendes Bild zum Ausgabenvorschlag" image_title: "Bildtitel" - budget/investment/milestone: + milestone: status_id: "Derzeitiger Status des Ausgabenvorschlags (optional)" title: "Titel" description: "Beschreibung (optional, wenn kein Status zugewiesen ist)" publication_date: "Datum der Veröffentlichung" - budget/investment/status: + milestone/status: name: "Name" description: "Beschreibung (optional)" budget/heading: diff --git a/config/locales/en-US/activerecord.yml b/config/locales/en-US/activerecord.yml index 28deaa039..0bf16fa71 100644 --- a/config/locales/en-US/activerecord.yml +++ b/config/locales/en-US/activerecord.yml @@ -1,10 +1,10 @@ en-US: activerecord: models: - budget/investment/milestone: + milestone: one: "Meilenstein" other: "Meilensteine" - budget/investment/status: + milestone/status: one: "Investitionsstatus, Anlagenstatus" other: "Investitionsstatus, Anlagenstatus" comment: diff --git a/config/locales/es-AR/activerecord.yml b/config/locales/es-AR/activerecord.yml index 23b50fca7..9e838c744 100644 --- a/config/locales/es-AR/activerecord.yml +++ b/config/locales/es-AR/activerecord.yml @@ -7,10 +7,10 @@ es-AR: budget/investment: one: "Proyecto de inversión" other: "Proyectos de inversión" - budget/investment/milestone: + milestone: one: "hito" other: "hitos" - budget/investment/status: + milestone/status: one: "Estado de Inversiones" other: "Estado de Inversiones" comment: @@ -113,12 +113,12 @@ es-AR: organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre" image: "Imagen descriptiva de la propuesta de inversión" image_title: "Título de la imagen" - budget/investment/milestone: + milestone: status_id: "Estado de inversión actual ( opcional)" title: "Título" description: "Descripción (opcional si hay estado asignado)" publication_date: "Fecha de publicación" - budget/investment/status: + milestone/status: name: "Nombre" description: "Descripción (opcional)" budget/heading: diff --git a/config/locales/es-BO/activerecord.yml b/config/locales/es-BO/activerecord.yml index 9eff5337e..878fd2c7d 100644 --- a/config/locales/es-BO/activerecord.yml +++ b/config/locales/es-BO/activerecord.yml @@ -7,7 +7,7 @@ es-BO: budget/investment: one: "Proyecto de inversión" other: "Proyectos de inversión" - budget/investment/milestone: + milestone: one: "hito" other: "hitos" comment: @@ -104,7 +104,7 @@ es-BO: organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre" image: "Imagen descriptiva de la propuesta de inversión" image_title: "Título de la imagen" - budget/investment/milestone: + milestone: title: "Título" publication_date: "Fecha de publicación" budget/heading: diff --git a/config/locales/es-CL/activerecord.yml b/config/locales/es-CL/activerecord.yml index 826b5101f..0bd35df38 100644 --- a/config/locales/es-CL/activerecord.yml +++ b/config/locales/es-CL/activerecord.yml @@ -10,10 +10,10 @@ es-CL: budget/investment: one: "Proyecto de inversión" other: "Proyectos de inversión" - budget/investment/milestone: + milestone: one: "hito" other: "hitos" - budget/investment/status: + milestone/status: one: "Estado de la inversión" other: "Estados de las inversiones" comment: @@ -128,12 +128,12 @@ es-CL: organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre" image: "Imagen descriptiva de la propuesta de inversión" image_title: "Título de la imagen" - budget/investment/milestone: + milestone: status_id: "Estado actual de la inversión (opcional)" title: "Título" description: "Descripción (opcional si hay una condición asignada)" publication_date: "Fecha de publicación" - budget/investment/status: + milestone/status: name: "Nombre" description: "Descripción (opcional)" budget/heading: diff --git a/config/locales/es-CO/activerecord.yml b/config/locales/es-CO/activerecord.yml index 41ebf026a..69cadde05 100644 --- a/config/locales/es-CO/activerecord.yml +++ b/config/locales/es-CO/activerecord.yml @@ -7,7 +7,7 @@ es-CO: budget/investment: one: "Proyecto de inversión" other: "Proyectos de inversión" - budget/investment/milestone: + milestone: one: "hito" other: "hitos" comment: @@ -104,7 +104,7 @@ es-CO: organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre" image: "Imagen descriptiva de la propuesta de inversión" image_title: "Título de la imagen" - budget/investment/milestone: + milestone: title: "Título" publication_date: "Fecha de publicación" budget/heading: diff --git a/config/locales/es-CR/activerecord.yml b/config/locales/es-CR/activerecord.yml index bc2bcff15..d24c27af4 100644 --- a/config/locales/es-CR/activerecord.yml +++ b/config/locales/es-CR/activerecord.yml @@ -7,7 +7,7 @@ es-CR: budget/investment: one: "Proyecto de inversión" other: "Proyectos de inversión" - budget/investment/milestone: + milestone: one: "hito" other: "hitos" comment: @@ -104,7 +104,7 @@ es-CR: organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre" image: "Imagen descriptiva de la propuesta de inversión" image_title: "Título de la imagen" - budget/investment/milestone: + milestone: title: "Título" publication_date: "Fecha de publicación" budget/heading: diff --git a/config/locales/es-DO/activerecord.yml b/config/locales/es-DO/activerecord.yml index e0cfcc982..21b0d65fa 100644 --- a/config/locales/es-DO/activerecord.yml +++ b/config/locales/es-DO/activerecord.yml @@ -7,7 +7,7 @@ es-DO: budget/investment: one: "Proyecto de inversión" other: "Proyectos de inversión" - budget/investment/milestone: + milestone: one: "hito" other: "hitos" comment: @@ -104,7 +104,7 @@ es-DO: organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre" image: "Imagen descriptiva de la propuesta de inversión" image_title: "Título de la imagen" - budget/investment/milestone: + milestone: title: "Título" publication_date: "Fecha de publicación" budget/heading: diff --git a/config/locales/es-EC/activerecord.yml b/config/locales/es-EC/activerecord.yml index d097a6eec..4540f0839 100644 --- a/config/locales/es-EC/activerecord.yml +++ b/config/locales/es-EC/activerecord.yml @@ -7,7 +7,7 @@ es-EC: budget/investment: one: "Proyecto de inversión" other: "Proyectos de inversión" - budget/investment/milestone: + milestone: one: "hito" other: "hitos" comment: @@ -104,7 +104,7 @@ es-EC: organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre" image: "Imagen descriptiva de la propuesta de inversión" image_title: "Título de la imagen" - budget/investment/milestone: + milestone: title: "Título" publication_date: "Fecha de publicación" budget/heading: diff --git a/config/locales/es-GT/activerecord.yml b/config/locales/es-GT/activerecord.yml index 5147d66da..1e9b19bf0 100644 --- a/config/locales/es-GT/activerecord.yml +++ b/config/locales/es-GT/activerecord.yml @@ -7,7 +7,7 @@ es-GT: budget/investment: one: "Proyecto de inversión" other: "Proyectos de inversión" - budget/investment/milestone: + milestone: one: "hito" other: "hitos" comment: @@ -104,7 +104,7 @@ es-GT: organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre" image: "Imagen descriptiva de la propuesta de inversión" image_title: "Título de la imagen" - budget/investment/milestone: + milestone: title: "Título" publication_date: "Fecha de publicación" budget/heading: diff --git a/config/locales/es-HN/activerecord.yml b/config/locales/es-HN/activerecord.yml index 483778186..7d597d531 100644 --- a/config/locales/es-HN/activerecord.yml +++ b/config/locales/es-HN/activerecord.yml @@ -7,7 +7,7 @@ es-HN: budget/investment: one: "Proyecto de inversión" other: "Proyectos de inversión" - budget/investment/milestone: + milestone: one: "hito" other: "hitos" comment: @@ -104,7 +104,7 @@ es-HN: organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre" image: "Imagen descriptiva de la propuesta de inversión" image_title: "Título de la imagen" - budget/investment/milestone: + milestone: title: "Título" publication_date: "Fecha de publicación" budget/heading: diff --git a/config/locales/es-MX/activerecord.yml b/config/locales/es-MX/activerecord.yml index 7d0d80da0..2e64e6124 100644 --- a/config/locales/es-MX/activerecord.yml +++ b/config/locales/es-MX/activerecord.yml @@ -10,10 +10,10 @@ es-MX: budget/investment: one: "Proyecto de inversión" other: "Proyectos de inversión" - budget/investment/milestone: + milestone: one: "hito" other: "hitos" - budget/investment/status: + milestone/status: one: "Estado de inversión" other: "Estados de inversión" comment: @@ -128,11 +128,11 @@ es-MX: organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre" image: "Imagen descriptiva de la propuesta de inversión" image_title: "Título de la imagen" - budget/investment/milestone: + milestone: title: "Título" description: "Descripción (opcional si cuenta con un estado asignado)" publication_date: "Fecha de publicación" - budget/investment/status: + milestone/status: name: "Nombre" description: "Descripción (opcional)" budget/heading: diff --git a/config/locales/es-NI/activerecord.yml b/config/locales/es-NI/activerecord.yml index d3b6d8242..c9aad963a 100644 --- a/config/locales/es-NI/activerecord.yml +++ b/config/locales/es-NI/activerecord.yml @@ -7,7 +7,7 @@ es-NI: budget/investment: one: "Proyecto de inversión" other: "Proyectos de inversión" - budget/investment/milestone: + milestone: one: "hito" other: "hitos" comment: @@ -104,7 +104,7 @@ es-NI: organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre" image: "Imagen descriptiva de la propuesta de inversión" image_title: "Título de la imagen" - budget/investment/milestone: + milestone: title: "Título" publication_date: "Fecha de publicación" budget/heading: diff --git a/config/locales/es-PA/activerecord.yml b/config/locales/es-PA/activerecord.yml index 95f617cbd..eac061779 100644 --- a/config/locales/es-PA/activerecord.yml +++ b/config/locales/es-PA/activerecord.yml @@ -7,7 +7,7 @@ es-PA: budget/investment: one: "Proyecto de inversión" other: "Proyectos de inversión" - budget/investment/milestone: + milestone: one: "hito" other: "hitos" comment: @@ -104,7 +104,7 @@ es-PA: organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre" image: "Imagen descriptiva de la propuesta de inversión" image_title: "Título de la imagen" - budget/investment/milestone: + milestone: title: "Título" publication_date: "Fecha de publicación" budget/heading: diff --git a/config/locales/es-PE/activerecord.yml b/config/locales/es-PE/activerecord.yml index 4604a2868..8569e3bfc 100644 --- a/config/locales/es-PE/activerecord.yml +++ b/config/locales/es-PE/activerecord.yml @@ -7,7 +7,7 @@ es-PE: budget/investment: one: "Proyecto de inversión" other: "Proyectos de inversión" - budget/investment/milestone: + milestone: one: "hito" other: "hitos" comment: @@ -104,7 +104,7 @@ es-PE: organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre" image: "Imagen descriptiva de la propuesta de inversión" image_title: "Título de la imagen" - budget/investment/milestone: + milestone: title: "Título" publication_date: "Fecha de publicación" budget/heading: diff --git a/config/locales/es-PR/activerecord.yml b/config/locales/es-PR/activerecord.yml index cf38eaba8..08d1a8662 100644 --- a/config/locales/es-PR/activerecord.yml +++ b/config/locales/es-PR/activerecord.yml @@ -7,7 +7,7 @@ es-PR: budget/investment: one: "Proyecto de inversión" other: "Proyectos de inversión" - budget/investment/milestone: + milestone: one: "hito" other: "hitos" comment: @@ -104,7 +104,7 @@ es-PR: organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre" image: "Imagen descriptiva de la propuesta de inversión" image_title: "Título de la imagen" - budget/investment/milestone: + milestone: title: "Título" publication_date: "Fecha de publicación" budget/heading: diff --git a/config/locales/es-PY/activerecord.yml b/config/locales/es-PY/activerecord.yml index fc3dd64b4..27150dfca 100644 --- a/config/locales/es-PY/activerecord.yml +++ b/config/locales/es-PY/activerecord.yml @@ -7,7 +7,7 @@ es-PY: budget/investment: one: "Proyecto de inversión" other: "Proyectos de inversión" - budget/investment/milestone: + milestone: one: "hito" other: "hitos" comment: @@ -104,7 +104,7 @@ es-PY: organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre" image: "Imagen descriptiva de la propuesta de inversión" image_title: "Título de la imagen" - budget/investment/milestone: + milestone: title: "Título" publication_date: "Fecha de publicación" budget/heading: diff --git a/config/locales/es-SV/activerecord.yml b/config/locales/es-SV/activerecord.yml index a4c3430c6..594d2003b 100644 --- a/config/locales/es-SV/activerecord.yml +++ b/config/locales/es-SV/activerecord.yml @@ -7,7 +7,7 @@ es-SV: budget/investment: one: "Proyecto de inversión" other: "Proyectos de inversión" - budget/investment/milestone: + milestone: one: "hito" other: "hitos" comment: @@ -104,7 +104,7 @@ es-SV: organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre" image: "Imagen descriptiva de la propuesta de inversión" image_title: "Título de la imagen" - budget/investment/milestone: + milestone: title: "Título" publication_date: "Fecha de publicación" budget/heading: diff --git a/config/locales/es-UY/activerecord.yml b/config/locales/es-UY/activerecord.yml index e8348ed68..ffa5059fd 100644 --- a/config/locales/es-UY/activerecord.yml +++ b/config/locales/es-UY/activerecord.yml @@ -7,7 +7,7 @@ es-UY: budget/investment: one: "Proyecto de inversión" other: "Proyectos de inversión" - budget/investment/milestone: + milestone: one: "hito" other: "hitos" comment: @@ -104,7 +104,7 @@ es-UY: organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre" image: "Imagen descriptiva de la propuesta de inversión" image_title: "Título de la imagen" - budget/investment/milestone: + milestone: title: "Título" publication_date: "Fecha de publicación" budget/heading: diff --git a/config/locales/es-VE/activerecord.yml b/config/locales/es-VE/activerecord.yml index 13e76a7be..7878f5019 100644 --- a/config/locales/es-VE/activerecord.yml +++ b/config/locales/es-VE/activerecord.yml @@ -7,7 +7,7 @@ es-VE: budget/investment: one: "Proyecto de inversión" other: "Proyectos de inversión" - budget/investment/milestone: + milestone: one: "hito" other: "hitos" comment: @@ -104,7 +104,7 @@ es-VE: organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre" image: "Imagen descriptiva de la propuesta de inversión" image_title: "Título de la imagen" - budget/investment/milestone: + milestone: title: "Título" publication_date: "Fecha de publicación" budget/heading: diff --git a/config/locales/fa-IR/activerecord.yml b/config/locales/fa-IR/activerecord.yml index e7baab9b0..4a417cc80 100644 --- a/config/locales/fa-IR/activerecord.yml +++ b/config/locales/fa-IR/activerecord.yml @@ -10,7 +10,7 @@ fa: budget/investment: one: "سرمایه گذاری" other: "سرمایه گذاری ها" - budget/investment/milestone: + milestone: one: "نقطه عطف" other: "نقاط عطف" comment: @@ -119,7 +119,7 @@ fa: organization_name: "اگر شما به نام یک گروه / سازمان، یا از طرف افراد بیشتری پیشنهاد می کنید، نام آنها را بنویسید." image: "تصویر طرح توصیفی" image_title: "عنوان تصویر" - budget/investment/milestone: + milestone: title: "عنوان" publication_date: "تاریخ انتشار" budget/heading: diff --git a/config/locales/fr/activerecord.yml b/config/locales/fr/activerecord.yml index 0b9540d10..247cdffb5 100644 --- a/config/locales/fr/activerecord.yml +++ b/config/locales/fr/activerecord.yml @@ -10,10 +10,10 @@ fr: budget/investment: one: "Projet d'investissement" other: "Projets d'investissement" - budget/investment/milestone: + milestone: one: "jalon" other: "jalons" - budget/investment/status: + milestone/status: one: "Statut d’investissement" other: "Statuts d’investissement" comment: @@ -128,12 +128,12 @@ fr: organization_name: "Si votre proposition se fait au nom d'un collectif ou d'une organisation, renseignez leur nom" image: "Image descriptive de la proposition" image_title: "Titre de l'image" - budget/investment/milestone: + milestone: status_id: "Statut actuel de l'investissement (facultatif)" title: "Titre" description: "Description (facultative si un statut est affecté)" publication_date: "Date de publication" - budget/investment/status: + milestone/status: name: "Nom" description: "Description (facultative)" budget/heading: diff --git a/config/locales/gl/activerecord.yml b/config/locales/gl/activerecord.yml index bef16f4db..725778290 100644 --- a/config/locales/gl/activerecord.yml +++ b/config/locales/gl/activerecord.yml @@ -10,10 +10,10 @@ gl: budget/investment: one: "Investimento" other: "Investimentos" - budget/investment/milestone: + milestone: one: "fito" other: "fitos" - budget/investment/status: + milestone/status: one: "Estado do investimento" other: "Estado dos investimentos" comment: @@ -131,12 +131,12 @@ gl: organization_name: "Se estás a propor no nome dunha organización, dun colectivo ou de mais xente, escribe o seu nome" image: "Imaxe descritiva da proposta" image_title: "Título da imaxe" - budget/investment/milestone: + milestone: status_id: "Estado do investimento actual (opcional)" title: "Título" description: "Descrición (opcional se hai unha condición asignada)" publication_date: "Data de publicación" - budget/investment/status: + milestone/status: name: "Nome" description: "Descrición (opcional)" budget/heading: diff --git a/config/locales/id-ID/activerecord.yml b/config/locales/id-ID/activerecord.yml index 66b109b6b..eae0f72cf 100644 --- a/config/locales/id-ID/activerecord.yml +++ b/config/locales/id-ID/activerecord.yml @@ -7,7 +7,7 @@ id: other: "Anggaran" budget/investment: other: "Investasi" - budget/investment/milestone: + milestone: other: "batu peringatan" comment: other: "Komentar" @@ -81,7 +81,7 @@ id: organization_name: "Jika Anda usulkan dalam nama kolektif/organisasi, atau atas nama orang lain, menulis namanya" image: "Gambar deskriptif proposal" image_title: "Judul gambar" - budget/investment/milestone: + milestone: title: "Judul" publication_date: "Tanggal publikasi" budget/heading: diff --git a/config/locales/it/activerecord.yml b/config/locales/it/activerecord.yml index 7de92dc08..84c494e0b 100644 --- a/config/locales/it/activerecord.yml +++ b/config/locales/it/activerecord.yml @@ -10,10 +10,10 @@ it: budget/investment: one: "Investimento" other: "Investimenti" - budget/investment/milestone: + milestone: one: "traguardo" other: "traguardi" - budget/investment/status: + milestone/status: one: "Status dell’investimento" other: "Status dell’investimento" comment: @@ -128,12 +128,12 @@ it: organization_name: "Se presenti una proposta a nome di un collettivo o di un’organizzazione, ovvero per conto di più persone, indicane il nome" image: "Immagine descrittiva della proposta" image_title: "Titolo dell’immagine" - budget/investment/milestone: + milestone: status_id: "Stato attuale dell’investimento (facoltativo)" title: "Titolo" description: "Descrizione (facoltativa se c’è gia uno stato assegnato)" publication_date: "Data di pubblicazione" - budget/investment/status: + milestone/status: name: "Nome" description: "Descrizione (facoltativa)" budget/heading: diff --git a/config/locales/nl/activerecord.yml b/config/locales/nl/activerecord.yml index 7cc9b19c3..559462b88 100644 --- a/config/locales/nl/activerecord.yml +++ b/config/locales/nl/activerecord.yml @@ -10,7 +10,7 @@ nl: budget/investment: one: "Investerning" other: "Investeringen" - budget/investment/milestone: + milestone: one: "mijlpaal" other: "mijlpalen" comment: @@ -122,12 +122,12 @@ nl: organization_name: "Als je een voorstel doet uit naam van een collectief/organisatie, voer dan hier de naam in" image: "Afbeelding ter omschrijving van het voorstel" image_title: "Naam van de afbeelding" - budget/investment/milestone: + milestone: status_id: "Huidige investeringsstatus (optioneel)" title: "Titel" description: "Omschrijving" publication_date: "Publicatiedatum" - budget/investment/status: + milestone/status: name: "Naam" description: "Beschrijving (optioneel)" budget/heading: diff --git a/config/locales/pl-PL/activerecord.yml b/config/locales/pl-PL/activerecord.yml index c16b494d1..e8a63da98 100644 --- a/config/locales/pl-PL/activerecord.yml +++ b/config/locales/pl-PL/activerecord.yml @@ -6,12 +6,12 @@ pl: few: "Inwestycje" many: "Inwestycji" other: "Inwestycji" - budget/investment/milestone: + milestone: one: "kamień milowy" few: "kamienie milowe" many: "kamieni milowych" other: "kamieni milowych" - budget/investment/status: + milestone/status: one: "Etap inwestycji" few: "Etapy inwestycji" many: "Etapów inwestycji" @@ -158,12 +158,12 @@ pl: organization_name: "Jeśli wnioskujesz w imieniu zespołu/organizacji, lub w imieniu większej liczby osób, wpisz ich nazwę" image: "Opisowy obraz wniosku" image_title: "Tytuł obrazu" - budget/investment/milestone: + milestone: status_id: "Bieżący stan inwestycji (opcjonalnie)" title: "Tytuł" description: "Opis (opcjonalnie, jeśli istnieje przydzielony stan)" publication_date: "Data publikacji" - budget/investment/status: + milestone/status: name: "Nazwa" description: "Opis (opcjonalnie)" budget/heading: diff --git a/config/locales/pt-BR/activerecord.yml b/config/locales/pt-BR/activerecord.yml index 93756f2fc..91fcd3dbc 100644 --- a/config/locales/pt-BR/activerecord.yml +++ b/config/locales/pt-BR/activerecord.yml @@ -10,10 +10,10 @@ pt-BR: budget/investment: one: "Investimento" other: "Investimentos" - budget/investment/milestone: + milestone: one: "Marco" other: "Marcos" - budget/investment/status: + milestone/status: one: "Status de investimento" other: "Status dos investimentos" comment: @@ -128,12 +128,12 @@ pt-BR: organization_name: "Se você está propondo em nome de um coletivo / organização, ou em nome de mais pessoas, escreva seu nome" image: "Imagem descritiva da proposta" image_title: "Título da imagem" - budget/investment/milestone: + milestone: status_id: "Status atual do investimento (opcional)" title: "Título" description: "Descrição (opcional, se houver uma condição atribuída)" publication_date: "Data de publicação" - budget/investment/status: + milestone/status: name: "Nome" description: "Descrição (opcional)" budget/heading: diff --git a/config/locales/ru/activerecord.yml b/config/locales/ru/activerecord.yml index efecc08c2..a97e2e69d 100644 --- a/config/locales/ru/activerecord.yml +++ b/config/locales/ru/activerecord.yml @@ -22,12 +22,12 @@ ru: organization_name: "Если вы делаете предложение от имени коллектива/организации или от имени большего числа людей, напишите его название" image: "Иллюстративное изображение предложения" image_title: "Название изображения" - budget/investment/milestone: + milestone: status_id: "Текущий инвестиционный статус (опционально)" title: "Название" description: "Описание (опционально, если присвоен статус)" publication_date: "Дата публикации" - budget/investment/status: + milestone/status: name: "Имя" description: "Описание (опционально)" budget/heading: diff --git a/config/locales/sq-AL/activerecord.yml b/config/locales/sq-AL/activerecord.yml index 8eaf2af24..e8882ffcc 100644 --- a/config/locales/sq-AL/activerecord.yml +++ b/config/locales/sq-AL/activerecord.yml @@ -10,10 +10,10 @@ sq: budget/investment: one: "Investim" other: "Investim" - budget/investment/milestone: + milestone: one: "moment historik" other: "milestone" - budget/investment/status: + milestone/status: one: "Statusi investimeve" other: "Statusi investimeve" comment: @@ -128,12 +128,12 @@ sq: organization_name: "Nëse propozoni në emër të një kolektivi / organizate, ose në emër të më shumë njerëzve, shkruani emrin e tij" image: "Imazhi përshkrues i propozimit" image_title: "Titulli i imazhit" - budget/investment/milestone: + milestone: status_id: "Statusi aktual i investimit (opsional)" title: "Titull" description: "Përshkrimi (opsional nëse ka status të caktuar)" publication_date: "Data e publikimit" - budget/investment/status: + milestone/status: name: "Emri" description: "Përshkrimi (opsional)" budget/heading: diff --git a/config/locales/sv-SE/activerecord.yml b/config/locales/sv-SE/activerecord.yml index 47f0e9a49..4dd7cf5c6 100644 --- a/config/locales/sv-SE/activerecord.yml +++ b/config/locales/sv-SE/activerecord.yml @@ -10,10 +10,10 @@ sv: budget/investment: one: "Budgetförslag" other: "Budgetförslag" - budget/investment/milestone: + milestone: one: "milstolpe" other: "milstolpar" - budget/investment/status: + milestone/status: one: "Budgetförslagets status" other: "Budgetförslagens status" comment: @@ -128,12 +128,12 @@ sv: organization_name: "Organisation eller grupp i vars namn du lämnar förslaget" image: "Förklarande bild till förslaget" image_title: "Bildtext" - budget/investment/milestone: + milestone: status_id: "Nuvarande status för budgetförslag (frivilligt fält)" title: "Titel" description: "Beskrivning (frivilligt fält om projektets status har ställts in)" publication_date: "Publiceringsdatum" - budget/investment/status: + milestone/status: name: "Namn" description: "Beskrivning (frivilligt fält)" budget/heading: diff --git a/config/locales/tr-TR/activerecord.yml b/config/locales/tr-TR/activerecord.yml index 160579200..46e4fd8cd 100644 --- a/config/locales/tr-TR/activerecord.yml +++ b/config/locales/tr-TR/activerecord.yml @@ -10,7 +10,7 @@ tr: budget/investment: one: "yatırım" other: "Yatırımlar" - budget/investment/milestone: + milestone: one: "kilometre taşı" other: "kilometre taşları" comment: diff --git a/config/locales/val/activerecord.yml b/config/locales/val/activerecord.yml index 7231bd73f..eac2133b8 100644 --- a/config/locales/val/activerecord.yml +++ b/config/locales/val/activerecord.yml @@ -10,10 +10,10 @@ val: budget/investment: one: "Proposta d'inversió" other: "Propostes d'inversió" - budget/investment/milestone: + milestone: one: "fita" other: "fites" - budget/investment/status: + milestone/status: one: "Estat de la proposta" other: "Estat de les propostes" comment: @@ -131,12 +131,12 @@ val: organization_name: "Si estàs proposant en nom d'una associació o col·lectiu, escriu el seu nom" image: "Imatge descriptiva de la proposta d'inversió" image_title: "Títol de la imatge" - budget/investment/milestone: + milestone: status_id: "Estat actual de la proposta (opcional)" title: "Títol" description: "Descripció (opcional si hi ha un estat asignat)" publication_date: "Data de publicació" - budget/investment/status: + milestone/status: name: "Nom" description: "Descripció (opcional)" budget/heading: diff --git a/config/locales/zh-CN/activerecord.yml b/config/locales/zh-CN/activerecord.yml index 90f1f94ec..ca8972641 100644 --- a/config/locales/zh-CN/activerecord.yml +++ b/config/locales/zh-CN/activerecord.yml @@ -7,9 +7,9 @@ zh-CN: other: "预算" budget/investment: other: "投资" - budget/investment/milestone: + milestone: other: "里程碑" - budget/investment/status: + milestone/status: other: "投资状态" comment: other: "意见" @@ -93,12 +93,12 @@ zh-CN: organization_name: "如果你是以集体/组织的名义或者代表更多的人提出建议,写下它的名字。" image: "建议说明性图像" image_title: "图像标题" - budget/investment/milestone: + milestone: status_id: "当前投资状况(可选)" title: "标题" description: "说明(如果指定了状态,则可选)" publication_date: "出版日期" - budget/investment/status: + milestone/status: name: "名字" description: "说明(可选)" budget/heading: diff --git a/config/locales/zh-TW/activerecord.yml b/config/locales/zh-TW/activerecord.yml index cebb171a9..1840ee3f7 100644 --- a/config/locales/zh-TW/activerecord.yml +++ b/config/locales/zh-TW/activerecord.yml @@ -7,9 +7,9 @@ zh-TW: other: "預算" budget/investment: other: "投資" - budget/investment/milestone: + milestone: other: "里程碑" - budget/investment/status: + milestone/status: other: "投資狀態" comment: other: "評論" @@ -93,12 +93,12 @@ zh-TW: organization_name: "如果您以集體/組織的名義,或代表多人提出建議,請寫下其名稱" image: "建議說明性圖像" image_title: "圖像標題" - budget/investment/milestone: + milestone: status_id: "當前投資狀況 (可選擇填寫)" title: "標題" description: "說明 (如果已經指定了狀態, 則可選擇填寫)" publication_date: "出版日期" - budget/investment/status: + milestone/status: name: "名字" description: "說明 (可選擇填寫)" budget/heading: From 85ac4e6c222e8feca584ec01211f449829fbd2ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 22 Nov 2018 01:29:36 +0100 Subject: [PATCH 24/64] Use `Date.current` instead of `Date.today` Using `Date.today` was making the spec fail around midnight. --- spec/lib/tasks/milestones_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/lib/tasks/milestones_spec.rb b/spec/lib/tasks/milestones_spec.rb index 56507d02b..f4c9dd052 100644 --- a/spec/lib/tasks/milestones_spec.rb +++ b/spec/lib/tasks/milestones_spec.rb @@ -47,7 +47,7 @@ describe "Milestones tasks" do expect(status.description).to eq "Good" expect(status.hidden_at).to be nil expect(status.created_at.to_date).to eq Date.yesterday - expect(status.updated_at.to_date).to eq Date.today + expect(status.updated_at.to_date).to eq Date.current end it "migrates milestones" do @@ -63,7 +63,7 @@ describe "Milestones tasks" do expect(milestone.publication_date).to eq Date.yesterday expect(milestone.status_id).to eq Milestone::Status.first.id expect(milestone.created_at.to_date).to eq Date.yesterday - expect(milestone.updated_at.to_date).to eq Date.today + expect(milestone.updated_at.to_date).to eq Date.current end it "Updates the primary key sequence correctly" do From ea9576096bd9f1df267ccd63fcc9f7cd7c9b7d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 30 Nov 2018 17:28:59 +0100 Subject: [PATCH 25/64] Don't load tasks if they're already loaded We were having problems under certain conditions with Travis and Knapsack where tasks were still being loaded twice and so they were being executed twice. --- Rakefile | 2 +- spec/rails_helper.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index 13a99536b..c4d34f626 100644 --- a/Rakefile +++ b/Rakefile @@ -3,5 +3,5 @@ require File.expand_path('../config/application', __FILE__) -Rails.application.load_tasks +Rails.application.load_tasks if Rake::Task.tasks.empty? KnapsackPro.load_tasks if defined?(KnapsackPro) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index c90695dca..c3772d5d8 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -12,7 +12,7 @@ require 'capybara/rails' require 'capybara/rspec' require 'selenium/webdriver' -Rails.application.load_tasks +Rails.application.load_tasks if Rake::Task.tasks.empty? I18n.default_locale = :en include Warden::Test::Helpers From 45a41a7528123e01fa2b1369602fb4c1045fb170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 20 Nov 2018 18:26:19 +0100 Subject: [PATCH 26/64] Rename Admin::Proposals to Admin::HiddenProposals The same way we do it with users and budget investments. --- ...ller.rb => hidden_proposals_controller.rb} | 2 +- app/helpers/admin_helper.rb | 2 +- app/views/admin/_menu.html.erb | 4 +-- .../index.html.erb | 10 +++---- config/i18n-tasks.yml | 2 +- config/locales/de-DE/admin.yml | 2 +- config/locales/en/admin.yml | 2 +- config/locales/es-AR/admin.yml | 2 +- config/locales/es-BO/admin.yml | 2 +- config/locales/es-CL/admin.yml | 2 +- config/locales/es-CO/admin.yml | 2 +- config/locales/es-CR/admin.yml | 2 +- config/locales/es-DO/admin.yml | 2 +- config/locales/es-EC/admin.yml | 2 +- config/locales/es-GT/admin.yml | 2 +- config/locales/es-HN/admin.yml | 2 +- config/locales/es-MX/admin.yml | 2 +- config/locales/es-NI/admin.yml | 2 +- config/locales/es-PA/admin.yml | 2 +- config/locales/es-PE/admin.yml | 2 +- config/locales/es-PR/admin.yml | 2 +- config/locales/es-PY/admin.yml | 2 +- config/locales/es-SV/admin.yml | 2 +- config/locales/es-UY/admin.yml | 2 +- config/locales/es-VE/admin.yml | 2 +- config/locales/es/admin.yml | 2 +- config/locales/fa-IR/admin.yml | 2 +- config/locales/fr/admin.yml | 2 +- config/locales/gl/admin.yml | 2 +- config/locales/he/admin.yml | 2 +- config/locales/id-ID/admin.yml | 2 +- config/locales/it/admin.yml | 2 +- config/locales/nl/admin.yml | 2 +- config/locales/pl-PL/admin.yml | 2 +- config/locales/pt-BR/admin.yml | 2 +- config/locales/sq-AL/admin.yml | 2 +- config/locales/sv-SE/admin.yml | 2 +- config/locales/val/admin.yml | 2 +- config/locales/zh-CN/admin.yml | 2 +- config/locales/zh-TW/admin.yml | 2 +- config/routes/admin.rb | 2 +- spec/features/admin/activity_spec.rb | 2 +- ...osals_spec.rb => hidden_proposals_spec.rb} | 26 +++++++++---------- 43 files changed, 60 insertions(+), 60 deletions(-) rename app/controllers/admin/{proposals_controller.rb => hidden_proposals_controller.rb} (92%) rename app/views/admin/{proposals => hidden_proposals}/index.html.erb (82%) rename spec/features/admin/{proposals_spec.rb => hidden_proposals_spec.rb} (79%) diff --git a/app/controllers/admin/proposals_controller.rb b/app/controllers/admin/hidden_proposals_controller.rb similarity index 92% rename from app/controllers/admin/proposals_controller.rb rename to app/controllers/admin/hidden_proposals_controller.rb index dbc09b3da..f6b39829d 100644 --- a/app/controllers/admin/proposals_controller.rb +++ b/app/controllers/admin/hidden_proposals_controller.rb @@ -1,4 +1,4 @@ -class Admin::ProposalsController < Admin::BaseController +class Admin::HiddenProposalsController < Admin::BaseController include FeatureFlags has_filters %w{without_confirmed_hide all with_confirmed_hide}, only: :index diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 0856ff87b..d0f3e5684 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -21,7 +21,7 @@ module AdminHelper end def menu_moderated_content? - ["proposals", "debates", "comments", "hidden_users", "activity", "hidden_budget_investments"].include?(controller_name) && controller.class.parent != Admin::Legislation + ["hidden_proposals", "debates", "comments", "hidden_users", "activity", "hidden_budget_investments"].include?(controller_name) && controller.class.parent != Admin::Legislation end def menu_budget? diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 911bc0713..841d64a4f 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -144,8 +144,8 @@
      > <% if feature?(:proposals) %> -
    • > - <%= link_to t("admin.menu.hidden_proposals"), admin_proposals_path %> +
    • > + <%= link_to t("admin.menu.hidden_proposals"), admin_hidden_proposals_path %>
    • <% end %> diff --git a/app/views/admin/proposals/index.html.erb b/app/views/admin/hidden_proposals/index.html.erb similarity index 82% rename from app/views/admin/proposals/index.html.erb rename to app/views/admin/hidden_proposals/index.html.erb index 0f94e276f..8be956a1d 100644 --- a/app/views/admin/proposals/index.html.erb +++ b/app/views/admin/hidden_proposals/index.html.erb @@ -1,7 +1,7 @@ -

      <%= t("admin.proposals.index.title") %>

      +

      <%= t("admin.hidden_proposals.index.title") %>

      <%= t("admin.shared.moderated_content") %>

      -<%= render 'shared/filter_subnav', i18n_namespace: "admin.proposals.index" %> +<%= render 'shared/filter_subnav', i18n_namespace: "admin.hidden_proposals.index" %> <% if @proposals.any? %>

      <%= page_entries_info @proposals %>

      @@ -33,13 +33,13 @@ <%= link_to t("admin.actions.restore"), - restore_admin_proposal_path(proposal, request.query_parameters), + restore_admin_hidden_proposal_path(proposal, request.query_parameters), method: :put, data: { confirm: t("admin.actions.confirm") }, class: "button hollow warning" %> <% unless proposal.confirmed_hide? %> <%= link_to t("admin.actions.confirm_hide"), - confirm_hide_admin_proposal_path(proposal, request.query_parameters), + confirm_hide_admin_hidden_proposal_path(proposal, request.query_parameters), method: :put, class: "button" %> <% end %> @@ -52,6 +52,6 @@ <%= paginate @proposals %> <% else %>
      - <%= t("admin.proposals.index.no_hidden_proposals") %> + <%= t("admin.hidden_proposals.index.no_hidden_proposals") %>
      <% end %> diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index cef2c8f97..4b683e7fd 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -128,7 +128,7 @@ ignore_unused: - 'admin.comments.index.filter*' - 'admin.banners.index.filters.*' - 'admin.debates.index.filter*' - - 'admin.proposals.index.filter*' + - 'admin.hidden_proposals.index.filter*' - 'admin.proposal_notifications.index.filter*' - 'admin.budgets.index.filter*' - 'admin.budget_investments.index.filter*' diff --git a/config/locales/de-DE/admin.yml b/config/locales/de-DE/admin.yml index 97d982f81..442617b6f 100644 --- a/config/locales/de-DE/admin.yml +++ b/config/locales/de-DE/admin.yml @@ -1004,7 +1004,7 @@ de: search: title: Organisationen suchen no_results: Keine Organisationen gefunden. - proposals: + hidden_proposals: index: filter: Filter filters: diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 6ee435c55..0e9ca294e 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -1032,7 +1032,7 @@ en: search: title: Search Organisations no_results: No organizations found. - proposals: + hidden_proposals: index: filter: Filter filters: diff --git a/config/locales/es-AR/admin.yml b/config/locales/es-AR/admin.yml index 2b3def5f7..ea6850dd3 100644 --- a/config/locales/es-AR/admin.yml +++ b/config/locales/es-AR/admin.yml @@ -906,7 +906,7 @@ es-AR: search: title: Buscar Organizaciones no_results: No se han encontrado organizaciones. - proposals: + hidden_proposals: index: filter: Filtro filters: diff --git a/config/locales/es-BO/admin.yml b/config/locales/es-BO/admin.yml index 806516882..afb2fefdd 100644 --- a/config/locales/es-BO/admin.yml +++ b/config/locales/es-BO/admin.yml @@ -711,7 +711,7 @@ es-BO: search: title: Buscar Organizaciones no_results: No se han encontrado organizaciones. - proposals: + hidden_proposals: index: filter: Filtro filters: diff --git a/config/locales/es-CL/admin.yml b/config/locales/es-CL/admin.yml index f47074f48..04f8472cd 100644 --- a/config/locales/es-CL/admin.yml +++ b/config/locales/es-CL/admin.yml @@ -841,7 +841,7 @@ es-CL: search: title: Buscar Organizaciones no_results: No se han encontrado organizaciones. - proposals: + hidden_proposals: index: filter: Filtro filters: diff --git a/config/locales/es-CO/admin.yml b/config/locales/es-CO/admin.yml index 793ec0af2..8f34dfe18 100644 --- a/config/locales/es-CO/admin.yml +++ b/config/locales/es-CO/admin.yml @@ -711,7 +711,7 @@ es-CO: search: title: Buscar Organizaciones no_results: No se han encontrado organizaciones. - proposals: + hidden_proposals: index: filter: Filtro filters: diff --git a/config/locales/es-CR/admin.yml b/config/locales/es-CR/admin.yml index 353036c46..965b7c0ad 100644 --- a/config/locales/es-CR/admin.yml +++ b/config/locales/es-CR/admin.yml @@ -711,7 +711,7 @@ es-CR: search: title: Buscar Organizaciones no_results: No se han encontrado organizaciones. - proposals: + hidden_proposals: index: filter: Filtro filters: diff --git a/config/locales/es-DO/admin.yml b/config/locales/es-DO/admin.yml index 03c35998d..15248078f 100644 --- a/config/locales/es-DO/admin.yml +++ b/config/locales/es-DO/admin.yml @@ -711,7 +711,7 @@ es-DO: search: title: Buscar Organizaciones no_results: No se han encontrado organizaciones. - proposals: + hidden_proposals: index: filter: Filtro filters: diff --git a/config/locales/es-EC/admin.yml b/config/locales/es-EC/admin.yml index 334585fe8..86e3e5759 100644 --- a/config/locales/es-EC/admin.yml +++ b/config/locales/es-EC/admin.yml @@ -711,7 +711,7 @@ es-EC: search: title: Buscar Organizaciones no_results: No se han encontrado organizaciones. - proposals: + hidden_proposals: index: filter: Filtro filters: diff --git a/config/locales/es-GT/admin.yml b/config/locales/es-GT/admin.yml index d974c4884..2e17a78cc 100644 --- a/config/locales/es-GT/admin.yml +++ b/config/locales/es-GT/admin.yml @@ -711,7 +711,7 @@ es-GT: search: title: Buscar Organizaciones no_results: No se han encontrado organizaciones. - proposals: + hidden_proposals: index: filter: Filtro filters: diff --git a/config/locales/es-HN/admin.yml b/config/locales/es-HN/admin.yml index 33951812a..e1c75fc71 100644 --- a/config/locales/es-HN/admin.yml +++ b/config/locales/es-HN/admin.yml @@ -711,7 +711,7 @@ es-HN: search: title: Buscar Organizaciones no_results: No se han encontrado organizaciones. - proposals: + hidden_proposals: index: filter: Filtro filters: diff --git a/config/locales/es-MX/admin.yml b/config/locales/es-MX/admin.yml index 8196084af..e1828cbf9 100644 --- a/config/locales/es-MX/admin.yml +++ b/config/locales/es-MX/admin.yml @@ -711,7 +711,7 @@ es-MX: search: title: Buscar Organizaciones no_results: No se han encontrado organizaciones. - proposals: + hidden_proposals: index: filter: Filtro filters: diff --git a/config/locales/es-NI/admin.yml b/config/locales/es-NI/admin.yml index 45235417d..3f810fdf9 100644 --- a/config/locales/es-NI/admin.yml +++ b/config/locales/es-NI/admin.yml @@ -711,7 +711,7 @@ es-NI: search: title: Buscar Organizaciones no_results: No se han encontrado organizaciones. - proposals: + hidden_proposals: index: filter: Filtro filters: diff --git a/config/locales/es-PA/admin.yml b/config/locales/es-PA/admin.yml index e9483eb97..cce514212 100644 --- a/config/locales/es-PA/admin.yml +++ b/config/locales/es-PA/admin.yml @@ -711,7 +711,7 @@ es-PA: search: title: Buscar Organizaciones no_results: No se han encontrado organizaciones. - proposals: + hidden_proposals: index: filter: Filtro filters: diff --git a/config/locales/es-PE/admin.yml b/config/locales/es-PE/admin.yml index d528b657e..dec901512 100644 --- a/config/locales/es-PE/admin.yml +++ b/config/locales/es-PE/admin.yml @@ -711,7 +711,7 @@ es-PE: search: title: Buscar Organizaciones no_results: No se han encontrado organizaciones. - proposals: + hidden_proposals: index: filter: Filtro filters: diff --git a/config/locales/es-PR/admin.yml b/config/locales/es-PR/admin.yml index 64eaa5fb7..3ab25fd5c 100644 --- a/config/locales/es-PR/admin.yml +++ b/config/locales/es-PR/admin.yml @@ -711,7 +711,7 @@ es-PR: search: title: Buscar Organizaciones no_results: No se han encontrado organizaciones. - proposals: + hidden_proposals: index: filter: Filtro filters: diff --git a/config/locales/es-PY/admin.yml b/config/locales/es-PY/admin.yml index 67f8d089d..d8b85a909 100644 --- a/config/locales/es-PY/admin.yml +++ b/config/locales/es-PY/admin.yml @@ -711,7 +711,7 @@ es-PY: search: title: Buscar Organizaciones no_results: No se han encontrado organizaciones. - proposals: + hidden_proposals: index: filter: Filtro filters: diff --git a/config/locales/es-SV/admin.yml b/config/locales/es-SV/admin.yml index dd6b5347b..40c1dae93 100644 --- a/config/locales/es-SV/admin.yml +++ b/config/locales/es-SV/admin.yml @@ -711,7 +711,7 @@ es-SV: search: title: Buscar Organizaciones no_results: No se han encontrado organizaciones. - proposals: + hidden_proposals: index: filter: Filtro filters: diff --git a/config/locales/es-UY/admin.yml b/config/locales/es-UY/admin.yml index 06887edc7..a8857cab4 100644 --- a/config/locales/es-UY/admin.yml +++ b/config/locales/es-UY/admin.yml @@ -711,7 +711,7 @@ es-UY: search: title: Buscar Organizaciones no_results: No se han encontrado organizaciones. - proposals: + hidden_proposals: index: filter: Filtro filters: diff --git a/config/locales/es-VE/admin.yml b/config/locales/es-VE/admin.yml index ce59ead1e..6da4ba856 100644 --- a/config/locales/es-VE/admin.yml +++ b/config/locales/es-VE/admin.yml @@ -773,7 +773,7 @@ es-VE: search: title: Buscar Organizaciones no_results: No se han encontrado organizaciones. - proposals: + hidden_proposals: index: filter: Filtro filters: diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index b16f85bd8..067700319 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -1031,7 +1031,7 @@ es: search: title: Buscar Organizaciones no_results: No se han encontrado organizaciones. - proposals: + hidden_proposals: index: filter: Filtro filters: diff --git a/config/locales/fa-IR/admin.yml b/config/locales/fa-IR/admin.yml index 5181924f0..d80d5edee 100644 --- a/config/locales/fa-IR/admin.yml +++ b/config/locales/fa-IR/admin.yml @@ -863,7 +863,7 @@ fa: search: title: جستجو سازمان ها no_results: هیچ سازمان یافت نشد - proposals: + hidden_proposals: index: filter: فیلتر filters: diff --git a/config/locales/fr/admin.yml b/config/locales/fr/admin.yml index bdc103d47..f0380beef 100644 --- a/config/locales/fr/admin.yml +++ b/config/locales/fr/admin.yml @@ -1006,7 +1006,7 @@ fr: search: title: Rechercher une organisation no_results: Aucune organisation trouvée. - proposals: + hidden_proposals: index: filter: Filtrer filters: diff --git a/config/locales/gl/admin.yml b/config/locales/gl/admin.yml index 341aef52f..158222161 100644 --- a/config/locales/gl/admin.yml +++ b/config/locales/gl/admin.yml @@ -1028,7 +1028,7 @@ gl: search: title: Buscar organizacións no_results: Non se atoparon organizacións. - proposals: + hidden_proposals: index: filter: Filtro filters: diff --git a/config/locales/he/admin.yml b/config/locales/he/admin.yml index 77789491e..389ecac1a 100644 --- a/config/locales/he/admin.yml +++ b/config/locales/he/admin.yml @@ -228,7 +228,7 @@ he: verify: Verify search: title: Search Organisations - proposals: + hidden_proposals: index: filter: Filter filters: diff --git a/config/locales/id-ID/admin.yml b/config/locales/id-ID/admin.yml index edba75f62..cc0748d22 100644 --- a/config/locales/id-ID/admin.yml +++ b/config/locales/id-ID/admin.yml @@ -738,7 +738,7 @@ id: search: title: Cari organisasi no_results: Tidak ada organisasi yang ditemukan. - proposals: + hidden_proposals: index: filters: with_confirmed_hide: Dikonfirmasi diff --git a/config/locales/it/admin.yml b/config/locales/it/admin.yml index 064d2002c..cc93da1d8 100644 --- a/config/locales/it/admin.yml +++ b/config/locales/it/admin.yml @@ -1009,7 +1009,7 @@ it: search: title: Cerca Organizzazioni no_results: Nessuna organizzazione trovata. - proposals: + hidden_proposals: index: filter: Filtra filters: diff --git a/config/locales/nl/admin.yml b/config/locales/nl/admin.yml index e8609b609..379629b94 100644 --- a/config/locales/nl/admin.yml +++ b/config/locales/nl/admin.yml @@ -1010,7 +1010,7 @@ nl: search: title: Zoek Organisaties no_results: Geen organisaties gevonden. - proposals: + hidden_proposals: index: filter: Filter filters: diff --git a/config/locales/pl-PL/admin.yml b/config/locales/pl-PL/admin.yml index b59aae930..650cb365e 100644 --- a/config/locales/pl-PL/admin.yml +++ b/config/locales/pl-PL/admin.yml @@ -1014,7 +1014,7 @@ pl: search: title: Szukaj organizacji no_results: Nie znaleziono organizacji. - proposals: + hidden_proposals: index: filter: Filtr filters: diff --git a/config/locales/pt-BR/admin.yml b/config/locales/pt-BR/admin.yml index 7d9a975b3..c5f766128 100644 --- a/config/locales/pt-BR/admin.yml +++ b/config/locales/pt-BR/admin.yml @@ -1013,7 +1013,7 @@ pt-BR: search: title: Buscar Organizações no_results: Nenhuma organização encontrada. - proposals: + hidden_proposals: index: filter: Filtro filters: diff --git a/config/locales/sq-AL/admin.yml b/config/locales/sq-AL/admin.yml index 6ec432ca8..040f99f22 100644 --- a/config/locales/sq-AL/admin.yml +++ b/config/locales/sq-AL/admin.yml @@ -1013,7 +1013,7 @@ sq: search: title: Kërko Organizatat no_results: Asnjë organizatë nuk u gjet. - proposals: + hidden_proposals: index: filter: Filtër filters: diff --git a/config/locales/sv-SE/admin.yml b/config/locales/sv-SE/admin.yml index 2789798a0..f1cecca98 100644 --- a/config/locales/sv-SE/admin.yml +++ b/config/locales/sv-SE/admin.yml @@ -1008,7 +1008,7 @@ sv: search: title: Sök organisationer no_results: Inga organisationer. - proposals: + hidden_proposals: index: filter: Filtrera filters: diff --git a/config/locales/val/admin.yml b/config/locales/val/admin.yml index 71fc42fe0..3fa00ee9c 100644 --- a/config/locales/val/admin.yml +++ b/config/locales/val/admin.yml @@ -972,7 +972,7 @@ val: search: title: Cercar Organitzacions no_results: No s'han trobat organitzacions. - proposals: + hidden_proposals: index: filter: Filtre filters: diff --git a/config/locales/zh-CN/admin.yml b/config/locales/zh-CN/admin.yml index ec24af62e..ab4a535cc 100644 --- a/config/locales/zh-CN/admin.yml +++ b/config/locales/zh-CN/admin.yml @@ -1007,7 +1007,7 @@ zh-CN: search: title: 搜索组织 no_results: 未找到任何组织。 - proposals: + hidden_proposals: index: filter: 过滤器 filters: diff --git a/config/locales/zh-TW/admin.yml b/config/locales/zh-TW/admin.yml index 8756ab394..eec55994d 100644 --- a/config/locales/zh-TW/admin.yml +++ b/config/locales/zh-TW/admin.yml @@ -1010,7 +1010,7 @@ zh-TW: search: title: 搜尋組織 no_results: 未找到任何組織。 - proposals: + hidden_proposals: index: filter: 篩選器 filters: diff --git a/config/routes/admin.rb b/config/routes/admin.rb index e65ec688a..b022b385e 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -29,7 +29,7 @@ namespace :admin do end end - resources :proposals, only: :index do + resources :hidden_proposals, only: :index do member do put :restore put :confirm_hide diff --git a/spec/features/admin/activity_spec.rb b/spec/features/admin/activity_spec.rb index 9cfd5f9b8..6f9270ffe 100644 --- a/spec/features/admin/activity_spec.rb +++ b/spec/features/admin/activity_spec.rb @@ -53,7 +53,7 @@ feature 'Admin activity' do scenario "Shows admin restores" do proposal = create(:proposal, :hidden) - visit admin_proposals_path + visit admin_hidden_proposals_path within("#proposal_#{proposal.id}") do click_on "Restore" diff --git a/spec/features/admin/proposals_spec.rb b/spec/features/admin/hidden_proposals_spec.rb similarity index 79% rename from spec/features/admin/proposals_spec.rb rename to spec/features/admin/hidden_proposals_spec.rb index 1f48fb482..3b55d98a0 100644 --- a/spec/features/admin/proposals_spec.rb +++ b/spec/features/admin/hidden_proposals_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'Admin proposals' do +feature 'Admin hidden proposals' do background do admin = create(:administrator) @@ -12,14 +12,14 @@ feature 'Admin proposals' do admin = create(:administrator) login_as(admin.user) - expect{ visit admin_proposals_path }.to raise_exception(FeatureFlags::FeatureDisabled) + expect{ visit admin_hidden_proposals_path }.to raise_exception(FeatureFlags::FeatureDisabled) Setting['feature.proposals'] = true end scenario 'List shows all relevant info' do proposal = create(:proposal, :hidden) - visit admin_proposals_path + visit admin_hidden_proposals_path expect(page).to have_content(proposal.title) expect(page).to have_content(proposal.summary) @@ -31,7 +31,7 @@ feature 'Admin proposals' do scenario 'Restore' do proposal = create(:proposal, :hidden) - visit admin_proposals_path + visit admin_hidden_proposals_path click_link 'Restore' @@ -43,7 +43,7 @@ feature 'Admin proposals' do scenario 'Confirm hide' do proposal = create(:proposal, :hidden) - visit admin_proposals_path + visit admin_hidden_proposals_path click_link 'Confirm moderation' @@ -55,22 +55,22 @@ feature 'Admin proposals' do end scenario "Current filter is properly highlighted" do - visit admin_proposals_path + visit admin_hidden_proposals_path expect(page).not_to have_link('Pending') expect(page).to have_link('All') expect(page).to have_link('Confirmed') - visit admin_proposals_path(filter: 'Pending') + visit admin_hidden_proposals_path(filter: 'Pending') expect(page).not_to have_link('Pending') expect(page).to have_link('All') expect(page).to have_link('Confirmed') - visit admin_proposals_path(filter: 'all') + visit admin_hidden_proposals_path(filter: 'all') expect(page).to have_link('Pending') expect(page).not_to have_link('All') expect(page).to have_link('Confirmed') - visit admin_proposals_path(filter: 'with_confirmed_hide') + visit admin_hidden_proposals_path(filter: 'with_confirmed_hide') expect(page).to have_link('All') expect(page).to have_link('Pending') expect(page).not_to have_link('Confirmed') @@ -80,15 +80,15 @@ feature 'Admin proposals' do create(:proposal, :hidden, title: "Unconfirmed proposal") create(:proposal, :hidden, :with_confirmed_hide, title: "Confirmed proposal") - visit admin_proposals_path(filter: 'pending') + visit admin_hidden_proposals_path(filter: 'pending') expect(page).to have_content('Unconfirmed proposal') expect(page).not_to have_content('Confirmed proposal') - visit admin_proposals_path(filter: 'all') + visit admin_hidden_proposals_path(filter: 'all') expect(page).to have_content('Unconfirmed proposal') expect(page).to have_content('Confirmed proposal') - visit admin_proposals_path(filter: 'with_confirmed_hide') + visit admin_hidden_proposals_path(filter: 'with_confirmed_hide') expect(page).not_to have_content('Unconfirmed proposal') expect(page).to have_content('Confirmed proposal') end @@ -97,7 +97,7 @@ feature 'Admin proposals' do per_page = Kaminari.config.default_per_page (per_page + 2).times { create(:proposal, :hidden, :with_confirmed_hide) } - visit admin_proposals_path(filter: 'with_confirmed_hide', page: 2) + visit admin_hidden_proposals_path(filter: 'with_confirmed_hide', page: 2) click_on('Restore', match: :first, exact: true) From b499c883734ea891809d18687e534703659d7f69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 20 Nov 2018 13:32:50 +0100 Subject: [PATCH 27/64] Extract method in menu moderated content This way we can make a long line considerably shorter. --- app/helpers/admin_helper.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index d0f3e5684..afce592a9 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -21,7 +21,12 @@ module AdminHelper end def menu_moderated_content? - ["hidden_proposals", "debates", "comments", "hidden_users", "activity", "hidden_budget_investments"].include?(controller_name) && controller.class.parent != Admin::Legislation + moderated_sections.include?(controller_name) && controller.class.parent != Admin::Legislation + end + + def moderated_sections + ["hidden_proposals", "debates", "comments", "hidden_users", "activity", + "hidden_budget_investments"] end def menu_budget? From 5cfc1592e4436e7fab32c7107922e9ca0bc47b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 20 Nov 2018 13:28:36 +0100 Subject: [PATCH 28/64] Use `%w[]` instead of `%w{}` As defined in our rubocop rules. --- app/controllers/admin/hidden_proposals_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/hidden_proposals_controller.rb b/app/controllers/admin/hidden_proposals_controller.rb index f6b39829d..48c910c0c 100644 --- a/app/controllers/admin/hidden_proposals_controller.rb +++ b/app/controllers/admin/hidden_proposals_controller.rb @@ -1,7 +1,7 @@ class Admin::HiddenProposalsController < Admin::BaseController include FeatureFlags - has_filters %w{without_confirmed_hide all with_confirmed_hide}, only: :index + has_filters %w[without_confirmed_hide all with_confirmed_hide], only: :index feature_flag :proposals From abf48af331feb152216282748846983f05311080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 19 Nov 2018 13:52:41 +0100 Subject: [PATCH 29/64] Rename `draft_texts` key to `draft_versions` This way we can refactor the legislation tabs, since now all translation keys follow the same convention (using the same name as the active tab name). --- app/views/admin/legislation/processes/_subnav.html.erb | 4 ++-- config/locales/de-DE/admin.yml | 2 +- config/locales/en/admin.yml | 2 +- config/locales/es-AR/admin.yml | 2 +- config/locales/es-CL/admin.yml | 2 +- config/locales/es/admin.yml | 2 +- config/locales/fr/admin.yml | 2 +- config/locales/gl/admin.yml | 2 +- config/locales/it/admin.yml | 2 +- config/locales/nl/admin.yml | 2 +- config/locales/pl-PL/admin.yml | 2 +- config/locales/pt-BR/admin.yml | 2 +- config/locales/sq-AL/admin.yml | 2 +- config/locales/sv-SE/admin.yml | 2 +- config/locales/val/admin.yml | 2 +- config/locales/zh-CN/admin.yml | 2 +- config/locales/zh-TW/admin.yml | 2 +- 17 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/views/admin/legislation/processes/_subnav.html.erb b/app/views/admin/legislation/processes/_subnav.html.erb index 2bfa9dd1d..7f3903101 100644 --- a/app/views/admin/legislation/processes/_subnav.html.erb +++ b/app/views/admin/legislation/processes/_subnav.html.erb @@ -31,11 +31,11 @@ <% if active == 'draft_versions' %>
    • -

      <%= t("admin.legislation.processes.subnav.draft_texts") %>

      +

      <%= t("admin.legislation.processes.subnav.draft_versions") %>

    • <% else %>
    • - <%= link_to t("admin.legislation.processes.subnav.draft_texts"), admin_legislation_process_draft_versions_path(process) %> + <%= link_to t("admin.legislation.processes.subnav.draft_versions"), admin_legislation_process_draft_versions_path(process) %>
    • <% end %>
    diff --git a/config/locales/de-DE/admin.yml b/config/locales/de-DE/admin.yml index 97d982f81..d557c88ac 100644 --- a/config/locales/de-DE/admin.yml +++ b/config/locales/de-DE/admin.yml @@ -403,7 +403,7 @@ de: status_planned: Geplant subnav: info: Information - draft_texts: Ausarbeitung + draft_versions: Ausarbeitung questions: Diskussion proposals: Vorschläge proposals: diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 6ee435c55..619158038 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -413,7 +413,7 @@ en: status_planned: Planned subnav: info: Information - draft_texts: Drafting + draft_versions: Drafting questions: Debate proposals: Proposals proposals: diff --git a/config/locales/es-AR/admin.yml b/config/locales/es-AR/admin.yml index 2b3def5f7..899de141d 100644 --- a/config/locales/es-AR/admin.yml +++ b/config/locales/es-AR/admin.yml @@ -367,7 +367,7 @@ es-AR: status_planned: Próximamente subnav: info: Información - draft_texts: Redacción + draft_versions: Redacción questions: Debate proposals: Propuestas proposals: diff --git a/config/locales/es-CL/admin.yml b/config/locales/es-CL/admin.yml index f47074f48..2c4f337dc 100644 --- a/config/locales/es-CL/admin.yml +++ b/config/locales/es-CL/admin.yml @@ -361,7 +361,7 @@ es-CL: status_planned: Próximamente subnav: info: Información - draft_texts: Redacción + draft_versions: Redacción questions: Debate proposals: Propuestas proposals: diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index b16f85bd8..6683718bc 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -413,7 +413,7 @@ es: status_planned: Próximamente subnav: info: Información - draft_texts: Redacción + draft_versions: Redacción questions: Debate proposals: Propuestas proposals: diff --git a/config/locales/fr/admin.yml b/config/locales/fr/admin.yml index bdc103d47..44606558e 100644 --- a/config/locales/fr/admin.yml +++ b/config/locales/fr/admin.yml @@ -402,7 +402,7 @@ fr: status_planned: Planifié subnav: info: Information - draft_texts: Brouillon + draft_versions: Brouillon questions: Débat proposals: Propositions proposals: diff --git a/config/locales/gl/admin.yml b/config/locales/gl/admin.yml index 341aef52f..b876dae35 100644 --- a/config/locales/gl/admin.yml +++ b/config/locales/gl/admin.yml @@ -411,7 +411,7 @@ gl: status_planned: Planificado subnav: info: Información - draft_texts: Redacción + draft_versions: Redacción questions: Debate proposals: Propostas proposals: diff --git a/config/locales/it/admin.yml b/config/locales/it/admin.yml index 064d2002c..4e24a115a 100644 --- a/config/locales/it/admin.yml +++ b/config/locales/it/admin.yml @@ -402,7 +402,7 @@ it: status_planned: Programmato subnav: info: Informazione - draft_texts: Redazione + draft_versions: Redazione questions: Dibattito proposals: Proposte proposals: diff --git a/config/locales/nl/admin.yml b/config/locales/nl/admin.yml index e8609b609..4f05f4a81 100644 --- a/config/locales/nl/admin.yml +++ b/config/locales/nl/admin.yml @@ -403,7 +403,7 @@ nl: status_planned: Gepland subnav: info: Informatie - draft_texts: Tekst + draft_versions: Tekst questions: Debat proposals: Voorstellen proposals: diff --git a/config/locales/pl-PL/admin.yml b/config/locales/pl-PL/admin.yml index b59aae930..4e3c5ad67 100644 --- a/config/locales/pl-PL/admin.yml +++ b/config/locales/pl-PL/admin.yml @@ -408,7 +408,7 @@ pl: status_planned: Zaplanowany subnav: info: Informacje - draft_texts: Opracowanie + draft_versions: Opracowanie questions: Debata proposals: Wnioski proposals: diff --git a/config/locales/pt-BR/admin.yml b/config/locales/pt-BR/admin.yml index 7d9a975b3..5a199a0b5 100644 --- a/config/locales/pt-BR/admin.yml +++ b/config/locales/pt-BR/admin.yml @@ -404,7 +404,7 @@ pt-BR: status_planned: Planejados subnav: info: Informação - draft_texts: Seleção + draft_versions: Seleção questions: Debate proposals: Propostas proposals: diff --git a/config/locales/sq-AL/admin.yml b/config/locales/sq-AL/admin.yml index 6ec432ca8..74367f811 100644 --- a/config/locales/sq-AL/admin.yml +++ b/config/locales/sq-AL/admin.yml @@ -404,7 +404,7 @@ sq: status_planned: Planifikuar subnav: info: Informacion - draft_texts: Hartimi + draft_versions: Hartimi questions: Debate proposals: Propozime proposals: diff --git a/config/locales/sv-SE/admin.yml b/config/locales/sv-SE/admin.yml index 2789798a0..322dfefba 100644 --- a/config/locales/sv-SE/admin.yml +++ b/config/locales/sv-SE/admin.yml @@ -403,7 +403,7 @@ sv: status_planned: Planerad subnav: info: Information - draft_texts: Utkast + draft_versions: Utkast questions: Diskussion proposals: Förslag proposals: diff --git a/config/locales/val/admin.yml b/config/locales/val/admin.yml index 71fc42fe0..2d36d0067 100644 --- a/config/locales/val/admin.yml +++ b/config/locales/val/admin.yml @@ -401,7 +401,7 @@ val: status_planned: Pròximament subnav: info: Informació - draft_texts: Text + draft_versions: Text questions: Debat proposals: Propostes proposals: diff --git a/config/locales/zh-CN/admin.yml b/config/locales/zh-CN/admin.yml index ec24af62e..3a5c9fb5b 100644 --- a/config/locales/zh-CN/admin.yml +++ b/config/locales/zh-CN/admin.yml @@ -401,7 +401,7 @@ zh-CN: status_planned: 计划 subnav: info: 信息 - draft_texts: 起草 + draft_versions: 起草 questions: 辩论 proposals: 提议 proposals: diff --git a/config/locales/zh-TW/admin.yml b/config/locales/zh-TW/admin.yml index 8756ab394..d320529e2 100644 --- a/config/locales/zh-TW/admin.yml +++ b/config/locales/zh-TW/admin.yml @@ -402,7 +402,7 @@ zh-TW: status_planned: 計劃 subnav: info: 資訊 - draft_texts: 起草 + draft_versions: 起草 questions: 辯論 proposals: 建議 proposals: From 9ad8c5728aa6f01a97be3ce6e23a5853e13bf389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 19 Nov 2018 14:07:03 +0100 Subject: [PATCH 30/64] Refactor legislation process subnav --- app/helpers/legislation_helper.rb | 9 ++++ .../legislation/processes/_subnav.html.erb | 48 ++++--------------- 2 files changed, 19 insertions(+), 38 deletions(-) diff --git a/app/helpers/legislation_helper.rb b/app/helpers/legislation_helper.rb index 38eba39ad..b2cd1399c 100644 --- a/app/helpers/legislation_helper.rb +++ b/app/helpers/legislation_helper.rb @@ -26,4 +26,13 @@ module LegislationHelper method: :patch, class: html_class end + + def legislation_process_tabs(process) + { + "info" => edit_admin_legislation_process_path(process), + "questions" => admin_legislation_process_questions_path(process), + "proposals" => admin_legislation_process_proposals_path(process), + "draft_versions" => admin_legislation_process_draft_versions_path(process) + } + end end diff --git a/app/views/admin/legislation/processes/_subnav.html.erb b/app/views/admin/legislation/processes/_subnav.html.erb index 7f3903101..56ec8971c 100644 --- a/app/views/admin/legislation/processes/_subnav.html.erb +++ b/app/views/admin/legislation/processes/_subnav.html.erb @@ -1,41 +1,13 @@ From baa7ddc4cc93080cf2b6eac2a3a761e47d468fdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 20 Nov 2018 14:09:22 +0100 Subject: [PATCH 31/64] Remove unused key --- config/locales/en/activerecord.yml | 3 --- config/locales/es/activerecord.yml | 3 --- 2 files changed, 6 deletions(-) diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 0ed4a9872..93040769b 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -82,9 +82,6 @@ en: legislation/draft_versions: one: "Draft version" other: "Draft versions" - legislation/draft_texts: - one: "Draft" - other: "Drafts" legislation/questions: one: "Question" other: "Questions" diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index 15bbb35bf..2737073eb 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -82,9 +82,6 @@ es: legislation/draft_versions: one: "Versión borrador" other: "Versiones borrador" - legislation/draft_texts: - one: "Borrador" - other: "Borradores" legislation/questions: one: "Pregunta" other: "Preguntas" From d819a9ccbc8d5c850fb0d4f93369a01d47c6223a Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Sun, 2 Dec 2018 17:12:57 +0100 Subject: [PATCH 32/64] add missing spec --- spec/features/admin/poll/questions_spec.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/spec/features/admin/poll/questions_spec.rb b/spec/features/admin/poll/questions_spec.rb index 4374800f2..5fedcbb34 100644 --- a/spec/features/admin/poll/questions_spec.rb +++ b/spec/features/admin/poll/questions_spec.rb @@ -72,7 +72,16 @@ feature 'Admin poll questions' do expect(page).to have_link(proposal.author.name, href: user_path(proposal.author)) end - pending "Create from successul proposal show" + scenario "Create from successful proposal show" do + poll = create(:poll, name: 'Proposals') + proposal = create(:proposal, :successful) + + visit proposal_path(proposal) + click_link "Create question" + + expect(page).to have_current_path(new_admin_question_path, ignore_query: true) + expect(page).to have_field('Question', with: proposal.title) + end scenario 'Update' do question1 = create(:poll_question) From 43dac8d276153086b568f6e96c8466aebc000478 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Sun, 2 Dec 2018 17:45:39 +0100 Subject: [PATCH 33/64] add missing spec --- .../features/admin/budget_investments_spec.rb | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index d58263d2a..592473251 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -802,7 +802,28 @@ feature 'Admin budget investments' do end end - pending "Do not display valuators of an assigned group" + scenario "Do not display valuators of an assigned group" do + budget_investment = create(:budget_investment) + + health_group = create(:valuator_group, name: "Health") + user = create(:user, username: 'Valentina', email: 'v1@valuators.org') + create(:valuator, user: user, valuator_group: health_group) + + visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment) + click_link 'Edit classification' + + check "budget_investment_valuator_group_ids_#{health_group.id}" + + click_button 'Update' + + expect(page).to have_content 'Investment project updated succesfully.' + + within('#assigned_valuator_groups') { expect(page).to have_content('Health') } + within('#assigned_valuators') do + expect(page).to have_content('Undefined') + expect(page).not_to have_content('Valentina (v1@valuators.org)') + end + end scenario "Adds existing valuation tags", :js do budget_investment1 = create(:budget_investment) From 333098502e93229f3362ae41124881ef47b8b737 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Sun, 2 Dec 2018 18:12:03 +0100 Subject: [PATCH 34/64] fix typo --- spec/features/legislation/proposals_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/legislation/proposals_spec.rb b/spec/features/legislation/proposals_spec.rb index 17a7c607e..d956964c5 100644 --- a/spec/features/legislation/proposals_spec.rb +++ b/spec/features/legislation/proposals_spec.rb @@ -20,7 +20,7 @@ feature 'Legislation Proposals' do end end - scenario 'Each user as a different and consistent random proposals order', :js do + scenario 'Each user has a different and consistent random proposals order', :js do create_list(:legislation_proposal, 10, process: process) in_browser(:one) do From aa41ce2c96cf47167208bf991bad81c90e74280e Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Sun, 2 Dec 2018 18:12:30 +0100 Subject: [PATCH 35/64] use Capybara.using_session method for multiple browsers specs --- spec/sessions_helper.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/spec/sessions_helper.rb b/spec/sessions_helper.rb index fc3fcc2f0..13c9504d0 100644 --- a/spec/sessions_helper.rb +++ b/spec/sessions_helper.rb @@ -1,8 +1,3 @@ -def in_browser(name) - old_session = Capybara.session_name - - Capybara.session_name = name - yield - - Capybara.session_name = old_session +def in_browser(name, &block) + Capybara.using_session(name, &block) end From c41349709496c1d8f60118e6f212d7cd66d0f51f Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Mon, 3 Dec 2018 17:12:47 +0100 Subject: [PATCH 36/64] add missing spec --- spec/features/proposal_notifications_spec.rb | 43 +++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/spec/features/proposal_notifications_spec.rb b/spec/features/proposal_notifications_spec.rb index c5c21d27a..f374a42c8 100644 --- a/spec/features/proposal_notifications_spec.rb +++ b/spec/features/proposal_notifications_spec.rb @@ -364,7 +364,48 @@ feature 'Proposal Notifications' do visit new_proposal_notification_path(proposal_id: proposal.id) end - pending "group notifications for the same proposal" + context "Group notifications" do + + background do + Setting[:proposal_notification_minimum_interval_in_days] = 0 + end + + after do + Setting[:proposal_notification_minimum_interval_in_days] = 3 + end + + scenario "for the same proposal", :js do + author = create(:user) + user = create(:user) + + proposal = create(:proposal, author: author) + + create(:follow, :followed_proposal, user: user, followable: proposal) + + login_as author.reload + + 3.times do + visit new_proposal_notification_path(proposal_id: proposal.id) + + fill_in "Title", with: "Thank you for supporting my proposal" + fill_in "Message", with: "Please share it with others so we can make it happen!" + click_button "Send message" + + expect(page).to have_content "Your message has been sent correctly." + end + + logout + login_as user.reload + visit root_path + + within("#notifications") { expect(page).to have_content :all, "You have 3 new notifications" } + find(".icon-notification").click + + expect(page).to have_css ".notification", count: 3 + expect(page).to have_content "There is one new notification on #{proposal.title}", count: 3 + end + end + end scenario "Error messages" do From 04e3bf57972d16e2016d973b4f78a5bf618a9034 Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 22 Nov 2018 12:39:07 +0100 Subject: [PATCH 37/64] Removes references to deleted general terms page --- config/locales/es/pages.yml | 1 - config/sitemap.rb | 5 ----- spec/lib/tasks/sitemap_spec.rb | 1 - 3 files changed, 7 deletions(-) diff --git a/config/locales/es/pages.yml b/config/locales/es/pages.yml index 739c93a26..5e16e4a4f 100644 --- a/config/locales/es/pages.yml +++ b/config/locales/es/pages.yml @@ -4,7 +4,6 @@ es: title: Condiciones de uso subtitle: AVISO LEGAL SOBRE LAS CONDICIONES DE USO, PRIVACIDAD Y PROTECCIÓN DE DATOS PERSONALES DEL PORTAL DE GOBIERNO ABIERTO description: Página de información sobre las condiciones de uso, privacidad y protección de datos personales. - general_terms: Términos y Condiciones help: title: "%{org} es una plataforma de participación ciudadana" guide: "Esta guía explica para qué sirven y cómo funcionan cada una de las secciones de %{org}." diff --git a/config/sitemap.rb b/config/sitemap.rb index a5e72e2b1..85aeee2a2 100644 --- a/config/sitemap.rb +++ b/config/sitemap.rb @@ -10,11 +10,6 @@ SitemapGenerator::Sitemap.default_host = Setting["url"] # sitemap generator SitemapGenerator::Sitemap.create do - pages = ["general_terms"] - pages.each do |page| - add page_path(id: page) - end - add help_path add how_to_use_path add faq_path diff --git a/spec/lib/tasks/sitemap_spec.rb b/spec/lib/tasks/sitemap_spec.rb index 01dd3f430..cfab39afc 100644 --- a/spec/lib/tasks/sitemap_spec.rb +++ b/spec/lib/tasks/sitemap_spec.rb @@ -32,7 +32,6 @@ feature 'rake sitemap:create' do expect(sitemap).to include(faq_path) expect(sitemap).to include(help_path) expect(sitemap).to include(how_to_use_path) - expect(sitemap).to include(page_path(id: 'general_terms')) # Dynamic URLs expect(sitemap).to include(polls_path) From ddcc03450d33addf2642efc30ddb8c6fe0113cb5 Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 22 Nov 2018 12:49:18 +0100 Subject: [PATCH 38/64] Improves styles for help text class --- app/assets/stylesheets/layout.scss | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index c4f90791a..73d5eaecc 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -434,6 +434,11 @@ a { text-transform: uppercase; } +.help-text { + line-height: rem-calc(20); + margin-top: 0; +} + // 02. Header // ---------- From 61c7b9a02b07464a30a4772ac73551b336136e3c Mon Sep 17 00:00:00 2001 From: decabeza Date: Tue, 27 Nov 2018 12:09:56 +0100 Subject: [PATCH 39/64] Changes width of additional documents container --- app/views/documents/_additional_documents.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/documents/_additional_documents.html.erb b/app/views/documents/_additional_documents.html.erb index db2344c74..383ce4ea0 100644 --- a/app/views/documents/_additional_documents.html.erb +++ b/app/views/documents/_additional_documents.html.erb @@ -1,7 +1,7 @@ <% if documents.any? %>
    -
    +