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.
This commit is contained in:
Marko Lovic
2018-07-16 13:13:30 +02:00
committed by Javi Martín
parent 7446ebbdd5
commit 81f516efd7
27 changed files with 187 additions and 165 deletions

View File

@@ -70,7 +70,7 @@ class Admin::BudgetInvestmentMilestonesController < Admin::BaseController
end end
def load_statuses def load_statuses
@statuses = Budget::Investment::Status.all @statuses = Milestone::Status.all
end end
end end

View File

@@ -1,20 +1,20 @@
class Admin::BudgetInvestmentStatusesController < Admin::BaseController class Admin::MilestoneStatusesController < Admin::BaseController
before_action :load_status, only: [:edit, :update, :destroy] before_action :load_status, only: [:edit, :update, :destroy]
def index def index
@statuses = Budget::Investment::Status.all @statuses = Milestone::Status.all
end end
def new def new
@status = Budget::Investment::Status.new @status = Milestone::Status.new
end end
def create def create
@status = Budget::Investment::Status.new(status_params) @status = Milestone::Status.new(status_params)
if @status.save if @status.save
redirect_to admin_budget_investment_statuses_path, redirect_to admin_milestone_statuses_path,
notice: t('admin.statuses.create.notice') notice: t('admin.statuses.create.notice')
else else
render :new render :new
@@ -26,7 +26,7 @@ class Admin::BudgetInvestmentStatusesController < Admin::BaseController
def update def update
if @status.update(status_params) if @status.update(status_params)
redirect_to admin_budget_investment_statuses_path, redirect_to admin_milestone_statuses_path,
notice: t('admin.statuses.update.notice') notice: t('admin.statuses.update.notice')
else else
render :edit render :edit
@@ -35,17 +35,17 @@ class Admin::BudgetInvestmentStatusesController < Admin::BaseController
def destroy def destroy
@status.destroy @status.destroy
redirect_to admin_budget_investment_statuses_path, redirect_to admin_milestone_statuses_path,
notice: t('admin.statuses.delete.notice') notice: t('admin.statuses.delete.notice')
end end
private private
def load_status def load_status
@status = Budget::Investment::Status.find(params[:id]) @status = Milestone::Status.find(params[:id])
end end
def status_params def status_params
params.require(:budget_investment_status).permit([:name, :description]) params.require(:milestone_status).permit([:name, :description])
end end
end end

View File

@@ -6,7 +6,7 @@ module Budgets
def show def show
authorize! :read_executions, @budget authorize! :read_executions, @budget
@statuses = ::Budget::Investment::Status.all @statuses = Milestone::Status.all
if params[:status].present? if params[:status].present?
@investments_by_heading = @budget.investments.winners @investments_by_heading = @budget.investments.winners

View File

@@ -11,7 +11,7 @@ class Budget
include Globalizable include Globalizable
belongs_to :investment belongs_to :investment
belongs_to :status, class_name: 'Budget::Investment::Status' belongs_to :status, class_name: 'Milestone::Status'
validates :investment, presence: true validates :investment, presence: true
validates :publication_date, presence: true validates :publication_date, presence: true

View File

@@ -1,4 +1,4 @@
class Budget::Investment::Status < ActiveRecord::Base class Milestone::Status < ActiveRecord::Base
acts_as_paranoid column: :hidden_at acts_as_paranoid column: :hidden_at
has_many :milestones has_many :milestones

View File

@@ -57,7 +57,7 @@
<% if feature?(:budgets) %> <% if feature?(:budgets) %>
<li class="section-title <%= "is-active" if controller_name == "budgets" || <li class="section-title <%= "is-active" if controller_name == "budgets" ||
controller_name == "budget_investment_statuses" %>"> controller_name == "milestone_statuses" %>">
<%= link_to admin_budgets_path do %> <%= link_to admin_budgets_path do %>
<span class="icon-budget"></span> <span class="icon-budget"></span>
<strong><%= t("admin.menu.budgets") %></strong> <strong><%= t("admin.menu.budgets") %></strong>

View File

@@ -8,7 +8,7 @@
{ include_blank: @statuses.any? ? '' : t('admin.milestones.form.no_statuses_defined') }, { include_blank: @statuses.any? ? '' : t('admin.milestones.form.no_statuses_defined') },
{ disabled: @statuses.blank? } %> { disabled: @statuses.blank? } %>
<%= link_to t('admin.milestones.form.admin_statuses'), <%= link_to t('admin.milestones.form.admin_statuses'),
admin_budget_investment_statuses_path %> admin_milestone_statuses_path %>
</div> </div>
<%= f.translatable_fields do |translations_form| %> <%= f.translatable_fields do |translations_form| %>

View File

@@ -1,5 +0,0 @@
<%= back_link_to admin_budget_investment_statuses_path %>
<h2><%= t("admin.statuses.edit.title") %></h2>
<%= render '/admin/budget_investment_statuses/form' %>

View File

