Skip to content
This repository
Browse code

all tests pass

  • Loading branch information...
commit 6c5a3bb3125735760e92f49c3824d757ef87c61e 1 parent ce21ea7
artem avetisyan authored December 12, 2010 wycats committed December 26, 2010
4  actionpack/lib/action_view/base.rb
@@ -232,8 +232,8 @@ def controller_path
232 232
       @controller_path ||= controller && controller.controller_path
233 233
     end
234 234
 
235  
-    def controller_prefix
236  
-      @controller_prefix ||= controller && controller._prefix
  235
+    def controller_prefixes
  236
+      @controller_prefixes ||= controller && controller._prefixes
237 237
     end
238 238
 
239 239
     ActiveSupport.run_load_hooks(:action_view, self)
2  actionpack/lib/action_view/lookup_context.rb
@@ -119,7 +119,7 @@ def normalize_name(name, prefixes) #:nodoc:
119 119
         name  = name.to_s.gsub(handlers_regexp, '')
120 120
         parts = name.split('/')
121 121
         name  = parts.pop
122  
-        prx = if not prefixes or prefixes.empty?
  122
+        prx = if prefixes.blank?
123 123
                 [parts.compact.join('/')]
124 124
               else
125 125
                 prefixes.map {|prefix| [prefix, *parts].compact.join('/') }
2  actionpack/lib/action_view/renderer/partial_renderer.rb
@@ -152,7 +152,7 @@ def partial_path(object = @object)
152 152
         object = object.to_model if object.respond_to?(:to_model)
153 153
 
154 154
         object.class.model_name.partial_path.dup.tap do |partial|
155  
-          path = @view.controller_prefix
  155
+          path = @view.controller_prefixes.first
156 156
           partial.insert(0, "#{File.dirname(path)}/") if partial.include?(?/) && path.include?(?/)
157 157
         end
158 158
       end
4  actionpack/lib/action_view/renderer/template_renderer.rb
@@ -22,14 +22,14 @@ def render(options)
22 22
     def render_once(options)
23 23
       paths, locals = options[:once], options[:locals] || {}
24 24
       layout, keys  = options[:layout], locals.keys
25  
-      prefix = options.fetch(:prefix, @view.controller_prefix)
  25
+      prefixes = options.fetch(:prefixes, @view.controller_prefixes)
26 26
 
27 27
       raise "render :once expects a String or an Array to be given" unless paths
28 28
 
29 29
       render_with_layout(layout, locals) do
30 30
         contents = []
31 31
         Array.wrap(paths).each do |path|
32  
-          template = find_template(path, prefix, false, keys)
  32
+          template = find_template(path, prefixes, false, keys)
33 33
           contents << render_template(template, nil, locals) if @rendered.add?(template)
34 34
         end
35 35
         contents.join("\n")
2  actionpack/lib/action_view/template.rb
@@ -163,7 +163,7 @@ def refresh(view)
163 163
       name    = pieces.pop
164 164
       partial = !!name.sub!(/^_/, "")
165 165
       lookup.disable_cache do
166  
-        lookup.find_template(name, pieces.join('/'), partial, @locals)
  166
+        lookup.find_template(name, [ pieces.join('/') ], partial, @locals)
167 167
       end
168 168
     end
169 169
 
8  actionpack/test/controller/new_base/render_once_test.rb
@@ -18,8 +18,8 @@ class RenderOnceController < ActionController::Base
18 18
 
19 19
     self.view_paths = [RESOLVER]
20 20
 
21  
-    def _prefix
22  
-      "test"
  21
+    def _prefixes
  22
+      %w(test)
23 23
     end
24 24
 
25 25
     def multiple
@@ -39,11 +39,11 @@ def with_layout
39 39
     end
40 40
 
41 41
     def with_prefix
42  
-      render :once => "result", :prefix => "other"
  42
+      render :once => "result", :prefixes => %w(other)
43 43
     end
44 44
 
45 45
     def with_nil_prefix
46  
-      render :once => "test/result", :prefix => nil
  46
+      render :once => "test/result", :prefixes => []
47 47
     end
48 48
   end
49 49
 
6  actionpack/test/template/log_subscriber_test.rb
@@ -57,7 +57,7 @@ def test_render_partial_template
57 57
   end
58 58
 
59 59
   def test_render_partial_with_implicit_path
60  
-    @view.stubs(:controller_prefix).returns("test")
  60
+    @view.stubs(:controller_prefixes).returns(%w(test))
61 61
     @view.render(Customer.new("david"), :greeting => "hi")
62 62
     wait
63 63
 
@@ -74,7 +74,7 @@ def test_render_collection_template
74 74
   end
75 75
 
76 76
   def test_render_collection_with_implicit_path
77  
-    @view.stubs(:controller_prefix).returns("test")
  77
