vigetlabs-unfuzzle 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/README.rdoc +21 -1
  2. data/Rakefile +2 -2
  3. data/lib/unfuzzle.rb +13 -2
  4. data/lib/unfuzzle/component.rb +31 -0
  5. data/lib/unfuzzle/milestone.rb +17 -26
  6. data/lib/unfuzzle/priority.rb +30 -0
  7. data/lib/unfuzzle/project.rb +13 -20
  8. data/lib/unfuzzle/request.rb +5 -8
  9. data/lib/unfuzzle/response.rb +0 -7
  10. data/lib/unfuzzle/severity.rb +31 -0
  11. data/lib/unfuzzle/ticket.rb +58 -25
  12. data/lib/unfuzzle/version.rb +1 -1
  13. data/test/fixtures/component.xml +8 -0
  14. data/test/fixtures/components.xml +17 -0
  15. data/test/fixtures/milestone.xml +12 -0
  16. data/test/fixtures/milestones.xml +25 -0
  17. data/test/fixtures/project.xml +17 -0
  18. data/test/fixtures/projects.xml +35 -0
  19. data/test/fixtures/severities.xml +24 -0
  20. data/test/fixtures/severity.xml +8 -0
  21. data/test/fixtures/ticket.xml +25 -0
  22. data/test/fixtures/tickets.xml +51 -0
  23. data/test/test_helper.rb +5 -7
  24. data/test/unit/unfuzzle/component_test.rb +36 -0
  25. data/test/unit/unfuzzle/milestone_test.rb +12 -44
  26. data/test/unit/unfuzzle/priority_test.rb +25 -0
  27. data/test/unit/unfuzzle/project_test.rb +17 -37
  28. data/test/unit/unfuzzle/request_test.rb +3 -13
  29. data/test/unit/unfuzzle/response_test.rb +0 -28
  30. data/test/unit/unfuzzle/severity_test.rb +36 -0
  31. data/test/unit/unfuzzle/ticket_test.rb +108 -47
  32. metadata +21 -12
  33. data/lib/unfuzzle/model.rb +0 -56
  34. data/test/fixtures/milestone.json +0 -11
  35. data/test/fixtures/milestones.json +0 -22
  36. data/test/fixtures/project.json +0 -16
  37. data/test/fixtures/projects.json +0 -32
  38. data/test/fixtures/tickets.json +0 -44
  39. data/test/unit/unfuzzle/model_test.rb +0 -55
@@ -7,16 +7,10 @@ module Unfuzzle
7
7
 
8
8
  should "be able to return a list of all projects" do
9
9
  response = mock_request_cycle :for => '/projects', :data => 'projects'
10
-
11
- elements = Array.new
12
-
13
- response.data.each do |data|
14
- element = stub()
15
- Unfuzzle::Project.expects(:new).with(data).returns(element)
16
- elements << element
17
- end
18
-
19
- Project.all.should == elements
10
+
11
+ Unfuzzle::Project.expects(:collection_from).with(response.body, 'projects/project').returns(['project_1', 'project_2'])
12
+
13
+ Project.all.should == ['project_1', 'project_2']
20
14
  end
21
15
 
22
16
  should "be able to find a project by its slug" do
@@ -24,7 +18,7 @@ module Unfuzzle
24
18
 
25
19
  response = mock_request_cycle :for => "/projects/by_short_name/#{slug}", :data => 'project'
26
20
 
27
- Unfuzzle::Project.expects(:new).with(response.data).returns('project')
21
+ Unfuzzle::Project.expects(:new).with(response.body).returns('project')
28
22
 
29
23
  Project.find_by_slug(slug).should == 'project'
30
24
  end
@@ -34,7 +28,7 @@ module Unfuzzle
34
28
 
35
29
  response = mock_request_cycle :for => "/projects/#{id}", :data => 'project'
36
30
 
37
- Unfuzzle::Project.expects(:new).with(response.data).returns('project')
31
+ Unfuzzle::Project.expects(:new).with(response.body).returns('project')
38
32
 
39
33
  Project.find_by_id(id).should == 'project'
40
34
  end
@@ -44,21 +38,21 @@ module Unfuzzle
44
38
 
45
39
  context "An instance of the Project class" do
46
40
 
