Adds basic Budget controller / views
This commit is contained in:
13
app/controllers/budgets_controller.rb
Normal file
13
app/controllers/budgets_controller.rb
Normal 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
|
||||
8
app/helpers/budget_helper.rb
Normal file
8
app/helpers/budget_helper.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
7
app/views/budgets/index.html.erb
Normal file
7
app/views/budgets/index.html.erb
Normal file
@@ -0,0 +1,7 @@
|
||||
<h1>Budget Index</h1>
|
||||
|
||||
<ul>
|
||||
<% @budgets.each do |budget| %>
|
||||
<li><%= link_to budget.name, budget %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
15
app/views/budgets/show.html.erb
Normal file
15
app/views/budgets/show.html.erb
Normal 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>
|
||||
@@ -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
|
||||
|
||||
18
spec/features/budgets_spec.rb
Normal file
18
spec/features/budgets_spec.rb
Normal 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
|
||||
Reference in New Issue
Block a user