Adds basic Budget controller / views

This commit is contained in:
kikito
2016-05-31 19:26:56 +02:00
parent 0427395f32
commit fa6f34bf5c
9 changed files with 72 additions and 3 deletions

View File

@@ -0,0 +1,13 @@
class BudgetsController < ApplicationController
load_and_authorize_resource
respond_to :html, :js
def show
end
def index
@budgets = @budgets.order(:created_at)
end
end

View File

@@ -0,0 +1,8 @@
module BudgetHelper
def format_price(budget, number)
number_to_currency(number,
precision: 0,
locale: I18n.default_locale,
unit: budget.currency_symbol)
end
end

View File

@@ -18,9 +18,6 @@ module Abilities
end
can [:retire_form, :retire], Proposal, author_id: user.id
can :read, SpendingProposal
can :read, Budget::Investment
can :create, Comment
can :create, Debate
can :create, Proposal

View File

@@ -6,6 +6,8 @@ module Abilities
can [:read, :map], Debate
can [:read, :map, :summary], Proposal
can :read, Comment
can :read, Budget
can :read, Budget::Investment
can :read, SpendingProposal
can :read, Legislation
can :read, User

View File

@@ -1,8 +1,11 @@
class Budget < ActiveRecord::Base
include Sanitizable
VALID_PHASES = %W{on_hold accepting selecting balloting finished}
validates :phase, inclusion: { in: VALID_PHASES }
validates :currency_symbol, presence: true
has_many :investments
has_many :ballots

View File

@@ -0,0 +1,7 @@
<h1>Budget Index</h1>
<ul>
<% @budgets.each do |budget| %>
<li><%= link_to budget.name, budget %></li>
<% end %>
</ul>

View File

@@ -0,0 +1,15 @@
<h1><%= @budget.name %></h1>
<div><%= @budget.description %></div>
<ul>
<li><%= link_to budget_investments_path(budget_id: @budget.id, heading_id: nil) do %>
No heading (<%= format_price(@budget, @budget.price) %>)
<% end %></li>
<% @budget.headings.each do |heading| %>
<li><%= link_to budget_investments_path(budget_id: @budget.id, heading_id: heading.id) do %>
<%= heading.name %> (<%= format_price(@budget, heading.price) %>)
<% end %>
</li>
<% end %>
</ul>

View File

@@ -69,6 +69,12 @@ Rails.application.routes.draw do
end
end
resources :budgets, only: [:show, :index] do
resources :investments, controller: "budgets/investments", only: [:index, :new, :create, :show, :destroy] do
member { post :vote }
end
end
scope '/participatory_budget' do
resources :spending_proposals, only: [:index, :new, :create, :show, :destroy], path: 'investment_projects' do
post :vote, on: :member

View File

@@ -0,0 +1,18 @@
require 'rails_helper'
feature 'Budgets' do
scenario 'Index' do
budgets = create_list(:budget, 3)
visit budgets_path
budgets.each {|budget| expect(page).to have_link(budget.name)}
end
scenario 'Show' do
budget = create(:budget)
heading = create(:budget_heading, budget: budget)
visit budget_path(budget)
expect(page).to have_content(budget.name)
expect(page).to have_content(heading.name)
end
end