diff options
Diffstat (limited to 'actionview')
25 files changed, 99 insertions, 125 deletions
diff --git a/actionview/lib/action_view/flows.rb b/actionview/lib/action_view/flows.rb index ed30afb83d..16874c1194 100644 --- a/actionview/lib/action_view/flows.rb +++ b/actionview/lib/action_view/flows.rb @@ -23,7 +23,6 @@ module ActionView @content[key] << value end alias_method :append!, :append - end class StreamingFlow < OutputFlow #:nodoc: diff --git a/actionview/lib/action_view/helpers/atom_feed_helper.rb b/actionview/lib/action_view/helpers/atom_feed_helper.rb index 46e4172e5d..e5d063e03c 100644 --- a/actionview/lib/action_view/helpers/atom_feed_helper.rb +++ b/actionview/lib/action_view/helpers/atom_feed_helper.rb @@ -198,7 +198,6 @@ module ActionView end end end - end end end diff --git a/actionview/lib/action_view/helpers/date_helper.rb b/actionview/lib/action_view/helpers/date_helper.rb index f2ef714e8e..99db209d63 100644 --- a/actionview/lib/action_view/helpers/date_helper.rb +++ b/actionview/lib/action_view/helpers/date_helper.rb @@ -103,58 +103,58 @@ module ActionView 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] - - 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 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 - 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 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] + + 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 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 + end + + 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 + fyear += 1 if from_time.month >= 3 + tyear = to_time.year + tyear -= 1 if to_time.month < 3 + leap_years = (fyear > tyear) ? 0 : (fyear..tyear).count{|x| Date.leap?(x)} + minute_offset_for_leap_year = leap_years * 1440 + # Discount the leap year days when calculating year distance. + # e.g. if there are 20 leap year days between 2 dates having the same day + # and month then the based on 365 days calculation + # the distance in years will come out to over 80 years when in written + # English it would read better as about 80 years. + minutes_with_offset = distance_in_minutes - minute_offset_for_leap_year else - if from_time.acts_like?(:time) && to_time.acts_like?(:time) - fyear = from_time.year - fyear += 1 if from_time.month >= 3 - tyear = to_time.year - tyear -= 1 if to_time.month < 3 - leap_years = (fyear > tyear) ? 0 : (fyear..tyear).count{|x| Date.leap?(x)} - minute_offset_for_leap_year = leap_years * 1440 - # Discount the leap year days when calculating year distance. - # e.g. if there are 20 leap year days between 2 dates having the same day - # and month then the based on 365 days calculation - # the distance in years will come out to over 80 years when in written - # English it would read better as about 80 years. - minutes_with_offset = distance_in_minutes - minute_offset_for_leap_year - else - minutes_with_offset = distance_in_minutes - end - 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) - elsif remainder < MINUTES_IN_THREE_QUARTERS_YEAR - locale.t(:over_x_years, count: distance_in_years) - else - locale.t(:almost_x_years, count: distance_in_years + 1) - end + minutes_with_offset = distance_in_minutes + end + 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) + elsif remainder < MINUTES_IN_THREE_QUARTERS_YEAR + locale.t(:over_x_years, count: distance_in_years) + else + locale.t(:almost_x_years, count: distance_in_years + 1) + end end end end @@ -1026,13 +1026,13 @@ module ActionView # => "<option value="">Select month</option>" 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.merge!(options)[type.to_sym] - when String - options + when Hash + 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: "") : "" @@ -1093,12 +1093,12 @@ module ActionView return "" if @options[:use_hidden] case type - when :year, :month, :day - @options[:"discard_#{type}"] ? "" : @options[:date_separator] - when :hour - (@options[:discard_year] && @options[:discard_day]) ? "" : @options[:datetime_separator] - when :minute, :second - @options[:"discard_#{type}"] ? "" : @options[:time_separator] + when :year, :month, :day + @options[:"discard_#{type}"] ? "" : @options[:date_separator] + when :hour + (@options[:discard_year] && @options[:discard_day]) ? "" : @options[:datetime_separator] + when :minute, :second + @options[:"discard_#{type}"] ? "" : @options[:time_separator] end end end diff --git a/actionview/lib/action_view/helpers/debug_helper.rb b/actionview/lib/action_view/helpers/debug_helper.rb index 468a798d93..f61ca2c9c2 100644 --- a/actionview/lib/action_view/helpers/debug_helper.rb +++ b/actionview/lib/action_view/helpers/debug_helper.rb @@ -4,7 +4,6 @@ module ActionView # Provides a set of methods for making it easier to debug Rails objects. module Helpers module DebugHelper - include TagHelper # Returns a YAML representation of +object+ wrapped with <pre> and </pre>. diff --git a/actionview/lib/action_view/helpers/form_tag_helper.rb b/actionview/lib/action_view/helpers/form_tag_helper.rb index 5b1392a099..a8abe6b7c4 100644 --- a/actionview/lib/action_view/helpers/form_tag_helper.rb +++ b/actionview/lib/action_view/helpers/form_tag_helper.rb @@ -858,21 +858,21 @@ module ActionView method = html_options.delete("method").to_s.downcase method_tag = case method - when "get" - html_options["method"] = "get" - "" - when "post", "" - html_options["method"] = "post" - token_tag(authenticity_token, form_options: { - action: html_options["action"], - method: "post" - }) + when "get" + html_options["method"] = "get" + "" + when "post", "" + html_options["method"] = "post" + token_tag(authenticity_token, form_options: { + action: html_options["action"], + method: "post" + }) else - html_options["method"] = "post" - method_tag(method) + token_tag(authenticity_token, form_options: { - action: html_options["action"], - method: method - }) + html_options["method"] = "post" + method_tag(method) + token_tag(authenticity_token, form_options: { + action: html_options["action"], + method: method + }) end if html_options.delete("enforce_utf8") { true } diff --git a/actionview/lib/action_view/helpers/number_helper.rb b/actionview/lib/action_view/helpers/number_helper.rb index 9540850004..75b898c3e9 100644 --- a/actionview/lib/action_view/helpers/number_helper.rb +++ b/actionview/lib/action_view/helpers/number_helper.rb @@ -5,7 +5,6 @@ require "active_support/number_helper" module ActionView # = Action View Number Helpers module Helpers #:nodoc: - # Provides methods for converting numbers into formatted strings. # Methods are provided for phone numbers, currency, percentage, # precision, positional notation, file size and pretty printing. @@ -13,7 +12,6 @@ module ActionView # Most methods expect a +number+ argument, and will return it # unchanged if can't be converted into a valid number. module NumberHelper - # Raised when argument +number+ param given to the helpers is invalid and # the option :raise is set to +true+. class InvalidNumberError < StandardError diff --git a/actionview/lib/action_view/helpers/tag_helper.rb b/actionview/lib/action_view/helpers/tag_helper.rb index dfa66e11d9..030d07845b 100644 --- a/actionview/lib/action_view/helpers/tag_helper.rb +++ b/actionview/lib/action_view/helpers/tag_helper.rb @@ -109,7 +109,6 @@ module ActionView def method_missing(called, *args, &block) tag_string(called, *args, &block) end - end # Returns an HTML tag. diff --git a/actionview/lib/action_view/layouts.rb b/actionview/lib/action_view/layouts.rb index bf36dde181..b2fcd823d2 100644 --- a/actionview/lib/action_view/layouts.rb +++ b/actionview/lib/action_view/layouts.rb @@ -291,10 +291,10 @@ module ActionView end layout_definition = case _layout - when String - _layout.inspect - when Symbol - <<-RUBY + when String + _layout.inspect + when Symbol + <<-RUBY #{_layout}.tap do |layout| return #{default_behavior} if layout.nil? unless layout.is_a?(String) || !layout @@ -303,20 +303,20 @@ module ActionView end end RUBY - when Proc - define_method :_layout_from_proc, &_layout - protected :_layout_from_proc - <<-RUBY + when Proc + define_method :_layout_from_proc, &_layout + protected :_layout_from_proc + <<-RUBY result = _layout_from_proc(#{_layout.arity == 0 ? '' : 'self'}) return #{default_behavior} if result.nil? result RUBY - when false - nil - when true - raise ArgumentError, "Layouts must be specified as a String, Symbol, Proc, false, or nil" - when nil - name_clause + when false + nil + when true + raise ArgumentError, "Layouts must be specified as a String, Symbol, Proc, false, or nil" + when nil + name_clause end self.class_eval <<-RUBY, __FILE__, __LINE__ + 1 diff --git a/actionview/lib/action_view/routing_url_for.rb b/actionview/lib/action_view/routing_url_for.rb index d07765265f..669cffab1a 100644 --- a/actionview/lib/action_view/routing_url_for.rb +++ b/actionview/lib/action_view/routing_url_for.rb @@ -2,7 +2,6 @@ require "action_dispatch/routing/polymorphic_routes" module ActionView module RoutingUrlFor - # Returns the URL for the set of +options+ provided. This takes the # same options as +url_for+ in Action Controller (see the # documentation for <tt>ActionController::Base#url_for</tt>). Note that by default diff --git a/actionview/lib/action_view/test_case.rb b/actionview/lib/action_view/test_case.rb index 29be7dc7a8..42fa17d1e0 100644 --- a/actionview/lib/action_view/test_case.rb +++ b/actionview/lib/action_view/test_case.rb @@ -96,7 +96,6 @@ module ActionView helper(helper_class) if helper_class include _helpers end - end def setup_with_controller diff --git a/actionview/test/actionpack/abstract/abstract_controller_test.rb b/actionview/test/actionpack/abstract/abstract_controller_test.rb index 9989b5a377..c92467c15f 100644 --- a/actionview/test/actionpack/abstract/abstract_controller_test.rb +++ b/actionview/test/actionpack/abstract/abstract_controller_test.rb @@ -3,7 +3,6 @@ require "set" module AbstractController module Testing - # Test basic dispatching. # ==== # * Call process @@ -248,7 +247,6 @@ module AbstractController end class TestRespondToAction < ActiveSupport::TestCase - def assert_dispatch(klass, body = "success", action = :index) controller = klass.new controller.process(action) @@ -284,11 +282,9 @@ module AbstractController end class TestActionMethodsReloading < ActiveSupport::TestCase - test "action_methods should be reloaded after defining a new method" do assert_equal Set.new(["index"]), Me6.action_methods end end - end end diff --git a/actionview/test/actionpack/abstract/helper_test.rb b/actionview/test/actionpack/abstract/helper_test.rb index a6c79f0308..5a2f0839e5 100644 --- a/actionview/test/actionpack/abstract/helper_test.rb +++ b/actionview/test/actionpack/abstract/helper_test.rb @@ -4,7 +4,6 @@ ActionController::Base.helpers_path = File.expand_path("../../../fixtures/helper module AbstractController module Testing - class ControllerWithHelpers < AbstractController::Base include AbstractController::Helpers include AbstractController::Rendering diff --git a/actionview/test/actionpack/abstract/layouts_test.rb b/actionview/test/actionpack/abstract/layouts_test.rb index e4abac1315..4ece992597 100644 --- a/actionview/test/actionpack/abstract/layouts_test.rb +++ b/actionview/test/actionpack/abstract/layouts_test.rb @@ -2,7 +2,6 @@ require "abstract_unit" module AbstractControllerTests module Layouts - # Base controller for these tests class Base < AbstractController::Base include AbstractController::Rendering diff --git a/actionview/test/actionpack/abstract/render_test.rb b/actionview/test/actionpack/abstract/render_test.rb index c658f5ae58..8b0c54fb77 100644 --- a/actionview/test/actionpack/abstract/render_test.rb +++ b/actionview/test/actionpack/abstract/render_test.rb @@ -2,7 +2,6 @@ require "abstract_unit" module AbstractController module Testing - class ControllerRenderer < AbstractController::Base include AbstractController::Rendering include ActionView::Rendering @@ -54,7 +53,6 @@ module AbstractController end class TestRenderer < ActiveSupport::TestCase - def setup @controller = ControllerRenderer.new end diff --git a/actionview/test/actionpack/controller/render_test.rb b/actionview/test/actionpack/controller/render_test.rb index 9c13bd7f8e..453c2e75d6 100644 --- a/actionview/test/actionpack/controller/render_test.rb +++ b/actionview/test/actionpack/controller/render_test.rb @@ -642,7 +642,7 @@ class TestController < ApplicationController def determine_layout case action_name - when "hello_world", "layout_test", "rendering_without_layout", + when "hello_world", "layout_test", "rendering_without_layout", "rendering_nothing_on_layout", "render_text_hello_world", "render_text_hello_world_with_layout", "hello_world_with_layout_false", @@ -652,11 +652,11 @@ class TestController < ApplicationController "render_with_explicit_string_template", "update_page", "update_page_with_instance_variables" - "layouts/standard" - when "action_talk_to_layout", "layout_overriding_layout" - "layouts/talk_from_action" - when "render_implicit_html_template_from_xhr_request" - (request.xhr? ? "layouts/xhr" : "layouts/standard") + "layouts/standard" + when "action_talk_to_layout", "layout_overriding_layout" + "layouts/talk_from_action" + when "render_implicit_html_template_from_xhr_request" + (request.xhr? ? "layouts/xhr" : "layouts/standard") end end end diff --git a/actionview/test/activerecord/relation_cache_test.rb b/actionview/test/activerecord/relation_cache_test.rb index 970dfae784..15ddcdd5f6 100644 --- a/actionview/test/activerecord/relation_cache_test.rb +++ b/actionview/test/activerecord/relation_cache_test.rb @@ -14,5 +14,4 @@ class RelationCacheTest < ActionView::TestCase end def view_cache_dependencies; end - end diff --git a/actionview/test/lib/controller/fake_models.rb b/actionview/test/lib/controller/fake_models.rb index e1b362c6ed..cc5f5c1d59 100644 --- a/actionview/test/lib/controller/fake_models.rb +++ b/actionview/test/lib/controller/fake_models.rb @@ -108,7 +108,6 @@ class Tag attr_accessor :relevances def relevances_attributes=(attributes); end - end class CommentRelevance diff --git a/actionview/test/template/active_model_helper_test.rb b/actionview/test/template/active_model_helper_test.rb index 1fba4298e8..8b8f686f96 100644 --- a/actionview/test/template/active_model_helper_test.rb +++ b/actionview/test/template/active_model_helper_test.rb @@ -95,5 +95,4 @@ class ActiveModelHelperTest < ActionView::TestCase ensure ActionView::Base.field_error_proc = old_proc if old_proc end - end diff --git a/actionview/test/template/form_options_helper_test.rb b/actionview/test/template/form_options_helper_test.rb index f588fb2fd2..84c322e522 100644 --- a/actionview/test/template/form_options_helper_test.rb +++ b/actionview/test/template/form_options_helper_test.rb @@ -495,9 +495,9 @@ class FormOptionsHelperTest < ActionView::TestCase assert_dom_equal( [ - %Q{<select id="post_origin" name="post[origin]"><optgroup label="<Africa>"><option value="<sa>"><South Africa></option>}, - %Q{<option value="so">Somalia</option></optgroup><optgroup label="Europe"><option value="dk">Denmark</option>}, - %Q{<option value="ie">Ireland</option></optgroup></select>}, + '<select id="post_origin" name="post[origin]"><optgroup label="<Africa>"><option value="<sa>"><South Africa></option>', + '<option value="so">Somalia</option></optgroup><optgroup label="Europe"><option value="dk">Denmark</option>', + '<option value="ie">Ireland</option></optgroup></select>', ].join("\n"), select("post", "origin", countries_by_continent) ) @@ -513,9 +513,9 @@ class FormOptionsHelperTest < ActionView::TestCase assert_dom_equal( [ - %Q{<select id="post_origin" name="post[origin]"><optgroup label="<Africa>"><option value="<sa>"><South Africa></option>}, - %Q{<option value="so">Somalia</option></optgroup><optgroup label="Europe"><option value="dk">Denmark</option>}, - %Q{<option value="ie">Ireland</option></optgroup></select>}, + '<select id="post_origin" name="post[origin]"><optgroup label="<Africa>"><option value="<sa>"><South Africa></option>', + '<option value="so">Somalia</option></optgroup><optgroup label="Europe"><option value="dk">Denmark</option>', + '<option value="ie">Ireland</option></optgroup></select>', ].join("\n"), select("post", "origin", countries_by_continent) ) diff --git a/actionview/test/template/lookup_context_test.rb b/actionview/test/template/lookup_context_test.rb index 2a8ae9d4a3..77fab5652f 100644 --- a/actionview/test/template/lookup_context_test.rb +++ b/actionview/test/template/lookup_context_test.rb @@ -284,5 +284,4 @@ class TestMissingTemplate < ActiveSupport::TestCase end assert_match %r{Missing partial parent/_foo with .* Searched in:\n \* "/Path/to/views"\n}, e.message end - end diff --git a/actionview/test/template/record_tag_helper_test.rb b/actionview/test/template/record_tag_helper_test.rb index 2840ad01b2..3685230558 100644 --- a/actionview/test/template/record_tag_helper_test.rb +++ b/actionview/test/template/record_tag_helper_test.rb @@ -14,7 +14,6 @@ class RecordTagPost end class RecordTagHelperTest < ActionView::TestCase - tests ActionView::Helpers::RecordTagHelper def setup diff --git a/actionview/test/template/tag_helper_test.rb b/actionview/test/template/tag_helper_test.rb index 3e060d0246..281fec7291 100644 --- a/actionview/test/template/tag_helper_test.rb +++ b/actionview/test/template/tag_helper_test.rb @@ -334,5 +334,4 @@ class TagHelperTest < ActionView::TestCase def test_respond_to assert_respond_to tag, :any_tag end - end diff --git a/actionview/test/template/test_case_test.rb b/actionview/test/template/test_case_test.rb index cd7221ca0e..40a5bfca53 100644 --- a/actionview/test/template/test_case_test.rb +++ b/actionview/test/template/test_case_test.rb @@ -2,7 +2,6 @@ require "abstract_unit" require "rails/engine" module ActionView - module ATestHelper end @@ -193,7 +192,6 @@ module ActionView test "protect_from_forgery? in any helpers returns false" do assert !view.help_me end - end class ATestHelperTest < ActionView::TestCase @@ -282,7 +280,6 @@ module ActionView @customers = [DeveloperStruct.new("Eloy"), DeveloperStruct.new("Manfred")] assert_match(/Hello: EloyHello: Manfred/, render(file: "test/list")) end - end class AssertionsTest < ActionView::TestCase diff --git a/actionview/test/template/text_helper_test.rb b/actionview/test/template/text_helper_test.rb index 0317c433d1..9f57e6a6ae 100644 --- a/actionview/test/template/text_helper_test.rb +++ b/actionview/test/template/text_helper_test.rb @@ -38,7 +38,7 @@ 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 '<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 diff --git a/actionview/test/template/url_helper_test.rb b/actionview/test/template/url_helper_test.rb index 4fd3e0369c..bbbeb39f3f 100644 --- a/actionview/test/template/url_helper_test.rb +++ b/actionview/test/template/url_helper_test.rb @@ -1,7 +1,6 @@ require "abstract_unit" class UrlHelperTest < ActiveSupport::TestCase - # In a few cases, the helper proxies to 'controller' # or request. # |