Skip to content
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

Add :time_entry method for retrieving single Time Entry records #76

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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 .env.sample
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
HARVEST_FIRST_NAME=<replace me with a test account>
HARVEST_LAST_NAME=<replace me with a test account>
HARVEST_ACCOUNT_ID=<replace me with a test account>
HARVEST_NON_ADMIN_ACCOUNT_ID=<replace me with a test account>
HARVEST_ACCESS_TOKEN=<replace me with a test account>
HARVEST_NON_ADMIN_ACCESS_TOKEN=<replace me with a test account>
HARVEST_ADMIN_FULL_NAME=<replace me with a test account>
HARVEST_NON_ADMIN_ACCOUNT_ID=<replace me with a test account>
HARVEST_NON_ADMIN_FULL_NAME=<replace me with a test account>
HARVEST_ADMIN_FULL_NAME=<replace me with a test account>
HARVEST_ADMIN_FIRST_NAME=<replace me with a test account>
HARVEST_ADMIN_LAST_NAME=<replace me with a test account>

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions lib/harvesting/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def contacts
end
end

# @return [Harvesting::Models::TimeEntry]
def time_entry(id, opts = {})
Harvesting::Models::TimeEntry.new(get("time_entries/#{id}", opts), harvest_client: self)
end

# @return [Harvesting::Models::TimeEntries]
def time_entries(opts = {})
Harvesting::Models::TimeEntries.new(get("time_entries", opts), opts, harvest_client: self)
Expand Down
23 changes: 23 additions & 0 deletions spec/harvesting/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,29 @@
context "when account has entries" do
let(:access_token) { admin_access_token }
let(:account_id) { admin_account_id }
let(:first_time_entry) { subject.time_entries.first } # the first of all time entries

it "retrieves a specific time entry by ID" do
# retrieve one specific time entry
expect(subject.time_entry(first_time_entry.id).attributes).to eq(first_time_entry.attributes)
end

context "when the time entry doesn't exist" do
it "raises a Harvesting::RequestNotFound error" do
expect do
subject.time_entry(9999999999) # a non-existent ID
end.to raise_error(Harvesting::RequestNotFound)
end
end

it "updates a time entry" do
original_notes = first_time_entry.notes
new_notes = "Client meeting"
first_time_entry.notes = new_notes
expect(original_notes).to_not eq(first_time_entry.notes)
first_time_entry.save
expect(subject.time_entry(first_time_entry.id).notes).to eq(new_notes)
end

it "returns the time_entries associated with the account" do
time_entries = subject.time_entries
Expand Down