From 28bb32a085a333903a57ba163fc115e8aa49bf5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 21 Mar 2018 20:15:57 +0100 Subject: [PATCH 1/7] Add Budget::Investment::Status migration --- ...0180321140337_create_budget_investment_statuses.rb | 11 +++++++++++ db/schema.rb | 10 ++++++++++ 2 files changed, 21 insertions(+) create mode 100644 db/migrate/20180321140337_create_budget_investment_statuses.rb diff --git a/db/migrate/20180321140337_create_budget_investment_statuses.rb b/db/migrate/20180321140337_create_budget_investment_statuses.rb new file mode 100644 index 000000000..292644ede --- /dev/null +++ b/db/migrate/20180321140337_create_budget_investment_statuses.rb @@ -0,0 +1,11 @@ +class CreateBudgetInvestmentStatuses < ActiveRecord::Migration + def change + create_table :budget_investment_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 da47db5ac..e0a25c219 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -139,6 +139,16 @@ ActiveRecord::Schema.define(version: 20180519132610) do t.datetime "publication_date" end + create_table "budget_investment_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 "budget_investment_statuses", ["hidden_at"], name: "index_budget_investment_statuses_on_hidden_at", using: :btree + create_table "budget_investments", force: :cascade do |t| t.integer "author_id" t.integer "administrator_id" From 87b13bab72d6992a1b6d121297a6d898da8d3385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 21 Mar 2018 20:17:05 +0100 Subject: [PATCH 2/7] Add Budget::Investment::Statuses model --- app/models/budget/investment/status.rb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 app/models/budget/investment/status.rb diff --git a/app/models/budget/investment/status.rb b/app/models/budget/investment/status.rb new file mode 100644 index 000000000..df2b991ba --- /dev/null +++ b/app/models/budget/investment/status.rb @@ -0,0 +1,7 @@ +class Budget::Investment::Status < ActiveRecord::Base + acts_as_paranoid column: :hidden_at + + has_many :milestones + + validates :name, presence: true +end From 2cb59260e9e71039c29bd880576e935afd70881e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 21 Mar 2018 20:16:38 +0100 Subject: [PATCH 3/7] Add Budget::Investment::Statuses controller and routes --- .../budget_investment_statuses_controller.rb | 51 +++++++++++++++++++ config/routes/admin.rb | 2 + 2 files changed, 53 insertions(+) create mode 100644 app/controllers/admin/budget_investment_statuses_controller.rb diff --git a/app/controllers/admin/budget_investment_statuses_controller.rb b/app/controllers/admin/budget_investment_statuses_controller.rb new file mode 100644 index 000000000..c3d7a4e16 --- /dev/null +++ b/app/controllers/admin/budget_investment_statuses_controller.rb @@ -0,0 +1,51 @@ +class Admin::BudgetInvestmentStatusesController < Admin::BaseController + + before_action :load_status, only: [:edit, :update, :destroy] + + def index + @statuses = Budget::Investment::Status.all + end + + def new + @status = Budget::Investment::Status.new + end + + def create + @status = Budget::Investment::Status.new(status_params) + + if @status.save + redirect_to admin_budget_investment_statuses_path, + notice: t('admin.statuses.create.notice') + else + render :new + end + end + + def edit + end + + def update + if @status.update(status_params) + redirect_to admin_budget_investment_statuses_path, + notice: t('admin.statuses.update.notice') + else + render :edit + end + end + + def destroy + @status.destroy + redirect_to admin_budget_investment_statuses_path, + notice: t('admin.statuses.delete.notice') + end + + private + + def load_status + @status = Budget::Investment::Status.find(params[:id]) + end + + def status_params + params.require(:budget_investment_status).permit([:name, :description]) + end +end diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 2125b6ee9..374b4512c 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -55,6 +55,8 @@ namespace :admin do resources :budget_phases, only: [:edit, :update] end + resources :budget_investment_statuses, only: [:index, :new, :create, :update, :edit, :destroy] + resources :signature_sheets, only: [:index, :new, :create, :show] resources :banners, only: [:index, :new, :create, :edit, :update, :destroy] do From 3a163b39c884ac8f6e9f9a71c11b754165aa23af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 21 Mar 2018 20:17:40 +0100 Subject: [PATCH 4/7] Add Budget::Investment::Statuses views --- app/views/admin/_menu.html.erb | 3 +- .../budget_investment_statuses/_form.html.erb | 10 +++++ .../budget_investment_statuses/edit.html.erb | 5 +++ .../budget_investment_statuses/index.html.erb | 41 +++++++++++++++++++ .../budget_investment_statuses/new.html.erb | 5 +++ 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 app/views/admin/budget_investment_statuses/_form.html.erb create mode 100644 app/views/admin/budget_investment_statuses/edit.html.erb create mode 100644 app/views/admin/budget_investment_statuses/index.html.erb create mode 100644 app/views/admin/budget_investment_statuses/new.html.erb diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 499f9a54c..8cf4f45af 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -49,7 +49,8 @@ <% end %> <% if feature?(:budgets) %> -
  • "> +
  • "> <%= link_to admin_budgets_path do %> <%= t("admin.menu.budgets") %> diff --git a/app/views/admin/budget_investment_statuses/_form.html.erb b/app/views/admin/budget_investment_statuses/_form.html.erb new file mode 100644 index 000000000..aff4b20d6 --- /dev/null +++ b/app/views/admin/budget_investment_statuses/_form.html.erb @@ -0,0 +1,10 @@ +<%= form_for [:admin, @status] do |f| %> + <%= render 'shared/errors', resource: @status %> + + <%= f.text_field :name %> + <%= f.text_area :description %> + +
    + <%= f.submit class: "button success" %> +
    +<% end %> diff --git a/app/views/admin/budget_investment_statuses/edit.html.erb b/app/views/admin/budget_investment_statuses/edit.html.erb new file mode 100644 index 000000000..e54bfcb08 --- /dev/null +++ b/app/views/admin/budget_investment_statuses/edit.html.erb @@ -0,0 +1,5 @@ +<%= 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/index.html.erb b/app/views/admin/budget_investment_statuses/index.html.erb new file mode 100644 index 000000000..f41a730cc --- /dev/null +++ b/app/views/admin/budget_investment_statuses/index.html.erb @@ -0,0 +1,41 @@ +

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

    + +<%= link_to t("admin.statuses.index.new_status"), + new_admin_budget_investment_status_path, + class: "button float-right margin-right" %> + +<% if @statuses.any? %> + + + + + + + + + + <% @statuses.each do |status| %> + + + + + + <% end %> + +
    <%= t("admin.statuses.index.table_name") %><%= t("admin.statuses.index.table_description") %><%= t("admin.statuses.index.table_actions") %>
    + <%= status.name %> + + <%= status.description %> + + <%= link_to t("admin.statuses.index.edit"), + edit_admin_budget_investment_status_path(status), + method: :get, class: "button hollow" %> + <%= link_to t("admin.statuses.index.delete"), + admin_budget_investment_status_path(status), + method: :delete, class: "button hollow alert" %> +
    +<% else %> +
    + <%= t("admin.statuses.index.empty_statuses") %> +
    +<% end %> diff --git a/app/views/admin/budget_investment_statuses/new.html.erb b/app/views/admin/budget_investment_statuses/new.html.erb new file mode 100644 index 000000000..336b41238 --- /dev/null +++ b/app/views/admin/budget_investment_statuses/new.html.erb @@ -0,0 +1,5 @@ +<%= back_link_to admin_budget_investment_statuses_path %> + +

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

    + +<%= render '/admin/budget_investment_statuses/form' %> From 564d1b32e21b7320c95176ea66ddc51bdbe78d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 21 Mar 2018 20:50:10 +0100 Subject: [PATCH 5/7] Add new translations --- config/locales/en/activerecord.yml | 6 ++++++ config/locales/en/admin.yml | 20 ++++++++++++++++++++ config/locales/es/activerecord.yml | 6 ++++++ config/locales/es/admin.yml | 20 ++++++++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 9dce0c25b..c7a69a8aa 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -13,6 +13,9 @@ en: budget/investment/milestone: one: "milestone" other: "milestones" + budget/investment/status: + one: "Investment status" + other: "Investment statuses" comment: one: "Comment" other: "Comments" @@ -126,6 +129,9 @@ en: title: "Title" description: "Description" publication_date: "Publication date" + budget/investment/status: + name: "Name" + description: "Description (optional)" budget/heading: name: "Heading name" price: "Price" diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 5e70d609f..2a21a1621 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -272,6 +272,26 @@ en: notice: Milestone updated successfully delete: notice: Milestone successfully deleted + statuses: + index: + title: Investment statuses + empty_statuses: There are no investment statuses created + new_status: Create new investment status + table_name: Name + table_description: Description + table_actions: Actions + delete: Delete + edit: Edit + edit: + title: Edit investment status + update: + notice: Investment status updated successfully + new: + title: Create investment status + create: + notice: Investment status created successfully + delete: + notice: Investment status deleted successfully comments: index: filter: Filter diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index c5d8a63bc..db6d7a42c 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -13,6 +13,9 @@ es: budget/investment/milestone: one: "hito" other: "hitos" + budget/investment/status: + one: "Estado de proyecto" + other: "Estados de proyecto" comment: one: "Comentario" other: "Comentarios" @@ -126,6 +129,9 @@ es: title: "Título" description: "Descripción" publication_date: "Fecha de publicación" + budget/investment/status: + name: "Nombre" + description: "Descripción (opcional)" budget/heading: name: "Nombre de la partida" price: "Cantidad" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 48a2ee30c..57c1a6f90 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -272,6 +272,26 @@ es: notice: Hito actualizado delete: 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 + table_name: Nombre + table_description: Descripción + table_actions: Acciones + delete: Borrar + edit: Editar + edit: + title: Editar estado de proyecto + update: + notice: Estado de proyecto editado correctamente + new: + title: Crear estado de proyecto + create: + notice: Estado de proyecto creado correctamente + delete: + notice: Estado de proyecto eliminado correctamente comments: index: filter: Filtro From e8e9fcd0dae6ec2811a007c43bb3f6157085e480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 21 Mar 2018 23:48:44 +0100 Subject: [PATCH 6/7] Add Budget::Investment::Statuses tests --- spec/factories.rb | 5 + .../admin/budget_investment_statuses_spec.rb | 95 +++++++++++++++++++ spec/models/budget/investment/status_spec.rb | 17 ++++ 3 files changed, 117 insertions(+) create mode 100644 spec/features/admin/budget_investment_statuses_spec.rb create mode 100644 spec/models/budget/investment/status_spec.rb diff --git a/spec/factories.rb b/spec/factories.rb index e69a5b8a1..32670b63f 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -404,6 +404,11 @@ 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" } + end + factory :budget_investment_milestone, class: 'Budget::Investment::Milestone' do association :investment, factory: :budget_investment sequence(:title) { |n| "Budget investment milestone #{n} title" } diff --git a/spec/features/admin/budget_investment_statuses_spec.rb b/spec/features/admin/budget_investment_statuses_spec.rb new file mode 100644 index 000000000..196dc2eee --- /dev/null +++ b/spec/features/admin/budget_investment_statuses_spec.rb @@ -0,0 +1,95 @@ +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/models/budget/investment/status_spec.rb b/spec/models/budget/investment/status_spec.rb new file mode 100644 index 000000000..36d472a76 --- /dev/null +++ b/spec/models/budget/investment/status_spec.rb @@ -0,0 +1,17 @@ +require 'rails_helper' + +describe Budget::Investment::Status do + + describe "Validations" do + let(:status) { build(:budget_investment_status) } + + it "is valid" do + expect(status).to be_valid + end + + it "is not valid without a name" do + status.name = nil + expect(status).not_to be_valid + end + end +end From 9eefcafcfb4fe9bdaa740e20195832830e0737f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 22 Mar 2018 23:12:33 +0100 Subject: [PATCH 7/7] Add Budget::Investment::Status to dev_seeds --- config/locales/en/seeds.yml | 12 +++++++++++- config/locales/es/seeds.yml | 12 +++++++++++- db/dev_seeds/budgets.rb | 7 +++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/config/locales/en/seeds.yml b/config/locales/en/seeds.yml index 87db8e5c9..b77ebfc21 100644 --- a/config/locales/en/seeds.yml +++ b/config/locales/en/seeds.yml @@ -36,10 +36,20 @@ en: groups: all_city: All City districts: Districts + valuator_groups: + culture_and_sports: Culture & Sports + gender_and_diversity: Gender & Diversity Policies + urban_development: Sustainable Urban Development + equity_and_employment: Equity & Employment + statuses: + studying_project: Studying the project + bidding: Bidding + executing_project: Executing the project + executed: Executed polls: current_poll: "Current Poll" current_poll_geozone_restricted: "Current Poll Geozone Restricted" incoming_poll: "Incoming Poll" recounting_poll: "Recounting Poll" expired_poll_without_stats: "Expired Poll without Stats & Results" - expired_poll_with_stats: "Expired Poll with Stats & Results" \ No newline at end of file + expired_poll_with_stats: "Expired Poll with Stats & Results" diff --git a/config/locales/es/seeds.yml b/config/locales/es/seeds.yml index ad6d5c656..7640e4e4d 100644 --- a/config/locales/es/seeds.yml +++ b/config/locales/es/seeds.yml @@ -36,10 +36,20 @@ es: groups: all_city: Toda la Ciudad districts: Distritos + valuator_groups: + culture_and_sports: Cultura y Deportes + gender_and_diversity: Políticas de Género y Diversidad + urban_development: Desarrollo Urbano Sostenible + equity_and_employment: Equidad y Empleo + statuses: + studying_project: Estudiando el proyecto + bidding: Licitación + executing_project: Ejecutando el proyecto + executed: Ejecutado polls: current_poll: "Votación Abierta" current_poll_geozone_restricted: "Votación Abierta restringida por geozona" incoming_poll: "Siguiente Votación" recounting_poll: "Votación en Recuento" expired_poll_without_stats: "Votación Finalizada (sin Estadísticas o Resultados)" - expired_poll_with_stats: "Votación Finalizada (con Estadísticas y Resultado)" \ No newline at end of file + expired_poll_with_stats: "Votación Finalizada (con Estadísticas y Resultado)" diff --git a/db/dev_seeds/budgets.rb b/db/dev_seeds/budgets.rb index 5d3294b46..5633e1dc6 100644 --- a/db/dev_seeds/budgets.rb +++ b/db/dev_seeds/budgets.rb @@ -123,3 +123,10 @@ section "Creating investment milestones" do end 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')) +end