+    @view.stubs(:controller_prefixes).returns(%w(test))
78 78
     @view.render([ Customer.new("david"), Customer.new("mary") ], :greeting => "hi")
79 79
     wait
80 80
 
@@ -83,7 +83,7 @@ def test_render_collection_with_implicit_path
83 83
   end
84 84
 
85 85
   def test_render_collection_template_without_path
86  
-    @view.stubs(:controller_prefix).returns("test")
  86
+    @view.stubs(:controller_prefixes).returns(%w(test))
87 87
     @view.render([ GoodCustomer.new("david"), Customer.new("mary") ], :greeting => "hi")
88 88
     wait
89 89
 
48  actionpack/test/template/lookup_context_test.rb
@@ -80,18 +80,18 @@ def teardown
80 80
   end
81 81
 
82 82
   test "find templates using the given view paths and configured details" do
83  
-    template = @lookup_context.find("hello_world", "test")
  83
+    template = @lookup_context.find("hello_world", %w(test))
84 84
     assert_equal "Hello world!", template.source
85 85
 
86 86
     @lookup_context.locale = :da
87  
-    template = @lookup_context.find("hello_world", "test")
  87
+    template = @lookup_context.find("hello_world", %w(test))
88 88
     assert_equal "Hey verden", template.source
89 89
   end
90 90
 
91 91
   test "found templates respects given formats if one cannot be found from template or handler" do
92 92
     ActionView::Template::Handlers::ERB.expects(:default_format).returns(nil)
93 93
     @lookup_context.formats = [:text]
94  
-    template = @lookup_context.find("hello_world", "test")
  94
+    template = @lookup_context.find("hello_world", %w(test))
95 95
     assert_equal [:text], template.formats
96 96
   end
97 97
 
@@ -137,44 +137,44 @@ def teardown
137 137
 
138 138
   test "gives the key forward to the resolver, so it can be used as cache key" do
139 139
     @lookup_context.view_paths = ActionView::FixtureResolver.new("test/_foo.erb" => "Foo")
140  
-    template = @lookup_context.find("foo", "test", true)
  140
+    template = @lookup_context.find("foo", %w(test), true)
141 141
     assert_equal "Foo", template.source
142 142
 
143 143
     # Now we are going to change the template, but it won't change the returned template
144 144
     # since we will hit the cache.
145 145
     @lookup_context.view_paths.first.hash["test/_foo.erb"] = "Bar"
146  
-    template = @lookup_context.find("foo", "test", true)
  146
+    template = @lookup_context.find("foo", %w(test), true)
147 147
     assert_equal "Foo", template.source
148 148
 
149 149
     # This time we will change the locale. The updated template should be picked since
150 150
     # lookup_context generated a new key after we changed the locale.
151 151
     @lookup_context.locale = :da
152  
-    template = @lookup_context.find("foo", "test", true)
  152
+    template = @lookup_context.find("foo", %w(test), true)
153 153
     assert_equal "Bar", template.source
154 154
 
155 155
     # Now we will change back the locale and it will still pick the old template.
156 156
     # This is expected because lookup_context will reuse the previous key for :en locale.
157 157
     @lookup_context.locale = :en
158  
-    template = @lookup_context.find("foo", "test", true)
  158
+    template = @lookup_context.find("foo", %w(test), true)
159 159
     assert_equal "Foo", template.source
160 160
 
161 161
     # Finally, we can expire the cache. And the expected template will be used.
162 162
     @lookup_context.view_paths.first.clear_cache
163  
-    template = @lookup_context.find("foo", "test", true)
  163
+    template = @lookup_context.find("foo", %w(test), true)
164 164
     assert_equal "Bar", template.source
165 165
   end
166 166
 
167 167
   test "can disable the cache on demand" do
168 168
     @lookup_context.view_paths = ActionView::FixtureResolver.new("test/_foo.erb" => "Foo")
169  
-    old_template = @lookup_context.find("foo", "test", true)
  169
+    old_template = @lookup_context.find("foo", %w(test), true)
170 170
 
171  
-    template = @lookup_context.find("foo", "test", true)
  171
+    template = @lookup_context.find("foo", %w(test), true)
172 172
     assert_equal template, old_template
173 173
 
174 174
     assert @lookup_context.cache
175 175
     template = @lookup_context.disable_cache do
176 176
       assert !@lookup_context.cache
177  
-      @lookup_context.find("foo", "test", true)
  177
+      @lookup_context.find("foo", %w(test), true)
178 178
     end
179 179
     assert @lookup_context.cache
180 180
 
@@ -182,11 +182,11 @@ def teardown
182 182
   end
183 183
 
184 184
   test "data can be stored in cached templates" do
185  
-    template = @lookup_context.find("hello_world", "test")
  185
