removes resolution status from spending proposals

This commit is contained in:
Juanjo Bazán
2016-02-24 18:50:39 +01:00
parent c5f994d250
commit 00eec532a6
9 changed files with 3 additions and 323 deletions

View File

@@ -1,14 +1,12 @@
class Admin::SpendingProposalsController < Admin::BaseController
include FeatureFlags
has_filters %w{unresolved accepted rejected}, only: :index
load_and_authorize_resource
feature_flag :spending_proposals
def index
@spending_proposals = @spending_proposals.includes([:geozone]).send(@current_filter).order(created_at: :desc).page(params[:page])
@spending_proposals = @spending_proposals.includes([:geozone], [administrator: :user]).order(created_at: :desc).page(params[:page])
end
def show

View File

@@ -4,8 +4,6 @@ class SpendingProposal < ActiveRecord::Base
apply_simple_captcha
RESOLUTIONS = ["accepted", "rejected"]
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
belongs_to :geozone
@@ -15,42 +13,10 @@ class SpendingProposal < ActiveRecord::Base
validates :title, length: { in: 4..SpendingProposal.title_max_length }
validates :description, length: { maximum: SpendingProposal.description_max_length }
validates :resolution, inclusion: { in: RESOLUTIONS, allow_nil: true }
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
scope :accepted, -> { where(resolution: "accepted") }
scope :rejected, -> { where(resolution: "rejected") }
scope :unresolved, -> { where(resolution: nil) }
def accept
update_attribute(:resolution, "accepted")
end
def reject
update_attribute(:resolution, "rejected")
end
def accepted?
resolution == "accepted"
end
def rejected?
resolution == "rejected"
end
def unresolved?
resolution.blank?
end
def legality
case legal
when true
"legal"
when false
"not_legal"
else
"undefined"
end
def description
super.try :html_safe
end
def feasibility
@@ -64,8 +30,4 @@ class SpendingProposal < ActiveRecord::Base
end
end
def description
super.try :html_safe
end
end

View File

@@ -1,7 +1,5 @@
<h2><%= t("admin.spending_proposals.index.title") %></h2>
<%= render 'shared/filter_subnav', i18n_namespace: "admin.spending_proposals.index" %>
<h3><%= page_entries_info @spending_proposals %></h3>
<table>
@@ -14,22 +12,6 @@
<td>
<%= geozone_name(spending_proposal) %>
</td>
<td>
<% unless spending_proposal.accepted? %>
<%= link_to t("admin.spending_proposals.actions.accept"),
accept_admin_spending_proposal_path(spending_proposal, request.query_parameters),
method: :put,
data: { confirm: t("admin.actions.confirm") },
class: "button radius tiny success no-margin" %>
<% end %>
<% unless spending_proposal.rejected? %>
<%= link_to t("admin.spending_proposals.actions.reject"),
reject_admin_spending_proposal_path(spending_proposal, request.query_parameters),
method: :put,
data: { confirm: t("admin.actions.confirm") },
class: "button radius tiny warning right" %>
<% end %>
</td>
</tr>
<% end %>
</table>

View File

@@ -15,30 +15,11 @@
<p><%= t("admin.spending_proposals.show.geozone") %>:
<%= geozone_name(@spending_proposal) %>
</p>
<p><%= l @spending_proposal.created_at, format: :datetime %></p>
<p>
<% unless @spending_proposal.accepted? %>
<%= link_to t("admin.spending_proposals.actions.accept"),
accept_admin_spending_proposal_path(@spending_proposal),
method: :put,
data: { confirm: t("admin.actions.confirm") },
class: "button radius tiny success no-margin" %>
<% end %>
<% unless @spending_proposal.rejected? %>
<%= link_to t("admin.spending_proposals.actions.reject"),
reject_admin_spending_proposal_path(@spending_proposal),
method: :put,
data: { confirm: t("admin.actions.confirm") },
class: "button radius tiny warning" %>
<% end %>
</p>
<h2><%= t("admin.spending_proposals.show.dossier") %>:</h2>
<p><strong><%= t("admin.spending_proposals.show.price") %>:</strong> <%= @spending_proposal.price %></p>
<p><strong><%= t("admin.spending_proposals.show.legality") %>:</strong> <%= t("admin.spending_proposals.show.#{@spending_proposal.legality}") %></p>
<p><strong><%= t("admin.spending_proposals.show.feasibility") %>:</strong> <%= t("admin.spending_proposals.show.#{@spending_proposal.feasibility}") %></p>
<%= safe_html_with_links(@spending_proposal.explanation.html_safe) if @spending_proposal.explanation %>

