ruby-trello 1.2.1 → 1.3.0

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/spec/card_spec.rb CHANGED
@@ -4,24 +4,34 @@ module Trello
4
4
  describe Card do
5
5
  include Helpers
6
6
 
7
- let(:card) { client.find(:card, 'abcdef123456789123456789') }
7
+ let(:card) { client.find(:card, 'abcdef123456789123456789') }
8
8
  let(:client) { Client.new }
9
9
 
10
- before(:each) do
11
- client.stub(:get).with("/cards/abcdef123456789123456789", {}).
12
- and_return JSON.generate(cards_details.first)
10
+ before do
11
+ allow(client)
12
+ .to receive(:get)
13
+ .with("/cards/abcdef123456789123456789", {})
14
+ .and_return JSON.generate(cards_details.first)
13
15
  end
14
16
 
15
17
  context "finding" do
16
18
  let(:client) { Trello.client }
17
19
 
20
+ before do
21
+ allow(client)
22
+ .to receive(:find)
23
+ end
24
+
18
25
  it "delegates to Trello.client#find" do
19
- client.should_receive(:find).with(:card, 'abcdef123456789123456789', {})
26
+ expect(client)
27
+ .to receive(:find)
28
+ .with(:card, 'abcdef123456789123456789', {})
29
+
20
30
  Card.find('abcdef123456789123456789')
21
31
  end
22
32
 
23
33
  it "is equivalent to client#find" do
24
- Card.find('abcdef123456789123456789').should eq(card)
34
+ expect(Card.find('abcdef123456789123456789')).to eq(card)
25
35
  end
26
36
  end
27
37
 
@@ -30,17 +40,17 @@ module Trello
30
40
 
31
41
  it "creates a new record" do
32
42
  card = Card.new(cards_details.first)
33
- card.should be_valid
43
+ expect(card).to be_valid
34
44
  end
35
45
 
36
46
  it 'must not be valid if not given a name' do
37
47
  card = Card.new('idList' => lists_details.first['id'])
38
- card.should_not be_valid
48
+ expect(card).to_not be_valid
39
49
  end
40
50
 
41
51
  it 'must not be valid if not given a list id' do
42
52
  card = Card.new('name' => lists_details.first['name'])
43
- card.should_not be_valid
53
+ expect(card).to_not be_valid
44
54
  end
45
55
 
46
56
  it 'creates a new record and saves it on Trello', refactor: true do
@@ -52,13 +62,16 @@ module Trello
52
62
  result = JSON.generate(cards_details.first.merge(payload.merge(idList: lists_details.first['id'])))
53
63
 
54
64
  expected_payload = {name: "Test Card", desc: nil, idList: "abcdef123456789123456789",
55
- idMembers: nil, labels: nil, pos: nil }
65
+ idMembers: nil, labels: nil, pos: nil, due: nil}
56
66
 
57
- client.should_receive(:post).with("/cards", expected_payload).and_return result
67
+ expect(client)
68
+ .to receive(:post)
69
+ .with("/cards", expected_payload)
70
+ .and_return result
58
71
 
59
72
  card = Card.create(cards_details.first.merge(payload.merge(list_id: lists_details.first['id'])))
60
73
 
61
- card.class.should be Card
74
+ expect(card).to be_a Card
62
75
  end
63
76
  end
64
77
 
@@ -70,133 +83,197 @@ module Trello
70
83
  name: expected_new_name,
71
84
  }
72
85
 
73
- client.should_receive(:put).once.with("/cards/abcdef123456789123456789", payload)
86
+ expect(client)
87
+ .to receive(:put)
88
+ .once
89
+ .with("/cards/abcdef123456789123456789", payload)
74
90
 
75
91
  card.name = expected_new_name
76
92
  card.save
77
93
  end
94
+
95
+ it "updating desc does a put on the correct resource with the correct value" do
96
+ expected_new_desc = "xxx"
97
+
98
+ payload = {
99
+ desc: expected_new_desc,
100
+ }
101
+
102
+ client.should_receive(:put).once.with("/cards/abcdef123456789123456789", payload)
103
+
104
+ card.desc = expected_new_desc
105
+ card.save
106
+ end
78
107
  end
