redirect to frendly url for debates and proposals if needed

This commit is contained in:
Julian Herrero
2016-01-10 13:38:22 +01:00
parent 083772aa62
commit 7c65b8555c
6 changed files with 96 additions and 0 deletions

View File

@@ -13,6 +13,11 @@ class DebatesController < ApplicationController
load_and_authorize_resource load_and_authorize_resource
respond_to :html, :js respond_to :html, :js
def show
super
redirect_to debate_path(@debate), status: :moved_permanently if request.path != debate_path(@debate)
end
def vote def vote
@debate.register_vote(current_user, params[:value]) @debate.register_vote(current_user, params[:value])
set_debate_votes(@debate) set_debate_votes(@debate)

View File

@@ -9,6 +9,11 @@ class Management::ProposalsController < Management::BaseController
has_orders %w{confidence_score hot_score created_at most_commented random}, only: [:index, :print] has_orders %w{confidence_score hot_score created_at most_commented random}, only: [:index, :print]
has_orders %w{most_voted newest}, only: :show has_orders %w{most_voted newest}, only: :show
def show
super
redirect_to management_proposal_path(@proposal), status: :moved_permanently if request.path != management_proposal_path(@proposal)
end
def vote def vote
@proposal.register_vote(current_user, 'yes') @proposal.register_vote(current_user, 'yes')
set_proposal_votes(@proposal) set_proposal_votes(@proposal)

View File

@@ -13,6 +13,11 @@ class ProposalsController < ApplicationController
load_and_authorize_resource load_and_authorize_resource
respond_to :html, :js respond_to :html, :js
def show
super
redirect_to proposal_path(@proposal), status: :moved_permanently if request.path != proposal_path(@proposal)
end
def index_customization def index_customization
@featured_proposals = Proposal.all.sort_by_confidence_score.limit(3) if (@search_terms.blank? && @tag_filter.blank?) @featured_proposals = Proposal.all.sort_by_confidence_score.limit(3) if (@search_terms.blank? && @tag_filter.blank?)
if @featured_proposals.present? if @featured_proposals.present?

View File

@@ -11,6 +11,26 @@ describe DebatesController do
SimpleCaptcha.always_pass = @original_captcha_pass_value SimpleCaptcha.always_pass = @original_captcha_pass_value
end end
describe "GET show" do
let(:debate) { create :debate }
context "when path matches" do
it "should not redirect to real path" do
get :show, id: debate.id
expect(response).to_not redirect_to debates_path(debate)
end
end
context "when path does not match" do
it "should redirect to real path" do
expect(request).to receive(:path).exactly(3).times.and_return "/#{debate.id}-something-else"
get :show, id: debate.id
expect(response).to redirect_to debate_path(debate)
end
end
end
describe 'POST create' do describe 'POST create' do
it 'should create an ahoy event' do it 'should create an ahoy event' do

View File

@@ -0,0 +1,37 @@
require 'rails_helper'
describe Management::ProposalsController do
describe "GET show" do
let(:proposal) { create :proposal }
let(:user) { create :user, :level_two }
context "when path matches" do
it "should not redirect to real path" do
sign_in user
login_managed_user(user)
session[:manager] = {user_key: "31415926" , date: "20151031135905", login: "JJB033"}
session[:document_type] = "1"
session[:document_number] = "12345678Z"
get :show, id: proposal.id
expect(response).to_not redirect_to management_proposals_path(proposal)
end
end
context "when path does not match" do
it "should redirect to real path" do
sign_in user
login_managed_user(user)
session[:manager] = {user_key: "31415926" , date: "20151031135905", login: "JJB033"}
session[:document_type] = "1"
session[:document_number] = "12345678Z"
expect(request).to receive(:path).exactly(2).times.and_return "/#{proposal.id}-something-else"
get :show, id: proposal.id
expect(response).to redirect_to management_proposal_path(proposal)
end
end
end
end

View File

@@ -0,0 +1,24 @@
require 'rails_helper'
describe ProposalsController do
describe "GET show" do
let(:proposal) { create :proposal }
context "when path matches" do
it "should not redirect to real path" do
get :show, id: proposal.id
expect(response).to_not redirect_to proposals_path(proposal)
end
end
context "when path does not match" do
it "should redirect to real path" do
expect(request).to receive(:path).exactly(3).times.and_return "/#{proposal.id}-something-else"
get :show, id: proposal.id
expect(response).to redirect_to proposal_path(proposal)
end
end
end
end