Skip to content

Commit

Permalink
Merge pull request #112 from vladra/master
Browse files Browse the repository at this point in the history
Make second arg to Hanami::View initialize accept keyword arguments
  • Loading branch information
AlfonsoUceda authored Nov 23, 2016
2 parents 04ba3aa + 226ecc3 commit 464f0d0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/hanami/view/rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module InstanceMethods
#
# template = Hanami::View::Template.new('index.html.erb')
# view = IndexView.new(template, {article: article})
def initialize(template, locals)
def initialize(template, **locals)
@template = template
@locals = locals
@scope = Scope.new(self, @locals)
Expand Down
18 changes: 18 additions & 0 deletions test/rendering_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@
describe Hanami::View do
reload_configuration!

describe 'initializing' do
before do
@view = Class.new do
include Hanami::View
end

@template = Hanami::View::Template.new(__dir__ + '/fixtures/templates/hello_world.html.erb')
end

it 'initializes view without keyword arguments' do
@view.new(@template).locals.must_equal Hash[]
end

it 'initializes view with keyword arguments' do
@view.new(@template, hello: 'world').locals.must_equal({hello: 'world'})
end
end

describe 'rendering' do
it 'renders a template' do
HelloWorldView.render(format: :html).must_include %(<h1>Hello, World!</h1>)
Expand Down

0 comments on commit 464f0d0

Please sign in to comment.