gradesfirst 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +1 -2
  3. data/Gemfile.lock +2 -6
  4. data/gradesfirst.gemspec +2 -2
  5. data/lib/gradesfirst.rb +1 -0
  6. data/lib/gradesfirst/cli.rb +7 -29
  7. data/lib/gradesfirst/cli_helper.rb +33 -0
  8. data/lib/gradesfirst/command.rb +7 -0
  9. data/lib/gradesfirst/commit_message_command.rb +1 -1
  10. data/lib/gradesfirst/task_add_command.rb +51 -0
  11. data/lib/gradesfirst/task_cli.rb +48 -0
  12. data/lib/gradesfirst/task_command.rb +38 -30
  13. data/lib/gradesfirst/task_delete_command.rb +64 -0
  14. data/lib/gradesfirst/task_list_command.rb +40 -0
  15. data/lib/gradesfirst/task_move_command.rb +64 -0
  16. data/lib/gradesfirst/task_toggle_command.rb +65 -0
  17. data/lib/http_magic.rb +2 -258
  18. data/lib/http_magic/api.rb +233 -0
  19. data/lib/http_magic/request.rb +93 -0
  20. data/lib/http_magic/uri.rb +74 -0
  21. data/lib/pivotal_tracker.rb +1 -1
  22. data/test/branch_command_test.rb +8 -21
  23. data/test/cli_test.rb +51 -34
  24. data/test/command_test.rb +5 -7
  25. data/test/commit_message_command_test.rb +37 -45
  26. data/test/fixtures/task.json +10 -0
  27. data/test/fixtures/task_added.txt +6 -0
  28. data/test/fixtures/task_deleted.txt +6 -0
  29. data/test/fixtures/task_moved.txt +6 -0
  30. data/test/fixtures/task_toggled.txt +6 -0
  31. data/test/fixtures/tasks.txt +2 -2
  32. data/test/http_magic/{get_test.rb → api/get_test.rb} +1 -1
  33. data/test/http_magic/api/post_test.rb +34 -0
  34. data/test/http_magic/request_test.rb +63 -0
  35. data/test/http_magic/uri_test.rb +28 -55
  36. data/test/support/pivotal_test_helper.rb +110 -0
  37. data/test/support/request_expectation.rb +33 -0
  38. data/test/task_add_command_test.rb +54 -0
  39. data/test/task_delete_command_test.rb +57 -0
  40. data/test/task_list_command_test.rb +18 -0
  41. data/test/task_move_command_test.rb +66 -0
  42. data/test/task_toggle_command_test.rb +58 -0
  43. data/test/test_helper.rb +35 -19
  44. metadata +29 -7
  45. data/test/pivotal_tracker_test.rb +0 -46
  46. data/test/task_command_test.rb +0 -52