79
108
 
80
109
  context "deleting" do
81
110
  it "deletes the card" do
82
- client.should_receive(:delete).with("/cards/#{card.id}")
111
+ expect(client)
112
+ .to receive(:delete)
113
+ .with("/cards/#{card.id}")
114
+
83
115
  card.delete
84
116
  end
85
117
  end
86
118
 
87
119
  context "fields" do
88
120
  it "gets its id" do
89
- card.id.should_not be_nil
121
+ expect(card.id).to_not be_nil
90
122
  end
91
123
 
92
124
  it "gets its short id" do
93
- card.short_id.should_not be_nil
125
+ expect(card.short_id).to_not be_nil
94
126
  end
95
127
 
96
128
  it "gets its name" do
97
- card.name.should_not be_nil
129
+ expect(card.name).to_not be_nil
98
130
  end
99
131
 
100
132
  it "gets its description" do
101
- card.desc.should_not be_nil
133
+ expect(card.desc).to_not be_nil
102
134
  end
103
135
 
104
136
  it "knows if it is open or closed" do
105
- card.closed.should_not be_nil
137
+ expect(card.closed).to_not be_nil
106
138
  end
107
139
 
108
140
  it "gets its url" do
109
- card.url.should_not be_nil
141
+ expect(card.url).to_not be_nil
110
142
  end
111
143
 
112
144
  it "gets its short url" do
113
- card.short_url.should_not be_nil
145
+ expect(card.short_url).to_not be_nil
114
146
  end
115
147
 
116
148
  it "gets its last active date" do
117
- card.last_activity_date.should_not be_nil
149
+ expect(card.last_activity_date).to_not be_nil
118
150
  end
119
151
 
120
152
  it "gets its cover image id" do
121
- card.cover_image_id.should_not be_nil
153
+ expect(card.cover_image_id).to_not be_nil
122
154
  end
123
155
 
124
156
  it "gets its pos" do
125
- card.pos.should_not be_nil
157
+ expect(card.pos).to_not be_nil
126
158
  end
127
159
  end
128
160
 
129
161
  context "actions" do
162
+ let(:filter) { :all }
163
+
164
+ before do
165
+ allow(client)
166
+ .to receive(:get)
167
+ .with("/cards/abcdef123456789123456789/actions", { filter: filter })
168
+ .and_return actions_payload
169
+ end
170
+
130
171
  it "asks for all actions by default" do
131
- client.stub(:get).with("/cards/abcdef123456789123456789/actions", { filter: :all }).and_return actions_payload
132
- card.actions.count.should be > 0
172
+ expect(card.actions.count).to be > 0
133
173
  end
134
174
 
135
- it "allows overriding the filter" do
136
- client.stub(:get).with("/cards/abcdef123456789123456789/actions", { filter: :updateCard }).and_return actions_payload
137
- card.actions(filter: :updateCard).count.should be > 0
175
+ context 'when overriding a filter' do
176
+ let(:filter) { :updateCard }
177
+
178
+ it "allows the filter" do
179
+ expect(card.actions(filter: filter).count).to be > 0
180
+ end
138
181
  end
139
182
  end
140
183
 
141
184
  context "boards" do
185
+ before do
186
+ allow(client)
187
+ .to receive(:get)
188
+ .with("/boards/abcdef123456789123456789", {})
189
+ .and_return JSON.generate(boards_details.first)
190
+ end
191
+
142
192
  it "has a board" do
143
- client.stub(:get).with("/boards/abcdef123456789123456789", {}).and_return JSON.generate(boards_details.first)
144
- card.board.should_not be_nil
193
+ expect(card.board).to_not be_nil
145
194
  end
146
195
  end
147
196
 
148
197
  context "cover image" do
198
+ before do
199
+ allow(client)
200
+ .to receive(:get)
201
+ .with("/attachments/abcdef123456789123456789", {})
202
+ .and_return JSON.generate(attachments_details.first)
203
+ end
204
+
149
205
  it "has a cover image" do
