mirror of https://github.com/rails/rails
modernizes hash syntax in actionview
This commit is contained in:
parent
5b6eb1d58b
commit
63fff600ac
|
@ -1,14 +1,14 @@
|
|||
require "rake/testtask"
|
||||
|
||||
desc "Default Task"
|
||||
task :default => :test
|
||||
task default: :test
|
||||
|
||||
task :package
|
||||
|
||||
# Run the unit tests
|
||||
|
||||
desc "Run all unit tests"
|
||||
task :test => ["test:template", "test:integration:action_pack", "test:integration:active_record"]
|
||||
task test: ["test:template", "test:integration:action_pack", "test:integration:active_record"]
|
||||
|
||||
namespace :test do
|
||||
task :isolated do
|
||||
|
|
|
@ -169,7 +169,7 @@ module ActionView #:nodoc:
|
|||
class_attribute :logger
|
||||
|
||||
class << self
|
||||
delegate :erb_trim_mode=, :to => "ActionView::Template::Handlers::ERB"
|
||||
delegate :erb_trim_mode=, to: "ActionView::Template::Handlers::ERB"
|
||||
|
||||
def cache_template_loading
|
||||
ActionView::Resolver.caching?
|
||||
|
@ -187,8 +187,8 @@ module ActionView #:nodoc:
|
|||
attr_accessor :view_renderer
|
||||
attr_internal :config, :assigns
|
||||
|
||||
delegate :lookup_context, :to => :view_renderer
|
||||
delegate :formats, :formats=, :locale, :locale=, :view_paths, :view_paths=, :to => :lookup_context
|
||||
delegate :lookup_context, to: :view_renderer
|
||||
delegate :formats, :formats=, :locale, :locale=, :view_paths, :view_paths=, to: :lookup_context
|
||||
|
||||
def assign(new_assigns) # :nodoc:
|
||||
@_assigns = new_assigns.each { |key, value| instance_variable_set("@#{key}", value) }
|
||||
|
|
|
@ -139,7 +139,7 @@ module ActionView
|
|||
"rel" => tag_options[:rel] || "alternate",
|
||||
"type" => tag_options[:type] || Template::Types[type].to_s,
|
||||
"title" => tag_options[:title] || type.to_s.upcase,
|
||||
"href" => url_options.is_a?(Hash) ? url_for(url_options.merge(:only_path => false)) : url_options
|
||||
"href" => url_options.is_a?(Hash) ? url_for(url_options.merge(only_path: false)) : url_options
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -172,9 +172,9 @@ module ActionView
|
|||
# # => <link href="/assets/mb-icon.png" rel="apple-touch-icon" type="image/png" />
|
||||
def favicon_link_tag(source="favicon.ico", options={})
|
||||
tag("link", {
|
||||
:rel => "shortcut icon",
|
||||
:type => "image/x-icon",
|
||||
:href => path_to_image(source)
|
||||
rel: "shortcut icon",
|
||||
type: "image/x-icon",
|
||||
href: path_to_image(source)
|
||||
}.merge!(options.symbolize_keys))
|
||||
end
|
||||
|
||||
|
@ -313,7 +313,7 @@ module ActionView
|
|||
|
||||
if sources.size > 1
|
||||
content_tag(type, options) do
|
||||
safe_join sources.map { |source| tag("source", :src => send("path_to_#{type}", source)) }
|
||||
safe_join sources.map { |source| tag("source", src: send("path_to_#{type}", source)) }
|
||||
end
|
||||
else
|
||||
options[:src] = send("path_to_#{type}", sources.first)
|
||||
|
|
|
@ -169,7 +169,7 @@ module ActionView
|
|||
# asset_url "application.js", host: "http://cdn.example.com" # => http://cdn.example.com/assets/application.js
|
||||
#
|
||||
def asset_url(source, options = {})
|
||||
path_to_asset(source, options.merge(:protocol => :request))
|
||||
path_to_asset(source, options.merge(protocol: :request))
|
||||
end
|
||||
alias_method :url_to_asset, :asset_url # aliased to avoid conflicts with an asset_url named route
|
||||
|
||||
|
|
|
@ -117,8 +117,8 @@ module ActionView
|
|||
|
||||
xml.feed(feed_opts) do
|
||||
xml.id(options[:id] || "tag:#{request.host},#{options[:schema_date]}:#{request.fullpath.split(".")[0]}")
|
||||
xml.link(:rel => "alternate", :type => "text/html", :href => options[:root_url] || (request.protocol + request.host_with_port))
|
||||
xml.link(:rel => "self", :type => "application/atom+xml", :href => options[:url] || request.url)
|
||||
xml.link(rel: "alternate", type: "text/html", href: options[:root_url] || (request.protocol + request.host_with_port))
|
||||
xml.link(rel: "self", type: "application/atom+xml", href: options[:url] || request.url)
|
||||
|
||||
yield AtomFeedBuilder.new(xml, self, options)
|
||||
end
|
||||
|
@ -138,7 +138,7 @@ module ActionView
|
|||
def method_missing(method, *arguments, &block)
|
||||
if xhtml_block?(method, arguments)
|
||||
@xml.__send__(method, *arguments) do
|
||||
@xml.div(:xmlns => "http://www.w3.org/1999/xhtml") do |xhtml|
|
||||
@xml.div(xmlns: "http://www.w3.org/1999/xhtml") do |xhtml|
|
||||
block.call(xhtml)
|
||||
end
|
||||
end
|
||||
|
@ -192,7 +192,7 @@ module ActionView
|
|||
type = options.fetch(:type, "text/html")
|
||||
|
||||
url = options.fetch(:url) { @view.polymorphic_url(record) }
|
||||
@xml.link(:rel => "alternate", :type => type, :href => url) if url
|
||||
@xml.link(rel: "alternate", type: type, href: url) if url
|
||||
|
||||
yield AtomBuilder.new(@xml)
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ module ActionView
|
|||
attr_internal :controller, :request
|
||||
|
||||
delegate :request_forgery_protection_token, :params, :session, :cookies, :response, :headers,
|
||||
:flash, :action_name, :controller_name, :controller_path, :to => :controller
|
||||
:flash, :action_name, :controller_name, :controller_path, to: :controller
|
||||
|
||||
def assign_controller(controller)
|
||||
if @_controller = controller
|
||||
|
|
|
@ -20,8 +20,8 @@ module ActionView
|
|||
def csrf_meta_tags
|
||||
if protect_against_forgery?
|
||||
[
|
||||
tag("meta", :name => "csrf-param", :content => request_forgery_protection_token),
|
||||
tag("meta", :name => "csrf-token", :content => form_authenticity_token)
|
||||
tag("meta", name: "csrf-param", content: request_forgery_protection_token),
|
||||
tag("meta", name: "csrf-token", content: form_authenticity_token)
|
||||
].join("\n").html_safe
|
||||
end
|
||||
end
|
||||
|
|
|
@ -101,34 +101,34 @@ module ActionView
|
|||
distance_in_minutes = ((to_time - from_time)/60.0).round
|
||||
distance_in_seconds = (to_time - from_time).round
|
||||
|
||||
I18n.with_options :locale => options[:locale], :scope => options[:scope] do |locale|
|
||||
I18n.with_options locale: options[:locale], scope: options[:scope] do |locale|
|
||||
case distance_in_minutes
|
||||
when 0..1
|
||||
return distance_in_minutes == 0 ?
|
||||
locale.t(:less_than_x_minutes, :count => 1) :
|
||||
locale.t(:x_minutes, :count => distance_in_minutes) unless options[:include_seconds]
|
||||
locale.t(:less_than_x_minutes, count: 1) :
|
||||
locale.t(:x_minutes, count: distance_in_minutes) unless options[:include_seconds]
|
||||
|
||||
case distance_in_seconds
|
||||
when 0..4 then locale.t :less_than_x_seconds, :count => 5
|
||||
when 5..9 then locale.t :less_than_x_seconds, :count => 10
|
||||
when 10..19 then locale.t :less_than_x_seconds, :count => 20
|
||||
when 0..4 then locale.t :less_than_x_seconds, count: 5
|
||||
when 5..9 then locale.t :less_than_x_seconds, count: 10
|
||||
when 10..19 then locale.t :less_than_x_seconds, count: 20
|
||||
when 20..39 then locale.t :half_a_minute
|
||||
when 40..59 then locale.t :less_than_x_minutes, :count => 1
|
||||
else locale.t :x_minutes, :count => 1
|
||||
when 40..59 then locale.t :less_than_x_minutes, count: 1
|
||||
else locale.t :x_minutes, count: 1
|
||||
end
|
||||
|
||||
when 2...45 then locale.t :x_minutes, :count => distance_in_minutes
|
||||
when 45...90 then locale.t :about_x_hours, :count => 1
|
||||
when 2...45 then locale.t :x_minutes, count: distance_in_minutes
|
||||
when 45...90 then locale.t :about_x_hours, count: 1
|
||||
# 90 mins up to 24 hours
|
||||
when 90...1440 then locale.t :about_x_hours, :count => (distance_in_minutes.to_f / 60.0).round
|
||||
when 90...1440 then locale.t :about_x_hours, count: (distance_in_minutes.to_f / 60.0).round
|
||||
# 24 hours up to 42 hours
|
||||
when 1440...2520 then locale.t :x_days, :count => 1
|
||||
when 1440...2520 then locale.t :x_days, count: 1
|
||||
# 42 hours up to 30 days
|
||||
when 2520...43200 then locale.t :x_days, :count => (distance_in_minutes.to_f / 1440.0).round
|
||||
when 2520...43200 then locale.t :x_days, count: (distance_in_minutes.to_f / 1440.0).round
|
||||
# 30 days up to 60 days
|
||||
when 43200...86400 then locale.t :about_x_months, :count => (distance_in_minutes.to_f / 43200.0).round
|
||||
when 43200...86400 then locale.t :about_x_months, count: (distance_in_minutes.to_f / 43200.0).round
|
||||
# 60 days up to 365 days
|
||||
when 86400...525600 then locale.t :x_months, :count => (distance_in_minutes.to_f / 43200.0).round
|
||||
when 86400...525600 then locale.t :x_months, count: (distance_in_minutes.to_f / 43200.0).round
|
||||
else
|
||||
if from_time.acts_like?(:time) && to_time.acts_like?(:time)
|
||||
fyear = from_time.year
|
||||
|
@ -149,11 +149,11 @@ module ActionView
|
|||
remainder = (minutes_with_offset % MINUTES_IN_YEAR)
|
||||
distance_in_years = (minutes_with_offset.div MINUTES_IN_YEAR)
|
||||
if remainder < MINUTES_IN_QUARTER_YEAR
|
||||
locale.t(:about_x_years, :count => distance_in_years)
|
||||
locale.t(:about_x_years, count: distance_in_years)
|
||||
elsif remainder < MINUTES_IN_THREE_QUARTERS_YEAR
|
||||
locale.t(:over_x_years, :count => distance_in_years)
|
||||
locale.t(:over_x_years, count: distance_in_years)
|
||||
else
|
||||
locale.t(:almost_x_years, :count => distance_in_years + 1)
|
||||
locale.t(:almost_x_years, count: distance_in_years + 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -682,10 +682,10 @@ module ActionView
|
|||
def time_tag(date_or_time, *args, &block)
|
||||
options = args.extract_options!
|
||||
format = options.delete(:format) || :long
|
||||
content = args.first || I18n.l(date_or_time, :format => format)
|
||||
content = args.first || I18n.l(date_or_time, format: format)
|
||||
datetime = date_or_time.acts_like?(:time) ? date_or_time.xmlschema : date_or_time.iso8601
|
||||
|
||||
content_tag("time".freeze, content, options.reverse_merge(:datetime => datetime), &block)
|
||||
content_tag("time".freeze, content, options.reverse_merge(datetime: datetime), &block)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -694,7 +694,7 @@ module ActionView
|
|||
|
||||
DEFAULT_PREFIX = "date".freeze
|
||||
POSITION = {
|
||||
:year => 1, :month => 2, :day => 3, :hour => 4, :minute => 5, :second => 6
|
||||
year: 1, month: 2, day: 3, hour: 4, minute: 5, second: 6
|
||||
}.freeze
|
||||
|
||||
AMPM_TRANSLATION = Hash[
|
||||
|
@ -781,7 +781,7 @@ module ActionView
|
|||
if @options[:use_hidden] || @options[:discard_minute]
|
||||
build_hidden(:minute, min)
|
||||
else
|
||||
build_options_and_select(:minute, min, :step => @options[:minute_step])
|
||||
build_options_and_select(:minute, min, step: @options[:minute_step])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -801,7 +801,7 @@ module ActionView
|
|||
if @options[:use_hidden] || @options[:discard_day]
|
||||
build_hidden(:day, day || 1)
|
||||
else
|
||||
build_options_and_select(:day, day, :start => 1, :end => 31, :leading_zeros => false, :use_two_digit_numbers => @options[:use_two_digit_numbers])
|
||||
build_options_and_select(:day, day, start: 1, end: 31, leading_zeros: false, use_two_digit_numbers: @options[:use_two_digit_numbers])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -811,7 +811,7 @@ module ActionView
|
|||
else
|
||||
month_options = []
|
||||
1.upto(12) do |month_number|
|
||||
options = { :value => month_number }
|
||||
options = { value: month_number }
|
||||
options[:selected] = "selected" if month == month_number
|
||||
month_options << content_tag("option".freeze, month_name(month_number), options) + "\n"
|
||||
end
|
||||
|
@ -861,7 +861,7 @@ module ActionView
|
|||
# valid. Otherwise, February 31st or February 29th, 2011 can be selected, which are invalid.
|
||||
def set_day_if_discarded
|
||||
if @datetime && @options[:discard_day]
|
||||
@datetime = @datetime.change(:day => 1)
|
||||
@datetime = @datetime.change(day: 1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -886,7 +886,7 @@ module ActionView
|
|||
# "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
|
||||
def translated_month_names
|
||||
key = @options[:use_short_month] ? :'date.abbr_month_names' : :'date.month_names'
|
||||
I18n.translate(key, :locale => @options[:locale])
|
||||
I18n.translate(key, locale: @options[:locale])
|
||||
end
|
||||
|
||||
# Looks up month names by number (1-based):
|
||||
|
@ -929,7 +929,7 @@ module ActionView
|
|||
end
|
||||
|
||||
def translated_date_order
|
||||
date_order = I18n.translate(:'date.order', :locale => @options[:locale], :default => [])
|
||||
date_order = I18n.translate(:'date.order', locale: @options[:locale], default: [])
|
||||
date_order = date_order.map(&:to_sym)
|
||||
|
||||
forbidden_elements = date_order - [:year, :month, :day]
|
||||
|
@ -976,7 +976,7 @@ module ActionView
|
|||
select_options = []
|
||||
start.step(stop, step) do |i|
|
||||
value = leading_zeros ? sprintf("%02d", i) : i
|
||||
tag_options = { :value => value }
|
||||
tag_options = { value: value }
|
||||
tag_options[:selected] = "selected" if selected == i
|
||||
text = options[:use_two_digit_numbers] ? sprintf("%02d", i) : value
|
||||
text = options[:ampm] ? AMPM_TRANSLATION[i] : text
|
||||
|
@ -993,14 +993,14 @@ module ActionView
|
|||
# </select>"
|
||||
def build_select(type, select_options_as_html)
|
||||
select_options = {
|
||||
:id => input_id_from_type(type),
|
||||
:name => input_name_from_type(type)
|
||||
id: input_id_from_type(type),
|
||||
name: input_name_from_type(type)
|
||||
}.merge!(@html_options)
|
||||
select_options[:disabled] = "disabled" if @options[:disabled]
|
||||
select_options[:class] = css_class_attribute(type, select_options[:class], @options[:with_css_classes]) if @options[:with_css_classes]
|
||||
|
||||
select_html = "\n"
|
||||
select_html << content_tag("option".freeze, "", :value => "") + "\n" if @options[:include_blank]
|
||||
select_html << content_tag("option".freeze, "", value: "") + "\n" if @options[:include_blank]
|
||||
select_html << prompt_option_tag(type, @options[:prompt]) + "\n" if @options[:prompt]
|
||||
select_html << select_options_as_html
|
||||
|
||||
|
@ -1027,15 +1027,15 @@ module ActionView
|
|||
def prompt_option_tag(type, options)
|
||||
prompt = case options
|
||||
when Hash
|
||||
default_options = {:year => false, :month => false, :day => false, :hour => false, :minute => false, :second => false}
|
||||
default_options = {year: false, month: false, day: false, hour: false, minute: false, second: false}
|
||||
default_options.merge!(options)[type.to_sym]
|
||||
when String
|
||||
options
|
||||
else
|
||||
I18n.translate(:"datetime.prompts.#{type}", :locale => @options[:locale])
|
||||
I18n.translate(:"datetime.prompts.#{type}", locale: @options[:locale])
|
||||
end
|
||||
|
||||
prompt ? content_tag("option".freeze, prompt, :value => "") : ""
|
||||
prompt ? content_tag("option".freeze, prompt, value: "") : ""
|
||||
end
|
||||
|
||||
# Builds hidden input tag for date part and value.
|
||||
|
@ -1043,10 +1043,10 @@ module ActionView
|
|||
# => "<input id="post_written_on_1i" name="post[written_on(1i)]" type="hidden" value="2008" />"
|
||||
def build_hidden(type, value)
|
||||
select_options = {
|
||||
:type => "hidden",
|
||||
:id => input_id_from_type(type),
|
||||
:name => input_name_from_type(type),
|
||||
:value => value
|
||||
type: "hidden",
|
||||
id: input_id_from_type(type),
|
||||
name: input_name_from_type(type),
|
||||
value: value
|
||||
}.merge!(@html_options.slice(:disabled))
|
||||
select_options[:disabled] = "disabled" if @options[:disabled]
|
||||
|
||||
|
|
|
@ -25,10 +25,10 @@ module ActionView
|
|||
def debug(object)
|
||||
Marshal::dump(object)
|
||||
object = ERB::Util.html_escape(object.to_yaml)
|
||||
content_tag(:pre, object, :class => "debug_dump")
|
||||
content_tag(:pre, object, class: "debug_dump")
|
||||
rescue # errors from Marshal or YAML
|
||||
# Object couldn't be dumped, perhaps because of singleton methods -- this is the fallback
|
||||
content_tag(:code, object.inspect, :class => "debug_dump")
|
||||
content_tag(:code, object.inspect, class: "debug_dump")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -42,9 +42,9 @@ module ActionView #:nodoc:
|
|||
options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector, :locale)
|
||||
|
||||
default_connectors = {
|
||||
:words_connector => ", ",
|
||||
:two_words_connector => " and ",
|
||||
:last_word_connector => ", and "
|
||||
words_connector: ", ",
|
||||
two_words_connector: " and ",
|
||||
last_word_connector: ", and "
|
||||
}
|
||||
if defined?(I18n)
|
||||
i18n_connectors = I18n.translate(:'support.array', locale: options[:locale], default: {})
|
||||
|
|
|
@ -27,12 +27,12 @@ module ActionView
|
|||
case options
|
||||
when Hash
|
||||
if block_given?
|
||||
view_renderer.render_partial(self, options.merge(:partial => options[:layout]), &block)
|
||||
view_renderer.render_partial(self, options.merge(partial: options[:layout]), &block)
|
||||
else
|
||||
view_renderer.render(self, options)
|
||||
end
|
||||
else
|
||||
view_renderer.render_partial(self, :partial => options, :locals => locals, &block)
|
||||
view_renderer.render_partial(self, partial: options, locals: locals, &block)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ module ActionView
|
|||
select = content_tag("select", add_options(option_tags, options, value), html_options)
|
||||
|
||||
if html_options["multiple"] && options.fetch(:include_hidden, true)
|
||||
tag("input", :disabled => html_options["disabled"], :name => html_options["name"], :type => "hidden", :value => "") + select
|
||||
tag("input", disabled: html_options["disabled"], name: html_options["name"], type: "hidden", value: "") + select
|
||||
else
|
||||
select
|
||||
end
|
||||
|
@ -143,10 +143,10 @@ module ActionView
|
|||
|
||||
def add_options(option_tags, options, value = nil)
|
||||
if options[:include_blank]
|
||||
option_tags = tag_builder.content_tag_string("option", options[:include_blank].kind_of?(String) ? options[:include_blank] : nil, :value => "") + "\n" + option_tags
|
||||
option_tags = tag_builder.content_tag_string("option", options[:include_blank].kind_of?(String) ? options[:include_blank] : nil, value: "") + "\n" + option_tags
|
||||
end
|
||||
if value.blank? && options[:prompt]
|
||||
option_tags = tag_builder.content_tag_string("option", prompt_text(options[:prompt]), :value => "") + "\n" + option_tags
|
||||
option_tags = tag_builder.content_tag_string("option", prompt_text(options[:prompt]), value: "") + "\n" + option_tags
|
||||
end
|
||||
option_tags
|
||||
end
|
||||
|
|
|
@ -13,8 +13,8 @@ module ActionView
|
|||
|
||||
def render
|
||||
option_tags_options = {
|
||||
:selected => @options.fetch(:selected) { value(@object) },
|
||||
:disabled => @options[:disabled]
|
||||
selected: @options.fetch(:selected) { value(@object) },
|
||||
disabled: @options[:disabled]
|
||||
}
|
||||
|
||||
select_content_tag(
|
||||
|
|
|
@ -15,8 +15,8 @@ module ActionView
|
|||
|
||||
def render
|
||||
option_tags_options = {
|
||||
:selected => @options.fetch(:selected) { value(@object) },
|
||||
:disabled => @options[:disabled]
|
||||
selected: @options.fetch(:selected) { value(@object) },
|
||||
disabled: @options[:disabled]
|
||||
}
|
||||
|
||||
select_content_tag(
|
||||
|
|
|
@ -3,7 +3,7 @@ module ActionView
|
|||
module Tags # :nodoc:
|
||||
class PasswordField < TextField # :nodoc:
|
||||
def render
|
||||
@options = {:value => nil}.merge!(@options)
|
||||
@options = {value: nil}.merge!(@options)
|
||||
super
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,8 +13,8 @@ module ActionView
|
|||
|
||||
def render
|
||||
option_tags_options = {
|
||||
:selected => @options.fetch(:selected) { value(@object) },
|
||||
:disabled => @options[:disabled]
|
||||
selected: @options.fetch(:selected) { value(@object) },
|
||||
disabled: @options[:disabled]
|
||||
}
|
||||
|
||||
option_tags = if grouped_choices?
|
||||
|
|
|
@ -205,7 +205,7 @@ module ActionView
|
|||
include ActionView::Rendering
|
||||
|
||||
included do
|
||||
class_attribute :_layout, :_layout_conditions, :instance_accessor => false
|
||||
class_attribute :_layout, :_layout_conditions, instance_accessor: false
|
||||
self._layout = nil
|
||||
self._layout_conditions = {}
|
||||
_write_layout_method
|
||||
|
|
|
@ -15,7 +15,7 @@ module ActionView
|
|||
# that new object is called in turn. This abstracts the setup and rendering
|
||||
# into a separate classes for partials and templates.
|
||||
class AbstractRenderer #:nodoc:
|
||||
delegate :find_template, :find_file, :template_exists?, :any_templates?, :with_fallbacks, :with_layout_format, :formats, :to => :@lookup_context
|
||||
delegate :find_template, :find_file, :template_exists?, :any_templates?, :with_fallbacks, :with_layout_format, :formats, to: :@lookup_context
|
||||
|
||||
def initialize(lookup_context)
|
||||
@lookup_context = lookup_context
|
||||
|
|
|
@ -64,7 +64,7 @@ module ActionView
|
|||
output = ActionView::StreamingBuffer.new(buffer)
|
||||
yielder = lambda { |*name| view._layout_for(*name) }
|
||||
|
||||
instrument(:template, :identifier => template.identifier, :layout => layout.try(:virtual_path)) do
|
||||
instrument(:template, identifier: template.identifier, layout: layout.try(:virtual_path)) do
|
||||
fiber = Fiber.new do
|
||||
if layout
|
||||
layout.render(view, locals, output, &yielder)
|
||||
|
|
|
@ -32,7 +32,7 @@ module ActionView
|
|||
with_fallbacks { find_file(options[:file], nil, false, keys, @details) }
|
||||
elsif options.key?(:inline)
|
||||
handler = Template.handler_for_extension(options[:type] || "erb")
|
||||
Template.new(options[:inline], "inline template", handler, :locals => keys)
|
||||
Template.new(options[:inline], "inline template", handler, locals: keys)
|
||||
elsif options.key?(:template)
|
||||
if options[:template].respond_to?(:render)
|
||||
options[:template]
|
||||
|
@ -50,7 +50,7 @@ module ActionView
|
|||
view, locals = @view, locals || {}
|
||||
|
||||
render_with_layout(layout_name, locals) do |layout|
|
||||
instrument(:template, :identifier => template.identifier, :layout => layout.try(:virtual_path)) do
|
||||
instrument(:template, identifier: template.identifier, layout: layout.try(:virtual_path)) do
|
||||
template.render(view, locals) { |*name| view._layout_for(*name) }
|
||||
end
|
||||
end
|
||||
|
@ -89,7 +89,7 @@ module ActionView
|
|||
find_template(layout, nil, false, [], details)
|
||||
end
|
||||
rescue ActionView::MissingTemplate
|
||||
all_details = @details.merge(:formats => @lookup_context.default_formats)
|
||||
all_details = @details.merge(formats: @lookup_context.default_formats)
|
||||
raise unless template_exists?(layout, nil, false, [], all_details)
|
||||
end
|
||||
when Proc
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
namespace :cache_digests do
|
||||
desc "Lookup nested dependencies for TEMPLATE (like messages/show or comments/_comment.html)"
|
||||
task :nested_dependencies => :environment do
|
||||
task nested_dependencies: :environment do
|
||||
abort "You must provide TEMPLATE for the task to run" unless ENV["TEMPLATE"].present?
|
||||
puts JSON.pretty_generate ActionView::Digestor.tree(CacheDigests.template_name, CacheDigests.finder).children.map(&:to_dep_map)
|
||||
end
|
||||
|
||||
desc "Lookup first-level dependencies for TEMPLATE (like messages/show or comments/_comment.html)"
|
||||
task :dependencies => :environment do
|
||||
task dependencies: :environment do
|
||||
abort "You must provide TEMPLATE for the task to run" unless ENV["TEMPLATE"].present?
|
||||
puts JSON.pretty_generate ActionView::Digestor.tree(CacheDigests.template_name, CacheDigests.finder).children.map(&:name)
|
||||
end
|
||||
|
|
|
@ -119,8 +119,8 @@ module ActionView
|
|||
|
||||
self.class.erb_implementation.new(
|
||||
erb,
|
||||
:escape => (self.class.escape_whitelist.include? template.type),
|
||||
:trim => (self.class.erb_trim_mode == "-")
|
||||
escape: (self.class.escape_whitelist.include? template.type),
|
||||
trim: (self.class.erb_trim_mode == "-")
|
||||
).src
|
||||
end
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ module ActionView
|
|||
class Cache #:nodoc:
|
||||
class SmallCache < Concurrent::Map
|
||||
def initialize(options = {})
|
||||
super(options.merge(:initial_capacity => 2))
|
||||
super(options.merge(initial_capacity: 2))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -204,7 +204,7 @@ module ActionView
|
|||
|
||||
# An abstract class that implements a Resolver with path semantics.
|
||||
class PathResolver < Resolver #:nodoc:
|
||||
EXTENSIONS = { :locale => ".", :formats => ".", :variants => "+", :handlers => "." }
|
||||
EXTENSIONS = { locale: ".", formats: ".", variants: "+", handlers: "." }
|
||||
DEFAULT_PATTERN = ":prefix/:action{.:locale,}{.:formats,}{+:variants,}{.:handlers,}"
|
||||
|
||||
def initialize(pattern=nil)
|
||||
|
@ -230,10 +230,10 @@ module ActionView
|
|||
contents = File.binread(template)
|
||||
|
||||
Template.new(contents, File.expand_path(template), handler,
|
||||
:virtual_path => path.virtual,
|
||||
:format => format,
|
||||
:variant => variant,
|
||||
:updated_at => mtime(template)
|
||||
virtual_path: path.virtual,
|
||||
format: format,
|
||||
variant: variant,
|
||||
updated_at: mtime(template)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -49,7 +49,7 @@ module ActionView
|
|||
|
||||
include ActiveSupport::Testing::ConstantLookup
|
||||
|
||||
delegate :lookup_context, :to => :controller
|
||||
delegate :lookup_context, to: :controller
|
||||
attr_accessor :controller, :output_buffer, :rendered
|
||||
|
||||
module ClassMethods
|
||||
|
|
|
@ -33,10 +33,10 @@ module ActionView #:nodoc:
|
|||
next unless query.match?(_path)
|
||||
handler, format, variant = extract_handler_and_format_and_variant(_path, formats)
|
||||
templates << Template.new(source, _path, handler,
|
||||
:virtual_path => path.virtual,
|
||||
:format => format,
|
||||
:variant => variant,
|
||||
:updated_at => updated_at
|
||||
virtual_path: path.virtual,
|
||||
format: format,
|
||||
variant: variant,
|
||||
updated_at: updated_at
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -47,7 +47,7 @@ module ActionView #:nodoc:
|
|||
class NullResolver < PathResolver
|
||||
def query(path, exts, formats, _)
|
||||
handler, format, variant = extract_handler_and_format_and_variant(path, formats)
|
||||
[ActionView::Template.new("Template generated by Null Resolver", path.virtual, handler, :virtual_path => path.virtual, :format => format, :variant => variant)]
|
||||
[ActionView::Template.new("Template generated by Null Resolver", path.virtual, handler, virtual_path: path.virtual, format: format, variant: variant)]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ module ActionView
|
|||
end
|
||||
|
||||
delegate :template_exists?, :any_templates?, :view_paths, :formats, :formats=,
|
||||
:locale, :locale=, :to => :lookup_context
|
||||
:locale, :locale=, to: :lookup_context
|
||||
|
||||
module ClassMethods
|
||||
def _prefixes # :nodoc:
|
||||
|
|
|
@ -137,7 +137,7 @@ class BasicController
|
|||
config.assets_dir = public_dir
|
||||
config.javascripts_dir = "#{public_dir}/javascripts"
|
||||
config.stylesheets_dir = "#{public_dir}/stylesheets"
|
||||
config.assets = ActiveSupport::InheritableOptions.new({ :prefix => "assets" })
|
||||
config.assets = ActiveSupport::InheritableOptions.new({ prefix: "assets" })
|
||||
config
|
||||
end
|
||||
end
|
||||
|
|
|
@ -38,7 +38,7 @@ module AbstractController
|
|||
|
||||
def render(options = {})
|
||||
if options.is_a?(String)
|
||||
options = {:_template_name => options}
|
||||
options = {_template_name: options}
|
||||
end
|
||||
super
|
||||
end
|
||||
|
@ -65,11 +65,11 @@ module AbstractController
|
|||
end
|
||||
|
||||
def rendering_to_body
|
||||
self.response_body = render_to_body :template => "naked_render"
|
||||
self.response_body = render_to_body template: "naked_render"
|
||||
end
|
||||
|
||||
def rendering_to_string
|
||||
self.response_body = render_to_string :template => "naked_render"
|
||||
self.response_body = render_to_string template: "naked_render"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -190,10 +190,10 @@ module AbstractController
|
|||
|
||||
private
|
||||
def self.layout(formats)
|
||||
find_template(name.underscore, {:formats => formats}, :_prefixes => ["layouts"])
|
||||
find_template(name.underscore, {formats: formats}, _prefixes: ["layouts"])
|
||||
rescue ActionView::MissingTemplate
|
||||
begin
|
||||
find_template("application", {:formats => formats}, :_prefixes => ["layouts"])
|
||||
find_template("application", {formats: formats}, _prefixes: ["layouts"])
|
||||
rescue ActionView::MissingTemplate
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ module AbstractController
|
|||
include ActionView::Rendering
|
||||
|
||||
def with_module
|
||||
render :inline => "Module <%= included_method %>"
|
||||
render inline: "Module <%= included_method %>"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -31,11 +31,11 @@ module AbstractController
|
|||
helper :abc
|
||||
|
||||
def with_block
|
||||
render :inline => "Hello <%= helpery_test %>"
|
||||
render inline: "Hello <%= helpery_test %>"
|
||||
end
|
||||
|
||||
def with_symbol
|
||||
render :inline => "I respond to bare_a: <%= respond_to?(:bare_a) %>"
|
||||
render inline: "I respond to bare_a: <%= respond_to?(:bare_a) %>"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ module AbstractControllerTests
|
|||
self.view_paths = []
|
||||
|
||||
def index
|
||||
render :template => ActionView::Template::Text.new("Hello blank!")
|
||||
render template: ActionView::Template::Text.new("Hello blank!")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -38,7 +38,7 @@ module AbstractControllerTests
|
|||
layout "hello_locals"
|
||||
|
||||
def index
|
||||
render :template => "some/template", locals: { foo: "less than 3" }
|
||||
render template: "some/template", locals: { foo: "less than 3" }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -46,7 +46,7 @@ module AbstractControllerTests
|
|||
layout "hello"
|
||||
|
||||
def index
|
||||
render :template => ActionView::Template::Text.new("Hello string!")
|
||||
render template: ActionView::Template::Text.new("Hello string!")
|
||||
end
|
||||
|
||||
def action_has_layout_false
|
||||
|
@ -54,15 +54,15 @@ module AbstractControllerTests
|
|||
end
|
||||
|
||||
def overwrite_default
|
||||
render :template => ActionView::Template::Text.new("Hello string!"), :layout => :default
|
||||
render template: ActionView::Template::Text.new("Hello string!"), layout: :default
|
||||
end
|
||||
|
||||
def overwrite_false
|
||||
render :template => ActionView::Template::Text.new("Hello string!"), :layout => false
|
||||
render template: ActionView::Template::Text.new("Hello string!"), layout: false
|
||||
end
|
||||
|
||||
def overwrite_string
|
||||
render :template => ActionView::Template::Text.new("Hello string!"), :layout => "overwrite"
|
||||
render template: ActionView::Template::Text.new("Hello string!"), layout: "overwrite"
|
||||
end
|
||||
|
||||
def overwrite_skip
|
||||
|
@ -92,7 +92,7 @@ module AbstractControllerTests
|
|||
layout proc { "overwrite" }
|
||||
|
||||
def index
|
||||
render :template => ActionView::Template::Text.new("Hello proc!")
|
||||
render template: ActionView::Template::Text.new("Hello proc!")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -116,7 +116,7 @@ module AbstractControllerTests
|
|||
layout proc { "overwrite" }
|
||||
|
||||
def index
|
||||
render :template => ActionView::Template::Text.new("Hello zero arity proc!")
|
||||
render template: ActionView::Template::Text.new("Hello zero arity proc!")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -129,7 +129,7 @@ module AbstractControllerTests
|
|||
}
|
||||
|
||||
def index
|
||||
render :template => ActionView::Template::Text.new("Hello again zero arity proc!")
|
||||
render template: ActionView::Template::Text.new("Hello again zero arity proc!")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -137,7 +137,7 @@ module AbstractControllerTests
|
|||
layout :hello
|
||||
|
||||
def index
|
||||
render :template => ActionView::Template::Text.new("Hello symbol!")
|
||||
render template: ActionView::Template::Text.new("Hello symbol!")
|
||||
end
|
||||
private
|
||||
def hello
|
||||
|
@ -149,7 +149,7 @@ module AbstractControllerTests
|
|||
layout :nilz
|
||||
|
||||
def index
|
||||
render :template => ActionView::Template::Text.new("Hello nilz!")
|
||||
render template: ActionView::Template::Text.new("Hello nilz!")
|
||||
end
|
||||
|
||||
def nilz() end
|
||||
|
@ -159,7 +159,7 @@ module AbstractControllerTests
|
|||
layout :objekt
|
||||
|
||||
def index
|
||||
render :template => ActionView::Template::Text.new("Hello nilz!")
|
||||
render template: ActionView::Template::Text.new("Hello nilz!")
|
||||
end
|
||||
|
||||
def objekt
|
||||
|
@ -171,7 +171,7 @@ module AbstractControllerTests
|
|||
layout :no_method
|
||||
|
||||
def index
|
||||
render :template => ActionView::Template::Text.new("Hello boom!")
|
||||
render template: ActionView::Template::Text.new("Hello boom!")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -179,7 +179,7 @@ module AbstractControllerTests
|
|||
layout "missing"
|
||||
|
||||
def index
|
||||
render :template => ActionView::Template::Text.new("Hello missing!")
|
||||
render template: ActionView::Template::Text.new("Hello missing!")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -187,7 +187,7 @@ module AbstractControllerTests
|
|||
layout false
|
||||
|
||||
def index
|
||||
render :template => ActionView::Template::Text.new("Hello false!")
|
||||
render template: ActionView::Template::Text.new("Hello false!")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -195,19 +195,19 @@ module AbstractControllerTests
|
|||
layout nil
|
||||
|
||||
def index
|
||||
render :template => ActionView::Template::Text.new("Hello nil!")
|
||||
render template: ActionView::Template::Text.new("Hello nil!")
|
||||
end
|
||||
end
|
||||
|
||||
class WithOnlyConditional < WithStringImpliedChild
|
||||
layout "overwrite", :only => :show
|
||||
layout "overwrite", only: :show
|
||||
|
||||
def index
|
||||
render :template => ActionView::Template::Text.new("Hello index!")
|
||||
render template: ActionView::Template::Text.new("Hello index!")
|
||||
end
|
||||
|
||||
def show
|
||||
render :template => ActionView::Template::Text.new("Hello show!")
|
||||
render template: ActionView::Template::Text.new("Hello show!")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -220,14 +220,14 @@ module AbstractControllerTests
|
|||
end
|
||||
|
||||
class WithExceptConditional < WithStringImpliedChild
|
||||
layout "overwrite", :except => :show
|
||||
layout "overwrite", except: :show
|
||||
|
||||
def index
|
||||
render :template => ActionView::Template::Text.new("Hello index!")
|
||||
render template: ActionView::Template::Text.new("Hello index!")
|
||||
end
|
||||
|
||||
def show
|
||||
render :template => ActionView::Template::Text.new("Hello show!")
|
||||
render template: ActionView::Template::Text.new("Hello show!")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -294,7 +294,7 @@ module AbstractControllerTests
|
|||
10.times do |x|
|
||||
controller = WithString.new
|
||||
controller.define_singleton_method :index do
|
||||
render :template => ActionView::Template::Text.new("Hello string!"), :locals => { :"x#{x}" => :omg }
|
||||
render template: ActionView::Template::Text.new("Hello string!"), locals: { :"x#{x}" => :omg }
|
||||
end
|
||||
controller.process(:index)
|
||||
end
|
||||
|
|
|
@ -21,15 +21,15 @@ module AbstractController
|
|||
)]
|
||||
|
||||
def template
|
||||
render :template => "template"
|
||||
render template: "template"
|
||||
end
|
||||
|
||||
def file
|
||||
render :file => "some/file"
|
||||
render file: "some/file"
|
||||
end
|
||||
|
||||
def inline
|
||||
render :inline => "With <%= :Inline %>"
|
||||
render inline: "With <%= :Inline %>"
|
||||
end
|
||||
|
||||
def text
|
||||
|
|
|
@ -9,22 +9,22 @@ class CaptureController < ActionController::Base
|
|||
|
||||
def content_for
|
||||
@title = nil
|
||||
render :layout => "talk_from_action"
|
||||
render layout: "talk_from_action"
|
||||
end
|
||||
|
||||
def content_for_with_parameter
|
||||
@title = nil
|
||||
render :layout => "talk_from_action"
|
||||
render layout: "talk_from_action"
|
||||
end
|
||||
|
||||
def content_for_concatenated
|
||||
@title = nil
|
||||
render :layout => "talk_from_action"
|
||||
render layout: "talk_from_action"
|
||||
end
|
||||
|
||||
def non_erb_block_content_for
|
||||
@title = nil
|
||||
render :layout => "talk_from_action"
|
||||
render layout: "talk_from_action"
|
||||
end
|
||||
|
||||
def proper_block_detection
|
||||
|
|
|
@ -92,7 +92,7 @@ end
|
|||
class StreamingLayoutController < LayoutTest
|
||||
def render(*args)
|
||||
options = args.extract_options!
|
||||
super(*args, options.merge(:stream => true))
|
||||
super(*args, options.merge(stream: true))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -119,27 +119,27 @@ end
|
|||
class PrependsViewPathController < LayoutTest
|
||||
def hello
|
||||
prepend_view_path File.dirname(__FILE__) + "/../../fixtures/actionpack/layout_tests/alt/"
|
||||
render :layout => "alt"
|
||||
render layout: "alt"
|
||||
end
|
||||
end
|
||||
|
||||
class OnlyLayoutController < LayoutTest
|
||||
layout "item", :only => "hello"
|
||||
layout "item", only: "hello"
|
||||
end
|
||||
|
||||
class ExceptLayoutController < LayoutTest
|
||||
layout "item", :except => "goodbye"
|
||||
layout "item", except: "goodbye"
|
||||
end
|
||||
|
||||
class SetsLayoutInRenderController < LayoutTest
|
||||
def hello
|
||||
render :layout => "third_party_template_library"
|
||||
render layout: "third_party_template_library"
|
||||
end
|
||||
end
|
||||
|
||||
class RendersNoLayoutController < LayoutTest
|
||||
def hello
|
||||
render :layout => false
|
||||
render layout: false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -241,7 +241,7 @@ end
|
|||
|
||||
class LayoutStatusIsRendered < LayoutTest
|
||||
def hello
|
||||
render :status => 401
|
||||
render status: 401
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ module Quiz
|
|||
# Controller
|
||||
class QuestionsController < ApplicationController
|
||||
def new
|
||||
render :partial => Quiz::Question.new("Namespaced Partial")
|
||||
render partial: Quiz::Question.new("Namespaced Partial")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -64,7 +64,7 @@ module Fun
|
|||
def hello_world; end
|
||||
|
||||
def nested_partial_with_form_builder
|
||||
render :partial => ActionView::Helpers::FormBuilder.new(:post, nil, view_context, {})
|
||||
render partial: ActionView::Helpers::FormBuilder.new(:post, nil, view_context, {})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -90,7 +90,7 @@ class TestController < ApplicationController
|
|||
end
|
||||
|
||||
def hello_world_file
|
||||
render :file => File.expand_path("../../../fixtures/actionpack/hello", __FILE__), :formats => [:html]
|
||||
render file: File.expand_path("../../../fixtures/actionpack/hello", __FILE__), formats: [:html]
|
||||
end
|
||||
|
||||
# :ported:
|
||||
|
@ -110,7 +110,7 @@ class TestController < ApplicationController
|
|||
|
||||
# :ported:
|
||||
def render_template_in_top_directory
|
||||
render :template => "shared"
|
||||
render template: "shared"
|
||||
end
|
||||
|
||||
# :deprecated:
|
||||
|
@ -126,11 +126,11 @@ class TestController < ApplicationController
|
|||
|
||||
# :ported:
|
||||
def render_action_hello_world
|
||||
render :action => "hello_world"
|
||||
render action: "hello_world"
|
||||
end
|
||||
|
||||
def render_action_upcased_hello_world
|
||||
render :action => "Hello_world"
|
||||
render action: "Hello_world"
|
||||
end
|
||||
|
||||
def render_action_hello_world_as_string
|
||||
|
@ -138,7 +138,7 @@ class TestController < ApplicationController
|
|||
end
|
||||
|
||||
def render_action_hello_world_with_symbol
|
||||
render :action => :hello_world
|
||||
render action: :hello_world
|
||||
end
|
||||
|
||||
# :ported:
|
||||
|
@ -149,34 +149,34 @@ class TestController < ApplicationController
|
|||
# :ported:
|
||||
def render_text_hello_world_with_layout
|
||||
@variable_for_layout = ", I am here!"
|
||||
render plain: "hello world", :layout => true
|
||||
render plain: "hello world", layout: true
|
||||
end
|
||||
|
||||
def hello_world_with_layout_false
|
||||
render :layout => false
|
||||
render layout: false
|
||||
end
|
||||
|
||||
# :ported:
|
||||
def render_file_with_instance_variables
|
||||
@secret = "in the sauce"
|
||||
path = File.join(File.dirname(__FILE__), "../../fixtures/test/render_file_with_ivar")
|
||||
render :file => path
|
||||
render file: path
|
||||
end
|
||||
|
||||
# :ported:
|
||||
def render_file_not_using_full_path
|
||||
@secret = "in the sauce"
|
||||
render :file => "test/render_file_with_ivar"
|
||||
render file: "test/render_file_with_ivar"
|
||||
end
|
||||
|
||||
def render_file_not_using_full_path_with_dot_in_path
|
||||
@secret = "in the sauce"
|
||||
render :file => "test/dot.directory/render_file_with_ivar"
|
||||
render file: "test/dot.directory/render_file_with_ivar"
|
||||
end
|
||||
|
||||
def render_file_using_pathname
|
||||
@secret = "in the sauce"
|
||||
render :file => Pathname.new(File.dirname(__FILE__)).join("..", "..", "fixtures", "test", "dot.directory", "render_file_with_ivar")
|
||||
render file: Pathname.new(File.dirname(__FILE__)).join("..", "..", "fixtures", "test", "dot.directory", "render_file_with_ivar")
|
||||
end
|
||||
|
||||
def render_file_from_template
|
||||
|
@ -186,33 +186,33 @@ class TestController < ApplicationController
|
|||
|
||||
def render_file_with_locals
|
||||
path = File.join(File.dirname(__FILE__), "../../fixtures/test/render_file_with_locals")
|
||||
render :file => path, :locals => {:secret => "in the sauce"}
|
||||
render file: path, locals: {secret: "in the sauce"}
|
||||
end
|
||||
|
||||
def render_file_as_string_with_locals
|
||||
path = File.expand_path(File.join(File.dirname(__FILE__), "../../fixtures/test/render_file_with_locals"))
|
||||
render file: path, :locals => {:secret => "in the sauce"}
|
||||
render file: path, locals: {secret: "in the sauce"}
|
||||
end
|
||||
|
||||
def accessing_request_in_template
|
||||
render :inline => "Hello: <%= request.host %>"
|
||||
render inline: "Hello: <%= request.host %>"
|
||||
end
|
||||
|
||||
def accessing_logger_in_template
|
||||
render :inline => "<%= logger.class %>"
|
||||
render inline: "<%= logger.class %>"
|
||||
end
|
||||
|
||||
def accessing_action_name_in_template
|
||||
render :inline => "<%= action_name %>"
|
||||
render inline: "<%= action_name %>"
|
||||
end
|
||||
|
||||
def accessing_controller_name_in_template
|
||||
render :inline => "<%= controller_name %>"
|
||||
render inline: "<%= controller_name %>"
|
||||
end
|
||||
|
||||
# :ported:
|
||||
def render_custom_code
|
||||
render plain: "hello world", :status => 404
|
||||
render plain: "hello world", status: 404
|
||||
end
|
||||
|
||||
# :ported:
|
||||
|
@ -240,7 +240,7 @@ class TestController < ApplicationController
|
|||
# setting content type
|
||||
def render_xml_hello
|
||||
@name = "David"
|
||||
render :template => "test/hello"
|
||||
render template: "test/hello"
|
||||
end
|
||||
|
||||
def render_xml_hello_as_string_template
|
||||
|
@ -249,7 +249,7 @@ class TestController < ApplicationController
|
|||
end
|
||||
|
||||
def render_line_offset
|
||||
render :inline => "<% raise %>", :locals => {:foo => "bar"}
|
||||
render inline: "<% raise %>", locals: {foo: "bar"}
|
||||
end
|
||||
|
||||
def heading
|
||||
|
@ -267,44 +267,44 @@ class TestController < ApplicationController
|
|||
|
||||
# :ported:
|
||||
def layout_test
|
||||
render :action => "hello_world"
|
||||
render action: "hello_world"
|
||||
end
|
||||
|
||||
# :ported:
|
||||
def builder_layout_test
|
||||
@name = nil
|
||||
render :action => "hello", :layout => "layouts/builder"
|
||||
render action: "hello", layout: "layouts/builder"
|
||||
end
|
||||
|
||||
# :move: test this in Action View
|
||||
def builder_partial_test
|
||||
render :action => "hello_world_container"
|
||||
render action: "hello_world_container"
|
||||
end
|
||||
|
||||
# :ported:
|
||||
def partials_list
|
||||
@test_unchanged = "hello"
|
||||
@customers = [ Customer.new("david"), Customer.new("mary") ]
|
||||
render :action => "list"
|
||||
render action: "list"
|
||||
end
|
||||
|
||||
def partial_only
|
||||
render :partial => true
|
||||
render partial: true
|
||||
end
|
||||
|
||||
def hello_in_a_string
|
||||
@customers = [ Customer.new("david"), Customer.new("mary") ]
|
||||
render plain: "How's there? " + render_to_string(:template => "test/list")
|
||||
render plain: "How's there? " + render_to_string(template: "test/list")
|
||||
end
|
||||
|
||||
def accessing_params_in_template
|
||||
render :inline => "Hello: <%= params[:name] %>"
|
||||
render inline: "Hello: <%= params[:name] %>"
|
||||
end
|
||||
|
||||
def accessing_local_assigns_in_inline_template
|
||||
name = params[:local_name]
|
||||
render :inline => "<%= 'Goodbye, ' + local_name %>",
|
||||
:locals => { :local_name => name }
|
||||
render inline: "<%= 'Goodbye, ' + local_name %>",
|
||||
locals: { local_name: name }
|
||||
end
|
||||
|
||||
def render_implicit_html_template_from_xhr_request
|
||||
|
@ -320,7 +320,7 @@ class TestController < ApplicationController
|
|||
end
|
||||
|
||||
def render_to_string_test
|
||||
@foo = render_to_string :inline => "this is a test"
|
||||
@foo = render_to_string inline: "this is a test"
|
||||
end
|
||||
|
||||
def default_render
|
||||
|
@ -333,27 +333,27 @@ class TestController < ApplicationController
|
|||
end
|
||||
|
||||
def render_action_hello_world_as_symbol
|
||||
render :action => :hello_world
|
||||
render action: :hello_world
|
||||
end
|
||||
|
||||
def layout_test_with_different_layout
|
||||
render :action => "hello_world", :layout => "standard"
|
||||
render action: "hello_world", layout: "standard"
|
||||
end
|
||||
|
||||
def layout_test_with_different_layout_and_string_action
|
||||
render "hello_world", :layout => "standard"
|
||||
render "hello_world", layout: "standard"
|
||||
end
|
||||
|
||||
def layout_test_with_different_layout_and_symbol_action
|
||||
render :hello_world, :layout => "standard"
|
||||
render :hello_world, layout: "standard"
|
||||
end
|
||||
|
||||
def rendering_without_layout
|
||||
render :action => "hello_world", :layout => false
|
||||
render action: "hello_world", layout: false
|
||||
end
|
||||
|
||||
def layout_overriding_layout
|
||||
render :action => "hello_world", :layout => "standard"
|
||||
render action: "hello_world", layout: "standard"
|
||||
end
|
||||
|
||||
def rendering_nothing_on_layout
|
||||
|
@ -364,38 +364,38 @@ class TestController < ApplicationController
|
|||
@before = "i'm before the render"
|
||||
render_to_string plain: "foo"
|
||||
@after = "i'm after the render"
|
||||
render :template => "test/hello_world"
|
||||
render template: "test/hello_world"
|
||||
end
|
||||
|
||||
def render_to_string_with_exception
|
||||
render_to_string :file => "exception that will not be caught - this will certainly not work"
|
||||
render_to_string file: "exception that will not be caught - this will certainly not work"
|
||||
end
|
||||
|
||||
def render_to_string_with_caught_exception
|
||||
@before = "i'm before the render"
|
||||
begin
|
||||
render_to_string :file => "exception that will be caught- hope my future instance vars still work!"
|
||||
render_to_string file: "exception that will be caught- hope my future instance vars still work!"
|
||||
rescue
|
||||
end
|
||||
@after = "i'm after the render"
|
||||
render :template => "test/hello_world"
|
||||
render template: "test/hello_world"
|
||||
end
|
||||
|
||||
def accessing_params_in_template_with_layout
|
||||
render :layout => true, :inline => "Hello: <%= params[:name] %>"
|
||||
render layout: true, inline: "Hello: <%= params[:name] %>"
|
||||
end
|
||||
|
||||
# :ported:
|
||||
def render_with_explicit_template
|
||||
render :template => "test/hello_world"
|
||||
render template: "test/hello_world"
|
||||
end
|
||||
|
||||
def render_with_explicit_unescaped_template
|
||||
render :template => "test/h*llo_world"
|
||||
render template: "test/h*llo_world"
|
||||
end
|
||||
|
||||
def render_with_explicit_escaped_template
|
||||
render :template => "test/hello,world"
|
||||
render template: "test/hello,world"
|
||||
end
|
||||
|
||||
def render_with_explicit_string_template
|
||||
|
@ -404,7 +404,7 @@ class TestController < ApplicationController
|
|||
|
||||
# :ported:
|
||||
def render_with_explicit_template_with_locals
|
||||
render :template => "test/render_file_with_locals", :locals => { :secret => "area51" }
|
||||
render template: "test/render_file_with_locals", locals: { secret: "area51" }
|
||||
end
|
||||
|
||||
# :ported:
|
||||
|
@ -414,13 +414,13 @@ class TestController < ApplicationController
|
|||
end
|
||||
|
||||
def double_redirect
|
||||
redirect_to :action => "double_render"
|
||||
redirect_to :action => "double_render"
|
||||
redirect_to action: "double_render"
|
||||
redirect_to action: "double_render"
|
||||
end
|
||||
|
||||
def render_and_redirect
|
||||
render plain: "hello"
|
||||
redirect_to :action => "double_render"
|
||||
redirect_to action: "double_render"
|
||||
end
|
||||
|
||||
def render_to_string_and_render
|
||||
|
@ -429,22 +429,22 @@ class TestController < ApplicationController
|
|||
end
|
||||
|
||||
def render_to_string_with_inline_and_render
|
||||
render_to_string :inline => "<%= 'dlrow olleh'.reverse %>"
|
||||
render :template => "test/hello_world"
|
||||
render_to_string inline: "<%= 'dlrow olleh'.reverse %>"
|
||||
render template: "test/hello_world"
|
||||
end
|
||||
|
||||
def rendering_with_conflicting_local_vars
|
||||
@name = "David"
|
||||
render :action => "potential_conflicts"
|
||||
render action: "potential_conflicts"
|
||||
end
|
||||
|
||||
def hello_world_from_rxml_using_action
|
||||
render :action => "hello_world_from_rxml", :handlers => [:builder]
|
||||
render action: "hello_world_from_rxml", handlers: [:builder]
|
||||
end
|
||||
|
||||
# :deprecated:
|
||||
def hello_world_from_rxml_using_template
|
||||
render :template => "test/hello_world_from_rxml", :handlers => [:builder]
|
||||
render template: "test/hello_world_from_rxml", handlers: [:builder]
|
||||
end
|
||||
|
||||
def action_talk_to_layout
|
||||
|
@ -462,7 +462,7 @@ class TestController < ApplicationController
|
|||
end
|
||||
|
||||
def yield_content_for
|
||||
render :action => "content_for", :layout => "yield"
|
||||
render action: "content_for", layout: "yield"
|
||||
end
|
||||
|
||||
def render_content_type_from_body
|
||||
|
@ -471,70 +471,70 @@ class TestController < ApplicationController
|
|||
end
|
||||
|
||||
def render_using_layout_around_block
|
||||
render :action => "using_layout_around_block"
|
||||
render action: "using_layout_around_block"
|
||||
end
|
||||
|
||||
def render_using_layout_around_block_in_main_layout_and_within_content_for_layout
|
||||
render :action => "using_layout_around_block", :layout => "layouts/block_with_layout"
|
||||
render action: "using_layout_around_block", layout: "layouts/block_with_layout"
|
||||
end
|
||||
|
||||
def partial_formats_html
|
||||
render :partial => "partial", :formats => [:html]
|
||||
render partial: "partial", formats: [:html]
|
||||
end
|
||||
|
||||
def partial
|
||||
render :partial => "partial"
|
||||
render partial: "partial"
|
||||
end
|
||||
|
||||
def partial_html_erb
|
||||
render :partial => "partial_html_erb"
|
||||
render partial: "partial_html_erb"
|
||||
end
|
||||
|
||||
def render_to_string_with_partial
|
||||
@partial_only = render_to_string :partial => "partial_only"
|
||||
@partial_with_locals = render_to_string :partial => "customer", :locals => { :customer => Customer.new("david") }
|
||||
render :template => "test/hello_world"
|
||||
@partial_only = render_to_string partial: "partial_only"
|
||||
@partial_with_locals = render_to_string partial: "customer", locals: { customer: Customer.new("david") }
|
||||
render template: "test/hello_world"
|
||||
end
|
||||
|
||||
def render_to_string_with_template_and_html_partial
|
||||
@text = render_to_string :template => "test/with_partial", :formats => [:text]
|
||||
@html = render_to_string :template => "test/with_partial", :formats => [:html]
|
||||
render :template => "test/with_html_partial"
|
||||
@text = render_to_string template: "test/with_partial", formats: [:text]
|
||||
@html = render_to_string template: "test/with_partial", formats: [:html]
|
||||
render template: "test/with_html_partial"
|
||||
end
|
||||
|
||||
def render_to_string_and_render_with_different_formats
|
||||
@html = render_to_string :template => "test/with_partial", :formats => [:html]
|
||||
render :template => "test/with_partial", :formats => [:text]
|
||||
@html = render_to_string template: "test/with_partial", formats: [:html]
|
||||
render template: "test/with_partial", formats: [:text]
|
||||
end
|
||||
|
||||
def render_template_within_a_template_with_other_format
|
||||
render :template => "test/with_xml_template",
|
||||
:formats => [:html],
|
||||
:layout => "with_html_partial"
|
||||
render template: "test/with_xml_template",
|
||||
formats: [:html],
|
||||
layout: "with_html_partial"
|
||||
end
|
||||
|
||||
def partial_with_counter
|
||||
render :partial => "counter", :locals => { :counter_counter => 5 }
|
||||
render partial: "counter", locals: { counter_counter: 5 }
|
||||
end
|
||||
|
||||
def partial_with_locals
|
||||
render :partial => "customer", :locals => { :customer => Customer.new("david") }
|
||||
render partial: "customer", locals: { customer: Customer.new("david") }
|
||||
end
|
||||
|
||||
def partial_with_form_builder
|
||||
render :partial => ActionView::Helpers::FormBuilder.new(:post, nil, view_context, {})
|
||||
render partial: ActionView::Helpers::FormBuilder.new(:post, nil, view_context, {})
|
||||
end
|
||||
|
||||
def partial_with_form_builder_subclass
|
||||
render :partial => LabellingFormBuilder.new(:post, nil, view_context, {})
|
||||
render partial: LabellingFormBuilder.new(:post, nil, view_context, {})
|
||||
end
|
||||
|
||||
def partial_collection
|
||||
render :partial => "customer", :collection => [ Customer.new("david"), Customer.new("mary") ]
|
||||
render partial: "customer", collection: [ Customer.new("david"), Customer.new("mary") ]
|
||||
end
|
||||
|
||||
def partial_collection_with_as
|
||||
render :partial => "customer_with_var", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => :customer
|
||||
render partial: "customer_with_var", collection: [ Customer.new("david"), Customer.new("mary") ], as: :customer
|
||||
end
|
||||
|
||||
def partial_collection_with_iteration
|
||||
|
@ -546,42 +546,42 @@ class TestController < ApplicationController
|
|||
end
|
||||
|
||||
def partial_collection_with_counter
|
||||
render :partial => "customer_counter", :collection => [ Customer.new("david"), Customer.new("mary") ]
|
||||
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
|
||||
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" }
|
||||
render partial: "customer_greeting", collection: [ Customer.new("david"), Customer.new("mary") ], locals: { greeting: "Bonjour" }
|
||||
end
|
||||
|
||||
def partial_collection_with_spacer
|
||||
render :partial => "customer", :spacer_template => "partial_only", :collection => [ Customer.new("david"), Customer.new("mary") ]
|
||||
render partial: "customer", spacer_template: "partial_only", collection: [ Customer.new("david"), Customer.new("mary") ]
|
||||
end
|
||||
|
||||
def partial_collection_with_spacer_which_uses_render
|
||||
render :partial => "customer", :spacer_template => "partial_with_partial", :collection => [ Customer.new("david"), Customer.new("mary") ]
|
||||
render partial: "customer", spacer_template: "partial_with_partial", collection: [ Customer.new("david"), Customer.new("mary") ]
|
||||
end
|
||||
|
||||
def partial_collection_shorthand_with_locals
|
||||
render :partial => [ Customer.new("david"), Customer.new("mary") ], :locals => { :greeting => "Bonjour" }
|
||||
render partial: [ Customer.new("david"), Customer.new("mary") ], locals: { greeting: "Bonjour" }
|
||||
end
|
||||
|
||||
def partial_collection_shorthand_with_different_types_of_records
|
||||
render :partial => [
|
||||
render partial: [
|
||||
BadCustomer.new("mark"),
|
||||
GoodCustomer.new("craig"),
|
||||
BadCustomer.new("john"),
|
||||
GoodCustomer.new("zach"),
|
||||
GoodCustomer.new("brandon"),
|
||||
BadCustomer.new("dan") ],
|
||||
:locals => { :greeting => "Bonjour" }
|
||||
locals: { greeting: "Bonjour" }
|
||||
end
|
||||
|
||||
def empty_partial_collection
|
||||
render :partial => "customer", :collection => []
|
||||
render partial: "customer", collection: []
|
||||
end
|
||||
|
||||
def partial_collection_shorthand_with_different_types_of_records_with_counter
|
||||
|
@ -589,15 +589,15 @@ class TestController < ApplicationController
|
|||
end
|
||||
|
||||
def missing_partial
|
||||
render :partial => "thisFileIsntHere"
|
||||
render partial: "thisFileIsntHere"
|
||||
end
|
||||
|
||||
def partial_with_hash_object
|
||||
render :partial => "hash_object", :object => {:first_name => "Sam"}
|
||||
render partial: "hash_object", object: {first_name: "Sam"}
|
||||
end
|
||||
|
||||
def partial_with_nested_object
|
||||
render :partial => "quiz/questions/question", :object => Quiz::Question.new("first")
|
||||
render partial: "quiz/questions/question", object: Quiz::Question.new("first")
|
||||
end
|
||||
|
||||
def partial_with_nested_object_shorthand
|
||||
|
@ -605,24 +605,24 @@ class TestController < ApplicationController
|
|||
end
|
||||
|
||||
def partial_hash_collection
|
||||
render :partial => "hash_object", :collection => [ {:first_name => "Pratik"}, {:first_name => "Amy"} ]
|
||||
render partial: "hash_object", collection: [ {first_name: "Pratik"}, {first_name: "Amy"} ]
|
||||
end
|
||||
|
||||
def partial_hash_collection_with_locals
|
||||
render :partial => "hash_greeting", :collection => [ {:first_name => "Pratik"}, {:first_name => "Amy"} ], :locals => { :greeting => "Hola" }
|
||||
render partial: "hash_greeting", collection: [ {first_name: "Pratik"}, {first_name: "Amy"} ], locals: { greeting: "Hola" }
|
||||
end
|
||||
|
||||
def partial_with_implicit_local_assignment
|
||||
@customer = Customer.new("Marcel")
|
||||
render :partial => "customer"
|
||||
render partial: "customer"
|
||||
end
|
||||
|
||||
def render_call_to_partial_with_layout
|
||||
render :action => "calling_partial_with_layout"
|
||||
render action: "calling_partial_with_layout"
|
||||
end
|
||||
|
||||
def render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout
|
||||
render :action => "calling_partial_with_layout", :layout => "layouts/partial_with_layout"
|
||||
render action: "calling_partial_with_layout", layout: "layouts/partial_with_layout"
|
||||
end
|
||||
|
||||
before_action only: :render_with_filters do
|
||||
|
@ -631,7 +631,7 @@ class TestController < ApplicationController
|
|||
|
||||
# Ensure that the before filter is executed *before* self.formats is set.
|
||||
def render_with_filters
|
||||
render :action => :formatted_xml_erb
|
||||
render action: :formatted_xml_erb
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -7,7 +7,7 @@ class ViewLoadPathsTest < ActionController::TestCase
|
|||
before_action :add_view_path, only: :hello_world_at_request_time
|
||||
|
||||
def hello_world() end
|
||||
def hello_world_at_request_time() render(:action => "hello_world") end
|
||||
def hello_world_at_request_time() render(action: "hello_world") end
|
||||
|
||||
private
|
||||
def add_view_path
|
||||
|
@ -18,7 +18,7 @@ class ViewLoadPathsTest < ActionController::TestCase
|
|||
module Test
|
||||
class SubController < ActionController::Base
|
||||
layout "test/sub"
|
||||
def hello_world; render(:template => "test/hello_world"); end
|
||||
def hello_world; render(template: "test/hello_world"); end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -132,8 +132,8 @@ class ViewLoadPathsTest < ActionController::TestCase
|
|||
template.identifier,
|
||||
template.handler,
|
||||
{
|
||||
:virtual_path => template.virtual_path,
|
||||
:format => template.formats
|
||||
virtual_path: template.virtual_path,
|
||||
format: template.formats
|
||||
}
|
||||
)
|
||||
end
|
||||
|
|
|
@ -44,9 +44,9 @@ class ActiveRecordTestConnector
|
|||
private
|
||||
def setup_connection
|
||||
if Object.const_defined?(:ActiveRecord)
|
||||
defaults = { :database => ":memory:" }
|
||||
defaults = { database: ":memory:" }
|
||||
adapter = defined?(JRUBY_VERSION) ? "jdbcsqlite3" : "sqlite3"
|
||||
options = defaults.merge :adapter => adapter, :timeout => 500
|
||||
options = defaults.merge adapter: adapter, timeout: 500
|
||||
ActiveRecord::Base.establish_connection(options)
|
||||
ActiveRecord::Base.configurations = { "sqlite3_ar_integration" => options }
|
||||
ActiveRecord::Base.connection
|
||||
|
|
|
@ -9,11 +9,11 @@ ActionController::Base.include(ActiveRecord::Railties::ControllerRuntime)
|
|||
class ControllerRuntimeLogSubscriberTest < ActionController::TestCase
|
||||
class LogSubscriberController < ActionController::Base
|
||||
def show
|
||||
render :inline => "<%= Project.all %>"
|
||||
render inline: "<%= Project.all %>"
|
||||
end
|
||||
|
||||
def zero
|
||||
render :inline => "Zero DB runtime"
|
||||
render inline: "Zero DB runtime"
|
||||
end
|
||||
|
||||
def create
|
||||
|
@ -24,11 +24,11 @@ class ControllerRuntimeLogSubscriberTest < ActionController::TestCase
|
|||
|
||||
def redirect
|
||||
Project.all
|
||||
redirect_to :action => "show"
|
||||
redirect_to action: "show"
|
||||
end
|
||||
|
||||
def db_after_render
|
||||
render :inline => "Hello world"
|
||||
render inline: "Hello world"
|
||||
Project.all
|
||||
ActiveRecord::LogSubscriber.runtime += 100
|
||||
end
|
||||
|
|
|
@ -39,12 +39,12 @@ class FormHelperActiveRecordTest < ActionView::TestCase
|
|||
|
||||
def test_nested_fields_for_with_child_index_option_override_on_a_nested_attributes_collection_association
|
||||
form_for(@developer) do |f|
|
||||
concat f.fields_for(:projects, @developer.projects.first, :child_index => "abc") { |cf|
|
||||
concat f.fields_for(:projects, @developer.projects.first, child_index: "abc") { |cf|
|
||||
concat cf.text_field(:name)
|
||||
}
|
||||
end
|
||||
|
||||
expected = whole_form("/developers/123", "edit_developer_123", "edit_developer", :method => "patch") do
|
||||
expected = whole_form("/developers/123", "edit_developer_123", "edit_developer", method: "patch") do
|
||||
'<input id="developer_projects_attributes_abc_name" name="developer[projects_attributes][abc][name]" type="text" value="project #321" />' +
|
||||
'<input id="developer_projects_attributes_abc_id" name="developer[projects_attributes][abc][id]" type="hidden" value="321" />'
|
||||
end
|
||||
|
|
|
@ -95,7 +95,7 @@ class PolymorphicRoutesTest < ActionController::TestCase
|
|||
|
||||
def test_string_with_options
|
||||
with_test_routes do
|
||||
assert_equal "http://example.com/projects?id=10", polymorphic_url("projects", :id => 10)
|
||||
assert_equal "http://example.com/projects?id=10", polymorphic_url("projects", id: 10)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -107,7 +107,7 @@ class PolymorphicRoutesTest < ActionController::TestCase
|
|||
|
||||
def test_symbol_with_options
|
||||
with_test_routes do
|
||||
assert_equal "http://example.com/projects?id=10", polymorphic_url(:projects, :id => 10)
|
||||
assert_equal "http://example.com/projects?id=10", polymorphic_url(:projects, id: 10)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -179,7 +179,7 @@ class PolymorphicRoutesTest < ActionController::TestCase
|
|||
def test_with_nil_id
|
||||
with_test_routes do
|
||||
exception = assert_raise ArgumentError do
|
||||
polymorphic_url({ :id => nil })
|
||||
polymorphic_url({ id: nil })
|
||||
end
|
||||
assert_equal "Nil location provided. Can't build URI.", exception.message
|
||||
end
|
||||
|
@ -233,8 +233,8 @@ class PolymorphicRoutesTest < ActionController::TestCase
|
|||
|
||||
def test_class_with_options
|
||||
with_test_routes do
|
||||
assert_equal "http://example.com/projects?foo=bar", polymorphic_url(@project.class, { :foo => :bar })
|
||||
assert_equal "/projects?foo=bar", polymorphic_path(@project.class, { :foo => :bar })
|
||||
assert_equal "http://example.com/projects?foo=bar", polymorphic_url(@project.class, { foo: :bar })
|
||||
assert_equal "/projects?foo=bar", polymorphic_path(@project.class, { foo: :bar })
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -274,7 +274,7 @@ class PolymorphicRoutesTest < ActionController::TestCase
|
|||
|
||||
def test_with_record_and_action
|
||||
with_test_routes do
|
||||
assert_equal "http://example.com/projects/new", polymorphic_url(@project, :action => "new")
|
||||
assert_equal "http://example.com/projects/new", polymorphic_url(@project, action: "new")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -303,35 +303,35 @@ class PolymorphicRoutesTest < ActionController::TestCase
|
|||
def test_url_helper_prefixed_with_edit_with_url_options
|
||||
with_test_routes do
|
||||
@project.save
|
||||
assert_equal "http://example.com/projects/#{@project.id}/edit?param1=10", edit_polymorphic_url(@project, :param1 => "10")
|
||||
assert_equal "http://example.com/projects/#{@project.id}/edit?param1=10", edit_polymorphic_url(@project, param1: "10")
|
||||
end
|
||||
end
|
||||
|
||||
def test_url_helper_with_url_options
|
||||
with_test_routes do
|
||||
@project.save
|
||||
assert_equal "http://example.com/projects/#{@project.id}?param1=10", polymorphic_url(@project, :param1 => "10")
|
||||
assert_equal "http://example.com/projects/#{@project.id}?param1=10", polymorphic_url(@project, param1: "10")
|
||||
end
|
||||
end
|
||||
|
||||
def test_format_option
|
||||
with_test_routes do
|
||||
@project.save
|
||||
assert_equal "http://example.com/projects/#{@project.id}.pdf", polymorphic_url(@project, :format => :pdf)
|
||||
assert_equal "http://example.com/projects/#{@project.id}.pdf", polymorphic_url(@project, format: :pdf)
|
||||
end
|
||||
end
|
||||
|
||||
def test_format_option_with_url_options
|
||||
with_test_routes do
|
||||
@project.save
|
||||
assert_equal "http://example.com/projects/#{@project.id}.pdf?param1=10", polymorphic_url(@project, :format => :pdf, :param1 => "10")
|
||||
assert_equal "http://example.com/projects/#{@project.id}.pdf?param1=10", polymorphic_url(@project, format: :pdf, param1: "10")
|
||||
end
|
||||
end
|
||||
|
||||
def test_id_and_format_option
|
||||
with_test_routes do
|
||||
@project.save
|
||||
assert_equal "http://example.com/projects/#{@project.id}.pdf", polymorphic_url(:id => @project, :format => :pdf)
|
||||
assert_equal "http://example.com/projects/#{@project.id}.pdf", polymorphic_url(id: @project, format: :pdf)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -373,7 +373,7 @@ class PolymorphicRoutesTest < ActionController::TestCase
|
|||
|
||||
def test_new_with_array_and_namespace
|
||||
with_admin_test_routes do
|
||||
assert_equal "http://example.com/admin/projects/new", polymorphic_url([:admin, @project], :action => "new")
|
||||
assert_equal "http://example.com/admin/projects/new", polymorphic_url([:admin, @project], action: "new")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -426,7 +426,7 @@ class PolymorphicRoutesTest < ActionController::TestCase
|
|||
with_test_routes do
|
||||
@project.save
|
||||
@task.save
|
||||
assert_equal "http://example.com/projects/#{@project.id}/bid/tasks/#{@task.id}.pdf", polymorphic_url([@project, :bid, @task], :format => :pdf)
|
||||
assert_equal "http://example.com/projects/#{@project.id}/bid/tasks/#{@task.id}.pdf", polymorphic_url([@project, :bid, @task], format: :pdf)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -474,13 +474,13 @@ class PolymorphicRoutesTest < ActionController::TestCase
|
|||
def test_with_hash
|
||||
with_test_routes do
|
||||
@project.save
|
||||
assert_equal "http://example.com/projects/#{@project.id}", polymorphic_url(:id => @project)
|
||||
assert_equal "http://example.com/projects/#{@project.id}", polymorphic_url(id: @project)
|
||||
end
|
||||
end
|
||||
|
||||
def test_polymorphic_path_accepts_options
|
||||
with_test_routes do
|
||||
assert_equal "/projects/new", polymorphic_path(@project, :action => "new")
|
||||
assert_equal "/projects/new", polymorphic_path(@project, action: "new")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -527,7 +527,7 @@ class PolymorphicRoutesTest < ActionController::TestCase
|
|||
|
||||
def test_with_irregular_plural_record_and_action
|
||||
with_test_routes do
|
||||
assert_equal "http://example.com/taxes/new", polymorphic_url(@tax, :action => "new")
|
||||
assert_equal "http://example.com/taxes/new", polymorphic_url(@tax, action: "new")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -561,7 +561,7 @@ class PolymorphicRoutesTest < ActionController::TestCase
|
|||
|
||||
def test_new_with_irregular_plural_array_and_namespace
|
||||
with_admin_test_routes do
|
||||
assert_equal "http://example.com/admin/taxes/new", polymorphic_url([:admin, @tax], :action => "new")
|
||||
assert_equal "http://example.com/admin/taxes/new", polymorphic_url([:admin, @tax], action: "new")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -622,7 +622,7 @@ class PolymorphicRoutesTest < ActionController::TestCase
|
|||
def with_namespaced_routes(name)
|
||||
with_routing do |set|
|
||||
set.draw do
|
||||
scope(:module => name) do
|
||||
scope(module: name) do
|
||||
resources :blogs do
|
||||
resources :posts do
|
||||
resources :faxes
|
||||
|
|
|
@ -3,46 +3,46 @@ require "active_record_unit"
|
|||
class RenderPartialWithRecordIdentificationController < ActionController::Base
|
||||
def render_with_has_many_and_belongs_to_association
|
||||
@developer = Developer.find(1)
|
||||
render :partial => @developer.projects
|
||||
render partial: @developer.projects
|
||||
end
|
||||
|
||||
def render_with_has_many_association
|
||||
@topic = Topic.find(1)
|
||||
render :partial => @topic.replies
|
||||
render partial: @topic.replies
|
||||
end
|
||||
|
||||
def render_with_scope
|
||||
render :partial => Reply.base
|
||||
render partial: Reply.base
|
||||
end
|
||||
|
||||
def render_with_has_many_through_association
|
||||
@developer = Developer.first
|
||||
render :partial => @developer.topics
|
||||
render partial: @developer.topics
|
||||
end
|
||||
|
||||
def render_with_has_one_association
|
||||
@company = Company.find(1)
|
||||
render :partial => @company.mascot
|
||||
render partial: @company.mascot
|
||||
end
|
||||
|
||||
def render_with_belongs_to_association
|
||||
@reply = Reply.find(1)
|
||||
render :partial => @reply.topic
|
||||
render partial: @reply.topic
|
||||
end
|
||||
|
||||
def render_with_record
|
||||
@developer = Developer.first
|
||||
render :partial => @developer
|
||||
render partial: @developer
|
||||
end
|
||||
|
||||
def render_with_record_collection
|
||||
@developers = Developer.all
|
||||
render :partial => @developers
|
||||
render partial: @developers
|
||||
end
|
||||
|
||||
def render_with_record_collection_and_spacer_template
|
||||
@developer = Developer.find(1)
|
||||
render :partial => @developer.projects, :spacer_template => "test/partial_only"
|
||||
render partial: @developer.projects, spacer_template: "test/partial_only"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -98,22 +98,22 @@ end
|
|||
module Fun
|
||||
class NestedController < ActionController::Base
|
||||
def render_with_record_in_nested_controller
|
||||
render :partial => Game.new("Pong")
|
||||
render partial: Game.new("Pong")
|
||||
end
|
||||
|
||||
def render_with_record_collection_in_nested_controller
|
||||
render :partial => [ Game.new("Pong"), Game.new("Tank") ]
|
||||
render partial: [ Game.new("Pong"), Game.new("Tank") ]
|
||||
end
|
||||
end
|
||||
|
||||
module Serious
|
||||
class NestedDeeperController < ActionController::Base
|
||||
def render_with_record_in_deeper_nested_controller
|
||||
render :partial => Game.new("Chess")
|
||||
render partial: Game.new("Chess")
|
||||
end
|
||||
|
||||
def render_with_record_collection_in_deeper_nested_controller
|
||||
render :partial => [ Game.new("Chess"), Game.new("Sudoku"), Game.new("Solitaire") ]
|
||||
render partial: [ Game.new("Chess"), Game.new("Sudoku"), Game.new("Solitaire") ]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class Developer < ActiveRecord::Base
|
||||
has_and_belongs_to_many :projects
|
||||
has_many :replies
|
||||
has_many :topics, :through => :replies
|
||||
has_many :topics, through: :replies
|
||||
accepts_nested_attributes_for :projects
|
||||
end
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
class Topic < ActiveRecord::Base
|
||||
has_many :replies, :dependent => :destroy
|
||||
has_many :replies, dependent: :destroy
|
||||
end
|
||||
|
|
|
@ -50,28 +50,28 @@ class ActiveModelHelperTest < ActionView::TestCase
|
|||
|
||||
def test_select_with_errors_and_blank_option
|
||||
expected_dom = %(<div class="field_with_errors"><select name="post[author_name]" id="post_author_name"><option value="">Choose one...</option>\n<option value="a">a</option>\n<option value="b">b</option></select></div>)
|
||||
assert_dom_equal(expected_dom, select("post", "author_name", [:a, :b], :include_blank => "Choose one..."))
|
||||
assert_dom_equal(expected_dom, select("post", "author_name", [:a, :b], :prompt => "Choose one..."))
|
||||
assert_dom_equal(expected_dom, select("post", "author_name", [:a, :b], include_blank: "Choose one..."))
|
||||
assert_dom_equal(expected_dom, select("post", "author_name", [:a, :b], prompt: "Choose one..."))
|
||||
end
|
||||
|
||||
def test_date_select_with_errors
|
||||
assert_dom_equal(
|
||||
%(<div class="field_with_errors"><select id="post_updated_at_1i" name="post[updated_at(1i)]">\n<option selected="selected" value="2004">2004</option>\n<option value="2005">2005</option>\n</select>\n<input id="post_updated_at_2i" name="post[updated_at(2i)]" type="hidden" value="6" />\n<input id="post_updated_at_3i" name="post[updated_at(3i)]" type="hidden" value="1" />\n</div>),
|
||||
date_select("post", "updated_at", :discard_month => true, :discard_day => true, :start_year => 2004, :end_year => 2005)
|
||||
date_select("post", "updated_at", discard_month: true, discard_day: true, start_year: 2004, end_year: 2005)
|
||||
)
|
||||
end
|
||||
|
||||
def test_datetime_select_with_errors
|
||||
assert_dom_equal(
|
||||
%(<div class="field_with_errors"><input id="post_updated_at_1i" name="post[updated_at(1i)]" type="hidden" value="2004" />\n<input id="post_updated_at_2i" name="post[updated_at(2i)]" type="hidden" value="6" />\n<input id="post_updated_at_3i" name="post[updated_at(3i)]" type="hidden" value="1" />\n<select id="post_updated_at_4i" name="post[updated_at(4i)]">\n<option selected="selected" value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n : <select id="post_updated_at_5i" name="post[updated_at(5i)]">\n<option selected="selected" value="00">00</option>\n</select>\n</div>),
|
||||
datetime_select("post", "updated_at", :discard_year => true, :discard_month => true, :discard_day => true, :minute_step => 60)
|
||||
datetime_select("post", "updated_at", discard_year: true, discard_month: true, discard_day: true, minute_step: 60)
|
||||
)
|
||||
end
|
||||
|
||||
def test_time_select_with_errors
|
||||
assert_dom_equal(
|
||||
%(<div class="field_with_errors"><input id="post_updated_at_1i" name="post[updated_at(1i)]" type="hidden" value="2004" />\n<input id="post_updated_at_2i" name="post[updated_at(2i)]" type="hidden" value="6" />\n<input id="post_updated_at_3i" name="post[updated_at(3i)]" type="hidden" value="15" />\n<select id="post_updated_at_4i" name="post[updated_at(4i)]">\n<option selected="selected" value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n : <select id="post_updated_at_5i" name="post[updated_at(5i)]">\n<option selected="selected" value="00">00</option>\n</select>\n</div>),
|
||||
time_select("post", "updated_at", :minute_step => 60)
|
||||
time_select("post", "updated_at", minute_step: 60)
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -306,7 +306,7 @@ class AssetTagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_autodiscovery_link_tag_with_unknown_type
|
||||
result = auto_discovery_link_tag(:xml, "/feed.xml", :type => "application/xml")
|
||||
result = auto_discovery_link_tag(:xml, "/feed.xml", type: "application/xml")
|
||||
expected = %(<link href="/feed.xml" rel="alternate" title="XML" type="application/xml" />)
|
||||
assert_dom_equal expected, result
|
||||
end
|
||||
|
@ -331,9 +331,9 @@ class AssetTagHelperTest < ActionView::TestCase
|
|||
def test_compute_asset_public_path
|
||||
assert_equal "/robots.txt", compute_asset_path("robots.txt")
|
||||
assert_equal "/robots.txt", compute_asset_path("/robots.txt")
|
||||
assert_equal "/javascripts/foo.js", compute_asset_path("foo.js", :type => :javascript)
|
||||
assert_equal "/javascripts/foo.js", compute_asset_path("/foo.js", :type => :javascript)
|
||||
assert_equal "/stylesheets/foo.css", compute_asset_path("foo.css", :type => :stylesheet)
|
||||
assert_equal "/javascripts/foo.js", compute_asset_path("foo.js", type: :javascript)
|
||||
assert_equal "/javascripts/foo.js", compute_asset_path("/foo.js", type: :javascript)
|
||||
assert_equal "/stylesheets/foo.css", compute_asset_path("foo.css", type: :stylesheet)
|
||||
end
|
||||
|
||||
def test_auto_discovery_link_tag
|
||||
|
@ -421,7 +421,7 @@ class AssetTagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_stylesheet_link_tag_escapes_options
|
||||
assert_dom_equal %(<link href="/file.css" media="<script>" rel="stylesheet" />), stylesheet_link_tag("/file", :media => "<script>")
|
||||
assert_dom_equal %(<link href="/file.css" media="<script>" rel="stylesheet" />), stylesheet_link_tag("/file", media: "<script>")
|
||||
end
|
||||
|
||||
def test_stylesheet_link_tag_should_not_output_the_same_asset_twice
|
||||
|
@ -470,14 +470,14 @@ class AssetTagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_image_tag_does_not_modify_options
|
||||
options = {:size => "16x10"}
|
||||
options = {size: "16x10"}
|
||||
image_tag("icon", options)
|
||||
assert_equal({:size => "16x10"}, options)
|
||||
assert_equal({size: "16x10"}, options)
|
||||
end
|
||||
|
||||
def test_image_tag_raises_an_error_for_competing_size_arguments
|
||||
exception = assert_raise(ArgumentError) do
|
||||
image_tag("gold.png", :height => "100", :width => "200", :size => "45x70")
|
||||
image_tag("gold.png", height: "100", width: "200", size: "45x70")
|
||||
end
|
||||
|
||||
assert_equal("Cannot pass a :size option with a :height or :width option", exception.message)
|
||||
|
@ -532,11 +532,11 @@ class AssetTagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_video_audio_tag_does_not_modify_options
|
||||
options = {:autoplay => true}
|
||||
options = {autoplay: true}
|
||||
video_tag("video", options)
|
||||
assert_equal({:autoplay => true}, options)
|
||||
assert_equal({autoplay: true}, options)
|
||||
audio_tag("audio", options)
|
||||
assert_equal({:autoplay => true}, options)
|
||||
assert_equal({autoplay: true}, options)
|
||||
end
|
||||
|
||||
def test_image_tag_interpreting_email_cid_correctly
|
||||
|
@ -545,7 +545,7 @@ class AssetTagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_image_tag_interpreting_email_adding_optional_alt_tag
|
||||
assert_equal '<img alt="Image" src="cid:thi%25%25sis@acontentid" />', image_tag("cid:thi%25%25sis@acontentid", :alt => "Image")
|
||||
assert_equal '<img alt="Image" src="cid:thi%25%25sis@acontentid" />', image_tag("cid:thi%25%25sis@acontentid", alt: "Image")
|
||||
end
|
||||
|
||||
def test_should_not_modify_source_string
|
||||
|
@ -634,11 +634,11 @@ class AssetTagHelperNonVhostTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_should_current_request_host_is_always_returned_for_request
|
||||
assert_equal "gopher://www.example.com", compute_asset_host("foo", :protocol => :request)
|
||||
assert_equal "gopher://www.example.com", compute_asset_host("foo", protocol: :request)
|
||||
end
|
||||
|
||||
def test_should_return_custom_host_if_passed_in_options
|
||||
assert_equal "http://custom.example.com", compute_asset_host("foo", :host => "http://custom.example.com")
|
||||
assert_equal "http://custom.example.com", compute_asset_host("foo", host: "http://custom.example.com")
|
||||
end
|
||||
|
||||
def test_should_ignore_relative_root_path_on_complete_url
|
||||
|
@ -652,12 +652,12 @@ class AssetTagHelperNonVhostTest < ActionView::TestCase
|
|||
|
||||
def test_should_return_relative_asset_host
|
||||
@controller.config.asset_host = "assets.example.com"
|
||||
assert_equal "//assets.example.com", compute_asset_host("foo", :protocol => :relative)
|
||||
assert_equal "//assets.example.com", compute_asset_host("foo", protocol: :relative)
|
||||
end
|
||||
|
||||
def test_should_return_custom_protocol_asset_host
|
||||
@controller.config.asset_host = "assets.example.com"
|
||||
assert_equal "ftp://assets.example.com", compute_asset_host("foo", :protocol => "ftp")
|
||||
assert_equal "ftp://assets.example.com", compute_asset_host("foo", protocol: "ftp")
|
||||
end
|
||||
|
||||
def test_should_compute_proper_path_with_asset_host
|
||||
|
@ -813,6 +813,6 @@ class AssetUrlHelperEmptyModuleTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
assert @module.config.asset_host
|
||||
assert_equal "http://custom.example.com/foo", @module.asset_url("foo", :host => "http://custom.example.com")
|
||||
assert_equal "http://custom.example.com/foo", @module.asset_url("foo", host: "http://custom.example.com")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -217,7 +217,7 @@ class ScrollsController < ActionController::Base
|
|||
Scroll.new(2, "2", "Hello Two", "Something Boring", Time.utc(2007, 12, 12, 15)),
|
||||
]
|
||||
|
||||
render :inline => FEEDS[params[:id]], :type => :builder
|
||||
render inline: FEEDS[params[:id]], type: :builder
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -278,22 +278,22 @@ class AtomFeedTest < ActionController::TestCase
|
|||
def test_feed_id_should_be_a_valid_tag
|
||||
with_restful_routing(:scrolls) do
|
||||
get :index, params: { id: "defaults" }
|
||||
assert_select "id", :text => "tag:www.nextangle.com,2008:/scrolls?id=defaults"
|
||||
assert_select "id", text: "tag:www.nextangle.com,2008:/scrolls?id=defaults"
|
||||
end
|
||||
end
|
||||
|
||||
def test_entry_id_should_be_a_valid_tag
|
||||
with_restful_routing(:scrolls) do
|
||||
get :index, params: { id: "defaults" }
|
||||
assert_select "entry id", :text => "tag:www.nextangle.com,2008:Scroll/1"
|
||||
assert_select "entry id", :text => "tag:www.nextangle.com,2008:Scroll/2"
|
||||
assert_select "entry id", text: "tag:www.nextangle.com,2008:Scroll/1"
|
||||
assert_select "entry id", text: "tag:www.nextangle.com,2008:Scroll/2"
|
||||
end
|
||||
end
|
||||
|
||||
def test_feed_should_allow_nested_xml_blocks
|
||||
with_restful_routing(:scrolls) do
|
||||
get :index, params: { id: "xml_block" }
|
||||
assert_select "author name", :text => "DHH"
|
||||
assert_select "author name", text: "DHH"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -309,9 +309,9 @@ class AtomFeedTest < ActionController::TestCase
|
|||
def test_feed_should_allow_overriding_ids
|
||||
with_restful_routing(:scrolls) do
|
||||
get :index, params: { id: "feed_with_overridden_ids" }
|
||||
assert_select "id", :text => "tag:test.rubyonrails.org,2008:test/"
|
||||
assert_select "entry id", :text => "tag:test.rubyonrails.org,2008:1"
|
||||
assert_select "entry id", :text => "tag:test.rubyonrails.org,2008:2"
|
||||
assert_select "id", text: "tag:test.rubyonrails.org,2008:test/"
|
||||
assert_select "entry id", text: "tag:test.rubyonrails.org,2008:1"
|
||||
assert_select "entry id", text: "tag:test.rubyonrails.org,2008:2"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -335,8 +335,8 @@ class AtomFeedTest < ActionController::TestCase
|
|||
with_restful_routing(:scrolls) do
|
||||
get :index, params: { id: "feed_with_xhtml_content" }
|
||||
assert_match %r{xmlns="http://www.w3.org/1999/xhtml"}, @response.body
|
||||
assert_select "summary", :text => /Something Boring/
|
||||
assert_select "summary", :text => /after 2/
|
||||
assert_select "summary", text: /Something Boring/
|
||||
assert_select "summary", text: /after 2/
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,28 +6,28 @@ class CompiledTemplatesTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_template_with_nil_erb_return
|
||||
assert_equal "This is nil: \n", render(:template => "test/nil_return")
|
||||
assert_equal "This is nil: \n", render(template: "test/nil_return")
|
||||
end
|
||||
|
||||
def test_template_gets_recompiled_when_using_different_keys_in_local_assigns
|
||||
assert_equal "one", render(:file => "test/render_file_with_locals_and_default")
|
||||
assert_equal "two", render(:file => "test/render_file_with_locals_and_default", :locals => { :secret => "two" })
|
||||
assert_equal "one", render(file: "test/render_file_with_locals_and_default")
|
||||
assert_equal "two", render(file: "test/render_file_with_locals_and_default", locals: { secret: "two" })
|
||||
end
|
||||
|
||||
def test_template_changes_are_not_reflected_with_cached_templates
|
||||
assert_equal "Hello world!", render(:file => "test/hello_world")
|
||||
assert_equal "Hello world!", render(file: "test/hello_world")
|
||||
modify_template "test/hello_world.erb", "Goodbye world!" do
|
||||
assert_equal "Hello world!", render(:file => "test/hello_world")
|
||||
assert_equal "Hello world!", render(file: "test/hello_world")
|
||||
end
|
||||
assert_equal "Hello world!", render(:file => "test/hello_world")
|
||||
assert_equal "Hello world!", render(file: "test/hello_world")
|
||||
end
|
||||
|
||||
def test_template_changes_are_reflected_with_uncached_templates
|
||||
assert_equal "Hello world!", render_without_cache(:file => "test/hello_world")
|
||||
assert_equal "Hello world!", render_without_cache(file: "test/hello_world")
|
||||
modify_template "test/hello_world.erb", "Goodbye world!" do
|
||||
assert_equal "Goodbye world!", render_without_cache(:file => "test/hello_world")
|
||||
assert_equal "Goodbye world!", render_without_cache(file: "test/hello_world")
|
||||
end
|
||||
assert_equal "Hello world!", render_without_cache(:file => "test/hello_world")
|
||||
assert_equal "Hello world!", render_without_cache(file: "test/hello_world")
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -12,24 +12,24 @@ class DateHelperDistanceOfTimeInWordsI18nTests < ActiveSupport::TestCase
|
|||
|
||||
def test_distance_of_time_in_words_calls_i18n
|
||||
{ # with include_seconds
|
||||
[2.seconds, { :include_seconds => true }] => [:'less_than_x_seconds', 5],
|
||||
[9.seconds, { :include_seconds => true }] => [:'less_than_x_seconds', 10],
|
||||
[19.seconds, { :include_seconds => true }] => [:'less_than_x_seconds', 20],
|
||||
[30.seconds, { :include_seconds => true }] => [:'half_a_minute', nil],
|
||||
[59.seconds, { :include_seconds => true }] => [:'less_than_x_minutes', 1],
|
||||
[60.seconds, { :include_seconds => true }] => [:'x_minutes', 1],
|
||||
[2.seconds, { include_seconds: true }] => [:'less_than_x_seconds', 5],
|
||||
[9.seconds, { include_seconds: true }] => [:'less_than_x_seconds', 10],
|
||||
[19.seconds, { include_seconds: true }] => [:'less_than_x_seconds', 20],
|
||||
[30.seconds, { include_seconds: true }] => [:'half_a_minute', nil],
|
||||
[59.seconds, { include_seconds: true }] => [:'less_than_x_minutes', 1],
|
||||
[60.seconds, { include_seconds: true }] => [:'x_minutes', 1],
|
||||
|
||||
# without include_seconds
|
||||
[29.seconds, { :include_seconds => false }] => [:'less_than_x_minutes', 1],
|
||||
[60.seconds, { :include_seconds => false }] => [:'x_minutes', 1],
|
||||
[44.minutes, { :include_seconds => false }] => [:'x_minutes', 44],
|
||||
[61.minutes, { :include_seconds => false }] => [:'about_x_hours', 1],
|
||||
[24.hours, { :include_seconds => false }] => [:'x_days', 1],
|
||||
[30.days, { :include_seconds => false }] => [:'about_x_months', 1],
|
||||
[60.days, { :include_seconds => false }] => [:'x_months', 2],
|
||||
[1.year, { :include_seconds => false }] => [:'about_x_years', 1],
|
||||
[3.years + 6.months, { :include_seconds => false }] => [:'over_x_years', 3],
|
||||
[3.years + 10.months, { :include_seconds => false }] => [:'almost_x_years', 4]
|
||||
[29.seconds, { include_seconds: false }] => [:'less_than_x_minutes', 1],
|
||||
[60.seconds, { include_seconds: false }] => [:'x_minutes', 1],
|
||||
[44.minutes, { include_seconds: false }] => [:'x_minutes', 44],
|
||||
[61.minutes, { include_seconds: false }] => [:'about_x_hours', 1],
|
||||
[24.hours, { include_seconds: false }] => [:'x_days', 1],
|
||||
[30.days, { include_seconds: false }] => [:'about_x_months', 1],
|
||||
[60.days, { include_seconds: false }] => [:'x_months', 2],
|
||||
[1.year, { include_seconds: false }] => [:'about_x_years', 1],
|
||||
[3.years + 6.months, { include_seconds: false }] => [:'over_x_years', 3],
|
||||
[3.years + 10.months, { include_seconds: false }] => [:'almost_x_years', 4]
|
||||
|
||||
}.each do |passed, expected|
|
||||
assert_distance_of_time_in_words_translates_key passed, expected
|
||||
|
@ -46,8 +46,8 @@ class DateHelperDistanceOfTimeInWordsI18nTests < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_time_ago_in_words_passes_locale
|
||||
assert_called_with(I18n, :t, [:less_than_x_minutes, :scope => :'datetime.distance_in_words', :count => 1, :locale => "ru"]) do
|
||||
time_ago_in_words(15.seconds.ago, :locale => "ru")
|
||||
assert_called_with(I18n, :t, [:less_than_x_minutes, scope: :'datetime.distance_in_words', count: 1, locale: "ru"]) do
|
||||
time_ago_in_words(15.seconds.ago, locale: "ru")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -69,7 +69,7 @@ class DateHelperDistanceOfTimeInWordsI18nTests < ActiveSupport::TestCase
|
|||
|
||||
}.each do |args, expected|
|
||||
key, count = *args
|
||||
assert_equal expected, I18n.t(key, :count => count, :scope => "datetime.distance_in_words")
|
||||
assert_equal expected, I18n.t(key, count: count, scope: "datetime.distance_in_words")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -95,28 +95,28 @@ class DateHelperSelectTagsI18nTests < ActiveSupport::TestCase
|
|||
|
||||
def test_select_month_given_use_month_names_option_does_not_translate_monthnames
|
||||
assert_not_called(I18n, :translate) do
|
||||
select_month(8, :locale => "en", :use_month_names => Date::MONTHNAMES)
|
||||
select_month(8, locale: "en", use_month_names: Date::MONTHNAMES)
|
||||
end
|
||||
end
|
||||
|
||||
def test_select_month_translates_monthnames
|
||||
assert_called_with(I18n, :translate, [:'date.month_names', :locale => "en"], returns: Date::MONTHNAMES) do
|
||||
select_month(8, :locale => "en")
|
||||
assert_called_with(I18n, :translate, [:'date.month_names', locale: "en"], returns: Date::MONTHNAMES) do
|
||||
select_month(8, locale: "en")
|
||||
end
|
||||
end
|
||||
|
||||
def test_select_month_given_use_short_month_option_translates_abbr_monthnames
|
||||
assert_called_with(I18n, :translate, [:'date.abbr_month_names', :locale => "en"], returns: Date::ABBR_MONTHNAMES) do
|
||||
select_month(8, :locale => "en", :use_short_month => true)
|
||||
assert_called_with(I18n, :translate, [:'date.abbr_month_names', locale: "en"], returns: Date::ABBR_MONTHNAMES) do
|
||||
select_month(8, locale: "en", use_short_month: true)
|
||||
end
|
||||
end
|
||||
|
||||
def test_date_or_time_select_translates_prompts
|
||||
prompt_defaults = {:year => "Year", :month => "Month", :day => "Day", :hour => "Hour", :minute => "Minute", :second => "Seconds"}
|
||||
defaults = {[:'date.order', :locale => "en", :default => []] => %w(year month day)}
|
||||
prompt_defaults = {year: "Year", month: "Month", day: "Day", hour: "Hour", minute: "Minute", second: "Seconds"}
|
||||
defaults = {[:'date.order', locale: "en", default: []] => %w(year month day)}
|
||||
|
||||
prompt_defaults.each do |key, prompt|
|
||||
defaults[[("datetime.prompts." + key.to_s).to_sym, :locale => "en"]] = prompt
|
||||
defaults[[("datetime.prompts." + key.to_s).to_sym, locale: "en"]] = prompt
|
||||
end
|
||||
|
||||
prompts_check = -> (prompt, x) do
|
||||
|
@ -129,7 +129,7 @@ class DateHelperSelectTagsI18nTests < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
I18n.stub(:translate, prompts_check) do
|
||||
datetime_select("post", "updated_at", :locale => "en", :include_seconds => true, :prompt => true, :use_month_names => Date::MONTHNAMES)
|
||||
datetime_select("post", "updated_at", locale: "en", include_seconds: true, prompt: true, use_month_names: Date::MONTHNAMES)
|
||||
end
|
||||
assert_equal defaults.count, @prompt_called
|
||||
end
|
||||
|
@ -138,27 +138,27 @@ class DateHelperSelectTagsI18nTests < ActiveSupport::TestCase
|
|||
|
||||
def test_date_or_time_select_given_an_order_options_does_not_translate_order
|
||||
assert_not_called(I18n, :translate) do
|
||||
datetime_select("post", "updated_at", :order => [:year, :month, :day], :locale => "en", :use_month_names => Date::MONTHNAMES)
|
||||
datetime_select("post", "updated_at", order: [:year, :month, :day], locale: "en", use_month_names: Date::MONTHNAMES)
|
||||
end
|
||||
end
|
||||
|
||||
def test_date_or_time_select_given_no_order_options_translates_order
|
||||
assert_called_with(I18n, :translate, [ [:'date.order', :locale => "en", :default => []], [:"date.month_names", {:locale=>"en"}] ], returns: %w(year month day)) do
|
||||
datetime_select("post", "updated_at", :locale => "en")
|
||||
assert_called_with(I18n, :translate, [ [:'date.order', locale: "en", default: []], [:"date.month_names", {locale: "en"}] ], returns: %w(year month day)) do
|
||||
datetime_select("post", "updated_at", locale: "en")
|
||||
end
|
||||
end
|
||||
|
||||
def test_date_or_time_select_given_invalid_order
|
||||
assert_called_with(I18n, :translate, [:'date.order', :locale => "en", :default => []], returns: %w(invalid month day)) do
|
||||
assert_called_with(I18n, :translate, [:'date.order', locale: "en", default: []], returns: %w(invalid month day)) do
|
||||
assert_raise StandardError do
|
||||
datetime_select("post", "updated_at", :locale => "en")
|
||||
datetime_select("post", "updated_at", locale: "en")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_date_or_time_select_given_symbol_keys
|
||||
assert_called_with(I18n, :translate, [ [:'date.order', :locale => "en", :default => []], [:"date.month_names", {:locale=>"en"}] ], returns: [:year, :month, :day]) do
|
||||
datetime_select("post", "updated_at", :locale => "en")
|
||||
assert_called_with(I18n, :translate, [ [:'date.order', locale: "en", default: []], [:"date.month_names", {locale: "en"}] ], returns: [:year, :month, :day]) do
|
||||
datetime_select("post", "updated_at", locale: "en")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -216,7 +216,7 @@ class TemplateDigestorTest < ActionView::TestCase
|
|||
|
||||
def test_details_are_included_in_cache_key
|
||||
# Cache the template digest.
|
||||
@finder = FixtureFinder.new({:formats => [:html]})
|
||||
@finder = FixtureFinder.new({formats: [:html]})
|
||||
old_digest = digest("events/_event")
|
||||
|
||||
# Change the template; the cached digest remains unchanged.
|
||||
|
|
|
@ -5,7 +5,7 @@ end
|
|||
|
||||
class FormCollectionsHelperTest < ActionView::TestCase
|
||||
def assert_no_select(selector, value = nil)
|
||||
assert_select(selector, :text => value, :count => 0)
|
||||
assert_select(selector, text: value, count: 0)
|
||||
end
|
||||
|
||||
def with_collection_radio_buttons(*args, &block)
|
||||
|
@ -45,7 +45,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test "collection radio accepts checked item" do
|
||||
with_collection_radio_buttons :user, :active, [[1, true], [0, false]], :last, :first, :checked => true
|
||||
with_collection_radio_buttons :user, :active, [[1, true], [0, false]], :last, :first, checked: true
|
||||
|
||||
assert_select "input[type=radio][value=true][checked=checked]"
|
||||
assert_no_select "input[type=radio][value=false][checked=checked]"
|
||||
|
@ -53,7 +53,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
|
||||
test "collection radio accepts multiple disabled items" do
|
||||
collection = [[1, true], [0, false], [2, "other"]]
|
||||
with_collection_radio_buttons :user, :active, collection, :last, :first, :disabled => [true, false]
|
||||
with_collection_radio_buttons :user, :active, collection, :last, :first, disabled: [true, false]
|
||||
|
||||
assert_select "input[type=radio][value=true][disabled=disabled]"
|
||||
assert_select "input[type=radio][value=false][disabled=disabled]"
|
||||
|
@ -62,7 +62,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
|
||||
test "collection radio accepts single disabled item" do
|
||||
collection = [[1, true], [0, false]]
|
||||
with_collection_radio_buttons :user, :active, collection, :last, :first, :disabled => true
|
||||
with_collection_radio_buttons :user, :active, collection, :last, :first, disabled: true
|
||||
|
||||
assert_select "input[type=radio][value=true][disabled=disabled]"
|
||||
assert_no_select "input[type=radio][value=false][disabled=disabled]"
|
||||
|
@ -70,7 +70,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
|
||||
test "collection radio accepts multiple readonly items" do
|
||||
collection = [[1, true], [0, false], [2, "other"]]
|
||||
with_collection_radio_buttons :user, :active, collection, :last, :first, :readonly => [true, false]
|
||||
with_collection_radio_buttons :user, :active, collection, :last, :first, readonly: [true, false]
|
||||
|
||||
assert_select "input[type=radio][value=true][readonly=readonly]"
|
||||
assert_select "input[type=radio][value=false][readonly=readonly]"
|
||||
|
@ -79,7 +79,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
|
||||
test "collection radio accepts single readonly item" do
|
||||
collection = [[1, true], [0, false]]
|
||||
with_collection_radio_buttons :user, :active, collection, :last, :first, :readonly => true
|
||||
with_collection_radio_buttons :user, :active, collection, :last, :first, readonly: true
|
||||
|
||||
assert_select "input[type=radio][value=true][readonly=readonly]"
|
||||
assert_no_select "input[type=radio][value=false][readonly=readonly]"
|
||||
|
@ -87,7 +87,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
|
||||
test "collection radio accepts html options as input" do
|
||||
collection = [[1, true], [0, false]]
|
||||
with_collection_radio_buttons :user, :active, collection, :last, :first, {}, :class => "special-radio"
|
||||
with_collection_radio_buttons :user, :active, collection, :last, :first, {}, class: "special-radio"
|
||||
|
||||
assert_select "input[type=radio][value=true].special-radio#user_active_true"
|
||||
assert_select "input[type=radio][value=false].special-radio#user_active_false"
|
||||
|
@ -146,7 +146,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
|
||||
test "collection radio with block helpers accept extra html options" do
|
||||
with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b|
|
||||
b.label(:class => "radio_button") + b.radio_button(:class => "radio_button")
|
||||
b.label(class: "radio_button") + b.radio_button(class: "radio_button")
|
||||
end
|
||||
|
||||
assert_select "label.radio_button[for=user_active_true] + input#user_active_true.radio_button[type=radio]"
|
||||
|
@ -155,7 +155,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
|
||||
test "collection radio with block helpers allows access to current text and value" do
|
||||
with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b|
|
||||
b.label(:"data-value" => b.value) { b.radio_button + b.text }
|
||||
b.label("data-value": b.value) { b.radio_button + b.text }
|
||||
end
|
||||
|
||||
assert_select "label[for=user_active_true][data-value=true]", "true" do
|
||||
|
@ -168,7 +168,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
|
||||
test "collection radio with block helpers allows access to the current object item in the collection to access extra properties" do
|
||||
with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b|
|
||||
b.label(:class => b.object) { b.radio_button + b.text }
|
||||
b.label(class: b.object) { b.radio_button + b.text }
|
||||
end
|
||||
|
||||
assert_select "label.true[for=user_active_true]", "true" do
|
||||
|
@ -193,7 +193,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test "collection radio accepts checked item which has a value of false" do
|
||||
with_collection_radio_buttons :user, :active, [[1, true], [0, false]], :last, :first, :checked => false
|
||||
with_collection_radio_buttons :user, :active, [[1, true], [0, false]], :last, :first, checked: false
|
||||
assert_no_select "input[type=radio][value=true][checked=checked]"
|
||||
assert_select "input[type=radio][value=false][checked=checked]"
|
||||
end
|
||||
|
@ -246,14 +246,14 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
collection = [Category.new(1, "Category 1"), Category.new(2, "Category 2")]
|
||||
with_collection_check_boxes :user, :category_ids, collection, :id, :name
|
||||
|
||||
assert_select "input[type=hidden][name='user[category_ids][]'][value='']", :count => 1
|
||||
assert_select "input[type=hidden][name='user[category_ids][]'][value='']", count: 1
|
||||
end
|
||||
|
||||
test "collection check boxes generates a hidden field using the given :name in :html_options" do
|
||||
collection = [Category.new(1, "Category 1"), Category.new(2, "Category 2")]
|
||||
with_collection_check_boxes :user, :category_ids, collection, :id, :name, {}, {name: "user[other_category_ids][]"}
|
||||
|
||||
assert_select "input[type=hidden][name='user[other_category_ids][]'][value='']", :count => 1
|
||||
assert_select "input[type=hidden][name='user[other_category_ids][]'][value='']", count: 1
|
||||
end
|
||||
|
||||
test "collection check boxes generates a hidden field with index if it was provided" do
|
||||
|
@ -267,7 +267,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
collection = [Category.new(1, "Category 1"), Category.new(2, "Category 2")]
|
||||
with_collection_check_boxes :user, :category_ids, collection, :id, :name, include_hidden: false
|
||||
|
||||
assert_select "input[type=hidden][name='user[category_ids][]'][value='']", :count => 0
|
||||
assert_select "input[type=hidden][name='user[category_ids][]'][value='']", count: 0
|
||||
end
|
||||
|
||||
test "collection check boxes does not generate a hidden field if include_hidden option is false with key as string" do
|
||||
|
@ -337,7 +337,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
|
||||
test "collection check boxes accepts selected values as :checked option" do
|
||||
collection = (1..3).map{|i| [i, "Category #{i}"] }
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, :checked => [1, 3]
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, checked: [1, 3]
|
||||
|
||||
assert_select 'input[type=checkbox][value="1"][checked=checked]'
|
||||
assert_select 'input[type=checkbox][value="3"][checked=checked]'
|
||||
|
@ -346,7 +346,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
|
||||
test "collection check boxes accepts selected string values as :checked option" do
|
||||
collection = (1..3).map{|i| [i, "Category #{i}"] }
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, :checked => ["1", "3"]
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, checked: ["1", "3"]
|
||||
|
||||
assert_select 'input[type=checkbox][value="1"][checked=checked]'
|
||||
assert_select 'input[type=checkbox][value="3"][checked=checked]'
|
||||
|
@ -355,7 +355,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
|
||||
test "collection check boxes accepts a single checked value" do
|
||||
collection = (1..3).map{|i| [i, "Category #{i}"] }
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, :checked => 3
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, checked: 3
|
||||
|
||||
assert_select 'input[type=checkbox][value="3"][checked=checked]'
|
||||
assert_no_select 'input[type=checkbox][value="1"][checked=checked]'
|
||||
|
@ -367,7 +367,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
collection = (1..3).map{|i| [i, "Category #{i}"] }
|
||||
|
||||
@output_buffer = fields_for(:user, user) do |p|
|
||||
p.collection_check_boxes :category_ids, collection, :first, :last, :checked => [1, 3]
|
||||
p.collection_check_boxes :category_ids, collection, :first, :last, checked: [1, 3]
|
||||
end
|
||||
|
||||
assert_select 'input[type=checkbox][value="1"][checked=checked]'
|
||||
|
@ -377,7 +377,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
|
||||
test "collection check boxes accepts multiple disabled items" do
|
||||
collection = (1..3).map{|i| [i, "Category #{i}"] }
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, :disabled => [1, 3]
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, disabled: [1, 3]
|
||||
|
||||
assert_select 'input[type=checkbox][value="1"][disabled=disabled]'
|
||||
assert_select 'input[type=checkbox][value="3"][disabled=disabled]'
|
||||
|
@ -386,7 +386,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
|
||||
test "collection check boxes accepts single disabled item" do
|
||||
collection = (1..3).map{|i| [i, "Category #{i}"] }
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, :disabled => 1
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, disabled: 1
|
||||
|
||||
assert_select 'input[type=checkbox][value="1"][disabled=disabled]'
|
||||
assert_no_select 'input[type=checkbox][value="3"][disabled=disabled]'
|
||||
|
@ -395,7 +395,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
|
||||
test "collection check boxes accepts a proc to disabled items" do
|
||||
collection = (1..3).map{|i| [i, "Category #{i}"] }
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, :disabled => proc { |i| i.first == 1 }
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, disabled: proc { |i| i.first == 1 }
|
||||
|
||||
assert_select 'input[type=checkbox][value="1"][disabled=disabled]'
|
||||
assert_no_select 'input[type=checkbox][value="3"][disabled=disabled]'
|
||||
|
@ -404,7 +404,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
|
||||
test "collection check boxes accepts multiple readonly items" do
|
||||
collection = (1..3).map{|i| [i, "Category #{i}"] }
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, :readonly => [1, 3]
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, readonly: [1, 3]
|
||||
|
||||
assert_select 'input[type=checkbox][value="1"][readonly=readonly]'
|
||||
assert_select 'input[type=checkbox][value="3"][readonly=readonly]'
|
||||
|
@ -413,7 +413,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
|
||||
test "collection check boxes accepts single readonly item" do
|
||||
collection = (1..3).map{|i| [i, "Category #{i}"] }
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, :readonly => 1
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, readonly: 1
|
||||
|
||||
assert_select 'input[type=checkbox][value="1"][readonly=readonly]'
|
||||
assert_no_select 'input[type=checkbox][value="3"][readonly=readonly]'
|
||||
|
@ -422,7 +422,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
|
||||
test "collection check boxes accepts a proc to readonly items" do
|
||||
collection = (1..3).map{|i| [i, "Category #{i}"] }
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, :readonly => proc { |i| i.first == 1 }
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, readonly: proc { |i| i.first == 1 }
|
||||
|
||||
assert_select 'input[type=checkbox][value="1"][readonly=readonly]'
|
||||
assert_no_select 'input[type=checkbox][value="3"][readonly=readonly]'
|
||||
|
@ -431,7 +431,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
|
||||
test "collection check boxes accepts html options" do
|
||||
collection = [[1, "Category 1"], [2, "Category 2"]]
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, {}, :class => "check"
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, {}, class: "check"
|
||||
|
||||
assert_select 'input.check[type=checkbox][value="1"]'
|
||||
assert_select 'input.check[type=checkbox][value="2"]'
|
||||
|
@ -477,7 +477,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
|
||||
test "collection check boxes with block helpers accept extra html options" do
|
||||
with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
|
||||
b.label(:class => "check_box") + b.check_box(:class => "check_box")
|
||||
b.label(class: "check_box") + b.check_box(class: "check_box")
|
||||
end
|
||||
|
||||
assert_select "label.check_box[for=user_active_true] + input#user_active_true.check_box[type=checkbox]"
|
||||
|
@ -486,7 +486,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
|
||||
test "collection check boxes with block helpers allows access to current text and value" do
|
||||
with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
|
||||
b.label(:"data-value" => b.value) { b.check_box + b.text }
|
||||
b.label("data-value": b.value) { b.check_box + b.text }
|
||||
end
|
||||
|
||||
assert_select "label[for=user_active_true][data-value=true]", "true" do
|
||||
|
@ -499,7 +499,7 @@ class FormCollectionsHelperTest < ActionView::TestCase
|
|||
|
||||
test "collection check boxes with block helpers allows access to the current object item in the collection to access extra properties" do
|
||||
with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b|
|
||||
b.label(:class => b.object) { b.check_box + b.text }
|
||||
b.label(class: b.object) { b.check_box + b.text }
|
||||
end
|
||||
|
||||
assert_select "label.true[for=user_active_true]", "true" do
|
||||
|
|
|
@ -22,7 +22,7 @@ class FormHelperTest < ActionView::TestCase
|
|||
post: {
|
||||
cost: "Total cost"
|
||||
},
|
||||
:"post/language" => {
|
||||
"post/language": {
|
||||
spanish: "Espanol"
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ class FormHelperTest < ActionView::TestCase
|
|||
post: {
|
||||
cost: "Total cost"
|
||||
},
|
||||
:"post/cost" => {
|
||||
"post/cost": {
|
||||
uk: "Pounds"
|
||||
}
|
||||
}
|
||||
|
@ -535,12 +535,12 @@ class FormHelperTest < ActionView::TestCase
|
|||
|
||||
def test_file_field_with_multiple_behavior
|
||||
expected = '<input id="import_file" multiple="multiple" name="import[file][]" type="file" />'
|
||||
assert_dom_equal expected, file_field("import", "file", :multiple => true)
|
||||
assert_dom_equal expected, file_field("import", "file", multiple: true)
|
||||
end
|
||||
|
||||
def test_file_field_with_multiple_behavior_and_explicit_name
|
||||
expected = '<input id="import_file" multiple="multiple" name="custom" type="file" />'
|
||||
assert_dom_equal expected, file_field("import", "file", :multiple => true, :name => "custom")
|
||||
assert_dom_equal expected, file_field("import", "file", multiple: true, name: "custom")
|
||||
end
|
||||
|
||||
def test_hidden_field
|
||||
|
|
|
@ -6,7 +6,7 @@ class FormOptionsHelperI18nTests < ActionView::TestCase
|
|||
def setup
|
||||
@prompt_message = "Select!"
|
||||
I18n.backend.send(:init_translations)
|
||||
I18n.backend.store_translations :en, :helpers => { :select => { :prompt => @prompt_message } }
|
||||
I18n.backend.store_translations :en, helpers: { select: { prompt: @prompt_message } }
|
||||
end
|
||||
|
||||
def teardown
|
||||
|
@ -14,15 +14,15 @@ class FormOptionsHelperI18nTests < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_select_with_prompt_true_translates_prompt_message
|
||||
assert_called_with(I18n, :translate, ["helpers.select.prompt", { :default => "Please select" }]) do
|
||||
select("post", "category", [], :prompt => true)
|
||||
assert_called_with(I18n, :translate, ["helpers.select.prompt", { default: "Please select" }]) do
|
||||
select("post", "category", [], prompt: true)
|
||||
end
|
||||
end
|
||||
|
||||
def test_select_with_translated_prompt
|
||||
assert_dom_equal(
|
||||
%Q(<select id="post_category" name="post[category]"><option value="">#{@prompt_message}</option>\n</select>),
|
||||
select("post", "category", [], :prompt => true)
|
||||
select("post", "category", [], prompt: true)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -82,28 +82,28 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
def test_collection_options_with_disabled_value
|
||||
assert_dom_equal(
|
||||
"<option value=\"<Abe>\"><Abe> went home</option>\n<option value=\"Babe\" disabled=\"disabled\">Babe went home</option>\n<option value=\"Cabe\">Cabe went home</option>",
|
||||
options_from_collection_for_select(dummy_posts, "author_name", "title", :disabled => "Babe")
|
||||
options_from_collection_for_select(dummy_posts, "author_name", "title", disabled: "Babe")
|
||||
)
|
||||
end
|
||||
|
||||
def test_collection_options_with_disabled_array
|
||||
assert_dom_equal(
|
||||
"<option value=\"<Abe>\"><Abe> went home</option>\n<option value=\"Babe\" disabled=\"disabled\">Babe went home</option>\n<option value=\"Cabe\" disabled=\"disabled\">Cabe went home</option>",
|
||||
options_from_collection_for_select(dummy_posts, "author_name", "title", :disabled => [ "Babe", "Cabe" ])
|
||||
options_from_collection_for_select(dummy_posts, "author_name", "title", disabled: [ "Babe", "Cabe" ])
|
||||
)
|
||||
end
|
||||
|
||||
def test_collection_options_with_preselected_and_disabled_value
|
||||
assert_dom_equal(
|
||||
"<option value=\"<Abe>\"><Abe> went home</option>\n<option value=\"Babe\" disabled=\"disabled\">Babe went home</option>\n<option value=\"Cabe\" selected=\"selected\">Cabe went home</option>",
|
||||
options_from_collection_for_select(dummy_posts, "author_name", "title", :selected => "Cabe", :disabled => "Babe")
|
||||
options_from_collection_for_select(dummy_posts, "author_name", "title", selected: "Cabe", disabled: "Babe")
|
||||
)
|
||||
end
|
||||
|
||||
def test_collection_options_with_proc_for_disabled
|
||||
assert_dom_equal(
|
||||
"<option value=\"<Abe>\"><Abe> went home</option>\n<option value=\"Babe\" disabled=\"disabled\">Babe went home</option>\n<option value=\"Cabe\" disabled=\"disabled\">Cabe went home</option>",
|
||||
options_from_collection_for_select(dummy_posts, "author_name", "title", :disabled => lambda {|p| %w(Babe Cabe).include?(p.author_name)})
|
||||
options_from_collection_for_select(dummy_posts, "author_name", "title", disabled: lambda {|p| %w(Babe Cabe).include?(p.author_name)})
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -124,7 +124,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
def test_collection_options_with_element_attributes
|
||||
assert_dom_equal(
|
||||
"<option value=\"USA\" class=\"bold\">USA</option>",
|
||||
options_from_collection_for_select([[ "USA", "USA", { :class => "bold" } ]], :first, :second)
|
||||
options_from_collection_for_select([[ "USA", "USA", { class: "bold" } ]], :first, :second)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -180,28 +180,28 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
def test_array_options_for_select_with_disabled_value
|
||||
assert_dom_equal(
|
||||
"<option value=\"Denmark\">Denmark</option>\n<option value=\"<USA>\" disabled=\"disabled\"><USA></option>\n<option value=\"Sweden\">Sweden</option>",
|
||||
options_for_select([ "Denmark", "<USA>", "Sweden" ], :disabled => "<USA>")
|
||||
options_for_select([ "Denmark", "<USA>", "Sweden" ], disabled: "<USA>")
|
||||
)
|
||||
end
|
||||
|
||||
def test_array_options_for_select_with_disabled_array
|
||||
assert_dom_equal(
|
||||
"<option value=\"Denmark\">Denmark</option>\n<option value=\"<USA>\" disabled=\"disabled\"><USA></option>\n<option value=\"Sweden\" disabled=\"disabled\">Sweden</option>",
|
||||
options_for_select([ "Denmark", "<USA>", "Sweden" ], :disabled => ["<USA>", "Sweden"])
|
||||
options_for_select([ "Denmark", "<USA>", "Sweden" ], disabled: ["<USA>", "Sweden"])
|
||||
)
|
||||
end
|
||||
|
||||
def test_array_options_for_select_with_selection_and_disabled_value
|
||||
assert_dom_equal(
|
||||
"<option value=\"Denmark\" selected=\"selected\">Denmark</option>\n<option value=\"<USA>\" disabled=\"disabled\"><USA></option>\n<option value=\"Sweden\">Sweden</option>",
|
||||
options_for_select([ "Denmark", "<USA>", "Sweden" ], :selected => "Denmark", :disabled => "<USA>")
|
||||
options_for_select([ "Denmark", "<USA>", "Sweden" ], selected: "Denmark", disabled: "<USA>")
|
||||
)
|
||||
end
|
||||
|
||||
def test_boolean_array_options_for_select_with_selection_and_disabled_value
|
||||
assert_dom_equal(
|
||||
"<option value=\"true\">true</option>\n<option value=\"false\" selected=\"selected\">false</option>",
|
||||
options_for_select([ true, false ], :selected => false, :disabled => nil)
|
||||
options_for_select([ true, false ], selected: false, disabled: nil)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -262,7 +262,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
albums = [ Album.new(1, "first","rap"), Album.new(2, "second","pop")]
|
||||
assert_dom_equal(
|
||||
%(<option selected="selected" value="1">rap</option>\n<option value="2">pop</option>),
|
||||
options_from_collection_for_select(albums, "id", "genre", :selected => "1")
|
||||
options_from_collection_for_select(albums, "id", "genre", selected: "1")
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -271,7 +271,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
|
||||
assert_dom_equal(
|
||||
%(<option selected="selected" value="1">rap</option>\n<option value="2">pop</option>),
|
||||
options_from_collection_for_select(albums, "id", "genre", :selected => 1)
|
||||
options_from_collection_for_select(albums, "id", "genre", selected: 1)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -280,7 +280,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
|
||||
assert_dom_equal(
|
||||
%(<option value="1.0">rap</option>\n<option value="2.0" selected="selected">pop</option>),
|
||||
options_from_collection_for_select(albums, "id", "genre", :selected => "2.0")
|
||||
options_from_collection_for_select(albums, "id", "genre", selected: "2.0")
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -289,7 +289,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
|
||||
assert_dom_equal(
|
||||
%(<option value="1.0">rap</option>\n<option value="2.0">pop</option>),
|
||||
options_from_collection_for_select(albums, "id", "genre", :selected => nil)
|
||||
options_from_collection_for_select(albums, "id", "genre", selected: nil)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -298,7 +298,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
|
||||
assert_dom_equal(
|
||||
%(<option value="1.0">rap</option>\n<option value="2.0">pop</option>),
|
||||
options_from_collection_for_select(albums, "id", "genre", :disabled => nil)
|
||||
options_from_collection_for_select(albums, "id", "genre", disabled: nil)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -307,7 +307,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
|
||||
assert_dom_equal(
|
||||
%(<option disabled="disabled" value="1.0">rap</option>\n<option disabled="disabled" value="2.0">pop</option>),
|
||||
options_from_collection_for_select(albums, "id", "genre", :disabled => ["1.0", 2.0])
|
||||
options_from_collection_for_select(albums, "id", "genre", disabled: ["1.0", 2.0])
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -347,8 +347,8 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
assert_dom_equal(
|
||||
"<optgroup label=\"North America\" data-foo=\"bar\"><option value=\"US\">United States</option>\n<option value=\"Canada\">Canada</option></optgroup><optgroup label=\"Europe\" disabled=\"disabled\"><option value=\"GB\">Great Britain</option>\n<option value=\"Germany\">Germany</option></optgroup>",
|
||||
grouped_options_for_select([
|
||||
["North America", [["United States","US"],"Canada"], :data => { :foo => "bar" }],
|
||||
["Europe", [["Great Britain","GB"], "Germany"], :disabled => "disabled"]
|
||||
["North America", [["United States","US"],"Canada"], data: { foo: "bar" }],
|
||||
["Europe", [["Great Britain","GB"], "Germany"], disabled: "disabled"]
|
||||
])
|
||||
)
|
||||
end
|
||||
|
@ -481,7 +481,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
def test_select_without_multiple
|
||||
assert_dom_equal(
|
||||
"<select id=\"post_category\" name=\"post[category]\"></select>",
|
||||
select(:post, :category, "", {}, :multiple => false)
|
||||
select(:post, :category, "", {}, multiple: false)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -561,7 +561,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
@post = Post.new
|
||||
@post.category = "<mus>"
|
||||
|
||||
output_buffer = fields_for :post, @post, :index => 108 do |f|
|
||||
output_buffer = fields_for :post, @post, index: 108 do |f|
|
||||
concat f.select(:category, %w( abe <mus> hest))
|
||||
end
|
||||
|
||||
|
@ -591,7 +591,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
options = raw("<option value=\"abe\">abe</option><option value=\"mus\">mus</option><option value=\"hest\">hest</option>")
|
||||
|
||||
output_buffer = fields_for :post, @post do |f|
|
||||
concat f.select(:category, options, :prompt => "The prompt")
|
||||
concat f.select(:category, options, prompt: "The prompt")
|
||||
end
|
||||
|
||||
assert_dom_equal(
|
||||
|
@ -629,7 +629,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_select_with_multiple_to_add_hidden_input
|
||||
output_buffer = select(:post, :category, "", {}, :multiple => true)
|
||||
output_buffer = select(:post, :category, "", {}, multiple: true)
|
||||
assert_dom_equal(
|
||||
"<input type=\"hidden\" name=\"post[category][]\" value=\"\"/><select multiple=\"multiple\" id=\"post_category\" name=\"post[category][]\"></select>",
|
||||
output_buffer
|
||||
|
@ -637,7 +637,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_select_with_multiple_and_without_hidden_input
|
||||
output_buffer = select(:post, :category, "", {:include_hidden => false}, :multiple => true)
|
||||
output_buffer = select(:post, :category, "", {include_hidden: false}, multiple: true)
|
||||
assert_dom_equal(
|
||||
"<select multiple=\"multiple\" id=\"post_category\" name=\"post[category][]\"></select>",
|
||||
output_buffer
|
||||
|
@ -653,7 +653,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_select_with_multiple_and_disabled_to_add_disabled_hidden_input
|
||||
output_buffer = select(:post, :category, "", {}, :multiple => true, :disabled => true)
|
||||
output_buffer = select(:post, :category, "", {}, multiple: true, disabled: true)
|
||||
assert_dom_equal(
|
||||
"<input disabled=\"disabled\"type=\"hidden\" name=\"post[category][]\" value=\"\"/><select multiple=\"multiple\" disabled=\"disabled\" id=\"post_category\" name=\"post[category][]\"></select>",
|
||||
output_buffer
|
||||
|
@ -665,7 +665,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
@post.category = "<mus>"
|
||||
assert_dom_equal(
|
||||
"<select id=\"post_category\" name=\"post[category]\"><option value=\"\"></option>\n<option value=\"abe\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
||||
select("post", "category", %w( abe <mus> hest), :include_blank => true)
|
||||
select("post", "category", %w( abe <mus> hest), include_blank: true)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -681,7 +681,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
@post.category = "<mus>"
|
||||
assert_dom_equal(
|
||||
"<select id=\"post_category\" name=\"post[category]\"><option value=\"\">None</option>\n<option value=\"abe\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
||||
select("post", "category", %w( abe <mus> hest), :include_blank => "None")
|
||||
select("post", "category", %w( abe <mus> hest), include_blank: "None")
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -690,7 +690,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
@post.category = "<mus>"
|
||||
assert_dom_equal(
|
||||
"<select id=\"post_category\" name=\"post[category]\"><option value=\"\"><None></option>\n<option value=\"abe\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
||||
select("post", "category", %w( abe <mus> hest), :include_blank => "<None>")
|
||||
select("post", "category", %w( abe <mus> hest), include_blank: "<None>")
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -699,7 +699,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
@post.category = ""
|
||||
assert_dom_equal(
|
||||
"<select id=\"post_category\" name=\"post[category]\"><option value=\"\">Please select</option>\n<option value=\"abe\">abe</option>\n<option value=\"<mus>\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
||||
select("post", "category", %w( abe <mus> hest), :prompt => true)
|
||||
select("post", "category", %w( abe <mus> hest), prompt: true)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -708,7 +708,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
@post.category = "<mus>"
|
||||
assert_dom_equal(
|
||||
"<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
||||
select("post", "category", %w( abe <mus> hest), :prompt => true)
|
||||
select("post", "category", %w( abe <mus> hest), prompt: true)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -717,7 +717,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
@post.category = ""
|
||||
assert_dom_equal(
|
||||
"<select id=\"post_category\" name=\"post[category]\"><option value=\"\">The prompt</option>\n<option value=\"abe\">abe</option>\n<option value=\"<mus>\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
||||
select("post", "category", %w( abe <mus> hest), :prompt => "The prompt")
|
||||
select("post", "category", %w( abe <mus> hest), prompt: "The prompt")
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -725,7 +725,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
@post = Post.new
|
||||
assert_dom_equal(
|
||||
"<select id=\"post_category\" name=\"post[category]\"><option value=\"\"><The prompt></option>\n<option value=\"abe\">abe</option>\n<option value=\"<mus>\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
||||
select("post", "category", %w( abe <mus> hest), :prompt => "<The prompt>")
|
||||
select("post", "category", %w( abe <mus> hest), prompt: "<The prompt>")
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -734,7 +734,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
@post.category = ""
|
||||
assert_dom_equal(
|
||||
"<select id=\"post_category\" name=\"post[category]\"><option value=\"\">Please select</option>\n<option value=\"\"></option>\n<option value=\"abe\">abe</option>\n<option value=\"<mus>\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
||||
select("post", "category", %w( abe <mus> hest), :prompt => true, :include_blank => true)
|
||||
select("post", "category", %w( abe <mus> hest), prompt: true, include_blank: true)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -743,7 +743,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
@post.category = ""
|
||||
assert_dom_equal(
|
||||
"<select id=\"post_category\" name=\"post[category]\"><option value=\"\">Please select</option>\n<option value=\"\"></option>\n</select>",
|
||||
select("post", "category", [], :prompt => true, :include_blank => true)
|
||||
select("post", "category", [], prompt: true, include_blank: true)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -812,7 +812,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
@post.category = ""
|
||||
assert_dom_equal(
|
||||
"<select id=\"post_category\" name=\"post[category]\"><option value=\"\">Please select</option>\n<option value=\"\"></option>\n<option value=\"1\">1</option></select>",
|
||||
select("post", "category", [1], :prompt => true, :include_blank => true)
|
||||
select("post", "category", [1], prompt: true, include_blank: true)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -821,7 +821,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
@post.category = ""
|
||||
assert_dom_equal(
|
||||
"<select id=\"post_category\" name=\"post[category]\"><option value=\"\">Please select</option>\n<option value=\"\"></option>\n<option value=\"number\">Number</option>\n<option value=\"text\">Text</option>\n<option value=\"boolean\">Yes/No</option></select>",
|
||||
select("post", "category", [["Number", "number"], ["Text", "text"], ["Yes/No", "boolean"]], :prompt => true, :include_blank => true)
|
||||
select("post", "category", [["Number", "number"], ["Text", "text"], ["Yes/No", "boolean"]], prompt: true, include_blank: true)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -830,7 +830,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
@post.category = "<mus>"
|
||||
assert_dom_equal(
|
||||
"<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\" selected=\"selected\">abe</option>\n<option value=\"<mus>\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
||||
select("post", "category", %w( abe <mus> hest ), :selected => "abe")
|
||||
select("post", "category", %w( abe <mus> hest ), selected: "abe")
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -842,7 +842,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
|
||||
assert_dom_equal(
|
||||
expected,
|
||||
select("album[]", "genre", %w[rap rock country], {}, { :index => nil })
|
||||
select("album[]", "genre", %w[rap rock country], {}, { index: nil })
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -858,7 +858,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
@post.category = "<mus>"
|
||||
assert_dom_equal(
|
||||
"<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"<mus>\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
||||
select("post", "category", %w( abe <mus> hest ), :selected => nil)
|
||||
select("post", "category", %w( abe <mus> hest ), selected: nil)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -867,7 +867,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
@post.category = "<mus>"
|
||||
assert_dom_equal(
|
||||
"<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\" disabled=\"disabled\">hest</option></select>",
|
||||
select("post", "category", %w( abe <mus> hest ), :disabled => "hest")
|
||||
select("post", "category", %w( abe <mus> hest ), disabled: "hest")
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -875,7 +875,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
@post = Post.new
|
||||
assert_dom_equal(
|
||||
"<select id=\"post_locale\" name=\"post[locale]\"><option value=\"en\">en</option>\n<option value=\"ru\" selected=\"selected\">ru</option></select>",
|
||||
select("post", "locale", %w( en ru ), :selected => "ru")
|
||||
select("post", "locale", %w( en ru ), selected: "ru")
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -883,7 +883,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
@post = Post.new
|
||||
assert_dom_equal(
|
||||
"<select id=\"post_category\" name=\"post[category]\"><option value=\"one\">one</option>\n<option selected=\"selected\" value=\"two\">two</option></select>",
|
||||
select("post", "category", %w( one two ), :selected => "two", :prompt => true)
|
||||
select("post", "category", %w( one two ), selected: "two", prompt: true)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -892,7 +892,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
@post.category = "<mus>"
|
||||
assert_dom_equal(
|
||||
"<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\" disabled=\"disabled\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\" disabled=\"disabled\">hest</option></select>",
|
||||
select("post", "category", %w( abe <mus> hest ), :disabled => ["hest", "abe"])
|
||||
select("post", "category", %w( abe <mus> hest ), disabled: ["hest", "abe"])
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -933,7 +933,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
@post = Post.new
|
||||
@post.author_name = "Babe"
|
||||
|
||||
output_buffer = fields_for :post, @post, :index => 815 do |f|
|
||||
output_buffer = fields_for :post, @post, index: 815 do |f|
|
||||
concat f.collection_select(:author_name, dummy_posts, :author_name, :author_name)
|
||||
end
|
||||
|
||||
|
@ -964,7 +964,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
|
||||
assert_dom_equal(
|
||||
"<select id=\"post_author_name\" name=\"post[author_name]\" style=\"width: 200px\"><option value=\"\"></option>\n<option value=\"<Abe>\"><Abe></option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
|
||||
collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { :include_blank => true }, "style" => "width: 200px")
|
||||
collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { include_blank: true }, "style" => "width: 200px")
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -974,7 +974,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
|
||||
assert_dom_equal(
|
||||
"<select id=\"post_author_name\" name=\"post[author_name]\" style=\"width: 200px\"><option value=\"\">No Selection</option>\n<option value=\"<Abe>\"><Abe></option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
|
||||
collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { :include_blank => "No Selection" }, "style" => "width: 200px")
|
||||
collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { include_blank: "No Selection" }, "style" => "width: 200px")
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -985,10 +985,10 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
expected = "<input type=\"hidden\" name=\"post[author_name][]\" value=\"\"/><select id=\"post_author_name\" name=\"post[author_name][]\" multiple=\"multiple\"><option value=\"\"></option>\n<option value=\"<Abe>\"><Abe></option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>"
|
||||
|
||||
# Should suffix default name with [].
|
||||
assert_dom_equal expected, collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { :include_blank => true }, :multiple => true)
|
||||
assert_dom_equal expected, collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { include_blank: true }, multiple: true)
|
||||
|
||||
# Shouldn't suffix custom name with [].
|
||||
assert_dom_equal expected, collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { :include_blank => true, :name => "post[author_name][]" }, :multiple => true)
|
||||
assert_dom_equal expected, collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { include_blank: true, name: "post[author_name][]" }, multiple: true)
|
||||
end
|
||||
|
||||
def test_collection_select_with_blank_and_selected
|
||||
|
@ -997,7 +997,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
|
||||
assert_dom_equal(
|
||||
%{<select id="post_author_name" name="post[author_name]"><option value=""></option>\n<option value="<Abe>" selected="selected"><Abe></option>\n<option value="Babe">Babe</option>\n<option value="Cabe">Cabe</option></select>},
|
||||
collection_select("post", "author_name", dummy_posts, "author_name", "author_name", {:include_blank => true, :selected => "<Abe>"})
|
||||
collection_select("post", "author_name", dummy_posts, "author_name", "author_name", {include_blank: true, selected: "<Abe>"})
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -1007,7 +1007,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
|
||||
assert_dom_equal(
|
||||
"<select id=\"post_author_name\" name=\"post[author_name]\"><option value=\"<Abe>\"><Abe></option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\" disabled=\"disabled\">Cabe</option></select>",
|
||||
collection_select("post", "author_name", dummy_posts, "author_name", "author_name", :disabled => "Cabe")
|
||||
collection_select("post", "author_name", dummy_posts, "author_name", "author_name", disabled: "Cabe")
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -1064,7 +1064,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
def test_time_zone_select_under_fields_for_with_index
|
||||
@firm = Firm.new("D")
|
||||
|
||||
output_buffer = fields_for :firm, @firm, :index => 305 do |f|
|
||||
output_buffer = fields_for :firm, @firm, index: 305 do |f|
|
||||
concat f.time_zone_select(:time_zone)
|
||||
end
|
||||
|
||||
|
@ -1102,7 +1102,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
|
||||
def test_time_zone_select_with_blank
|
||||
@firm = Firm.new("D")
|
||||
html = time_zone_select("firm", "time_zone", nil, :include_blank => true)
|
||||
html = time_zone_select("firm", "time_zone", nil, include_blank: true)
|
||||
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
|
||||
"<option value=\"\"></option>\n" +
|
||||
"<option value=\"A\">A</option>\n" +
|
||||
|
@ -1116,7 +1116,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
|
||||
def test_time_zone_select_with_blank_as_string
|
||||
@firm = Firm.new("D")
|
||||
html = time_zone_select("firm", "time_zone", nil, :include_blank => "No Zone")
|
||||
html = time_zone_select("firm", "time_zone", nil, include_blank: "No Zone")
|
||||
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
|
||||
"<option value=\"\">No Zone</option>\n" +
|
||||
"<option value=\"A\">A</option>\n" +
|
||||
|
@ -1141,13 +1141,13 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
"</select>",
|
||||
html
|
||||
assert_dom_equal html, time_zone_select("firm", "time_zone", nil, {},
|
||||
:style => "color: red")
|
||||
style: "color: red")
|
||||
end
|
||||
|
||||
def test_time_zone_select_with_blank_and_style
|
||||
@firm = Firm.new("D")
|
||||
html = time_zone_select("firm", "time_zone", nil,
|
||||
{ :include_blank => true }, "style" => "color: red")
|
||||
{ include_blank: true }, "style" => "color: red")
|
||||
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\" style=\"color: red\">" +
|
||||
"<option value=\"\"></option>\n" +
|
||||
"<option value=\"A\">A</option>\n" +
|
||||
|
@ -1158,13 +1158,13 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
"</select>",
|
||||
html
|
||||
assert_dom_equal html, time_zone_select("firm", "time_zone", nil,
|
||||
{ :include_blank => true }, :style => "color: red")
|
||||
{ include_blank: true }, style: "color: red")
|
||||
end
|
||||
|
||||
def test_time_zone_select_with_blank_as_string_and_style
|
||||
@firm = Firm.new("D")
|
||||
html = time_zone_select("firm", "time_zone", nil,
|
||||
{ :include_blank => "No Zone" }, "style" => "color: red")
|
||||
{ include_blank: "No Zone" }, "style" => "color: red")
|
||||
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\" style=\"color: red\">" +
|
||||
"<option value=\"\">No Zone</option>\n" +
|
||||
"<option value=\"A\">A</option>\n" +
|
||||
|
@ -1175,7 +1175,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
"</select>",
|
||||
html
|
||||
assert_dom_equal html, time_zone_select("firm", "time_zone", nil,
|
||||
{ :include_blank => "No Zone" }, :style => "color: red")
|
||||
{ include_blank: "No Zone" }, style: "color: red")
|
||||
end
|
||||
|
||||
def test_time_zone_select_with_priority_zones
|
||||
|
@ -1237,7 +1237,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
@firm = Firm.new()
|
||||
@firm.time_zone = nil
|
||||
|
||||
html = time_zone_select( "firm", "time_zone", nil, :default => "B" )
|
||||
html = time_zone_select( "firm", "time_zone", nil, default: "B" )
|
||||
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
|
||||
"<option value=\"A\">A</option>\n" +
|
||||
"<option value=\"B\" selected=\"selected\">B</option>\n" +
|
||||
|
@ -1251,7 +1251,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
def test_time_zone_select_with_default_time_zone_and_value
|
||||
@firm = Firm.new("D")
|
||||
|
||||
html = time_zone_select( "firm", "time_zone", nil, :default => "B" )
|
||||
html = time_zone_select( "firm", "time_zone", nil, default: "B" )
|
||||
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
|
||||
"<option value=\"A\">A</option>\n" +
|
||||
"<option value=\"B\">B</option>\n" +
|
||||
|
@ -1265,42 +1265,42 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
def test_options_for_select_with_element_attributes
|
||||
assert_dom_equal(
|
||||
"<option value=\"<Denmark>\" class=\"bold\"><Denmark></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" ])
|
||||
options_for_select([ [ "<Denmark>", { class: "bold" } ], [ "USA", { onclick: "alert('Hello World');" } ], [ "Sweden" ], "Germany" ])
|
||||
)
|
||||
end
|
||||
|
||||
def test_options_for_select_with_data_element
|
||||
assert_dom_equal(
|
||||
"<option value=\"<Denmark>\" data-test=\"bold\"><Denmark></option>",
|
||||
options_for_select([ [ "<Denmark>", { :data => { :test => "bold" } } ] ])
|
||||
options_for_select([ [ "<Denmark>", { data: { test: "bold" } } ] ])
|
||||
)
|
||||
end
|
||||
|
||||
def test_options_for_select_with_data_element_with_special_characters
|
||||
assert_dom_equal(
|
||||
"<option value=\"<Denmark>\" data-test=\"<bold>\"><Denmark></option>",
|
||||
options_for_select([ [ "<Denmark>", { :data => { :test => "<bold>" } } ] ])
|
||||
options_for_select([ [ "<Denmark>", { data: { test: "<bold>" } } ] ])
|
||||
)
|
||||
end
|
||||
|
||||
def test_options_for_select_with_element_attributes_and_selection
|
||||
assert_dom_equal(
|
||||
"<option value=\"<Denmark>\"><Denmark></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")
|
||||
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=\"<Denmark>\"><Denmark></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" ])
|
||||
options_for_select([ "<Denmark>", [ "USA", { class: "bold" } ], "Sweden" ], [ "USA", "Sweden" ])
|
||||
)
|
||||
end
|
||||
|
||||
def test_options_for_select_with_special_characters
|
||||
assert_dom_equal(
|
||||
"<option value=\"<Denmark>\" onclick=\"alert("<code>")\"><Denmark></option>",
|
||||
options_for_select([ [ "<Denmark>", { :onclick => %(alert("<code>")) } ] ])
|
||||
options_for_select([ [ "<Denmark>", { onclick: %(alert("<code>")) } ] ])
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -1314,8 +1314,8 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
|
||||
def test_option_html_attributes_with_single_element_hash
|
||||
assert_equal(
|
||||
{:class => "fancy"},
|
||||
option_html_attributes([ "foo", "bar", { :class => "fancy" } ])
|
||||
{class: "fancy"},
|
||||
option_html_attributes([ "foo", "bar", { class: "fancy" } ])
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -1329,7 +1329,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
def test_option_html_attributes_with_multiple_hashes
|
||||
assert_equal(
|
||||
{:class => "fancy", "onclick" => "alert('Hello World');"},
|
||||
option_html_attributes([ "foo", "bar", { :class => "fancy" }, { "onclick" => "alert('Hello World');" } ])
|
||||
option_html_attributes([ "foo", "bar", { class: "fancy" }, { "onclick" => "alert('Hello World');" } ])
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -1357,7 +1357,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
|
||||
assert_dom_equal(
|
||||
%Q{<select id="post_origin" name="post[origin]"><optgroup label="<Africa>"><option value="<sa>"><South Africa></option>\n<option value="so">Somalia</option></optgroup><optgroup label="Europe"><option value="dk" selected="selected">Denmark</option>\n<option value="ie">Ireland</option></optgroup></select>},
|
||||
grouped_collection_select("post", "origin", dummy_continents, :countries, :continent_name, :country_id, :country_name, :selected => "dk")
|
||||
grouped_collection_select("post", "origin", dummy_continents, :countries, :continent_name, :country_id, :country_name, selected: "dk")
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -1366,7 +1366,7 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
|
||||
assert_dom_equal(
|
||||
%Q{<select id="post_origin" name="post[origin]"><optgroup label="<Africa>"><option value="<sa>"><South Africa></option>\n<option value="so">Somalia</option></optgroup><optgroup label="Europe"><option disabled="disabled" value="dk">Denmark</option>\n<option value="ie">Ireland</option></optgroup></select>},
|
||||
grouped_collection_select("post", "origin", dummy_continents, :countries, :continent_name, :country_id, :country_name, :disabled => "dk")
|
||||
grouped_collection_select("post", "origin", dummy_continents, :countries, :continent_name, :country_id, :country_name, disabled: "dk")
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -89,53 +89,53 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
|
||||
def test_form_tag_multipart
|
||||
actual = form_tag({}, { "multipart" => true })
|
||||
expected = whole_form("http://www.example.com", :enctype => true)
|
||||
expected = whole_form("http://www.example.com", enctype: true)
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
||||
def test_form_tag_with_method_patch
|
||||
actual = form_tag({}, { :method => :patch })
|
||||
expected = whole_form("http://www.example.com", :method => :patch)
|
||||
actual = form_tag({}, { method: :patch })
|
||||
expected = whole_form("http://www.example.com", method: :patch)
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
||||
def test_form_tag_with_method_put
|
||||
actual = form_tag({}, { :method => :put })
|
||||
expected = whole_form("http://www.example.com", :method => :put)
|
||||
actual = form_tag({}, { method: :put })
|
||||
expected = whole_form("http://www.example.com", method: :put)
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
||||
def test_form_tag_with_method_delete
|
||||
actual = form_tag({}, { :method => :delete })
|
||||
actual = form_tag({}, { method: :delete })
|
||||
|
||||
expected = whole_form("http://www.example.com", :method => :delete)
|
||||
expected = whole_form("http://www.example.com", method: :delete)
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
||||
def test_form_tag_with_remote
|
||||
actual = form_tag({}, :remote => true)
|
||||
actual = form_tag({}, remote: true)
|
||||
|
||||
expected = whole_form("http://www.example.com", :remote => true)
|
||||
expected = whole_form("http://www.example.com", remote: true)
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
||||
def test_form_tag_with_remote_false
|
||||
actual = form_tag({}, :remote => false)
|
||||
actual = form_tag({}, remote: false)
|
||||
|
||||
expected = whole_form
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
||||
def test_form_tag_enforce_utf8_true
|
||||
actual = form_tag({}, { :enforce_utf8 => true })
|
||||
expected = whole_form("http://www.example.com", :enforce_utf8 => true)
|
||||
actual = form_tag({}, { enforce_utf8: true })
|
||||
expected = whole_form("http://www.example.com", enforce_utf8: true)
|
||||
assert_dom_equal expected, actual
|
||||
assert actual.html_safe?
|
||||
end
|
||||
|
||||
def test_form_tag_enforce_utf8_false
|
||||
actual = form_tag({}, { :enforce_utf8 => false })
|
||||
expected = whole_form("http://www.example.com", :enforce_utf8 => false)
|
||||
actual = form_tag({}, { enforce_utf8: false })
|
||||
expected = whole_form("http://www.example.com", enforce_utf8: false)
|
||||
assert_dom_equal expected, actual
|
||||
assert actual.html_safe?
|
||||
end
|
||||
|
@ -150,7 +150,7 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
def test_form_tag_with_block_and_method_in_erb
|
||||
output_buffer = render_erb("<%= form_tag('http://www.example.com', :method => :put) do %>Hello world!<% end %>")
|
||||
|
||||
expected = whole_form("http://www.example.com", :method => "put") do
|
||||
expected = whole_form("http://www.example.com", method: "put") do
|
||||
"Hello world!"
|
||||
end
|
||||
|
||||
|
@ -173,7 +173,7 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_file_field_tag_with_options
|
||||
assert_dom_equal "<input name=\"picsplz\" type=\"file\" id=\"picsplz\" class=\"pix\"/>", file_field_tag("picsplz", :class => "pix")
|
||||
assert_dom_equal "<input name=\"picsplz\" type=\"file\" id=\"picsplz\" class=\"pix\"/>", file_field_tag("picsplz", class: "pix")
|
||||
end
|
||||
|
||||
def test_password_field_tag
|
||||
|
@ -257,13 +257,13 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_select_tag_with_prompt
|
||||
actual = select_tag "places", raw("<option>Home</option><option>Work</option><option>Pub</option>"), :prompt => "string"
|
||||
actual = select_tag "places", raw("<option>Home</option><option>Work</option><option>Pub</option>"), prompt: "string"
|
||||
expected = %(<select id="places" name="places"><option value="">string</option><option>Home</option><option>Work</option><option>Pub</option></select>)
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
||||
def test_select_tag_escapes_prompt
|
||||
actual = select_tag "places", raw("<option>Home</option><option>Work</option><option>Pub</option>"), :prompt => "<script>alert(1337)</script>"
|
||||
actual = select_tag "places", raw("<option>Home</option><option>Work</option><option>Pub</option>"), prompt: "<script>alert(1337)</script>"
|
||||
expected = %(<select id="places" name="places"><option value=""><script>alert(1337)</script></option><option>Home</option><option>Work</option><option>Pub</option></select>)
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
@ -275,13 +275,13 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_select_tag_with_nil_option_tags_and_include_blank
|
||||
actual = select_tag "places", nil, :include_blank => true
|
||||
actual = select_tag "places", nil, include_blank: true
|
||||
expected = %(<select id="places" name="places"><option value="" label=" "></option></select>)
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
||||
def test_select_tag_with_nil_option_tags_and_prompt
|
||||
actual = select_tag "places", nil, :prompt => "string"
|
||||
actual = select_tag "places", nil, prompt: "string"
|
||||
expected = %(<select id="places" name="places"><option value="">string</option></select>)
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
@ -293,13 +293,13 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_text_area_tag_size_symbol
|
||||
actual = text_area_tag "body", "hello world", :size => "20x40"
|
||||
actual = text_area_tag "body", "hello world", size: "20x40"
|
||||
expected = %(<textarea cols="20" id="body" name="body" rows="40">\nhello world</textarea>)
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
||||
def test_text_area_tag_should_disregard_size_if_its_given_as_an_integer
|
||||
actual = text_area_tag "body", "hello world", :size => 20
|
||||
actual = text_area_tag "body", "hello world", size: 20
|
||||
expected = %(<textarea id="body" name="body">\nhello world</textarea>)
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
@ -310,19 +310,19 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_text_area_tag_escape_content
|
||||
actual = text_area_tag "body", "<b>hello world</b>", :size => "20x40"
|
||||
actual = text_area_tag "body", "<b>hello world</b>", size: "20x40"
|
||||
expected = %(<textarea cols="20" id="body" name="body" rows="40">\n<b>hello world</b></textarea>)
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
||||
def test_text_area_tag_unescaped_content
|
||||
actual = text_area_tag "body", "<b>hello world</b>", :size => "20x40", :escape => false
|
||||
actual = text_area_tag "body", "<b>hello world</b>", size: "20x40", escape: false
|
||||
expected = %(<textarea cols="20" id="body" name="body" rows="40">\n<b>hello world</b></textarea>)
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
||||
def test_text_area_tag_unescaped_nil_content
|
||||
actual = text_area_tag "body", nil, :escape => false
|
||||
actual = text_area_tag "body", nil, escape: false
|
||||
expected = %(<textarea id="body" name="body">\n</textarea>)
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
@ -340,7 +340,7 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_text_field_tag_size_symbol
|
||||
actual = text_field_tag "title", "Hello!", :size => 75
|
||||
actual = text_field_tag "title", "Hello!", size: 75
|
||||
expected = %(<input id="title" name="title" size="75" type="text" value="Hello!" />)
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
@ -352,7 +352,7 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_text_field_tag_maxlength_symbol
|
||||
actual = text_field_tag "title", "Hello!", :maxlength => 75
|
||||
actual = text_field_tag "title", "Hello!", maxlength: 75
|
||||
expected = %(<input id="title" name="title" maxlength="75" type="text" value="Hello!" />)
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
@ -376,7 +376,7 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_text_field_tag_with_multiple_options
|
||||
actual = text_field_tag "title", "Hello!", :size => 70, :maxlength => 80
|
||||
actual = text_field_tag "title", "Hello!", size: 70, maxlength: 80
|
||||
expected = %(<input id="title" name="title" size="70" maxlength="80" type="text" value="Hello!" />)
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
@ -425,21 +425,21 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_label_tag_with_block_and_argument_and_options
|
||||
output = label_tag("clock", :id => "label_clock") { "Grandfather" }
|
||||
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)
|
||||
assert_dom_equal %(<input type="checkbox" />), tag(:input, :type => "checkbox", :checked => false)
|
||||
assert_dom_equal %(<select id="people" multiple="multiple" name="people[]"><option>david</option></select>), select_tag("people", raw("<option>david</option>"), :multiple => true)
|
||||
assert_dom_equal %(<select id="people_" multiple="multiple" name="people[]"><option>david</option></select>), select_tag("people[]", raw("<option>david</option>"), :multiple => true)
|
||||
assert_dom_equal %(<select id="people" name="people"><option>david</option></select>), select_tag("people", raw("<option>david</option>"), :multiple => nil)
|
||||
assert_dom_equal %(<input checked="checked" id="admin" name="admin" type="checkbox" value="1" />), check_box_tag("admin", 1, true, disabled: false, readonly: nil)
|
||||
assert_dom_equal %(<input type="checkbox" />), tag(:input, type: "checkbox", checked: false)
|
||||
assert_dom_equal %(<select id="people" multiple="multiple" name="people[]"><option>david</option></select>), select_tag("people", raw("<option>david</option>"), multiple: true)
|
||||
assert_dom_equal %(<select id="people_" multiple="multiple" name="people[]"><option>david</option></select>), select_tag("people[]", raw("<option>david</option>"), multiple: true)
|
||||
assert_dom_equal %(<select id="people" name="people"><option>david</option></select>), select_tag("people", raw("<option>david</option>"), multiple: nil)
|
||||
end
|
||||
|
||||
def test_stringify_symbol_keys
|
||||
actual = text_field_tag "title", "Hello!", :id => "admin"
|
||||
actual = text_field_tag "title", "Hello!", id: "admin"
|
||||
expected = %(<input id="admin" name="title" type="text" value="Hello!" />)
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
@ -447,7 +447,7 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
def test_submit_tag
|
||||
assert_dom_equal(
|
||||
%(<input name='commit' data-disable-with="Saving..." onclick="alert('hello!')" type="submit" value="Save" />),
|
||||
submit_tag("Save", :onclick => "alert('hello!')", :data => { :disable_with => "Saving..." })
|
||||
submit_tag("Save", onclick: "alert('hello!')", data: { disable_with: "Saving..." })
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -485,21 +485,21 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
def test_submit_tag_having_data_hash_disable_with_boolean
|
||||
assert_dom_equal(
|
||||
%(<input data-confirm="Are you sure?" name='commit' type="submit" value="Save" />),
|
||||
submit_tag("Save", { :data => { :confirm => "Are you sure?", :disable_with => false } })
|
||||
submit_tag("Save", { data: { confirm: "Are you sure?", disable_with: false } })
|
||||
)
|
||||
end
|
||||
|
||||
def test_submit_tag_with_no_onclick_options
|
||||
assert_dom_equal(
|
||||
%(<input name='commit' data-disable-with="Saving..." type="submit" value="Save" />),
|
||||
submit_tag("Save", :data => { :disable_with => "Saving..." })
|
||||
submit_tag("Save", data: { disable_with: "Saving..." })
|
||||
)
|
||||
end
|
||||
|
||||
def test_submit_tag_with_confirmation
|
||||
assert_dom_equal(
|
||||
%(<input name='commit' type='submit' value='Save' data-confirm="Are you sure?" data-disable-with="Save" />),
|
||||
submit_tag("Save", :data => { :confirm => "Are you sure?" })
|
||||
submit_tag("Save", data: { confirm: "Are you sure?" })
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -528,35 +528,35 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
def test_button_tag_with_submit_type
|
||||
assert_dom_equal(
|
||||
%(<button name="button" type="submit">Save</button>),
|
||||
button_tag("Save", :type => "submit")
|
||||
button_tag("Save", type: "submit")
|
||||
)
|
||||
end
|
||||
|
||||
def test_button_tag_with_button_type
|
||||
assert_dom_equal(
|
||||
%(<button name="button" type="button">Button</button>),
|
||||
button_tag("Button", :type => "button")
|
||||
button_tag("Button", type: "button")
|
||||
)
|
||||
end
|
||||
|
||||
def test_button_tag_with_reset_type
|
||||
assert_dom_equal(
|
||||
%(<button name="button" type="reset">Reset</button>),
|
||||
button_tag("Reset", :type => "reset")
|
||||
button_tag("Reset", type: "reset")
|
||||
)
|
||||
end
|
||||
|
||||
def test_button_tag_with_disabled_option
|
||||
assert_dom_equal(
|
||||
%(<button name="button" type="reset" disabled="disabled">Reset</button>),
|
||||
button_tag("Reset", :type => "reset", :disabled => true)
|
||||
button_tag("Reset", type: "reset", disabled: true)
|
||||
)
|
||||
end
|
||||
|
||||
def test_button_tag_escape_content
|
||||
assert_dom_equal(
|
||||
%(<button name="button" type="reset" disabled="disabled"><b>Reset</b></button>),
|
||||
button_tag("<b>Reset</b>", :type => "reset", :disabled => true)
|
||||
button_tag("<b>Reset</b>", type: "reset", disabled: true)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -565,19 +565,19 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_button_tag_with_block_and_options
|
||||
output = button_tag(:name => "temptation", :type => "button") { content_tag(:strong, "Do not press me") }
|
||||
output = button_tag(name: "temptation", type: "button") { content_tag(:strong, "Do not press me") }
|
||||
assert_dom_equal('<button name="temptation" type="button"><strong>Do not press me</strong></button>', output)
|
||||
end
|
||||
|
||||
def test_button_tag_defaults_with_block_and_options
|
||||
output = button_tag(:name => "temptation", :value => "within") { content_tag(:strong, "Do not press me") }
|
||||
output = button_tag(name: "temptation", value: "within") { content_tag(:strong, "Do not press me") }
|
||||
assert_dom_equal('<button name="temptation" value="within" type="submit" ><strong>Do not press me</strong></button>', output)
|
||||
end
|
||||
|
||||
def test_button_tag_with_confirmation
|
||||
assert_dom_equal(
|
||||
%(<button name="button" type="submit" data-confirm="Are you sure?">Save</button>),
|
||||
button_tag("Save", :type => "submit", :data => { :confirm => "Are you sure?" })
|
||||
button_tag("Save", type: "submit", data: { confirm: "Are you sure?" })
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -591,7 +591,7 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
def test_image_submit_tag_with_confirmation
|
||||
assert_dom_equal(
|
||||
%(<input alt="Save" type="image" src="/images/save.gif" data-confirm="Are you sure?" />),
|
||||
image_submit_tag("save.gif", :data => { :confirm => "Are you sure?" })
|
||||
image_submit_tag("save.gif", data: { confirm: "Are you sure?" })
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -652,12 +652,12 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
|
||||
def test_number_field_tag
|
||||
expected = %{<input name="quantity" max="9" id="quantity" type="number" min="1" />}
|
||||
assert_dom_equal(expected, number_field_tag("quantity", nil, :in => 1...10))
|
||||
assert_dom_equal(expected, number_field_tag("quantity", nil, in: 1...10))
|
||||
end
|
||||
|
||||
def test_range_input_tag
|
||||
expected = %{<input name="volume" step="0.1" max="11" id="volume" type="range" min="0" />}
|
||||
assert_dom_equal(expected, range_field_tag("volume", nil, :in => 0..11, :step => 0.1))
|
||||
assert_dom_equal(expected, range_field_tag("volume", nil, in: 0..11, step: 0.1))
|
||||
end
|
||||
|
||||
def test_field_set_tag_in_erb
|
||||
|
@ -693,33 +693,33 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_text_area_tag_options_symbolize_keys_side_effects
|
||||
options = { :option => "random_option" }
|
||||
options = { option: "random_option" }
|
||||
text_area_tag "body", "hello world", options
|
||||
assert_equal options, { :option => "random_option" }
|
||||
assert_equal options, { option: "random_option" }
|
||||
end
|
||||
|
||||
def test_submit_tag_options_symbolize_keys_side_effects
|
||||
options = { :option => "random_option" }
|
||||
options = { option: "random_option" }
|
||||
submit_tag "submit value", options
|
||||
assert_equal options, { :option => "random_option" }
|
||||
assert_equal options, { option: "random_option" }
|
||||
end
|
||||
|
||||
def test_button_tag_options_symbolize_keys_side_effects
|
||||
options = { :option => "random_option" }
|
||||
options = { option: "random_option" }
|
||||
button_tag "button value", options
|
||||
assert_equal options, { :option => "random_option" }
|
||||
assert_equal options, { option: "random_option" }
|
||||
end
|
||||
|
||||
def test_image_submit_tag_options_symbolize_keys_side_effects
|
||||
options = { :option => "random_option" }
|
||||
options = { option: "random_option" }
|
||||
image_submit_tag "submit source", options
|
||||
assert_equal options, { :option => "random_option" }
|
||||
assert_equal options, { option: "random_option" }
|
||||
end
|
||||
|
||||
def test_image_label_tag_options_symbolize_keys_side_effects
|
||||
options = { :option => "random_option" }
|
||||
options = { option: "random_option" }
|
||||
label_tag "submit source", "title", options
|
||||
assert_equal options, { :option => "random_option" }
|
||||
assert_equal options, { option: "random_option" }
|
||||
end
|
||||
|
||||
def protect_against_forgery?
|
||||
|
|
|
@ -53,7 +53,7 @@ class JavaScriptHelperTest < ActionView::TestCase
|
|||
|
||||
def test_javascript_tag_with_options
|
||||
assert_dom_equal "<script id=\"the_js_tag\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>",
|
||||
javascript_tag("alert('hello')", :id => "the_js_tag")
|
||||
javascript_tag("alert('hello')", id: "the_js_tag")
|
||||
end
|
||||
|
||||
def test_javascript_cdata_section
|
||||
|
|
|
@ -32,7 +32,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase
|
|||
|
||||
def test_render_file_template
|
||||
Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do
|
||||
@view.render(:file => "test/hello_world")
|
||||
@view.render(file: "test/hello_world")
|
||||
wait
|
||||
|
||||
assert_equal 2, @logger.logged(:info).size
|
||||
|
@ -43,7 +43,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase
|
|||
|
||||
def test_render_text_template
|
||||
Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do
|
||||
@view.render(:text => "TEXT")
|
||||
@view.render(text: "TEXT")
|
||||
wait
|
||||
|
||||
assert_equal 2, @logger.logged(:info).size
|
||||
|
@ -54,7 +54,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase
|
|||
|
||||
def test_render_inline_template
|
||||
Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do
|
||||
@view.render(:inline => "<%= 'TEXT' %>")
|
||||
@view.render(inline: "<%= 'TEXT' %>")
|
||||
wait
|
||||
|
||||
assert_equal 2, @logger.logged(:info).size
|
||||
|
@ -65,7 +65,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase
|
|||
|
||||
def test_render_partial_template
|
||||
Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do
|
||||
@view.render(:partial => "test/customer")
|
||||
@view.render(partial: "test/customer")
|
||||
wait
|
||||
|
||||
assert_equal 1, @logger.logged(:info).size
|
||||
|
@ -75,7 +75,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase
|
|||
|
||||
def test_render_partial_with_implicit_path
|
||||
Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do
|
||||
@view.render(Customer.new("david"), :greeting => "hi")
|
||||
@view.render(Customer.new("david"), greeting: "hi")
|
||||
wait
|
||||
|
||||
assert_equal 1, @logger.logged(:info).size
|
||||
|
@ -85,7 +85,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase
|
|||
|
||||
def test_render_collection_template
|
||||
Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do
|
||||
@view.render(:partial => "test/customer", :collection => [ Customer.new("david"), Customer.new("mary") ])
|
||||
@view.render(partial: "test/customer", collection: [ Customer.new("david"), Customer.new("mary") ])
|
||||
wait
|
||||
|
||||
assert_equal 1, @logger.logged(:info).size
|
||||
|
@ -95,7 +95,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase
|
|||
|
||||
def test_render_collection_with_implicit_path
|
||||
Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do
|
||||
@view.render([ Customer.new("david"), Customer.new("mary") ], :greeting => "hi")
|
||||
@view.render([ Customer.new("david"), Customer.new("mary") ], greeting: "hi")
|
||||
wait
|
||||
|
||||
assert_equal 1, @logger.logged(:info).size
|
||||
|
@ -105,7 +105,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase
|
|||
|
||||
def test_render_collection_template_without_path
|
||||
Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do
|
||||
@view.render([ GoodCustomer.new("david"), Customer.new("mary") ], :greeting => "hi")
|
||||
@view.render([ GoodCustomer.new("david"), Customer.new("mary") ], greeting: "hi")
|
||||
wait
|
||||
|
||||
assert_equal 1, @logger.logged(:info).size
|
||||
|
|
|
@ -279,7 +279,7 @@ class TestMissingTemplate < ActiveSupport::TestCase
|
|||
|
||||
test "if a single prefix is passed as a string and the lookup fails, MissingTemplate accepts it" do
|
||||
e = assert_raise ActionView::MissingTemplate do
|
||||
details = {:handlers=>[], :formats=>[], :variants=>[], :locale=>[]}
|
||||
details = {handlers: [], formats: [], variants: [], locale: []}
|
||||
@lookup_context.view_paths.find("foo", "parent", true, details)
|
||||
end
|
||||
assert_match %r{Missing partial parent/_foo with .* Searched in:\n \* "/Path/to/views"\n}, e.message
|
||||
|
|
|
@ -71,27 +71,27 @@ class NumberHelperTest < ActionView::TestCase
|
|||
|
||||
def test_number_to_human_escape_units
|
||||
volume = { unit: "<b>ml</b>", thousand: "<b>lt</b>", million: "<b>m3</b>", trillion: "<b>km3</b>", quadrillion: "<b>Pl</b>" }
|
||||
assert_equal "123 <b>lt</b>", number_to_human(123456, :units => volume)
|
||||
assert_equal "12 <b>ml</b>", number_to_human(12, :units => volume)
|
||||
assert_equal "1.23 <b>m3</b>", number_to_human(1234567, :units => volume)
|
||||
assert_equal "1.23 <b>km3</b>", number_to_human(1_234_567_000_000, :units => volume)
|
||||
assert_equal "1.23 <b>Pl</b>", number_to_human(1_234_567_000_000_000, :units => volume)
|
||||
assert_equal "123 <b>lt</b>", number_to_human(123456, units: volume)
|
||||
assert_equal "12 <b>ml</b>", number_to_human(12, units: volume)
|
||||
assert_equal "1.23 <b>m3</b>", number_to_human(1234567, units: volume)
|
||||
assert_equal "1.23 <b>km3</b>", number_to_human(1_234_567_000_000, units: volume)
|
||||
assert_equal "1.23 <b>Pl</b>", number_to_human(1_234_567_000_000_000, units: volume)
|
||||
|
||||
#Including fractionals
|
||||
distance = { mili: "<b>mm</b>", centi: "<b>cm</b>", deci: "<b>dm</b>", unit: "<b>m</b>",
|
||||
ten: "<b>dam</b>", hundred: "<b>hm</b>", thousand: "<b>km</b>",
|
||||
micro: "<b>um</b>", nano: "<b>nm</b>", pico: "<b>pm</b>", femto: "<b>fm</b>"}
|
||||
assert_equal "1.23 <b>mm</b>", number_to_human(0.00123, :units => distance)
|
||||
assert_equal "1.23 <b>cm</b>", number_to_human(0.0123, :units => distance)
|
||||
assert_equal "1.23 <b>dm</b>", number_to_human(0.123, :units => distance)
|
||||
assert_equal "1.23 <b>m</b>", number_to_human(1.23, :units => distance)
|
||||
assert_equal "1.23 <b>dam</b>", number_to_human(12.3, :units => distance)
|
||||
assert_equal "1.23 <b>hm</b>", number_to_human(123, :units => distance)
|
||||
assert_equal "1.23 <b>km</b>", number_to_human(1230, :units => distance)
|
||||
assert_equal "1.23 <b>um</b>", number_to_human(0.00000123, :units => distance)
|
||||
assert_equal "1.23 <b>nm</b>", number_to_human(0.00000000123, :units => distance)
|
||||
assert_equal "1.23 <b>pm</b>", number_to_human(0.00000000000123, :units => distance)
|
||||
assert_equal "1.23 <b>fm</b>", number_to_human(0.00000000000000123, :units => distance)
|
||||
assert_equal "1.23 <b>mm</b>", number_to_human(0.00123, units: distance)
|
||||
assert_equal "1.23 <b>cm</b>", number_to_human(0.0123, units: distance)
|
||||
assert_equal "1.23 <b>dm</b>", number_to_human(0.123, units: distance)
|
||||
assert_equal "1.23 <b>m</b>", number_to_human(1.23, units: distance)
|
||||
assert_equal "1.23 <b>dam</b>", number_to_human(12.3, units: distance)
|
||||
assert_equal "1.23 <b>hm</b>", number_to_human(123, units: distance)
|
||||
assert_equal "1.23 <b>km</b>", number_to_human(1230, units: distance)
|
||||
assert_equal "1.23 <b>um</b>", number_to_human(0.00000123, units: distance)
|
||||
assert_equal "1.23 <b>nm</b>", number_to_human(0.00000000123, units: distance)
|
||||
assert_equal "1.23 <b>pm</b>", number_to_human(0.00000000000123, units: distance)
|
||||
assert_equal "1.23 <b>fm</b>", number_to_human(0.00000000000000123, units: distance)
|
||||
end
|
||||
|
||||
def test_number_helpers_escape_delimiter_and_separator
|
||||
|
@ -117,8 +117,8 @@ class NumberHelperTest < ActionView::TestCase
|
|||
|
||||
def test_number_to_human_with_custom_translation_scope
|
||||
I18n.backend.store_translations "ts",
|
||||
:custom_units_for_number_to_human => {:mili => "mm", :centi => "cm", :deci => "dm", :unit => "m", :ten => "dam", :hundred => "hm", :thousand => "km"}
|
||||
assert_equal "1.01 cm", number_to_human(0.0101, :locale => "ts", :units => :custom_units_for_number_to_human)
|
||||
custom_units_for_number_to_human: {mili: "mm", centi: "cm", deci: "dm", unit: "m", ten: "dam", hundred: "hm", thousand: "km"}
|
||||
assert_equal "1.01 cm", number_to_human(0.0101, locale: "ts", units: :custom_units_for_number_to_human)
|
||||
ensure
|
||||
I18n.reload!
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ end
|
|||
|
||||
module RenderTestCases
|
||||
def setup_view(paths)
|
||||
@assigns = { :secret => "in the sauce" }
|
||||
@assigns = { secret: "in the sauce" }
|
||||
@view = Class.new(ActionView::Base) do
|
||||
def view_cache_dependencies; end
|
||||
|
||||
|
@ -31,73 +31,73 @@ module RenderTestCases
|
|||
end
|
||||
|
||||
def test_render_file
|
||||
assert_equal "Hello world!", @view.render(:file => "test/hello_world")
|
||||
assert_equal "Hello world!", @view.render(file: "test/hello_world")
|
||||
end
|
||||
|
||||
# Test if :formats, :locale etc. options are passed correctly to the resolvers.
|
||||
def test_render_file_with_format
|
||||
assert_match "<h1>No Comment</h1>", @view.render(:file => "comments/empty", :formats => [:html])
|
||||
assert_match "<error>No Comment</error>", @view.render(:file => "comments/empty", :formats => [:xml])
|
||||
assert_match "<error>No Comment</error>", @view.render(:file => "comments/empty", :formats => :xml)
|
||||
assert_match "<h1>No Comment</h1>", @view.render(file: "comments/empty", formats: [:html])
|
||||
assert_match "<error>No Comment</error>", @view.render(file: "comments/empty", formats: [:xml])
|
||||
assert_match "<error>No Comment</error>", @view.render(file: "comments/empty", formats: :xml)
|
||||
end
|
||||
|
||||
def test_render_template_with_format
|
||||
assert_match "<h1>No Comment</h1>", @view.render(:template => "comments/empty", :formats => [:html])
|
||||
assert_match "<error>No Comment</error>", @view.render(:template => "comments/empty", :formats => [:xml])
|
||||
assert_match "<h1>No Comment</h1>", @view.render(template: "comments/empty", formats: [:html])
|
||||
assert_match "<error>No Comment</error>", @view.render(template: "comments/empty", formats: [:xml])
|
||||
end
|
||||
|
||||
def test_rendered_format_without_format
|
||||
@view.render(:inline => "test")
|
||||
@view.render(inline: "test")
|
||||
assert_equal :html, @view.lookup_context.rendered_format
|
||||
end
|
||||
|
||||
def test_render_partial_implicitly_use_format_of_the_rendered_template
|
||||
@view.lookup_context.formats = [:json]
|
||||
assert_equal "Hello world", @view.render(:template => "test/one", :formats => [:html])
|
||||
assert_equal "Hello world", @view.render(template: "test/one", formats: [:html])
|
||||
end
|
||||
|
||||
def test_render_partial_implicitly_use_format_of_the_rendered_partial
|
||||
@view.lookup_context.formats = [:html]
|
||||
assert_equal "Third level", @view.render(:template => "test/html_template")
|
||||
assert_equal "Third level", @view.render(template: "test/html_template")
|
||||
end
|
||||
|
||||
def test_render_partial_use_last_prepended_format_for_partials_with_the_same_names
|
||||
@view.lookup_context.formats = [:html]
|
||||
assert_equal "\nHTML Template, but JSON partial", @view.render(:template => "test/change_priority")
|
||||
assert_equal "\nHTML Template, but JSON partial", @view.render(template: "test/change_priority")
|
||||
end
|
||||
|
||||
def test_render_template_with_a_missing_partial_of_another_format
|
||||
@view.lookup_context.formats = [:html]
|
||||
e = assert_raise ActionView::Template::Error do
|
||||
@view.render(:template => "with_format", :formats => [:json])
|
||||
@view.render(template: "with_format", formats: [:json])
|
||||
end
|
||||
assert_includes(e.message, "Missing partial /_missing with {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby]}.")
|
||||
end
|
||||
|
||||
def test_render_file_with_locale
|
||||
assert_equal "<h1>Kein Kommentar</h1>", @view.render(:file => "comments/empty", :locale => [:de])
|
||||
assert_equal "<h1>Kein Kommentar</h1>", @view.render(:file => "comments/empty", :locale => :de)
|
||||
assert_equal "<h1>Kein Kommentar</h1>", @view.render(file: "comments/empty", locale: [:de])
|
||||
assert_equal "<h1>Kein Kommentar</h1>", @view.render(file: "comments/empty", locale: :de)
|
||||
end
|
||||
|
||||
def test_render_template_with_locale
|
||||
assert_equal "<h1>Kein Kommentar</h1>", @view.render(:template => "comments/empty", :locale => [:de])
|
||||
assert_equal "<h1>Kein Kommentar</h1>", @view.render(template: "comments/empty", locale: [:de])
|
||||
end
|
||||
|
||||
def test_render_file_with_handlers
|
||||
assert_equal "<h1>No Comment</h1>\n", @view.render(:file => "comments/empty", :handlers => [:builder])
|
||||
assert_equal "<h1>No Comment</h1>\n", @view.render(:file => "comments/empty", :handlers => :builder)
|
||||
assert_equal "<h1>No Comment</h1>\n", @view.render(file: "comments/empty", handlers: [:builder])
|
||||
assert_equal "<h1>No Comment</h1>\n", @view.render(file: "comments/empty", handlers: :builder)
|
||||
end
|
||||
|
||||
def test_render_template_with_handlers
|
||||
assert_equal "<h1>No Comment</h1>\n", @view.render(:template => "comments/empty", :handlers => [:builder])
|
||||
assert_equal "<h1>No Comment</h1>\n", @view.render(template: "comments/empty", handlers: [:builder])
|
||||
end
|
||||
|
||||
def test_render_raw_template_with_handlers
|
||||
assert_equal "<%= hello_world %>\n", @view.render(:template => "plain_text")
|
||||
assert_equal "<%= hello_world %>\n", @view.render(template: "plain_text")
|
||||
end
|
||||
|
||||
def test_render_raw_template_with_quotes
|
||||
assert_equal %q;Here are some characters: !@#$%^&*()-="'}{`; + "\n", @view.render(:template => "plain_text_with_characters")
|
||||
assert_equal %q;Here are some characters: !@#$%^&*()-="'}{`; + "\n", @view.render(template: "plain_text_with_characters")
|
||||
end
|
||||
|
||||
def test_render_raw_is_html_safe_and_does_not_escape_output
|
||||
|
@ -108,47 +108,47 @@ module RenderTestCases
|
|||
end
|
||||
|
||||
def test_render_ruby_template_with_handlers
|
||||
assert_equal "Hello from Ruby code", @view.render(:template => "ruby_template")
|
||||
assert_equal "Hello from Ruby code", @view.render(template: "ruby_template")
|
||||
end
|
||||
|
||||
def test_render_ruby_template_inline
|
||||
assert_equal "4", @view.render(:inline => "(2**2).to_s", :type => :ruby)
|
||||
assert_equal "4", @view.render(inline: "(2**2).to_s", type: :ruby)
|
||||
end
|
||||
|
||||
def test_render_file_with_localization_on_context_level
|
||||
old_locale, @view.locale = @view.locale, :da
|
||||
assert_equal "Hey verden", @view.render(:file => "test/hello_world")
|
||||
assert_equal "Hey verden", @view.render(file: "test/hello_world")
|
||||
ensure
|
||||
@view.locale = old_locale
|
||||
end
|
||||
|
||||
def test_render_file_with_dashed_locale
|
||||
old_locale, @view.locale = @view.locale, :"pt-BR"
|
||||
assert_equal "Ola mundo", @view.render(:file => "test/hello_world")
|
||||
assert_equal "Ola mundo", @view.render(file: "test/hello_world")
|
||||
ensure
|
||||
@view.locale = old_locale
|
||||
end
|
||||
|
||||
def test_render_file_at_top_level
|
||||
assert_equal "Elastica", @view.render(:file => "/shared")
|
||||
assert_equal "Elastica", @view.render(file: "/shared")
|
||||
end
|
||||
|
||||
def test_render_file_with_full_path
|
||||
template_path = File.join(File.dirname(__FILE__), "../fixtures/test/hello_world")
|
||||
assert_equal "Hello world!", @view.render(:file => template_path)
|
||||
assert_equal "Hello world!", @view.render(file: template_path)
|
||||
end
|
||||
|
||||
def test_render_file_with_instance_variables
|
||||
assert_equal "The secret is in the sauce\n", @view.render(:file => "test/render_file_with_ivar")
|
||||
assert_equal "The secret is in the sauce\n", @view.render(file: "test/render_file_with_ivar")
|
||||
end
|
||||
|
||||
def test_render_file_with_locals
|
||||
locals = { :secret => "in the sauce" }
|
||||
assert_equal "The secret is in the sauce\n", @view.render(:file => "test/render_file_with_locals", :locals => locals)
|
||||
locals = { secret: "in the sauce" }
|
||||
assert_equal "The secret is in the sauce\n", @view.render(file: "test/render_file_with_locals", locals: locals)
|
||||
end
|
||||
|
||||
def test_render_file_not_using_full_path_with_dot_in_path
|
||||
assert_equal "The secret is in the sauce\n", @view.render(:file => "test/dot.directory/render_file_with_ivar")
|
||||
assert_equal "The secret is in the sauce\n", @view.render(file: "test/dot.directory/render_file_with_ivar")
|
||||
end
|
||||
|
||||
def test_render_partial_from_default
|
||||
|
@ -158,82 +158,82 @@ module RenderTestCases
|
|||
def test_render_outside_path
|
||||
assert File.exist?(File.join(File.dirname(__FILE__), "../../test/abstract_unit.rb"))
|
||||
assert_raises ActionView::MissingTemplate do
|
||||
@view.render(:template => "../\\../test/abstract_unit.rb")
|
||||
@view.render(template: "../\\../test/abstract_unit.rb")
|
||||
end
|
||||
end
|
||||
|
||||
def test_render_partial
|
||||
assert_equal "only partial", @view.render(:partial => "test/partial_only")
|
||||
assert_equal "only partial", @view.render(partial: "test/partial_only")
|
||||
end
|
||||
|
||||
def test_render_partial_with_format
|
||||
assert_equal "partial html", @view.render(:partial => "test/partial")
|
||||
assert_equal "partial html", @view.render(partial: "test/partial")
|
||||
end
|
||||
|
||||
def test_render_partial_with_selected_format
|
||||
assert_equal "partial html", @view.render(:partial => "test/partial", :formats => :html)
|
||||
assert_equal "partial js", @view.render(:partial => "test/partial", :formats => [:js])
|
||||
assert_equal "partial html", @view.render(partial: "test/partial", formats: :html)
|
||||
assert_equal "partial js", @view.render(partial: "test/partial", formats: [:js])
|
||||
end
|
||||
|
||||
def test_render_partial_at_top_level
|
||||
# file fixtures/_top_level_partial_only (not fixtures/test)
|
||||
assert_equal "top level partial", @view.render(:partial => "/top_level_partial_only")
|
||||
assert_equal "top level partial", @view.render(partial: "/top_level_partial_only")
|
||||
end
|
||||
|
||||
def test_render_partial_with_format_at_top_level
|
||||
# file fixtures/_top_level_partial.html (not fixtures/test, with format extension)
|
||||
assert_equal "top level partial html", @view.render(:partial => "/top_level_partial")
|
||||
assert_equal "top level partial html", @view.render(partial: "/top_level_partial")
|
||||
end
|
||||
|
||||
def test_render_partial_with_locals
|
||||
assert_equal "5", @view.render(:partial => "test/counter", :locals => { :counter_counter => 5 })
|
||||
assert_equal "5", @view.render(partial: "test/counter", locals: { counter_counter: 5 })
|
||||
end
|
||||
|
||||
def test_render_partial_with_locals_from_default
|
||||
assert_equal "only partial", @view.render("test/partial_only", :counter_counter => 5)
|
||||
assert_equal "only partial", @view.render("test/partial_only", counter_counter: 5)
|
||||
end
|
||||
|
||||
def test_render_partial_with_number
|
||||
assert_nothing_raised { @view.render(:partial => "test/200") }
|
||||
assert_nothing_raised { @view.render(partial: "test/200") }
|
||||
end
|
||||
|
||||
def test_render_partial_with_missing_filename
|
||||
assert_raises(ActionView::MissingTemplate) { @view.render(:partial => "test/") }
|
||||
assert_raises(ActionView::MissingTemplate) { @view.render(partial: "test/") }
|
||||
end
|
||||
|
||||
def test_render_partial_with_incompatible_object
|
||||
e = assert_raises(ArgumentError) { @view.render(:partial => nil) }
|
||||
e = assert_raises(ArgumentError) { @view.render(partial: nil) }
|
||||
assert_equal "'#{nil.inspect}' is not an ActiveModel-compatible object. It must implement :to_partial_path.", e.message
|
||||
end
|
||||
|
||||
def test_render_partial_starting_with_a_capital
|
||||
assert_nothing_raised { @view.render(:partial => "test/FooBar") }
|
||||
assert_nothing_raised { @view.render(partial: "test/FooBar") }
|
||||
end
|
||||
|
||||
def test_render_partial_with_hyphen
|
||||
assert_nothing_raised { @view.render(:partial => "test/a-in") }
|
||||
assert_nothing_raised { @view.render(partial: "test/a-in") }
|
||||
end
|
||||
|
||||
def test_render_partial_with_unicode_text
|
||||
assert_nothing_raised { @view.render(:partial => "test/🍣") }
|
||||
assert_nothing_raised { @view.render(partial: "test/🍣") }
|
||||
end
|
||||
|
||||
def test_render_partial_with_invalid_option_as
|
||||
e = assert_raises(ArgumentError) { @view.render(:partial => "test/partial_only", :as => "a-in") }
|
||||
e = assert_raises(ArgumentError) { @view.render(partial: "test/partial_only", as: "a-in") }
|
||||
assert_equal "The value (a-in) of the option `as` is not a valid Ruby identifier; " +
|
||||
"make sure it starts with lowercase letter, " +
|
||||
"and is followed by any combination of letters, numbers and underscores.", e.message
|
||||
end
|
||||
|
||||
def test_render_partial_with_hyphen_and_invalid_option_as
|
||||
e = assert_raises(ArgumentError) { @view.render(:partial => "test/a-in", :as => "a-in") }
|
||||
e = assert_raises(ArgumentError) { @view.render(partial: "test/a-in", as: "a-in") }
|
||||
assert_equal "The value (a-in) of the option `as` is not a valid Ruby identifier; " +
|
||||
"make sure it starts with lowercase letter, " +
|
||||
"and is followed by any combination of letters, numbers and underscores.", e.message
|
||||
end
|
||||
|
||||
def test_render_partial_with_errors
|
||||
e = assert_raises(ActionView::Template::Error) { @view.render(:partial => "test/raise") }
|
||||
e = assert_raises(ActionView::Template::Error) { @view.render(partial: "test/raise") }
|
||||
assert_match %r!method.*doesnt_exist!, e.message
|
||||
assert_equal "", e.sub_template_message
|
||||
assert_equal "1", e.line_number
|
||||
|
@ -242,7 +242,7 @@ module RenderTestCases
|
|||
end
|
||||
|
||||
def test_render_error_indentation
|
||||
e = assert_raises(ActionView::Template::Error) { @view.render(:partial => "test/raise_indentation") }
|
||||
e = assert_raises(ActionView::Template::Error) { @view.render(partial: "test/raise_indentation") }
|
||||
error_lines = e.annoted_source_code
|
||||
assert_match %r!error\shere!, e.message
|
||||
assert_equal "11", e.line_number
|
||||
|
@ -251,7 +251,7 @@ module RenderTestCases
|
|||
end
|
||||
|
||||
def test_render_sub_template_with_errors
|
||||
e = assert_raises(ActionView::Template::Error) { @view.render(:template => "test/sub_template_raise") }
|
||||
e = assert_raises(ActionView::Template::Error) { @view.render(template: "test/sub_template_raise") }
|
||||
assert_match %r!method.*doesnt_exist!, e.message
|
||||
assert_equal "Trace of template inclusion: #{File.expand_path("#{FIXTURE_LOAD_PATH}/test/sub_template_raise.html.erb")}", e.sub_template_message
|
||||
assert_equal "1", e.line_number
|
||||
|
@ -259,7 +259,7 @@ module RenderTestCases
|
|||
end
|
||||
|
||||
def test_render_file_with_errors
|
||||
e = assert_raises(ActionView::Template::Error) { @view.render(:file => File.expand_path("test/_raise", FIXTURE_LOAD_PATH)) }
|
||||
e = assert_raises(ActionView::Template::Error) { @view.render(file: File.expand_path("test/_raise", FIXTURE_LOAD_PATH)) }
|
||||
assert_match %r!method.*doesnt_exist!, e.message
|
||||
assert_equal "", e.sub_template_message
|
||||
assert_equal "1", e.line_number
|
||||
|
@ -268,45 +268,45 @@ module RenderTestCases
|
|||
end
|
||||
|
||||
def test_render_object
|
||||
assert_equal "Hello: david", @view.render(:partial => "test/customer", :object => Customer.new("david"))
|
||||
assert_equal "FalseClass", @view.render(:partial => "test/klass", :object => false)
|
||||
assert_equal "NilClass", @view.render(:partial => "test/klass", :object => nil)
|
||||
assert_equal "Hello: david", @view.render(partial: "test/customer", object: Customer.new("david"))
|
||||
assert_equal "FalseClass", @view.render(partial: "test/klass", object: false)
|
||||
assert_equal "NilClass", @view.render(partial: "test/klass", object: nil)
|
||||
end
|
||||
|
||||
def test_render_object_with_array
|
||||
assert_equal "[1, 2, 3]", @view.render(:partial => "test/object_inspector", :object => [1, 2, 3])
|
||||
assert_equal "[1, 2, 3]", @view.render(partial: "test/object_inspector", object: [1, 2, 3])
|
||||
end
|
||||
|
||||
def test_render_partial_collection
|
||||
assert_equal "Hello: davidHello: mary", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), Customer.new("mary") ])
|
||||
assert_equal "Hello: davidHello: mary", @view.render(partial: "test/customer", collection: [ Customer.new("david"), Customer.new("mary") ])
|
||||
end
|
||||
|
||||
def test_render_partial_collection_with_partial_name_containing_dot
|
||||
assert_equal "Hello: davidHello: mary",
|
||||
@view.render(:partial => "test/customer.mobile", :collection => [ Customer.new("david"), Customer.new("mary") ])
|
||||
@view.render(partial: "test/customer.mobile", collection: [ Customer.new("david"), Customer.new("mary") ])
|
||||
end
|
||||
|
||||
def test_render_partial_collection_as_by_string
|
||||
assert_equal "david david davidmary mary mary",
|
||||
@view.render(:partial => "test/customer_with_var", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => "customer")
|
||||
@view.render(partial: "test/customer_with_var", collection: [ Customer.new("david"), Customer.new("mary") ], as: "customer")
|
||||
end
|
||||
|
||||
def test_render_partial_collection_as_by_symbol
|
||||
assert_equal "david david davidmary mary mary",
|
||||
@view.render(:partial => "test/customer_with_var", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => :customer)
|
||||
@view.render(partial: "test/customer_with_var", collection: [ Customer.new("david"), Customer.new("mary") ], as: :customer)
|
||||
end
|
||||
|
||||
def test_render_partial_collection_without_as
|
||||
assert_equal "local_inspector,local_inspector_counter,local_inspector_iteration",
|
||||
@view.render(:partial => "test/local_inspector", :collection => [ Customer.new("mary") ])
|
||||
@view.render(partial: "test/local_inspector", collection: [ Customer.new("mary") ])
|
||||
end
|
||||
|
||||
def test_render_partial_with_empty_collection_should_return_nil
|
||||
assert_nil @view.render(:partial => "test/customer", :collection => [])
|
||||
assert_nil @view.render(partial: "test/customer", collection: [])
|
||||
end
|
||||
|
||||
def test_render_partial_with_nil_collection_should_return_nil
|
||||
assert_nil @view.render(:partial => "test/customer", :collection => nil)
|
||||
assert_nil @view.render(partial: "test/customer", collection: nil)
|
||||
end
|
||||
|
||||
def test_render_partial_collection_for_non_array
|
||||
|
@ -326,30 +326,30 @@ module RenderTestCases
|
|||
end
|
||||
|
||||
def test_render_partial_with_nil_values_in_collection
|
||||
assert_equal "Hello: davidHello: Anonymous", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), nil ])
|
||||
assert_equal "Hello: davidHello: Anonymous", @view.render(partial: "test/customer", collection: [ Customer.new("david"), nil ])
|
||||
end
|
||||
|
||||
def test_render_partial_with_layout_using_collection_and_template
|
||||
assert_equal "<b>Hello: Amazon</b><b>Hello: Yahoo</b>", @view.render(:partial => "test/customer", :layout => "test/b_layout_for_partial", :collection => [ Customer.new("Amazon"), Customer.new("Yahoo") ])
|
||||
assert_equal "<b>Hello: Amazon</b><b>Hello: Yahoo</b>", @view.render(partial: "test/customer", layout: "test/b_layout_for_partial", collection: [ Customer.new("Amazon"), Customer.new("Yahoo") ])
|
||||
end
|
||||
|
||||
def test_render_partial_with_layout_using_collection_and_template_makes_current_item_available_in_layout
|
||||
assert_equal '<b class="amazon">Hello: Amazon</b><b class="yahoo">Hello: Yahoo</b>',
|
||||
@view.render(:partial => "test/customer", :layout => "test/b_layout_for_partial_with_object", :collection => [ Customer.new("Amazon"), Customer.new("Yahoo") ])
|
||||
@view.render(partial: "test/customer", layout: "test/b_layout_for_partial_with_object", collection: [ Customer.new("Amazon"), Customer.new("Yahoo") ])
|
||||
end
|
||||
|
||||
def test_render_partial_with_layout_using_collection_and_template_makes_current_item_counter_available_in_layout
|
||||
assert_equal '<b data-counter="0">Hello: Amazon</b><b data-counter="1">Hello: Yahoo</b>',
|
||||
@view.render(:partial => "test/customer", :layout => "test/b_layout_for_partial_with_object_counter", :collection => [ Customer.new("Amazon"), Customer.new("Yahoo") ])
|
||||
@view.render(partial: "test/customer", layout: "test/b_layout_for_partial_with_object_counter", collection: [ Customer.new("Amazon"), Customer.new("Yahoo") ])
|
||||
end
|
||||
|
||||
def test_render_partial_with_layout_using_object_and_template_makes_object_available_in_layout
|
||||
assert_equal '<b class="amazon">Hello: Amazon</b>',
|
||||
@view.render(:partial => "test/customer", :layout => "test/b_layout_for_partial_with_object", :object => Customer.new("Amazon"))
|
||||
@view.render(partial: "test/customer", layout: "test/b_layout_for_partial_with_object", object: Customer.new("Amazon"))
|
||||
end
|
||||
|
||||
def test_render_partial_with_empty_array_should_return_nil
|
||||
assert_nil @view.render(:partial => [])
|
||||
assert_nil @view.render(partial: [])
|
||||
end
|
||||
|
||||
def test_render_partial_using_string
|
||||
|
@ -357,28 +357,28 @@ module RenderTestCases
|
|||
end
|
||||
|
||||
def test_render_partial_with_locals_using_string
|
||||
assert_equal "Hola: david", @controller_view.render("customer_greeting", :greeting => "Hola", :customer_greeting => Customer.new("david"))
|
||||
assert_equal "Hola: david", @controller_view.render("customer_greeting", greeting: "Hola", customer_greeting: Customer.new("david"))
|
||||
end
|
||||
|
||||
def test_render_partial_with_object_uses_render_partial_path
|
||||
assert_equal "Hello: lifo",
|
||||
@controller_view.render(:partial => Customer.new("lifo"), :locals => {:greeting => "Hello"})
|
||||
@controller_view.render(partial: Customer.new("lifo"), locals: {greeting: "Hello"})
|
||||
end
|
||||
|
||||
def test_render_partial_with_object_and_format_uses_render_partial_path
|
||||
assert_equal "<greeting>Hello</greeting><name>lifo</name>",
|
||||
@controller_view.render(:partial => Customer.new("lifo"), :formats => :xml, :locals => {:greeting => "Hello"})
|
||||
@controller_view.render(partial: Customer.new("lifo"), formats: :xml, locals: {greeting: "Hello"})
|
||||
end
|
||||
|
||||
def test_render_partial_using_object
|
||||
assert_equal "Hello: lifo",
|
||||
@controller_view.render(Customer.new("lifo"), :greeting => "Hello")
|
||||
@controller_view.render(Customer.new("lifo"), greeting: "Hello")
|
||||
end
|
||||
|
||||
def test_render_partial_using_collection
|
||||
customers = [ Customer.new("Amazon"), Customer.new("Yahoo") ]
|
||||
assert_equal "Hello: AmazonHello: Yahoo",
|
||||
@controller_view.render(customers, :greeting => "Hello")
|
||||
@controller_view.render(customers, greeting: "Hello")
|
||||
end
|
||||
|
||||
def test_render_partial_using_collection_without_path
|
||||
|
@ -395,32 +395,32 @@ module RenderTestCases
|
|||
|
||||
# TODO: The reason for this test is unclear, improve documentation
|
||||
def test_render_partial_and_fallback_to_layout
|
||||
assert_equal "Before (Josh)\n\nAfter", @view.render(:partial => "test/layout_for_partial", :locals => { :name => "Josh" })
|
||||
assert_equal "Before (Josh)\n\nAfter", @view.render(partial: "test/layout_for_partial", locals: { name: "Josh" })
|
||||
end
|
||||
|
||||
# TODO: The reason for this test is unclear, improve documentation
|
||||
def test_render_missing_xml_partial_and_raise_missing_template
|
||||
@view.formats = [:xml]
|
||||
assert_raises(ActionView::MissingTemplate) { @view.render(:partial => "test/layout_for_partial") }
|
||||
assert_raises(ActionView::MissingTemplate) { @view.render(partial: "test/layout_for_partial") }
|
||||
ensure
|
||||
@view.formats = nil
|
||||
end
|
||||
|
||||
def test_render_layout_with_block_and_other_partial_inside
|
||||
render = @view.render(:layout => "test/layout_with_partial_and_yield") { "Yield!" }
|
||||
render = @view.render(layout: "test/layout_with_partial_and_yield") { "Yield!" }
|
||||
assert_equal "Before\npartial html\nYield!\nAfter\n", render
|
||||
end
|
||||
|
||||
def test_render_inline
|
||||
assert_equal "Hello, World!", @view.render(:inline => "Hello, World!")
|
||||
assert_equal "Hello, World!", @view.render(inline: "Hello, World!")
|
||||
end
|
||||
|
||||
def test_render_inline_with_locals
|
||||
assert_equal "Hello, Josh!", @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" })
|
||||
assert_equal "Hello, Josh!", @view.render(inline: "Hello, <%= name %>!", locals: { name: "Josh" })
|
||||
end
|
||||
|
||||
def test_render_fallbacks_to_erb_for_unknown_types
|
||||
assert_equal "Hello, World!", @view.render(:inline => "Hello, World!", :type => :bar)
|
||||
assert_equal "Hello, World!", @view.render(inline: "Hello, World!", type: :bar)
|
||||
end
|
||||
|
||||
CustomHandler = lambda do |template|
|
||||
|
@ -478,54 +478,54 @@ module RenderTestCases
|
|||
ActiveSupport::Deprecation.silence do
|
||||
%w(malformed malformed.erb malformed.html.erb malformed.en.html.erb).each do |name|
|
||||
assert File.exist?(File.expand_path("#{FIXTURE_LOAD_PATH}/test/malformed/#{name}~")), "Malformed file (#{name}~) which should be ignored does not exists"
|
||||
assert_raises(ActionView::MissingTemplate) { @view.render(:file => "test/malformed/#{name}") }
|
||||
assert_raises(ActionView::MissingTemplate) { @view.render(file: "test/malformed/#{name}") }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_render_with_layout
|
||||
assert_equal %(<title></title>\nHello world!\n),
|
||||
@view.render(:file => "test/hello_world", :layout => "layouts/yield")
|
||||
@view.render(file: "test/hello_world", layout: "layouts/yield")
|
||||
end
|
||||
|
||||
def test_render_with_layout_which_has_render_inline
|
||||
assert_equal %(welcome\nHello world!\n),
|
||||
@view.render(:file => "test/hello_world", :layout => "layouts/yield_with_render_inline_inside")
|
||||
@view.render(file: "test/hello_world", layout: "layouts/yield_with_render_inline_inside")
|
||||
end
|
||||
|
||||
def test_render_with_layout_which_renders_another_partial
|
||||
assert_equal %(partial html\nHello world!\n),
|
||||
@view.render(:file => "test/hello_world", :layout => "layouts/yield_with_render_partial_inside")
|
||||
@view.render(file: "test/hello_world", layout: "layouts/yield_with_render_partial_inside")
|
||||
end
|
||||
|
||||
def test_render_partial_with_html_only_extension
|
||||
assert_equal %(<h1>partial html</h1>\nHello world!\n),
|
||||
@view.render(:file => "test/hello_world", :layout => "layouts/render_partial_html")
|
||||
@view.render(file: "test/hello_world", layout: "layouts/render_partial_html")
|
||||
end
|
||||
|
||||
def test_render_layout_with_block_and_yield
|
||||
assert_equal %(Content from block!\n),
|
||||
@view.render(:layout => "layouts/yield_only") { "Content from block!" }
|
||||
@view.render(layout: "layouts/yield_only") { "Content from block!" }
|
||||
end
|
||||
|
||||
def test_render_layout_with_block_and_yield_with_params
|
||||
assert_equal %(Yield! Content from block!\n),
|
||||
@view.render(:layout => "layouts/yield_with_params") { |param| "#{param} Content from block!" }
|
||||
@view.render(layout: "layouts/yield_with_params") { |param| "#{param} Content from block!" }
|
||||
end
|
||||
|
||||
def test_render_layout_with_block_which_renders_another_partial_and_yields
|
||||
assert_equal %(partial html\nContent from block!\n),
|
||||
@view.render(:layout => "layouts/partial_and_yield") { "Content from block!" }
|
||||
@view.render(layout: "layouts/partial_and_yield") { "Content from block!" }
|
||||
end
|
||||
|
||||
def test_render_partial_and_layout_without_block_with_locals
|
||||
assert_equal %(Before (Foo!)\npartial html\nAfter),
|
||||
@view.render(:partial => "test/partial", :layout => "test/layout_for_partial", :locals => { :name => "Foo!"})
|
||||
@view.render(partial: "test/partial", layout: "test/layout_for_partial", locals: { name: "Foo!"})
|
||||
end
|
||||
|
||||
def test_render_partial_and_layout_without_block_with_locals_and_rendering_another_partial
|
||||
assert_equal %(Before (Foo!)\npartial html\npartial with partial\n\nAfter),
|
||||
@view.render(:partial => "test/partial_with_partial", :layout => "test/layout_for_partial", :locals => { :name => "Foo!"})
|
||||
@view.render(partial: "test/partial_with_partial", layout: "test/layout_for_partial", locals: { name: "Foo!"})
|
||||
end
|
||||
|
||||
def test_render_partial_shortcut_with_block_content
|
||||
|
@ -535,17 +535,17 @@ module RenderTestCases
|
|||
|
||||
def test_render_layout_with_a_nested_render_layout_call
|
||||
assert_equal %(Before (Foo!)\nBefore (Bar!)\npartial html\nAfter\npartial with layout\n\nAfter),
|
||||
@view.render(:partial => "test/partial_with_layout", :layout => "test/layout_for_partial", :locals => { :name => "Foo!"})
|
||||
@view.render(partial: "test/partial_with_layout", layout: "test/layout_for_partial", locals: { name: "Foo!"})
|
||||
end
|
||||
|
||||
def test_render_layout_with_a_nested_render_layout_call_using_block_with_render_partial
|
||||
assert_equal %(Before (Foo!)\nBefore (Bar!)\n\n partial html\n\nAfterpartial with layout\n\nAfter),
|
||||
@view.render(:partial => "test/partial_with_layout_block_partial", :layout => "test/layout_for_partial", :locals => { :name => "Foo!"})
|
||||
@view.render(partial: "test/partial_with_layout_block_partial", layout: "test/layout_for_partial", locals: { name: "Foo!"})
|
||||
end
|
||||
|
||||
def test_render_layout_with_a_nested_render_layout_call_using_block_with_render_content
|
||||
assert_equal %(Before (Foo!)\nBefore (Bar!)\n\n Content from inside layout!\n\nAfterpartial with layout\n\nAfter),
|
||||
@view.render(:partial => "test/partial_with_layout_block_content", :layout => "test/layout_for_partial", :locals => { :name => "Foo!"})
|
||||
@view.render(partial: "test/partial_with_layout_block_content", layout: "test/layout_for_partial", locals: { name: "Foo!"})
|
||||
end
|
||||
|
||||
def test_render_partial_with_layout_raises_descriptive_error
|
||||
|
@ -555,17 +555,17 @@ module RenderTestCases
|
|||
|
||||
def test_render_with_nested_layout
|
||||
assert_equal %(<title>title</title>\n\n<div id="column">column</div>\n<div id="content">content</div>\n),
|
||||
@view.render(:file => "test/nested_layout", :layout => "layouts/yield")
|
||||
@view.render(file: "test/nested_layout", layout: "layouts/yield")
|
||||
end
|
||||
|
||||
def test_render_with_file_in_layout
|
||||
assert_equal %(\n<title>title</title>\n\n),
|
||||
@view.render(:file => "test/layout_render_file")
|
||||
@view.render(file: "test/layout_render_file")
|
||||
end
|
||||
|
||||
def test_render_layout_with_object
|
||||
assert_equal %(<title>David</title>),
|
||||
@view.render(:file => "test/layout_render_object")
|
||||
@view.render(file: "test/layout_render_object")
|
||||
end
|
||||
|
||||
def test_render_with_passing_couple_extensions_to_one_register_template_handler_function_call
|
||||
|
@ -615,7 +615,7 @@ class LazyViewRenderTest < ActiveSupport::TestCase
|
|||
|
||||
def test_render_utf8_template_with_magic_comment
|
||||
with_external_encoding Encoding::ASCII_8BIT do
|
||||
result = @view.render(:file => "test/utf8_magic", :formats => [:html], :layouts => "layouts/yield")
|
||||
result = @view.render(file: "test/utf8_magic", formats: [:html], layouts: "layouts/yield")
|
||||
assert_equal Encoding::UTF_8, result.encoding
|
||||
assert_equal "\nРусский \nтекст\n\nUTF-8\nUTF-8\nUTF-8\n", result
|
||||
end
|
||||
|
@ -623,7 +623,7 @@ class LazyViewRenderTest < ActiveSupport::TestCase
|
|||
|
||||
def test_render_utf8_template_with_default_external_encoding
|
||||
with_external_encoding Encoding::UTF_8 do
|
||||
result = @view.render(:file => "test/utf8", :formats => [:html], :layouts => "layouts/yield")
|
||||
result = @view.render(file: "test/utf8", formats: [:html], layouts: "layouts/yield")
|
||||
assert_equal Encoding::UTF_8, result.encoding
|
||||
assert_equal "Русский текст\n\nUTF-8\nUTF-8\nUTF-8\n", result
|
||||
end
|
||||
|
@ -631,14 +631,14 @@ class LazyViewRenderTest < ActiveSupport::TestCase
|
|||
|
||||
def test_render_utf8_template_with_incompatible_external_encoding
|
||||
with_external_encoding Encoding::SHIFT_JIS do
|
||||
e = assert_raises(ActionView::Template::Error) { @view.render(:file => "test/utf8", :formats => [:html], :layouts => "layouts/yield") }
|
||||
e = assert_raises(ActionView::Template::Error) { @view.render(file: "test/utf8", formats: [:html], layouts: "layouts/yield") }
|
||||
assert_match "Your template was not saved as valid Shift_JIS", e.cause.message
|
||||
end
|
||||
end
|
||||
|
||||
def test_render_utf8_template_with_partial_with_incompatible_encoding
|
||||
with_external_encoding Encoding::SHIFT_JIS do
|
||||
e = assert_raises(ActionView::Template::Error) { @view.render(:file => "test/utf8_magic_with_bare_partial", :formats => [:html], :layouts => "layouts/yield") }
|
||||
e = assert_raises(ActionView::Template::Error) { @view.render(file: "test/utf8_magic_with_bare_partial", formats: [:html], layouts: "layouts/yield") }
|
||||
assert_match "Your template was not saved as valid Shift_JIS", e.cause.message
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ end
|
|||
class FiberedTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
view_paths = ActionController::Base.view_paths
|
||||
@assigns = { :secret => "in the sauce", :name => nil }
|
||||
@assigns = { secret: "in the sauce", name: nil }
|
||||
@view = ActionView::Base.new(view_paths, @assigns)
|
||||
@controller_view = TestController.new.view_context
|
||||
end
|
||||
|
@ -26,7 +26,7 @@ class FiberedTest < ActiveSupport::TestCase
|
|||
|
||||
def test_streaming_works
|
||||
content = []
|
||||
body = render_body(:template => "test/hello_world", :layout => "layouts/yield")
|
||||
body = render_body(template: "test/hello_world", layout: "layouts/yield")
|
||||
|
||||
body.each do |piece|
|
||||
content << piece
|
||||
|
@ -40,68 +40,68 @@ class FiberedTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_render_file
|
||||
assert_equal "Hello world!", buffered_render(:file => "test/hello_world")
|
||||
assert_equal "Hello world!", buffered_render(file: "test/hello_world")
|
||||
end
|
||||
|
||||
def test_render_file_with_locals
|
||||
locals = { :secret => "in the sauce" }
|
||||
assert_equal "The secret is in the sauce\n", buffered_render(:file => "test/render_file_with_locals", :locals => locals)
|
||||
locals = { secret: "in the sauce" }
|
||||
assert_equal "The secret is in the sauce\n", buffered_render(file: "test/render_file_with_locals", locals: locals)
|
||||
end
|
||||
|
||||
def test_render_partial
|
||||
assert_equal "only partial", buffered_render(:partial => "test/partial_only")
|
||||
assert_equal "only partial", buffered_render(partial: "test/partial_only")
|
||||
end
|
||||
|
||||
def test_render_inline
|
||||
assert_equal "Hello, World!", buffered_render(:inline => "Hello, World!")
|
||||
assert_equal "Hello, World!", buffered_render(inline: "Hello, World!")
|
||||
end
|
||||
|
||||
def test_render_without_layout
|
||||
assert_equal "Hello world!", buffered_render(:template => "test/hello_world")
|
||||
assert_equal "Hello world!", buffered_render(template: "test/hello_world")
|
||||
end
|
||||
|
||||
def test_render_with_layout
|
||||
assert_equal %(<title></title>\nHello world!\n),
|
||||
buffered_render(:template => "test/hello_world", :layout => "layouts/yield")
|
||||
buffered_render(template: "test/hello_world", layout: "layouts/yield")
|
||||
end
|
||||
|
||||
def test_render_with_layout_which_has_render_inline
|
||||
assert_equal %(welcome\nHello world!\n),
|
||||
buffered_render(:template => "test/hello_world", :layout => "layouts/yield_with_render_inline_inside")
|
||||
buffered_render(template: "test/hello_world", layout: "layouts/yield_with_render_inline_inside")
|
||||
end
|
||||
|
||||
def test_render_with_layout_which_renders_another_partial
|
||||
assert_equal %(partial html\nHello world!\n),
|
||||
buffered_render(:template => "test/hello_world", :layout => "layouts/yield_with_render_partial_inside")
|
||||
buffered_render(template: "test/hello_world", layout: "layouts/yield_with_render_partial_inside")
|
||||
end
|
||||
|
||||
def test_render_with_nested_layout
|
||||
assert_equal %(<title>title</title>\n\n<div id="column">column</div>\n<div id="content">content</div>\n),
|
||||
buffered_render(:template => "test/nested_layout", :layout => "layouts/yield")
|
||||
buffered_render(template: "test/nested_layout", layout: "layouts/yield")
|
||||
end
|
||||
|
||||
def test_render_with_file_in_layout
|
||||
assert_equal %(\n<title>title</title>\n\n),
|
||||
buffered_render(:template => "test/layout_render_file")
|
||||
buffered_render(template: "test/layout_render_file")
|
||||
end
|
||||
|
||||
def test_render_with_handler_without_streaming_support
|
||||
assert_match "<p>This is grand!</p>", buffered_render(:template => "test/hello")
|
||||
assert_match "<p>This is grand!</p>", buffered_render(template: "test/hello")
|
||||
end
|
||||
|
||||
def test_render_with_streaming_multiple_yields_provide_and_content_for
|
||||
assert_equal "Yes, \nthis works\n like a charm.",
|
||||
buffered_render(:template => "test/streaming", :layout => "layouts/streaming")
|
||||
buffered_render(template: "test/streaming", layout: "layouts/streaming")
|
||||
end
|
||||
|
||||
def test_render_with_streaming_with_fake_yields_and_streaming_buster
|
||||
assert_equal "This won't look\n good.",
|
||||
buffered_render(:template => "test/streaming_buster", :layout => "layouts/streaming")
|
||||
buffered_render(template: "test/streaming_buster", layout: "layouts/streaming")
|
||||
end
|
||||
|
||||
def test_render_with_nested_streaming_multiple_yields_provide_and_content_for
|
||||
assert_equal "?Yes, \n\nthis works\n\n? like a charm.",
|
||||
buffered_render(:template => "test/nested_streaming", :layout => "layouts/streaming")
|
||||
buffered_render(template: "test/nested_streaming", layout: "layouts/streaming")
|
||||
end
|
||||
|
||||
def test_render_with_streaming_and_capture
|
||||
|
|
|
@ -7,7 +7,7 @@ class TagHelperTest < ActionView::TestCase
|
|||
|
||||
def test_tag
|
||||
assert_equal "<br />", tag("br")
|
||||
assert_equal "<br clear=\"left\" />", tag(:br, :clear => "left")
|
||||
assert_equal "<br clear=\"left\" />", tag(:br, clear: "left")
|
||||
assert_equal "<br>", tag("br", nil, true)
|
||||
end
|
||||
|
||||
|
@ -36,7 +36,7 @@ class TagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_tag_options_rejects_nil_option
|
||||
assert_equal "<p />", tag("p", :ignored => nil)
|
||||
assert_equal "<p />", tag("p", ignored: nil)
|
||||
end
|
||||
|
||||
def test_tag_builder_options_rejects_nil_option
|
||||
|
@ -44,7 +44,7 @@ class TagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_tag_options_accepts_false_option
|
||||
assert_equal "<p value=\"false\" />", tag("p", :value => false)
|
||||
assert_equal "<p value=\"false\" />", tag("p", value: false)
|
||||
end
|
||||
|
||||
def test_tag_builder_options_accepts_false_option
|
||||
|
@ -52,7 +52,7 @@ class TagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_tag_options_accepts_blank_option
|
||||
assert_equal "<p included=\"\" />", tag("p", :included => "")
|
||||
assert_equal "<p included=\"\" />", tag("p", included: "")
|
||||
end
|
||||
|
||||
def test_tag_builder_options_accepts_blank_option
|
||||
|
@ -61,7 +61,7 @@ class TagHelperTest < ActionView::TestCase
|
|||
|
||||
def test_tag_options_converts_boolean_option
|
||||
assert_dom_equal '<p disabled="disabled" itemscope="itemscope" multiple="multiple" readonly="readonly" allowfullscreen="allowfullscreen" seamless="seamless" typemustmatch="typemustmatch" sortable="sortable" default="default" inert="inert" truespeed="truespeed" />',
|
||||
tag("p", :disabled => true, :itemscope => true, :multiple => true, :readonly => true, :allowfullscreen => true, :seamless => true, :typemustmatch => true, :sortable => true, :default => true, :inert => true, :truespeed => true)
|
||||
tag("p", disabled: true, itemscope: true, multiple: true, readonly: true, allowfullscreen: true, seamless: true, typemustmatch: true, sortable: true, default: true, inert: true, truespeed: true)
|
||||
end
|
||||
|
||||
def test_tag_builder_options_converts_boolean_option
|
||||
|
@ -73,7 +73,7 @@ class TagHelperTest < ActionView::TestCase
|
|||
assert_equal "<a href=\"create\">Create</a>", content_tag("a", "Create", "href" => "create")
|
||||
assert content_tag("a", "Create", "href" => "create").html_safe?
|
||||
assert_equal content_tag("a", "Create", "href" => "create"),
|
||||
content_tag("a", "Create", :href => "create")
|
||||
content_tag("a", "Create", href: "create")
|
||||
assert_equal "<p><script>evil_js</script></p>",
|
||||
content_tag(:p, "<script>evil_js</script>")
|
||||
assert_equal "<p><script>evil_js</script></p>",
|
||||
|
@ -131,7 +131,7 @@ class TagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_content_tag_with_block_and_options_out_of_erb
|
||||
assert_dom_equal %(<div class="green">Hello world!</div>), content_tag(:div, :class => "green") { "Hello world!" }
|
||||
assert_dom_equal %(<div class="green">Hello world!</div>), content_tag(:div, class: "green") { "Hello world!" }
|
||||
end
|
||||
|
||||
def test_tag_builder_with_block_and_options_out_of_erb
|
||||
|
@ -139,7 +139,7 @@ class TagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_content_tag_with_block_and_options_outside_out_of_erb
|
||||
assert_equal content_tag("a", "Create", :href => "create"),
|
||||
assert_equal content_tag("a", "Create", href: "create"),
|
||||
content_tag("a", "href" => "create") { "Create" }
|
||||
end
|
||||
|
||||
|
@ -173,13 +173,13 @@ class TagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_content_tag_with_escaped_array_class
|
||||
str = content_tag("p", "limelight", :class => ["song", "play>"])
|
||||
str = content_tag("p", "limelight", class: ["song", "play>"])
|
||||
assert_equal "<p class=\"song play>\">limelight</p>", str
|
||||
|
||||
str = content_tag("p", "limelight", :class => ["song", "play"])
|
||||
str = content_tag("p", "limelight", class: ["song", "play"])
|
||||
assert_equal "<p class=\"song play\">limelight</p>", str
|
||||
|
||||
str = content_tag("p", "limelight", :class => ["song", ["play"]])
|
||||
str = content_tag("p", "limelight", class: ["song", ["play"]])
|
||||
assert_equal "<p class=\"song play\">limelight</p>", str
|
||||
end
|
||||
|
||||
|
@ -195,10 +195,10 @@ class TagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_content_tag_with_unescaped_array_class
|
||||
str = content_tag("p", "limelight", {:class => ["song", "play>"]}, false)
|
||||
str = content_tag("p", "limelight", {class: ["song", "play>"]}, false)
|
||||
assert_equal "<p class=\"song play>\">limelight</p>", str
|
||||
|
||||
str = content_tag("p", "limelight", {:class => ["song", ["play>"]]}, false)
|
||||
str = content_tag("p", "limelight", {class: ["song", ["play>"]]}, false)
|
||||
assert_equal "<p class=\"song play>\">limelight</p>", str
|
||||
end
|
||||
|
||||
|
@ -211,7 +211,7 @@ class TagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_content_tag_with_empty_array_class
|
||||
str = content_tag("p", "limelight", {:class => []})
|
||||
str = content_tag("p", "limelight", {class: []})
|
||||
assert_equal '<p class="">limelight</p>', str
|
||||
end
|
||||
|
||||
|
@ -220,7 +220,7 @@ class TagHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_content_tag_with_unescaped_empty_array_class
|
||||
str = content_tag("p", "limelight", {:class => []}, false)
|
||||
str = content_tag("p", "limelight", {class: []}, false)
|
||||
assert_equal '<p class="">limelight</p>', str
|
||||
end
|
||||
|
||||
|
@ -259,14 +259,14 @@ class TagHelperTest < ActionView::TestCase
|
|||
|
||||
def test_tag_honors_html_safe_for_param_values
|
||||
["1&2", "1 < 2", "“test“"].each do |escaped|
|
||||
assert_equal %(<a href="#{escaped}" />), tag("a", :href => escaped.html_safe)
|
||||
assert_equal %(<a href="#{escaped}" />), tag("a", href: escaped.html_safe)
|
||||
assert_equal %(<a href="#{escaped}"></a>), tag.a(href: escaped.html_safe)
|
||||
end
|
||||
end
|
||||
|
||||
def test_tag_honors_html_safe_with_escaped_array_class
|
||||
assert_equal '<p class="song> play>" />', tag("p", :class => ["song>", raw("play>")])
|
||||
assert_equal '<p class="song> play>" />', tag("p", :class => [raw("song>"), "play>"])
|
||||
assert_equal '<p class="song> play>" />', tag("p", class: ["song>", raw("play>")])
|
||||
assert_equal '<p class="song> play>" />', tag("p", class: [raw("song>"), "play>"])
|
||||
end
|
||||
|
||||
def test_tag_builder_honors_html_safe_with_escaped_array_class
|
||||
|
@ -276,13 +276,13 @@ class TagHelperTest < ActionView::TestCase
|
|||
|
||||
def test_skip_invalid_escaped_attributes
|
||||
["&1;", "dfa3;", "& #123;"].each do |escaped|
|
||||
assert_equal %(<a href="#{escaped.gsub(/&/, '&')}" />), tag("a", :href => escaped)
|
||||
assert_equal %(<a href="#{escaped.gsub(/&/, '&')}" />), tag("a", href: escaped)
|
||||
assert_equal %(<a href="#{escaped.gsub(/&/, '&')}"></a>), tag.a(href: escaped)
|
||||
end
|
||||
end
|
||||
|
||||
def test_disable_escaping
|
||||
assert_equal '<a href="&" />', tag("a", { :href => "&" }, false, false)
|
||||
assert_equal '<a href="&" />', tag("a", { href: "&" }, false, false)
|
||||
end
|
||||
|
||||
def test_tag_builder_disable_escaping
|
||||
|
|
|
@ -55,12 +55,12 @@ module ActionView
|
|||
end
|
||||
|
||||
test "works without testing a helper module" do
|
||||
assert_equal "Eloy", render("developers/developer", :developer => DeveloperStruct.new("Eloy"))
|
||||
assert_equal "Eloy", render("developers/developer", developer: DeveloperStruct.new("Eloy"))
|
||||
end
|
||||
|
||||
test "can render a layout with block" do
|
||||
assert_equal "Before (ChrisCruft)\n!\nAfter",
|
||||
render(:layout => "test/layout_for_partial", :locals => {:name => "ChrisCruft"}) {"!"}
|
||||
render(layout: "test/layout_for_partial", locals: {name: "ChrisCruft"}) {"!"}
|
||||
end
|
||||
|
||||
helper AnotherTestHelper
|
||||
|
@ -110,14 +110,14 @@ module ActionView
|
|||
from_another_helper
|
||||
end
|
||||
end
|
||||
assert_equal "Howdy!", render(:partial => "test/from_helper")
|
||||
assert_equal "Howdy!", render(partial: "test/from_helper")
|
||||
end
|
||||
end
|
||||
|
||||
class HelperInclusionTest < ActionView::TestCase
|
||||
module RenderHelper
|
||||
def render_from_helper
|
||||
render :partial => "customer", :collection => @customers
|
||||
render partial: "customer", collection: @customers
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -127,14 +127,14 @@ module ActionView
|
|||
@controller.controller_path = "test"
|
||||
|
||||
@customers = [DeveloperStruct.new("Eloy"), DeveloperStruct.new("Manfred")]
|
||||
assert_match(/Hello: EloyHello: Manfred/, render(:partial => "test/from_helper"))
|
||||
assert_match(/Hello: EloyHello: Manfred/, render(partial: "test/from_helper"))
|
||||
end
|
||||
end
|
||||
|
||||
class ControllerHelperMethod < ActionView::TestCase
|
||||
module SomeHelper
|
||||
def some_method
|
||||
render :partial => "test/from_helper"
|
||||
render partial: "test/from_helper"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -156,7 +156,7 @@ module ActionView
|
|||
test "view_assigns returns a Hash of user defined ivars" do
|
||||
@a = "b"
|
||||
@c = "d"
|
||||
assert_equal({:a => "b", :c => "d"}, view_assigns)
|
||||
assert_equal({a: "b", c: "d"}, view_assigns)
|
||||
end
|
||||
|
||||
test "view_assigns excludes internal ivars" do
|
||||
|
@ -174,7 +174,7 @@ module ActionView
|
|||
end
|
||||
end)
|
||||
test "is able to make methods available to the view" do
|
||||
assert_equal "Word!", render(:partial => "test/from_helper")
|
||||
assert_equal "Word!", render(partial: "test/from_helper")
|
||||
end
|
||||
|
||||
def from_test_case; "Word!"; end
|
||||
|
@ -218,14 +218,14 @@ module ActionView
|
|||
test "is able to use routes" do
|
||||
controller.request.assign_parameters(@routes, "foo", "index", {}, "/foo", [])
|
||||
assert_equal "/foo", url_for
|
||||
assert_equal "/bar", url_for(:controller => "bar")
|
||||
assert_equal "/bar", url_for(controller: "bar")
|
||||
end
|
||||
|
||||
test "is able to use named routes" do
|
||||
with_routing do |set|
|
||||
set.draw { resources :contents }
|
||||
assert_equal "http://test.host/contents/new", new_content_url
|
||||
assert_equal "http://test.host/contents/1", content_url(:id => 1)
|
||||
assert_equal "http://test.host/contents/1", content_url(id: 1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -236,7 +236,7 @@ module ActionView
|
|||
@routes ||= ActionDispatch::Routing::RouteSet.new
|
||||
end
|
||||
|
||||
routes.draw { get "bar", :to => lambda {} }
|
||||
routes.draw { get "bar", to: lambda {} }
|
||||
|
||||
def self.call(*)
|
||||
end
|
||||
|
@ -257,21 +257,21 @@ module ActionView
|
|||
end
|
||||
end
|
||||
|
||||
assert_equal "http://test.host/contents/new", render(:partial => "test/from_helper")
|
||||
assert_equal "http://test.host/contents/new", render(partial: "test/from_helper")
|
||||
end
|
||||
end
|
||||
|
||||
test "is able to render partials with local variables" do
|
||||
assert_equal "Eloy", render("developers/developer", :developer => DeveloperStruct.new("Eloy"))
|
||||
assert_equal "Eloy", render(:partial => "developers/developer",
|
||||
:locals => { :developer => DeveloperStruct.new("Eloy") })
|
||||
assert_equal "Eloy", render("developers/developer", developer: DeveloperStruct.new("Eloy"))
|
||||
assert_equal "Eloy", render(partial: "developers/developer",
|
||||
locals: { developer: DeveloperStruct.new("Eloy") })
|
||||
end
|
||||
|
||||
test "is able to render partials from templates and also use instance variables" do
|
||||
@controller.controller_path = "test"
|
||||
|
||||
@customers = [DeveloperStruct.new("Eloy"), DeveloperStruct.new("Manfred")]
|
||||
assert_match(/Hello: EloyHello: Manfred/, render(:file => "test/list"))
|
||||
assert_match(/Hello: EloyHello: Manfred/, render(file: "test/list"))
|
||||
end
|
||||
|
||||
test "is able to render partials from templates and also use instance variables after view has been referenced" do
|
||||
|
@ -280,7 +280,7 @@ module ActionView
|
|||
view
|
||||
|
||||
@customers = [DeveloperStruct.new("Eloy"), DeveloperStruct.new("Manfred")]
|
||||
assert_match(/Hello: EloyHello: Manfred/, render(:file => "test/list"))
|
||||
assert_match(/Hello: EloyHello: Manfred/, render(file: "test/list"))
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -288,16 +288,16 @@ module ActionView
|
|||
class AssertionsTest < ActionView::TestCase
|
||||
def render_from_helper
|
||||
form_tag("/foo") do
|
||||
safe_concat render(:text => "<ul><li>foo</li></ul>")
|
||||
safe_concat render(text: "<ul><li>foo</li></ul>")
|
||||
end
|
||||
end
|
||||
helper_method :render_from_helper
|
||||
|
||||
test "uses the output_buffer for assert_select" do
|
||||
render(:partial => "test/from_helper")
|
||||
render(partial: "test/from_helper")
|
||||
|
||||
assert_select "form" do
|
||||
assert_select "li", :text => "foo"
|
||||
assert_select "li", text: "foo"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ class PeopleHelperTest < ActionView::TestCase
|
|||
def with_test_route_set
|
||||
with_routing do |set|
|
||||
set.draw do
|
||||
get "people", :to => "people#index", :as => :people
|
||||
get "people", to: "people#index", as: :people
|
||||
end
|
||||
yield
|
||||
end
|
||||
|
|
|
@ -3,13 +3,13 @@ require "abstract_unit"
|
|||
class FixtureResolverTest < ActiveSupport::TestCase
|
||||
def test_should_return_empty_list_for_unknown_path
|
||||
resolver = ActionView::FixtureResolver.new()
|
||||
templates = resolver.find_all("path", "arbitrary", false, {:locale => [], :formats => [:html], :variants => [], :handlers => []})
|
||||
templates = resolver.find_all("path", "arbitrary", false, {locale: [], formats: [:html], variants: [], handlers: []})
|
||||
assert_equal [], templates, "expected an empty list of templates"
|
||||
end
|
||||
|
||||
def test_should_return_template_for_declared_path
|
||||
resolver = ActionView::FixtureResolver.new("arbitrary/path.erb" => "this text")
|
||||
templates = resolver.find_all("path", "arbitrary", false, {:locale => [], :formats => [:html], :variants => [], :handlers => [:erb]})
|
||||
templates = resolver.find_all("path", "arbitrary", false, {locale: [], formats: [:html], variants: [], handlers: [:erb]})
|
||||
assert_equal 1, templates.size, "expected one template"
|
||||
assert_equal "this text", templates.first.source
|
||||
assert_equal "arbitrary/path", templates.first.virtual_path
|
||||
|
|
|
@ -3,7 +3,7 @@ require "abstract_unit"
|
|||
class NullResolverTest < ActiveSupport::TestCase
|
||||
def test_should_return_template_for_any_path
|
||||
resolver = ActionView::NullResolver.new()
|
||||
templates = resolver.find_all("path.erb", "arbitrary", false, {:locale => [], :formats => [:html], :handlers => []})
|
||||
templates = resolver.find_all("path.erb", "arbitrary", false, {locale: [], formats: [:html], handlers: []})
|
||||
assert_equal 1, templates.size, "expected one template"
|
||||
assert_equal "Template generated by Null Resolver", templates.first.source
|
||||
assert_equal "arbitrary/path.erb", templates.first.virtual_path.to_s
|
||||
|
|
|
@ -38,8 +38,8 @@ class TextHelperTest < ActionView::TestCase
|
|||
text = "A\r\n \nB\n\n\r\n\t\nC\nD".freeze
|
||||
assert_equal "<p>A\n<br /> \n<br />B</p>\n\n<p>\t\n<br />C\n<br />D</p>", simple_format(text)
|
||||
|
||||
assert_equal %q(<p class="test">This is a classy test</p>), simple_format("This is a classy test", :class => "test")
|
||||
assert_equal %Q(<p class="test">para 1</p>\n\n<p class="test">para 2</p>), simple_format("para 1\n\npara 2", :class => "test")
|
||||
assert_equal %q(<p class="test">This is a classy test</p>), simple_format("This is a classy test", class: "test")
|
||||
assert_equal %Q(<p class="test">para 1</p>\n\n<p class="test">para 2</p>), simple_format("para 1\n\npara 2", class: "test")
|
||||
end
|
||||
|
||||
def test_simple_format_should_sanitize_input_when_sanitize_option_is_not_false
|
||||
|
@ -52,15 +52,15 @@ class TextHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_simple_format_should_not_sanitize_input_when_sanitize_option_is_false
|
||||
assert_equal "<p><b> test with unsafe string </b><script>code!</script></p>", simple_format("<b> test with unsafe string </b><script>code!</script>", {}, :sanitize => false)
|
||||
assert_equal "<p><b> test with unsafe string </b><script>code!</script></p>", simple_format("<b> test with unsafe string </b><script>code!</script>", {}, sanitize: false)
|
||||
end
|
||||
|
||||
def test_simple_format_with_custom_wrapper
|
||||
assert_equal "<div></div>", simple_format(nil, {}, :wrapper_tag => "div")
|
||||
assert_equal "<div></div>", simple_format(nil, {}, wrapper_tag: "div")
|
||||
end
|
||||
|
||||
def test_simple_format_with_custom_wrapper_and_multi_line_breaks
|
||||
assert_equal "<div>We want to put a wrapper...</div>\n\n<div>...right there.</div>", simple_format("We want to put a wrapper...\n\n...right there.", {}, :wrapper_tag => "div")
|
||||
assert_equal "<div>We want to put a wrapper...</div>\n\n<div>...right there.</div>", simple_format("We want to put a wrapper...\n\n...right there.", {}, wrapper_tag: "div")
|
||||
end
|
||||
|
||||
def test_simple_format_should_not_change_the_text_passed
|
||||
|
@ -71,22 +71,22 @@ class TextHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_simple_format_does_not_modify_the_html_options_hash
|
||||
options = { :class => "foobar"}
|
||||
options = { class: "foobar"}
|
||||
passed_options = options.dup
|
||||
simple_format("some text", passed_options)
|
||||
assert_equal options, passed_options
|
||||
end
|
||||
|
||||
def test_simple_format_does_not_modify_the_options_hash
|
||||
options = { :wrapper_tag => :div, :sanitize => false }
|
||||
options = { wrapper_tag: :div, sanitize: false }
|
||||
passed_options = options.dup
|
||||
simple_format("some text", {}, passed_options)
|
||||
assert_equal options, passed_options
|
||||
end
|
||||
|
||||
def test_truncate
|
||||
assert_equal "Hello World!", truncate("Hello World!", :length => 12)
|
||||
assert_equal "Hello Wor...", truncate("Hello World!!", :length => 12)
|
||||
assert_equal "Hello World!", truncate("Hello World!", length: 12)
|
||||
assert_equal "Hello Wor...", truncate("Hello World!!", length: 12)
|
||||
end
|
||||
|
||||
def test_truncate_should_use_default_length_of_30
|
||||
|
@ -95,21 +95,21 @@ class TextHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_truncate_with_options_hash
|
||||
assert_equal "This is a string that wil[...]", truncate("This is a string that will go longer then the default truncate length of 30", :omission => "[...]")
|
||||
assert_equal "Hello W...", truncate("Hello World!", :length => 10)
|
||||
assert_equal "Hello[...]", truncate("Hello World!", :omission => "[...]", :length => 10)
|
||||
assert_equal "Hello[...]", truncate("Hello Big World!", :omission => "[...]", :length => 13, :separator => " ")
|
||||
assert_equal "Hello Big[...]", truncate("Hello Big World!", :omission => "[...]", :length => 14, :separator => " ")
|
||||
assert_equal "Hello Big[...]", truncate("Hello Big World!", :omission => "[...]", :length => 15, :separator => " ")
|
||||
assert_equal "This is a string that wil[...]", truncate("This is a string that will go longer then the default truncate length of 30", omission: "[...]")
|
||||
assert_equal "Hello W...", truncate("Hello World!", length: 10)
|
||||
assert_equal "Hello[...]", truncate("Hello World!", omission: "[...]", length: 10)
|
||||
assert_equal "Hello[...]", truncate("Hello Big World!", omission: "[...]", length: 13, separator: " ")
|
||||
assert_equal "Hello Big[...]", truncate("Hello Big World!", omission: "[...]", length: 14, separator: " ")
|
||||
assert_equal "Hello Big[...]", truncate("Hello Big World!", omission: "[...]", length: 15, separator: " ")
|
||||
end
|
||||
|
||||
def test_truncate_multibyte
|
||||
assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding(Encoding::UTF_8),
|
||||
truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding(Encoding::UTF_8), :length => 10)
|
||||
truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding(Encoding::UTF_8), length: 10)
|
||||
end
|
||||
|
||||
def test_truncate_does_not_modify_the_options_hash
|
||||
options = { :length => 10 }
|
||||
options = { length: 10 }
|
||||
passed_options = options.dup
|
||||
truncate("some text", passed_options)
|
||||
assert_equal options, passed_options
|
||||
|
@ -117,49 +117,49 @@ class TextHelperTest < ActionView::TestCase
|
|||
|
||||
def test_truncate_with_link_options
|
||||
assert_equal "Here is a long test and ...<a href=\"#\">Continue</a>",
|
||||
truncate("Here is a long test and I need a continue to read link", :length => 27) { link_to "Continue", "#" }
|
||||
truncate("Here is a long test and I need a continue to read link", length: 27) { link_to "Continue", "#" }
|
||||
end
|
||||
|
||||
def test_truncate_should_be_html_safe
|
||||
assert truncate("Hello World!", :length => 12).html_safe?
|
||||
assert truncate("Hello World!", length: 12).html_safe?
|
||||
end
|
||||
|
||||
def test_truncate_should_escape_the_input
|
||||
assert_equal "Hello <sc...", truncate("Hello <script>code!</script>World!!", :length => 12)
|
||||
assert_equal "Hello <sc...", truncate("Hello <script>code!</script>World!!", length: 12)
|
||||
end
|
||||
|
||||
def test_truncate_should_not_escape_the_input_with_escape_false
|
||||
assert_equal "Hello <sc...", truncate("Hello <script>code!</script>World!!", :length => 12, :escape => false)
|
||||
assert_equal "Hello <sc...", truncate("Hello <script>code!</script>World!!", length: 12, escape: false)
|
||||
end
|
||||
|
||||
def test_truncate_with_escape_false_should_be_html_safe
|
||||
truncated = truncate("Hello <script>code!</script>World!!", :length => 12, :escape => false)
|
||||
truncated = truncate("Hello <script>code!</script>World!!", length: 12, escape: false)
|
||||
assert truncated.html_safe?
|
||||
end
|
||||
|
||||
def test_truncate_with_block_should_be_html_safe
|
||||
truncated = truncate("Here's a long test and I need a continue to read link", :length => 27) { link_to "Continue", "#" }
|
||||
truncated = truncate("Here's a long test and I need a continue to read link", length: 27) { link_to "Continue", "#" }
|
||||
assert truncated.html_safe?
|
||||
end
|
||||
|
||||
def test_truncate_with_block_should_escape_the_input
|
||||
assert_equal "<script>code!</script>He...<a href=\"#\">Continue</a>",
|
||||
truncate("<script>code!</script>Here's a long test and I need a continue to read link", :length => 27) { link_to "Continue", "#" }
|
||||
truncate("<script>code!</script>Here's a long test and I need a continue to read link", length: 27) { link_to "Continue", "#" }
|
||||
end
|
||||
|
||||
def test_truncate_with_block_should_not_escape_the_input_with_escape_false
|
||||
assert_equal "<script>code!</script>He...<a href=\"#\">Continue</a>",
|
||||
truncate("<script>code!</script>Here's a long test and I need a continue to read link", :length => 27, :escape => false) { link_to "Continue", "#" }
|
||||
truncate("<script>code!</script>Here's a long test and I need a continue to read link", length: 27, escape: false) { link_to "Continue", "#" }
|
||||
end
|
||||
|
||||
def test_truncate_with_block_with_escape_false_should_be_html_safe
|
||||
truncated = truncate("<script>code!</script>Here's a long test and I need a continue to read link", :length => 27, :escape => false) { link_to "Continue", "#" }
|
||||
truncated = truncate("<script>code!</script>Here's a long test and I need a continue to read link", length: 27, escape: false) { link_to "Continue", "#" }
|
||||
assert truncated.html_safe?
|
||||
end
|
||||
|
||||
def test_truncate_with_block_should_escape_the_block
|
||||
assert_equal "Here is a long test and ...<script>alert('foo');</script>",
|
||||
truncate("Here is a long test and I need a continue to read link", :length => 27) { "<script>alert('foo');</script>" }
|
||||
truncate("Here is a long test and I need a continue to read link", length: 27) { "<script>alert('foo');</script>" }
|
||||
end
|
||||
|
||||
def test_highlight_should_be_html_safe
|
||||
|
@ -179,7 +179,7 @@ class TextHelperTest < ActionView::TestCase
|
|||
|
||||
assert_equal(
|
||||
"This is a <b>beautiful</b> morning, but also a <b>beautiful</b> day",
|
||||
highlight("This is a beautiful morning, but also a beautiful day", "beautiful", :highlighter => '<b>\1</b>')
|
||||
highlight("This is a beautiful morning, but also a beautiful day", "beautiful", highlighter: '<b>\1</b>')
|
||||
)
|
||||
|
||||
assert_equal(
|
||||
|
@ -206,7 +206,7 @@ class TextHelperTest < ActionView::TestCase
|
|||
def test_highlight_should_not_sanitize_if_sanitize_option_if_false
|
||||
assert_equal(
|
||||
"This is a <mark>beautiful</mark> morning<script>code!</script>",
|
||||
highlight("This is a beautiful morning<script>code!</script>", "beautiful", :sanitize => false)
|
||||
highlight("This is a beautiful morning<script>code!</script>", "beautiful", sanitize: false)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -233,7 +233,7 @@ class TextHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_highlight_with_multiple_phrases_in_one_pass
|
||||
assert_equal %(<em>wow</em> <em>em</em>), highlight("wow em", %w(wow em), :highlighter => '<em>\1</em>')
|
||||
assert_equal %(<em>wow</em> <em>em</em>), highlight("wow em", %w(wow em), highlighter: '<em>\1</em>')
|
||||
end
|
||||
|
||||
def test_highlight_with_html
|
||||
|
@ -259,12 +259,12 @@ class TextHelperTest < ActionView::TestCase
|
|||
)
|
||||
assert_equal(
|
||||
"<div>abc <b>div</b></div>",
|
||||
highlight("<div>abc div</div>", "div", :highlighter => '<b>\1</b>')
|
||||
highlight("<div>abc div</div>", "div", highlighter: '<b>\1</b>')
|
||||
)
|
||||
end
|
||||
|
||||
def test_highlight_does_not_modify_the_options_hash
|
||||
options = { :highlighter => '<b>\1</b>', :sanitize => false }
|
||||
options = { highlighter: '<b>\1</b>', sanitize: false }
|
||||
passed_options = options.dup
|
||||
highlight("<div>abc div</div>", "div", passed_options)
|
||||
assert_equal options, passed_options
|
||||
|
@ -278,73 +278,73 @@ class TextHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_excerpt
|
||||
assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", :radius => 5))
|
||||
assert_equal("This is a...", excerpt("This is a beautiful morning", "this", :radius => 5))
|
||||
assert_equal("...iful morning", excerpt("This is a beautiful morning", "morning", :radius => 5))
|
||||
assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", radius: 5))
|
||||
assert_equal("This is a...", excerpt("This is a beautiful morning", "this", radius: 5))
|
||||
assert_equal("...iful morning", excerpt("This is a beautiful morning", "morning", radius: 5))
|
||||
assert_nil excerpt("This is a beautiful morning", "day")
|
||||
end
|
||||
|
||||
def test_excerpt_with_regex
|
||||
assert_equal("...is a beautiful! mor...", excerpt("This is a beautiful! morning", "beautiful", :radius => 5))
|
||||
assert_equal("...is a beautiful? mor...", excerpt("This is a beautiful? morning", "beautiful", :radius => 5))
|
||||
assert_equal("...is a beautiful? mor...", excerpt("This is a beautiful? morning", /\bbeau\w*\b/i, :radius => 5))
|
||||
assert_equal("...is a beautiful? mor...", excerpt("This is a beautiful? morning", /\b(beau\w*)\b/i, :radius => 5))
|
||||
assert_equal("...udge Allen and...", excerpt("This day was challenging for judge Allen and his colleagues.", /\ballen\b/i, :radius => 5))
|
||||
assert_equal("...judge Allen and...", excerpt("This day was challenging for judge Allen and his colleagues.", /\ballen\b/i, :radius => 1, :separator => " "))
|
||||
assert_equal("...was challenging for...", excerpt("This day was challenging for judge Allen and his colleagues.", /\b(\w*allen\w*)\b/i, :radius => 5))
|
||||
assert_equal("...is a beautiful! mor...", excerpt("This is a beautiful! morning", "beautiful", radius: 5))
|
||||
assert_equal("...is a beautiful? mor...", excerpt("This is a beautiful? morning", "beautiful", radius: 5))
|
||||
assert_equal("...is a beautiful? mor...", excerpt("This is a beautiful? morning", /\bbeau\w*\b/i, radius: 5))
|
||||
assert_equal("...is a beautiful? mor...", excerpt("This is a beautiful? morning", /\b(beau\w*)\b/i, radius: 5))
|
||||
assert_equal("...udge Allen and...", excerpt("This day was challenging for judge Allen and his colleagues.", /\ballen\b/i, radius: 5))
|
||||
assert_equal("...judge Allen and...", excerpt("This day was challenging for judge Allen and his colleagues.", /\ballen\b/i, radius: 1, separator: " "))
|
||||
assert_equal("...was challenging for...", excerpt("This day was challenging for judge Allen and his colleagues.", /\b(\w*allen\w*)\b/i, radius: 5))
|
||||
end
|
||||
|
||||
def test_excerpt_should_not_be_html_safe
|
||||
assert !excerpt("This is a beautiful! morning", "beautiful", :radius => 5).html_safe?
|
||||
assert !excerpt("This is a beautiful! morning", "beautiful", radius: 5).html_safe?
|
||||
end
|
||||
|
||||
def test_excerpt_in_borderline_cases
|
||||
assert_equal("", excerpt("", "", :radius => 0))
|
||||
assert_equal("a", excerpt("a", "a", :radius => 0))
|
||||
assert_equal("...b...", excerpt("abc", "b", :radius => 0))
|
||||
assert_equal("abc", excerpt("abc", "b", :radius => 1))
|
||||
assert_equal("abc...", excerpt("abcd", "b", :radius => 1))
|
||||
assert_equal("...abc", excerpt("zabc", "b", :radius => 1))
|
||||
assert_equal("...abc...", excerpt("zabcd", "b", :radius => 1))
|
||||
assert_equal("zabcd", excerpt("zabcd", "b", :radius => 2))
|
||||
assert_equal("", excerpt("", "", radius: 0))
|
||||
assert_equal("a", excerpt("a", "a", radius: 0))
|
||||
assert_equal("...b...", excerpt("abc", "b", radius: 0))
|
||||
assert_equal("abc", excerpt("abc", "b", radius: 1))
|
||||
assert_equal("abc...", excerpt("abcd", "b", radius: 1))
|
||||
assert_equal("...abc", excerpt("zabc", "b", radius: 1))
|
||||
assert_equal("...abc...", excerpt("zabcd", "b", radius: 1))
|
||||
assert_equal("zabcd", excerpt("zabcd", "b", radius: 2))
|
||||
|
||||
# excerpt strips the resulting string before ap-/prepending excerpt_string.
|
||||
# whether this behavior is meaningful when excerpt_string is not to be
|
||||
# appended is questionable.
|
||||
assert_equal("zabcd", excerpt(" zabcd ", "b", :radius => 4))
|
||||
assert_equal("...abc...", excerpt("z abc d", "b", :radius => 1))
|
||||
assert_equal("zabcd", excerpt(" zabcd ", "b", radius: 4))
|
||||
assert_equal("...abc...", excerpt("z abc d", "b", radius: 1))
|
||||
end
|
||||
|
||||
def test_excerpt_with_omission
|
||||
assert_equal("[...]is a beautiful morn[...]", excerpt("This is a beautiful morning", "beautiful", :omission => "[...]",:radius => 5))
|
||||
assert_equal("[...]is a beautiful morn[...]", excerpt("This is a beautiful morning", "beautiful", omission: "[...]",radius: 5))
|
||||
assert_equal(
|
||||
"This is the ultimate supercalifragilisticexpialidoceous very looooooooooooooooooong looooooooooooong beautiful morning with amazing sunshine and awesome tempera[...]",
|
||||
excerpt("This is the ultimate supercalifragilisticexpialidoceous very looooooooooooooooooong looooooooooooong beautiful morning with amazing sunshine and awesome temperatures. So what are you gonna do about it?", "very",
|
||||
:omission => "[...]")
|
||||
omission: "[...]")
|
||||
)
|
||||
end
|
||||
|
||||
def test_excerpt_with_utf8
|
||||
assert_equal("...\357\254\203ciency could not be...".force_encoding(Encoding::UTF_8), excerpt("That's why e\357\254\203ciency could not be helped".force_encoding(Encoding::UTF_8), "could", :radius => 8))
|
||||
assert_equal("...\357\254\203ciency could not be...".force_encoding(Encoding::UTF_8), excerpt("That's why e\357\254\203ciency could not be helped".force_encoding(Encoding::UTF_8), "could", radius: 8))
|
||||
end
|
||||
|
||||
def test_excerpt_does_not_modify_the_options_hash
|
||||
options = { :omission => "[...]",:radius => 5 }
|
||||
options = { omission: "[...]",radius: 5 }
|
||||
passed_options = options.dup
|
||||
excerpt("This is a beautiful morning", "beautiful", passed_options)
|
||||
assert_equal options, passed_options
|
||||
end
|
||||
|
||||
def test_excerpt_with_separator
|
||||
options = { :separator => " ", :radius => 1 }
|
||||
options = { separator: " ", radius: 1 }
|
||||
assert_equal("...a very beautiful...", excerpt("This is a very beautiful morning", "very", options))
|
||||
assert_equal("This is...", excerpt("This is a very beautiful morning", "this", options))
|
||||
assert_equal("...beautiful morning", excerpt("This is a very beautiful morning", "morning", options))
|
||||
|
||||
options = { :separator => "\n", :radius => 0 }
|
||||
options = { separator: "\n", radius: 0 }
|
||||
assert_equal("...very long...", excerpt("my very\nvery\nvery long\nstring", "long", options))
|
||||
|
||||
options = { :separator => "\n", :radius => 1 }
|
||||
options = { separator: "\n", radius: 1 }
|
||||
assert_equal("...very\nvery long\nstring", excerpt("my very\nvery\nvery long\nstring", "long", options))
|
||||
|
||||
assert_equal excerpt("This is a beautiful morning", "a"),
|
||||
|
@ -352,15 +352,15 @@ class TextHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_word_wrap
|
||||
assert_equal("my very very\nvery long\nstring", word_wrap("my very very very long string", :line_width => 15))
|
||||
assert_equal("my very very\nvery long\nstring", word_wrap("my very very very long string", line_width: 15))
|
||||
end
|
||||
|
||||
def test_word_wrap_with_extra_newlines
|
||||
assert_equal("my very very\nvery long\nstring\n\nwith another\nline", word_wrap("my very very very long string\n\nwith another line", :line_width => 15))
|
||||
assert_equal("my very very\nvery long\nstring\n\nwith another\nline", word_wrap("my very very very long string\n\nwith another line", line_width: 15))
|
||||
end
|
||||
|
||||
def test_word_wrap_does_not_modify_the_options_hash
|
||||
options = { :line_width => 15 }
|
||||
options = { line_width: 15 }
|
||||
passed_options = options.dup
|
||||
word_wrap("some text", passed_options)
|
||||
assert_equal options, passed_options
|
||||
|
@ -458,12 +458,12 @@ class TextHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_named_cycles
|
||||
assert_equal("1", cycle(1, 2, 3, :name => "numbers"))
|
||||
assert_equal("red", cycle("red", "blue", :name => "colors"))
|
||||
assert_equal("2", cycle(1, 2, 3, :name => "numbers"))
|
||||
assert_equal("blue", cycle("red", "blue", :name => "colors"))
|
||||
assert_equal("3", cycle(1, 2, 3, :name => "numbers"))
|
||||
assert_equal("red", cycle("red", "blue", :name => "colors"))
|
||||
assert_equal("1", cycle(1, 2, 3, name: "numbers"))
|
||||
assert_equal("red", cycle("red", "blue", name: "colors"))
|
||||
assert_equal("2", cycle(1, 2, 3, name: "numbers"))
|
||||
assert_equal("blue", cycle("red", "blue", name: "colors"))
|
||||
assert_equal("3", cycle(1, 2, 3, name: "numbers"))
|
||||
assert_equal("red", cycle("red", "blue", name: "colors"))
|
||||
end
|
||||
|
||||
def test_current_cycle_with_default_name
|
||||
|
@ -476,11 +476,11 @@ class TextHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_current_cycle_with_named_cycles
|
||||
cycle("red", "blue", :name => "colors")
|
||||
cycle("red", "blue", name: "colors")
|
||||
assert_equal "red", current_cycle("colors")
|
||||
cycle("red", "blue", :name => "colors")
|
||||
cycle("red", "blue", name: "colors")
|
||||
assert_equal "blue", current_cycle("colors")
|
||||
cycle("red", "blue", :name => "colors")
|
||||
cycle("red", "blue", name: "colors")
|
||||
assert_equal "red", current_cycle("colors")
|
||||
end
|
||||
|
||||
|
@ -502,7 +502,7 @@ class TextHelperTest < ActionView::TestCase
|
|||
|
||||
def test_default_named_cycle
|
||||
assert_equal("1", cycle(1, 2, 3))
|
||||
assert_equal("2", cycle(1, 2, 3, :name => "default"))
|
||||
assert_equal("2", cycle(1, 2, 3, name: "default"))
|
||||
assert_equal("3", cycle(1, 2, 3))
|
||||
end
|
||||
|
||||
|
@ -518,13 +518,13 @@ class TextHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_reset_named_cycle
|
||||
assert_equal("1", cycle(1, 2, 3, :name => "numbers"))
|
||||
assert_equal("red", cycle("red", "blue", :name => "colors"))
|
||||
assert_equal("1", cycle(1, 2, 3, name: "numbers"))
|
||||
assert_equal("red", cycle("red", "blue", name: "colors"))
|
||||
reset_cycle("numbers")
|
||||
assert_equal("1", cycle(1, 2, 3, :name => "numbers"))
|
||||
assert_equal("blue", cycle("red", "blue", :name => "colors"))
|
||||
assert_equal("2", cycle(1, 2, 3, :name => "numbers"))
|
||||
assert_equal("red", cycle("red", "blue", :name => "colors"))
|
||||
assert_equal("1", cycle(1, 2, 3, name: "numbers"))
|
||||
assert_equal("blue", cycle("red", "blue", name: "colors"))
|
||||
assert_equal("2", cycle(1, 2, 3, name: "numbers"))
|
||||
assert_equal("red", cycle("red", "blue", name: "colors"))
|
||||
end
|
||||
|
||||
def test_cycle_no_instance_variable_clashes
|
||||
|
|
|
@ -15,22 +15,22 @@ class TranslationHelperTest < ActiveSupport::TestCase
|
|||
|
||||
setup do
|
||||
I18n.backend.store_translations(:en,
|
||||
:translations => {
|
||||
:templates => {
|
||||
:found => { :foo => "Foo" },
|
||||
:array => { :foo => { :bar => "Foo Bar" } },
|
||||
:default => { :foo => "Foo" }
|
||||
translations: {
|
||||
templates: {
|
||||
found: { foo: "Foo" },
|
||||
array: { foo: { bar: "Foo Bar" } },
|
||||
default: { foo: "Foo" }
|
||||
},
|
||||
:foo => "Foo",
|
||||
:hello => "<a>Hello World</a>",
|
||||
:html => "<a>Hello World</a>",
|
||||
:hello_html => "<a>Hello World</a>",
|
||||
:interpolated_html => "<a>Hello %{word}</a>",
|
||||
:array_html => %w(foo bar),
|
||||
:array => %w(foo bar),
|
||||
:count_html => {
|
||||
:one => "<a>One %{count}</a>",
|
||||
:other => "<a>Other %{count}</a>"
|
||||
foo: "Foo",
|
||||
hello: "<a>Hello World</a>",
|
||||
html: "<a>Hello World</a>",
|
||||
hello_html: "<a>Hello World</a>",
|
||||
interpolated_html: "<a>Hello %{word}</a>",
|
||||
array_html: %w(foo bar),
|
||||
array: %w(foo bar),
|
||||
count_html: {
|
||||
one: "<a>One %{count}</a>",
|
||||
other: "<a>Other %{count}</a>"
|
||||
}
|
||||
}
|
||||
)
|
||||
|
@ -42,8 +42,8 @@ class TranslationHelperTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_delegates_setting_to_i18n
|
||||
assert_called_with(I18n, :translate, [:foo, :locale => "en", :raise => true], returns: "") do
|
||||
translate :foo, :locale => "en"
|
||||
assert_called_with(I18n, :translate, [:foo, locale: "en", raise: true], returns: "") do
|
||||
translate :foo, locale: "en"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -96,7 +96,7 @@ class TranslationHelperTest < ActiveSupport::TestCase
|
|||
|
||||
def test_raises_missing_translation_message_with_raise_option
|
||||
assert_raise(I18n::MissingTranslationData) do
|
||||
translate(:"translations.missing", :raise => true)
|
||||
translate(:"translations.missing", raise: true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -122,20 +122,20 @@ class TranslationHelperTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_finds_translation_scoped_by_partial
|
||||
assert_equal "Foo", view.render(:file => "translations/templates/found").strip
|
||||
assert_equal "Foo", view.render(file: "translations/templates/found").strip
|
||||
end
|
||||
|
||||
def test_finds_array_of_translations_scoped_by_partial
|
||||
assert_equal "Foo Bar", @view.render(:file => "translations/templates/array").strip
|
||||
assert_equal "Foo Bar", @view.render(file: "translations/templates/array").strip
|
||||
end
|
||||
|
||||
def test_default_lookup_scoped_by_partial
|
||||
assert_equal "Foo", view.render(:file => "translations/templates/default").strip
|
||||
assert_equal "Foo", view.render(file: "translations/templates/default").strip
|
||||
end
|
||||
|
||||
def test_missing_translation_scoped_by_partial
|
||||
expected = '<span class="translation_missing" title="translation missing: en.translations.templates.missing.missing">Missing</span>'
|
||||
assert_equal expected, view.render(:file => "translations/templates/missing").strip
|
||||
assert_equal expected, view.render(file: "translations/templates/missing").strip
|
||||
end
|
||||
|
||||
def test_translate_does_not_mark_plain_text_as_safe_html
|
||||
|
@ -152,14 +152,14 @@ class TranslationHelperTest < ActiveSupport::TestCase
|
|||
|
||||
def test_translate_escapes_interpolations_in_translations_with_a_html_suffix
|
||||
word_struct = Struct.new(:to_s)
|
||||
assert_equal "<a>Hello <World></a>", translate(:'translations.interpolated_html', :word => "<World>")
|
||||
assert_equal "<a>Hello <World></a>", translate(:'translations.interpolated_html', :word => word_struct.new("<World>"))
|
||||
assert_equal "<a>Hello <World></a>", translate(:'translations.interpolated_html', word: "<World>")
|
||||
assert_equal "<a>Hello <World></a>", translate(:'translations.interpolated_html', word: word_struct.new("<World>"))
|
||||
end
|
||||
|
||||
def test_translate_with_html_count
|
||||
assert_equal "<a>One 1</a>", translate(:'translations.count_html', :count => 1)
|
||||
assert_equal "<a>Other 2</a>", translate(:'translations.count_html', :count => 2)
|
||||
assert_equal "<a>Other <One></a>", translate(:'translations.count_html', :count => "<One>")
|
||||
assert_equal "<a>One 1</a>", translate(:'translations.count_html', count: 1)
|
||||
assert_equal "<a>Other 2</a>", translate(:'translations.count_html', count: 2)
|
||||
assert_equal "<a>Other <One></a>", translate(:'translations.count_html', count: "<One>")
|
||||
end
|
||||
|
||||
def test_translation_returning_an_array_ignores_html_suffix
|
||||
|
@ -167,13 +167,13 @@ class TranslationHelperTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_translate_with_default_named_html
|
||||
translation = translate(:'translations.missing', :default => :'translations.hello_html')
|
||||
translation = translate(:'translations.missing', default: :'translations.hello_html')
|
||||
assert_equal "<a>Hello World</a>", translation
|
||||
assert_equal true, translation.html_safe?
|
||||
end
|
||||
|
||||
def test_translate_with_missing_default
|
||||
translation = translate(:'translations.missing', :default => :'translations.missing_html')
|
||||
translation = translate(:'translations.missing', default: :'translations.missing_html')
|
||||
expected = '<span class="translation_missing" title="translation missing: en.translations.missing_html">Missing Html</span>'
|
||||
assert_equal expected, translation
|
||||
assert_equal true, translation.html_safe?
|
||||
|
@ -181,24 +181,24 @@ class TranslationHelperTest < ActiveSupport::TestCase
|
|||
|
||||
def test_translate_with_missing_default_and_raise_option
|
||||
assert_raise(I18n::MissingTranslationData) do
|
||||
translate(:'translations.missing', :default => :'translations.missing_html', :raise => true)
|
||||
translate(:'translations.missing', default: :'translations.missing_html', raise: true)
|
||||
end
|
||||
end
|
||||
|
||||
def test_translate_with_two_defaults_named_html
|
||||
translation = translate(:'translations.missing', :default => [:'translations.missing_html', :'translations.hello_html'])
|
||||
translation = translate(:'translations.missing', default: [:'translations.missing_html', :'translations.hello_html'])
|
||||
assert_equal "<a>Hello World</a>", translation
|
||||
assert_equal true, translation.html_safe?
|
||||
end
|
||||
|
||||
def test_translate_with_last_default_named_html
|
||||
translation = translate(:'translations.missing', :default => [:'translations.missing', :'translations.hello_html'])
|
||||
translation = translate(:'translations.missing', default: [:'translations.missing', :'translations.hello_html'])
|
||||
assert_equal "<a>Hello World</a>", translation
|
||||
assert_equal true, translation.html_safe?
|
||||
end
|
||||
|
||||
def test_translate_with_last_default_not_named_html
|
||||
translation = translate(:'translations.missing', :default => [:'translations.missing_html', :'translations.foo'])
|
||||
translation = translate(:'translations.missing', default: [:'translations.missing_html', :'translations.foo'])
|
||||
assert_equal "Foo", translation
|
||||
assert_equal false, translation.html_safe?
|
||||
end
|
||||
|
|
|
@ -452,7 +452,7 @@ class UrlHelperTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_current_page_with_http_head_method
|
||||
@request = request_for_url("/", :method => :head)
|
||||
@request = request_for_url("/", method: :head)
|
||||
assert current_page?(url_hash)
|
||||
assert current_page?("http://www.example.com/")
|
||||
end
|
||||
|
@ -492,7 +492,7 @@ class UrlHelperTest < ActiveSupport::TestCase
|
|||
def test_current_page_with_escaped_params_with_different_encoding
|
||||
@request = request_for_url("/")
|
||||
@request.stub(:path, "/category/administra%c3%a7%c3%a3o".force_encoding(Encoding::ASCII_8BIT)) do
|
||||
assert current_page?(:controller => "foo", :action => "category", category: "administração")
|
||||
assert current_page?(controller: "foo", action: "category", category: "administração")
|
||||
assert current_page?("http://www.example.com/category/administra%c3%a7%c3%a3o")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue