Commit 4fbe9f50bbcb0414f59ef1fa0602f4998d49cccc
Exists in
master
and in
29 other branches
Merge branch 'I13-fix_partial_for_class' into 'master'
I13 fix partial for class Fixes #13 See merge request !333
Showing
2 changed files
with
15 additions
and
1 deletions
Show diff stats
app/helpers/application_helper.rb
| @@ -304,7 +304,7 @@ module ApplicationHelper | @@ -304,7 +304,7 @@ module ApplicationHelper | ||
| 304 | def partial_for_class(klass, prefix=nil, suffix=nil) | 304 | def partial_for_class(klass, prefix=nil, suffix=nil) |
| 305 | raise ArgumentError, 'No partial for object. Is there a partial for any class in the inheritance hierarchy?' if klass.nil? | 305 | raise ArgumentError, 'No partial for object. Is there a partial for any class in the inheritance hierarchy?' if klass.nil? |
| 306 | name = klass.name.underscore | 306 | name = klass.name.underscore |
| 307 | - controller.view_paths.reverse_each do |view_path| | 307 | + controller.view_paths.each do |view_path| |
| 308 | partial = partial_for_class_in_view_path(klass, view_path, prefix, suffix) | 308 | partial = partial_for_class_in_view_path(klass, view_path, prefix, suffix) |
| 309 | return partial if partial | 309 | return partial if partial |
| 310 | end | 310 | end |
test/unit/application_helper_test.rb
| @@ -49,6 +49,20 @@ class ApplicationHelperTest < ActionView::TestCase | @@ -49,6 +49,20 @@ class ApplicationHelperTest < ActionView::TestCase | ||
| 49 | end | 49 | end |
| 50 | end | 50 | end |
| 51 | 51 | ||
| 52 | + should 'plugins path take precedence over core path' do | ||
| 53 | + core_path = 'core/' | ||
| 54 | + plugin_path = 'path/' | ||
| 55 | + @controller = mock() | ||
| 56 | + @controller.stubs(:view_paths).returns([plugin_path, core_path]) | ||
| 57 | + self.stubs(:params).returns({:controller => 'test'}) | ||
| 58 | + | ||
| 59 | + File.stubs(:exists?).returns(false) | ||
| 60 | + File.stubs(:exists?).with(core_path+"test/_block.html.erb").returns(true) | ||
| 61 | + File.stubs(:exists?).with(plugin_path+"test/_raw_html_block.html.erb").returns(true) | ||
| 62 | + | ||
| 63 | + assert_equal 'raw_html_block', partial_for_class(RawHTMLBlock) | ||
| 64 | + end | ||
| 65 | + | ||
| 52 | should 'generate link to stylesheet' do | 66 | should 'generate link to stylesheet' do |
| 53 | File.stubs(:exists?).returns(false) | 67 | File.stubs(:exists?).returns(false) |
| 54 | File.expects(:exists?).with(Rails.root.join('public', 'stylesheets', 'something.css')).returns(true) | 68 | File.expects(:exists?).with(Rails.root.join('public', 'stylesheets', 'something.css')).returns(true) |