spec/lib/tomatoharvest/time_entry_spec.rb in tomatoharvest-0.0.1 vs spec/lib/tomatoharvest/time_entry_spec.rb in tomatoharvest-0.1.0
- old
+ new
@@ -4,63 +4,68 @@
describe '#test' do
let(:entry) do
described_class.new.tap do |entry|
- entry.stub(project: double, task: double)
+ allow(entry).to receive(:project) { double }
+ allow(entry).to receive(:task) { double }
end
end
it "raises an error if project can't be found" do
- entry.stub(project: nil)
+ allow(entry).to receive(:project) { nil }
expect{ entry.test }.to raise_error("Couldn't find project")
end
it "raises an error if task can't be found" do
- entry.stub(task: nil)
+ allow(entry).to receive(:task) { nil }
expect{ entry.test }.to raise_error("Couldn't find task type")
end
end
describe '#log' do
+ let(:options) do
+ {
+ 'domain' => 'domain',
+ 'username' => 'user',
+ 'password' => 'password',
+ 'project' => 'Pomodoro',
+ 'task' => 'Ruby Development',
+ 'name' => 'Template Refactoring'
+ }
+ end
- context 'task is already logged today' do
- let(:options) do
- {
- 'domain' => 'domain',
- 'username' => 'user',
- 'password' => 'password',
- 'project' => 'Pomodoro',
- 'task' => 'Ruby Development',
- 'name' => 'Template Refactoring'
- }
- end
+ let(:entries) { [] }
- before do
- body = {
- projects: [ {
- name: 'Pomodoro',
- id: 1,
- tasks: [
- {
- name: 'Ruby Development',
- id: 1
- }
- ]
- } ],
+ before do
+ body = {
+ projects: [ {
+ name: 'Pomodoro',
+ id: 1,
+ tasks: [
+ {
+ name: 'Ruby Development',
+ id: 1
+ }
+ ]
+ } ],
+ day_entries: entries
+ }
- day_entries: [ {
- notes: 'Template Refactoring',
- project_id: 1,
- task_id: 1,
- hours: 1
- } ]
- }
+ stub_request(:get, /https:\/\/user:password@domain.harvestapp.com\/daily\/.*/).
+ to_return(:status => 200, :body => body.to_json, :headers => {})
+ end
- stub_request(:get, /https:\/\/user:password@domain.harvestapp.com\/daily\/.*/).
- to_return(:status => 200, :body => body.to_json, :headers => {})
+ context 'task is already logged today' do
+ let(:entries) do
+ [ {
+ notes: 'Template Refactoring',
+ project_id: 1,
+ task_id: 1,
+ hours: 1
+ } ]
end
it 'updates exisiting entry' do
update_url = "https://user:password@domain.harvestapp.com/daily/update/"
body = {
@@ -73,10 +78,24 @@
stub = stub_request(:put, update_url).with(:body => body.to_json)
entry = TomatoHarvest::TimeEntry.new(options)
entry.log(60 * 30)
- stub.should have_been_requested
+ expect(stub).to have_been_requested
+ end
+
+ end
+
+ context 'seconds are rounded to 0.00 hours' do
+
+ it 'should not log' do
+ update_url = "https://user:password@domain.harvestapp.com/daily/add"
+ stub = stub_request(:post, update_url)
+
+ entry = TomatoHarvest::TimeEntry.new(options)
+ entry.log(0)
+
+ expect(stub).not_to have_been_requested
end
end
end