Permalink
Browse files

adding attribute assignment method to base, with specs

  • Loading branch information...
jmoline committed Jun 25, 2012
1 parent bd97d1e commit c47d91975b8e096882f76d8aa2f8bff219d6c4cb
Showing with 17 additions and 1 deletion.
  1. +5 −1 lib/zuora/objects/base.rb
  2. +12 −0 spec/zuora/objects/base_spec.rb
@@ -9,10 +9,14 @@ class Base
# generate a new instance of a Zuora object
def initialize(attrs={}, &block)
apply_default_attributes
+ self.attributes = attrs
+ yield self if block_given?
+ end
+
+ def attributes=(attrs={})
attrs.each do |name, value|
self.send("#{name.to_s.underscore}=", value)
end
- yield self if block_given?
end
# given a soap response hash, initialize a record
@@ -27,5 +27,17 @@ def initialize(model)
Zuora::Objects::Invoice.new.includes_usage.should be_true
Zuora::Objects::Invoice.new(:includes_usage => false).includes_usage.should be_false
end
+
+ it "assigns attributes from passed in hash" do
+ Zuora::Objects::Account.new(:name => "Test Name").name.should == "Test Name"
+ end
+ end
+
+ describe "attributes=" do
+ it "should assign attributes to an existing instance from passed in hash" do
+ account = Zuora::Objects::Account.new(:name => "Test Name")
+ account.attributes = {:name => "New Name"}
+ account.name.should == "New Name"
+ end
end
end

0 comments on commit c47d919

Please sign in to comment.