Merge pull request #1749 from consul/budget-results-meta

Budget results meta tags
This commit is contained in:
BertoCQ
2017-07-13 18:07:01 +02:00
committed by GitHub
3 changed files with 33 additions and 5 deletions

View File

@@ -1,22 +1,31 @@
module Budgets module Budgets
class ResultsController < ApplicationController class ResultsController < ApplicationController
before_action :load_budget
before_action :load_heading
load_and_authorize_resource :budget load_and_authorize_resource :budget
def show def show
authorize! :read_results, @budget authorize! :read_results, @budget
@investments = load_result.investments @investments = load_result.investments
@heading = heading
end end
private private
def load_result def load_result
Budget::Result.new(@budget, heading) Budget::Result.new(@budget, @heading)
end end
def heading def load_budget
@budget.headings.find(params[:heading_id]) @budget = Budget.find_by(id: params[:budget_id])
end
def load_heading
if params[:heading_id].present?
@heading = @budget.headings.find(params[:heading_id])
else
@heading = @budget.headings.first
end
end end
end end

View File

@@ -1,6 +1,13 @@
<% provide :title, t("budgets.results.page_title", budget: @budget.name) %> <% provide :title, t("budgets.results.page_title", budget: @budget.name) %>
<% content_for :meta_description do %><%= @budget.description_finished %><% end %>
<% provide :social_media_meta_tags do %>
<%= render "shared/social_media_meta_tags",
social_url: budget_results_url(@budget),
social_title: @budget.name,
social_description: @budget.description_finished %>
<% end %>
<% content_for :canonical do %> <% content_for :canonical do %>
<%= render "shared/canonical", href: budget_results_url(@budget, heading_id: @heading) %> <%= render "shared/canonical", href: budget_results_url(@budget) %>
<% end %> <% end %>
<div class="expanded budget no-margin-top"> <div class="expanded budget no-margin-top">

View File

@@ -46,6 +46,18 @@ feature 'Results' do
end end
end end
scenario "Load first budget heading if not specified" do
other_heading = create(:budget_heading, group: group)
other_investment = create(:budget_investment, :winner, heading: other_heading)
visit budget_results_path(budget)
within("#budget-investments-compatible") do
expect(page).to have_content investment1.title
expect(page).to_not have_content other_investment.title
end
end
scenario "If budget is in a phase different from finished results can't be accessed" do 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 - ["finished"]).sample
visit budget_path(budget) visit budget_path(budget)