Skip to content

Commit

Permalink
Fix issue with event bindings methodizing, Closes #273
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanstout committed Aug 17, 2015
1 parent 38b298c commit f681850
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/volt/server/html_parser/attribute_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ def methodize_string(str)
# instance
parts = str.split('.')

end_call = parts.last
end_call = parts.last.strip

# If no method(args) is passed, we assume they want to convert the method
# to a Method, to be called with *args (from any trigger's), then event.
if end_call !~ /[a-z0-9!?]+\(/
if str !~ /[\[\]\$\@\=]/ && end_call =~ /[_a-z0-9!?]+$/
parts[-1] = "method(:#{end_call})"

str = parts.join('.')
Expand Down
44 changes: 44 additions & 0 deletions spec/server/html_parser/view_scope_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'spec_helper'

describe Volt::ViewScope do
describe "methodize strings" do
def methodize(str)
Volt::ViewScope.methodize_string(str)
end

it 'should methodize a method without args' do
code = methodize('something')
expect(code).to eq('method(:something)')
end

it 'should methodize a method without args2' do
code = methodize('something?')
expect(code).to eq('method(:something?)')
end

it 'should methodize a method wit args1' do
code = methodize('set_something(true)')
expect(code).to eq('set_something(true)')
end

it 'should not methodize a method call with args' do
code = methodize('something(item1, item2)')
expect(code).to eq('something(item1, item2)')
end

it 'should not methodize on assignment' do
code = methodize('params._something = 5')
expect(code).to eq('params._something = 5')
end

it 'should not methodize on hash lookup' do
code = methodize('hash[:something]')
expect(code).to eq('hash[:something]')
end

it 'should not methodize on instance variables' do
code = methodize('@something.call')
expect(code).to eq('@something.call')
end
end
end

0 comments on commit f681850

Please sign in to comment.