@@ -0,0 +1,57 @@
1
+ require 'test_helper'
2
+ require 'gradesfirst/task_delete_command'
3
+
4
+ describe GradesFirst::TaskDeleteCommand do
5
+ before do
6
+ @task_position = '2'
7
+ @invalid_position = '8'
8
+ @task_id = 6
9
+ @command = GradesFirst::TaskDeleteCommand.new
10
+ end
11
+
12
+ def stub_bar_story_task_delete_request(task_id, response)
13
+ stub_pivotal_request(
14
+ :delete,
15
+ urn_for_bar_story_task(task_id),
16
+ response: response
17
+ )
18
+ end
19
+
20
+ def stub_failing_bar_story_task_delete_request(task_id)
21
+ stub_bar_story_task_delete_request(task_id, status: 500)
22
+ end
23
+
24
+ def stub_working_bar_story_task_delete_request(task_id)
25
+ stub_bar_story_task_delete_request(task_id, status: 204)
26
+ end
27
+
28
+ specify '#execute deletes the task' do
29
+ stubbed_requests = [
30
+ stub_bar_story_request,
31
+ stub_bar_story_tasks_request.times(2),
32
+ stub_working_bar_story_task_delete_request(@task_id)
33
+ ]
34
+
35
+ response = nil
36
+ expect_requests stubbed_requests do
37
+ @command.stub :current_branch, bar_story_id do
38
+ @command.execute(@task_position)
39
+ end
40
+ response = @command.response
41
+ end
42
+ assert_equal fixture_file('task_deleted.txt'), response
43
+ end
44
+
45
+ specify '#response when deleting the task fails' do
46
+ stub_bar_story_request
47
+ stub_bar_story_tasks_request
48
+ stub_failing_bar_story_task_delete_request(@task_id)
49
+ @command.stub :current_branch, bar_story_id do
50
+ @command.execute(@task_position)
51
+ end
52
+ assert_equal @command.send(:task_error_message), @command.response
53
+ end
54
+
55
+ specify_response_for_invalid_task_position :delete, @invalid_position
56
+ specify_response_for_invalid_story @task_position
57
+ end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+ require 'pivotal_tracker'
3
+ require 'gradesfirst/task_list_command'
4
+
5
+ describe GradesFirst::TaskListCommand do
6
+ before do
7
+ @command = GradesFirst::TaskListCommand.new
8
+ end
9
+
10
+ specify '#response responds with a task list with a valid story ' do
11
+ expect_requests stub_bar_story_request, stub_bar_story_tasks_request do
12
+ @command.stub :current_branch, bar_story_id, &call_execute
13
+ end
14
+ assert_equal fixture_file('tasks.txt'), @command.response
15
+ end
16
+
17
+ specify_response_for_invalid_story
18
+ end
@@ -0,0 +1,66 @@
1
+ require 'test_helper'
2
+ require 'gradesfirst/task_move_command'
3
+
4
+ describe GradesFirst::TaskMoveCommand do
5
+ before do
6
+ @task_id = 6
7
+ @from_position = '2'
8
+ @to_position = '1'
9
+ @command = GradesFirst::TaskMoveCommand.new
10
+ end
11
+
12
+ def stub_bar_story_task_move_request(task_id, to_position, response)
13
+ stub_pivotal_request(
14
+ :put,
15
+ urn_for_bar_story_task(task_id),
16
+ request: { body: "{\"position\":#{to_position}}" },
17
+ response: response
18
+ )
19
+ end
20
+
21
+ def stub_failing_bar_story_task_move_request(task_id, to_position)
22
+ stub_bar_story_task_move_request(
23
+ task_id,
24
+ to_position,
25
+ status: 500
26
+ )
27
+ end
28
+
29
+ def stub_working_bar_story_task_move_request(task_id, to_position)
30
+ stub_bar_story_task_move_request(
31
+ task_id,
32
+ to_position,
33
+ body: fixture_file('task.json')
34
+ )
35
+ end
36
+
37
+ specify '#execute moves the task to a new position' do
38
+ stubbed_requests = [
39
+ stub_bar_story_request,
40
+ stub_bar_story_tasks_request.times(2),
41
+ stub_working_bar_story_task_move_request(@task_id, @to_position)
42
+ ]
43
+
44
+ response = nil
45
+ expect_requests stubbed_requests do
46
+ @command.stub :current_branch, bar_story_id do
47
+ @command.execute(@from_position, @to_position)
48
+ end
49
+ response = @command.response
50
+ end
51
+ assert_equal fixture_file('task_moved.txt'), response
52
+ end
53
+
54
+ specify '#response when moving the task fails' do
55
+ stub_bar_story_request
56
+ stub_bar_story_tasks_request
57
+ stub_failing_bar_story_task_move_request(@task_id, @to_position)
58
+ @command.stub :current_branch, bar_story_id do
59
+ @command.execute(@from_position, @to_position)
60
+ end
61
+ assert_equal @command.send(:task_error_message), @command.response
62
+ end
63
+
64
+ specify_response_for_invalid_task_position :put, @from_position, @to_position
65
+ specify_response_for_invalid_story @from_position, @to_position
66
+ end
@@ -0,0 +1,58 @@
1
+ require 'test_helper'
2
+ require 'gradesfirst/task_toggle_command'
3
+
4
+ describe GradesFirst::TaskToggleCommand do
5
+ before do
6
+ @task_position = '2'
7
+ @invalid_position = '8'
8
+ @task_id = 6
9
+ @command = GradesFirst::TaskToggleCommand.new
10
+ end
11
+
12
+ def stub_bar_story_task_toggle_request(task_id, response)
13
+ stub_pivotal_request(
14
+ :put,
15
+ urn_for_bar_story_task(task_id),
16
+ request: { body: "{\"complete\":true}" },
17
+ response: response
18
+ )
19
+ end
20
+
21
+ def stub_failing_bar_story_task_toggle_request(task_id)
22
+ stub_bar_story_task_toggle_request(task_id, status: 500)
23
+ end
24
+
25
+ def stub_working_bar_story_task_toggle_request(task_id)
26
+ stub_bar_story_task_toggle_request(task_id, body: fixture_file('task.json'))
27
+ end
28
+
29
+ specify '#execute toggles completion status of the task' do
30
+ stubbed_requests = [
31
+ stub_bar_story_request,
32
+ stub_bar_story_tasks_request.times(2),
33
+ stub_working_bar_story_task_toggle_request(@task_id)
34
+ ]
35
+
36
+ response = nil
37
+ expect_requests stubbed_requests do
38
+ @command.stub :current_branch, bar_story_id do
39
+ @command.execute(@task_position)
40
+ end
41
+ response = @command.response
42
+ end
43
+ assert_equal fixture_file('task_toggled.txt'), response
44
+ end
45
+
46
+ specify '#response when toggling the task fails' do
47
+ stub_bar_story_request
48
+ stub_bar_story_tasks_request
49
+ stub_failing_bar_story_task_toggle_request(@task_id)
50
+ @command.stub :current_branch, bar_story_id do
51
+ @command.execute(@task_position)
52
+ end
53
+ assert_equal @command.send(:task_error_message), @command.response
54
+ end
55
+
56
+ specify_response_for_invalid_task_position :put, @invalid_position
57
+ specify_response_for_invalid_story @task_position
58
+ end
data/test/test_helper.rb CHANGED
@@ -4,26 +4,42 @@ require 'rubygems'
4
4
  gem 'minitest' if RUBY_VERSION > '1.9'