47
- when_populating Project, :from => 'projects' do
48
-
49
- value_for :id, :is => 1
50
- value_for :archived, :is => false
51
- value_for :slug, :is => 'aa'
52
- value_for :name, :is => 'A Client'
53
- value_for :description, :is => 'A great project'
54
- value_for :created_timestamp, :is => '2008-07-28T16:57:10Z'
55
- value_for :updated_timestamp, :is => '2009-04-28T18:48:52Z'
56
-
41
+ when_populating Project, :from => 'project' do
42
+
43
+ value_for :id, :is => 1
44
+ value_for :archived, :is => false
45
+ value_for :slug, :is => 'blip'
46
+ value_for :name, :is => 'Blip Bleep Co.'
47
+ value_for :description, :is => 'This is the project for Blip Bleep Co.'
48
+ value_for :created_at, :is => Time.parse('2008-07-28T16:57:10Z')
49
+ value_for :updated_at, :is => Time.parse('2009-04-28T18:48:52Z')
50
+
57
51
  end
58
52
 
59
53
  context "with a new instance" do
60
54
 
61
- setup { @project = Project.new(stub()) }
55
+ setup { @project = Project.new }
62
56
 
63
57
  should "know that it's archived" do
64
58
  @project.stubs(:archived).with().returns(true)
@@ -70,20 +64,6 @@ module Unfuzzle
70
64
  @project.archived?.should be(false)
71
65
  end
72
66
 
73
- should "have a create date" do
74
- DateTime.expects(:parse).with('2008-07-28T16:57:10Z').returns('create_date')
75
-
76
- @project.stubs(:created_timestamp).with().returns('2008-07-28T16:57:10Z')
77
- @project.created_at.should == 'create_date'
78
- end
79
-
80
- should "have an update date" do
81
- DateTime.expects(:parse).with('2009-04-28T18:48:52Z').returns('update_date')
82
-
83
- @project.stubs(:updated_timestamp).with().returns('2009-04-28T18:48:52Z')
84
- @project.updated_at.should == 'update_date'
85
- end
86
-
87
67
  should "have a list of associated milestones" do
88
68
  id = 1
89
69
  Milestone.expects(:find_all_by_project_id).with(id).returns('milestones')
@@ -14,7 +14,7 @@ module Unfuzzle
14
14
 
15
15
  should "be able to perform a PUT request" do
16
16
  request = mock() {|r| r.expects(:put).with().returns('response') }
17
- Unfuzzle::Request.expects(:new).with('/projects', '<payload>', :format => :xml).returns(request)
17
+ Unfuzzle::Request.expects(:new).with('/projects', '<payload>').returns(request)
18
18
 
19
19
  Unfuzzle::Request.put('/projects', '<payload>').should == 'response'
20
20
  end
@@ -23,27 +23,17 @@ module Unfuzzle
23
23
 
24
24
  context "An instance of the Request class" do
25
25
 
26
- should "default the data format to JSON" do
27
- request = Unfuzzle::Request.new('/projects')
28
- request.request_format.should == 'json'
29
- end
30
-
31
- should "be able to override the request data format" do
32
- request = Unfuzzle::Request.new('/projects', nil, :format => :xml)
33
- request.request_format.should == 'xml'
34
- end
35
-
36
26
  should "have an endpoint URI" do
37
27
  Unfuzzle.stubs(:subdomain).with().returns('viget')
38
28
 
39
29
  request = Unfuzzle::Request.new('/projects')
40
- request.endpoint_uri.should == URI.parse('http://viget.unfuddle.com/api/v1/projects.json')
30
+ request.endpoint_uri.should == URI.parse('http://viget.unfuddle.com/api/v1/projects.xml')
41
31
  end
42
32
 
43
33
  should "have an endpoint URI with the appropriate format when specified" do
44
34
  Unfuzzle.stubs(:subdomain).with().returns('viget')
45
35
 
46
- request = Unfuzzle::Request.new('/projects', nil, :format => :xml)
36
+ request = Unfuzzle::Request.new('/projects', nil)
47
37
  request.endpoint_uri.should == URI.parse('http://viget.unfuddle.com/api/v1/projects.xml')
48
38
  end
49
39
 
@@ -31,34 +31,6 @@ module Unfuzzle
31
31
  response.error?.should be(true)
32
32
  end
33
33
 
