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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
def after_create_path
|
||||
@@ -21,6 +21,6 @@ class DebateLinksController < ApplicationController
|
||||
|
||||
def resource_model
|
||||
Debate
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -24,9 +24,9 @@ class Debate < ActiveRecord::Base
|
||||
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?:\/\/*/},
|
||||
validates :external_link, :presence => true,
|
||||
length: { in: 10..Debate.external_link_max_length },
|
||||
format: { with: /https?:\/\/*/},
|
||||
:if => :link_required?
|
||||
|
||||
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
|
||||
@@ -45,6 +45,8 @@ class Debate < ActiveRecord::Base
|
||||
# Ahoy setup
|
||||
visitable # Ahoy will automatically assign visit_id on create
|
||||
|
||||
attr_accessor :link_required
|
||||
|
||||
def searchable_values
|
||||
{ title => 'A',
|
||||
author.username => 'B',
|
||||
@@ -132,19 +134,11 @@ class Debate < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def description_required?
|
||||
if self.external_link == nil
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
!link_required?
|
||||
end
|
||||
|
||||
|
||||
def link_required?
|
||||
if self.external_link == nil
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
link_required
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -31,6 +31,7 @@ describe Debate do
|
||||
end
|
||||
|
||||
describe "#external_link" do
|
||||
before { debate.link_required = true }
|
||||
|
||||
it "should not be valid without a url" do
|
||||
debate.external_link = ""
|
||||
|
||||
Reference in New Issue
Block a user