5
5
  require 'minitest/autorun'
6
6
  require 'webmock/minitest'
7
- require 'mocha/setup'
8
7
  require 'pry'
9
8
 
10
- # Retreive the contents of fixture files to be used in tests. It is easier
11
- # to view, modify and visualize text used in tests when it is stored in files.
12
- # Also, it is much easier to reuse that text.
13
- def fixture_file(file_name)
14
- File.open(File.dirname(__FILE__) + '/fixtures/' + file_name, 'rb').read
15
- end
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
10
+
11
+ class MiniTest::Unit::TestCase
12
+ include GradesFirst::PivotalTestHelper
13
+ extend GradesFirst::PivotalTestHelper::ClassMethods
14
+
15
+ def setup
16
+ pivotal_tracker_setup
17
+ end
18
+
19
+ # Retreive the contents of fixture files to be used in tests. It is easier
20
+ # to view, modify and visualize text used in tests when it is stored in files.
21
+ # Also, it is much easier to reuse that text.
22
+ def fixture_file(file_name)
23
+ File.open(fixture_file_path(file_name), 'rb').read
24
+ end
25
+
26
+ def fixture_file_path(file_name)
27
+ File.join(File.dirname(__FILE__), 'fixtures', file_name)
28
+ end
29
+
30
+ # This returns a lambda for use as the block argument of #stub. The lambda
31
+ # returned calls #execute on the object being stubbed.
32
+ def call_execute
33
+ ->(stubbed_object) { stubbed_object.execute }
34
+ end
16
35
 
17
- # Simplify and DRY up stubbing out of PivotalTracker requests.
18
- def stub_pivotal_request(method, urn, options)
19
- default_options = {
20
- headers: { 'Content-Type' => 'application/json' },
21
- body: '',
22
- status: 200
23
- }
24
-
25
- uri = "https://www.pivotaltracker.com:443/services/v5/#{urn}"
26
- stub_request(method, uri).
27
- with(headers: { 'X-TrackerToken' => 'test_token' }).
28
- to_return(default_options.merge(options))
36
+ # Verifies that stubbed out requests have actually been requested.
37
+ #
38
+ # expectations - A variable number of RequestExpectation objects.
39
+ def expect_requests(*expectations)
40
+ yield
41
+ expectations.
42
+ flatten.
43
+ each { |expectation| assert_requested(*expectation.to_args) }
44
+ end
29
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gradesfirst
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-18 00:00:00.000000000 Z
12
+ date: 2014-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.14.6
21
+ version: 0.18.1
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 0.14.6
29
+ version: 0.18.1
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: minitest
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -62,10 +62,20 @@ files:
62
62
  - lib/gradesfirst.rb
63
63
  - lib/gradesfirst/branch_command.rb
64
64
  - lib/gradesfirst/cli.rb
65
+ - lib/gradesfirst/cli_helper.rb
65
66
  - lib/gradesfirst/command.rb
66
67
  - lib/gradesfirst/commit_message_command.rb
68
+ - lib/gradesfirst/task_add_command.rb
69
+ - lib/gradesfirst/task_cli.rb
67
70
  - lib/gradesfirst/task_command.rb
71
+ - lib/gradesfirst/task_delete_command.rb
72
+ - lib/gradesfirst/task_list_command.rb
73
+ - lib/gradesfirst/task_move_command.rb
74
+ - lib/gradesfirst/task_toggle_command.rb
68
75
  - lib/http_magic.rb
