forked from jsmestad/pivotal-tracker
/
story_spec.rb
239 lines (193 loc) · 8.52 KB
/
story_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
require 'spec_helper'
describe PivotalTracker::Story do
before do
@project = PivotalTracker::Project.find(102622)
end
context ".all" do
it "should return all stories" do
@project.stories.all.should be_a(Array)
@project.stories.all.first.should be_a(PivotalTracker::Story)
end
it "should allow filtering" do
@project.stories.all(:story_type => ['bug']).should be_a(Array)
@project.stories.all(:story_type => ['feature']).should be_a(Array)
end
it "should cache stories" do
count = @project.stories.all.count
@project.stories.all.count.should == count
bugs_count = @project.stories.all(:story_type => ['bug']).count
bugs_count.should_not == count
@project.stories.all(:story_type => ['bug']).count.should == bugs_count
end
end
context ".find" do
it "should return the matching story" do
@project.stories.find(4459994).should be_a(PivotalTracker::Story)
end
end
context ".create" do
it "should return the created story" do
@project.stories.create(:name => 'Create Stuff').should be_a(PivotalTracker::Story)
end
context "on failure" do
before do
FakeWeb.register_uri(:post, "#{PivotalTracker::Client.api_url}/projects/#{@project.id}/stories",
:body => %{<?xml version="1.0" encoding="UTF-8"?>
<errors>
<error>error#1 message</error>
<error>error#2 message</error>
</errors>%},
:status => "422")
end
it "should not raise an exception" do
expect { @project.stories.create }.to_not raise_error(Exception)
end
it "should report errors encountered" do
story = @project.stories.create :name => "Invalid story"
story.errors.messages.should =~ ["error#1 message", "error#2 message"]
end
end
end
context ".attachments" do
it "should return an array of attachments" do
@story = @project.stories.find(4460598)
@story.attachments.should be_a(Array)
@story.attachments.first.should be_a(PivotalTracker::Attachment)
end
end
context ".move" do
let(:project_id) { @project.id }
let(:top_story_id) {4460598}
let(:bottom_story_id) {4459994}
let(:top_story) { @project.stories.find(top_story_id) }
let(:bottom_story) { @project.stories.find(bottom_story_id) }
it "should return the moved story when moved before" do
expected_uri = "#{PivotalTracker::Client.api_url}/projects/#{project_id}/stories/#{top_story_id}/moves?move\[move\]=before&move\[target\]=#{bottom_story_id}"
FakeWeb.register_uri(:post, expected_uri, :body => %{<story><id type="integer">#{top_story_id}</id></story>})
@moved_story = top_story.move(:before, bottom_story)
@moved_story.should be_a(PivotalTracker::Story)
@moved_story.id.should be(top_story_id)
end
it "should return the moved story when moved after" do
expected_uri = "#{PivotalTracker::Client.api_url}/projects/#{project_id}/stories/#{bottom_story_id}/moves?move\[move\]=after&move\[target\]=#{top_story_id}"
FakeWeb.register_uri(:post, expected_uri, :body => %{<story><id type="integer">#{bottom_story_id}</id></story>})
@moved_story = bottom_story.move(:after, top_story)
@moved_story.should be_a(PivotalTracker::Story)
@moved_story.id.should be(bottom_story_id)
end
it "should raise an error when trying to move in an invalid position" do
expect { top_story.move(:next_to, bottom_story) }.to raise_error(ArgumentError)
end
end
context ".move_to_project" do
let(:expected_uri) {"#{PivotalTracker::Client.api_url}/projects/#{project_id}/stories/#{story_id}"}
let(:project_id) { @project.id }
let(:movable_story) { @project.stories.find(4459994) }
let(:story_id) { movable_story.id }
let(:target_project) { PivotalTracker::Project.new(:id => 103014) }
before do
FakeWeb.register_uri(:put, expected_uri, :body => %{<?xml version="1.0" encoding="UTF-8"?>
<story>
<project_id type="integer">#{target_project.id}</project_id>
</story>})
end
it "should return an updated story from the target project when passed a PivotalTracker::Story" do
target_story = PivotalTracker::Story.new(:project_id => target_project.id)
response = movable_story.move_to_project(target_story)
response.should_not be_nil
response.project_id.should == target_story.project_id
end
it "should return an updated story from the target project when passed a PivotalTracker::Project" do
response = movable_story.move_to_project(target_project)
response.project_id.should == target_project.id
end
it "should return an updated story from the target project when passed a String" do
response = movable_story.move_to_project(target_project.id.to_s)
response.project_id.should == target_project.id
end
it "should return an updated story from the target project when passed an Integer"do
response = movable_story.move_to_project(target_project.id.to_i)
response.project_id.should == target_project.id
end
end
context ".new" do
def story_for(attrs)
story = @project.stories.new(attrs)
@story = Hash.from_xml(story.send(:to_xml))['story']
end
describe "attributes that are not sent to the tracker" do
it "should include id" do
story_for(:id => 10)["id"].should be_nil
end
it "should include url" do
story_for(:url => "somewhere")["url"].should be_nil
end
end
describe "attributes that are sent to the tracker" do
it "should include name" do
story_for(:name => "A user should...")["name"].should == "A user should..."
end
it "should include description" do
story_for(:description => "desc...")["description"].should == "desc..."
end
it "should include story_type" do
story_for(:story_type => "feature")["story_type"].should == "feature"
end
it "should include estimate" do
story_for(:estimate => 5)["estimate"].should == "5"
end
it "should include current_state" do
story_for(:current_state => "accepted")["current_state"].should == "accepted"
end
it "should include requested_by" do
story_for(:requested_by => "Joe Doe")["requested_by"].should == "Joe Doe"
end
it "should include owned_by" do
story_for(:owned_by => "Joe Doe")["owned_by"].should == "Joe Doe"
end
it "should include labels" do
story_for(:labels => "abc")["labels"].should == "abc"
end
it "should include other_id" do
it "when passed a string" do
story_for(:other_id => "10")["other_id"].should == "10"
end
it "when passed an integer" do
story_for(:other_id => 10)["other_id"].should == "10"
end
end
it "should include integration_id" do
story_for(:integration_id => 1000)["integration_id"].should == '1000'
end
# the tracker returns 422 when this is included, even if it is not used
# it "should include jira_id" do
# story_for(:jira_id => 10)["jira_id"].should == "10"
# end
#
# it "should include jira_url" do
# story_for(:jira_url => "somewhere")["jira_url"].should == "somewhere"
# end
context "date attributes" do
before do
@datestring = "1984-09-20T10:23:00+00:00"
@date = DateTime.new(1984, 9, 20, 10, 23, 0, 0)
end
[:created_at, :accepted_at].each do |date_attribute|
it "should include #{date_attribute} date when given a string" do
story_for(:created_at => @date.to_s)["created_at"].should == @datestring
end
it "should include #{date_attribute} date when given a Time" do
story_for(:created_at => Time.parse(@date.to_s).utc)["created_at"].should == @datestring
end
it "should include #{date_attribute} date when given a DateTime" do
story_for(:created_at => @date)["created_at"].should == @datestring
end
it "should include #{date_attribute} date when given a Date" do
# Dates don't have time zones, but the time will be in local time, so we convert the date to create the expectation
story_for(:created_at => Date.new(1984, 9, 20))["created_at"].should == DateTime.new(1984, 9, 20).to_s
end
end
end
end
end
end