Skip to content
This repository
Browse code

ActionPack components should no longer have undeclared dependencies.

  * Tests can be run in isolation
  * Dependencies added
  * A few tests modified to avoid depending on AS deps 
    not depended on my files they were testing
  • Loading branch information...
commit 86fc43fd584726ba81b1a3b3e0a6f6000c1f4cc8 1 parent 00ee990
authored June 08, 2009
8  actionpack/Rakefile
@@ -35,6 +35,14 @@ Rake::TestTask.new(:test_action_pack) do |t|
35 35
   t.verbose = true
36 36
   #t.warning = true
37 37
 end
  38
+
  39
+task :test_action_pack_isolated do
  40
+  test_files = Dir.glob( "test/{controller,dispatch,template,html-scanner}/**/*_test.rb" ).sort
  41
+  test_lib   = test_lib_dirs.map { |lib| "-I#{lib}" }.join(' ')
  42
+  test_files.map! { |f| "ruby #{test_lib} #{f}" }
  43
+  exec test_files.join(" && ")
  44
+end
  45
+
38 46
 task :isolated_test do
39 47
   ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
40 48
   Dir.glob("test/{controller,dispatch,template}/**/*_test.rb").all? do |file|
4  actionpack/lib/action_controller/routing/resources.rb
@@ -150,9 +150,9 @@ def set_allowed_actions
150 150
           end
151 151
 
152 152
           if only
153  
-            @allowed_actions[:only] = Array(only).map(&:to_sym)
  153
+            @allowed_actions[:only] = Array(only).map {|a| a.to_sym }
154 154
           elsif except
155  
-            @allowed_actions[:except] = Array(except).map(&:to_sym)
  155
+            @allowed_actions[:except] = Array(except).map {|a| a.to_sym }
156 156
           end
157 157
         end
158 158
 
1  actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb
... ...
@@ -1,3 +1,4 @@
  1
+require "active_support/core_ext/kernel/requires"
1 2
 begin
2 3
   require_library_or_gem 'memcache'
3 4
 
2  actionpack/lib/action_dispatch/middleware/show_exceptions.rb
... ...
@@ -1,3 +1,5 @@
  1
+require "active_support/core_ext/exception"
  2
+
1 3
 module ActionDispatch
2 4
   class ShowExceptions
3 5
     include StatusCodes
2  actionpack/lib/action_view/helpers/active_record_helper.rb
... ...
@@ -1,6 +1,8 @@
1 1
 require 'cgi'
2 2
 require 'action_view/helpers/form_helper'
3 3
 require 'active_support/core_ext/class/attribute_accessors'
  4
+require 'active_support/core_ext/enumerable'
  5
+require 'active_support/core_ext/kernel/reporting'
4 6
 
5 7
 module ActionView
6 8
   class Base
2  actionpack/lib/action_view/helpers/benchmark_helper.rb
... ...
@@ -1,4 +1,4 @@
1  
-require 'benchmark'
  1
+require 'active_support/core_ext/benchmark'
2 2
 
3 3
 module ActionView
4 4
   module Helpers
6  actionpack/lib/action_view/helpers/url_helper.rb
@@ -221,9 +221,9 @@ def link_to(*args, &block)
221 221
           html_options = args.second
222 222
           concat(link_to(capture(&block), options, html_options))
223 223
         else
224  
-          name         = args.first
225  
-          options      = args.second || {}
226  
-          html_options = args.third
  224
+          name         = args[0]
  225
+          options      = args[1] || {}
  226
+          html_options = args[2]
227 227
 
228 228
           url = url_for(options)
229 229
 
2  actionpack/lib/action_view/template/error.rb
... ...
@@ -1,3 +1,5 @@
  1
+require "active_support/core_ext/enumerable"
  2
+
1 3
 module ActionView
2 4
   # The TemplateError exception is raised when the compilation of the template fails. This exception then gathers a
3 5
   # bunch of intimate details and uses it to report a very precise exception message.
