harvested 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +15 -0
- data/HISTORY +11 -0
- data/README.md +14 -6
- data/Rakefile +13 -31
- data/TODO +2 -0
- data/VERSION +1 -1
- data/examples/user_assignments.rb +1 -1
- data/harvested.gemspec +114 -126
- data/lib/ext/array.rb +52 -0
- data/lib/ext/date.rb +9 -0
- data/lib/ext/hash.rb +17 -0
- data/lib/ext/time.rb +5 -0
- data/lib/harvest/api/account.rb +8 -1
- data/lib/harvest/api/base.rb +32 -10
- data/lib/harvest/api/contacts.rb +1 -1
- data/lib/harvest/api/expenses.rb +3 -4
- data/lib/harvest/api/invoice_categories.rb +26 -0
- data/lib/harvest/api/invoices.rb +16 -0
- data/lib/harvest/api/projects.rb +2 -10
- data/lib/harvest/api/reports.rb +13 -16
- data/lib/harvest/api/task_assignments.rb +8 -6
- data/lib/harvest/api/tasks.rb +1 -1
- data/lib/harvest/api/time.rb +13 -13
- data/lib/harvest/api/user_assignments.rb +7 -5
- data/lib/harvest/base.rb +9 -1
- data/lib/harvest/behavior/activatable.rb +2 -2
- data/lib/harvest/behavior/crud.rb +15 -13
- data/lib/harvest/client.rb +18 -13
- data/lib/harvest/contact.rb +13 -11
- data/lib/harvest/errors.rb +6 -4
- data/lib/harvest/expense.rb +40 -14
- data/lib/harvest/expense_category.rb +10 -9
- data/lib/harvest/hardy_client.rb +1 -1
- data/lib/harvest/invoice.rb +103 -0
- data/lib/harvest/invoice_category.rb +18 -0
- data/lib/harvest/line_item.rb +12 -0
- data/lib/harvest/model.rb +120 -0
- data/lib/harvest/project.rb +55 -26
- data/lib/harvest/rate_limit_status.rb +9 -8
- data/lib/harvest/task.rb +17 -14
- data/lib/harvest/task_assignment.rb +27 -22
- data/lib/harvest/time_entry.rb +32 -30
- data/lib/harvest/user.rb +46 -22
- data/lib/harvest/user_assignment.rb +24 -17
- data/lib/harvested.rb +12 -5
- data/spec/functional/account_spec.rb +17 -0
- data/spec/functional/clients_spec.rb +58 -0
- data/spec/functional/errors_spec.rb +22 -0
- data/spec/functional/expenses_spec.rb +84 -0
- data/spec/functional/hardy_client_spec.rb +33 -0
- data/spec/functional/invoice_spec.rb +67 -0
- data/spec/functional/project_spec.rb +50 -0
- data/spec/functional/reporting_spec.rb +80 -0
- data/spec/functional/tasks_spec.rb +88 -0
- data/spec/functional/time_tracking_spec.rb +53 -0
- data/spec/functional/users_spec.rb +102 -0
- data/spec/harvest/base_spec.rb +1 -1
- data/spec/harvest/credentials_spec.rb +1 -1
- data/spec/harvest/expense_category_spec.rb +5 -0
- data/spec/harvest/expense_spec.rb +8 -5
- data/spec/harvest/invoice_spec.rb +47 -0
- data/spec/harvest/project_spec.rb +11 -0
- data/spec/harvest/task_assignment_spec.rb +4 -4
- data/spec/harvest/task_spec.rb +7 -0
- data/spec/harvest/time_entry_spec.rb +11 -10
- data/spec/harvest/user_assignment_spec.rb +3 -3
- data/spec/harvest/user_spec.rb +3 -1
- data/spec/spec_helper.rb +37 -6
- data/{features → spec}/support/harvest_credentials.example.yml +0 -1
- data/spec/support/harvested_helpers.rb +44 -0
- data/spec/support/json_examples.rb +11 -0
- data/spec/test_rubies +5 -0
- metadata +109 -85
- data/.gitignore +0 -28
- data/features/account.feature +0 -7
- data/features/client_contacts.feature +0 -23
- data/features/clients.feature +0 -29
- data/features/errors.feature +0 -25
- data/features/expense_categories.feature +0 -21
- data/features/expenses.feature +0 -55
- data/features/hardy_client.feature +0 -40
- data/features/projects.feature +0 -39
- data/features/reporting.feature +0 -72
- data/features/step_definitions/account_steps.rb +0 -7
- data/features/step_definitions/assignment_steps.rb +0 -100
- data/features/step_definitions/contact_steps.rb +0 -11
- data/features/step_definitions/debug_steps.rb +0 -3
- data/features/step_definitions/error_steps.rb +0 -113
- data/features/step_definitions/expenses_steps.rb +0 -46
- data/features/step_definitions/harvest_steps.rb +0 -8
- data/features/step_definitions/model_steps.rb +0 -90
- data/features/step_definitions/people_steps.rb +0 -4
- data/features/step_definitions/report_steps.rb +0 -91
- data/features/step_definitions/time_entry_steps.rb +0 -40
- data/features/support/env.rb +0 -37
- data/features/support/error_helpers.rb +0 -18
- data/features/support/fixtures/empty_clients.xml +0 -2
- data/features/support/fixtures/over_limit.xml +0 -8
- data/features/support/fixtures/receipt.png +0 -0
- data/features/support/fixtures/under_limit.xml +0 -8
- data/features/support/harvest_helpers.rb +0 -11
- data/features/support/inflections.rb +0 -9
- data/features/task_assignment.feature +0 -69
- data/features/tasks.feature +0 -25
- data/features/time_tracking.feature +0 -29
- data/features/user_assignments.feature +0 -33
- data/features/users.feature +0 -55
- data/lib/harvest/base_model.rb +0 -73
- data/spec/spec.default.opts +0 -1
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'harvest tasks' do
|
4
|
+
it 'allows adding, updating and removing tasks' do
|
5
|
+
cassette('tasks') do
|
6
|
+
task = harvest.tasks.create(
|
7
|
+
"name" => "A crud task",
|
8
|
+
"billable_by_default" => true,
|
9
|
+
"default_hourly_rate" => 120
|
10
|
+
)
|
11
|
+
task.default_hourly_rate.should == "120.0"
|
12
|
+
|
13
|
+
task.default_hourly_rate = 140
|
14
|
+
task = harvest.tasks.update(task)
|
15
|
+
task.default_hourly_rate.should == "140.0"
|
16
|
+
|
17
|
+
harvest.tasks.delete(task)
|
18
|
+
harvest.tasks.all.select {|t| t.name == "A crud task"}.should == []
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "task assignments" do
|
23
|
+
it "allows adding, updating, and removing tasks from projects" do
|
24
|
+
cassette('tasks2') do
|
25
|
+
client = harvest.clients.create(
|
26
|
+
"name" => "Joe's Steam Cleaning",
|
27
|
+
"details" => "Building API Widgets across the country"
|
28
|
+
)
|
29
|
+
|
30
|
+
project = harvest.projects.create(
|
31
|
+
"name" => "Test Project2",
|
32
|
+
"active" => true,
|
33
|
+
"notes" => "project to test the api",
|
34
|
+
"client_id" => client.id
|
35
|
+
)
|
36
|
+
|
37
|
+
task1 = harvest.tasks.create(
|
38
|
+
"name" => "A task for joe",
|
39
|
+
"billable_by_default" => true,
|
40
|
+
"default_hourly_rate" => 120
|
41
|
+
)
|
42
|
+
|
43
|
+
# need to keep at least one task on the project
|
44
|
+
task2 = harvest.tasks.create(
|
45
|
+
"name" => "A task for joe2",
|
46
|
+
"billable_by_default" => true,
|
47
|
+
"default_hourly_rate" => 100
|
48
|
+
)
|
49
|
+
|
50
|
+
harvest.task_assignments.create("project" => project, "task" => task1)
|
51
|
+
harvest.task_assignments.create("project" => project, "task" => task2)
|
52
|
+
|
53
|
+
all_assignments = harvest.task_assignments.all(project)
|
54
|
+
assignment1 = all_assignments.detect {|a| a.task_id == task1.id }
|
55
|
+
assignment2 = all_assignments.detect {|a| a.task_id == task2.id }
|
56
|
+
|
57
|
+
assignment1.hourly_rate = 100
|
58
|
+
assignment1 = harvest.task_assignments.update(assignment1)
|
59
|
+
assignment1.hourly_rate.should == "100.0"
|
60
|
+
|
61
|
+
harvest.task_assignments.delete(assignment1)
|
62
|
+
all_assignments = harvest.task_assignments.all(project)
|
63
|
+
all_assignments.size.should == 1
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it "allows creating and assigning the task at the same time" do
|
68
|
+
cassette('tasks3') do
|
69
|
+
client = harvest.clients.create(
|
70
|
+
"name" => "Joe's Steam Cleaning 2",
|
71
|
+
"details" => "Building API Widgets across the country"
|
72
|
+
)
|
73
|
+
|
74
|
+
project = harvest.projects.create(
|
75
|
+
"name" => "Test Project3",
|
76
|
+
"active" => true,
|
77
|
+
"notes" => "project to test the api",
|
78
|
+
"client_id" => client.id
|
79
|
+
)
|
80
|
+
|
81
|
+
project2 = harvest.projects.create_task(project, "A simple task")
|
82
|
+
project2.should == project
|
83
|
+
|
84
|
+
harvest.task_assignments.all(project).size.should == 1
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'harvest time tracking' do
|
4
|
+
it 'allows adding, updating and removing entries' do
|
5
|
+
cassette("time_tracking1") do
|
6
|
+
client = harvest.clients.create("name" => "Jane's Car Shop")
|
7
|
+
project = harvest.projects.create("name" => "Tracking Project", "client_id" => client.id)
|
8
|
+
harvest.projects.create_task(project, "A billable task")
|
9
|
+
task = harvest.tasks.all.detect {|t| t.name == "A billable task"}
|
10
|
+
|
11
|
+
entry = harvest.time.create("notes" => "Test api support", "hours" => 3, "spent_at" => "12/28/2009", "task_id" => task.id, "project_id" => project.id)
|
12
|
+
entry.notes.should == "Test api support"
|
13
|
+
|
14
|
+
entry.notes = "Upgraded to JSON"
|
15
|
+
entry = harvest.time.update(entry)
|
16
|
+
entry.notes.should == "Upgraded to JSON"
|
17
|
+
|
18
|
+
harvest.time.delete(entry)
|
19
|
+
harvest.time.all(Time.utc(2009, 12, 28)).should == []
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'allows you to save entries for a different user' do
|
24
|
+
cassette("time_tracking2") do
|
25
|
+
user = harvest.users.create(
|
26
|
+
"email" => "frank@example.com",
|
27
|
+
"first_name" => "Frank",
|
28
|
+
"last_name" => "Doe",
|
29
|
+
"password" => "secure"
|
30
|
+
)
|
31
|
+
client = harvest.clients.create("name" => "Kim's Tux Shop")
|
32
|
+
project = harvest.projects.create("name" => "Other User Tracking Project", "client_id" => client.id)
|
33
|
+
harvest.user_assignments.create("project" => project, "user" => user)
|
34
|
+
harvest.projects.create_task(project, "A billable task for tuxes")
|
35
|
+
task = harvest.tasks.all.detect {|t| t.name == "A billable task for tuxes"}
|
36
|
+
|
37
|
+
entry = harvest.time.create("notes" => "Test api support", "hours" => 3, "spent_at" => "12/28/2009", "task_id" => task.id, "project_id" => project.id, "of_user" => user.id)
|
38
|
+
harvest.time.all(Time.utc(2009, 12, 28), user).should == [entry]
|
39
|
+
|
40
|
+
entry.notes = "Updating notes"
|
41
|
+
entry = harvest.time.update(entry, user)
|
42
|
+
entry.notes.should == "Updating notes"
|
43
|
+
|
44
|
+
entry = harvest.time.find(entry, user)
|
45
|
+
entry.notes.should == "Updating notes"
|
46
|
+
|
47
|
+
harvest.time.delete(entry, user)
|
48
|
+
harvest.time.all(Time.utc(2009, 12, 28), user).should == []
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'allows toggling of timers'
|
53
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'harvest users' do
|
4
|
+
it "allows adding, updating, and removing users" do
|
5
|
+
cassette("users") do
|
6
|
+
user = harvest.users.create(
|
7
|
+
"first_name" => "Edgar",
|
8
|
+
"last_name" => "Ruth",
|
9
|
+
"email" => "edgar@ruth.com",
|
10
|
+
"password" => "mypassword",
|
11
|
+
"timezone" => "cst",
|
12
|
+
"is_admin" => "false",
|
13
|
+
"telephone" => "444-4444"
|
14
|
+
)
|
15
|
+
user.id.should_not be_blank
|
16
|
+
|
17
|
+
user.first_name = "Joey"
|
18
|
+
user = harvest.users.update(user)
|
19
|
+
user.first_name.should == "Joey"
|
20
|
+
|
21
|
+
id = harvest.users.delete(user)
|
22
|
+
harvest.users.all.map(&:id).should_not include(id)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "allows activating and deactivating users" do
|
27
|
+
cassette("users2") do
|
28
|
+
user = harvest.users.create(
|
29
|
+
"first_name" => "John",
|
30
|
+
"last_name" => "Ruth",
|
31
|
+
"email" => "john@ruth.com",
|
32
|
+
"password" => "mypassword",
|
33
|
+
"timezone" => "cst",
|
34
|
+
"is_admin" => "false",
|
35
|
+
"telephone" => "444-4444"
|
36
|
+
)
|
37
|
+
user.should be_active
|
38
|
+
|
39
|
+
user = harvest.users.deactivate(user)
|
40
|
+
user.should_not be_active
|
41
|
+
|
42
|
+
user = harvest.users.activate(user)
|
43
|
+
user.should be_active
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "allows password resets" do
|
48
|
+
cassette("users3") do
|
49
|
+
user = harvest.users.create(
|
50
|
+
"first_name" => "Timmy",
|
51
|
+
"last_name" => "Ruth",
|
52
|
+
"email" => "timmy@ruth.com",
|
53
|
+
"password" => "mypassword",
|
54
|
+
"timezone" => "cst",
|
55
|
+
"is_admin" => "false",
|
56
|
+
"telephone" => "444-4444"
|
57
|
+
)
|
58
|
+
user.should be_active
|
59
|
+
|
60
|
+
harvest.users.reset_password(user) # nothing else to assert
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "assignments" do
|
65
|
+
it "allows adding, updating, and removing users from projects" do
|
66
|
+
cassette('users4') do
|
67
|
+
client = harvest.clients.create(
|
68
|
+
"name" => "Joe's Steam Cleaning w/Users",
|
69
|
+
"details" => "Building API Widgets across the country"
|
70
|
+
)
|
71
|
+
|
72
|
+
project = harvest.projects.create(
|
73
|
+
"name" => "Test Project w/User",
|
74
|
+
"active" => true,
|
75
|
+
"notes" => "project to test the api",
|
76
|
+
"client_id" => client.id
|
77
|
+
)
|
78
|
+
|
79
|
+
user = harvest.users.create(
|
80
|
+
"first_name" => "Sally",
|
81
|
+
"last_name" => "Ruth",
|
82
|
+
"email" => "sally@ruth.com",
|
83
|
+
"password" => "mypassword",
|
84
|
+
"timezone" => "cst",
|
85
|
+
"is_admin" => "false",
|
86
|
+
"telephone" => "444-4444"
|
87
|
+
)
|
88
|
+
|
89
|
+
|
90
|
+
assignment = harvest.user_assignments.create("project" => project, "user" => user)
|
91
|
+
|
92
|
+
assignment.hourly_rate = 100
|
93
|
+
assignment = harvest.user_assignments.update(assignment)
|
94
|
+
assignment.hourly_rate.should == "100.0"
|
95
|
+
|
96
|
+
harvest.user_assignments.delete(assignment)
|
97
|
+
all_assignments = harvest.user_assignments.all(project)
|
98
|
+
all_assignments.size.should == 1
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/spec/harvest/base_spec.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Harvest::Expense do
|
4
|
+
it_behaves_like 'a json sanitizer', %w(has_receipt receipt_url)
|
5
|
+
|
4
6
|
describe "#spent_at" do
|
5
7
|
it "should parse strings" do
|
6
|
-
|
7
|
-
expense.spent_at
|
8
|
+
date = RUBY_VERSION =~ /1.8/ ? "12/01/2009" : "01/12/2009"
|
9
|
+
expense = Harvest::Expense.new(:spent_at => date)
|
10
|
+
expense.spent_at.should == Time.parse(date)
|
8
11
|
end
|
9
12
|
|
10
13
|
it "should accept times" do
|
11
|
-
expense = Harvest::Expense.new(:spent_at => Time.
|
12
|
-
expense.spent_at.should == Time.
|
14
|
+
expense = Harvest::Expense.new(:spent_at => Time.utc(2009, 12, 1))
|
15
|
+
expense.spent_at.should == Time.utc(2009, 12, 1)
|
13
16
|
end
|
14
17
|
end
|
15
18
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Harvest::Invoice do
|
4
|
+
context 'line_items' do
|
5
|
+
it 'parses csv into objects' do
|
6
|
+
invoice = Harvest::Invoice.new(:line_items => "kind,description,quantity,unit_price,amount,taxed,taxed2,project_id\nService,Abc,200,12.00,2400.0,false,false,100\nService,def,1.00,20.00,20.0,false,false,101\n")
|
7
|
+
invoice.line_items.count.should == 2
|
8
|
+
line_item = invoice.line_items.first
|
9
|
+
|
10
|
+
line_item.kind.should == "Service"
|
11
|
+
line_item.project_id.should == "100"
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'parses csv into objects w/o projects' do
|
15
|
+
invoice = Harvest::Invoice.new(:line_items => "kind,description,quantity,unit_price,amount,taxed,taxed2,project_id\nService,Abc,200,12.00,2400.0,false,false,\nService,def,1.00,20.00,20.0,false,false,\n")
|
16
|
+
invoice.line_items.count.should == 2
|
17
|
+
line_item = invoice.line_items.first
|
18
|
+
|
19
|
+
line_item.kind.should == "Service"
|
20
|
+
line_item.description.should == "Abc"
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'parses empty strings' do
|
24
|
+
invoice = Harvest::Invoice.new(:line_items => "")
|
25
|
+
invoice.line_items.should == []
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'accepts rich objects' do
|
29
|
+
Harvest::Invoice.new(:line_items => [Harvest::LineItem.new(:kind => "Service")]).line_items.count.should == 1
|
30
|
+
Harvest::Invoice.new(:line_items => Harvest::LineItem.new(:kind => "Service")).line_items.count.should == 1
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'accepts nil' do
|
34
|
+
Harvest::Invoice.new(:line_items => nil).line_items.should == []
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "as_json" do
|
39
|
+
it 'encodes line items csv' do
|
40
|
+
invoice = Harvest::Invoice.new(:line_items => "kind,description,quantity,unit_price,amount,taxed,taxed2,project_id\nService,Abc,200,12.00,2400.0,false,false,\nService,def,1.00,20.00,20.0,false,false,\n")
|
41
|
+
invoice.line_items.count.should == 2
|
42
|
+
invoice.line_items.first.kind.should == "Service"
|
43
|
+
|
44
|
+
invoice.as_json["doc"]["csv_line_items"].should == "kind,description,quantity,unit_price,amount,taxed,taxed2,project_id\nService,Abc,200,12.00,2400.0,false,false,\nService,def,1.00,20.00,20.0,false,false,\n"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Harvest::Project do
|
4
|
+
it_behaves_like 'a json sanitizer', %w(hint_latest_record_at hint_earliest_record_at cache_version)
|
5
|
+
|
6
|
+
it "cleans up weird attributes" do
|
7
|
+
project = Harvest::Project.parse('[{"project":{"hint-earliest-record-at":10, "hint-latest-record-at":20}}]').first
|
8
|
+
project.hint_earliest_record_at.should == 10
|
9
|
+
project.hint_latest_record_at.should == 20
|
10
|
+
end
|
11
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Harvest::TaskAssignment do
|
4
|
-
|
5
|
-
it "
|
4
|
+
context "task_as_json" do
|
5
|
+
it "generates the json for existing tasks" do
|
6
6
|
assignment = Harvest::TaskAssignment.new(:task => mock(:task, :to_i => 3))
|
7
|
-
assignment.
|
7
|
+
assignment.task_as_json.should == {"task" => {"id" => 3}}
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -1,22 +1,23 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Harvest::TimeEntry do
|
4
|
-
|
5
|
-
it
|
6
|
-
entry = Harvest::TimeEntry.new(:notes => 'the notes', :project_id => 'the project id', :task_id => 'the task id', :hours => 'the hours', :spent_at =>
|
7
|
-
entry.
|
4
|
+
context '#as_json' do
|
5
|
+
it 'builds a specialized hash' do
|
6
|
+
entry = Harvest::TimeEntry.new(:notes => 'the notes', :project_id => 'the project id', :task_id => 'the task id', :hours => 'the hours', :spent_at => Time.utc(2009, 12, 28))
|
7
|
+
entry.as_json.should == {"notes" => "the notes", "hours" => "the hours", "project_id" => "the project id", "task_id" => "the task id", "spent_at" => "2009-12-28T00:00:00Z"}
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
context "#spent_at" do
|
12
12
|
it "should parse strings" do
|
13
|
-
|
14
|
-
entry.spent_at
|
13
|
+
date = RUBY_VERSION =~ /1.8/ ? "12/01/2009" : "01/12/2009"
|
14
|
+
entry = Harvest::TimeEntry.new(:spent_at => date)
|
15
|
+
entry.spent_at.should == Time.parse(date)
|
15
16
|
end
|
16
17
|
|
17
18
|
it "should accept times" do
|
18
|
-
entry = Harvest::TimeEntry.new(:spent_at => Time.
|
19
|
-
entry.spent_at.should == Time.
|
19
|
+
entry = Harvest::TimeEntry.new(:spent_at => Time.utc(2009, 12, 1))
|
20
|
+
entry.spent_at.should == Time.utc(2009, 12, 1)
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Harvest::UserAssignment do
|
4
|
-
describe "#
|
4
|
+
describe "#user_as_json" do
|
5
5
|
it "should generate the xml for existing users" do
|
6
6
|
assignment = Harvest::UserAssignment.new(:user => mock(:user, :to_i => 3))
|
7
|
-
assignment.
|
7
|
+
assignment.user_as_json.should == {"user" => {"id" => 3}}
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
data/spec/harvest/user_spec.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Harvest::User do
|
4
|
+
it_behaves_like 'a json sanitizer', %w(cache_version)
|
5
|
+
|
4
6
|
describe "#timezone" do
|
5
7
|
it "should convert friendly timezone setting" do
|
6
8
|
p = Harvest::User.new(:timezone => :cst)
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,41 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
-
require "rubygems"
|
4
1
|
require 'harvested'
|
5
|
-
require '
|
6
|
-
require '
|
2
|
+
require 'webmock/rspec'
|
3
|
+
require 'vcr'
|
7
4
|
|
8
|
-
|
5
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require File.expand_path(f) }
|
6
|
+
|
7
|
+
VCR.config do |c|
|
8
|
+
c.cassette_library_dir = '.cassettes'
|
9
|
+
c.stub_with :webmock
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.include HarvestedHelpers
|
14
|
+
|
15
|
+
config.before(:suite) do
|
16
|
+
WebMock.allow_net_connect!
|
17
|
+
cassette("clean") do
|
18
|
+
HarvestedHelpers.clean_remote
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
config.before(:each) do
|
23
|
+
WebMock.allow_net_connect!
|
24
|
+
end
|
9
25
|
|
26
|
+
def cassette(*args)
|
27
|
+
if ENV['CACHE'] == "false"
|
28
|
+
if args.last.is_a?(Hash)
|
29
|
+
last = args.pop
|
30
|
+
last[:record] = :all
|
31
|
+
args << last
|
32
|
+
else
|
33
|
+
args << {:record => :all}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
VCR.use_cassette(*args) do
|
38
|
+
yield
|
39
|
+
end
|
40
|
+
end
|
10
41
|
end
|