Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/her/model/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def self.use_setter_methods(model, params)
#
# @private
def method_missing(method, *args, &blk)
if method.to_s =~ /[?=]$/ || @attributes.include?(method)
if method.to_s =~ /[^\[\]][?=]$/ || @attributes.include?(method)
# Extract the attribute
attribute = method.to_s.sub(/[?=]$/, '')

Expand All @@ -87,7 +87,7 @@ def method_missing(method, *args, &blk)

# @private
def respond_to_missing?(method, include_private = false)
method.to_s.end_with?('=') || method.to_s.end_with?('?') || @attributes.include?(method) || super
method.to_s =~ /[^\[\]][?=]$/ || method.to_s.end_with?('?') || @attributes.include?(method) || super
end

# Assign new attributes to a resource
Expand Down
12 changes: 12 additions & 0 deletions spec/model/attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@
@new_user.get_attribute(:unknown_method_for_a_user).should be_nil
@new_user.get_attribute(:'life-span').should == '3 years'
end

it "does not try to handle hash syntax setter" do
@new_user = Foo::User.new
expect { @new_user[:fullname] = "Tobias Fünke" }.to_not raise_error(ArgumentError)
expect { @new_user[:fullname] = "Tobias Fünke" }.to raise_error(NoMethodError)
end

it "does not respond to hash syntax setter method" do
@new_user = Foo::User.new
expect(@new_user).to_not respond_to(:[]=)
end

end


Expand Down