Merge branch 'master' into feature/2275#destroy_budgets
This commit is contained in:
@@ -20,7 +20,7 @@ Rails:
|
||||
Enabled: true
|
||||
|
||||
Metrics/LineLength:
|
||||
Max: 140
|
||||
Max: 100
|
||||
|
||||
Layout/IndentationConsistency:
|
||||
EnforcedStyle: rails
|
||||
|
||||
@@ -27,7 +27,7 @@ class Admin::BudgetsController < Admin::BaseController
|
||||
|
||||
def update
|
||||
if @budget.update(budget_params)
|
||||
redirect_to admin_budget_path(@budget), notice: t('admin.budgets.update.notice')
|
||||
redirect_to admin_budgets_path, notice: t('admin.budgets.update.notice')
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class BudgetsController < ApplicationController
|
||||
include FeatureFlags
|
||||
include BudgetsHelper
|
||||
feature_flag :budgets
|
||||
|
||||
load_and_authorize_resource
|
||||
@@ -9,6 +10,7 @@ class BudgetsController < ApplicationController
|
||||
respond_to :html, :js
|
||||
|
||||
def show
|
||||
raise ActionController::RoutingError, 'Not Found' unless budget_published?(@budget)
|
||||
end
|
||||
|
||||
def index
|
||||
|
||||
@@ -42,4 +42,9 @@ module BudgetsHelper
|
||||
def investment_tags_select_options
|
||||
Budget::Investment.tags_on(:valuation).order(:name).select(:name).distinct
|
||||
end
|
||||
|
||||
def budget_published?(budget)
|
||||
!budget.drafting? || current_user&.administrator?
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -3,7 +3,8 @@ class Budget < ActiveRecord::Base
|
||||
include Measurable
|
||||
include Sluggable
|
||||
|
||||
PHASES = %w(accepting reviewing selecting valuating balloting reviewing_ballots finished).freeze
|
||||
PHASES = %w(drafting accepting reviewing selecting valuating balloting
|
||||
reviewing_ballots finished).freeze
|
||||
CURRENCY_SYMBOLS = %w(€ $ £ ¥).freeze
|
||||
|
||||
validates :name, presence: true, uniqueness: true
|
||||
@@ -19,6 +20,7 @@ class Budget < ActiveRecord::Base
|
||||
before_validation :sanitize_descriptions
|
||||
|
||||
scope :on_hold, -> { where(phase: %w(reviewing valuating reviewing_ballots")) }
|
||||
scope :drafting, -> { where(phase: "drafting") }
|
||||
scope :accepting, -> { where(phase: "accepting") }
|
||||
scope :reviewing, -> { where(phase: "reviewing") }
|
||||
scope :selecting, -> { where(phase: "selecting") }
|
||||
@@ -41,6 +43,10 @@ class Budget < ActiveRecord::Base
|
||||
80
|
||||
end
|
||||
|
||||
def drafting?
|
||||
phase == "drafting"
|
||||
end
|
||||
|
||||
def accepting?
|
||||
phase == "accepting"
|
||||
end
|
||||
|
||||
@@ -16,14 +16,16 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @budgets.each do |budget| %>
|
||||
<tr>
|
||||
<td>
|
||||
<%= link_to budget.name, budget %>
|
||||
</td>
|
||||
<td>
|
||||
<%= budget.translated_phase %>
|
||||
</td>
|
||||
</tr>
|
||||
<% if budget_published?(budget) %>
|
||||
<tr>
|
||||
<td>
|
||||
<%= link_to budget.name, budget %>
|
||||
</td>
|
||||
<td>
|
||||
<%= budget.translated_phase %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
<% provide :social_media_meta_tags do %>
|
||||
<%= render "shared/social_media_meta_tags",
|
||||
social_url: budget_investments_path(investment),
|
||||
social_title: investment.title,
|
||||
social_description: investment.description,
|
||||
twitter_image_url: (investment.image.present? ? investment.image_url(:thumb) : nil),
|
||||
og_image_url: (investment.image.present? ? investment.image_url(:thumb) : nil) %>
|
||||
<% end %>
|
||||
|
||||
<section class="budget-investment-show" id="<%= dom_id(investment) %>">
|
||||
|
||||
<div class="row">
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
<%= render "shared/social_media_meta_tags",
|
||||
social_url: proposal_url(@proposal),
|
||||
social_title: @proposal.title,
|
||||
social_description: @proposal.summary %>
|
||||
social_description: @proposal.summary,
|
||||
twitter_image_url: (@proposal.image.present? ? @proposal.image_url(:thumb) : nil),
|
||||
og_image_url: (@proposal.image.present? ? @proposal.image_url(:thumb) : nil) %>
|
||||
<% end %>
|
||||
<% content_for :canonical do %>
|
||||
<%= render "shared/canonical", href: proposal_url(@proposal) %>
|
||||
|
||||
@@ -29,6 +29,7 @@ en:
|
||||
unselected_title: Investments not selected for balloting phase
|
||||
unselected: See investments not selected for balloting phase
|
||||
phase:
|
||||
drafting: Draft (Not visible to the public)
|
||||
accepting: Accepting projects
|
||||
reviewing: Reviewing projects
|
||||
selecting: Selecting projects
|
||||
|
||||
@@ -29,6 +29,7 @@ es:
|
||||
unselected_title: Propuestas no seleccionadas para la votación final
|
||||
unselected: Ver las propuestas no seleccionadas para la votación final
|
||||
phase:
|
||||
drafting: Borrador (No visible para el público)
|
||||
accepting: Presentación de proyectos
|
||||
reviewing: Revisión interna de proyectos
|
||||
selecting: Fase de apoyos
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddDraftingPhaseToBudget < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :budgets, :description_drafting, :text
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20171220010000) do
|
||||
ActiveRecord::Schema.define(version: 20180108182839) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -201,6 +201,7 @@ ActiveRecord::Schema.define(version: 20171220010000) do
|
||||
t.text "description_reviewing_ballots"
|
||||
t.text "description_finished"
|
||||
t.string "slug"
|
||||
t.text "description_drafting"
|
||||
end
|
||||
|
||||
create_table "campaigns", force: :cascade do |t|
|
||||
|
||||
@@ -8,21 +8,33 @@ describe 'Customization Engine' do
|
||||
let(:test_key) { I18n.t('account.show.change_credentials_link') }
|
||||
let!(:default_path) { I18n.load_path }
|
||||
|
||||
before do
|
||||
reset_load_path_and_reload(default_path)
|
||||
end
|
||||
|
||||
after do
|
||||
reset_load_path_and_reload(default_path)
|
||||
end
|
||||
|
||||
it "loads custom and override original locales" do
|
||||
I18n.load_path += Dir[Rails.root.join('spec', 'support', 'locales', 'custom', '*.{rb,yml}')]
|
||||
I18n.reload!
|
||||
increase_load_path_and_reload(Dir[Rails.root.join('spec', 'support',
|
||||
'locales', 'custom', '*.{rb,yml}')])
|
||||
expect(test_key).to eq 'Overriden string with custom locales'
|
||||
end
|
||||
|
||||
it "does not override original locales" do
|
||||
I18n.load_path.delete_if {|item| item =~ /spec\/support\/locales\/custom/ }
|
||||
I18n.load_path += Dir[Rails.root.join('spec', 'support', 'locales', '**', '*.{rb,yml}')]
|
||||
I18n.reload!
|
||||
increase_load_path_and_reload(Dir[Rails.root.join('spec', 'support',
|
||||
'locales', '**', '*.{rb,yml}')])
|
||||
expect(test_key).to eq 'Not overriden string with custom locales'
|
||||
end
|
||||
|
||||
after do
|
||||
I18n.load_path = default_path
|
||||
def reset_load_path_and_reload(path)
|
||||
I18n.load_path = path
|
||||
I18n.reload!
|
||||
end
|
||||
|
||||
def increase_load_path_and_reload(path)
|
||||
I18n.load_path += path
|
||||
I18n.reload!
|
||||
end
|
||||
|
||||
|
||||
@@ -223,6 +223,7 @@ FactoryBot.define do
|
||||
sequence(:name) { |n| "Budget #{n}" }
|
||||
currency_symbol "€"
|
||||
phase 'accepting'
|
||||
description_drafting "This budget is drafting"
|
||||
description_accepting "This budget is accepting"
|
||||
description_reviewing "This budget is reviewing"
|
||||
description_selecting "This budget is selecting"
|
||||
@@ -231,6 +232,10 @@ FactoryBot.define do
|
||||
description_reviewing_ballots "This budget is reviewing ballots"
|
||||
description_finished "This budget is finished"
|
||||
|
||||
trait :drafting do
|
||||
phase 'drafting'
|
||||
end
|
||||
|
||||
trait :accepting do
|
||||
phase 'accepting'
|
||||
end
|
||||
|
||||
@@ -34,32 +34,32 @@ feature 'Admin budgets' do
|
||||
end
|
||||
|
||||
scenario 'Filters by phase' do
|
||||
budget1 = create(:budget)
|
||||
budget2 = create(:budget, :accepting)
|
||||
budget3 = create(:budget, :selecting)
|
||||
budget4 = create(:budget, :balloting)
|
||||
budget5 = create(:budget, :finished)
|
||||
drafting_budget = create(:budget, :drafting)
|
||||
accepting_budget = create(:budget, :accepting)
|
||||
selecting_budget = create(:budget, :selecting)
|
||||
balloting_budget = create(:budget, :balloting)
|
||||
finished_budget = create(:budget, :finished)
|
||||
|
||||
visit admin_budgets_path
|
||||
expect(page).to have_content(budget1.name)
|
||||
expect(page).to have_content(budget2.name)
|
||||
expect(page).to have_content(budget3.name)
|
||||
expect(page).to have_content(budget4.name)
|
||||
expect(page).not_to have_content(budget5.name)
|
||||
expect(page).to have_content(drafting_budget.name)
|
||||
expect(page).to have_content(accepting_budget.name)
|
||||
expect(page).to have_content(selecting_budget.name)
|
||||
expect(page).to have_content(balloting_budget.name)
|
||||
expect(page).not_to have_content(finished_budget.name)
|
||||
|
||||
click_link 'Finished'
|
||||
expect(page).not_to have_content(budget1.name)
|
||||
expect(page).not_to have_content(budget2.name)
|
||||
expect(page).not_to have_content(budget3.name)
|
||||
expect(page).not_to have_content(budget4.name)
|
||||
expect(page).to have_content(budget5.name)
|
||||
expect(page).not_to have_content(drafting_budget.name)
|
||||
expect(page).not_to have_content(accepting_budget.name)
|
||||
expect(page).not_to have_content(selecting_budget.name)
|
||||
expect(page).not_to have_content(balloting_budget.name)
|
||||
expect(page).to have_content(finished_budget.name)
|
||||
|
||||
click_link 'Open'
|
||||
expect(page).to have_content(budget1.name)
|
||||
expect(page).to have_content(budget2.name)
|
||||
expect(page).to have_content(budget3.name)
|
||||
expect(page).to have_content(budget4.name)
|
||||
expect(page).not_to have_content(budget5.name)
|
||||
expect(page).to have_content(drafting_budget.name)
|
||||
expect(page).to have_content(accepting_budget.name)
|
||||
expect(page).to have_content(selecting_budget.name)
|
||||
expect(page).to have_content(balloting_budget.name)
|
||||
expect(page).not_to have_content(finished_budget.name)
|
||||
end
|
||||
|
||||
scenario 'Open filter is properly highlighted' do
|
||||
@@ -133,6 +133,24 @@ feature 'Admin budgets' do
|
||||
expect(page).to have_content('You cannot destroy a Budget that has associated investments')
|
||||
expect(page).to have_content('There is 1 participatory budget')
|
||||
end
|
||||
end
|
||||
|
||||
context 'Update' do
|
||||
|
||||
background do
|
||||
create(:budget)
|
||||
end
|
||||
|
||||
scenario 'Update budget' do
|
||||
visit admin_budgets_path
|
||||
click_link 'Edit budget'
|
||||
|
||||
fill_in 'budget_name', with: 'More trees on the streets'
|
||||
click_button 'Update Participatory budget'
|
||||
|
||||
expect(page).to have_content('More trees on the streets')
|
||||
expect(page).to have_current_path(admin_budgets_path)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@ require 'rails_helper'
|
||||
|
||||
feature 'Budgets' do
|
||||
|
||||
let(:budget) { create(:budget) }
|
||||
let(:level_two_user) { create(:user, :level_two) }
|
||||
|
||||
scenario 'Index' do
|
||||
budgets = create_list(:budget, 3)
|
||||
visit budgets_path
|
||||
@@ -11,7 +14,6 @@ feature 'Budgets' do
|
||||
context 'Show' do
|
||||
|
||||
scenario "List all groups" do
|
||||
budget = create(:budget)
|
||||
group1 = create(:budget_group, budget: budget)
|
||||
group2 = create(:budget_group, budget: budget)
|
||||
|
||||
@@ -61,9 +63,59 @@ feature 'Budgets' do
|
||||
|
||||
end
|
||||
|
||||
context 'Accepting' do
|
||||
context "In Drafting phase" do
|
||||
|
||||
let(:budget) { create(:budget) }
|
||||
let(:admin) { create(:administrator).user }
|
||||
|
||||
background do
|
||||
logout
|
||||
budget.update(phase: 'drafting')
|
||||
end
|
||||
|
||||
context "Listed" do
|
||||
scenario "Not listed to guest users at the public budgets list" do
|
||||
visit budgets_path
|
||||
|
||||
expect(page).not_to have_content(budget.name)
|
||||
end
|
||||
|
||||
scenario "Not listed to logged users at the public budgets list" do
|
||||
login_as(level_two_user)
|
||||
visit budgets_path
|
||||
|
||||
expect(page).not_to have_content(budget.name)
|
||||
end
|
||||
|
||||
scenario "Is listed to admins at the public budgets list" do
|
||||
login_as(admin)
|
||||
visit budgets_path
|
||||
|
||||
expect(page).to have_content(budget.name)
|
||||
end
|
||||
end
|
||||
|
||||
context "Shown" do
|
||||
scenario "Not accesible to guest users" do
|
||||
expect { visit budget_path(budget) }.to raise_error(ActionController::RoutingError)
|
||||
end
|
||||
|
||||
scenario "Not accesible to logged users" do
|
||||
login_as(level_two_user)
|
||||
|
||||
expect { visit budget_path(budget) }.to raise_error(ActionController::RoutingError)
|
||||
end
|
||||
|
||||
scenario "Is accesible to admin users" do
|
||||
login_as(admin)
|
||||
visit budget_path(budget)
|
||||
|
||||
expect(page.status_code).to eq(200)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'Accepting' do
|
||||
|
||||
background do
|
||||
budget.update(phase: 'accepting')
|
||||
@@ -72,8 +124,7 @@ feature 'Budgets' do
|
||||
context "Permissions" do
|
||||
|
||||
scenario "Verified user" do
|
||||
user = create(:user, :level_two)
|
||||
login_as(user)
|
||||
login_as(level_two_user)
|
||||
|
||||
visit budget_path(budget)
|
||||
|
||||
@@ -97,4 +148,4 @@ feature 'Budgets' do
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -65,7 +65,7 @@ feature 'Results' do
|
||||
end
|
||||
|
||||
scenario "If budget is in a phase different from finished results can't be accessed" do
|
||||
budget.update phase: (Budget::PHASES - ["finished"]).sample
|
||||
budget.update(phase: (Budget::PHASES - ['drafting', 'finished']).sample)
|
||||
visit budget_path(budget)
|
||||
expect(page).not_to have_link "See results"
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ feature 'Tags' do
|
||||
let!(:heading) { create(:budget_heading, name: "More hospitals", group: group) }
|
||||
let!(:tag_medio_ambiente) { create(:tag, :category, name: 'Medio Ambiente') }
|
||||
let!(:tag_economia) { create(:tag, :category, name: 'Economía') }
|
||||
let(:admin) { create(:administrator).user }
|
||||
|
||||
scenario 'Index' do
|
||||
earth = create(:budget_investment, heading: heading, tag_list: tag_medio_ambiente.name)
|
||||
@@ -185,6 +186,7 @@ feature 'Tags' do
|
||||
Budget::PHASES.each do |phase|
|
||||
budget.update(phase: phase)
|
||||
|
||||
login_as(admin) if budget.drafting?
|
||||
visit budget_investments_path(budget, heading_id: heading.id)
|
||||
|
||||
within "#tag-cloud" do
|
||||
@@ -204,6 +206,7 @@ feature 'Tags' do
|
||||
end
|
||||
end
|
||||
|
||||
login_as(admin) if budget.drafting?
|
||||
visit budget_path(budget)
|
||||
click_link group.name
|
||||
|
||||
@@ -230,6 +233,7 @@ feature 'Tags' do
|
||||
Budget::PHASES.each do |phase|
|
||||
budget.update(phase: phase)
|
||||
|
||||
login_as(admin) if budget.drafting?
|
||||
visit budget_investments_path(budget, heading_id: heading.id)
|
||||
|
||||
within "#categories" do
|
||||
@@ -249,6 +253,7 @@ feature 'Tags' do
|
||||
end
|
||||
end
|
||||
|
||||
login_as(admin) if budget.drafting?
|
||||
visit budget_path(budget)
|
||||
click_link group.name
|
||||
|
||||
@@ -282,8 +287,7 @@ feature 'Tags' do
|
||||
investment.set_tag_list_on(:valuation, 'Education')
|
||||
investment.save
|
||||
|
||||
admin = create(:administrator)
|
||||
login_as(admin.user)
|
||||
login_as(admin)
|
||||
|
||||
visit admin_budget_budget_investment_path(budget, investment)
|
||||
click_link 'Edit classification'
|
||||
|
||||
@@ -40,6 +40,9 @@ describe Budget do
|
||||
end
|
||||
|
||||
it "produces auxiliary methods" do
|
||||
budget.phase = "drafting"
|
||||
expect(budget).to be_drafting
|
||||
|
||||
budget.phase = "accepting"
|
||||
expect(budget).to be_accepting
|
||||
|
||||
@@ -63,6 +66,9 @@ describe Budget do
|
||||
end
|
||||
|
||||
it "on_hold?" do
|
||||
budget.phase = "drafting"
|
||||
expect(budget).not_to be_on_hold
|
||||
|
||||
budget.phase = "accepting"
|
||||
expect(budget).not_to be_on_hold
|
||||
|
||||
@@ -86,6 +92,9 @@ describe Budget do
|
||||
end
|
||||
|
||||
it "balloting_or_later?" do
|
||||
budget.phase = "drafting"
|
||||
expect(budget).not_to be_balloting_or_later
|
||||
|
||||
budget.phase = "accepting"
|
||||
expect(budget).not_to be_balloting_or_later
|
||||
|
||||
|
||||
Reference in New Issue
Block a user