150
- client.stub(:get).with("/attachments/abcdef123456789123456789", {}).and_return JSON.generate(attachments_details.first)
151
- card.cover_image.should_not be_nil
206
+ expect(card.cover_image).to_not be_nil
152
207
  end
153
208
  end
154
209
 
155
210
  context "checklists" do
156
- before(:each) do
157
- client.stub(:get).with("/cards/abcdef123456789123456789/checklists", { filter: :all }).and_return checklists_payload
211
+ before do
212
+ allow(client)
213
+ .to receive(:get)
214
+ .with("/cards/abcdef123456789123456789/checklists", { filter: :all})
215
+ .and_return checklists_payload
158
216
  end
159
217
 
160
218
  it "has a list of checklists" do
161
- card.checklists.count.should be > 0
219
+ expect(card.checklists.count).to be > 0
162
220
  end
163
221
 
164
222
  it "creates a new checklist for the card" do
165
- client.should_receive(:post).with("/cards/abcdef123456789123456789/checklists", name: "new checklist")
223
+ expect(client)
224
+ .to receive(:post)
225
+ .with("/cards/abcdef123456789123456789/checklists", name: "new checklist")
226
+
166
227
  card.create_new_checklist("new checklist")
167
228
  end
168
229
  end
169
230
 
170
231
  context "list" do
232
+ before do
233
+ allow(client)
234
+ .to receive(:get)
235
+ .with("/lists/abcdef123456789123456789", {})
236
+ .and_return JSON.generate(lists_details.first)
237
+ end
171
238
  it 'has a list' do
172
- client.stub(:get).with("/lists/abcdef123456789123456789", {}).and_return JSON.generate(lists_details.first)
173
- card.list.should_not be_nil
239
+ expect(card.list).to_not be_nil
174
240
  end
175
241
 
176
242
  it 'can be moved to another list' do
177
243
  other_list = double(id: '987654321987654321fedcba')
178
244
  payload = {value: other_list.id}
179
- client.should_receive(:put).with("/cards/abcdef123456789123456789/idList", payload)
245
+
246
+ expect(client)
247
+ .to receive(:put)
248
+ .with("/cards/abcdef123456789123456789/idList", payload)
249
+
180
250
  card.move_to_list(other_list)
181
251
  end
182
252
 
183
253
  it 'should not be moved if new list is identical to old list' do
184
254
  other_list = double(id: 'abcdef123456789123456789')
185
- payload = { value: other_list.id }
186
- client.should_not_receive(:put)
255
+ expect(client).to_not receive(:put)
187
256
  card.move_to_list(other_list)
188
257
  end
189
258
 
190
259
  it "should accept a string for moving a card to list" do
191
260
  payload = { value: "12345678"}
192
- client.should_receive(:put).with("/cards/abcdef123456789123456789/idList", payload)
261
+
262
+ expect(client)
263
+ .to receive(:put)
264
+ .with("/cards/abcdef123456789123456789/idList", payload)
265
+
193
266
  card.move_to_list("12345678")
194
267
  end
195
268
 
196
269
  it 'can be moved to another board' do
197
270
  other_board = double(id: '987654321987654321fedcba')
198
271
  payload = {value: other_board.id}
199
- client.should_receive(:put).with("/cards/abcdef123456789123456789/idBoard", payload)
272
+
273
+ expect(client)
274
+ .to receive(:put)
275
+ .with("/cards/abcdef123456789123456789/idBoard", payload)
276
+
200
277
  card.move_to_board(other_board)
201
278
  end
202
279
 
@@ -204,24 +281,37 @@ module Trello
204
281
  other_board = double(id: '987654321987654321fedcba')
205
282
  other_list = double(id: '987654321987654321aalist')
206
283
  payload = {value: other_board.id, idList: other_list.id}
207
- client.should_receive(:put).with("/cards/abcdef123456789123456789/idBoard", payload)
284
+
285
+ expect(client)
286
+ .to receive(:put)
287
+ .with("/cards/abcdef123456789123456789/idBoard", payload)
288
+
208
289
  card.move_to_board(other_board, other_list)
209
290
  end
210
291
 
211
292
  it 'should not be moved if new board is identical with old board', focus: true do