@@ -1,5 +0,0 @@
<%= back_link_to admin_budget_investment_statuses_path %>
<h2><%= t("admin.statuses.new.title") %></h2>
<%= render '/admin/budget_investment_statuses/form' %>

View File

@@ -0,0 +1,5 @@
<%= back_link_to admin_milestone_statuses_path %>
<h2><%= t("admin.statuses.edit.title") %></h2>
<%= render '/admin/milestone_statuses/form' %>

View File

@@ -1,7 +1,7 @@
<h2 class="inline-block"><%= t("admin.statuses.index.title") %></h2> <h2 class="inline-block"><%= t("admin.statuses.index.title") %></h2>
<%= link_to t("admin.statuses.index.new_status"), <%= 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" %> class: "button float-right margin-right" %>
<% if @statuses.any? %> <% if @statuses.any? %>
@@ -15,7 +15,7 @@
</thead> </thead>
<tbody> <tbody>
<% @statuses.each do |status| %> <% @statuses.each do |status| %>
<tr id="<%= dom_id(status) %>" class="budget_investment_status"> <tr id="<%= dom_id(status) %>" class="milestone_status">
<td> <td>
<%= status.name %> <%= status.name %>
</td> </td>
@@ -24,10 +24,10 @@
</td> </td>
<td> <td>
<%= link_to t("admin.statuses.index.edit"), <%= 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" %> method: :get, class: "button hollow" %>
<%= link_to t("admin.statuses.index.delete"), <%= link_to t("admin.statuses.index.delete"),
admin_budget_investment_status_path(status), admin_milestone_status_path(status),
method: :delete, class: "button hollow alert" %> method: :delete, class: "button hollow alert" %>
</td> </td>
</tr> </tr>

View File

@@ -0,0 +1,5 @@
<%= back_link_to admin_milestone_statuses_path %>
<h2><%= t("admin.statuses.new.title") %></h2>
<%= render '/admin/milestone_statuses/form' %>

View File

@@ -13,9 +13,9 @@ en:
budget/investment/milestone: budget/investment/milestone:
one: "milestone" one: "milestone"
other: "milestones" other: "milestones"
budget/investment/status: milestone/status:
one: "Investment status" one: "Milestone Status"
other: "Investment statuses" other: "Milestone Statuses"
comment: comment:
one: "Comment" one: "Comment"
other: "Comments" other: "Comments"

View File

@@ -286,24 +286,24 @@ en:
notice: Milestone successfully deleted notice: Milestone successfully deleted
statuses: statuses:
index: index:
title: Investment statuses title: Milestone statuses
empty_statuses: There are no investment statuses created empty_statuses: There are no milestone statuses created
new_status: Create new investment status new_status: Create new milestone status
table_name: Name table_name: Name
table_description: Description table_description: Description
table_actions: Actions table_actions: Actions
delete: Delete delete: Delete
edit: Edit edit: Edit
edit: edit:
title: Edit investment status title: Edit milestone status
update: update:
notice: Investment status updated successfully notice: Milestone status updated successfully
new: new:
title: Create investment status title: Create milestone status
create: create:
notice: Investment status created successfully notice: Milestone status created successfully
delete: delete:
notice: Investment status deleted successfully notice: Milestone status deleted successfully
comments: comments:
index: index:
filter: Filter filter: Filter

View File

@@ -13,9 +13,9 @@ es:
budget/investment/milestone: budget/investment/milestone:
one: "hito" one: "hito"
other: "hitos" other: "hitos"
budget/investment/status: milestone/status:
one: "Estado del proyecto" one: "Estado de seguimiento"
other: "Estados del proyecto" other: "Estados de seguimiento"
comment: comment:
one: "Comentario" one: "Comentario"
other: "Comentarios" other: "Comentarios"

View File

@@ -286,24 +286,24 @@ es:
notice: Hito borrado correctamente notice: Hito borrado correctamente
statuses: statuses:
index: index:
title: Estados de proyectos title: Estados de seguimiento
empty_statuses: Aún no se ha creado ningún estado de proyecto empty_statuses: Aún no se ha creado ningún estado de seguimiento
new_status: Crear nuevo estado de proyecto new_status: Crear nuevo estado de seguimiento
table_name: Nombre table_name: Nombre
table_description: Descripción table_description: Descripción
table_actions: Acciones table_actions: Acciones
delete: Borrar delete: Borrar
edit: Editar edit: Editar
edit: edit:
title: Editar estado de proyecto title: Editar estado de seguimiento
update: update:
notice: Estado de proyecto editado correctamente notice: Estado de seguimiento editado correctamente
new: new:
title: Crear estado de proyecto title: Crear estado de seguimiento
create: create:
notice: Estado de proyecto creado correctamente notice: Estado de seguimiento creado correctamente
delete: delete:
notice: Estado de proyecto eliminado correctamente notice: Estado de seguimiento eliminado correctamente
comments: comments:
index: index:
filter: Filtro filter: Filtro

View File

@@ -69,7 +69,7 @@ namespace :admin do
resources :budget_phases, only: [:edit, :update] resources :budget_phases, only: [:edit, :update]
end 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] resources :signature_sheets, only: [:index, :new, :create, :show]