+    template = @lookup_context.find("hello_world", %w(test))
186 186
     template.data["cached"] = "data"
187 187
     assert_equal "Hello world!", template.source
188 188
 
189  
-    template = @lookup_context.find("hello_world", "test")
  189
+    template = @lookup_context.find("hello_world", %w(test))
190 190
     assert_equal "data", template.data["cached"]
191 191
     assert_equal "Hello world!", template.source
192 192
   end
@@ -200,54 +200,54 @@ def setup
200 200
   end
201 201
 
202 202
   test "templates are always found in the resolver but timestamp is checked before being compiled" do
203  
-    template = @lookup_context.find("foo", "test", true)
  203
+    template = @lookup_context.find("foo", %w(test), true)
204 204
     assert_equal "Foo", template.source
205 205
 
206 206
     # Now we are going to change the template, but it won't change the returned template
207 207
     # since the timestamp is the same.
208 208
     @resolver.hash["test/_foo.erb"][0] = "Bar"
209  
-    template = @lookup_context.find("foo", "test", true)
  209
+    template = @lookup_context.find("foo", %w(test), true)
210 210
     assert_equal "Foo", template.source
211 211
 
212 212
     # Now update the timestamp.
213 213
     @resolver.hash["test/_foo.erb"][1] = Time.now.utc
214  
-    template = @lookup_context.find("foo", "test", true)
  214
+    template = @lookup_context.find("foo", %w(test), true)
215 215
     assert_equal "Bar", template.source
216 216
   end
217 217
 
218 218
   test "if no template was found in the second lookup, with no cache, raise error" do
219  
-    template = @lookup_context.find("foo", "test", true)
  219
+    template = @lookup_context.find("foo", %w(test), true)
220 220
     assert_equal "Foo", template.source
221 221
 
222 222
     @resolver.hash.clear
223 223
     assert_raise ActionView::MissingTemplate do
224  
-      @lookup_context.find("foo", "test", true)
  224
+      @lookup_context.find("foo", %w(test), true)
225 225
     end
226 226
   end
227 227
 
228 228
   test "if no template was cached in the first lookup, retrieval should work in the second call" do
229 229
     @resolver.hash.clear
230 230
     assert_raise ActionView::MissingTemplate do
231  
-      @lookup_context.find("foo", "test", true)
  231
+      @lookup_context.find("foo", %w(test), true)
232 232
     end
233 233
 
234 234
     @resolver.hash["test/_foo.erb"] = ["Foo", Time.utc(2000)]
235  
-    template = @lookup_context.find("foo", "test", true)
  235
+    template = @lookup_context.find("foo", %w(test), true)
236 236
     assert_equal "Foo", template.source
237 237
   end
238 238
 
239 239
   test "data can be stored as long as template was not updated" do
240  
-    template = @lookup_context.find("foo", "test", true)
  240
+    template = @lookup_context.find("foo", %w(test), true)
241 241
     template.data["cached"] = "data"
242 242
     assert_equal "Foo", template.source
243 243
 
244  
-    template = @lookup_context.find("foo", "test", true)
  244
+    template = @lookup_context.find("foo", %w(test), true)
245 245
     assert_equal "data", template.data["cached"]
246 246
     assert_equal "Foo", template.source
247 247
 
248 248
     @resolver.hash["test/_foo.erb"][1] = Time.now.utc
249  
-    template = @lookup_context.find("foo", "test", true)
  249
+    template = @lookup_context.find("foo", %w(test), true)
250 250
     assert_nil template.data["cached"]
251 251
     assert_equal "Foo", template.source
252 252
   end
253  
-end
  253
+end
4  actionpack/test/template/template_test.rb
@@ -95,14 +95,14 @@ def test_virtual_path
95 95
   def test_refresh_with_templates
96 96
     @template = new_template("Hello", :virtual_path => "test/foo/bar")
97 97
     @template.locals = [:key]
98  
-    @context.lookup_context.expects(:find_template).with("bar", "test/foo", false, [:key]).returns("template")
  98
+    @context.lookup_context.expects(:find_template).with("bar", %w(test/foo), false, [:key]).returns("template")
99 99
     assert_equal "template", @template.refresh(@context)
100 100
   end
101 101
 
102 102
   def test_refresh_with_partials
103 103
     @template = new_template("Hello", :virtual_path => "test/_foo")
104 104
     @template.locals = [:key]
105  
-    @context.lookup_context.expects(:find_template).with("foo", "test", true, [:key]).returns("partial")
  105
+    @context.lookup_context.expects(:find_template).with("foo", %w(test), true, [:key]).returns("partial")
106 106
     assert_equal "partial", @template.refresh(@context)
107 107
   end
108 108
 

0 notes on commit 6c5a3bb

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