212
293
  other_board = double(id: 'abcdef123456789123456789')
213
- client.should_not_receive(:put)
294
+ expect(client).to_not receive(:put)
214
295
  card.move_to_board(other_board)
215
296
  end
216
297
  end
217
298
 
218
299
  context "members" do
219
- it "has a list of members" do
220
- client.stub(:get).with("/boards/abcdef123456789123456789", {}).and_return JSON.generate(boards_details.first)
221
- client.stub(:get).with("/members/abcdef123456789123456789").and_return user_payload
300
+ before do
301
+ allow(client)
302
+ .to receive(:get)
303
+ .with("/boards/abcdef123456789123456789", {})
304
+ .and_return JSON.generate(boards_details.first)
222
305
 
223
- card.board.should_not be_nil
224
- card.members.should_not be_nil
306
+ allow(client)
307
+ .to receive(:get)
308
+ .with("/members/abcdef123456789123456789")
309
+ .and_return user_payload
310
+ end
311
+
312
+ it "has a list of members" do
313
+ expect(card.board).to_not be_nil
314
+ expect(card.members).to_not be_nil
225
315
  end
226
316
 
227
317
  it "allows a member to be added to a card" do
@@ -229,40 +319,63 @@ module Trello
229
319
  payload = {
230
320
  value: new_member.id
231
321
  }
232
- client.should_receive(:post).with("/cards/abcdef123456789123456789/members", payload)
322
+
323
+ expect(client)
324
+ .to receive(:post)
325
+ .with("/cards/abcdef123456789123456789/members", payload)
326
+
233
327
  card.add_member(new_member)
234
328
  end
235
329
 
236
330
  it "allows a member to be removed from a card" do
237
331
  existing_member = double(id: '4ee7df3ce582acdec80000b2')
238
- client.should_receive(:delete).with("/cards/abcdef123456789123456789/members/#{existing_member.id}")
332
+
333
+ expect(client)
334
+ .to receive(:delete)
335
+ .with("/cards/abcdef123456789123456789/members/#{existing_member.id}")
336
+
239
337
  card.remove_member(existing_member)
240
338
  end
241
339
  end
242
340
 
243
341
  context "comments" do
244
342
  it "posts a comment" do
245
- client.should_receive(:post).
246
- with("/cards/abcdef123456789123456789/actions/comments", { text: 'testing' }).
247
- and_return JSON.generate(boards_details.first)
343
+ expect(client)
344
+ .to receive(:post)
345
+ .with("/cards/abcdef123456789123456789/actions/comments", { text: 'testing' })
346
+ .and_return JSON.generate(boards_details.first)
248
347
 
249
348
  card.add_comment "testing"
250
349
  end
251
350
  end
252
351
 
253
352
  context "labels" do
353
+ before do
354
+ allow(client)
355
+ .to receive(:get)
356
+ .with("/cards/abcdef123456789123456789/labels")
357
+ .and_return label_payload
358
+
359
+ allow(client)
360
+ .to receive(:post)
361
+ .with("/cards/abcdef123456789123456789/labels", { value: 'green' })
362
+ .and_return "not important"
363
+
364
+ allow(client)
365
+ .to receive(:delete)
366
+ .with("/cards/abcdef123456789123456789/labels/green")
367
+ .and_return "not important"
368
+ end
254
369
  it "can retrieve labels" do
255
- client.stub(:get).with("/cards/abcdef123456789123456789/labels").
370
+ client.stub(:get).with("/cards/abcdef123456789123456789/labels", {}).
256
371
  and_return label_payload
257
372
  labels = card.labels
258
373
  expect(labels.size).to eq(4)
259
-
260
374
  expect(labels[0].color).to eq('yellow')
261
375
  expect(labels[0].id).to eq('abcdef123456789123456789')
262
376
  expect(labels[0].board_id).to eq('abcdef123456789123456789')
263
377
  expect(labels[0].name).to eq('iOS')
264
378
  expect(labels[0].uses).to eq(3)
265
-
266
379
  expect(labels[1].color).to eq('purple')
267
380
  expect(labels[1].id).to eq('abcdef123456789123456789')
