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
def load_statuses
@statuses = Budget::Investment::Status.all
@statuses = Milestone::Status.all
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]
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

View File

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

View File

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

View File

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

View File

@@ -57,7 +57,7 @@
<% if feature?(: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 %>
<span class="icon-budget"></span>
<strong><%= t("admin.menu.budgets") %></strong>

View File

@@ -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 %>
</div>
<%= 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>
<%= 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 @@
</thead>
<tbody>
<% @statuses.each do |status| %>
<tr id="<%= dom_id(status) %>" class="budget_investment_status">
<tr id="<%= dom_id(status) %>" class="milestone_status">
<td>
<%= status.name %>
</td>
@@ -24,10 +24,10 @@
</td>
<td>
<%= 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" %>
</td>
</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:
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"

View File

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

View File

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

View File

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

View File

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

View File

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

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", ["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

View File

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

View File

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

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

View File

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