Skip to content

Commit

Permalink
Merge 75f200b into 026fb0d
Browse files Browse the repository at this point in the history
  • Loading branch information
yesmeck committed Feb 11, 2015
2 parents 026fb0d + 75f200b commit 7fc61bc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#### Next

* The `render` method will not modify endpoint options at runtime now. [#35](https://github.com/LTe/grape-rabl/issues/35) [@yesmeck](https://github.com/yesmeck)
* Your contribution here.

#### v0.3.0
Expand Down
13 changes: 8 additions & 5 deletions lib/grape-rabl/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,21 @@ def view_path(template)
end

def rablable?
!!endpoint.options[:route_options][:rabl]
!!rabl_template
end

def rabl
template = endpoint.options[:route_options][:rabl]
fail 'missing rabl template' unless template
fail 'missing rabl template' unless rabl_template
set_view_root unless env['api.tilt.root']
yield template
yield rabl_template
end

def locals
endpoint.options[:route_options][:rabl_locals] || {}
env['api.tilt.rabl_locals'] || endpoint.options[:route_options][:rabl_locals] || {}
end

def rabl_template
env['api.tilt.rabl'] || endpoint.options[:route_options][:rabl]
end

def set_view_root
Expand Down
4 changes: 2 additions & 2 deletions lib/grape-rabl/render.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module GrapeRabl
module Render
def render(options = {})
env['api.endpoint'].options[:route_options][:rabl] = options.delete(:rabl) if options.include?(:rabl)
env['api.endpoint'].options[:route_options][:rabl_locals] = options.delete(:locals)
env['api.tilt.rabl'] = options.delete(:rabl) if options.include?(:rabl)
env['api.tilt.rabl_locals'] = options.delete(:locals)
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions spec/grape_rabl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ def app
get('/about')
parsed_response.should == JSON.parse('{"user":{"name":"LTe","project":null}}')
end

it 'does not modify endpoint options' do
get '/home'
expect(last_request.env['api.endpoint'].options[:route_options][:rabl]).to eq 'user'
end
end

it 'should respond with proper content-type' do
Expand Down

0 comments on commit 7fc61bc

Please sign in to comment.