View File

@@ -23,11 +23,6 @@
</div>
<% end %>
<% if @spending_proposal.resolution.present? %>
<div class="spending-proposal-resolution">
<%= @spending_proposal.resolution %>
</div>
<% end %>
</div>
</div>

View File

@@ -137,9 +137,6 @@ en:
button: Search
placeholder: Search user by name or email'
spending_proposals:
actions:
accept: Accept
reject: Reject
index:
filter: Filter
filters:
@@ -153,9 +150,6 @@ en:
geozone: Scope
dossier: Dossier
price: Price
legality: Legality
legal: Legal
not_legal: Not legal
feasibility: Feasibility
feasible: Feasible
not_feasible: Not feasible

View File

@@ -137,9 +137,6 @@ es:
button: Buscar
placeholder: Buscar usuario por nombre o email
spending_proposals:
actions:
accept: Aceptar
reject: Rechazar
index:
filter: Filtro
filters:
@@ -153,9 +150,6 @@ es:
geozone: Ámbito
dossier: Informe
price: Coste
legality: Legalidad
legal: Legal
not_legal: No legal
feasibility: Viabilidad
feasible: Viable
not_feasible: No viable

View File

@@ -19,97 +19,12 @@ feature 'Admin spending proposals' do
expect(page).to have_content(spending_proposal.title)
end
scenario 'Accept from index' do
spending_proposal = create(:spending_proposal)
visit admin_spending_proposals_path
click_link 'Accept'
expect(page).to_not have_content(spending_proposal.title)
click_link 'Accepted'
expect(page).to have_content(spending_proposal.title)
expect(spending_proposal.reload).to be_accepted
end
scenario 'Reject from index' do
spending_proposal = create(:spending_proposal)
visit admin_spending_proposals_path
click_link 'Reject'
expect(page).to_not have_content(spending_proposal.title)
click_link('Rejected')
expect(page).to have_content(spending_proposal.title)
expect(spending_proposal.reload).to be_rejected
end
scenario "Current filter is properly highlighted" do
visit admin_spending_proposals_path
expect(page).to_not have_link('Unresolved')
expect(page).to have_link('Accepted')
expect(page).to have_link('Rejected')
visit admin_spending_proposals_path(filter: 'unresolved')
expect(page).to_not have_link('Unresolved')
expect(page).to have_link('Accepted')
expect(page).to have_link('Rejected')
visit admin_spending_proposals_path(filter: 'accepted')
expect(page).to have_link('Unresolved')
expect(page).to_not have_link('Accepted')
expect(page).to have_link('Rejected')
visit admin_spending_proposals_path(filter: 'rejected')
expect(page).to have_link('Accepted')
expect(page).to have_link('Unresolved')
expect(page).to_not have_link('Rejected')
end
scenario "Filtering proposals" do
create(:spending_proposal, title: "Recent spending proposal")
create(:spending_proposal, title: "Good spending proposal", resolution: "accepted")
create(:spending_proposal, title: "Bad spending proposal", resolution: "rejected")
visit admin_spending_proposals_path(filter: 'unresolved')
expect(page).to have_content('Recent spending proposal')
expect(page).to_not have_content('Good spending proposal')
expect(page).to_not have_content('Bad spending proposal')
visit admin_spending_proposals_path(filter: 'accepted')
expect(page).to have_content('Good spending proposal')
expect(page).to_not have_content('Recent spending proposal')
expect(page).to_not have_content('Bad spending proposal')
visit admin_spending_proposals_path(filter: 'rejected')
expect(page).to have_content('Bad spending proposal')
expect(page).to_not have_content('Good spending proposal')
expect(page).to_not have_content('Recent spending proposal')
end
scenario "Action links remember the pagination setting and the filter" do
per_page = Kaminari.config.default_per_page
(per_page + 2).times { create(:spending_proposal, resolution: "accepted") }
visit admin_spending_proposals_path(filter: 'accepted', page: 2)
click_on('Reject', match: :first, exact: true)
expect(current_url).to include('filter=accepted')
expect(current_url).to include('page=2')
end
scenario 'Show' do
spending_proposal = create(:spending_proposal,
geozone: create(:geozone),
association_name: 'People of the neighbourhood',
price: 1234.56,
legal: true,
feasible: false,
explanation: "It's impossible")
visit admin_spending_proposals_path
click_link spending_proposal.title
@@ -120,37 +35,8 @@ feature 'Admin spending proposals' do
expect(page).to have_content(spending_proposal.association_name)
expect(page).to have_content(spending_proposal.geozone.name)
expect(page).to have_content("1234.56")
expect(page).to have_content("Legal")
expect(page).to have_content("Not feasible")
expect(page).to have_content("It's impossible")
end
scenario 'Accept from show' do
spending_proposal = create(:spending_proposal)
visit admin_spending_proposal_path(spending_proposal)
click_link 'Accept'
expect(page).to_not have_content(spending_proposal.title)
click_link 'Accepted'
expect(page).to have_content(spending_proposal.title)
expect(spending_proposal.reload).to be_accepted
end
scenario 'Reject from show' do
spending_proposal = create(:spending_proposal)
visit admin_spending_proposal_path(spending_proposal)
click_link 'Reject'
expect(page).to_not have_content(spending_proposal.title)
click_link('Rejected')
expect(page).to have_content(spending_proposal.title)
expect(spending_proposal.reload).to be_rejected
end
end

