refactors debate_links using an attr_accessor
refactors debate_links using an attr_accessor
This commit is contained in:
@@ -8,11 +8,11 @@ class DebateLinksController < ApplicationController
|
|||||||
private
|
private
|
||||||
|
|
||||||
def create_params
|
def create_params
|
||||||
params.require(:debate).permit(:title, :external_link, :tag_list, :terms_of_service, :captcha, :captcha_key)
|
params.require(:debate).permit(:title, :external_link, :tag_list, :terms_of_service, :captcha, :captcha_key).merge(link_required: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def debate_params
|
def debate_params
|
||||||
params.require(:debate).permit(:title, :external_link, :tag_list, :terms_of_service, :captcha, :captcha_key)
|
params.require(:debate).permit(:title, :external_link, :tag_list, :terms_of_service, :captcha, :captcha_key).merge(link_required: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_create_path
|
def after_create_path
|
||||||
@@ -21,6 +21,6 @@ class DebateLinksController < ApplicationController
|
|||||||
|
|
||||||
def resource_model
|
def resource_model
|
||||||
Debate
|
Debate
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ class Debate < ActiveRecord::Base
|
|||||||
validates :title, length: { in: 4..Debate.title_max_length }
|
validates :title, length: { in: 4..Debate.title_max_length }
|
||||||
validates :description, length: { in: 10..Debate.description_max_length }, :if => :description_required?
|
validates :description, length: { in: 10..Debate.description_max_length }, :if => :description_required?
|
||||||
|
|
||||||
validates :external_link, :presence => true,
|
validates :external_link, :presence => true,
|
||||||
length: { in: 10..Debate.external_link_max_length },
|
length: { in: 10..Debate.external_link_max_length },
|
||||||
format: { with: /https?:\/\/*/},
|
format: { with: /https?:\/\/*/},
|
||||||
:if => :link_required?
|
:if => :link_required?
|
||||||
|
|
||||||
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
|
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
|
||||||
@@ -45,6 +45,8 @@ class Debate < ActiveRecord::Base
|
|||||||
# Ahoy setup
|
# Ahoy setup
|
||||||
visitable # Ahoy will automatically assign visit_id on create
|
visitable # Ahoy will automatically assign visit_id on create
|
||||||
|
|
||||||
|
attr_accessor :link_required
|
||||||
|
|
||||||
def searchable_values
|
def searchable_values
|
||||||
{ title => 'A',
|
{ title => 'A',
|
||||||
author.username => 'B',
|
author.username => 'B',
|
||||||
@@ -132,19 +134,11 @@ class Debate < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def description_required?
|
def description_required?
|
||||||
if self.external_link == nil
|
!link_required?
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_required?
|
def link_required?
|
||||||
if self.external_link == nil
|
link_required
|
||||||
return false
|
|
||||||
else
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ describe Debate do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "#external_link" do
|
describe "#external_link" do
|
||||||
|
before { debate.link_required = true }
|
||||||
|
|
||||||
it "should not be valid without a url" do
|
it "should not be valid without a url" do
|
||||||
debate.external_link = ""
|
debate.external_link = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user