34
- should "be able to parse the response" do
35
- response = Unfuzzle::Response.new(stub())
36
- response.expects(:body).with().returns('json')
37
- response.stubs(:error?).with().returns(false)
38
-
39
- JSON.expects(:parse).with('json').returns('data')
40
-
41
- response.data.should == 'data'
42
- end
43
-
44
- should "cache the parsed data from the response" do
45
- response = Unfuzzle::Response.new(stub())
46
- response.stubs(:body).with().returns('json')
47
- response.stubs(:error?).with().returns(false)
48
-
49
- JSON.stubs(:parse).with('json').once.returns('data')
50
-
51
- 2.times { response.data }
52
- end
53
-
54
- should "return nil when parsing data if there are errors in the response" do
55
- response = Unfuzzle::Response.new(stub())
56
- response.expects(:error?).with().returns(true)
57
-
58
- response.data.should be(nil)
59
-
60
- end
61
-
62
34
  end
63
35
 
64
36
  end
@@ -0,0 +1,36 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ module Unfuzzle
4
+ class SeverityTest < Test::Unit::TestCase
5
+
6
+ context "The Severity class" do
7
+
8
+ should "be able to return a severity for a project and severity id" do
9
+ project_id = 1
10
+ severity_id = 1
11
+
12
+ response = mock_request_cycle :for => "/projects/#{project_id}/severities/#{severity_id}", :data => 'severity'
13
+
14
+ Unfuzzle::Severity.expects(:new).with(response.body).returns('severity')
15
+
16
+ Unfuzzle::Severity.find_by_project_id_and_severity_id(project_id, severity_id).should == 'severity'
17
+ end
18
+
19
+ end
20
+
21
+ context "An instance of the Severity class" do
22
+
23
+ when_populating Severity, :from => 'severity' do
24
+
25
+ value_for :id, :is => 1
26
+ value_for :name, :is => 'Story'
27
+ value_for :project_id, :is => 2
28
+ value_for :created_at, :is => Time.parse('2009-04-02T19:44:49Z')
29
+ value_for :updated_at, :is => Time.parse('2009-04-02T19:44:49Z')
30
+
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
@@ -10,15 +10,9 @@ module Unfuzzle
10
10
 
11
11
  response = mock_request_cycle :for => "/projects/#{project_id}/tickets", :data => 'tickets'
12
12
 
13
- tickets = []
13
+ Unfuzzle::Ticket.expects(:collection_from).with(response.body, 'tickets/ticket').returns(['ticket_1', 'ticket_2'])
14
14
 
15
- response.data.each do |data|
16
- ticket = stub()
17
- Ticket.expects(:new).with(data).returns(ticket)
18
- tickets << ticket
19
- end
20
-
21
- Ticket.find_all_by_project_id(project_id).should == tickets
15
+ Ticket.find_all_by_project_id(project_id).should == ['ticket_1', 'ticket_2']
22
16
  end
23
17
 
24
18
  should "be able to return a list of tickets for a milestone" do
@@ -27,32 +21,29 @@ module Unfuzzle
27
21
 
28
22
  response = mock_request_cycle :for => "/projects/#{project_id}/milestones/#{milestone_id}/tickets", :data => 'tickets'
29
23
 
30
- tickets = []
31
-
32
- response.data.each do |data|
33
- ticket = stub()
34
- Ticket.expects(:new).with(data).returns(ticket)
35
- tickets << ticket
36
- end
37
-
38
- Ticket.find_all_by_project_id_and_milestone_id(project_id, milestone_id).should == tickets
24
+ Unfuzzle::Ticket.expects(:collection_from).with(response.body, 'tickets/ticket').returns(['ticket_1', 'ticket_2'])
25
+
26
+ Ticket.find_all_by_project_id_and_milestone_id(project_id, milestone_id).should == ['ticket_1', 'ticket_2']
39
27
  end
40
28
 
41
29
  end
42
30
 
43
31
  context "An instance of the Ticket class" do
44
32
 
45
- when_populating Ticket, :from => 'tickets' do
33
+ when_populating Ticket, :from => 'ticket' do
46
34
 
47
35
  value_for :id, :is => 1
48
36
  value_for :project_id, :is => 1
49
37
  value_for :milestone_id, :is => 1
50
- value_for :created_timestamp, :is => '2008-11-25T14:00:19Z'
51
- value_for :updated_timestamp, :is => '2008-12-31T15:51:41Z'
52
- value_for :number, :is => 1
38
+ value_for :severity_id, :is => 123
39
+ value_for :priority_id, :is => 3
40
+ value_for :component_id, :is => 1
41
+ value_for :created_at, :is => Time.parse('2008-11-25T14:00:19Z')
42
+ value_for :updated_at, :is => Time.parse('2008-12-31T15:51:41Z')
43
+ value_for :number, :is => '1'
53
44
  value_for :title, :is => 'Ticket #1'
