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