aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/activerecord/controller_runtime_test.rb26
-rw-r--r--actionpack/test/controller/caching_test.rb3
-rw-r--r--actionpack/test/controller/deprecation/deprecated_base_methods_test.rb26
-rw-r--r--actionpack/test/controller/helper_test.rb2
-rw-r--r--actionpack/test/controller/log_subscriber_test.rb6
-rw-r--r--actionpack/test/controller/params_wrapper_test.rb12
-rw-r--r--actionpack/test/controller/render_test.rb7
-rw-r--r--actionpack/test/controller/request_forgery_protection_test.rb6
-rw-r--r--actionpack/test/controller/view_paths_test.rb8
-rw-r--r--actionpack/test/dispatch/cookies_test.rb12
-rw-r--r--actionpack/test/dispatch/response_body_is_proc_test.rb37
-rw-r--r--actionpack/test/dispatch/session/cookie_store_test.rb2
-rw-r--r--actionpack/test/fixtures/sprockets/app/javascripts/application.js1
-rw-r--r--actionpack/test/fixtures/sprockets/app/stylesheets/application.css1
-rw-r--r--actionpack/test/fixtures/test/deprecated_nested_layout.erb3
-rw-r--r--actionpack/test/template/atom_feed_helper_test.rb18
-rw-r--r--actionpack/test/template/form_helper_test.rb125
-rw-r--r--actionpack/test/template/number_helper_test.rb9
-rw-r--r--actionpack/test/template/sprockets_helper_test.rb36
-rw-r--r--actionpack/test/template/streaming_render_test.rb4
-rw-r--r--actionpack/test/template/test_case_test.rb16
-rw-r--r--actionpack/test/template/url_helper_test.rb2
22 files changed, 214 insertions, 148 deletions
diff --git a/actionpack/test/activerecord/controller_runtime_test.rb b/actionpack/test/activerecord/controller_runtime_test.rb
index b87b9f9c47..2d789395ce 100644
--- a/actionpack/test/activerecord/controller_runtime_test.rb
+++ b/actionpack/test/activerecord/controller_runtime_test.rb
@@ -15,6 +15,17 @@ class ControllerRuntimeLogSubscriberTest < ActionController::TestCase
def zero
render :inline => "Zero DB runtime"
end
+
+ def redirect
+ Project.all
+ redirect_to :action => 'show'
+ end
+
+ def db_after_render
+ render :inline => "Hello world"
+ Project.all
+ ActiveRecord::LogSubscriber.runtime += 100
+ end
end
include ActiveSupport::LogSubscriber::TestHelper
@@ -52,4 +63,19 @@ class ControllerRuntimeLogSubscriberTest < ActionController::TestCase
assert_equal 2, @logger.logged(:info).size
assert_match(/\(Views: [\d.]+ms \| ActiveRecord: 0.0ms\)/, @logger.logged(:info)[1])
end
+
+ def test_log_with_active_record_when_redirecting
+ get :redirect
+ wait
+ assert_equal 3, @logger.logged(:info).size
+ assert_match(/\(ActiveRecord: [\d.]+ms\)/, @logger.logged(:info)[2])
+ end
+
+ def test_include_time_query_time_after_rendering
+ get :db_after_render
+ wait
+
+ assert_equal 2, @logger.logged(:info).size
+ assert_match(/\(Views: [\d.]+ms \| ActiveRecord: ([1-9][\d.]+)ms\)/, @logger.logged(:info)[1])
+ end
end
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb
index fada0c7748..82c2c23607 100644
--- a/actionpack/test/controller/caching_test.rb
+++ b/actionpack/test/controller/caching_test.rb
@@ -187,6 +187,9 @@ class ActionCachingTestController < CachingController
rescue_from(ActiveRecord::RecordNotFound) { head :not_found }
end
+ # Eliminate uninitialized ivar warning
+ before_filter { @title = nil }
+
caches_action :index, :redirected, :forbidden, :if => Proc.new { |c| !c.request.format.json? }, :expires_in => 1.hour
caches_action :show, :cache_path => 'http://test.host/custom/show'
caches_action :edit, :cache_path => Proc.new { |c| c.params[:id] ? "http://test.host/#{c.params[:id]};edit" : "http://test.host/edit" }
diff --git a/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb b/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb
deleted file mode 100644
index 0c02afea36..0000000000
--- a/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-require 'abstract_unit'
-
-class DeprecatedBaseMethodsTest < ActionController::TestCase
- class Target < ActionController::Base
- def home_url(greeting)
- "http://example.com/#{greeting}"
- end
-
- def raises_name_error
- this_method_doesnt_exist
- end
-
- def rescue_action(e) raise e end
- end
-
- tests Target
-
- if defined? Test::Unit::Error
- def test_assertion_failed_error_silences_deprecation_warnings
- get :raises_name_error
- rescue => e
- error = Test::Unit::Error.new('testing ur doodz', e)
- assert_not_deprecated { error.message }
- end
- end
-end
diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb
index 9f0670ffdf..584d73668a 100644
--- a/actionpack/test/controller/helper_test.rb
+++ b/actionpack/test/controller/helper_test.rb
@@ -77,7 +77,7 @@ class HelperTest < ActiveSupport::TestCase
self.test_helper = LocalAbcHelper
end
- def test_deprecated_helper
+ def test_helper
assert_equal expected_helper_methods, missing_methods
assert_nothing_raised { @controller_class.helper TestHelper }
assert_equal [], missing_methods
diff --git a/actionpack/test/controller/log_subscriber_test.rb b/actionpack/test/controller/log_subscriber_test.rb
index 5d7a51e902..80c4fa2ee5 100644
--- a/actionpack/test/controller/log_subscriber_test.rb
+++ b/actionpack/test/controller/log_subscriber_test.rb
@@ -4,7 +4,7 @@ require "action_controller/log_subscriber"
module Another
class LogSubscribersController < ActionController::Base
- wrap_parameters :person, :only => :name, :format => :json
+ wrap_parameters :person, :include => :name, :format => :json
def show
render :nothing => true
@@ -34,11 +34,11 @@ module Another
cache_page("Super soaker", "/index.html")
render :nothing => true
end
-
+
def with_exception
raise Exception
end
-
+
end
end
diff --git a/actionpack/test/controller/params_wrapper_test.rb b/actionpack/test/controller/params_wrapper_test.rb
index a50065bcc7..7bef1e8d5d 100644
--- a/actionpack/test/controller/params_wrapper_test.rb
+++ b/actionpack/test/controller/params_wrapper_test.rb
@@ -65,9 +65,9 @@ class ParamsWrapperTest < ActionController::TestCase
end
end
- def test_specify_only_option
+ def test_specify_include_option
with_default_wrapper_options do
- UsersController.wrap_parameters :only => :username
+ UsersController.wrap_parameters :include => :username
@request.env['CONTENT_TYPE'] = 'application/json'
post :parse, { 'username' => 'sikachu', 'title' => 'Developer' }
@@ -75,9 +75,9 @@ class ParamsWrapperTest < ActionController::TestCase
end
end
- def test_specify_except_option
+ def test_specify_exclude_option
with_default_wrapper_options do
- UsersController.wrap_parameters :except => :title
+ UsersController.wrap_parameters :exclude => :title
@request.env['CONTENT_TYPE'] = 'application/json'
post :parse, { 'username' => 'sikachu', 'title' => 'Developer' }
@@ -85,9 +85,9 @@ class ParamsWrapperTest < ActionController::TestCase
end
end
- def test_specify_both_wrapper_name_and_only_option
+ def test_specify_both_wrapper_name_and_include_option
with_default_wrapper_options do
- UsersController.wrap_parameters :person, :only => :username
+ UsersController.wrap_parameters :person, :include => :username
@request.env['CONTENT_TYPE'] = 'application/json'
post :parse, { 'username' => 'sikachu', 'title' => 'Developer' }
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index e62f3155c5..be59da9105 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -1023,11 +1023,6 @@ class RenderTest < ActionController::TestCase
assert_equal " ", @response.body
end
- def test_render_to_string_not_deprecated
- assert_not_deprecated { get :hello_in_a_string }
- assert_equal "How's there? goodbyeHello: davidHello: marygoodbye\n", @response.body
- end
-
def test_render_to_string_doesnt_break_assigns
get :render_to_string_with_assigns
assert_equal "i'm before the render", assigns(:before)
@@ -1106,7 +1101,7 @@ class RenderTest < ActionController::TestCase
end
def test_yield_content_for
- assert_not_deprecated { get :yield_content_for }
+ get :yield_content_for
assert_equal "<title>Putting stuff in the title!</title>\nGreat stuff!\n", @response.body
end
diff --git a/actionpack/test/controller/request_forgery_protection_test.rb b/actionpack/test/controller/request_forgery_protection_test.rb
index dea80ed887..d94db7f5fb 100644
--- a/actionpack/test/controller/request_forgery_protection_test.rb
+++ b/actionpack/test/controller/request_forgery_protection_test.rb
@@ -80,7 +80,7 @@ module RequestForgeryProtectionTests
def setup
@token = "cf50faa3fe97702ca1ae"
- ActiveSupport::SecureRandom.stubs(:base64).returns(@token)
+ SecureRandom.stubs(:base64).returns(@token)
ActionController::Base.request_forgery_protection_token = :custom_authenticity_token
end
@@ -184,7 +184,7 @@ class RequestForgeryProtectionControllerTest < ActionController::TestCase
end
test 'should emit a csrf-param meta tag and a csrf-token meta tag' do
- ActiveSupport::SecureRandom.stubs(:base64).returns(@token + '<=?')
+ SecureRandom.stubs(:base64).returns(@token + '<=?')
get :meta
assert_select 'meta[name=?][content=?]', 'csrf-param', 'custom_authenticity_token'
assert_select 'meta[name=?][content=?]', 'csrf-token', 'cf50faa3fe97702ca1ae&lt;=?'
@@ -207,7 +207,7 @@ class FreeCookieControllerTest < ActionController::TestCase
@response = ActionController::TestResponse.new
@token = "cf50faa3fe97702ca1ae"
- ActiveSupport::SecureRandom.stubs(:base64).returns(@token)
+ SecureRandom.stubs(:base64).returns(@token)
end
def test_should_not_render_form_with_token_tag
diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb
index 3de1849db8..f5ac886c20 100644
--- a/actionpack/test/controller/view_paths_test.rb
+++ b/actionpack/test/controller/view_paths_test.rb
@@ -32,17 +32,11 @@ class ViewLoadPathsTest < ActionController::TestCase
@controller.send :assign_shortcuts, @request, @response
@controller.send :initialize_template_class, @response
- # Track the last warning.
- @old_behavior = ActiveSupport::Deprecation.behavior
- @last_message = nil
- ActiveSupport::Deprecation.behavior = Proc.new { |message, callback| @last_message = message }
-
@paths = TestController.view_paths
end
def teardown
TestController.view_paths = @paths
- ActiveSupport::Deprecation.behavior = @old_behavior
end
def expand(array)
@@ -179,7 +173,7 @@ class ViewLoadPathsTest < ActionController::TestCase
assert_nothing_raised { C.append_view_path 'c/path' }
assert_paths C, "c/path"
end
-
+
def test_lookup_context_accessor
assert_equal ["test"], TestController.new.lookup_context.prefixes
end
diff --git a/actionpack/test/dispatch/cookies_test.rb b/actionpack/test/dispatch/cookies_test.rb
index ebc16694db..e42c39f527 100644
--- a/actionpack/test/dispatch/cookies_test.rb
+++ b/actionpack/test/dispatch/cookies_test.rb
@@ -121,7 +121,7 @@ class CookiesTest < ActionController::TestCase
end
def string_key
- cookies['user_name'] = "david"
+ cookies['user_name'] = "dhh"
head :ok
end
@@ -417,14 +417,18 @@ class CookiesTest < ActionController::TestCase
assert_cookie_header "user_name=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"
end
+
def test_cookies_hash_is_indifferent_access
- [:symbol_key, :string_key].each do |cookie_key|
- get cookie_key
+ get :symbol_key
assert_equal "david", cookies[:user_name]
assert_equal "david", cookies['user_name']
- end
+ get :string_key
+ assert_equal "dhh", cookies[:user_name]
+ assert_equal "dhh", cookies['user_name']
end
+
+
def test_setting_request_cookies_is_indifferent_access
@request.cookies.clear
@request.cookies[:user_name] = "andrew"
diff --git a/actionpack/test/dispatch/response_body_is_proc_test.rb b/actionpack/test/dispatch/response_body_is_proc_test.rb
deleted file mode 100644
index fd94832624..0000000000
--- a/actionpack/test/dispatch/response_body_is_proc_test.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-require 'abstract_unit'
-
-class ResponseBodyIsProcTest < ActionDispatch::IntegrationTest
- class TestController < ActionController::Base
- def test
- self.response_body = proc { |response, output|
- output.write 'Hello'
- }
- end
- end
-
- def test_simple_get
- with_test_route_set do
- assert_deprecated do
- get '/test'
- end
- assert_response :success
- assert_equal 'Hello', response.body
- end
- end
-
- private
-
- def with_test_route_set(options = {})
- with_routing do |set|
- set.draw do
- match ':action', :to => ::ResponseBodyIsProcTest::TestController
- end
-
- @app = self.class.build_app(set) do |middleware|
- middleware.delete "ActionDispatch::ShowExceptions"
- end
-
- yield
- end
- end
-end
diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb
index b0efbcef4a..301bf9c6d2 100644
--- a/actionpack/test/dispatch/session/cookie_store_test.rb
+++ b/actionpack/test/dispatch/session/cookie_store_test.rb
@@ -6,7 +6,7 @@ class CookieStoreTest < ActionDispatch::IntegrationTest
SessionSecret = 'b3c631c314c0bbca50c1b2843150fe33'
Verifier = ActiveSupport::MessageVerifier.new(SessionSecret, 'SHA1')
- SignedBar = Verifier.generate(:foo => "bar", :session_id => ActiveSupport::SecureRandom.hex(16))
+ SignedBar = Verifier.generate(:foo => "bar", :session_id => SecureRandom.hex(16))
class TestController < ActionController::Base
def no_session_access
diff --git a/actionpack/test/fixtures/sprockets/app/javascripts/application.js b/actionpack/test/fixtures/sprockets/app/javascripts/application.js
index e69de29bb2..e611d2b129 100644
--- a/actionpack/test/fixtures/sprockets/app/javascripts/application.js
+++ b/actionpack/test/fixtures/sprockets/app/javascripts/application.js
@@ -0,0 +1 @@
+//= require xmlhr
diff --git a/actionpack/test/fixtures/sprockets/app/stylesheets/application.css b/actionpack/test/fixtures/sprockets/app/stylesheets/application.css
index e69de29bb2..2365eaa4cd 100644
--- a/actionpack/test/fixtures/sprockets/app/stylesheets/application.css
+++ b/actionpack/test/fixtures/sprockets/app/stylesheets/application.css
@@ -0,0 +1 @@
+/*= require style */
diff --git a/actionpack/test/fixtures/test/deprecated_nested_layout.erb b/actionpack/test/fixtures/test/deprecated_nested_layout.erb
deleted file mode 100644
index 7b6dcbb6c7..0000000000
--- a/actionpack/test/fixtures/test/deprecated_nested_layout.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-<% content_for :title, "title" -%>
-<% content_for :column do -%>column<% end -%>
-<% render :layout => 'layouts/column' do -%>content<% end -%> \ No newline at end of file
diff --git a/actionpack/test/template/atom_feed_helper_test.rb b/actionpack/test/template/atom_feed_helper_test.rb
index 36102bbc4f..81d7444cf8 100644
--- a/actionpack/test/template/atom_feed_helper_test.rb
+++ b/actionpack/test/template/atom_feed_helper_test.rb
@@ -16,7 +16,7 @@ class ScrollsController < ActionController::Base
feed.title("My great blog!")
feed.updated((@scrolls.first.created_at))
- for scroll in @scrolls
+ @scrolls.each do |scroll|
feed.entry(scroll) do |entry|
entry.title(scroll.title)
entry.content(scroll.body, :type => 'html')
@@ -33,7 +33,7 @@ class ScrollsController < ActionController::Base
feed.title("My great blog!")
feed.updated((@scrolls.first.created_at))
- for scroll in @scrolls
+ @scrolls.each do |scroll|
feed.entry(scroll, :url => "/otherstuff/" + scroll.to_param.to_s, :updated => Time.utc(2007, 1, scroll.id)) do |entry|
entry.title(scroll.title)
entry.content(scroll.body, :type => 'html')
@@ -54,7 +54,7 @@ class ScrollsController < ActionController::Base
author.name("DHH")
end
- for scroll in @scrolls
+ @scrolls.each do |scroll|
feed.entry(scroll, :url => "/otherstuff/" + scroll.to_param.to_s, :updated => Time.utc(2007, 1, scroll.id)) do |entry|
entry.title(scroll.title)
entry.content(scroll.body, :type => 'html')
@@ -68,7 +68,7 @@ class ScrollsController < ActionController::Base
feed.title("My great blog!")
feed.updated((@scrolls.first.created_at))
- for scroll in @scrolls
+ @scrolls.each do |scroll|
feed.entry(scroll) do |entry|
entry.title(scroll.title)
entry.content(scroll.body, :type => 'html')
@@ -86,7 +86,7 @@ class ScrollsController < ActionController::Base
feed.title("My great blog!")
feed.updated((@scrolls.first.created_at))
- for scroll in @scrolls
+ @scrolls.each do |scroll|
feed.entry(scroll, :id => "tag:test.rubyonrails.org,2008:"+scroll.id.to_s) do |entry|
entry.title(scroll.title)
entry.content(scroll.body, :type => 'html')
@@ -105,7 +105,7 @@ class ScrollsController < ActionController::Base
feed.title("My great blog!")
feed.updated((@scrolls.first.created_at))
- for scroll in @scrolls
+ @scrolls.each do |scroll|
feed.entry(scroll) do |entry|
entry.title(scroll.title)
entry.content(scroll.body, :type => 'html')
@@ -123,7 +123,7 @@ class ScrollsController < ActionController::Base
feed.title("My great blog!")
feed.updated((@scrolls.first.created_at))
- for scroll in @scrolls
+ @scrolls.each do |scroll|
feed.entry(scroll) do |entry|
entry.title(scroll.title)
entry.content(scroll.body, :type => 'html')
@@ -140,7 +140,7 @@ class ScrollsController < ActionController::Base
feed.title("My great blog!")
feed.updated((@scrolls.first.created_at))
- for scroll in @scrolls
+ @scrolls.each do |scroll|
feed.entry(scroll) do |entry|
entry.title(scroll.title)
entry.summary(:type => 'xhtml') do |xhtml|
@@ -165,7 +165,7 @@ class ScrollsController < ActionController::Base
feed.title("My great blog!")
feed.updated((@scrolls.first.created_at))
- for scroll in @scrolls
+ @scrolls.each do |scroll|
feed.entry(scroll) do |entry|
entry.title(scroll.title)
entry.content(scroll.body, :type => 'html')
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 286bfb4d04..f2a49f7a68 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -974,6 +974,22 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
+ def test_nested_fields_for_with_index_with_index_and_parent_fields
+ form_for(@post, :index => 1) do |c|
+ concat c.text_field(:title)
+ concat c.fields_for_with_index('comment', @comment, :index => 1) { |r, comment_index|
+ concat r.text_field(:name, "data-index" => comment_index)
+ }
+ end
+
+ expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', 'put') do
+ "<input name='post[1][title]' size='30' type='text' id='post_1_title' value='Hello World' />" +
+ "<input name='post[1][comment][1][name]' size='30' type='text' id='post_1_comment_1_name' value='new comment' data-index='1' />"
+ end
+
+ assert_dom_equal expected, output_buffer
+ end
+
def test_form_for_with_index_and_nested_fields_for
output_buffer = form_for(@post, :index => 1) do |f|
concat f.fields_for(:comment, @post) { |c|
@@ -1030,6 +1046,20 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
+ def test_nested_fields_for_with_index_with_index_radio_button
+ form_for(@post) do |f|
+ concat f.fields_for_with_index(:comment, @post, :index => 5) { |c, index|
+ concat c.radio_button(:title, "hello", "data-index" => index)
+ }
+ end
+
+ expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', 'put') do
+ "<input name='post[comment][5][title]' type='radio' id='post_comment_5_title_hello' value='hello' data-index='5' />"
+ end
+
+ assert_dom_equal expected, output_buffer
+ end
+
def test_nested_fields_for_with_auto_index_on_both
form_for(@post, :as => "post[]") do |f|
concat f.fields_for("comment[]", @post) { |c|
@@ -1229,6 +1259,29 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
+ def test_nested_fields_for_with_index_with_existing_records_on_a_nested_attributes_collection_association
+ @post.comments = Array.new(2) { |id| Comment.new(id + 1) }
+
+ form_for(@post) do |f|
+ concat f.text_field(:title)
+ @post.comments.each do |comment|
+ concat f.fields_for_with_index(:comments, comment) { |cf, index|
+ concat cf.text_field(:name, "data-index" => index)
+ }
+ end
+ end
+
+ expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do
+ '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
+ '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #1" data-index="0" />' +
+ '<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
+ '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="comment #2" data-index="1" />' +
+ '<input id="post_comments_attributes_1_id" name="post[comments_attributes][1][id]" type="hidden" value="2" />'
+ end
+
+ assert_dom_equal expected, output_buffer
+ end
+
def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collection_association_with_disabled_hidden_id
@post.comments = Array.new(2) { |id| Comment.new(id + 1) }
@post.author = Author.new(321)
@@ -1256,6 +1309,33 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
+ def test_nested_fields_for_with_index_with_existing_records_on_a_nested_attributes_collection_association_with_disabled_hidden_id
+ @post.comments = Array.new(2) { |id| Comment.new(id + 1) }
+ @post.author = Author.new(321)
+
+ form_for(@post) do |f|
+ concat f.text_field(:title)
+ concat f.fields_for(:author) { |af|
+ concat af.text_field(:name)
+ }
+ @post.comments.each do |comment|
+ concat f.fields_for_with_index(:comments, comment, :include_id => false) { |cf, index|
+ concat cf.text_field(:name, 'data-index' => index)
+ }
+ end
+ end
+
+ expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do
+ '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
+ '<input id="post_author_attributes_name" name="post[author_attributes][name]" size="30" type="text" value="author #321" />' +
+ '<input id="post_author_attributes_id" name="post[author_attributes][id]" type="hidden" value="321" />' +
+ '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #1" data-index="0" />' +
+ '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="comment #2" data-index="1" />'
+ end
+
+ assert_dom_equal expected, output_buffer
+ end
+
def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collection_association_with_disabled_hidden_id_inherited
@post.comments = Array.new(2) { |id| Comment.new(id + 1) }
@post.author = Author.new(321)
@@ -1377,6 +1457,28 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
+ def test_nested_fields_for_with_index_with_new_records_on_a_nested_attributes_collection_association
+ @post.comments = [Comment.new, Comment.new]
+
+ form_for(@post) do |f|
+ concat f.text_field(:title)
+ @post.comments.each do |comment|
+ concat f.fields_for_with_index(:comments, comment) { |cf, index|
+ concat cf.text_field(:name, "data-index" => index)
+ }
+ end
+ end
+
+ expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do
+ '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
+ '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="new comment" data-index="0" />' +
+ '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="new comment" data-index="1" />'
+ end
+
+ assert_dom_equal expected, output_buffer
+ end
+
+
def test_nested_fields_for_with_existing_and_new_records_on_a_nested_attributes_collection_association
@post.comments = [Comment.new(321), Comment.new]
@@ -1399,6 +1501,29 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
+ def test_nested_fields_for_with_index_with_existing_and_new_records_on_a_nested_attributes_collection_association
+ @post.comments = [Comment.new(321), Comment.new]
+
+ form_for(@post) do |f|
+ concat f.text_field(:title)
+ @post.comments.each do |comment|
+ concat f.fields_for_with_index(:comments, comment) { |cf, index|
+ concat cf.text_field(:name, "data-index" => index)
+ }
+ end
+ end
+
+ expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do
+ '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
+ '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #321" data-index="0" />' +
+ '<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="321" />' +
+ '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="new comment" data-index="1" />'
+ end
+
+ assert_dom_equal expected, output_buffer
+ end
+
+
def test_nested_fields_for_with_an_empty_supplied_attributes_collection
form_for(@post) do |f|
concat f.text_field(:title)
diff --git a/actionpack/test/template/number_helper_test.rb b/actionpack/test/template/number_helper_test.rb
index 63b92aadf4..0104c20bc7 100644
--- a/actionpack/test/template/number_helper_test.rb
+++ b/actionpack/test/template/number_helper_test.rb
@@ -19,15 +19,6 @@ class NumberHelperTest < ActionView::TestCase
gigabytes(number) * 1024
end
- def silence_deprecation_warnings
- @old_deprecatios_silenced = ActiveSupport::Deprecation.silenced
- ActiveSupport::Deprecation.silenced = true
- end
-
- def restore_deprecation_warnings
- ActiveSupport::Deprecation.silenced = @old_deprecatios_silenced
- end
-
def test_number_to_phone
assert_equal("555-1234", number_to_phone(5551234))
assert_equal("800-555-1212", number_to_phone(8005551212))
diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb
index 8d3be09a4f..b26315083c 100644
--- a/actionpack/test/template/sprockets_helper_test.rb
+++ b/actionpack/test/template/sprockets_helper_test.rb
@@ -1,11 +1,10 @@
require 'abstract_unit'
require 'sprockets'
+require 'sprockets/helpers/rails_helper'
require 'mocha'
-module Rails; end
-
class SprocketsHelperTest < ActionView::TestCase
- tests ActionView::Helpers::SprocketsHelper
+ tests Sprockets::Helpers::RailsHelper
attr_accessor :assets
@@ -13,6 +12,7 @@ class SprocketsHelperTest < ActionView::TestCase
super
@controller = BasicController.new
+ @controller.stubs(:params).returns({})
@request = Class.new do
def protocol() 'http://' end
@@ -77,18 +77,21 @@ class SprocketsHelperTest < ActionView::TestCase
test "javascript include tag" do
assert_equal '<script src="/assets/application-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>',
- sprockets_javascript_include_tag(:application)
+ javascript_include_tag(:application)
assert_equal '<script src="/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>',
- sprockets_javascript_include_tag("xmlhr")
+ javascript_include_tag("xmlhr")
assert_equal '<script src="/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>',
- sprockets_javascript_include_tag("xmlhr.js")
+ javascript_include_tag("xmlhr.js")
assert_equal '<script src="http://www.example.com/xmlhr" type="text/javascript"></script>',
- sprockets_javascript_include_tag("http://www.example.com/xmlhr")
+ javascript_include_tag("http://www.example.com/xmlhr")
+
+ assert_equal "<script src=\"/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js?body=1\" type=\"text/javascript\"></script>\n<script src=\"/assets/application-d41d8cd98f00b204e9800998ecf8427e.js?body=1\" type=\"text/javascript\"></script>",
+ javascript_include_tag(:application, :debug => true)
end
test "stylesheet path" do
- assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.css", asset_path(:application, "css")
+ assert_equal "/assets/application-68b329da9893e34099c7d8ad5cb9c940.css", asset_path(:application, "css")
assert_equal "/assets/style-d41d8cd98f00b204e9800998ecf8427e.css", asset_path("style", "css")
assert_equal "/assets/dir/style-d41d8cd98f00b204e9800998ecf8427e.css", asset_path("dir/style.css", "css")
@@ -101,19 +104,22 @@ class SprocketsHelperTest < ActionView::TestCase
end
test "stylesheet link tag" do
- assert_equal '<link href="/assets/application-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />',
- sprockets_stylesheet_link_tag(:application)
+ assert_equal '<link href="/assets/application-68b329da9893e34099c7d8ad5cb9c940.css" media="screen" rel="stylesheet" type="text/css" />',
+ stylesheet_link_tag(:application)
assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />',
- sprockets_stylesheet_link_tag("style")
+ stylesheet_link_tag("style")
assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />',
- sprockets_stylesheet_link_tag("style.css")
+ stylesheet_link_tag("style.css")
assert_equal '<link href="http://www.example.com/style.css" media="screen" rel="stylesheet" type="text/css" />',
- sprockets_stylesheet_link_tag("http://www.example.com/style.css")
+ stylesheet_link_tag("http://www.example.com/style.css")
assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="all" rel="stylesheet" type="text/css" />',
- sprockets_stylesheet_link_tag("style", :media => "all")
+ stylesheet_link_tag("style", :media => "all")
assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="print" rel="stylesheet" type="text/css" />',
- sprockets_stylesheet_link_tag("style", :media => "print")
+ stylesheet_link_tag("style", :media => "print")
+
+ assert_equal "<link href=\"/assets/style-d41d8cd98f00b204e9800998ecf8427e.css?body=1\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<link href=\"/assets/application-68b329da9893e34099c7d8ad5cb9c940.css?body=1\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />",
+ stylesheet_link_tag(:application, :debug => true)
end
end
diff --git a/actionpack/test/template/streaming_render_test.rb b/actionpack/test/template/streaming_render_test.rb
index b2df8efee3..023ce723ed 100644
--- a/actionpack/test/template/streaming_render_test.rb
+++ b/actionpack/test/template/streaming_render_test.rb
@@ -8,7 +8,7 @@ end
class FiberedTest < ActiveSupport::TestCase
def setup
view_paths = ActionController::Base.view_paths
- @assigns = { :secret => 'in the sauce' }
+ @assigns = { :secret => 'in the sauce', :name => nil }
@view = ActionView::Base.new(view_paths, @assigns)
@controller_view = TestController.new.view_context
end
@@ -106,4 +106,4 @@ class FiberedTest < ActiveSupport::TestCase
buffered_render(:template => "test/nested_streaming", :layout => "layouts/streaming")
end
-end if defined?(Fiber) \ No newline at end of file
+end if defined?(Fiber)
diff --git a/actionpack/test/template/test_case_test.rb b/actionpack/test/template/test_case_test.rb
index cd4618a505..f463675a2e 100644
--- a/actionpack/test/template/test_case_test.rb
+++ b/actionpack/test/template/test_case_test.rb
@@ -141,22 +141,6 @@ module ActionView
end
end
- class AssignsTest < ActionView::TestCase
- setup do
- ActiveSupport::Deprecation.stubs(:warn)
- end
-
- test "_assigns delegates to user_defined_ivars" do
- self.expects(:view_assigns)
- _assigns
- end
-
- test "_assigns is deprecated" do
- ActiveSupport::Deprecation.expects(:warn)
- _assigns
- end
- end
-
class ViewAssignsTest < ActionView::TestCase
test "view_assigns returns a Hash of user defined ivars" do
@a = 'b'
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb
index 8d0f0124c2..4aa45c8bf0 100644
--- a/actionpack/test/template/url_helper_test.rb
+++ b/actionpack/test/template/url_helper_test.rb
@@ -25,6 +25,8 @@ class UrlHelperTest < ActiveSupport::TestCase
include ActionView::Context
include RenderERBUtils
+ setup :_prepare_context
+
def hash_for(opts = [])
ActiveSupport::OrderedHash[*([:controller, "foo", :action, "bar"].concat(opts))]
end