2017-07-23 11:36:41 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 12:50:17 -04:00
|
|
|
require "abstract_unit"
|
|
|
|
require "active_support/logger"
|
2005-07-03 07:01:43 -04:00
|
|
|
|
|
|
|
class CaptureController < ActionController::Base
|
2017-05-15 10:17:28 -04:00
|
|
|
self.view_paths = [ File.expand_path("../../fixtures/actionpack", __dir__) ]
|
2013-08-06 18:20:33 -04:00
|
|
|
|
2005-07-03 07:01:43 -04:00
|
|
|
def self.controller_name; "test"; end
|
|
|
|
def self.controller_path; "test"; end
|
|
|
|
|
2005-07-24 09:20:29 -04:00
|
|
|
def content_for
|
2010-09-28 16:44:26 -04:00
|
|
|
@title = nil
|
2016-08-06 13:36:34 -04:00
|
|
|
render layout: "talk_from_action"
|
2005-07-24 09:20:29 -04:00
|
|
|
end
|
2006-11-12 19:53:20 -05:00
|
|
|
|
2007-09-20 23:40:25 -04:00
|
|
|
def content_for_with_parameter
|
2010-09-28 16:44:26 -04:00
|
|
|
@title = nil
|
2016-08-06 13:36:34 -04:00
|
|
|
render layout: "talk_from_action"
|
2007-09-20 23:40:25 -04:00
|
|
|
end
|
|
|
|
|
2008-06-06 21:01:14 -04:00
|
|
|
def content_for_concatenated
|
2010-09-28 16:44:26 -04:00
|
|
|
@title = nil
|
2016-08-06 13:36:34 -04:00
|
|
|
render layout: "talk_from_action"
|
2006-02-26 14:47:50 -05:00
|
|
|
end
|
2006-11-12 19:53:20 -05:00
|
|
|
|
2006-02-26 14:47:50 -05:00
|
|
|
def non_erb_block_content_for
|
2010-09-28 16:44:26 -04:00
|
|
|
@title = nil
|
2016-08-06 13:36:34 -04:00
|
|
|
render layout: "talk_from_action"
|
2006-02-26 14:47:50 -05:00
|
|
|
end
|
2005-07-24 09:20:29 -04:00
|
|
|
|
2010-09-29 10:10:38 -04:00
|
|
|
def proper_block_detection
|
|
|
|
@todo = "some todo"
|
|
|
|
end
|
2005-07-03 07:01:43 -04:00
|
|
|
end
|
|
|
|
|
2009-01-07 16:23:10 -05:00
|
|
|
class CaptureTest < ActionController::TestCase
|
|
|
|
tests CaptureController
|
2005-07-03 07:01:43 -04:00
|
|
|
|
2018-09-24 17:49:26 -04:00
|
|
|
with_routes do
|
|
|
|
get :content_for, to: "test#content_for"
|
|
|
|
get :capturing, to: "test#capturing"
|
|
|
|
get :proper_block_detection, to: "test#proper_block_detection"
|
|
|
|
get :non_erb_block_content_for, to: "test#non_erb_block_content_for"
|
|
|
|
get :content_for_concatenated, to: "test#content_for_concatenated"
|
|
|
|
get :content_for_with_parameter, to: "test#content_for_with_parameter"
|
|
|
|
end
|
|
|
|
|
2009-01-07 16:23:10 -05:00
|
|
|
def setup
|
2009-04-08 20:33:06 -04:00
|
|
|
super
|
2005-07-03 07:01:43 -04:00
|
|
|
# enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
|
|
|
|
# a more accurate simulation of what happens in "real life".
|
2011-12-23 13:47:21 -05:00
|
|
|
@controller.logger = ActiveSupport::Logger.new(nil)
|
2005-07-03 07:01:43 -04:00
|
|
|
|
|
|
|
@request.host = "www.nextangle.com"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_simple_capture
|
|
|
|
get :capturing
|
|
|
|
assert_equal "Dreamy days", @response.body.strip
|
|
|
|
end
|
2006-11-12 19:53:20 -05:00
|
|
|
|
2005-07-24 09:20:29 -04:00
|
|
|
def test_content_for
|
|
|
|
get :content_for
|
2006-02-26 14:47:50 -05:00
|
|
|
assert_equal expected_content_for_output, @response.body
|
|
|
|
end
|
2006-11-12 19:53:20 -05:00
|
|
|
|
2015-09-20 14:02:11 -04:00
|
|
|
def test_should_concatenate_content_for
|
2007-09-20 23:40:25 -04:00
|
|
|
get :content_for_concatenated
|
|
|
|
assert_equal expected_content_for_output, @response.body
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_should_set_content_for_with_parameter
|
|
|
|
get :content_for_with_parameter
|
2006-02-26 14:47:50 -05:00
|
|
|
assert_equal expected_content_for_output, @response.body
|
|
|
|
end
|
2006-11-12 19:53:20 -05:00
|
|
|
|
2006-02-26 14:47:50 -05:00
|
|
|
def test_non_erb_block_content_for
|
|
|
|
get :non_erb_block_content_for
|
|
|
|
assert_equal expected_content_for_output, @response.body
|
2005-07-24 09:20:29 -04:00
|
|
|
end
|
2005-07-03 07:01:43 -04:00
|
|
|
|
2010-05-15 20:22:30 -04:00
|
|
|
def test_proper_block_detection
|
|
|
|
get :proper_block_detection
|
2010-09-29 10:10:38 -04:00
|
|
|
assert_equal "some todo", @response.body
|
2010-05-15 20:22:30 -04:00
|
|
|
end
|
|
|
|
|
2006-02-26 14:47:50 -05:00
|
|
|
private
|
2007-03-13 01:24:10 -04:00
|
|
|
def expected_content_for_output
|
2010-05-17 11:41:54 -04:00
|
|
|
"<title>Putting stuff in the title!</title>\nGreat stuff!"
|
2007-03-13 01:24:10 -04:00
|
|
|
end
|
2005-07-03 07:01:43 -04:00
|
|
|
end
|