Skip to content

Commit

Permalink
Provide a more ActiveRecord-like interface by aliasing new_record? to…
Browse files Browse the repository at this point in the history
… new?
  • Loading branch information
WizardOfOgz committed Aug 12, 2015
1 parent 6921ddc commit 672f120
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/her/model/orm.rb
Expand Up @@ -8,6 +8,7 @@ module ORM
def new?
id.nil?
end
alias new_record? new?

# Return `true` if a resource is not `#new?`
def persisted?
Expand Down
2 changes: 2 additions & 0 deletions spec/model/orm_spec.rb
Expand Up @@ -49,10 +49,12 @@
it "handles new resource" do
@new_user = Foo::User.new(:fullname => "Tobias Fünke")
@new_user.new?.should be_truthy
@new_user.new_record?.should be_truthy
@new_user.fullname.should == "Tobias Fünke"

@existing_user = Foo::User.find(1)
@existing_user.new?.should be_falsey
@existing_user.new_record?.should be_falsey
end

it 'handles new resource with custom primary key' do
Expand Down

0 comments on commit 672f120

Please sign in to comment.