View File

@@ -139,16 +139,16 @@ section "Creating Valuation Assignments" do
end end
end end
section "Creating default Investment Milestone Statuses" do section "Creating default Milestone Statuses" do
Budget::Investment::Status.create(name: I18n.t('seeds.budgets.statuses.studying_project')) Milestone::Status.create(name: I18n.t('seeds.budgets.statuses.studying_project'))
Budget::Investment::Status.create(name: I18n.t('seeds.budgets.statuses.bidding')) Milestone::Status.create(name: I18n.t('seeds.budgets.statuses.bidding'))
Budget::Investment::Status.create(name: I18n.t('seeds.budgets.statuses.executing_project')) Milestone::Status.create(name: I18n.t('seeds.budgets.statuses.executing_project'))
Budget::Investment::Status.create(name: I18n.t('seeds.budgets.statuses.executed')) Milestone::Status.create(name: I18n.t('seeds.budgets.statuses.executed'))
end end
section "Creating investment milestones" do section "Creating investment milestones" do
Budget::Investment.find_each do |investment| 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| I18n.available_locales.map do |locale|
Globalize.with_locale(locale) do Globalize.with_locale(locale) do
milestone.description = "Description for locale #{locale}" milestone.description = "Description for locale #{locale}"

View File

@@ -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

View File

@@ -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", ["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 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| create_table "moderators", force: :cascade do |t|
t.integer "user_id" t.integer "user_id"
end end

View File

@@ -193,14 +193,14 @@ FactoryBot.define do
reason "unfeasible" reason "unfeasible"
end end
factory :budget_investment_status, class: 'Budget::Investment::Status' do factory :milestone_status, class: 'Milestone::Status' do
sequence(:name) { |n| "Budget investment status #{n} name" } sequence(:name) { |n| "Milestone status #{n} name" }
sequence(:description) { |n| "Budget investment status #{n} description" } sequence(:description) { |n| "Milestone status #{n} description" }
end end
factory :budget_investment_milestone, class: 'Budget::Investment::Milestone' do factory :budget_investment_milestone, class: 'Budget::Investment::Milestone' do
association :investment, factory: :budget_investment association :investment, factory: :budget_investment
association :status, factory: :budget_investment_status association :status, factory: :milestone_status
sequence(:title) { |n| "Budget investment milestone #{n} title" } sequence(:title) { |n| "Budget investment milestone #{n} title" }
description 'Milestone description' description 'Milestone description'
publication_date { Date.current } publication_date { Date.current }

View File

@@ -41,7 +41,7 @@ feature 'Admin budget investment milestones' do
context "New" do context "New" do
scenario "Add milestone" do scenario "Add milestone" do
status = create(:budget_investment_status) 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' click_link 'Create new milestone'

View File

@@ -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

View File

@@ -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

View File

@@ -46,7 +46,7 @@ feature 'Executions' do
end end
scenario "Show message when there are no winning investments with the selected status", :js do 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) visit budget_path(budget)
@@ -129,8 +129,8 @@ feature 'Executions' do
context 'Filters' do context 'Filters' do
let!(:status1) { create(:budget_investment_status, name: I18n.t('seeds.budgets.statuses.studying_project')) } let!(:status1) { create(:milestone_status, name: I18n.t('seeds.budgets.statuses.studying_project')) }
let!(:status2) { create(:budget_investment_status, name: I18n.t('seeds.budgets.statuses.bidding')) } let!(:status2) { create(:milestone_status, name: I18n.t('seeds.budgets.statuses.bidding')) }
scenario 'Filters select with counter are shown' do scenario 'Filters select with counter are shown' do
create(:budget_investment_milestone, investment: investment1, create(:budget_investment_milestone, investment: investment1,
@@ -154,7 +154,7 @@ feature 'Executions' do
scenario 'by milestone status', :js do scenario 'by milestone status', :js do
create(:budget_investment_milestone, investment: investment1, status: status1) create(:budget_investment_milestone, investment: investment1, status: status1)
create(:budget_investment_milestone, investment: investment2, status: status2) 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) visit budget_path(budget)
@@ -260,7 +260,7 @@ feature 'Executions' do
context 'No milestones' do context 'No milestones' do
scenario 'Milestone not yet published' do scenario 'Milestone not yet published' do
status = create(:budget_investment_status) status = create(:milestone_status)
unpublished_milestone = create(:budget_investment_milestone, investment: investment1, unpublished_milestone = create(:budget_investment_milestone, investment: investment1,
status: status, publication_date: Date.tomorrow) status: status, publication_date: Date.tomorrow)

View File

@@ -1,9 +1,9 @@
require 'rails_helper' require 'rails_helper'
describe Budget::Investment::Status do describe Milestone::Status do
describe "Validations" do describe "Validations" do
let(:status) { build(:budget_investment_status) } let(:status) { build(:milestone_status) }
it "is valid" do it "is valid" do
expect(status).to be_valid expect(status).to be_valid