Skip to content

Commit

Permalink
Merge pull request #120 from brianp/master
Browse files Browse the repository at this point in the history
NoMethodError fix
  • Loading branch information
cbarton committed Nov 9, 2013
2 parents a99a3ff + 4741aa5 commit 163c763
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/recurly/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -765,8 +765,8 @@ def save!
# account.save # => true
# account.valid? # => true
def valid?
return true if persisted? && changed_attributes.empty?
return if errors.empty? && changed_attributes?
return true if persisted? && !changed?
return if errors.empty? && changed?
errors.empty?
end

Expand Down
28 changes: 28 additions & 0 deletions spec/recurly/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -453,5 +453,33 @@ def record.to_param() 1 end
proc { record.destroy }.must_raise Resource::NotFound
end
end

describe "#valid?" do
it "must return true if persisted without changes" do
record.persist!
record.valid?.must_equal true
end

it "must return true if not persisted without changes and no errors" do
record.valid?.must_equal true
end

it "must return nil if persisted with changes" do
record.persist!
record[:uuid] = 'changed'
record.valid?.must_equal nil
end

it "must return nil if not persisted with changes and no errors" do
record[:uuid] = 'changed'
record.valid?.must_equal nil
end

it "must return false if it has errors" do
record.errors[:name] = 'an error'
record.valid?.must_equal false
end
end

end
end

0 comments on commit 163c763

Please sign in to comment.