diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2012-03-13 16:21:41 -0300 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2012-03-14 12:46:23 -0300 |
commit | 4c16791f355c74f8e6ad916e67fd4ae81efbf708 (patch) | |
tree | 4d0bac9dddd90c1b7ffaea3f309e79c0b7468154 /actionpack/test/controller | |
parent | cc1c4acc8eeee4287627b1d184d7d04a22eddb27 (diff) | |
download | rails-4c16791f355c74f8e6ad916e67fd4ae81efbf708.tar.gz rails-4c16791f355c74f8e6ad916e67fd4ae81efbf708.tar.bz2 rails-4c16791f355c74f8e6ad916e67fd4ae81efbf708.zip |
Add ActionController::HTTP
More info http://edgeguides.rubyonrails.org/api_app.html
[Carlos Antonio da Silva & Santiago Pastorino]
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/http/action_methods_test.rb | 19 | ||||
-rw-r--r-- | actionpack/test/controller/http/conditional_get_test.rb | 55 | ||||
-rw-r--r-- | actionpack/test/controller/http/data_streaming_test.rb | 27 | ||||
-rw-r--r-- | actionpack/test/controller/http/force_ssl_test.rb | 20 | ||||
-rw-r--r-- | actionpack/test/controller/http/redirect_to_test.rb | 19 | ||||
-rw-r--r-- | actionpack/test/controller/http/renderers_test.rb | 37 | ||||
-rw-r--r-- | actionpack/test/controller/http/url_for_test.rb | 20 |
7 files changed, 197 insertions, 0 deletions
diff --git a/actionpack/test/controller/http/action_methods_test.rb b/actionpack/test/controller/http/action_methods_test.rb new file mode 100644 index 0000000000..20bb53aca2 --- /dev/null +++ b/actionpack/test/controller/http/action_methods_test.rb @@ -0,0 +1,19 @@ +require 'abstract_unit' + +class ActionMethodsHTTPController < ActionController::HTTP + def one; end + def two; end + hide_action :two +end + +class ActionMethodsHTTPTest < ActiveSupport::TestCase + def setup + @controller = ActionMethodsHTTPController.new + end + + def test_action_methods + assert_equal Set.new(%w(one)), + @controller.class.action_methods, + "#{@controller.controller_path} should not be empty!" + end +end diff --git a/actionpack/test/controller/http/conditional_get_test.rb b/actionpack/test/controller/http/conditional_get_test.rb new file mode 100644 index 0000000000..70d5ef296f --- /dev/null +++ b/actionpack/test/controller/http/conditional_get_test.rb @@ -0,0 +1,55 @@ +require 'abstract_unit' + +class ConditionalGetHTTPController < ActionController::HTTP + before_filter :handle_last_modified_and_etags, :only => :two + + def one + if stale?(:last_modified => Time.now.utc.beginning_of_day, :etag => [:foo, 123]) + render :text => "Hi!" + end + end + + def two + render :text => "Hi!" + end + + private + + def handle_last_modified_and_etags + fresh_when(:last_modified => Time.now.utc.beginning_of_day, :etag => [ :foo, 123 ]) + end +end + +class ConditionalGetHTTPTest < ActionController::TestCase + tests ConditionalGetHTTPController + + def setup + @last_modified = Time.now.utc.beginning_of_day.httpdate + end + + def test_request_with_bang_gets_last_modified + get :two + assert_equal @last_modified, @response.headers['Last-Modified'] + assert_response :success + end + + def test_request_with_bang_obeys_last_modified + @request.if_modified_since = @last_modified + get :two + assert_response :not_modified + end + + def test_last_modified_works_with_less_than_too + @request.if_modified_since = 5.years.ago.httpdate + get :two + assert_response :success + end + + def test_request_not_modified + @request.if_modified_since = @last_modified + get :one + assert_equal 304, @response.status.to_i + assert_blank @response.body + assert_equal @last_modified, @response.headers['Last-Modified'] + end +end diff --git a/actionpack/test/controller/http/data_streaming_test.rb b/actionpack/test/controller/http/data_streaming_test.rb new file mode 100644 index 0000000000..67457b25b0 --- /dev/null +++ b/actionpack/test/controller/http/data_streaming_test.rb @@ -0,0 +1,27 @@ +require 'abstract_unit' + +module TestHTTPFileUtils + def file_name() File.basename(__FILE__) end + def file_path() File.expand_path(__FILE__) end + def file_data() @data ||= File.open(file_path, 'rb') { |f| f.read } end +end + +class DataStreamingHTTPController < ActionController::HTTP + include TestHTTPFileUtils + + def one; end + def two + send_data(file_data, {}) + end +end + +class DataStreamingHTTPTest < ActionController::TestCase + include TestHTTPFileUtils + tests DataStreamingHTTPController + + def test_data + response = process('two') + assert_kind_of String, response.body + assert_equal file_data, response.body + end +end diff --git a/actionpack/test/controller/http/force_ssl_test.rb b/actionpack/test/controller/http/force_ssl_test.rb new file mode 100644 index 0000000000..479ede6b78 --- /dev/null +++ b/actionpack/test/controller/http/force_ssl_test.rb @@ -0,0 +1,20 @@ +require 'abstract_unit' + +class ForceSSLHTTPController < ActionController::HTTP + force_ssl + + def one; end + def two + head :ok + end +end + +class ForceSSLHTTPTest < ActionController::TestCase + tests ForceSSLHTTPController + + def test_banana_redirects_to_https + get :two + assert_response 301 + assert_equal "https://test.host/force_sslhttp/two", redirect_to_url + end +end diff --git a/actionpack/test/controller/http/redirect_to_test.rb b/actionpack/test/controller/http/redirect_to_test.rb new file mode 100644 index 0000000000..c410910bae --- /dev/null +++ b/actionpack/test/controller/http/redirect_to_test.rb @@ -0,0 +1,19 @@ +require 'abstract_unit' + +class RedirectToHTTPController < ActionController::HTTP + def one + redirect_to :action => "two" + end + + def two; end +end + +class RedirectToHTTPTest < ActionController::TestCase + tests RedirectToHTTPController + + def test_redirect_to + get :one + assert_response :redirect + assert_equal "http://test.host/redirect_to_http/two", redirect_to_url + end +end diff --git a/actionpack/test/controller/http/renderers_test.rb b/actionpack/test/controller/http/renderers_test.rb new file mode 100644 index 0000000000..a28f226a94 --- /dev/null +++ b/actionpack/test/controller/http/renderers_test.rb @@ -0,0 +1,37 @@ +require 'abstract_unit' + +class Model + def to_json(options = {}) + { :a => 'b' }.to_json(options) + end + + def to_xml(options = {}) + { :a => 'b' }.to_xml(options) + end +end + +class RenderersHTTPController < ActionController::HTTP + def one + render :json => Model.new + end + + def two + render :xml => Model.new + end +end + +class RenderersHTTPTest < ActionController::TestCase + tests RenderersHTTPController + + def test_render_json + get :one + assert_response :success + assert_equal({ :a => 'b' }.to_json, @response.body) + end + + def test_render_xml + get :two + assert_response :success + assert_equal({ :a => 'b' }.to_xml, @response.body) + end +end diff --git a/actionpack/test/controller/http/url_for_test.rb b/actionpack/test/controller/http/url_for_test.rb new file mode 100644 index 0000000000..fba24011a2 --- /dev/null +++ b/actionpack/test/controller/http/url_for_test.rb @@ -0,0 +1,20 @@ +require 'abstract_unit' + +class UrlForHTTPController < ActionController::HTTP + def one; end + def two; end +end + +class UrlForHTTPTest < ActionController::TestCase + tests UrlForHTTPController + + def setup + super + @request.host = 'www.example.com' + end + + def test_url_for + get :one + assert_equal "http://www.example.com/url_for_http/one", @controller.url_for + end +end |