6  actionpack/test/controller/helper_test.rb
@@ -127,7 +127,7 @@ def test_helper_for_acronym_controller
127 127
   end
128 128
 
129 129
   def test_all_helpers
130  
-    methods = AllHelpersController.master_helper_module.instance_methods.map(&:to_s)
  130
+    methods = AllHelpersController.master_helper_module.instance_methods.map {|m| m.to_s}
131 131
 
132 132
     # abc_helper.rb
133 133
     assert methods.include?('bare_a')
@@ -171,11 +171,11 @@ def test_helper_proxy
171 171
 
172 172
   private
173 173
     def expected_helper_methods
174  
-      TestHelper.instance_methods.map(&:to_s)
  174
+      TestHelper.instance_methods.map {|m| m.to_s }
175 175
     end
176 176
 
177 177
     def master_helper_methods
178  
-      @controller_class.master_helper_module.instance_methods.map(&:to_s)
  178
+      @controller_class.master_helper_module.instance_methods.map {|m| m.to_s }
179 179
     end
180 180
 
181 181
     def missing_methods
8  actionpack/test/controller/routing_test.rb
@@ -1623,13 +1623,13 @@ def test_generate_extras
1623 1623
     set.draw { |m| m.connect ':controller/:action/:id' }
1624 1624
     path, extras = set.generate_extras(:controller => "foo", :action => "bar", :id => 15, :this => "hello", :that => "world")
1625 1625
     assert_equal "/foo/bar/15", path
1626  
-    assert_equal %w(that this), extras.map(&:to_s).sort
  1626
+    assert_equal %w(that this), extras.map { |e| e.to_s }.sort
1627 1627
   end
1628 1628
 
1629 1629
   def test_extra_keys
1630 1630
     set.draw { |m| m.connect ':controller/:action/:id' }
1631 1631
     extras = set.extra_keys(:controller => "foo", :action => "bar", :id => 15, :this => "hello", :that => "world")
1632  
-    assert_equal %w(that this), extras.map(&:to_s).sort
  1632
+    assert_equal %w(that this), extras.map { |e| e.to_s }.sort
1633 1633
   end
1634 1634
 
1635 1635
   def test_generate_extras_not_first
@@ -1639,7 +1639,7 @@ def test_generate_extras_not_first
1639 1639
     end
1640 1640
     path, extras = set.generate_extras(:controller => "foo", :action => "bar", :id => 15, :this => "hello", :that => "world")
1641 1641
     assert_equal "/foo/bar/15", path
1642  
-    assert_equal %w(that this), extras.map(&:to_s).sort
  1642
+    assert_equal %w(that this), extras.map { |e| e.to_s }.sort
1643 1643
   end
1644 1644
 
1645 1645
   def test_generate_not_first
@@ -1656,7 +1656,7 @@ def test_extra_keys_not_first
1656 1656
       map.connect ':controller/:action/:id'
1657 1657
     end
1658 1658
     extras = set.extra_keys(:controller => "foo", :action => "bar", :id => 15, :this => "hello", :that => "world")
1659  
-    assert_equal %w(that this), extras.map(&:to_s).sort
  1659
+    assert_equal %w(that this), extras.map { |e| e.to_s }.sort
1660 1660
   end
1661 1661
 
1662 1662
   def test_draw
4  actionpack/test/dispatch/mime_type_test.rb
@@ -56,7 +56,7 @@ class MimeTypeTest < ActiveSupport::TestCase
56 56
 
57 57
   test "type convenience methods" do
58 58
     # Don't test Mime::ALL, since it Mime::ALL#html? == true
59  
-    types = Mime::SET.to_a.map(&:to_sym).uniq - [:all]
  59
+    types = Mime::SET.to_a.map{|m| m.to_sym }.uniq - [:all]
60 60
 
61 61
     # Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
62 62
     types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) }
@@ -76,7 +76,7 @@ class MimeTypeTest < ActiveSupport::TestCase
76 76
   end
77 77
 
78 78
   test "verifiable mime types" do
