2009-09-19 13:10:41 -04:00
|
|
|
require 'abstract_unit'
|
2009-06-17 15:00:23 -04:00
|
|
|
|
|
|
|
module RenderRjs
|
|
|
|
class BasicController < ActionController::Base
|
2009-06-17 18:32:55 -04:00
|
|
|
self.view_paths = [ActionView::FixtureResolver.new(
|
2009-06-17 15:00:23 -04:00
|
|
|
"render_rjs/basic/index.js.rjs" => "page[:customer].replace_html render(:partial => 'customer')",
|
|
|
|
"render_rjs/basic/index_html.js.rjs" => "page[:customer].replace_html :partial => 'customer'",
|
|
|
|
"render_rjs/basic/_customer.js.erb" => "JS Partial",
|
|
|
|
"render_rjs/basic/_customer.html.erb" => "HTML Partial",
|
|
|
|
"render_rjs/basic/index_locale.js.rjs" => "page[:customer].replace_html :partial => 'customer'",
|
|
|
|
"render_rjs/basic/_customer.da.html.erb" => "Danish HTML Partial",
|
|
|
|
"render_rjs/basic/_customer.da.js.erb" => "Danish JS Partial"
|
|
|
|
)]
|
|
|
|
|
|
|
|
def index
|
|
|
|
render
|
|
|
|
end
|
|
|
|
|
|
|
|
def index_locale
|
2010-03-11 06:45:05 -05:00
|
|
|
self.locale = :da
|
2009-06-17 15:00:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-10-04 00:18:32 -04:00
|
|
|
class TestBasic < Rack::TestCase
|
2009-06-17 15:00:23 -04:00
|
|
|
testing BasicController
|
|
|
|
|
2009-09-19 14:22:09 -04:00
|
|
|
def setup
|
|
|
|
@old_locale = I18n.locale
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
I18n.locale = @old_locale
|
|
|
|
end
|
|
|
|
|
2009-06-17 15:00:23 -04:00
|
|
|
test "rendering a partial in an RJS template should pick the JS template over the HTML one" do
|
2009-08-15 01:32:40 -04:00
|
|
|
get :index, "format" => "js"
|
2009-06-17 15:00:23 -04:00
|
|
|
assert_response("$(\"customer\").update(\"JS Partial\");")
|
|
|
|
end
|
|
|
|
|
|
|
|
test "replacing an element with a partial in an RJS template should pick the HTML template over the JS one" do
|
2009-08-15 01:32:40 -04:00
|
|
|
get :index_html, "format" => "js"
|
2009-06-17 15:00:23 -04:00
|
|
|
assert_response("$(\"customer\").update(\"HTML Partial\");")
|
|
|
|
end
|
|
|
|
|
|
|
|
test "replacing an element with a partial in an RJS template with a locale should pick the localed HTML template" do
|
2009-08-15 01:32:40 -04:00
|
|
|
get :index_locale, "format" => "js"
|
2009-06-17 15:00:23 -04:00
|
|
|
assert_response("$(\"customer\").update(\"Danish HTML Partial\");")
|
|
|
|
end
|
|
|
|
end
|
2009-09-13 17:30:27 -04:00
|
|
|
end
|