268
381
  expect(labels[1].board_id).to eq('abcdef123456789123456789')
@@ -270,120 +383,120 @@ module Trello
270
383
  expect(labels[1].uses).to eq(1)
271
384
  end
272
385
 
273
- it "can add a label" do
274
- client.stub(:post).with("/cards/abcdef123456789123456789/labels", { value: 'green' }).
275
- and_return "not important"
276
- card.add_label('green')
277
- expect(card.errors).to be_empty
278
- end
279
-
280
386
  it "can remove a label" do
281
- client.stub(:delete).with("/cards/abcdef123456789123456789/labels/green").
282
- and_return "not important"
283
- card.remove_label('green')
284
- expect(card.errors).to be_empty
285
- end
286
-
287
- it "can remove a label instance" do
288
387
  client.should_receive(:delete).once.with("/cards/abcdef123456789123456789/idLabels/abcdef123456789123456789")
289
388
  label = Label.new(label_details.first)
290
389
  card.remove_label(label)
291
390
  end
292
391
 
293
- it "can add a label of any valid color" do
294
- %w(green yellow orange red purple blue sky lime pink black).each do |color|
295
- client.stub(:post).with("/cards/abcdef123456789123456789/labels", { :value => color }).
296
- and_return "not important"
297
- card.add_label(color)
298
- expect(card.errors).to be_empty
299
- end
300
- end
301
-
302
- it "can add a label instance" do
392
+ it "can add a label" do
303
393
  client.should_receive(:post).once.with("/cards/abcdef123456789123456789/idLabels", {:value => "abcdef123456789123456789"})
304
394
  label = Label.new(label_details.first)
305
395
  card.add_label label
306
396
  end
307
397
 
308
- it "throws an error when trying to add a label with an unknown colour" do
309
- client.stub(:post).with("/cards/abcdef123456789123456789/labels", { value: 'green' }).
398
+ it "throws an error when trying to add a invalid label" do
399
+ client.stub(:post).with("/cards/abcdef123456789123456789/idLabels", { value: 'abcdef123456789123456789' }).
310
400
  and_return "not important"
311
- card.add_label('mauve')
312
- expect(card.errors.full_messages.to_sentence).to eq("Label colour 'mauve' does not exist")
401
+ label = Label.new(label_details.first)
402
+ label.name = nil
403
+ card.add_label(label)
404
+ expect(card.errors.full_messages.to_sentence).to eq("Label is not valid.")
313
405
  end
314
406
 
315
- it "throws an error when trying to remove a label with an unknown colour" do
316
- client.stub(:delete).with("/cards/abcdef123456789123456789/labels/mauve").
407
+ it "throws an error when trying to remove a invalid label" do
408
+ client.stub(:delete).with("/cards/abcdef123456789123456789/idLabels/abcdef123456789123456789").
317
409
  and_return "not important"
318
- card.remove_label('mauve')
319
- expect(card.errors.full_messages.to_sentence).to eq("Label colour 'mauve' does not exist")
410
+ label = Label.new(label_details.first)
411
+ label.name = nil
412
+ card.remove_label(label)
413
+ expect(card.errors.full_messages.to_sentence).to eq("Label is not valid.")
320
414
  end
321
415
  end
322
416
 
323
417
  context "attachments" do
324
418
  it "can add an attachment" do
325
419
  f = File.new('spec/list_spec.rb', 'r')
326
- client.stub(:get).with("/cards/abcdef123456789123456789/attachments").and_return attachments_payload
327
- client.stub(:post).with("/cards/abcdef123456789123456789/attachments",
328
- { file: f, name: '' }).
329
- and_return "not important"
420
+ allow(client)
421
+ .to receive(:get)
422
+ .with("/cards/abcdef123456789123456789/attachments")
423
+ .and_return attachments_payload
424
+
425
+ allow(client)
426
+ .to receive(:post)
427
+ .with("/cards/abcdef123456789123456789/attachments", { file: f, name: '' })
428
+ .and_return "not important"
330
429
 
331
430
  card.add_attachment(f)
332
431
 
333
- card.errors.should be_empty
432
+ expect(card.errors).to be_empty
334
433
  end
