Add CRUD Milestone on Admin::BudgetInvestment. Rename Checkpoint to Milestone.
This commit is contained in:
@@ -0,0 +1,55 @@
|
|||||||
|
class Admin::BudgetInvestmentMilestonesController < Admin::BaseController
|
||||||
|
|
||||||
|
before_action :load_budget_investment, only: [:index, :new, :create, :edit, :update, :destroy]
|
||||||
|
before_action :load_budget_investment_milestone, only: [:edit, :update, :destroy]
|
||||||
|
|
||||||
|
def index
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@milestone = Budget::Investment::Milestone.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@milestone = Budget::Investment::Milestone.new(milestone_params)
|
||||||
|
@milestone.investment = @investment
|
||||||
|
if @milestone.save
|
||||||
|
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment), notice: t('admin.milestones.create.notice')
|
||||||
|
else
|
||||||
|
render :new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if @milestone.update(milestone_params)
|
||||||
|
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment), notice: t('admin.milestones.update.notice')
|
||||||
|
else
|
||||||
|
render :edit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@milestone.destroy
|
||||||
|
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment), notice: t('admin.milestones.delete.notice')
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def milestone_params
|
||||||
|
params.require(:budget_investment_milestone)
|
||||||
|
.permit(:title, :description, :budget_investment_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_budget_investment
|
||||||
|
@investment = Budget::Investment.find params[:budget_investment_id]
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_budget_investment_milestone
|
||||||
|
@milestone = Budget::Investment::Milestone.find params[:id]
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
@@ -20,7 +20,7 @@ class Budget
|
|||||||
has_many :valuator_assignments, dependent: :destroy
|
has_many :valuator_assignments, dependent: :destroy
|
||||||
has_many :valuators, through: :valuator_assignments
|
has_many :valuators, through: :valuator_assignments
|
||||||
has_many :comments, as: :commentable
|
has_many :comments, as: :commentable
|
||||||
has_many :checkpoints
|
has_many :milestones
|
||||||
|
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
validates :author, presence: true
|
validates :author, presence: true
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
class Budget
|
class Budget
|
||||||
class Investment
|
class Investment
|
||||||
class Checkpoint < ActiveRecord::Base
|
class Milestone < ActiveRecord::Base
|
||||||
belongs_to :investment
|
belongs_to :investment
|
||||||
|
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
validates :investment, presence: true
|
validates :investment, presence: true
|
||||||
|
|
||||||
|
def self.title_max_length
|
||||||
|
80
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<%= form_for [:admin, @investment.budget, @investment, @milestone] do |f| %>
|
||||||
|
|
||||||
|
<%= f.text_field :title, maxlength: Budget::Investment::Milestone.title_max_length %>
|
||||||
|
<%= f.text_area :description %>
|
||||||
|
|
||||||
|
<%= f.submit nil, class: "button success" %>
|
||||||
|
<% end %>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<%= back_link_to admin_budget_budget_investment_path(@investment.budget, @investment) %>
|
||||||
|
|
||||||
|
<h2><%= t("admin.milestones.edit.title") %></h2>
|
||||||
|
|
||||||
|
<%= render '/admin/budget_investment_milestones/form' %>
|
||||||
10
app/views/admin/budget_investment_milestones/new.html.erb
Normal file
10
app/views/admin/budget_investment_milestones/new.html.erb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<div class="milestone-new row">
|
||||||
|
|
||||||
|
<div class="small-12 column">
|
||||||
|
<%= back_link_to admin_budget_budget_investment_path(@investment.budget, @investment) %>
|
||||||
|
|
||||||
|
<h1><%= t("admin.milestones.new.creating") %></h1>
|
||||||
|
|
||||||
|
<%= render "form" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
32
app/views/admin/budget_investments/_milestones.html.erb
Normal file
32
app/views/admin/budget_investments/_milestones.html.erb
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<% if @investment.milestones.any? %>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><%= t("admin.milestones.index.table_id") %></th>
|
||||||
|
<th><%= t("admin.milestones.index.table_title") %></th>
|
||||||
|
<th><%= t("admin.milestones.index.table_description") %></th>
|
||||||
|
<th><%= t("admin.milestones.index.table_actions") %></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% @investment.milestones.each do |milestone| %>
|
||||||
|
<tr id="<%= dom_id(milestone) %>" class="milestone">
|
||||||
|
<td>
|
||||||
|
<%= milestone.id %>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= link_to milestone.title, edit_admin_budget_budget_investment_budget_investment_milestone_path(@investment.budget, @investment, milestone) %>
|
||||||
|
</td>
|
||||||
|
<td class="small">
|
||||||
|
<%= milestone.description %>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= link_to t("admin.milestones.index.delete"), admin_budget_budget_investment_budget_investment_milestone_path(@investment.budget, @investment, milestone),
|
||||||
|
method: :delete,
|
||||||
|
class: 'button hollow alert expanded' %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<% end %>
|
||||||
@@ -47,3 +47,12 @@
|
|||||||
<%= link_to t("admin.budget_investments.show.edit_dossier"), edit_valuation_budget_budget_investment_path(@budget, @investment) %>
|
<%= link_to t("admin.budget_investments.show.edit_dossier"), edit_valuation_budget_budget_investment_path(@budget, @investment) %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<h2><%= t("admin.budget_investments.show.milestone") %></h2>
|
||||||
|
|
||||||
|
<%= render 'admin/budget_investments/milestones' %>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= link_to t("admin.budget_investments.show.new_milestone"), new_admin_budget_budget_investment_budget_investment_milestone_path(@budget, @investment) %>
|
||||||
|
</p>
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ en:
|
|||||||
budget/investment:
|
budget/investment:
|
||||||
one: "Investment"
|
one: "Investment"
|
||||||
other: "Investments"
|
other: "Investments"
|
||||||
|
budget/investment/milestone:
|
||||||
|
one: "milestone"
|
||||||
|
other: "milestones"
|
||||||
comment:
|
comment:
|
||||||
one: "Comment"
|
one: "Comment"
|
||||||
other: "Comments"
|
other: "Comments"
|
||||||
@@ -98,6 +101,9 @@ en:
|
|||||||
title: "Title"
|
title: "Title"
|
||||||
location: "Location"
|
location: "Location"
|
||||||
organization_name: "If you are proposing in the name of a collective/organization, write its name"
|
organization_name: "If you are proposing in the name of a collective/organization, write its name"
|
||||||
|
budget/investment/milestone:
|
||||||
|
title: "Title"
|
||||||
|
description: "Description"
|
||||||
comment:
|
comment:
|
||||||
body: "Comment"
|
body: "Comment"
|
||||||
user: "User"
|
user: "User"
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ es:
|
|||||||
budget/investment:
|
budget/investment:
|
||||||
one: "Proyecto de inversión"
|
one: "Proyecto de inversión"
|
||||||
other: "Proyectos de inversión"
|
other: "Proyectos de inversión"
|
||||||
|
budget/investment/milestone:
|
||||||
|
one: "seguimiento"
|
||||||
|
other: "seguimientos"
|
||||||
comment:
|
comment:
|
||||||
one: "Comentario"
|
one: "Comentario"
|
||||||
other: "Comentarios"
|
other: "Comentarios"
|
||||||
@@ -96,6 +99,9 @@ es:
|
|||||||
comment:
|
comment:
|
||||||
body: "Comentario"
|
body: "Comentario"
|
||||||
user: "Usuario"
|
user: "Usuario"
|
||||||
|
budget/investment/milestone:
|
||||||
|
title: "Título"
|
||||||
|
description: "Descripción"
|
||||||
debate:
|
debate:
|
||||||
author: "Autor"
|
author: "Autor"
|
||||||
description: "Opinión"
|
description: "Opinión"
|
||||||
|
|||||||
@@ -151,6 +151,8 @@ en:
|
|||||||
edit_dossier: Edit dossier
|
edit_dossier: Edit dossier
|
||||||
tags: Tags
|
tags: Tags
|
||||||
undefined: Undefined
|
undefined: Undefined
|
||||||
|
milestone: Milestone
|
||||||
|
new_milestone: Create new milestone
|
||||||
edit:
|
edit:
|
||||||
classification: Clasification
|
classification: Clasification
|
||||||
assigned_valuators: Valuators
|
assigned_valuators: Valuators
|
||||||
@@ -160,6 +162,23 @@ en:
|
|||||||
tags_placeholder: "Write the tags you want separated by commas (,)"
|
tags_placeholder: "Write the tags you want separated by commas (,)"
|
||||||
undefined: Undefined
|
undefined: Undefined
|
||||||
search_unfeasible: Search unfeasible
|
search_unfeasible: Search unfeasible
|
||||||
|
milestones:
|
||||||
|
index:
|
||||||
|
table_id: "ID"
|
||||||
|
table_title: "Title"
|
||||||
|
table_description: "Description"
|
||||||
|
table_actions: "Actions"
|
||||||
|
delete: "Delete milestone"
|
||||||
|
new:
|
||||||
|
creating: Create milestone
|
||||||
|
edit:
|
||||||
|
title: Edit milestone
|
||||||
|
create:
|
||||||
|
notice: New milestone created successfully!
|
||||||
|
update:
|
||||||
|
notice: Milestone updated successfully
|
||||||
|
delete:
|
||||||
|
notice: Milestone successfully deleted
|
||||||
comments:
|
comments:
|
||||||
index:
|
index:
|
||||||
filter: Filter
|
filter: Filter
|
||||||
|
|||||||
@@ -151,6 +151,8 @@ es:
|
|||||||
edit_dossier: Editar informe
|
edit_dossier: Editar informe
|
||||||
tags: Etiquetas
|
tags: Etiquetas
|
||||||
undefined: Sin definir
|
undefined: Sin definir
|
||||||
|
milestone: Seguimiento
|
||||||
|
new_milestone: Crear nuevo seguimiento
|
||||||
edit:
|
edit:
|
||||||
classification: Clasificación
|
classification: Clasificación
|
||||||
assigned_valuators: Evaluadores
|
assigned_valuators: Evaluadores
|
||||||
@@ -160,6 +162,23 @@ es:
|
|||||||
tags_placeholder: "Escribe las etiquetas que desees separadas por comas (,)"
|
tags_placeholder: "Escribe las etiquetas que desees separadas por comas (,)"
|
||||||
undefined: Sin definir
|
undefined: Sin definir
|
||||||
search_unfeasible: Buscar inviables
|
search_unfeasible: Buscar inviables
|
||||||
|
milestones:
|
||||||
|
index:
|
||||||
|
table_id: "ID"
|
||||||
|
table_title: "Título"
|
||||||
|
table_description: "Descripción"
|
||||||
|
table_actions: "Acciones"
|
||||||
|
delete: "Eliminar seguimiento"
|
||||||
|
new:
|
||||||
|
creating: Crear seguimiento
|
||||||
|
edit:
|
||||||
|
title: Editar seguimiento
|
||||||
|
create:
|
||||||
|
notice: Nuevo seguimiento creado con éxito!
|
||||||
|
update:
|
||||||
|
notice: Seguimiento actualizado
|
||||||
|
delete:
|
||||||
|
notice: Seguimiento borrado correctamente
|
||||||
comments:
|
comments:
|
||||||
index:
|
index:
|
||||||
filter: Filtro
|
filter: Filtro
|
||||||
|
|||||||
@@ -199,10 +199,12 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
|
|
||||||
resources :budget_investments, only: [:index, :show, :edit, :update] do
|
resources :budget_investments, only: [:index, :show, :edit, :update] do
|
||||||
|
resources :budget_investment_milestones
|
||||||
member { patch :toggle_selection }
|
member { patch :toggle_selection }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
resources :signature_sheets, only: [:index, :new, :create, :show]
|
resources :signature_sheets, only: [:index, :new, :create, :show]
|
||||||
|
|
||||||
resources :banners, only: [:index, :new, :create, :edit, :update, :destroy] do
|
resources :banners, only: [:index, :new, :create, :edit, :update, :destroy] do
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class CreateBudgetInvestmentCheckpoints < ActiveRecord::Migration
|
class CreateBudgetInvestmentMilestones < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
create_table :budget_investment_checkpoints do |t|
|
create_table :budget_investment_milestones do |t|
|
||||||
t.integer :investment_id
|
t.integer :investment_id
|
||||||
t.string "title", limit: 80
|
t.string "title", limit: 80
|
||||||
t.text "description"
|
t.text "description"
|
||||||
@@ -114,7 +114,7 @@ ActiveRecord::Schema.define(version: 20170620132731) do
|
|||||||
|
|
||||||
add_index "budget_headings", ["group_id"], name: "index_budget_headings_on_group_id", using: :btree
|
add_index "budget_headings", ["group_id"], name: "index_budget_headings_on_group_id", using: :btree
|
||||||
|
|
||||||
create_table "budget_investment_checkpoints", force: :cascade do |t|
|
create_table "budget_investment_milestones", force: :cascade do |t|
|
||||||
t.integer "investment_id"
|
t.integer "investment_id"
|
||||||
t.string "title", limit: 80
|
t.string "title", limit: 80
|
||||||
t.text "description"
|
t.text "description"
|
||||||
@@ -932,7 +932,7 @@ ActiveRecord::Schema.define(version: 20170620132731) do
|
|||||||
t.boolean "email_digest", default: true
|
t.boolean "email_digest", default: true
|
||||||
t.boolean "email_on_direct_message", default: true
|
t.boolean "email_on_direct_message", default: true
|
||||||
t.boolean "official_position_badge", default: false
|
t.boolean "official_position_badge", default: false
|
||||||
t.datetime "password_changed_at", default: '2017-06-20 13:30:34', null: false
|
t.datetime "password_changed_at", default: '2017-06-22 11:21:30', null: false
|
||||||
t.boolean "created_from_signature", default: false
|
t.boolean "created_from_signature", default: false
|
||||||
t.integer "failed_email_digests_count", default: 0
|
t.integer "failed_email_digests_count", default: 0
|
||||||
t.text "former_users_data_log", default: ""
|
t.text "former_users_data_log", default: ""
|
||||||
|
|||||||
@@ -322,10 +322,10 @@ FactoryGirl.define do
|
|||||||
reason "unfeasible"
|
reason "unfeasible"
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :budget_investment_checkpoint, class: 'Budget::Investment::Checkpoint' do
|
factory :budget_investment_milestone, class: 'Budget::Investment::Milestone' do
|
||||||
association :investment, factory: :budget_investment
|
association :investment, factory: :budget_investment
|
||||||
sequence(:title) { |n| "Budget Investment Checkpoint #{n} title" }
|
sequence(:title) { |n| "Budget Investment Milestone #{n} title" }
|
||||||
description 'Checkpoint description'
|
description 'Milestone description'
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :vote do
|
factory :vote do
|
||||||
|
|||||||
70
spec/features/admin/budget_investment_milestones_spec.rb
Normal file
70
spec/features/admin/budget_investment_milestones_spec.rb
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
feature 'Admin budget investment milestones' do
|
||||||
|
|
||||||
|
background do
|
||||||
|
admin = create(:administrator)
|
||||||
|
login_as(admin.user)
|
||||||
|
|
||||||
|
@investment = create(:budget_investment)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "Index" do
|
||||||
|
scenario 'Displaying milestones' do
|
||||||
|
milestone = create(:budget_investment_milestone, investment: @investment)
|
||||||
|
|
||||||
|
visit admin_budget_budget_investment_path(@investment.budget, @investment)
|
||||||
|
|
||||||
|
expect(page).to have_content("Milestone")
|
||||||
|
expect(page).to have_content(milestone.title)
|
||||||
|
expect(page).to have_content(milestone.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "New" do
|
||||||
|
scenario "Add milestone" do
|
||||||
|
visit admin_budget_budget_investment_path(@investment.budget, @investment)
|
||||||
|
|
||||||
|
click_link 'Create new milestone'
|
||||||
|
|
||||||
|
fill_in 'budget_investment_milestone_title', with: 'New title milestone'
|
||||||
|
fill_in 'budget_investment_milestone_description', with: 'New description milestone'
|
||||||
|
|
||||||
|
click_button 'Create milestone'
|
||||||
|
|
||||||
|
expect(page).to have_content 'New title milestone'
|
||||||
|
expect(page).to have_content 'New description milestone'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "Edit" do
|
||||||
|
scenario "Change title and description" do
|
||||||
|
milestone = create(:budget_investment_milestone, investment: @investment)
|
||||||
|
|
||||||
|
visit admin_budget_budget_investment_path(@investment.budget, @investment)
|
||||||
|
|
||||||
|
click_link milestone.title
|
||||||
|
|
||||||
|
fill_in 'budget_investment_milestone_title', with: 'Changed title'
|
||||||
|
fill_in 'budget_investment_milestone_description', with: 'Changed description'
|
||||||
|
|
||||||
|
click_button 'Update milestone'
|
||||||
|
|
||||||
|
expect(page).to have_content 'Changed title'
|
||||||
|
expect(page).to have_content 'Changed description'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "Delete" do
|
||||||
|
scenario "Remove milestone" do
|
||||||
|
milestone = create(:budget_investment_milestone, investment: @investment, title: "Title will it remove")
|
||||||
|
|
||||||
|
visit admin_budget_budget_investment_path(@investment.budget, @investment)
|
||||||
|
|
||||||
|
click_link "Delete milestone"
|
||||||
|
|
||||||
|
expect(page).to_not have_content 'Title will it remove'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -27,7 +27,7 @@ feature 'Admin budget investments' do
|
|||||||
|
|
||||||
context "Index" do
|
context "Index" do
|
||||||
|
|
||||||
scenario 'Displaying investmentss' do
|
scenario 'Displaying investments' do
|
||||||
budget_investment = create(:budget_investment, budget: @budget, cached_votes_up: 77)
|
budget_investment = create(:budget_investment, budget: @budget, cached_votes_up: 77)
|
||||||
visit admin_budget_budget_investments_path(budget_id: @budget.id)
|
visit admin_budget_budget_investments_path(budget_id: @budget.id)
|
||||||
expect(page).to have_content(budget_investment.title)
|
expect(page).to have_content(budget_investment.title)
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
describe "Budget::Investment::Checkpoint" do
|
|
||||||
|
|
||||||
describe "Validations" do
|
|
||||||
let(:checkpoint) { build(:budget_investment_checkpoint) }
|
|
||||||
|
|
||||||
it "should be valid" do
|
|
||||||
expect(checkpoint).to be_valid
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should not be valid without a title" do
|
|
||||||
checkpoint.title = nil
|
|
||||||
expect(checkpoint).to_not be_valid
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should not be valid without an investment" do
|
|
||||||
checkpoint.investment_id = nil
|
|
||||||
expect(checkpoint).to_not be_valid
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
23
spec/models/budget/investment/milestone_spec.rb
Normal file
23
spec/models/budget/investment/milestone_spec.rb
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe "Budget::Investment::Milestone" do
|
||||||
|
|
||||||
|
describe "Validations" do
|
||||||
|
let(:milestone) { build(:budget_investment_milestone) }
|
||||||
|
|
||||||
|
it "should be valid" do
|
||||||
|
expect(milestone).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should not be valid without a title" do
|
||||||
|
milestone.title = nil
|
||||||
|
expect(milestone).to_not be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should not be valid without an investment" do
|
||||||
|
milestone.investment_id = nil
|
||||||
|
expect(milestone).to_not be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user