Skip to content

Commit

Permalink
Duplicate locals hash when setting instance vars
Browse files Browse the repository at this point in the history
When a frozen locals hash is passed a RuntimeError occurs
  • Loading branch information
badosu committed Apr 19, 2017
1 parent 3a1e4f1 commit b54c49b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rabl/engine.rb
Expand Up @@ -27,6 +27,8 @@ def source=(source)
# Renders the representation based on source, object, context_scope and locals
# Rabl::Engine.new("...source...", { :format => "xml" }).apply(context_scope, { :foo => "bar", :object => @user })
def apply(context_scope, locals, &block)
locals = locals.dup unless locals.nil?

set_instance_variables!(context_scope, locals)

reset_settings!
Expand Down
6 changes: 6 additions & 0 deletions test/engine_test.rb
Expand Up @@ -23,6 +23,12 @@
asserts_topic.assigns :_view_path
end

context "#apply" do
denies("that it raises exception when given frozen locals").raises(RuntimeError) do
Rabl::Engine.new("").apply(Object.new, {}.freeze)
end
end

context "#request_format" do
context "is json by default" do
setup do
Expand Down

0 comments on commit b54c49b

Please sign in to comment.