79  
-    all_types = Mime::SET.to_a.map(&:to_sym)
  79
+    all_types = Mime::SET.to_a.map{|m| m.to_sym}
80 80
     all_types.uniq!
81 81
     # Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
82 82
     all_types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) }
2  actionpack/test/fixtures/test/_local_inspector.html.erb
... ...
@@ -1 +1 @@
1  
-<%= local_assigns.keys.map(&:to_s).sort.join(",") -%>
  1
+<%= local_assigns.keys.map {|k| k.to_s }.sort.join(",") -%>
13  actionpack/test/new_base/abstract_unit.rb
@@ -11,9 +11,6 @@
11 11
 require 'test/unit'
12 12
 require 'active_support'
13 13
 
14  
-# TODO : Revisit requiring all the core extensions here
15  
-require 'active_support/core_ext'
16  
-
17 14
 require 'active_support/test_case'
18 15
 require 'action_controller/abstract'
19 16
 require 'action_controller/new_base'
@@ -45,6 +42,16 @@
45 42
 
46 43
 FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), '../fixtures')
47 44
 
  45
+module ActionView
  46
+  class TestCase
  47
+    setup do
  48
+      ActionController::Routing::Routes.draw do |map|
  49
+        map.connect ':controller/:action/:id'
  50
+      end
  51
+    end
  52
+  end
  53
+end
  54
+
48 55
 module ActionController
