Skip to content

Consistently use record.new_record?. #1803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/rspec/rails/matchers/be_a_new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def unmatched_attributes
end

# @api public
# Passes if actual is an instance of `model_class` and returns `false` for
# `persisted?`. Typically used to specify instance variables assigned to
# Passes if actual is an instance of `model_class` and returns `true` for
# `new_record?`. Typically used to specify instance variables assigned to
# views by controller actions
#
# Use the `with` method to specify the specific attributes to match on the
Expand Down
4 changes: 2 additions & 2 deletions lib/rspec/rails/matchers/be_new_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Matchers
# @private
class BeANewRecord < RSpec::Matchers::BuiltIn::BaseMatcher
def matches?(actual)
!actual.persisted?
actual.new_record?
end

def failure_message
Expand All @@ -17,7 +17,7 @@ def failure_message_when_negated
end

# @api public
# Passes if actual returns `false` for `persisted?`.
# Passes if actual returns `true` for `new_record?`.
#
# @example
# get :new
Expand Down
8 changes: 4 additions & 4 deletions spec/rspec/rails/matchers/be_new_record_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require "spec_helper"

describe "be_new_record" do
context "un-persisted record" do
let(:record) { double('record', :persisted? => false) }
context "a new record" do
let(:record) { double('record', :new_record? => true) }

it "passes" do
expect(record).to be_new_record
Expand All @@ -15,8 +15,8 @@
end
end

context "persisted record" do
let(:record) { double('record', :persisted? => true) }
context "a persisted record" do
let(:record) { double('record', :new_record? => false) }

it "fails" do
expect(record).not_to be_new_record
Expand Down