Skip to content

Commit

Permalink
only allow attributes that have a getter method.
Browse files Browse the repository at this point in the history
  • Loading branch information
pitluga committed Mar 2, 2012
1 parent b3d03c0 commit 8f697ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/curator/model.rb
Expand Up @@ -13,11 +13,8 @@ module Model

def initialize(args = {})
args.each do |attribute, value|
if respond_to?("#{attribute}=")
send("#{attribute}=", value)
else
instance_variable_set("@#{attribute}", value)
end
send("#{attribute}=", value) if respond_to?("#{attribute}=")
instance_variable_set("@#{attribute}", value) if respond_to?(attribute.to_s)
end
end

Expand Down
10 changes: 10 additions & 0 deletions spec/curator/model_spec.rb
Expand Up @@ -12,6 +12,16 @@
model.one.should be_nil
model.two.should == 't'
end

it "does not set arbitrary fields" do
model_class = Class.new do
include Curator::Model
attr_reader :foo
end

model = model_class.new(:foo => "bar", :baz => "qux")
model.instance_variable_get("@baz").should be_nil
end
end

describe "==" do
Expand Down

0 comments on commit 8f697ec

Please sign in to comment.