Skip to content
New issue

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

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

Already on GitHub? # to your account

Add find_by as an alias of first #14

Merged
merged 1 commit into from
Dec 25, 2020
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
1 change: 1 addition & 0 deletions lib/hawk/model/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def all(params = {})
def first(params = {})
limit(1).all(params).first
end
alias find_by first

def first!(params = {})
first(params) or raise Hawk::Error::NotFound, "Can't find #{klass} with #{params.to_json}"
Expand Down
1 change: 1 addition & 0 deletions lib/hawk/model/querying.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def from(path)
def first(params = {})
limit(1).first(params)
end
alias find_by first

# Looks for the first record or raises a
# {Hawk::Error::NotFound} if not found
Expand Down
6 changes: 6 additions & 0 deletions spec/basic_operations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ class Person < Hawk::Model::Base
end
end

describe '.find_by' do
it 'is an alias of first' do
expect(Person.method(:find_by).original_name).to eq(:first)
end
end

describe '.all' do
specify do
stub_request(:GET, "http://zombo.com/people").
Expand Down