335
434
 
336
435
  it "can list the existing attachments with correct fields" do
337
- client.stub(:get).with("/boards/abcdef123456789123456789", {}).and_return JSON.generate(boards_details.first)
338
- client.stub(:get).with("/cards/abcdef123456789123456789/attachments").and_return attachments_payload
436
+ allow(client)
437
+ .to receive(:get)
438
+ .with("/boards/abcdef123456789123456789", {})
439
+ .and_return JSON.generate(boards_details.first)
440
+
441
+ allow(client)
442
+ .to receive(:get)
443
+ .with("/cards/abcdef123456789123456789/attachments")
444
+ .and_return attachments_payload
445
+
446
+ expect(card.board).to_not be_nil
447
+ expect(card.attachments).to_not be_nil
339
448
 
340
- card.board.should_not be_nil
341
- card.attachments.should_not be_nil
342
449
  first_attachment = card.attachments.first
343
- first_attachment.id.should == attachments_details[0]["id"]
344
- first_attachment.name.should == attachments_details[0]["name"]
345
- first_attachment.url.should == attachments_details[0]["url"]
346
- first_attachment.bytes.should == attachments_details[0]["bytes"]
347
- first_attachment.member_id.should == attachments_details[0]["idMember"]
348
- first_attachment.date.should == Time.parse(attachments_details[0]["date"])
349
- first_attachment.is_upload.should == attachments_details[0]["isUpload"]
350
- first_attachment.mime_type.should == attachments_details[0]["mimeType"]
450
+ expect(first_attachment.id).to eq attachments_details[0]["id"]
451
+ expect(first_attachment.name).to eq attachments_details[0]["name"]
452
+ expect(first_attachment.url).to eq attachments_details[0]["url"]
453
+ expect(first_attachment.bytes).to eq attachments_details[0]["bytes"]
454
+ expect(first_attachment.member_id).to eq attachments_details[0]["idMember"]
455
+ expect(first_attachment.date).to eq Time.parse(attachments_details[0]["date"])
456
+ expect(first_attachment.is_upload).to eq attachments_details[0]["isUpload"]
457
+ expect(first_attachment.mime_type).to eq attachments_details[0]["mimeType"]
351
458
  end
352
459
 
353
460
  it "can remove an attachment" do
354
- client.stub(:delete).with("/cards/abcdef123456789123456789/attachments/abcdef123456789123456789").
355
- and_return "not important"
356
- client.stub(:get).with("/cards/abcdef123456789123456789/attachments").and_return attachments_payload
461
+ allow(client)
462
+ .to receive(:delete)
463
+ .with("/cards/abcdef123456789123456789/attachments/abcdef123456789123456789")
464
+ .and_return "not important"
465
+
466
+ allow(client)
467
+ .to receive(:get)
468
+ .with("/cards/abcdef123456789123456789/attachments")
469
+ .and_return attachments_payload
357
470
 
358
471
  card.remove_attachment(card.attachments.first)
359
- card.errors.should be_empty
472
+ expect(card.errors).to be_empty
360
473
  end
361
474
  end
362
475
 
363
476
  describe "#closed?" do
364
477
  it "returns the closed attribute" do
365
- expect(card.closed?).to be(false)
478
+ expect(card).to_not be_closed
366
479
  end
367
480
  end
368
481
 
369
482
  describe "#close" do
370
483
  it "updates the close attribute to true" do
371
484
  card.close
372
- expect(card.closed).to be(true)
485
+ expect(card).to be_closed
373
486
  end
374
487
  end
375
488
 
376
489
  describe "#close!" do
377
490
  it "updates the close attribute to true and saves the list" do
378
- payload = {
379
- closed: true,
380
- }
491
+ payload = { closed: true }
381
492
 
382
- client.should_receive(:put).once.with("/cards/abcdef123456789123456789", payload)
493
+ expect(client)
494
+ .to receive(:put)
495
+ .once
496
+ .with("/cards/abcdef123456789123456789", payload)
383
497
 
384
498
  card.close!
385
499
  end
386
500
  end
387
-
388
501
  end
389
502
  end