supaspoida-harvest 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY +3 -0
- data/LICENSE +23 -0
- data/README.rdoc +173 -0
- data/Rakefile +44 -0
- data/lib/harvest/base.rb +83 -0
- data/lib/harvest/harvest_resource.rb +15 -0
- data/lib/harvest/plugins/active_resource_inheritable_headers.rb +36 -0
- data/lib/harvest/plugins/toggleable.rb +12 -0
- data/lib/harvest/resources/client.rb +8 -0
- data/lib/harvest/resources/entry.rb +34 -0
- data/lib/harvest/resources/expense.rb +22 -0
- data/lib/harvest/resources/expense_category.rb +7 -0
- data/lib/harvest/resources/person.rb +44 -0
- data/lib/harvest/resources/project.rb +51 -0
- data/lib/harvest/resources/task.rb +8 -0
- data/lib/harvest/resources/task_assignment.rb +27 -0
- data/lib/harvest/resources/user_assignment.rb +27 -0
- data/lib/harvest.rb +36 -0
- data/test/integration/client_integration.rb +17 -0
- data/test/integration/client_teardown.rb +11 -0
- data/test/integration/expense_category_integration.rb +16 -0
- data/test/integration/expense_category_teardown.rb +12 -0
- data/test/integration/harvest_integration_test.rb +47 -0
- data/test/integration/project_integration.rb +19 -0
- data/test/integration/project_teardown.rb +12 -0
- data/test/integration/task_integration.rb +19 -0
- data/test/integration/task_teardown.rb +12 -0
- data/test/test_helper.rb +51 -0
- data/test/unit/base_test.rb +84 -0
- data/test/unit/resources/client_test.rb +82 -0
- data/test/unit/resources/expense_category_test.rb +49 -0
- data/test/unit/resources/expense_test.rb +14 -0
- data/test/unit/resources/person_test.rb +150 -0
- data/test/unit/resources/project_test.rb +154 -0
- data/test/unit/resources/task_assignment_test.rb +72 -0
- data/test/unit/resources/task_test.rb +82 -0
- data/test/unit/resources/user_assignment_test.rb +71 -0
- metadata +109 -0
@@ -0,0 +1,11 @@
|
|
1
|
+
class ClientTeardown < Test::Unit::TestCase
|
2
|
+
|
3
|
+
def test_should_destroy_the_client
|
4
|
+
client = $harvest.clients.find($test_client.id)
|
5
|
+
client.destroy
|
6
|
+
assert_raise ActiveResource::ResourceNotFound do
|
7
|
+
$harvest.clients.find($test_client)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class ExpenseCategoryIntegration < Test::Unit::TestCase
|
2
|
+
|
3
|
+
def test_should_create_and_update_a_new_expense_category
|
4
|
+
# create
|
5
|
+
expense_category = $harvest.expense_categories.new
|
6
|
+
expense_category.name = "GemEntertainmentBeforeUpdate"
|
7
|
+
expense_category.save
|
8
|
+
$test_expense_category = $harvest.expense_categories.find(:all).detect {|c| c.name == "GemEntertainmentBeforeUpdate"}
|
9
|
+
|
10
|
+
#update
|
11
|
+
expense_category.name = "GemEntertainment"
|
12
|
+
expense_category.save
|
13
|
+
assert_equal "GemEntertainment", $harvest.expense_categories.find(:all).detect {|c| c.name == "GemEntertainment"}.name
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class ExpenseCategoryTeardown < Test::Unit::TestCase
|
2
|
+
|
3
|
+
def test_should_destroy_the_expense_category
|
4
|
+
expense_category = $harvest.expense_categories.find(:all).detect {|c| c.name == "GemEntertainment"}
|
5
|
+
expense_category.destroy
|
6
|
+
assert_raise ActiveResource::ResourceNotFound do
|
7
|
+
$harvest.expense_categories.find($test_expense_category)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
$test_mode = :integration
|
3
|
+
|
4
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
5
|
+
require "test/unit/testsuite"
|
6
|
+
require "test/unit/ui/console/testrunner"
|
7
|
+
|
8
|
+
require "client_integration"
|
9
|
+
require "client_teardown"
|
10
|
+
require "expense_category_integration"
|
11
|
+
require "expense_category_teardown"
|
12
|
+
require "project_integration"
|
13
|
+
require "project_teardown"
|
14
|
+
require "task_integration"
|
15
|
+
require "task_teardown"
|
16
|
+
|
17
|
+
|
18
|
+
# Make sure that credentials have been specified:
|
19
|
+
if [:email, :password, :sub_domain].any? { |k| $integration_credentials[k].nil? }
|
20
|
+
raise ArgumentError, "Integration test cannot be run without login credentials; Please specify in test/test_helper.rb"
|
21
|
+
end
|
22
|
+
|
23
|
+
# Initialize a harvest object with credentials.
|
24
|
+
$harvest = Harvest($integration_credentials)
|
25
|
+
|
26
|
+
# Global variables to hold resources
|
27
|
+
# for later reference.
|
28
|
+
$test_client = nil
|
29
|
+
$test_project = nil
|
30
|
+
$test_person = nil
|
31
|
+
|
32
|
+
class HarvestIntegration
|
33
|
+
def self.suite
|
34
|
+
suite = Test::Unit::TestSuite.new
|
35
|
+
suite << ExpenseCategoryIntegration.suite
|
36
|
+
suite << TaskIntegration.suite
|
37
|
+
suite << ClientIntegration.suite
|
38
|
+
suite << ProjectIntegration.suite
|
39
|
+
suite << ProjectTeardown.suite
|
40
|
+
suite << ClientTeardown.suite
|
41
|
+
suite << TaskTeardown.suite
|
42
|
+
suite << ExpenseCategoryTeardown.suite
|
43
|
+
return suite
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
Test::Unit::UI::Console::TestRunner.run(HarvestIntegration)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class ProjectIntegration < Test::Unit::TestCase
|
2
|
+
|
3
|
+
def test_should_create_and_update_a_new_project
|
4
|
+
# create
|
5
|
+
project = $harvest.projects.new
|
6
|
+
project.name = "HarvestGem Project"
|
7
|
+
project.active = false
|
8
|
+
project.bill_by = "None"
|
9
|
+
project.client_id = $test_client.id
|
10
|
+
project.save
|
11
|
+
|
12
|
+
# update
|
13
|
+
$test_project = $harvest.projects.find(:all).detect {|c| c.name == "HarvestGem Project"}
|
14
|
+
project.active = true
|
15
|
+
project.save
|
16
|
+
assert $harvest.projects.find($test_project.id).active?
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class ProjectTeardown < Test::Unit::TestCase
|
2
|
+
|
3
|
+
def test_should_destroy_the_project
|
4
|
+
project = $harvest.projects.find($test_project.id)
|
5
|
+
project.destroy
|
6
|
+
assert_raise ActiveResource::ResourceNotFound do
|
7
|
+
$harvest.projects.find($test_project)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class TaskIntegration < Test::Unit::TestCase
|
2
|
+
|
3
|
+
def test_should_create_and_update_a_new_task
|
4
|
+
# create
|
5
|
+
task = $harvest.tasks.new
|
6
|
+
task.billable_by_default = false
|
7
|
+
task.default_hourly_rate = 100
|
8
|
+
task.is_default = false
|
9
|
+
task.name = "GemIntegration"
|
10
|
+
task.save
|
11
|
+
|
12
|
+
# update
|
13
|
+
$test_task = $harvest.tasks.find(:all).detect {|t| t.name == "GemIntegration"}
|
14
|
+
task.name = "GemIntegrationUpdated"
|
15
|
+
task.save
|
16
|
+
assert_equal "GemIntegrationUpdated", $harvest.tasks.find($test_task.id).name
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "active_resource"
|
3
|
+
require "active_resource_throttle"
|
4
|
+
require "test/unit"
|
5
|
+
require "shoulda"
|
6
|
+
require "mocha"
|
7
|
+
|
8
|
+
# The integration test will not run by default.
|
9
|
+
# To run it, type:
|
10
|
+
# rake test:integration
|
11
|
+
#
|
12
|
+
# If running the integration test, login credentials
|
13
|
+
# must be specified here. The integration test verifies
|
14
|
+
# that various resources in a Harvest account can be created,
|
15
|
+
# deleted, updated, destroyed, etc.
|
16
|
+
#
|
17
|
+
# It's best to run this test on a trial account, where no
|
18
|
+
# sensitive data can be manipulated.
|
19
|
+
#
|
20
|
+
# Leave these values nil if not running the integration test.
|
21
|
+
$integration_credentials = {:email => nil,
|
22
|
+
:password => nil,
|
23
|
+
:sub_domain => nil}
|
24
|
+
|
25
|
+
require File.join(File.dirname(__FILE__), "..", "lib", "harvest.rb")
|
26
|
+
|
27
|
+
# Disengage throttling if in unit test mode (Integration test needs throttling).
|
28
|
+
if ($test_mode ||= :unit) == :unit
|
29
|
+
require "active_resource/http_mock"
|
30
|
+
Harvest::HarvestResource.throttle(:interval => 0, :requests => 0)
|
31
|
+
Harvest::HarvestResource.site = "http://example.com/"
|
32
|
+
end
|
33
|
+
|
34
|
+
# Load all available resources.
|
35
|
+
ResourcesPath = File.join(File.dirname(__FILE__), "..", "lib", "harvest", "resources")
|
36
|
+
Harvest.load_all_ruby_files_from_path(ResourcesPath)
|
37
|
+
|
38
|
+
# Custom assert_raise to test exception message in addition to the exception itself.
|
39
|
+
class Test::Unit::TestCase
|
40
|
+
def assert_raise_plus(exception_class, exception_message, message=nil, &block)
|
41
|
+
begin
|
42
|
+
yield
|
43
|
+
rescue => e
|
44
|
+
error_message = build_message(message, '<?>, <?> expected but was <?>, <?>', exception_class, exception_message, e.class, e.message)
|
45
|
+
assert_block(error_message) { e.class == exception_class && e.message == exception_message }
|
46
|
+
else
|
47
|
+
error_message = build_message(nil, '<?>, <?> expected but raised nothing.', exception_class, exception_message)
|
48
|
+
assert_block(error_message) { false }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
|
3
|
+
class BaseTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "A Harvest object" do
|
6
|
+
setup do
|
7
|
+
@password = "secret"
|
8
|
+
@email = "james@example.com"
|
9
|
+
@sub_domain = "bond"
|
10
|
+
@headers = {"User-Agent" => "HarvestGemTest"}
|
11
|
+
@harvest = Harvest::Base.new(:email => @email,
|
12
|
+
:password => @password,
|
13
|
+
:sub_domain => @sub_domain,
|
14
|
+
:headers => @headers)
|
15
|
+
end
|
16
|
+
|
17
|
+
should "initialize the resource base class" do
|
18
|
+
assert_equal "http://bond.harvestapp.com", Harvest::HarvestResource.site.to_s
|
19
|
+
assert_equal @password, Harvest::HarvestResource.password
|
20
|
+
assert_equal @email, Harvest::HarvestResource.user
|
21
|
+
end
|
22
|
+
|
23
|
+
should "raise an error if sub_domain is missing" do
|
24
|
+
assert_raise_plus ArgumentError, "Missing required option(s): sub_domain" do
|
25
|
+
Harvest(:email => "joe@example.com", :password => "secret")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
should "raise an error if password is missing" do
|
30
|
+
assert_raise_plus ArgumentError, "Missing required option(s): password" do
|
31
|
+
Harvest(:email => "joe@example.com", :sub_domain => "time")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
should "raise an error if email is missing" do
|
36
|
+
assert_raise_plus ArgumentError, "Missing required option(s): email" do
|
37
|
+
Harvest(:password => "secret", :sub_domain => "time")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
should "set the headers" do
|
42
|
+
assert_equal @headers, Harvest::HarvestResource.headers
|
43
|
+
end
|
44
|
+
|
45
|
+
should "return the Client class" do
|
46
|
+
assert_equal Harvest::Resources::Client, @harvest.clients
|
47
|
+
end
|
48
|
+
|
49
|
+
should "return the Expense class" do
|
50
|
+
assert_equal Harvest::Resources::Expense, @harvest.expenses
|
51
|
+
end
|
52
|
+
|
53
|
+
should "return the ExpenseCategory class" do
|
54
|
+
assert_equal Harvest::Resources::ExpenseCategory, @harvest.expense_categories
|
55
|
+
end
|
56
|
+
|
57
|
+
should "return the Person class" do
|
58
|
+
assert_equal Harvest::Resources::Project, @harvest.projects
|
59
|
+
end
|
60
|
+
|
61
|
+
should "return the Project class" do
|
62
|
+
assert_equal Harvest::Resources::Project, @harvest.projects
|
63
|
+
end
|
64
|
+
|
65
|
+
should "return the Task class" do
|
66
|
+
assert_equal Harvest::Resources::Task, @harvest.tasks
|
67
|
+
end
|
68
|
+
|
69
|
+
context "with SSL enabled" do
|
70
|
+
setup do
|
71
|
+
@harvest = Harvest::Base.new(:email => @email,
|
72
|
+
:password => @password,
|
73
|
+
:sub_domain => @sub_domain,
|
74
|
+
:headers => @headers,
|
75
|
+
:ssl => true)
|
76
|
+
end
|
77
|
+
|
78
|
+
should "have https in URL" do
|
79
|
+
assert_equal "https://bond.harvestapp.com", Harvest::HarvestResource.site.to_s
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "test_helper")
|
2
|
+
|
3
|
+
class ClientTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup_resources
|
6
|
+
@client = {:id => 1, :name => "Widgets&Co"}.to_xml(:root => "client")
|
7
|
+
@clients = [{:id => 1, :name => "Widgets&Co"}].to_xml(:root => "clients")
|
8
|
+
end
|
9
|
+
|
10
|
+
def mock_client_responses
|
11
|
+
ActiveResource::HttpMock.respond_to do |mock|
|
12
|
+
mock.get "/clients.xml", {}, @clients
|
13
|
+
mock.get "/clients/1.xml", {}, @client
|
14
|
+
mock.post "/clients.xml", {}, @client, 201, "Location" => "/clients/5.xml"
|
15
|
+
mock.put "/clients/1.xml", {}, nil, 200
|
16
|
+
mock.delete "/clients/1.xml", {}, nil, 200
|
17
|
+
mock.put "/clients/1/toggle.xml", {}, nil, 200
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "Client actions" do
|
22
|
+
setup do
|
23
|
+
setup_resources
|
24
|
+
mock_client_responses
|
25
|
+
end
|
26
|
+
|
27
|
+
should "get index" do
|
28
|
+
Harvest::Resources::Client.find(:all)
|
29
|
+
expected_request = ActiveResource::Request.new(:get, "/clients.xml")
|
30
|
+
assert ActiveResource::HttpMock.requests.include?(expected_request)
|
31
|
+
end
|
32
|
+
|
33
|
+
should "get a single client" do
|
34
|
+
Harvest::Resources::Client.find(1)
|
35
|
+
expected_request = ActiveResource::Request.new(:get, "/clients/1.xml")
|
36
|
+
assert ActiveResource::HttpMock.requests.include?(expected_request)
|
37
|
+
end
|
38
|
+
|
39
|
+
should "create a new client" do
|
40
|
+
client = Harvest::Resources::Client.new(:name => "Widgets&Co")
|
41
|
+
client.save
|
42
|
+
expected_request = ActiveResource::Request.new(:post, "/clients.xml")
|
43
|
+
assert ActiveResource::HttpMock.requests.include?(expected_request)
|
44
|
+
end
|
45
|
+
|
46
|
+
should "update an existing client" do
|
47
|
+
client = Harvest::Resources::Client.find(1)
|
48
|
+
client.name = "Sprockets & Co"
|
49
|
+
client.save
|
50
|
+
expected_request = ActiveResource::Request.new(:put, "/clients/1.xml")
|
51
|
+
assert ActiveResource::HttpMock.requests.include?(expected_request)
|
52
|
+
end
|
53
|
+
|
54
|
+
should "delete an existing client" do
|
55
|
+
Harvest::Resources::Client.delete(1)
|
56
|
+
expected_request = ActiveResource::Request.new(:delete, "/clients/1.xml")
|
57
|
+
assert ActiveResource::HttpMock.requests.include?(expected_request)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
context "Toggling active/inactive status" do
|
63
|
+
setup do
|
64
|
+
setup_resources
|
65
|
+
mock_client_responses
|
66
|
+
end
|
67
|
+
|
68
|
+
should "hit the toggle method" do
|
69
|
+
client = Harvest::Resources::Client.find(1)
|
70
|
+
client.toggle
|
71
|
+
expected_request = ActiveResource::Request.new(:put, "/clients/1/toggle.xml")
|
72
|
+
assert ActiveResource::HttpMock.requests.include?(expected_request)
|
73
|
+
end
|
74
|
+
|
75
|
+
should "return 200 Success toggle method" do
|
76
|
+
client = Harvest::Resources::Client.find(1)
|
77
|
+
assert client.toggle.code == 200
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "test_helper")
|
2
|
+
|
3
|
+
class ExpenseCategoryTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup_resources
|
6
|
+
@expense_category = {:id => 1, :name => "Mileage"}.to_xml(:root => "expense_category")
|
7
|
+
@expense_categories = [{:id => 1, :name => "Mileage"}].to_xml(:root => "expense_categories")
|
8
|
+
end
|
9
|
+
|
10
|
+
def mock_responses
|
11
|
+
ActiveResource::HttpMock.respond_to do |mock|
|
12
|
+
mock.get "/expense_categories.xml", {}, @expense_categories
|
13
|
+
mock.post "/expense_categories.xml", {}, @expence_categories, 201, "Location" => "/expense_categories/5.xml"
|
14
|
+
mock.put "/expense_categories/1.xml", {}, nil, 200
|
15
|
+
mock.delete "/expense_categories/1.xml", {}, nil, 200
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "expense_category actions" do
|
20
|
+
setup do
|
21
|
+
setup_resources
|
22
|
+
mock_responses
|
23
|
+
end
|
24
|
+
|
25
|
+
# Note: The api technically supports updates; however, it doesn't support a show and
|
26
|
+
# therefore doesn't work well with activeresource.
|
27
|
+
|
28
|
+
should "get index" do
|
29
|
+
Harvest::Resources::ExpenseCategory.find(:all)
|
30
|
+
expected_request = ActiveResource::Request.new(:get, "/expense_categories.xml")
|
31
|
+
assert ActiveResource::HttpMock.requests.include?(expected_request)
|
32
|
+
end
|
33
|
+
|
34
|
+
should "create a new expense_category" do
|
35
|
+
expense_category = Harvest::Resources::ExpenseCategory.new(:name => "Widgets&Co")
|
36
|
+
expense_category.save
|
37
|
+
expected_request = ActiveResource::Request.new(:post, "/expense_categories.xml")
|
38
|
+
assert ActiveResource::HttpMock.requests.include?(expected_request)
|
39
|
+
end
|
40
|
+
|
41
|
+
should "delete an existing expense_category" do
|
42
|
+
Harvest::Resources::ExpenseCategory.delete(1)
|
43
|
+
expected_request = ActiveResource::Request.new(:delete, "/expense_categories/1.xml")
|
44
|
+
assert ActiveResource::HttpMock.requests.include?(expected_request)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "test_helper")
|
2
|
+
|
3
|
+
class ExpenseAssignmentTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "ExpenseAssignment class" do
|
6
|
+
|
7
|
+
should "adjust the site setting when the person_id is set" do
|
8
|
+
expense_class = Harvest::Resources::Expense.clone
|
9
|
+
expense_class.person_id = 5
|
10
|
+
assert_equal "http://example.com/people/5", expense_class.site.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "test_helper")
|
2
|
+
|
3
|
+
class PersonTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup_resources
|
6
|
+
@person_xml = {:id => 1, :name => "Joe Coder"}.to_xml(:root => "person")
|
7
|
+
@people = [{:id => 1, :name => "Joe Coder"}].to_xml(:root => "people")
|
8
|
+
@entry = [{:id => 2, :project_id => 50}].to_xml(:root => "day-entries")
|
9
|
+
@entries = [{:id => 1, :project_id => "25"},
|
10
|
+
{:id => 2, :project_id => 50} ].to_xml(:root => "day-entries")
|
11
|
+
@expenses = [{:id => 1, :project_id => "25"},
|
12
|
+
{:id => 2, :project_id => 50} ].to_xml(:root => "expenses")
|
13
|
+
end
|
14
|
+
|
15
|
+
def mock_responses
|
16
|
+
ActiveResource::HttpMock.respond_to do |mock|
|
17
|
+
mock.get "/people.xml", {}, @people
|
18
|
+
mock.get "/people/1.xml", {}, @person_xml
|
19
|
+
mock.post "/people.xml", {}, @person_xml, 201, "Location" => "/people/5.xml"
|
20
|
+
mock.put "/people/1.xml", {}, nil, 200
|
21
|
+
mock.delete "/people/1.xml", {}, nil, 200
|
22
|
+
mock.put "/people/1/toggle.xml", {}, nil, 200
|
23
|
+
mock.get "/people/1/entries.xml?from=20080101&to=20080131", {}, @entries
|
24
|
+
mock.get "/people/1/entries.xml?from=20080101&project_id=3&to=20080131", {}, @entry
|
25
|
+
mock.get "/people/1/expenses.xml?from=20080101&to=20080131", {}, @expenses
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "People CRUD actions -- " do
|
30
|
+
setup do
|
31
|
+
setup_resources
|
32
|
+
mock_responses
|
33
|
+
end
|
34
|
+
|
35
|
+
should "get index" do
|
36
|
+
Harvest::Resources::Person.find(:all)
|
37
|
+
expected_request = ActiveResource::Request.new(:get, "/people.xml")
|
38
|
+
assert ActiveResource::HttpMock.requests.include?(expected_request)
|
39
|
+
end
|
40
|
+
|
41
|
+
should "get a single project" do
|
42
|
+
Harvest::Resources::Person.find(1)
|
43
|
+
expected_request = ActiveResource::Request.new(:get, "/people/1.xml")
|
44
|
+
assert ActiveResource::HttpMock.requests.include?(expected_request)
|
45
|
+
end
|
46
|
+
|
47
|
+
should "create a new project" do
|
48
|
+
project = Harvest::Resources::Person.new(:name => "Widgets&Co")
|
49
|
+
project.save
|
50
|
+
expected_request = ActiveResource::Request.new(:post, "/people.xml")
|
51
|
+
assert ActiveResource::HttpMock.requests.include?(expected_request)
|
52
|
+
end
|
53
|
+
|
54
|
+
should "update an existing project" do
|
55
|
+
project = Harvest::Resources::Person.find(1)
|
56
|
+
project.name = "Joe Coder"
|
57
|
+
project.save
|
58
|
+
expected_request = ActiveResource::Request.new(:put, "/people/1.xml")
|
59
|
+
assert ActiveResource::HttpMock.requests.include?(expected_request)
|
60
|
+
end
|
61
|
+
|
62
|
+
should "delete an existing project" do
|
63
|
+
Harvest::Resources::Person.delete(1)
|
64
|
+
expected_request = ActiveResource::Request.new(:delete, "/people/1.xml")
|
65
|
+
assert ActiveResource::HttpMock.requests.include?(expected_request)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
context "Toggling active/inactive status" do
|
72
|
+
setup do
|
73
|
+
setup_resources
|
74
|
+
mock_responses
|
75
|
+
end
|
76
|
+
|
77
|
+
should "hit the toggle method" do
|
78
|
+
person = Harvest::Resources::Person.find(1)
|
79
|
+
person.toggle
|
80
|
+
expected_request = ActiveResource::Request.new(:put, "/people/1/toggle.xml")
|
81
|
+
assert ActiveResource::HttpMock.requests.include?(expected_request)
|
82
|
+
end
|
83
|
+
|
84
|
+
should "return 200 Success toggle method" do
|
85
|
+
person = Harvest::Resources::Person.find(1)
|
86
|
+
assert person.toggle.code == 200
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
context "Getting entries" do
|
92
|
+
setup do
|
93
|
+
setup_resources
|
94
|
+
mock_responses
|
95
|
+
@person = Harvest::Resources::Person.find(1)
|
96
|
+
end
|
97
|
+
|
98
|
+
should "raise an error if start and end are not included" do
|
99
|
+
assert_raises ArgumentError, "Must specify :start and :end as dates." do
|
100
|
+
@person.entries
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
should "raise an error if end date precedes start date" do
|
105
|
+
assert_raises ArgumentError, "Must specify :start and :end as dates." do
|
106
|
+
@person.entries(:from => Time.utc(2007, 1, 1), :to => Time.utc(2006, 1, 1))
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
should "return the project site prefix" do
|
111
|
+
entry_class = Harvest::Resources::Entry.clone
|
112
|
+
entry_class.person_id = @person.id
|
113
|
+
assert_equal "http://example.com/people/1", entry_class.site.to_s
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
context "Reports -- " do
|
119
|
+
setup do
|
120
|
+
setup_resources
|
121
|
+
mock_responses
|
122
|
+
@from = Time.utc(2008, 1, 1)
|
123
|
+
@to = Time.utc(2008, 1, 31)
|
124
|
+
@person = Harvest::Resources::Person.find(1)
|
125
|
+
@request_path = "/people/1/entries.xml?from=20080101&to=20080131"
|
126
|
+
@expense_path = "/people/1/expenses.xml?from=20080101&to=20080131"
|
127
|
+
end
|
128
|
+
|
129
|
+
should "get all entries for a given date range" do
|
130
|
+
@person.entries(:from => @from, :to => @to)
|
131
|
+
expected_request = ActiveResource::Request.new(:get, @request_path)
|
132
|
+
assert ActiveResource::HttpMock.requests.include?(expected_request)
|
133
|
+
end
|
134
|
+
|
135
|
+
should "get all entries for the given date range and user" do
|
136
|
+
path = "/people/1/entries.xml?from=20080101&project_id=3&to=20080131"
|
137
|
+
@person.entries(:from => @from, :to => @to, :project_id => 3)
|
138
|
+
expected_request = ActiveResource::Request.new(:get, path)
|
139
|
+
assert ActiveResource::HttpMock.requests.include?(expected_request)
|
140
|
+
end
|
141
|
+
|
142
|
+
should "return all expense entries logged by the given user" do
|
143
|
+
@person.expenses(:from => @from, :to => @to)
|
144
|
+
expected_request = ActiveResource::Request.new(:get, @expense_path)
|
145
|
+
assert ActiveResource::HttpMock.requests.include?(expected_request)
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|