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

Associated time entries for project #32

Merged
merged 3 commits into from
Jan 24, 2019
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

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

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

4 changes: 4 additions & 0 deletions lib/harvesting/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def path
def to_hash
{ client_id: client.id }.merge(super)
end

def time_entries
harvest_client.time_entries(project_id: self.id)
end
end
end
end
41 changes: 41 additions & 0 deletions spec/harvesting/models/project_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'spec_helper'

RSpec.describe Harvesting::Models::Project, :vcr do
let(:attrs) { Hash.new }
let(:project) { Harvesting::Models::Project.new(attrs) }
let(:project_id) { 19815868 }

include_context "harvest data setup"

describe '.new' do
context 'with client attributes in attrs' do
let(:project_id) { '1235' }
let(:project_name) { 'Lannister Co' }
let(:client_attrs) { { "id" => project_id, "name" => project_name } }
let(:attrs) { { "client" => client_attrs } }

it 'provides access to a client object with the specified attributes' do
expect(project.client.id).to eq(project_id)
expect(project.client.name).to eq(project_name)
end
end
end

describe '.get' do
it 'provides direct access to a specific project' do
project = Harvesting::Models::Project.get(project_id)
expect(project.id).to eq(project_id)
expect(project.name).to eq("X")
end
end

describe "#time_entries" do
it "loads associated time entries" do
project = Harvesting::Models::Project.get(project_id)

expect(project.time_entries.size).to eq(1)
expect(project.time_entries.first.hours).to eq(1.25)
end
end

end