aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorRizwan Reza <rizwanreza@gmail.com>2010-05-17 02:40:15 +0430
committerRizwan Reza <rizwanreza@gmail.com>2010-05-17 02:40:15 +0430
commitd148a6f6ba5f8ee65905f12cd2601fcc377d4852 (patch)
tree4bcb5e7ad47cfb9a9bb14ffe7c9e003d4646d64c /actionpack
parente1c773006969abea3c0619fbdc7e32c121b6085f (diff)
parent6b4e0cc526f55b5532cf99292c94f0a4db53b16f (diff)
downloadrails-d148a6f6ba5f8ee65905f12cd2601fcc377d4852.tar.gz
rails-d148a6f6ba5f8ee65905f12cd2601fcc377d4852.tar.bz2
rails-d148a6f6ba5f8ee65905f12cd2601fcc377d4852.zip
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/Rakefile19
-rw-r--r--actionpack/lib/action_dispatch/middleware/flash.rb10
-rw-r--r--actionpack/lib/action_dispatch/middleware/session/cookie_store.rb2
-rw-r--r--actionpack/lib/action_dispatch/middleware/show_exceptions.rb12
-rw-r--r--actionpack/lib/action_dispatch/testing/assertions/selector.rb16
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helper.rb2
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb61
-rw-r--r--actionpack/lib/action_view/helpers/form_options_helper.rb27
-rw-r--r--actionpack/lib/action_view/helpers/form_tag_helper.rb10
-rw-r--r--actionpack/lib/action_view/render/partials.rb27
-rw-r--r--actionpack/lib/action_view/template/error.rb5
-rw-r--r--actionpack/lib/action_view/template/handlers/erb.rb2
-rw-r--r--actionpack/test/controller/assert_select_test.rb22
-rw-r--r--actionpack/test/controller/capture_test.rb5
-rw-r--r--actionpack/test/controller/flash_test.rb20
-rw-r--r--actionpack/test/controller/render_test.rb13
-rw-r--r--actionpack/test/dispatch/request/xml_params_parsing_test.rb2
-rw-r--r--actionpack/test/fixtures/test/_customer_counter_with_as.erb1
-rw-r--r--actionpack/test/fixtures/test/proper_block_detection.erb1
-rw-r--r--actionpack/test/template/asset_tag_helper_test.rb3
-rw-r--r--actionpack/test/template/capture_helper_test.rb2
-rw-r--r--actionpack/test/template/form_helper_test.rb117
-rw-r--r--actionpack/test/template/form_options_helper_test.rb56
-rw-r--r--actionpack/test/template/form_tag_helper_test.rb14
-rw-r--r--actionpack/test/template/render_test.rb1
25 files changed, 365 insertions, 85 deletions
diff --git a/actionpack/Rakefile b/actionpack/Rakefile
index b9ace8658a..f3bd7dfc10 100644
--- a/actionpack/Rakefile
+++ b/actionpack/Rakefile
@@ -88,23 +88,4 @@ task :lines do
end
puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
-end
-
-# Publishing ------------------------------------------------------
-
-task :update_scriptaculous do
- for js in %w( controls dragdrop effects )
- system("svn export --force http://dev.rubyonrails.org/svn/rails/spinoffs/scriptaculous/src/#{js}.js #{File.dirname(__FILE__)}/lib/action_view/helpers/javascripts/#{js}.js")
- end
-end
-
-desc "Updates actionpack to the latest version of the javascript spinoffs"
-task :update_js => [ :update_scriptaculous ]
-
-# Publishing ------------------------------------------------------
-
-desc "Publish the API documentation"
-task :pdoc => [:rdoc] do
- require 'rake/contrib/sshpublisher'
- Rake::SshDirPublisher.new("wrath.rubyonrails.org", "public_html/ap", "doc").upload
end \ No newline at end of file
diff --git a/actionpack/lib/action_dispatch/middleware/flash.rb b/actionpack/lib/action_dispatch/middleware/flash.rb
index 99b36366d6..adde183cdb 100644
--- a/actionpack/lib/action_dispatch/middleware/flash.rb
+++ b/actionpack/lib/action_dispatch/middleware/flash.rb
@@ -49,6 +49,16 @@ module ActionDispatch
def [](k)
@flash[k]
end
+
+ # Convenience accessor for flash.now[:alert]=
+ def alert=(message)
+ self[:alert] = message
+ end
+
+ # Convenience accessor for flash.now[:notice]=
+ def notice=(message)
+ self[:notice] = message
+ end
end
class FlashHash < Hash
diff --git a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
index 88ba941676..7114f42003 100644
--- a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
@@ -177,7 +177,7 @@ module ActionDispatch
if key.blank?
raise ArgumentError, 'A key is required to write a ' +
'cookie containing the session data. Use ' +
- 'config.action_controller.session_store :cookie_store, { :key => ' +
+ 'config.session_store :cookie_store, { :key => ' +
'"_myapp_session" } in config/application.rb'
end
end
diff --git a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb
index 12a93d6a24..2dd2ec9fe9 100644
--- a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb
+++ b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb
@@ -133,14 +133,10 @@ module ActionDispatch
return unless logger
ActiveSupport::Deprecation.silence do
- if ActionView::Template::Error === exception
- logger.fatal(exception.to_s)
- else
- logger.fatal(
- "\n#{exception.class} (#{exception.message}):\n " +
- clean_backtrace(exception).join("\n ") + "\n\n"
- )
- end
+ message = "\n#{exception.class} (#{exception.message}):\n"
+ message << exception.annoted_source_code if exception.respond_to?(:annoted_source_code)
+ message << exception.backtrace.join("\n ")
+ logger.fatal("#{message}\n\n")
end
end
diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb
index a6b1126e2b..9deabf5b3c 100644
--- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb
+++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb
@@ -298,10 +298,14 @@ module ActionDispatch
# found one but expecting two.
message ||= content_mismatch if matches.empty?
# Test minimum/maximum occurrence.
- min, max = equals[:minimum], equals[:maximum]
- message = message || %(Expected #{count_description(min, max)} matching "#{selector.to_s}", found #{matches.size}.)
- assert matches.size >= min, message if min
- assert matches.size <= max, message if max
+ min, max, count = equals[:minimum], equals[:maximum], equals[:count]
+ message = message || %(Expected #{count_description(min, max, count)} matching "#{selector.to_s}", found #{matches.size}.)
+ if count
+ assert matches.size == count, message
+ else
+ assert matches.size >= min, message if min
+ assert matches.size <= max, message if max
+ end
# If a block is given call that block. Set @selected to allow
# nested assert_select, which can be nested several levels deep.
@@ -318,11 +322,13 @@ module ActionDispatch
matches
end
- def count_description(min, max) #:nodoc:
+ def count_description(min, max, count) #:nodoc:
pluralize = lambda {|word, quantity| word << (quantity == 1 ? '' : 's')}
if min && max && (max != min)
"between #{min} and #{max} elements"
+ elsif min && max && max == min && count
+ "exactly #{count} #{pluralize['element', min]}"
elsif min && !(min == 1 && max == 1)
"at least #{min} #{pluralize['element', min]}"
elsif max
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
index 8731ed0ef3..e1fbc118d5 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -620,7 +620,7 @@ module ActionView
options.symbolize_keys!
src = options[:src] = path_to_image(source)
- options[:alt] ||= File.basename(src, '.*').capitalize
+ options[:alt] = options.fetch(:alt){ File.basename(src, '.*').capitalize }
if size = options.delete(:size)
options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$}
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index 6e26ae6c29..414a5d4cd9 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -573,8 +573,19 @@ module ActionView
# label(:post, :privacy, "Public Post", :value => "public")
# # => <label for="post_privacy_public">Public Post</label>
#
- def label(object_name, method, text = nil, options = {})
- InstanceTag.new(object_name, method, self, options.delete(:object)).to_label_tag(text, options)
+ # label(:post, :terms) do
+ # 'Accept <a href="/terms">Terms</a>.'
+ # end
+ def label(object_name, method, content_or_options = nil, options = nil, &block)
+ if block_given?
+ options = content_or_options if content_or_options.is_a?(Hash)
+ text = nil
+ else
+ text = content_or_options
+ end
+
+ options ||= {}
+ InstanceTag.new(object_name, method, self, options.delete(:object)).to_label_tag(text, options, &block)
end
# Returns an input tag of the "text" type tailored for accessing a specified attribute (identified by +method+) on an object
@@ -823,7 +834,7 @@ module ActionView
module InstanceTagMethods #:nodoc:
extend ActiveSupport::Concern
- include Helpers::TagHelper, Helpers::FormTagHelper
+ include Helpers::CaptureHelper, Context, Helpers::TagHelper, Helpers::FormTagHelper
attr_reader :method_name, :object_name
@@ -844,28 +855,38 @@ module ActionView
end
end
- def to_label_tag(text = nil, options = {})
+ def to_label_tag(text = nil, options = {}, &block)
options = options.stringify_keys
tag_value = options.delete("value")
name_and_id = options.dup
- name_and_id["id"] = name_and_id["for"]
+
+ if name_and_id["for"]
+ name_and_id["id"] = name_and_id["for"]
+ else
+ name_and_id.delete("id")
+ end
+
add_default_name_and_id_for_value(tag_value, name_and_id)
options.delete("index")
options["for"] ||= name_and_id["id"]
- content = if text.blank?
- I18n.t("helpers.label.#{object_name}.#{method_name}", :default => "").presence
+ if block_given?
+ label_tag(name_and_id["id"], options, &block)
else
- text.to_s
- end
+ content = if text.blank?
+ I18n.t("helpers.label.#{object_name}.#{method_name}", :default => "").presence
+ else
+ text.to_s
+ end
- content ||= if object && object.class.respond_to?(:human_attribute_name)
- object.class.human_attribute_name(method_name)
- end
+ content ||= if object && object.class.respond_to?(:human_attribute_name)
+ object.class.human_attribute_name(method_name)
+ end
- content ||= method_name.humanize
+ content ||= method_name.humanize
- label_tag(name_and_id["id"], content, options)
+ label_tag(name_and_id["id"], content, options)
+ end
end
def to_input_field_tag(field_type, options = {})
@@ -1012,7 +1033,7 @@ module ActionView
pretty_tag_value = tag_value.to_s.gsub(/\s/, "_").gsub(/\W/, "").downcase
specified_id = options["id"]
add_default_name_and_id(options)
- options["id"] += "_#{pretty_tag_value}" unless specified_id
+ options["id"] += "_#{pretty_tag_value}" if specified_id.blank? && options["id"].present?
else
add_default_name_and_id(options)
end
@@ -1021,14 +1042,14 @@ module ActionView
def add_default_name_and_id(options)
if options.has_key?("index")
options["name"] ||= tag_name_with_index(options["index"])
- options["id"] ||= tag_id_with_index(options["index"])
+ options["id"] = options.fetch("id", tag_id_with_index(options["index"]))
options.delete("index")
elsif defined?(@auto_index)
options["name"] ||= tag_name_with_index(@auto_index)
- options["id"] ||= tag_id_with_index(@auto_index)
+ options["id"] = options.fetch("id", tag_id_with_index(@auto_index))
else
options["name"] ||= tag_name + (options.has_key?('multiple') ? '[]' : '')
- options["id"] ||= tag_id
+ options["id"] = options.fetch("id", tag_id)
end
end
@@ -1137,8 +1158,8 @@ module ActionView
@template.fields_for(name, *args, &block)
end
- def label(method, text = nil, options = {})
- @template.label(@object_name, method, text, objectify_options(options))
+ def label(method, text = nil, options = {}, &block)
+ @template.label(@object_name, method, text, objectify_options(options), &block)
end
def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb
index 8f8db548c3..fe71d2cdf7 100644
--- a/actionpack/lib/action_view/helpers/form_options_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_options_helper.rb
@@ -270,6 +270,15 @@ module ActionView
# options_for_select([ "VISA", "MasterCard", "Discover" ], ["VISA", "Discover"])
# <option selected="selected">VISA</option>\n<option>MasterCard</option>\n<option selected="selected">Discover</option>
#
+ # You can optionally provide html attributes as the last element of the array.
+ #
+ # Examples:
+ # options_for_select([ "Denmark", ["USA", {:class=>'bold'}], "Sweden" ], ["USA", "Sweden"])
+ # <option value="Denmark">Denmark</option>\n<option value="USA" class="bold" selected="selected">USA</option>\n<option value="Sweden" selected="selected">Sweden</option>
+ #
+ # options_for_select([["Dollar", "$", {:class=>"bold"}], ["Kroner", "DKK", {:onclick => "alert('HI');"}]])
+ # <option value="$" class="bold">Dollar</option>\n<option value="DKK" onclick="alert('HI');">Kroner</option>
+ #
# If you wish to specify disabled option tags, set +selected+ to be a hash, with <tt>:disabled</tt> being either a value
# or array of values to be disabled. In this case, you can use <tt>:selected</tt> to specify selected option tags.
#
@@ -291,10 +300,11 @@ module ActionView
selected, disabled = extract_selected_and_disabled(selected)
options_for_select = container.inject([]) do |options, element|
+ html_attributes = option_html_attributes(element)
text, value = option_text_and_value(element)
selected_attribute = ' selected="selected"' if option_value_selected?(value, selected)
disabled_attribute = ' disabled="disabled"' if disabled && option_value_selected?(value, disabled)
- options << %(<option value="#{html_escape(value.to_s)}"#{selected_attribute}#{disabled_attribute}>#{html_escape(text.to_s)}</option>)
+ options << %(<option value="#{html_escape(value.to_s)}"#{selected_attribute}#{disabled_attribute}#{html_attributes}>#{html_escape(text.to_s)}</option>)
end
options_for_select.join("\n").html_safe
@@ -486,9 +496,22 @@ module ActionView
end
private
+ def option_html_attributes(element)
+ return "" unless Array === element
+ html_attributes = []
+ element.select { |e| Hash === e }.reduce({}, :merge).each do |k, v|
+ html_attributes << " #{k}=\"#{html_escape(v.to_s)}\""
+ end
+ html_attributes.join
+ end
+
def option_text_and_value(option)
# Options are [text, value] pairs or strings used for both.
- if !option.is_a?(String) and option.respond_to?(:first) and option.respond_to?(:last)
+ case
+ when Array === option
+ option = option.reject { |e| Hash === e }
+ [option.first, option.last]
+ when !option.is_a?(String) && option.respond_to?(:first) && option.respond_to?(:last)
[option.first, option.last]
else
[option, option]
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb
index b840f77fb5..2a3f826c15 100644
--- a/actionpack/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -142,7 +142,7 @@ module ActionView
tag :input, { "type" => "text", "name" => name, "id" => sanitize_to_id(name), "value" => value }.update(options.stringify_keys)
end
- # Creates a label field
+ # Creates a label element. Accepts a block.
#
# ==== Options
# * Creates standard HTML attributes for the tag.
@@ -156,8 +156,12 @@ module ActionView
#
# label_tag 'name', nil, :class => 'small_label'
# # => <label for="name" class="small_label">Name</label>
- def label_tag(name, text = nil, options = {})
- content_tag :label, text || name.to_s.humanize, { "for" => sanitize_to_id(name) }.update(options.stringify_keys)
+ def label_tag(name = nil, content_or_options = nil, options = nil, &block)
+ options = content_or_options if block_given? && content_or_options.is_a?(Hash)
+ options ||= {}
+ options.stringify_keys!
+ options["for"] = sanitize_to_id(name) unless name.blank? || options.has_key?("for")
+ content_tag :label, content_or_options || name.to_s.humanize, options, &block
end
# Creates a hidden form input field used to transmit data that would be lost due to HTTP's statelessness or
diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb
index 974345633c..85f67d4f14 100644
--- a/actionpack/lib/action_view/render/partials.rb
+++ b/actionpack/lib/action_view/render/partials.rb
@@ -241,15 +241,21 @@ module ActionView
end
def collection_with_template(template = @template)
- segments, locals, as, template = [], @locals, @options[:as] || @template.variable_name, @template
+ segments, locals, template = [], @locals, @template
- counter_name = template.counter_name
- locals[counter_name] = -1
+ if @options[:as]
+ as = @options[:as]
+ counter = "#{as}_counter".to_sym
+ else
+ as = template.variable_name
+ counter = template.counter_name
+ end
+
+ locals[counter] = -1
@collection.each do |object|
- locals[counter_name] += 1
+ locals[counter] += 1
locals[as] = object
-
segments << template.render(@view, locals)
end
@@ -257,13 +263,18 @@ module ActionView
end
def collection_without_template(collection_paths = @collection_paths)
- segments, locals, as = [], @locals, @options[:as]
- index, template = -1, nil
+ segments, locals = [], @locals
+ index, template = -1, nil
+
+ if @options[:as]
+ as = @options[:as]
+ counter = "#{as}_counter"
+ end
@collection.each_with_index do |object, i|
template = find_template(collection_paths[i])
- locals[template.counter_name] = (index += 1)
locals[as || template.variable_name] = object
+ locals[counter || template.counter_name] = (index += 1)
segments << template.render(@view, locals)
end
diff --git a/actionpack/lib/action_view/template/error.rb b/actionpack/lib/action_view/template/error.rb
index a947d746e3..6866eabf77 100644
--- a/actionpack/lib/action_view/template/error.rb
+++ b/actionpack/lib/action_view/template/error.rb
@@ -84,9 +84,8 @@ module ActionView
end
end
- def to_s
- "\n#{self.class} (#{message}) #{source_location}:\n\n" +
- "#{source_extract(4)}\n #{backtrace.join("\n ")}\n\n"
+ def annoted_source_code
+ source_extract(4)
end
private
diff --git a/actionpack/lib/action_view/template/handlers/erb.rb b/actionpack/lib/action_view/template/handlers/erb.rb
index 705c2bf82e..237746437a 100644
--- a/actionpack/lib/action_view/template/handlers/erb.rb
+++ b/actionpack/lib/action_view/template/handlers/erb.rb
@@ -28,7 +28,7 @@ module ActionView
src << "@output_buffer.safe_concat('" << escape_text(text) << "');"
end
- BLOCK_EXPR = /(do|\{)(\s*\|[^|]*\|)?\s*\Z/
+ BLOCK_EXPR = /\s+(do|\{)(\s*\|[^|]*\|)?\s*\Z/
def add_expr_literal(src, code)
if code =~ BLOCK_EXPR
diff --git a/actionpack/test/controller/assert_select_test.rb b/actionpack/test/controller/assert_select_test.rb
index 4ef6fa4000..7012c4c9b0 100644
--- a/actionpack/test/controller/assert_select_test.rb
+++ b/actionpack/test/controller/assert_select_test.rb
@@ -80,10 +80,15 @@ class AssertSelectTest < ActionController::TestCase
def test_assert_select
render_html %Q{<div id="1"></div><div id="2"></div>}
assert_select "div", 2
- assert_failure(/Expected at least 3 elements matching \"div\", found 2/) { assert_select "div", 3 }
assert_failure(/Expected at least 1 element matching \"p\", found 0/) { assert_select "p" }
end
+ def test_equality_integer
+ render_html %Q{<div id="1"></div><div id="2"></div>}
+ assert_failure(/Expected exactly 3 elements matching \"div\", found 2/) { assert_select "div", 3 }
+ assert_failure(/Expected exactly 0 elements matching \"div\", found 2/) { assert_select "div", 0 }
+ end
+
def test_equality_true_false
render_html %Q{<div id="1"></div><div id="2"></div>}
assert_nothing_raised { assert_select "div" }
@@ -94,6 +99,11 @@ class AssertSelectTest < ActionController::TestCase
assert_nothing_raised { assert_select "p", false }
end
+ def test_equality_false_message
+ render_html %Q{<div id="1"></div><div id="2"></div>}
+ assert_failure(/Expected exactly 0 elements matching \"div\", found 2/) { assert_select "div", false }
+ end
+
def test_equality_string_and_regexp
render_html %Q{<div id="1">foo</div><div id="2">foo</div>}
assert_nothing_raised { assert_select "div", "foo" }
@@ -128,7 +138,7 @@ class AssertSelectTest < ActionController::TestCase
def test_counts
render_html %Q{<div id="1">foo</div><div id="2">foo</div>}
assert_nothing_raised { assert_select "div", 2 }
- assert_failure(/Expected at least 3 elements matching \"div\", found 2/) do
+ assert_failure(/Expected exactly 3 elements matching \"div\", found 2/) do
assert_select "div", 3
end
assert_nothing_raised { assert_select "div", 1..2 }
@@ -136,7 +146,7 @@ class AssertSelectTest < ActionController::TestCase
assert_select "div", 3..4
end
assert_nothing_raised { assert_select "div", :count=>2 }
- assert_failure(/Expected at least 3 elements matching \"div\", found 2/) do
+ assert_failure(/Expected exactly 3 elements matching \"div\", found 2/) do
assert_select "div", :count=>3
end
assert_nothing_raised { assert_select "div", :minimum=>1 }
@@ -201,7 +211,7 @@ class AssertSelectTest < ActionController::TestCase
assert_nothing_raised { assert_select "div", "foo" }
assert_nothing_raised { assert_select "div", "bar" }
assert_nothing_raised { assert_select "div", /\w*/ }
- assert_nothing_raised { assert_select "div", /\w*/, :count=>2 }
+ assert_nothing_raised { assert_select "div", :text => /\w*/, :count=>2 }
assert_raise(Assertion) { assert_select "div", :text=>"foo", :count=>2 }
assert_nothing_raised { assert_select "div", :html=>"<span>bar</span>" }
assert_nothing_raised { assert_select "div", :html=>"<span>bar</span>" }
@@ -266,8 +276,8 @@ class AssertSelectTest < ActionController::TestCase
def test_css_select
render_html %Q{<div id="1"></div><div id="2"></div>}
- assert 2, css_select("div").size
- assert 0, css_select("p").size
+ assert_equal 2, css_select("div").size
+ assert_equal 0, css_select("p").size
end
def test_nested_css_select
diff --git a/actionpack/test/controller/capture_test.rb b/actionpack/test/controller/capture_test.rb
index 06a5af6b32..d1dbd535c4 100644
--- a/actionpack/test/controller/capture_test.rb
+++ b/actionpack/test/controller/capture_test.rb
@@ -61,6 +61,11 @@ class CaptureTest < ActionController::TestCase
assert_equal expected_content_for_output, @response.body
end
+ def test_proper_block_detection
+ @todo = "some todo"
+ get :proper_block_detection
+ end
+
private
def expected_content_for_output
"<title>Putting stuff in the title!</title>\n\nGreat stuff!"
diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb
index 3c651ebebc..c662ce264b 100644
--- a/actionpack/test/controller/flash_test.rb
+++ b/actionpack/test/controller/flash_test.rb
@@ -81,6 +81,16 @@ class FlashTest < ActionController::TestCase
redirect_to '/somewhere', :notice => "Good luck in the somewheres!"
end
+ def render_with_flash_now_alert
+ flash.now.alert = "Beware the nowheres now!"
+ render :inline => "hello"
+ end
+
+ def render_with_flash_now_notice
+ flash.now.notice = "Good luck in the somewheres now!"
+ render :inline => "hello"
+ end
+
def redirect_with_other_flashes
redirect_to '/wonderland', :flash => { :joyride => "Horses!" }
end
@@ -183,6 +193,16 @@ class FlashTest < ActionController::TestCase
assert_equal "Good luck in the somewheres!", @controller.send(:flash)[:notice]
end
+ def test_render_with_flash_now_alert
+ get :render_with_flash_now_alert
+ assert_equal "Beware the nowheres now!", @controller.send(:flash)[:alert]
+ end
+
+ def test_render_with_flash_now_notice
+ get :render_with_flash_now_notice
+ assert_equal "Good luck in the somewheres now!", @controller.send(:flash)[:notice]
+ end
+
def test_redirect_to_with_other_flashes
get :redirect_with_other_flashes
assert_equal "Horses!", @controller.send(:flash)[:joyride]
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index 2f3997518f..52049f2a8a 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -547,6 +547,10 @@ class TestController < ActionController::Base
render :partial => "customer_counter", :collection => [ Customer.new("david"), Customer.new("mary") ]
end
+ def partial_collection_with_as_and_counter
+ render :partial => "customer_counter_with_as", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => :client
+ end
+
def partial_collection_with_locals
render :partial => "customer_greeting", :collection => [ Customer.new("david"), Customer.new("mary") ], :locals => { :greeting => "Bonjour" }
end
@@ -1242,6 +1246,11 @@ class RenderTest < ActionController::TestCase
assert_equal "david0mary1", @response.body
end
+ def test_partial_collection_with_as_and_counter
+ get :partial_collection_with_as_and_counter
+ assert_equal "david0mary1", @response.body
+ end
+
def test_partial_collection_with_locals
get :partial_collection_with_locals
assert_equal "Bonjour: davidBonjour: mary", @response.body
@@ -1379,7 +1388,7 @@ class EtagRenderTest < ActionController::TestCase
def test_render_against_etag_request_should_have_no_content_length_when_match
@request.if_none_match = etag_for("hello david")
get :render_hello_world_from_variable
- assert !@response.headers.has_key?("Content-Length"), @response.headers['Content-Length']
+ assert !@response.headers.has_key?("Content-Length")
end
def test_render_against_etag_request_should_200_when_no_match
@@ -1515,4 +1524,4 @@ class LastModifiedRenderTest < ActionController::TestCase
get :conditional_hello_with_bangs
assert_response :success
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/dispatch/request/xml_params_parsing_test.rb b/actionpack/test/dispatch/request/xml_params_parsing_test.rb
index f2ce2c5b93..d44c642420 100644
--- a/actionpack/test/dispatch/request/xml_params_parsing_test.rb
+++ b/actionpack/test/dispatch/request/xml_params_parsing_test.rb
@@ -21,7 +21,7 @@ class XmlParamsParsingTest < ActionController::IntegrationTest
def call(env)
bar = env['action_dispatch.request.request_parameters']['foo']
result = "<ok>#{bar}</ok>"
- [200, {"Content-Type" => "application/xml", "Content-Length" => result.length.to_s}, result]
+ [200, {"Content-Type" => "application/xml", "Content-Length" => result.length.to_s}, [result]]
end
end
req = Rack::MockRequest.new(ActionDispatch::ParamsParser.new(Linted.new))
diff --git a/actionpack/test/fixtures/test/_customer_counter_with_as.erb b/actionpack/test/fixtures/test/_customer_counter_with_as.erb
new file mode 100644
index 0000000000..1241eb604d
--- /dev/null
+++ b/actionpack/test/fixtures/test/_customer_counter_with_as.erb
@@ -0,0 +1 @@
+<%= client.name %><%= client_counter %> \ No newline at end of file
diff --git a/actionpack/test/fixtures/test/proper_block_detection.erb b/actionpack/test/fixtures/test/proper_block_detection.erb
new file mode 100644
index 0000000000..23564dbcee
--- /dev/null
+++ b/actionpack/test/fixtures/test/proper_block_detection.erb
@@ -0,0 +1 @@
+<%= @todo %>
diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb
index 124bf734ac..b6a6f52876 100644
--- a/actionpack/test/template/asset_tag_helper_test.rb
+++ b/actionpack/test/template/asset_tag_helper_test.rb
@@ -154,7 +154,8 @@ class AssetTagHelperTest < ActionView::TestCase
%(image_tag(".pdf.png")) => %(<img alt=".pdf" src="/images/.pdf.png" />),
%(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="http://www.rubyonrails.com/images/rails.png" />),
%(image_tag("mouse.png", :mouseover => "/images/mouse_over.png")) => %(<img alt="Mouse" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" src="/images/mouse.png" />),
- %(image_tag("mouse.png", :mouseover => image_path("mouse_over.png"))) => %(<img alt="Mouse" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" src="/images/mouse.png" />)
+ %(image_tag("mouse.png", :mouseover => image_path("mouse_over.png"))) => %(<img alt="Mouse" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" src="/images/mouse.png" />),
+ %(image_tag("mouse.png", :alt => nil)) => %(<img src="/images/mouse.png" />)
}
FaviconLinkToTag = {
diff --git a/actionpack/test/template/capture_helper_test.rb b/actionpack/test/template/capture_helper_test.rb
index bf541c17d3..9f3d68a639 100644
--- a/actionpack/test/template/capture_helper_test.rb
+++ b/actionpack/test/template/capture_helper_test.rb
@@ -74,7 +74,7 @@ class CaptureHelperTest < ActionView::TestCase
@av.output_buffer.force_encoding(alt_encoding)
@av.with_output_buffer do
- assert alt_encoding, @av.output_buffer.encoding
+ assert_equal alt_encoding, @av.output_buffer.encoding
end
end
end
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 2234fbece9..d1e1338a17 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -139,6 +139,10 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal('<label for="post_title_great_title">The title goes here</label>', label("post", "title", "The title goes here", :value => "great title"))
end
+ def test_label_with_block
+ assert_dom_equal('<label for="post_title">The title, please:</label>', label(:post, :title) { "The title, please:" })
+ end
+
def test_text_field
assert_dom_equal(
'<input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />', text_field("post", "title")
@@ -419,6 +423,90 @@ class FormHelperTest < ActionView::TestCase
check_box("post", "secret", :id => "i mean it")
end
+ def test_nil_id
+ assert_dom_equal(
+ '<input name="post[title]" size="30" type="text" value="Hello World" />', text_field("post", "title", "id" => nil)
+ )
+ assert_dom_equal(
+ '<textarea cols="40" name="post[body]" rows="20">Back to the hill and over it again!</textarea>',
+ text_area("post", "body", "id" => nil)
+ )
+ assert_dom_equal(
+ '<input name="post[secret]" type="hidden" value="0" /><input checked="checked" name="post[secret]" type="checkbox" value="1" />',
+ check_box("post", "secret", "id" => nil)
+ )
+ assert_dom_equal(
+ '<input type="radio" name="post[secret]" value="0" />',
+ radio_button("post", "secret", "0", "id" => nil)
+ )
+ assert_dom_equal(
+ '<select name="post[secret]"></select>',
+ select("post", "secret", [], {}, "id" => nil)
+ )
+ assert_dom_equal text_field("post", "title", "id" => nil),
+ text_field("post", "title", :id => nil)
+ assert_dom_equal text_area("post", "body", "id" => nil),
+ text_area("post", "body", :id => nil)
+ assert_dom_equal check_box("post", "secret", "id" => nil),
+ check_box("post", "secret", :id => nil)
+ assert_dom_equal radio_button("post", "secret", "0", "id" => nil),
+ radio_button("post", "secret", "0", :id => nil)
+ end
+
+ def test_index
+ assert_dom_equal(
+ '<input name="post[5][title]" size="30" id="post_5_title" type="text" value="Hello World" />',
+ text_field("post", "title", "index" => 5)
+ )
+ assert_dom_equal(
+ '<textarea cols="40" name="post[5][body]" id="post_5_body" rows="20">Back to the hill and over it again!</textarea>',
+ text_area("post", "body", "index" => 5)
+ )
+ assert_dom_equal(
+ '<input name="post[5][secret]" type="hidden" value="0" /><input checked="checked" name="post[5][secret]" type="checkbox" value="1" id="post_5_secret" />',
+ check_box("post", "secret", "index" => 5)
+ )
+ assert_dom_equal(
+ text_field("post", "title", "index" => 5),
+ text_field("post", "title", "index" => 5)
+ )
+ assert_dom_equal(
+ text_area("post", "body", "index" => 5),
+ text_area("post", "body", "index" => 5)
+ )
+ assert_dom_equal(
+ check_box("post", "secret", "index" => 5),
+ check_box("post", "secret", "index" => 5)
+ )
+ end
+
+ def test_index_with_nil_id
+ assert_dom_equal(
+ '<input name="post[5][title]" size="30" type="text" value="Hello World" />',
+ text_field("post", "title", "index" => 5, 'id' => nil)
+ )
+ assert_dom_equal(
+ '<textarea cols="40" name="post[5][body]" rows="20">Back to the hill and over it again!</textarea>',
+ text_area("post", "body", "index" => 5, 'id' => nil)
+ )
+ assert_dom_equal(
+ '<input name="post[5][secret]" type="hidden" value="0" /><input checked="checked" name="post[5][secret]" type="checkbox" value="1" />',
+ check_box("post", "secret", "index" => 5, 'id' => nil)
+ )
+ assert_dom_equal(
+ text_field("post", "title", "index" => 5, 'id' => nil),
+ text_field("post", "title", :index => 5, :id => nil)
+ )
+ assert_dom_equal(
+ text_area("post", "body", "index" => 5, 'id' => nil),
+ text_area("post", "body", :index => 5, :id => nil)
+ )
+ assert_dom_equal(
+ check_box("post", "secret", "index" => 5, 'id' => nil),
+ check_box("post", "secret", :index => 5, :id => nil)
+ )
+ end
+
def test_auto_index
pid = @post.id
assert_dom_equal(
@@ -445,10 +533,33 @@ class FormHelperTest < ActionView::TestCase
)
end
+ def test_auto_index_with_nil_id
+ pid = @post.id
+ assert_dom_equal(
+ "<input name=\"post[#{pid}][title]\" size=\"30\" type=\"text\" value=\"Hello World\" />",
+ text_field("post[]","title", :id => nil)
+ )
+ assert_dom_equal(
+ "<textarea cols=\"40\" name=\"post[#{pid}][body]\" rows=\"20\">Back to the hill and over it again!</textarea>",
+ text_area("post[]", "body", :id => nil)
+ )
+ assert_dom_equal(
+ "<input name=\"post[#{pid}][secret]\" type=\"hidden\" value=\"0\" /><input checked=\"checked\" name=\"post[#{pid}][secret]\" type=\"checkbox\" value=\"1\" />",
+ check_box("post[]", "secret", :id => nil)
+ )
+ assert_dom_equal(
+"<input checked=\"checked\" name=\"post[#{pid}][title]\" type=\"radio\" value=\"Hello World\" />",
+ radio_button("post[]", "title", "Hello World", :id => nil)
+ )
+ assert_dom_equal("<input name=\"post[#{pid}][title]\" type=\"radio\" value=\"Goodbye World\" />",
+ radio_button("post[]", "title", "Goodbye World", :id => nil)
+ )
+ end
+
def test_form_for
assert_deprecated do
form_for(:post, @post, :html => { :id => 'create-post' }) do |f|
- concat f.label(:title)
+ concat f.label(:title) { "The Title" }
concat f.text_field(:title)
concat f.text_area(:body)
concat f.check_box(:secret)
@@ -458,7 +569,7 @@ class FormHelperTest < ActionView::TestCase
expected =
"<form action='http://www.example.com' id='create-post' method='post'>" +
- "<label for='post_title'>Title</label>" +
+ "<label for='post_title'>The Title</label>" +
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
@@ -485,7 +596,7 @@ class FormHelperTest < ActionView::TestCase
"<input name='other_name[title]' size='30' id='other_name_title' value='Hello World' type='text' />" +
"<textarea name='other_name[body]' id='other_name_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='other_name[secret]' value='0' type='hidden' />" +
- "<input name='other_name[secret]' checked='checked' id='other_name_secret' value='1' type='checkbox' />" +
+ "<input name='other_name[secret]' checked='checked' id='other_name_secret' value='1' type='checkbox' />" +
"<input name='commit' id='other_name_submit' value='Create post' type='submit' /></form>"
assert_dom_equal expected, output_buffer
diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb
index 98503c32fd..19b73aa810 100644
--- a/actionpack/test/template/form_options_helper_test.rb
+++ b/actionpack/test/template/form_options_helper_test.rb
@@ -767,6 +767,62 @@ class FormOptionsHelperTest < ActionView::TestCase
html
end
+ def test_options_for_select_with_element_attributes
+ assert_dom_equal(
+ "<option value=\"&lt;Denmark&gt;\" class=\"bold\">&lt;Denmark&gt;</option>\n<option value=\"USA\" onclick=\"alert('Hello World');\">USA</option>\n<option value=\"Sweden\">Sweden</option>\n<option value=\"Germany\">Germany</option>",
+ options_for_select([ [ "<Denmark>", { :class => 'bold' } ], [ "USA", { :onclick => "alert('Hello World');" } ], [ "Sweden" ], "Germany" ])
+ )
+ end
+
+ def test_options_for_select_with_element_attributes_and_selection
+ assert_dom_equal(
+ "<option value=\"&lt;Denmark&gt;\">&lt;Denmark&gt;</option>\n<option value=\"USA\" class=\"bold\" selected=\"selected\">USA</option>\n<option value=\"Sweden\">Sweden</option>",
+ options_for_select([ "<Denmark>", [ "USA", { :class => 'bold' } ], "Sweden" ], "USA")
+ )
+ end
+
+ def test_options_for_select_with_element_attributes_and_selection_array
+ assert_dom_equal(
+ "<option value=\"&lt;Denmark&gt;\">&lt;Denmark&gt;</option>\n<option value=\"USA\" class=\"bold\" selected=\"selected\">USA</option>\n<option value=\"Sweden\" selected=\"selected\">Sweden</option>",
+ options_for_select([ "<Denmark>", [ "USA", { :class => 'bold' } ], "Sweden" ], [ "USA", "Sweden" ])
+ )
+ end
+
+ def test_option_html_attributes_from_without_hash
+ assert_dom_equal(
+ "",
+ option_html_attributes([ 'foo', 'bar' ])
+ )
+ end
+
+ def test_option_html_attributes_with_single_element_hash
+ assert_dom_equal(
+ " class=\"fancy\"",
+ option_html_attributes([ 'foo', 'bar', { :class => 'fancy' } ])
+ )
+ end
+
+ def test_option_html_attributes_with_multiple_element_hash
+ assert_dom_equal(
+ " class=\"fancy\" onclick=\"alert('Hello World');\"",
+ option_html_attributes([ 'foo', 'bar', { :class => 'fancy', 'onclick' => "alert('Hello World');" } ])
+ )
+ end
+
+ def test_option_html_attributes_with_multiple_hashes
+ assert_dom_equal(
+ " class=\"fancy\" onclick=\"alert('Hello World');\"",
+ option_html_attributes([ 'foo', 'bar', { :class => 'fancy' }, { 'onclick' => "alert('Hello World');" } ])
+ )
+ end
+
+ def test_option_html_attributes_with_special_characters
+ assert_dom_equal(
+ " onclick=\"alert(&quot;&lt;code&gt;&quot;)\"",
+ option_html_attributes([ 'foo', 'bar', { :onclick => %(alert("<code>")) } ])
+ )
+ end
+
def test_grouped_collection_select
@continents = [
Continent.new("<Africa>", [Country.new("<sa>", "<South Africa>"), Country.new("so", "Somalia")] ),
diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb
index abb0e1df93..1c095b621e 100644
--- a/actionpack/test/template/form_tag_helper_test.rb
+++ b/actionpack/test/template/form_tag_helper_test.rb
@@ -288,6 +288,20 @@ class FormTagHelperTest < ActionView::TestCase
assert_match VALID_HTML_ID, label_elem['for']
end
+ def test_label_tag_with_block
+ assert_dom_equal('<label>Blocked</label>', label_tag { "Blocked" })
+ end
+
+ def test_label_tag_with_block_and_argument
+ output = label_tag("clock") { "Grandfather" }
+ assert_dom_equal('<label for="clock">Grandfather</label>', output)
+ end
+
+ def test_label_tag_with_block_and_argument_and_options
+ output = label_tag("clock", :id => "label_clock") { "Grandfather" }
+ assert_dom_equal('<label for="clock" id="label_clock">Grandfather</label>', output)
+ end
+
def test_boolean_options
assert_dom_equal %(<input checked="checked" disabled="disabled" id="admin" name="admin" readonly="readonly" type="checkbox" value="1" />), check_box_tag("admin", 1, true, 'disabled' => true, :readonly => "yes")
assert_dom_equal %(<input checked="checked" id="admin" name="admin" type="checkbox" value="1" />), check_box_tag("admin", 1, true, :disabled => false, :readonly => nil)
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index c9a50da418..d0212024ae 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -111,6 +111,7 @@ module RenderTestCases
assert_match %r!method.*doesnt_exist!, e.message
assert_equal "", e.sub_template_message
assert_equal "1", e.line_number
+ assert_equal "1: <%= doesnt_exist %>", e.annoted_source_code.strip
assert_equal File.expand_path("#{FIXTURE_LOAD_PATH}/test/_raise.html.erb"), e.file_name
end