49 56
   Base.session = {
50 57
   :key         => '_testing_session',
2  actionpack/test/template/erb_util_test.rb
@@ -16,7 +16,7 @@ class ErbUtilTest < Test::Unit::TestCase
16 16
   end
17 17
   
18 18
   def test_rest_in_ascii
19  
-    (0..127).to_a.map(&:chr).each do |chr|
  19
+    (0..127).to_a.map {|int| int.chr }.each do |chr|
20 20
       next if %w(& " < >).include?(chr)
21 21
       assert_equal chr, html_escape(chr)
22 22
     end
42  actionpack/test/template/number_helper_test.rb
@@ -3,6 +3,22 @@
3 3
 class NumberHelperTest < ActionView::TestCase
4 4
   tests ActionView::Helpers::NumberHelper
5 5
 
  6
+  def kilobytes(number)
  7
+    number * 1024
  8
+  end
  9
+
  10
+  def megabytes(number)
  11
+    kilobytes(number) * 1024
  12
+  end
  13
+
  14
+  def gigabytes(number)
  15
+    megabytes(number) * 1024
  16
+  end
  17
+
  18
+  def terabytes(number)
  19
+    gigabytes(number) * 1024
  20
+  end
  21
+
6 22
   def test_number_to_phone
7 23
     assert_equal("555-1234", number_to_phone(5551234))
8 24
     assert_equal("800-555-1212", number_to_phone(8005551212))
@@ -96,16 +112,16 @@ def test_number_to_human_size
96 112
     assert_equal '1.2 MB',    number_to_human_size(1234567)
97 113
     assert_equal '1.1 GB',    number_to_human_size(1234567890)
98 114
     assert_equal '1.1 TB',    number_to_human_size(1234567890123)
99  
-    assert_equal '1025 TB',   number_to_human_size(1025.terabytes)
100  
-    assert_equal '444 KB',    number_to_human_size(444.kilobytes)
101  
-    assert_equal '1023 MB',   number_to_human_size(1023.megabytes)
102  
-    assert_equal '3 TB',      number_to_human_size(3.terabytes)
  115
+    assert_equal '1025 TB',   number_to_human_size(terabytes(1025))
  116
+    assert_equal '444 KB',    number_to_human_size(kilobytes(444))
  117
+    assert_equal '1023 MB',   number_to_human_size(megabytes(1023))
  118
+    assert_equal '3 TB',      number_to_human_size(terabytes(3))
103 119
     assert_equal '1.18 MB',   number_to_human_size(1234567, :precision => 2)
104 120
     assert_equal '3 Bytes',   number_to_human_size(3.14159265, :precision => 4)
105 121
     assert_equal("123 Bytes", number_to_human_size("123"))
106  
-    assert_equal '1.01 KB',   number_to_human_size(1.0123.kilobytes, :precision => 2)
107  
-    assert_equal '1.01 KB',   number_to_human_size(1.0100.kilobytes, :precision => 4)
108  
-    assert_equal '10 KB',   number_to_human_size(10.000.kilobytes, :precision => 4)
  122
+    assert_equal '1.01 KB',   number_to_human_size(kilobytes(1.0123), :precision => 2)
  123
+    assert_equal '1.01 KB',   number_to_human_size(kilobytes(1.0100), :precision => 4)
  124
+    assert_equal '10 KB',   number_to_human_size(kilobytes(10.000), :precision => 4)
109 125
     assert_equal '1 Byte',   number_to_human_size(1.1)
110 126
     assert_equal '10 Bytes', number_to_human_size(10)
111 127
     #assert_nil number_to_human_size('x') # fails due to API consolidation
@@ -115,9 +131,9 @@ def test_number_to_human_size
115 131
   def test_number_to_human_size_with_options_hash
116 132
     assert_equal '1.18 MB',   number_to_human_size(1234567, :precision => 2)
117 133
     assert_equal '3 Bytes',   number_to_human_size(3.14159265, :precision => 4)
118  
-    assert_equal '1.01 KB',   number_to_human_size(1.0123.kilobytes, :precision => 2)
119  
-    assert_equal '1.01 KB',   number_to_human_size(1.0100.kilobytes, :precision => 4)
120  
-    assert_equal '10 KB',     number_to_human_size(10.000.kilobytes, :precision => 4)
  134
+    assert_equal '1.01 KB',   number_to_human_size(kilobytes(1.0123), :precision => 2)
  135
+    assert_equal '1.01 KB',   number_to_human_size(kilobytes(1.0100), :precision => 4)
  136
+    assert_equal '10 KB',     number_to_human_size(kilobytes(10.000), :precision => 4)
121 137
     assert_equal '1 TB', number_to_human_size(1234567890123, :precision => 0)
122 138
     assert_equal '500 MB', number_to_human_size(524288000, :precision=>0)
123 139
     assert_equal '40 KB', number_to_human_size(41010, :precision => 0)
@@ -125,8 +141,8 @@ def test_number_to_human_size_with_options_hash
125 141
   end
126 142
 
127 143
   def test_number_to_human_size_with_custom_delimiter_and_separator
128  
-    assert_equal '1,01 KB',     number_to_human_size(1.0123.kilobytes, :precision => 2, :separator => ',')
129  
-    assert_equal '1,01 KB',     number_to_human_size(1.0100.kilobytes, :precision => 4, :separator => ',')
130  
-    assert_equal '1.000,1 TB',  number_to_human_size(1000.1.terabytes, :delimiter => '.', :separator => ',')
  144
+    assert_equal '1,01 KB',     number_to_human_size(kilobytes(1.0123), :precision => 2, :separator => ',')
  145
+    assert_equal '1,01 KB',     number_to_human_size(kilobytes(1.0100), :precision => 4, :separator => ',')
  146
+    assert_equal '1.000,1 TB',  number_to_human_size(terabytes(1000.1), :delimiter => '.', :separator => ',')
131 147
   end
132 148
 end
2  actionpack/test/template/render_test.rb
@@ -13,7 +13,7 @@ def setup_view(paths)
13 13
     I18n.backend.store_translations 'pt-BR', {}
14 14
 
15 15
     # Ensure original are still the same since we are reindexing view paths
16  
-    assert_equal ORIGINAL_LOCALES, I18n.available_locales.map(&:to_s).sort
  16
+    assert_equal ORIGINAL_LOCALES, I18n.available_locales.map {|l| l.to_s }.sort
17 17
   end
18 18
 
19 19
   def test_render_file

0 notes on commit 86fc43f

Please sign in to comment.
Something went wrong with that request. Please try again.