aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/mime/accept_format_test.rb
diff options
context:
space:
mode:
authorBen Woosley <ben.woosley@gmail.com>2013-08-17 08:30:00 -0700
committerBen Woosley <ben.woosley@gmail.com>2013-08-17 19:01:53 -0700
commit6776980b9648383c7a4c87d291d7dd8fdce5b2d8 (patch)
tree4cdd7d51c91c574e57842309a07bcfb5a67d3ffa /actionpack/test/controller/mime/accept_format_test.rb
parent9abe72c7600132aa964ca48c312ef981007ab8b1 (diff)
downloadrails-6776980b9648383c7a4c87d291d7dd8fdce5b2d8.tar.gz
rails-6776980b9648383c7a4c87d291d7dd8fdce5b2d8.tar.bz2
rails-6776980b9648383c7a4c87d291d7dd8fdce5b2d8.zip
Split the 1200+ line mime_responds_test into 3 more focused and manageable test files.
Diffstat (limited to 'actionpack/test/controller/mime/accept_format_test.rb')
-rw-r--r--actionpack/test/controller/mime/accept_format_test.rb94
1 files changed, 94 insertions, 0 deletions
diff --git a/actionpack/test/controller/mime/accept_format_test.rb b/actionpack/test/controller/mime/accept_format_test.rb
new file mode 100644
index 0000000000..c03c7edeb8
--- /dev/null
+++ b/actionpack/test/controller/mime/accept_format_test.rb
@@ -0,0 +1,94 @@
+require 'abstract_unit'
+
+class StarStarMimeController < ActionController::Base
+ layout nil
+
+ def index
+ render
+ end
+end
+
+class StarStarMimeControllerTest < ActionController::TestCase
+ tests StarStarMimeController
+
+ def test_javascript_with_format
+ @request.accept = "text/javascript"
+ get :index, :format => 'js'
+ assert_match "function addition(a,b){ return a+b; }", @response.body
+ end
+
+ def test_javascript_with_no_format
+ @request.accept = "text/javascript"
+ get :index
+ assert_match "function addition(a,b){ return a+b; }", @response.body
+ end
+
+ def test_javascript_with_no_format_only_star_star
+ @request.accept = "*/*"
+ get :index
+ assert_match "function addition(a,b){ return a+b; }", @response.body
+ end
+end
+
+class AbstractPostController < ActionController::Base
+ self.view_paths = File.dirname(__FILE__) + "/../../fixtures/post_test/"
+end
+
+# For testing layouts which are set automatically
+class PostController < AbstractPostController
+ around_action :with_iphone
+
+ def index
+ respond_to(:html, :iphone, :js)
+ end
+
+protected
+
+ def with_iphone
+ request.format = "iphone" if request.env["HTTP_ACCEPT"] == "text/iphone"
+ yield
+ end
+end
+
+class SuperPostController < PostController
+end
+
+class MimeControllerLayoutsTest < ActionController::TestCase
+ tests PostController
+
+ def setup
+ super
+ @request.host = "www.example.com"
+ Mime::Type.register_alias("text/html", :iphone)
+ end
+
+ def teardown
+ super
+ Mime::Type.unregister(:iphone)
+ end
+
+ def test_missing_layout_renders_properly
+ get :index
+ assert_equal '<html><div id="html">Hello Firefox</div></html>', @response.body
+
+ @request.accept = "text/iphone"
+ get :index
+ assert_equal 'Hello iPhone', @response.body
+ end
+
+ def test_format_with_inherited_layouts
+ @controller = SuperPostController.new
+
+ get :index
+ assert_equal '<html><div id="html">Super Firefox</div></html>', @response.body
+
+ @request.accept = "text/iphone"
+ get :index
+ assert_equal '<html><div id="super_iphone">Super iPhone</div></html>', @response.body
+ end
+
+ def test_non_navigational_format_with_no_template_fallbacks_to_html_template_with_no_layout
+ get :index, :format => :js
+ assert_equal "Hello Firefox", @response.body
+ end
+end