76
+ - lib/http_magic/api.rb
77
+ - lib/http_magic/request.rb
78
+ - lib/http_magic/uri.rb
69
79
  - lib/pivotal_tracker.rb
70
80
  - test/branch_command_test.rb
71
81
  - test/cli_test.rb
@@ -77,12 +87,24 @@ files:
77
87
  - test/fixtures/projects.json
78
88
  - test/fixtures/story_bar.json
79
89
  - test/fixtures/story_foo.json
90
+ - test/fixtures/task.json
91
+ - test/fixtures/task_added.txt
92
+ - test/fixtures/task_deleted.txt
93
+ - test/fixtures/task_moved.txt
94
+ - test/fixtures/task_toggled.txt
80
95
  - test/fixtures/tasks.json
81
96
  - test/fixtures/tasks.txt
82
- - test/http_magic/get_test.rb
97
+ - test/http_magic/api/get_test.rb
98
+ - test/http_magic/api/post_test.rb
99
+ - test/http_magic/request_test.rb
83
100
  - test/http_magic/uri_test.rb
84
- - test/pivotal_tracker_test.rb
85
- - test/task_command_test.rb
101
+ - test/support/pivotal_test_helper.rb
102
+ - test/support/request_expectation.rb
103
+ - test/task_add_command_test.rb
104
+ - test/task_delete_command_test.rb
105
+ - test/task_list_command_test.rb
106
+ - test/task_move_command_test.rb
107
+ - test/task_toggle_command_test.rb
86
108
  - test/test_helper.rb
87
109
  homepage: http://www.gradesfirst.com
88
110
  licenses:
@@ -1,46 +0,0 @@
1
- require 'test_helper'
2
- require 'pivotal_tracker'
3
-
4
- describe 'PivotalTracker' do
5
- it 'should make a good root uri' do
6
- assert_equal(
7
- 'www.pivotaltracker.com/services/v5',
8
- PivotalTracker.uri
9
- )
10
- end
11
-
12
- it 'should make a good project list uri' do
13
- assert_equal(
14
- 'www.pivotaltracker.com/services/v5/projects',
15
- PivotalTracker.projects.uri
16
- )
17
- end
18
-
19
- it 'should make a good project uri' do
20
- assert_equal(
21
- 'www.pivotaltracker.com/services/v5/projects/99',
22
- PivotalTracker.projects[99].uri
23
- )
24
- end
25
-
26
- it 'should make a good iterations uri' do
27
- assert_equal(
28
- 'www.pivotaltracker.com/services/v5/projects/99/iterations',
29
- PivotalTracker.projects[99].iterations.uri
30
- )
31
- end
32
-
33
- it 'should return a pivotal project' do
34
- stub_pivotal_request(
35
- :get,
36
- 'projects/99',
37
- body: fixture_file('projects.json')
38
- )
39
-
40
- PivotalTracker.api_token = 'test_token'
41
- assert_equal(
42
- 'GradesFirst',
43
- PivotalTracker.projects[99].get.first['name']
44
- )
45
- end
46
- end
@@ -1,52 +0,0 @@
1
- require 'test_helper'
2
- require 'gradesfirst/task_command'
3
-
4
- describe GradesFirst::TaskCommand do
5
- before do
6
- stub_pivotal_request(
7
- :get,
8
- 'stories/29384799',
9
- status: 404
10
- )
11
-
12
- stub_pivotal_request(
13
- :get,
14
- 'stories/29384793',
15
- body: fixture_file('story_bar.json')
16
- )
17
-
18
- stub_pivotal_request(
19
- :get,
20
- 'projects/10687/stories/29384793/tasks',
21
- body: fixture_file('tasks.json')
22
- )
23
-
24
- PivotalTracker.api_token = 'test_token'
25
- end
26
-
27
- describe '#response with a valid story' do
28
- before do
29
- @command = GradesFirst::TaskCommand.new
30
- @command.stub :current_branch, '29384793' do
31
- @command.execute
32
- end
33
- end
34
-
35
- it 'should respond with a task list' do
36
- assert_equal fixture_file('tasks.txt'), @command.response
37
- end
38
- end
39
-
40
- describe '#response with an invalid story' do
41
- before do
42
- @command = GradesFirst::TaskCommand.new
43
- @command.stub :current_branch, '29384799' do
44
- @command.execute
45
- end
46
- end
47
-
48
- it 'should respond with error message' do
49
- assert_equal @command.send(:error_message), @command.response
50
- end
51
- end
52
- end