@@ -18,6 +18,11 @@ class DebatesController < ApplicationController
|
||||
helper_method :resource_model, :resource_name
|
||||
respond_to :html, :js
|
||||
|
||||
def show
|
||||
super
|
||||
redirect_to debate_path(@debate), status: :moved_permanently if request.path != debate_path(@debate)
|
||||
end
|
||||
|
||||
def vote
|
||||
@debate.register_vote(current_user, params[:value])
|
||||
set_debate_votes(@debate)
|
||||
|
||||
@@ -11,6 +11,11 @@ class Management::ProposalsController < Management::BaseController
|
||||
has_orders %w{confidence_score hot_score created_at most_commented random}, only: [:index, :print]
|
||||
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
|
||||
@proposal.register_vote(current_user, 'yes')
|
||||
set_proposal_votes(@proposal)
|
||||
|
||||
@@ -17,6 +17,11 @@ class ProposalsController < ApplicationController
|
||||
helper_method :resource_model, :resource_name
|
||||
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
|
||||
@featured_proposals = Proposal.all.sort_by_confidence_score.limit(3) if (!@advanced_search_terms && @search_terms.blank? && @tag_filter.blank?)
|
||||
if @featured_proposals.present?
|
||||
|
||||
@@ -55,6 +55,10 @@ class Debate < ActiveRecord::Base
|
||||
self.pg_search(terms)
|
||||
end
|
||||
|
||||
def to_param
|
||||
"#{id}-#{title}".parameterize
|
||||
end
|
||||
|
||||
def description
|
||||
super.try :html_safe
|
||||
end
|
||||
|
||||
@@ -43,6 +43,10 @@ class Proposal < ActiveRecord::Base
|
||||
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
|
||||
scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)}
|
||||
|
||||
def to_param
|
||||
"#{id}-#{title}".parameterize
|
||||
end
|
||||
|
||||
def searchable_values
|
||||
{ title => 'A',
|
||||
question => 'B',
|
||||
|
||||
@@ -67,6 +67,28 @@ feature 'Debates' do
|
||||
expect(link_text).to include(debates_path order: :hot_score, page: 1)
|
||||
end
|
||||
|
||||
context "Show" do
|
||||
scenario 'When path matches the friendly url' do
|
||||
debate = create(:debate)
|
||||
|
||||
right_path = debate_path(debate)
|
||||
visit right_path
|
||||
|
||||
expect(current_path).to eq(right_path)
|
||||
end
|
||||
|
||||
scenario 'When path does not match the friendly url' do
|
||||
debate = create(:debate)
|
||||
|
||||
right_path = debate_path(debate)
|
||||
old_path = "#{debates_path}/#{debate.id}-something-else"
|
||||
visit old_path
|
||||
|
||||
expect(current_path).to_not eq(old_path)
|
||||
expect(current_path).to eq(right_path)
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'Create' do
|
||||
author = create(:user)
|
||||
login_as(author)
|
||||
|
||||
@@ -56,6 +56,34 @@ feature 'Proposals' do
|
||||
end
|
||||
end
|
||||
|
||||
context "Show" do
|
||||
scenario 'When path matches the friendly url' do
|
||||
proposal = create(:proposal)
|
||||
|
||||
user = create(:user, :level_two)
|
||||
login_managed_user(user)
|
||||
|
||||
right_path = management_proposal_path(proposal)
|
||||
visit right_path
|
||||
|
||||
expect(current_path).to eq(right_path)
|
||||
end
|
||||
|
||||
scenario 'When path does not match the friendly url' do
|
||||
proposal = create(:proposal)
|
||||
|
||||
user = create(:user, :level_two)
|
||||
login_managed_user(user)
|
||||
|
||||
right_path = management_proposal_path(proposal)
|
||||
old_path = "#{management_proposals_path}/#{proposal.id}-something-else"
|
||||
visit old_path
|
||||
|
||||
expect(current_path).to_not eq(old_path)
|
||||
expect(current_path).to eq(right_path)
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Searching" do
|
||||
proposal1 = create(:proposal, title: "Show me what you got")
|
||||
proposal2 = create(:proposal, title: "Get Schwifty")
|
||||
|
||||
@@ -65,6 +65,28 @@ feature 'Proposals' do
|
||||
end
|
||||
end
|
||||
|
||||
context "Show" do
|
||||
scenario 'When path matches the friendly url' do
|
||||
proposal = create(:proposal)
|
||||
|
||||
right_path = proposal_path(proposal)
|
||||
visit right_path
|
||||
|
||||
expect(current_path).to eq(right_path)
|
||||
end
|
||||
|
||||
scenario 'When path does not match the friendly url' do
|
||||
proposal = create(:proposal)
|
||||
|
||||
right_path = proposal_path(proposal)
|
||||
old_path = "#{proposals_path}/#{proposal.id}-something-else"
|
||||
visit old_path
|
||||
|
||||
expect(current_path).to_not eq(old_path)
|
||||
expect(current_path).to eq(right_path)
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'Social Media Cards' do
|
||||
proposal = create(:proposal)
|
||||
|
||||
|
||||
@@ -692,4 +692,10 @@ describe Debate do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#to_param" do
|
||||
it "should return a friendly url" do
|
||||
expect(debate.to_param).to eq "#{debate.id} #{debate.title}".parameterize
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -735,4 +735,10 @@ describe Proposal do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#to_param" do
|
||||
it "should return a friendly url" do
|
||||
expect(proposal.to_param).to eq "#{proposal.id} #{proposal.title}".parameterize
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user