Skip to content

Commit

Permalink
Fix mocking belongs_to associations in Rails 4.2+
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan del Strother authored and JonRowe committed Sep 7, 2015
1 parent 55d72f6 commit 6f29268
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rspec/active_model/mocks/mocks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def [](key)
send(key)
end

# Rails>4.2 uses _read_attribute internally, as an optimized
# alternative to record['id']
alias_method :_read_attribute, :[]

# Returns the opposite of `persisted?`
def new_record?
!persisted?
Expand Down

0 comments on commit 6f29268

Please sign in to comment.