54
45
  value_for :description, :is => 'Do something important'
55
- value_for :due_datestamp, :is => nil
46
+ value_for :due_on, :is => nil
56
47
  value_for :status, :is => 'closed'
57
48
 
58
49
  end
@@ -61,32 +52,13 @@ module Unfuzzle
61
52
  should_set_a_value_for :description
62
53
 
63
54
  context "with a new instance" do
64
- setup { @ticket = Ticket.new({}) }
65
-
66
- should "have a create date/time" do
67
- DateTime.expects(:parse).with('2008-07-28T16:57:10Z').returns('create_date')
68
-
69
- @ticket.stubs(:created_timestamp).with().returns('2008-07-28T16:57:10Z')
70
- @ticket.created_at.should == 'create_date'
71
- end
72
-
73
- should "have an update date/time" do
74
- DateTime.expects(:parse).with('2009-04-28T18:48:52Z').returns('update_date')
75
-
76
- @ticket.stubs(:updated_timestamp).with().returns('2009-04-28T18:48:52Z')
77
- @ticket.updated_at.should == 'update_date'
78
- end
55
+ setup { @ticket = Ticket.new }
79
56
 
80
57
  should "have a due date" do
81
- Date.expects(:parse).with('2008-07-30').returns('due_date')
82
-
83
- @ticket.stubs(:due_datestamp).with().returns('2008-07-30')
84
- @ticket.due_on.should == 'due_date'
85
- end
86
-
87
- should "not have a due date if there isn't one associated" do
88
- @ticket.stubs(:due_datestamp).with().returns(nil)
89
- @ticket.due_on.should be(nil)
58
+ xml = '<ticket><due-on>2009-08-01</due-on></ticket>'
59
+
60
+ ticket = Ticket.new(xml)
61
+ ticket.due_on.should == Date.parse('2009-08-01')
90
62
  end
91
63
 
92
64
  should "have an associated milestone" do
@@ -98,6 +70,95 @@ module Unfuzzle
98
70
  @ticket.milestone.should == 'milestone'
99
71
  end
100
72
 
73
+ should "have an associated severity" do
74
+ project_id = 1
75
+ severity_id = 1
76
+
77
+ Severity.expects(:find_by_project_id_and_severity_id).with(project_id, severity_id).returns('severity')
78
+
79
+ @ticket.stubs(:project_id).with().returns(project_id)
80
+ @ticket.stubs(:severity_id).with().returns(severity_id)
81
+
82
+ @ticket.severity.should == 'severity'
83
+ end
84
+
85
+ should "have no associated severity if it is not set" do
86
+ @ticket.stubs(:severity_id).with().returns(nil)
87
+ @ticket.severity.should be(nil)
88
+ end
89
+
90
+ should "have a severity_name" do
91
+ @ticket.stubs(:severity).with().returns(stub(:name => 'Story'))
92
+ @ticket.severity_name.should == 'Story'
93
+ end
94
+
95
+ should "have no severity_name if there is no severity" do
96
+ @ticket.stubs(:severity).with().returns(nil)
97
+ @ticket.severity_name.should be(nil)
98
+ end
99
+
100
+ should "have an associated priority" do
101
+ Priority.expects(:new).with(1).returns('priority')
102
+
103
+ @ticket.stubs(:priority_id).with().returns(1)
104
+ @ticket.priority.should == 'priority'
105
+ end
106
+
107
+ should "have a priority_name" do
108
+ @ticket.stubs(:priority).with().returns(stub(:name => 'High'))
109
+ @ticket.priority_name.should == 'High'
110
+ end
111
+
112
+ should "have an associated component" do
113
+ project_id = 1
114
+ component_id = 1
115
+
116
+ Component.expects(:find_by_project_id_and_component_id).with(project_id, component_id).returns('component')
117
+
118
+ @ticket.stubs(:project_id).with().returns(project_id)
119
+ @ticket.stubs(:component_id).with().returns(component_id)
120
+
121
+ @ticket.component.should == 'component'
122
+ end
123
+
124
+ should "have no associated component if it is not set" do
125
+ @ticket.stubs(:component_id).with().returns(nil)
126
+ @ticket.component.should be(nil)
127
+ end
128
+
129
+ should "have a component_name" do
130
+ @ticket.stubs(:component).with().returns(stub(:name => 'Admin'))
131
+ @ticket.component_name.should == 'Admin'
132
+ end
133
+
134
+ should "have no component_name if there is no component" do
135
+ @ticket.stubs(:component).with().returns(nil)
136
+ @ticket.component_name.should be(nil)
137
+ end
138
+
139
+ should "be able to generate a hash representation of itself for updating" do
140
+ @ticket.id = 1
141
+ @ticket.project_id = 2
142
+ @ticket.milestone_id = 3
143
+ @ticket.number = '12'
144
+ @ticket.title = 'summary'
145
+ @ticket.description = 'description'
146
+ @ticket.status = 'closed'
147
+
148
+
149
+ expected = {
150
+ 'id' => 1,
151
+ 'project_id' => 2,
152
+ 'milestone_id' => 3,
153
+ 'number' => '12',
154
+ 'summary' => 'summary',
155
+ 'description' => 'description',
156
+ 'status' => 'closed'
157
+ }
158
+
159
+ @ticket.to_hash.should == expected
160
+ end
161
+
101
162
  should "be able to perform an update" do
