Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[fix #361] Added test+fix on special usage of view_path within Rails con... #404

Merged
merged 1 commit into from

2 participants

@vimutter

Hi, here is the test and fix for issue with Rails look-up raising errors that prevent manual look-up from happening.

@nesquena
Owner

Thanks Mark, looks good.

@nesquena nesquena merged commit 4109c92 into nesquena:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 46 additions and 1 deletion.
  1. +2 −1  lib/rabl/partials.rb
  2. +44 −0 test/partials_test.rb
View
3  lib/rabl/partials.rb
@@ -76,7 +76,8 @@ def fetch_rails_source(file, options={})
source_format = rendered_format unless rendered_format == :html
context_scope.lookup_context.find(file, [], partial, [], {:formats => [source_format]})
end }
- template = lookup_proc.call(false) rescue lookup_proc.call(true)
+ template = lookup_proc.call(false) rescue nil
+ template ||= lookup_proc.call(true) rescue nil
template.identifier if template
elsif source_format && context_scope.respond_to?(:view_paths) # Rails 2
template = context_scope.view_paths.find_template(file, source_format, false)
View
44 test/partials_test.rb
@@ -88,4 +88,48 @@ class TestPartial
Rabl.configuration.view_paths = []
end
end
+
+ context "fetch source with Rails" do
+ context "and :view_path" do
+ helper(:tmp_path) { @tmp_path ||= Pathname.new(Dir.mktmpdir) }
+
+ setup do
+ ::Rails = stub(Class.new)
+ ::ActionPack = Module.new
+ ::ActionPack::VERSION = Module.new
+ ::ActionPack::VERSION::MAJOR = 3
+ ::ActionPack::VERSION::MINOR = 2
+ @it = TestPartial.new
+
+ def @it.context_scope; @context_scope ||= Object.new; end
+ def @it.request_format; :json; end
+ context_scope = @it.context_scope
+
+ def context_scope.view_paths; []; end
+ def context_scope.lookup_context; @lookup_context ||= Object.new; end
+ lookup_context = context_scope.lookup_context
+
+ def lookup_context.rendered_format; :json; end
+ def lookup_context.find(*args)
+ raise RuntimeError, 'Something happen with Rails lookup'
+ end
+
+ File.open(tmp_path + "test.json.rabl", "w") { |f| f.puts "content" }
+
+ @it
+ end
+
+ asserts('rails lookups dont break manual') do
+ @it.fetch_source('test', :view_path => tmp_path.to_s)
+ end.equals do
+ ["content\n", (tmp_path + "test.json.rabl").to_s ]
+ end
+
+ teardown do
+ Object.send(:remove_const, :Rails)
+ Object.send(:remove_const, :ActionPack)
+ Rabl.configuration.view_paths = []
+ end
+ end
+ end
end
Something went wrong with that request. Please try again.