diff options
Diffstat (limited to 'actionview/test/activerecord')
6 files changed, 101 insertions, 99 deletions
diff --git a/actionview/test/activerecord/controller_runtime_test.rb b/actionview/test/activerecord/controller_runtime_test.rb index af91348d76..590559f592 100644 --- a/actionview/test/activerecord/controller_runtime_test.rb +++ b/actionview/test/activerecord/controller_runtime_test.rb @@ -1,19 +1,19 @@ -require 'active_record_unit' -require 'active_record/railties/controller_runtime' -require 'fixtures/project' -require 'active_support/log_subscriber/test_helper' -require 'action_controller/log_subscriber' +require "active_record_unit" +require "active_record/railties/controller_runtime" +require "fixtures/project" +require "active_support/log_subscriber/test_helper" +require "action_controller/log_subscriber" 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 @@ -38,8 +38,8 @@ class ControllerRuntimeLogSubscriberTest < ActionController::TestCase tests LogSubscriberController def setup - super @old_logger = ActionController::Base.logger + super ActionController::LogSubscriber.attach_to :action_controller end diff --git a/actionview/test/activerecord/debug_helper_test.rb b/actionview/test/activerecord/debug_helper_test.rb index 03cb1d5a91..06ae555a03 100644 --- a/actionview/test/activerecord/debug_helper_test.rb +++ b/actionview/test/activerecord/debug_helper_test.rb @@ -1,14 +1,17 @@ -require 'active_record_unit' -require 'nokogiri' +require "active_record_unit" +require "nokogiri" class DebugHelperTest < ActionView::TestCase def test_debug company = Company.new(name: "firebase") - assert_match "name: firebase", debug(company) + output = debug(company) + assert_match "name: name", output + assert_match "value_before_type_cast: firebase", output + assert_match "active_record_yaml_version: 2", output end def test_debug_with_marshal_error - obj = -> { } + obj = -> {} assert_match obj.inspect, Nokogiri.XML(debug(obj)).content end end diff --git a/actionview/test/activerecord/form_helper_activerecord_test.rb b/actionview/test/activerecord/form_helper_activerecord_test.rb index 2769b97445..6152ec4720 100644 --- a/actionview/test/activerecord/form_helper_activerecord_test.rb +++ b/actionview/test/activerecord/form_helper_activerecord_test.rb @@ -1,6 +1,6 @@ -require 'active_record_unit' -require 'fixtures/project' -require 'fixtures/developer' +require "active_record_unit" +require "fixtures/project" +require "fixtures/developer" class FormHelperActiveRecordTest < ActionView::TestCase tests ActionView::Helpers::FormHelper @@ -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 @@ -54,35 +54,35 @@ class FormHelperActiveRecordTest < ActionView::TestCase protected - def hidden_fields(method = nil) - txt = %{<input name="utf8" type="hidden" value="✓" />} + def hidden_fields(method = nil) + txt = %{<input name="utf8" type="hidden" value="✓" />} - if method && !%w(get post).include?(method.to_s) - txt << %{<input name="_method" type="hidden" value="#{method}" />} + if method && !%w(get post).include?(method.to_s) + txt << %{<input name="_method" type="hidden" value="#{method}" />} + end + + txt end - txt - end + def form_text(action = "/", id = nil, html_class = nil, remote = nil, multipart = nil, method = nil) + txt = %{<form accept-charset="UTF-8" action="#{action}"} + txt << %{ enctype="multipart/form-data"} if multipart + txt << %{ data-remote="true"} if remote + txt << %{ class="#{html_class}"} if html_class + txt << %{ id="#{id}"} if id + method = method.to_s == "get" ? "get" : "post" + txt << %{ method="#{method}">} + end - def form_text(action = "/", id = nil, html_class = nil, remote = nil, multipart = nil, method = nil) - txt = %{<form accept-charset="UTF-8" action="#{action}"} - txt << %{ enctype="multipart/form-data"} if multipart - txt << %{ data-remote="true"} if remote - txt << %{ class="#{html_class}"} if html_class - txt << %{ id="#{id}"} if id - method = method.to_s == "get" ? "get" : "post" - txt << %{ method="#{method}">} - end + def whole_form(action = "/", id = nil, html_class = nil, options = nil) + contents = block_given? ? yield : "" - def whole_form(action = "/", id = nil, html_class = nil, options = nil) - contents = block_given? ? yield : "" + if options.is_a?(Hash) + method, remote, multipart = options.values_at(:method, :remote, :multipart) + else + method = options + end - if options.is_a?(Hash) - method, remote, multipart = options.values_at(:method, :remote, :multipart) - else - method = options + form_text(action, id, html_class, remote, multipart, method) + hidden_fields(method) + contents + "</form>" end - - form_text(action, id, html_class, remote, multipart, method) + hidden_fields(method) + contents + "</form>" - end end diff --git a/actionview/test/activerecord/polymorphic_routes_test.rb b/actionview/test/activerecord/polymorphic_routes_test.rb index 34b2698c7f..8495949975 100644 --- a/actionview/test/activerecord/polymorphic_routes_test.rb +++ b/actionview/test/activerecord/polymorphic_routes_test.rb @@ -1,28 +1,28 @@ -require 'active_record_unit' -require 'fixtures/project' +require "active_record_unit" +require "fixtures/project" class Task < ActiveRecord::Base - self.table_name = 'projects' + self.table_name = "projects" end class Step < ActiveRecord::Base - self.table_name = 'projects' + self.table_name = "projects" end class Bid < ActiveRecord::Base - self.table_name = 'projects' + self.table_name = "projects" end class Tax < ActiveRecord::Base - self.table_name = 'projects' + self.table_name = "projects" end class Fax < ActiveRecord::Base - self.table_name = 'projects' + self.table_name = "projects" end class Series < ActiveRecord::Base - self.table_name = 'projects' + self.table_name = "projects" end class ModelDelegator @@ -41,17 +41,17 @@ class ModelDelegate end def to_param - 'overridden' + "overridden" end end module Blog class Post < ActiveRecord::Base - self.table_name = 'projects' + self.table_name = "projects" end class Blog < ActiveRecord::Base - self.table_name = 'projects' + self.table_name = "projects" end def self.use_relative_model_naming? @@ -61,7 +61,7 @@ end class PolymorphicRoutesTest < ActionController::TestCase include SharedTestRoutes.url_helpers - self.default_url_options[:host] = 'example.com' + self.default_url_options[:host] = "example.com" def setup @project = Project.new @@ -79,7 +79,7 @@ class PolymorphicRoutesTest < ActionController::TestCase def assert_url(url, args) host = self.class.default_url_options[:host] - assert_equal url.sub(/http:\/\/#{host}/, ''), polymorphic_path(args) + assert_equal url.sub(/http:\/\/#{host}/, ""), polymorphic_path(args) assert_equal url, polymorphic_url(args) assert_equal url, url_for(args) 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 @@ -493,7 +493,7 @@ class PolymorphicRoutesTest < ActionController::TestCase object_array = [:admin, @project, @task] original_args = [object_array.dup, options.dup] - assert_no_difference('object_array.size') { polymorphic_path(object_array, options) } + assert_no_difference("object_array.size") { polymorphic_path(object_array, options) } assert_equal original_args, [object_array, options] 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 @@ -598,7 +598,7 @@ class PolymorphicRoutesTest < ActionController::TestCase end end - # Tests for uncountable names + # Tests for uncountable names def test_uncountable_resource with_test_routes do @series.save @@ -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 @@ -728,6 +728,6 @@ class PolymorphicPathRoutesTest < PolymorphicRoutesTest def assert_url(url, args) host = self.class.default_url_options[:host] - assert_equal url.sub(/http:\/\/#{host}/, ''), url_for(args) + assert_equal url.sub(/http:\/\/#{host}/, ""), url_for(args) end end diff --git a/actionview/test/activerecord/relation_cache_test.rb b/actionview/test/activerecord/relation_cache_test.rb index 8e97417b94..880e80a8dc 100644 --- a/actionview/test/activerecord/relation_cache_test.rb +++ b/actionview/test/activerecord/relation_cache_test.rb @@ -1,4 +1,4 @@ -require 'active_record_unit' +require "active_record_unit" class RelationCacheTest < ActionView::TestCase tests ActionView::Helpers::CacheHelper @@ -9,10 +9,9 @@ class RelationCacheTest < ActionView::TestCase end def test_cache_relation_other - cache(Project.all){ concat("Hello World") } + cache(Project.all) { concat("Hello World") } assert_equal "Hello World", controller.cache_store.read("views/projects-#{Project.count}/") end def view_cache_dependencies; end - end diff --git a/actionview/test/activerecord/render_partial_with_record_identification_test.rb b/actionview/test/activerecord/render_partial_with_record_identification_test.rb index 9772ebb39e..55886da30f 100644 --- a/actionview/test/activerecord/render_partial_with_record_identification_test.rb +++ b/actionview/test/activerecord/render_partial_with_record_identification_test.rb @@ -1,48 +1,48 @@ -require 'active_record_unit' +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 @@ -57,27 +57,27 @@ class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase def test_rendering_partial_with_has_many_association get :render_with_has_many_association - assert_equal 'Birdman is better!', @response.body + assert_equal "Birdman is better!", @response.body end def test_rendering_partial_with_scope get :render_with_scope - assert_equal 'Birdman is better!Nuh uh!', @response.body + assert_equal "Birdman is better!Nuh uh!", @response.body end def test_render_with_record get :render_with_record - assert_equal 'David', @response.body + assert_equal "David", @response.body end def test_render_with_record_collection get :render_with_record_collection - assert_equal 'DavidJamisfixture_3fixture_4fixture_5fixture_6fixture_7fixture_8fixture_9fixture_10Jamis', @response.body + assert_equal "DavidJamisfixture_3fixture_4fixture_5fixture_6fixture_7fixture_8fixture_9fixture_10Jamis", @response.body end def test_render_with_record_collection_and_spacer_template get :render_with_record_collection_and_spacer_template - assert_equal Developer.find(1).projects.map(&:name).join('only partial'), @response.body + assert_equal Developer.find(1).projects.map(&:name).join("only partial"), @response.body end def test_rendering_partial_with_has_one_association @@ -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 |