102
163
  @ticket.stubs(:project_id).with().returns(1)
103
164
  @ticket.stubs(:id).with().returns(2)
@@ -105,7 +166,7 @@ module Unfuzzle
105
166
  resource_path = '/projects/1/tickets/2'
106
167
  ticket_xml = '<ticket />'
107
168
 
108
- @ticket.stubs(:to_xml).with().returns(ticket_xml)
169
+ @ticket.stubs(:to_xml).with('ticket').returns(ticket_xml)
109
170
 
110
171
  Unfuzzle::Request.expects(:put).with(resource_path, ticket_xml).returns('response')
111
172
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vigetlabs-unfuzzle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Reagan
@@ -9,18 +9,18 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-06 00:00:00 -07:00
12
+ date: 2009-07-23 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: json
16
+ name: graft
17
17
  type: :runtime
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.1.6
23
+ version: 0.1.1
24
24
  version:
25
25
  description:
26
26
  email: patrick.reagan@viget.com
@@ -34,28 +34,37 @@ files:
34
34
  - README.rdoc
35
35
  - Rakefile
36
36
  - lib/unfuzzle
37
+ - lib/unfuzzle/component.rb
37
38
  - lib/unfuzzle/milestone.rb
38
- - lib/unfuzzle/model.rb
39
+ - lib/unfuzzle/priority.rb
39
40
  - lib/unfuzzle/project.rb
40
41
  - lib/unfuzzle/request.rb
41
42
  - lib/unfuzzle/response.rb
43
+ - lib/unfuzzle/severity.rb
42
44
  - lib/unfuzzle/ticket.rb
43
45
  - lib/unfuzzle/version.rb
44
46
  - lib/unfuzzle.rb
45
47
  - test/fixtures
46
- - test/fixtures/milestone.json
47
- - test/fixtures/milestones.json
48
- - test/fixtures/project.json
49
- - test/fixtures/projects.json
50
- - test/fixtures/tickets.json
48
+ - test/fixtures/component.xml
49
+ - test/fixtures/components.xml
50
+ - test/fixtures/milestone.xml
51
+ - test/fixtures/milestones.xml
52
+ - test/fixtures/project.xml
53
+ - test/fixtures/projects.xml
54
+ - test/fixtures/severities.xml
55
+ - test/fixtures/severity.xml
56
+ - test/fixtures/ticket.xml
57
+ - test/fixtures/tickets.xml
51
58
  - test/test_helper.rb
52
59
  - test/unit
53
60
  - test/unit/unfuzzle
61
+ - test/unit/unfuzzle/component_test.rb
54
62
  - test/unit/unfuzzle/milestone_test.rb
55
- - test/unit/unfuzzle/model_test.rb
63
+ - test/unit/unfuzzle/priority_test.rb
56
64
  - test/unit/unfuzzle/project_test.rb
57
65
  - test/unit/unfuzzle/request_test.rb
58
66
  - test/unit/unfuzzle/response_test.rb
67
+ - test/unit/unfuzzle/severity_test.rb
59
68
  - test/unit/unfuzzle/ticket_test.rb
60
69
  - test/unit/unfuzzle_test.rb
61
70
  has_rdoc: false
@@ -84,6 +93,6 @@ rubyforge_project:
84
93
  rubygems_version: 1.2.0
85
94
  signing_key:
86
95
  specification_version: 3
87
- summary: This gem provides an interface to the Unfuddle JSON API
96
+ summary: This gem provides an interface to the Unfuddle XML API
88
97
  test_files: []
89
98