reverts debate links
This commit is contained in:
@@ -40,7 +40,7 @@ module CommentableActions
|
||||
|
||||
if @resource.save_with_captcha
|
||||
track_event
|
||||
redirect_path = after_create_path
|
||||
redirect_path = url_for(controller: controller_name, action: :show, id: @resource.id)
|
||||
redirect_to redirect_path, notice: t("flash.actions.create.#{resource_name.underscore}")
|
||||
else
|
||||
load_categories
|
||||
@@ -153,8 +153,4 @@ module CommentableActions
|
||||
def index_customization
|
||||
nil
|
||||
end
|
||||
|
||||
def after_create_path
|
||||
url_for(controller: controller_name, action: :show, id: @resource.id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,7 +26,7 @@ class DebatesController < ApplicationController
|
||||
private
|
||||
|
||||
def debate_params
|
||||
params.require(:debate).permit(:title, :description, :external_link, :tag_list, :terms_of_service, :captcha, :captcha_key)
|
||||
params.require(:debate).permit(:title, :description, :tag_list, :terms_of_service, :captcha, :captcha_key)
|
||||
end
|
||||
|
||||
def resource_model
|
||||
|
||||
@@ -7,10 +7,6 @@ module Measurable
|
||||
@@title_max_length ||= self.columns.find { |c| c.name == 'title' }.limit || 80
|
||||
end
|
||||
|
||||
def external_link_max_length
|
||||
@@external_link_max_length ||= self.columns.find { |c| c.name == 'external_link' }.limit || 100
|
||||
end
|
||||
|
||||
def responsible_name_max_length
|
||||
@@responsible_name_max_length ||= self.columns.find { |c| c.name == 'responsible_name' }.limit || 60
|
||||
end
|
||||
|
||||
@@ -18,16 +18,11 @@ class Debate < ActiveRecord::Base
|
||||
has_many :comments, as: :commentable
|
||||
|
||||
validates :title, presence: true
|
||||
validates :description, presence: true, :if => :description_required?
|
||||
validates :description, presence: true
|
||||
validates :author, presence: true
|
||||
|
||||
validates :title, length: { in: 4..Debate.title_max_length }
|
||||
validates :description, length: { in: 10..Debate.description_max_length }, :if => :description_required?
|
||||
|
||||
validates :external_link, :presence => true,
|
||||
length: { in: 10..Debate.external_link_max_length },
|
||||
format: { with: /https?:\/\/*/},
|
||||
:if => :link_required?
|
||||
validates :description, length: { in: 10..Debate.description_max_length }
|
||||
|
||||
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
|
||||
|
||||
@@ -133,12 +128,4 @@ class Debate < ActiveRecord::Base
|
||||
self.tags.each{ |t| t.increment_custom_counter_for('Debate') }
|
||||
end
|
||||
|
||||
def description_required?
|
||||
!link_required?
|
||||
end
|
||||
|
||||
def link_required?
|
||||
link_required || external_link.present? # needed for edit/update
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
<%= form_for @debate,url: debate_links_path, :method => :post do |f| %>
|
||||
<%= render 'shared/errors', resource: @debate %>
|
||||
<div class="row">
|
||||
<div class="small-12 column">
|
||||
<%= f.label :title, t("debates.form.debate_title") %>
|
||||
<%= f.text_field :title, maxlength: Debate.title_max_length, placeholder: t("debates.form.debate_title"), label: false, data: {js_suggest_result: "js_suggest_result", js_suggest: "#js-suggest", js_url: suggest_debates_path}%>
|
||||
</div>
|
||||
<div id="js-suggest"></div>
|
||||
<div class="small-12 column">
|
||||
<%= f.label :external_link, t("debate_links.form.debate_link") %>
|
||||
<%= f.text_field :external_link, maxlength: Debate.title_max_length, placeholder: t("debate_links.form.debate_link"), label: false %>
|
||||
</div>
|
||||
<div class="small-12 column">
|
||||
<%= f.label :tag_list, t("debates.form.tags_label") %>
|
||||
<p class="note"><%= t("debates.form.tags_instructions") %></p>
|
||||
|
||||
<%= f.text_field :tag_list, value: @debate.tag_list.to_s,
|
||||
label: false,
|
||||
placeholder: t("debates.form.tags_placeholder") %>
|
||||
</div>
|
||||
<div class="small-12 column">
|
||||
<% if @debate.new_record? %>
|
||||
<%= f.label :terms_of_service do %>
|
||||
<%= f.check_box :terms_of_service, label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("form.accept_terms",
|
||||
policy: link_to(t("form.policy"), "/privacy", target: "blank"),
|
||||
conditions: link_to(t("form.conditions"), "/conditions", target: "blank")).html_safe %>
|
||||
</span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= f.simple_captcha input_html: { required: false } %>
|
||||
</div>
|
||||
|
||||
<div class="actions small-12 column">
|
||||
<%= f.submit(class: "button radius", value: t("debate_links.#{action_name}.form.submit_button")) %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -1,29 +0,0 @@
|
||||
<div class="debate-new row">
|
||||
|
||||
<div class="small-12 medium-9 column">
|
||||
<%= link_to debates_path, class: "left back" do %>
|
||||
<i class="icon-angle-left left"></i>
|
||||
<%= t("debates.new.back_link") %>
|
||||
<% end %>
|
||||
<h1><%= t("debate_links.new.start_new") %></h1>
|
||||
<div class="alert-box info radius">
|
||||
<%= t("debates.new.info",
|
||||
info_link: link_to(t("debates.new.info_link"), new_proposal_path )).html_safe %>
|
||||
<%= link_to "/more_information", target: "_blank" do %>
|
||||
<strong><%= t("debates.new.more_info")%></strong>
|
||||
<% end %>
|
||||
</div>
|
||||
<%= render "form" %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-3 column">
|
||||
<i class="icon-debates right"></i>
|
||||
<h2><%= t("debate_links.new.recommendations_title") %></h2>
|
||||
<ul class="recommendations">
|
||||
<li><%= t("debates.new.recommendation_one") %></li>
|
||||
<li><%= t("debates.new.recommendation_two") %></li>
|
||||
<li><%= t("debates.new.recommendation_three") %></li>
|
||||
<li><%= t("debates.new.recommendation_four") %></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1 +0,0 @@
|
||||
<%= render "shared/suggest" %>
|
||||
@@ -41,12 +41,7 @@
|
||||
|
||||
</p>
|
||||
<div class="debate-description">
|
||||
<% if debate.description.present? %>
|
||||
<%= link_to debate.description, debate %>
|
||||
<% end %>
|
||||
<% if debate.external_link.present? %>
|
||||
<%= link_to debate.external_link, debate.external_link, target: '_blank' %>
|
||||
<% end %>
|
||||
<%= link_to debate.description, debate %>
|
||||
<div class="truncate"></div>
|
||||
</div>
|
||||
<%= render "shared/tags", taggable: debate, limit: 5 %>
|
||||
|
||||
@@ -6,17 +6,11 @@
|
||||
<%= f.text_field :title, maxlength: Debate.title_max_length, placeholder: t("debates.form.debate_title"), label: false, data: {js_suggest_result: "js_suggest_result", js_suggest: "#js-suggest", js_url: suggest_debates_path}%>
|
||||
</div>
|
||||
<div id="js-suggest"></div>
|
||||
<% if @debate.external_link != nil %>
|
||||
<div class="small-12 column">
|
||||
<%= f.label :external_link, t("debate_links.form.debate_link") %>
|
||||
<%= f.text_field :external_link, maxlength: Debate.external_link_max_length, placeholder: t("debates.form.debate_title"), label: false %>
|
||||
</div>
|
||||
<% else %>
|
||||
<div class="ckeditor small-12 column">
|
||||
<%= f.label :description, t("debates.form.debate_text") %>
|
||||
<%= f.cktext_area :description, maxlength: Debate.description_max_length, ckeditor: { language: I18n.locale }, label: false %>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="ckeditor small-12 column">
|
||||
<%= f.label :description, t("debates.form.debate_text") %>
|
||||
<%= f.cktext_area :description, maxlength: Debate.description_max_length, ckeditor: { language: I18n.locale }, label: false %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= f.label :tag_list, t("debates.form.tags_label") %>
|
||||
<p class="note"><%= t("debates.form.tags_instructions") %></p>
|
||||
|
||||
@@ -44,7 +44,6 @@
|
||||
<div class="small-12 medium-3 column">
|
||||
<aside class="sidebar" role="complementary">
|
||||
<%= link_to t("debates.index.start_debate"), new_debate_path, class: 'button radius expand' %>
|
||||
<%= link_to t("debates.index.share_debate"), debate_links_new_path, class: 'button radius expand' %>
|
||||
<%= render "shared/tag_cloud", taggable: 'debate' %>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
@@ -34,13 +34,7 @@
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<% if @debate.external_link.present? %>
|
||||
<%= safe_html_with_links link_to @debate.external_link, @debate.external_link, target: '_blank'%>
|
||||
<% end %>
|
||||
|
||||
<% if @debate.description.present? %>
|
||||
<%= safe_html_with_links @debate.description %>
|
||||
<% end %>
|
||||
<%= safe_html_with_links @debate.description %>
|
||||
|
||||
<%= render 'shared/tags', taggable: @debate %>
|
||||
|
||||
|
||||
@@ -108,7 +108,6 @@ en:
|
||||
select_order: Order by
|
||||
start_debate: Start a debate
|
||||
title: Debates
|
||||
share_debate: "Share a link"
|
||||
new:
|
||||
back_link: Go back
|
||||
form:
|
||||
@@ -137,17 +136,6 @@ en:
|
||||
update:
|
||||
form:
|
||||
submit_button: Save changes
|
||||
debate_links:
|
||||
form:
|
||||
debate_link: "Link"
|
||||
new:
|
||||
start_new: "Share a link"
|
||||
recommendations_title: "Recommendations for sharing a link"
|
||||
form:
|
||||
submit_button: "Share link"
|
||||
create:
|
||||
form:
|
||||
submit_button: "Share link"
|
||||
errors:
|
||||
messages:
|
||||
user_not_found: User not found
|
||||
|
||||
@@ -109,7 +109,6 @@ es:
|
||||
select_order: Ordenar por
|
||||
start_debate: Empieza un debate
|
||||
title: Debates
|
||||
share_debate: "Comparte un enlace"
|
||||
new:
|
||||
back_link: Volver
|
||||
form:
|
||||
@@ -138,17 +137,6 @@ es:
|
||||
update:
|
||||
form:
|
||||
submit_button: Guardar cambios
|
||||
debate_links:
|
||||
form:
|
||||
debate_link: "Enlace"
|
||||
new:
|
||||
start_new: "Compartir un enlace"
|
||||
recommendations_title: "Recomendaciones para compartir un enlace"
|
||||
form:
|
||||
submit_button: "Comparte un enlace"
|
||||
create:
|
||||
form:
|
||||
submit_button: "Comparte un enlace"
|
||||
errors:
|
||||
messages:
|
||||
user_not_found: No se encontró el usuario
|
||||
|
||||
@@ -44,9 +44,6 @@ Rails.application.routes.draw do
|
||||
end
|
||||
end
|
||||
|
||||
get 'debate_links/new' => 'debate_links#new'
|
||||
post 'debate_links' => 'debate_links#create'
|
||||
|
||||
resources :proposals do
|
||||
member do
|
||||
post :vote
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
class AddExternalLinkToDebates < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :debates, :external_link, :string, limit: 100
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class RemovesExternalLinkFromDebates < ActiveRecord::Migration
|
||||
def change
|
||||
remove_column :debates, :external_link
|
||||
end
|
||||
end
|
||||
34
db/schema.rb
34
db/schema.rb
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160219111057) do
|
||||
ActiveRecord::Schema.define(version: 20160219172824) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -103,24 +103,23 @@ ActiveRecord::Schema.define(version: 20160219111057) do
|
||||
t.string "title", limit: 80
|
||||
t.text "description"
|
||||
t.integer "author_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "visit_id"
|
||||
t.datetime "hidden_at"
|
||||
t.integer "flags_count", default: 0
|
||||
t.integer "cached_votes_total", default: 0
|
||||
t.integer "cached_votes_up", default: 0
|
||||
t.integer "cached_votes_down", default: 0
|
||||
t.integer "flags_count", default: 0
|
||||
t.datetime "ignored_flag_at"
|
||||
t.integer "comments_count", default: 0
|
||||
t.integer "cached_votes_total", default: 0
|
||||
t.integer "cached_votes_up", default: 0
|
||||
t.integer "cached_votes_down", default: 0
|
||||
t.integer "comments_count", default: 0
|
||||
t.datetime "confirmed_hide_at"
|
||||
t.integer "cached_anonymous_votes_total", default: 0
|
||||
t.integer "cached_votes_score", default: 0
|
||||
t.integer "hot_score", limit: 8, default: 0
|
||||
t.integer "confidence_score", default: 0
|
||||
t.integer "cached_anonymous_votes_total", default: 0
|
||||
t.integer "cached_votes_score", default: 0
|
||||
t.integer "hot_score", limit: 8, default: 0
|
||||
t.integer "confidence_score", default: 0
|
||||
t.integer "geozone_id"
|
||||
t.tsvector "tsv"
|
||||
t.string "external_link", limit: 100
|
||||
end
|
||||
|
||||
add_index "debates", ["author_id", "hidden_at"], name: "index_debates_on_author_id_and_hidden_at", using: :btree
|
||||
@@ -130,7 +129,6 @@ ActiveRecord::Schema.define(version: 20160219111057) do
|
||||
add_index "debates", ["cached_votes_total"], name: "index_debates_on_cached_votes_total", using: :btree
|
||||
add_index "debates", ["cached_votes_up"], name: "index_debates_on_cached_votes_up", using: :btree
|
||||
add_index "debates", ["confidence_score"], name: "index_debates_on_confidence_score", using: :btree
|
||||
add_index "debates", ["description"], name: "index_debates_on_description", using: :btree
|
||||
add_index "debates", ["geozone_id"], name: "index_debates_on_geozone_id", using: :btree
|
||||
add_index "debates", ["hidden_at"], name: "index_debates_on_hidden_at", using: :btree
|
||||
add_index "debates", ["hot_score"], name: "index_debates_on_hot_score", using: :btree
|
||||
@@ -207,7 +205,7 @@ ActiveRecord::Schema.define(version: 20160219111057) do
|
||||
create_table "locks", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "tries", default: 0
|
||||
t.datetime "locked_until", default: '2000-01-01 00:01:01', null: false
|
||||
t.datetime "locked_until", default: '2000-01-01 07:01:01', null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
@@ -267,7 +265,6 @@ ActiveRecord::Schema.define(version: 20160219111057) do
|
||||
add_index "proposals", ["author_id"], name: "index_proposals_on_author_id", using: :btree
|
||||
add_index "proposals", ["cached_votes_up"], name: "index_proposals_on_cached_votes_up", using: :btree
|
||||
add_index "proposals", ["confidence_score"], name: "index_proposals_on_confidence_score", using: :btree
|
||||
add_index "proposals", ["description"], name: "index_proposals_on_description", using: :btree
|
||||
add_index "proposals", ["geozone_id"], name: "index_proposals_on_geozone_id", using: :btree
|
||||
add_index "proposals", ["hidden_at"], name: "index_proposals_on_hidden_at", using: :btree
|
||||
add_index "proposals", ["hot_score"], name: "index_proposals_on_hot_score", using: :btree
|
||||
@@ -330,8 +327,8 @@ ActiveRecord::Schema.define(version: 20160219111057) do
|
||||
t.boolean "featured", default: false
|
||||
t.integer "debates_count", default: 0
|
||||
t.integer "proposals_count", default: 0
|
||||
t.integer "spending_proposals_count", default: 0
|
||||
t.string "kind"
|
||||
t.integer "spending_proposals_count", default: 0
|
||||
end
|
||||
|
||||
add_index "tags", ["debates_count"], name: "index_tags_on_debates_count", using: :btree
|
||||
@@ -407,8 +404,8 @@ ActiveRecord::Schema.define(version: 20160219111057) do
|
||||
t.boolean "public_activity", default: true
|
||||
t.boolean "newsletter", default: false
|
||||
t.integer "notifications_count", default: 0
|
||||
t.boolean "registering_with_oauth", default: false
|
||||
t.string "locale"
|
||||
t.boolean "registering_with_oauth", default: false
|
||||
t.string "oauth_email"
|
||||
t.integer "geozone_id"
|
||||
end
|
||||
@@ -494,6 +491,7 @@ ActiveRecord::Schema.define(version: 20160219111057) do
|
||||
add_foreign_key "moderators", "users"
|
||||
add_foreign_key "notifications", "users"
|
||||
add_foreign_key "organizations", "users"
|
||||
add_foreign_key "users", "geozones"
|
||||
add_foreign_key "valuators", "users"
|
||||
add_foreign_key "users", "geozones"
|
||||
end
|
||||
|
||||
@@ -86,24 +86,6 @@ feature 'Debates' do
|
||||
expect(page).to have_content I18n.l(Debate.last.created_at.to_date)
|
||||
end
|
||||
|
||||
scenario 'Create_link' do
|
||||
author = create(:user)
|
||||
login_as(author)
|
||||
|
||||
visit debate_links_new_path
|
||||
fill_in 'debate_title', with: 'A title for a debate'
|
||||
fill_in 'debate_external_link', with: 'http://localhost:3000'
|
||||
fill_in 'debate_captcha', with: correct_captcha_text
|
||||
check 'debate_terms_of_service'
|
||||
|
||||
click_button 'Share link'
|
||||
|
||||
expect(page).to have_content 'A title for a debate'
|
||||
expect(page).to have_content 'Debate created successfully.'
|
||||
expect(page).to have_content author.name
|
||||
expect(page).to have_content I18n.l(Debate.last.created_at.to_date)
|
||||
end
|
||||
|
||||
scenario 'Captcha is required for debate creation' do
|
||||
login_as(create(:user))
|
||||
|
||||
|
||||
@@ -30,25 +30,6 @@ describe Debate do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#external_link" do
|
||||
before { debate.link_required = true }
|
||||
|
||||
it "should not be valid without a url" do
|
||||
debate.external_link = ""
|
||||
expect(debate).to_not be_valid
|
||||
end
|
||||
|
||||
it "should not be valid when very short" do
|
||||
debate.external_link = "abc"
|
||||
expect(debate).to_not be_valid
|
||||
end
|
||||
|
||||
it "should not be valid when very long" do
|
||||
debate.external_link = "a" * 101
|
||||
expect(debate).to_not be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "#description" do
|
||||
it "should not be valid without a description" do
|
||||
debate.description = nil
|
||||
|
||||
Reference in New Issue
Block a user