View File

@@ -43,23 +43,6 @@ describe SpendingProposal do
end
describe "dossier info" do
describe "#legality" do
it "can be legal" do
spending_proposal.legal = true
expect(spending_proposal.legality).to eq "legal"
end
it "can be not-legal" do
spending_proposal.legal = false
expect(spending_proposal.legality).to eq "not_legal"
end
it "can be undefined" do
spending_proposal.legal = nil
expect(spending_proposal.legality).to eq "undefined"
end
end
describe "#feasibility" do
it "can be feasible" do
spending_proposal.feasible = true
@@ -78,99 +61,4 @@ describe SpendingProposal do
end
end
describe "resolution status" do
it "should be valid" do
spending_proposal.resolution = "accepted"
expect(spending_proposal).to be_valid
spending_proposal.resolution = "rejected"
expect(spending_proposal).to be_valid
spending_proposal.resolution = "wrong"
expect(spending_proposal).to_not be_valid
end
it "can be accepted" do
spending_proposal.accept
expect(spending_proposal.reload.resolution).to eq("accepted")
end
it "can be rejected" do
spending_proposal.reject
expect(spending_proposal.reload.resolution).to eq("rejected")
end
describe "#accepted?" do
it "should be true if resolution equals 'accepted'" do
spending_proposal.resolution = "accepted"
expect(spending_proposal.accepted?).to eq true
end
it "should be false otherwise" do
spending_proposal.resolution = "rejected"
expect(spending_proposal.accepted?).to eq false
spending_proposal.resolution = nil
expect(spending_proposal.accepted?).to eq false
end
end
describe "#rejected?" do
it "should be true if resolution equals 'rejected'" do
spending_proposal.resolution = "rejected"
expect(spending_proposal.rejected?).to eq true
end
it "should be false otherwise" do
spending_proposal.resolution = "accepted"
expect(spending_proposal.rejected?).to eq false
spending_proposal.resolution = nil
expect(spending_proposal.rejected?).to eq false
end
end
describe "#unresolved?" do
it "should be true if resolution is blank" do
spending_proposal.resolution = nil
expect(spending_proposal.unresolved?).to eq true
end
it "should be false otherwise" do
spending_proposal.resolution = "accepted"
expect(spending_proposal.unresolved?).to eq false
spending_proposal.resolution = "rejected"
expect(spending_proposal.unresolved?).to eq false
end
end
end
describe "scopes" do
before(:each) do
2.times { create(:spending_proposal, resolution: "accepted") }
2.times { create(:spending_proposal, resolution: "rejected") }
2.times { create(:spending_proposal, resolution: nil) }
end
describe "unresolved" do
it "should return all spending proposals without resolution" do
unresolved = SpendingProposal.all.unresolved
expect(unresolved.size).to eq(2)
unresolved.each {|u| expect(u.resolution).to be_nil}
end
end
describe "accepted" do
it "should return all accepted spending proposals" do
accepted = SpendingProposal.all.accepted
expect(accepted.size).to eq(2)
accepted.each {|a| expect(a.resolution).to eq("accepted")}
end
end
describe "rejected" do
it "should return all rejected spending proposals" do
rejected = SpendingProposal.all.rejected
expect(rejected.size).to eq(2)
rejected.each {|r| expect(r.resolution).to eq("rejected")}
end
end
end
end