diff --git a/app/controllers/admin/budget_investment_milestones_controller.rb b/app/controllers/admin/budget_investment_milestones_controller.rb new file mode 100644 index 000000000..a4b8acc5d --- /dev/null +++ b/app/controllers/admin/budget_investment_milestones_controller.rb @@ -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 diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 10d822b36..e13678cdb 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -20,7 +20,7 @@ class Budget has_many :valuator_assignments, dependent: :destroy has_many :valuators, through: :valuator_assignments has_many :comments, as: :commentable - has_many :checkpoints + has_many :milestones validates :title, presence: true validates :author, presence: true diff --git a/app/models/budget/investment/checkpoint.rb b/app/models/budget/investment/milestone.rb similarity index 63% rename from app/models/budget/investment/checkpoint.rb rename to app/models/budget/investment/milestone.rb index 6bc4229c6..9ecbe4dc3 100644 --- a/app/models/budget/investment/checkpoint.rb +++ b/app/models/budget/investment/milestone.rb @@ -1,10 +1,14 @@ class Budget class Investment - class Checkpoint < ActiveRecord::Base + class Milestone < ActiveRecord::Base belongs_to :investment validates :title, presence: true validates :investment, presence: true + + def self.title_max_length + 80 + end end end end diff --git a/app/views/admin/budget_investment_milestones/_form.html.erb b/app/views/admin/budget_investment_milestones/_form.html.erb new file mode 100644 index 000000000..5f8af9d33 --- /dev/null +++ b/app/views/admin/budget_investment_milestones/_form.html.erb @@ -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 %> diff --git a/app/views/admin/budget_investment_milestones/edit.html.erb b/app/views/admin/budget_investment_milestones/edit.html.erb new file mode 100644 index 000000000..c72cd840a --- /dev/null +++ b/app/views/admin/budget_investment_milestones/edit.html.erb @@ -0,0 +1,5 @@ +<%= back_link_to admin_budget_budget_investment_path(@investment.budget, @investment) %> + +
| <%= t("admin.milestones.index.table_id") %> | +<%= t("admin.milestones.index.table_title") %> | +<%= t("admin.milestones.index.table_description") %> | +<%= t("admin.milestones.index.table_actions") %> | +
|---|---|---|---|
| + <%= milestone.id %> + | ++ <%= link_to milestone.title, edit_admin_budget_budget_investment_budget_investment_milestone_path(@investment.budget, @investment, milestone) %> + | ++ <%= milestone.description %> + | ++ <%= 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' %> + | +
+ <%= link_to t("admin.budget_investments.show.new_milestone"), new_admin_budget_budget_investment_budget_investment_milestone_path(@budget, @investment) %> +
diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index 0af387a50..d45c569d4 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -10,6 +10,9 @@ en: budget/investment: one: "Investment" other: "Investments" + budget/investment/milestone: + one: "milestone" + other: "milestones" comment: one: "Comment" other: "Comments" @@ -98,6 +101,9 @@ en: title: "Title" location: "Location" organization_name: "If you are proposing in the name of a collective/organization, write its name" + budget/investment/milestone: + title: "Title" + description: "Description" comment: body: "Comment" user: "User" diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml index b2b5fc20e..86bb76c87 100644 --- a/config/locales/activerecord.es.yml +++ b/config/locales/activerecord.es.yml @@ -10,6 +10,9 @@ es: budget/investment: one: "Proyecto de inversión" other: "Proyectos de inversión" + budget/investment/milestone: + one: "seguimiento" + other: "seguimientos" comment: one: "Comentario" other: "Comentarios" @@ -96,6 +99,9 @@ es: comment: body: "Comentario" user: "Usuario" + budget/investment/milestone: + title: "Título" + description: "Descripción" debate: author: "Autor" description: "Opinión" diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index bbd8dd1bd..96dc32a8b 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -151,6 +151,8 @@ en: edit_dossier: Edit dossier tags: Tags undefined: Undefined + milestone: Milestone + new_milestone: Create new milestone edit: classification: Clasification assigned_valuators: Valuators @@ -160,6 +162,23 @@ en: tags_placeholder: "Write the tags you want separated by commas (,)" undefined: Undefined 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: index: filter: Filter diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index a3c6a99b9..405f70152 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -151,6 +151,8 @@ es: edit_dossier: Editar informe tags: Etiquetas undefined: Sin definir + milestone: Seguimiento + new_milestone: Crear nuevo seguimiento edit: classification: Clasificación assigned_valuators: Evaluadores @@ -160,6 +162,23 @@ es: tags_placeholder: "Escribe las etiquetas que desees separadas por comas (,)" undefined: Sin definir 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: index: filter: Filtro diff --git a/config/routes.rb b/config/routes.rb index 5c5284a91..e436244a1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -199,10 +199,12 @@ Rails.application.routes.draw do end resources :budget_investments, only: [:index, :show, :edit, :update] do + resources :budget_investment_milestones member { patch :toggle_selection } end end + resources :signature_sheets, only: [:index, :new, :create, :show] resources :banners, only: [:index, :new, :create, :edit, :update, :destroy] do diff --git a/db/migrate/20170620132731_create_budget_investment_checkpoints.rb b/db/migrate/20170620132731_create_budget_investment_milestones.rb similarity index 57% rename from db/migrate/20170620132731_create_budget_investment_checkpoints.rb rename to db/migrate/20170620132731_create_budget_investment_milestones.rb index 22081f319..199d8e70e 100644 --- a/db/migrate/20170620132731_create_budget_investment_checkpoints.rb +++ b/db/migrate/20170620132731_create_budget_investment_milestones.rb @@ -1,6 +1,6 @@ -class CreateBudgetInvestmentCheckpoints < ActiveRecord::Migration +class CreateBudgetInvestmentMilestones < ActiveRecord::Migration def change - create_table :budget_investment_checkpoints do |t| + create_table :budget_investment_milestones do |t| t.integer :investment_id t.string "title", limit: 80 t.text "description" diff --git a/db/schema.rb b/db/schema.rb index a5d7ecbb5..4cfa7229f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 - create_table "budget_investment_checkpoints", force: :cascade do |t| + create_table "budget_investment_milestones", force: :cascade do |t| t.integer "investment_id" t.string "title", limit: 80 t.text "description" @@ -932,7 +932,7 @@ ActiveRecord::Schema.define(version: 20170620132731) do t.boolean "email_digest", default: true t.boolean "email_on_direct_message", default: true 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.integer "failed_email_digests_count", default: 0 t.text "former_users_data_log", default: "" diff --git a/spec/factories.rb b/spec/factories.rb index 6401616e7..1d842e299 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -322,10 +322,10 @@ FactoryGirl.define do reason "unfeasible" end - factory :budget_investment_checkpoint, class: 'Budget::Investment::Checkpoint' do + factory :budget_investment_milestone, class: 'Budget::Investment::Milestone' do association :investment, factory: :budget_investment - sequence(:title) { |n| "Budget Investment Checkpoint #{n} title" } - description 'Checkpoint description' + sequence(:title) { |n| "Budget Investment Milestone #{n} title" } + description 'Milestone description' end factory :vote do diff --git a/spec/features/admin/budget_investment_milestones_spec.rb b/spec/features/admin/budget_investment_milestones_spec.rb new file mode 100644 index 000000000..1550f05e6 --- /dev/null +++ b/spec/features/admin/budget_investment_milestones_spec.rb @@ -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 diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index 52c008c18..c50a05f32 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -27,7 +27,7 @@ feature 'Admin budget investments' do context "Index" do - scenario 'Displaying investmentss' do + scenario 'Displaying investments' do budget_investment = create(:budget_investment, budget: @budget, cached_votes_up: 77) visit admin_budget_budget_investments_path(budget_id: @budget.id) expect(page).to have_content(budget_investment.title) diff --git a/spec/models/budget/investment/checkpoint_spec.rb b/spec/models/budget/investment/checkpoint_spec.rb deleted file mode 100644 index fe40a58bb..000000000 --- a/spec/models/budget/investment/checkpoint_spec.rb +++ /dev/null @@ -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 diff --git a/spec/models/budget/investment/milestone_spec.rb b/spec/models/budget/investment/milestone_spec.rb new file mode 100644 index 000000000..5fc749d36 --- /dev/null +++ b/spec/models/budget/investment/milestone_spec.rb @@ -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