Skip to content

Commit

Permalink
Merge pull request #223 from recurly/changed-attributes
Browse files Browse the repository at this point in the history
Don't set changed attributes when reading a resource
  • Loading branch information
bhelx committed Nov 18, 2015
2 parents 4d40a4b + cbeb603 commit 58d3f66
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/recurly/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,11 @@ def has_many collection_name, options = {}
associations << Association.new(:has_many, collection_name.to_s, options)
associations_helper.module_eval do
define_method collection_name do
self[collection_name] ||= []
if self[collection_name]
self[collection_name]
else
attributes[collection_name] = []
end
end
if options.key?(:readonly) && options[:readonly] == false
define_method "#{collection_name}=" do |collection|
Expand Down
6 changes: 6 additions & 0 deletions spec/recurly/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ def to_param
it "must return a pager for fresh records" do
resource.new.reasons.must_be_kind_of Enumerable
end

it "should not set changed attributes when reading a resource" do
record = resource.new
record.reasons
record.changed_attributes.keys.must_be_empty
end
end

describe ".has_one and .belongs_to" do
Expand Down

0 comments on commit 58d3f66

Please sign in to comment.