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.
- checksums.yaml +4 -4
- data/README.md +6 -5
- data/lib/trello/board.rb +6 -8
- data/lib/trello/card.rb +14 -28
- data/lib/trello/checklist.rb +14 -0
- data/lib/trello/item.rb +4 -0
- data/lib/trello/label.rb +3 -3
- data/lib/trello/list.rb +13 -3
- data/lib/trello/organization.rb +14 -7
- data/spec/action_spec.rb +67 -31
- data/spec/array_spec.rb +1 -1
- data/spec/association_spec.rb +11 -7
- data/spec/basic_auth_policy_spec.rb +4 -4
- data/spec/board_spec.rb +169 -92
- data/spec/card_spec.rb +232 -119
- data/spec/checklist_spec.rb +109 -16
- data/spec/client_spec.rb +83 -45
- data/spec/configuration_spec.rb +24 -43
- data/spec/hash_spec.rb +5 -1
- data/spec/item_spec.rb +27 -9
- data/spec/label_spec.rb +52 -27
- data/spec/list_spec.rb +86 -29
- data/spec/member_spec.rb +62 -40
- data/spec/notification_spec.rb +57 -22
- data/spec/oauth_policy_spec.rb +45 -24
- data/spec/organization_spec.rb +16 -8
- data/spec/spec_helper.rb +28 -3
- data/spec/string_spec.rb +11 -8
- data/spec/token_spec.rb +31 -11
- data/spec/trello_spec.rb +20 -23
- data/spec/webhook_spec.rb +24 -9
- metadata +4 -6
- data/spec/item_state_spec.rb +0 -0
data/spec/array_spec.rb
CHANGED
@@ -5,6 +5,6 @@ describe Array, '#jsoned_into' do
|
|
5
5
|
include Helpers
|
6
6
|
|
7
7
|
it "should convert an array of parsed json into cards" do
|
8
|
-
cards_details.jsoned_into(Trello::Card).
|
8
|
+
expect(cards_details.jsoned_into(Trello::Card)).to eq([cards_details.first.jsoned_into(Trello::Card)])
|
9
9
|
end
|
10
10
|
end
|
data/spec/association_spec.rb
CHANGED
@@ -7,16 +7,20 @@ module Trello
|
|
7
7
|
let(:organization) { client.find(:organization, '4ee7e59ae582acdec8000291') }
|
8
8
|
let(:client) { Client.new(consumer_key: 'xxx') }
|
9
9
|
|
10
|
-
before
|
11
|
-
client
|
12
|
-
|
13
|
-
|
14
|
-
and_return
|
10
|
+
before do
|
11
|
+
allow(client)
|
12
|
+
.to receive(:get)
|
13
|
+
.with('/organizations/4ee7e59ae582acdec8000291', {})
|
14
|
+
.and_return organization_payload
|
15
|
+
|
16
|
+
allow(client)
|
17
|
+
.to receive(:get)
|
18
|
+
.with('/organizations/4ee7e59ae582acdec8000291/boards/all')
|
19
|
+
.and_return boards_payload
|
15
20
|
end
|
16
21
|
|
17
22
|
it 'should set the proper client for all associated boards of the organization' do
|
18
|
-
organization.boards.first.client.consumer_key.
|
23
|
+
expect(organization.boards.first.client.consumer_key).to eq 'xxx'
|
19
24
|
end
|
20
|
-
|
21
25
|
end
|
22
26
|
end
|
@@ -21,8 +21,8 @@ describe BasicAuthPolicy do
|
|
21
21
|
|
22
22
|
the_query_parameters = Addressable::URI.parse(authorized_request.uri).query_values
|
23
23
|
|
24
|
-
the_query_parameters['key'].
|
25
|
-
the_query_parameters['token'].
|
24
|
+
expect(the_query_parameters['key']).to eq 'xxx_developer_public_key_xxx'
|
25
|
+
expect(the_query_parameters['token']).to eq 'xxx_member_token_xxx'
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'preserves other query parameters' do
|
@@ -34,7 +34,7 @@ describe BasicAuthPolicy do
|
|
34
34
|
|
35
35
|
the_query_parameters = Addressable::URI.parse(authorized_request.uri).query_values
|
36
36
|
|
37
|
-
the_query_parameters['name'].
|
37
|
+
expect(the_query_parameters['name']).to eq 'Phil'
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'preserves headers' do
|
@@ -44,7 +44,7 @@ describe BasicAuthPolicy do
|
|
44
44
|
|
45
45
|
authorized_request = BasicAuthPolicy.authorize request
|
46
46
|
|
47
|
-
authorized_request.headers.
|
47
|
+
expect(authorized_request.headers).to eq request.headers
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'does what when a query parameter already exists called key or token?'
|
data/spec/board_spec.rb
CHANGED
@@ -8,169 +8,228 @@ module Trello
|
|
8
8
|
let(:client) { Client.new }
|
9
9
|
let(:member) { Member.new(user_payload) }
|
10
10
|
|
11
|
-
before
|
12
|
-
client
|
13
|
-
|
11
|
+
before do
|
12
|
+
allow(client)
|
13
|
+
.to receive(:get)
|
14
|
+
.with("/boards/abcdef123456789123456789", {})
|
15
|
+
.and_return JSON.generate(boards_details.first)
|
14
16
|
end
|
15
17
|
|
16
18
|
context "finding" do
|
17
19
|
let(:client) { Trello.client }
|
18
20
|
|
19
21
|
it "delegates to client#find" do
|
20
|
-
client
|
22
|
+
expect(client)
|
23
|
+
.to receive(:find)
|
24
|
+
.with(:board, 'abcdef123456789123456789', {})
|
25
|
+
|
21
26
|
Board.find('abcdef123456789123456789')
|
22
27
|
end
|
23
28
|
|
24
29
|
it "is equivalent to client#find" do
|
25
|
-
Board.find('abcdef123456789123456789').
|
30
|
+
expect(Board.find('abcdef123456789123456789')).to eq(board)
|
26
31
|
end
|
27
32
|
end
|
28
33
|
|
29
34
|
context "self.all" do
|
30
35
|
let(:client) { Trello.client }
|
31
36
|
|
32
|
-
|
33
|
-
Member
|
34
|
-
|
37
|
+
before do
|
38
|
+
allow(Member)
|
39
|
+
.to receive_message_chain(:find, :username)
|
40
|
+
.and_return "testuser"
|
41
|
+
|
42
|
+
allow(client)
|
43
|
+
.to receive(:get)
|
44
|
+
.with("/members/testuser/boards")
|
45
|
+
.and_return boards_payload
|
46
|
+
end
|
35
47
|
|
36
|
-
|
37
|
-
Board.all.first.
|
48
|
+
it "gets all boards" do
|
49
|
+
expect(Board.all.first).to eq Board.new(boards_details.first)
|
38
50
|
end
|
39
51
|
end
|
40
52
|
|
41
53
|
context "fields" do
|
42
54
|
it "gets an id" do
|
43
|
-
board.id.
|
55
|
+
expect(board.id).to_not be_nil
|
44
56
|
end
|
45
57
|
|
46
58
|
it "gets a name" do
|
47
|
-
board.name.
|
59
|
+
expect(board.name).to_not be_nil
|
48
60
|
end
|
49
61
|
|
50
62
|
it "gets the description" do
|
51
|
-
board.description.
|
63
|
+
expect(board.description).to_not be_nil
|
52
64
|
end
|
53
65
|
|
54
66
|
it "knows if it is closed or open" do
|
55
|
-
board.
|
67
|
+
expect(board).to_not be_closed
|
56
68
|
end
|
57
|
-
|
69
|
+
|
58
70
|
it "knows if it is starred or not" do
|
59
|
-
board.
|
71
|
+
expect(board).to_not be_starred
|
60
72
|
end
|
61
73
|
|
62
74
|
it "gets its url" do
|
63
|
-
board.url.
|
75
|
+
expect(board.url).to_not be_nil
|
64
76
|
end
|
65
77
|
end
|
66
78
|
|
67
79
|
context "actions" do
|
68
|
-
|
69
|
-
client
|
70
|
-
|
80
|
+
before do
|
81
|
+
allow(client)
|
82
|
+
.to receive(:get)
|
83
|
+
.with("/boards/abcdef123456789123456789/actions", {filter: :all})
|
84
|
+
.and_return actions_payload
|
85
|
+
end
|
71
86
|
|
72
|
-
|
87
|
+
it "has a list of actions" do
|
88
|
+
expect(board.actions.count).to be > 0
|
73
89
|
end
|
74
90
|
end
|
75
91
|
|
76
92
|
context "cards" do
|
77
|
-
|
78
|
-
client
|
79
|
-
|
93
|
+
before do
|
94
|
+
allow(client)
|
95
|
+
.to receive(:get)
|
96
|
+
.with("/boards/abcdef123456789123456789/cards", {filter: :open})
|
97
|
+
.and_return cards_payload
|
98
|
+
end
|
80
99
|
|
81
|
-
|
100
|
+
it "gets its list of cards" do
|
101
|
+
expect(board.cards.count).to be > 0
|
82
102
|
end
|
83
103
|
end
|
84
104
|
|
85
105
|
context "labels" do
|
106
|
+
before do
|
107
|
+
allow(client)
|
108
|
+
.to receive(:get)
|
109
|
+
.with("/boards/abcdef123456789123456789/labels")
|
110
|
+
.and_return label_payload
|
111
|
+
|
112
|
+
allow(client)
|
113
|
+
.to receive(:get)
|
114
|
+
.with("/boards/abcdef123456789123456789/labelnames")
|
115
|
+
.and_return label_name_payload
|
116
|
+
end
|
117
|
+
|
86
118
|
it "gets the specific labels for the board" do
|
87
|
-
client.stub(:get).with("/boards/abcdef123456789123456789/labels").
|
119
|
+
client.stub(:get).with("/boards/abcdef123456789123456789/labels", {}).
|
88
120
|
and_return label_payload
|
89
|
-
labels = board.labels
|
121
|
+
labels = board.labels
|
90
122
|
labels.count.should eq(4)
|
91
123
|
|
92
|
-
|
93
124
|
expect(labels[2].color).to eq('red')
|
94
125
|
expect(labels[2].id).to eq('abcdef123456789123456789')
|
95
126
|
expect(labels[2].board_id).to eq('abcdef123456789123456789')
|
96
127
|
expect(labels[2].name).to eq('deploy')
|
97
128
|
expect(labels[2].uses).to eq(2)
|
98
|
-
|
99
129
|
expect(labels[3].color).to eq('blue')
|
100
130
|
expect(labels[3].id).to eq('abcdef123456789123456789')
|
101
131
|
expect(labels[3].board_id).to eq('abcdef123456789123456789')
|
102
132
|
expect(labels[3].name).to eq('on hold')
|
103
133
|
expect(labels[3].uses).to eq(6)
|
104
134
|
end
|
105
|
-
|
106
|
-
it "gets the specific labels for the board" do
|
107
|
-
client.stub(:get).with("/boards/abcdef123456789123456789/labelnames").
|
108
|
-
and_return label_name_payload
|
109
|
-
|
110
|
-
board.labels.count.should eq(10)
|
111
|
-
end
|
112
135
|
end
|
113
136
|
|
114
137
|
context "find_card" do
|
138
|
+
before do
|
139
|
+
allow(client)
|
140
|
+
.to receive(:get)
|
141
|
+
.with("/boards/abcdef123456789123456789/cards/1")
|
142
|
+
.and_return card_payload
|
143
|
+
end
|
144
|
+
|
115
145
|
it "gets a card" do
|
116
|
-
|
117
|
-
and_return card_payload
|
118
|
-
board.find_card(1).should be_a(Card)
|
146
|
+
expect(board.find_card(1)).to be_a(Card)
|
119
147
|
end
|
120
148
|
end
|
121
149
|
|
122
150
|
context "add_member" do
|
151
|
+
before do
|
152
|
+
allow(client)
|
153
|
+
.to receive(:put)
|
154
|
+
end
|
155
|
+
|
123
156
|
it "adds a member to the board as a normal user (default)" do
|
124
|
-
client
|
157
|
+
expect(client)
|
158
|
+
.to receive(:put)
|
159
|
+
.with("/boards/abcdef123456789123456789/members/id", type: :normal)
|
160
|
+
|
125
161
|
board.add_member(member)
|
126
162
|
end
|
127
163
|
|
128
164
|
it "adds a member to the board as an admin" do
|
129
|
-
client
|
165
|
+
expect(client)
|
166
|
+
.to receive(:put)
|
167
|
+
.with("/boards/abcdef123456789123456789/members/id", type: :admin)
|
168
|
+
|
130
169
|
board.add_member(member, :admin)
|
131
170
|
end
|
132
171
|
end
|
133
172
|
|
134
173
|
context "remove_member" do
|
174
|
+
before do
|
175
|
+
allow(client)
|
176
|
+
.to receive(:delete)
|
177
|
+
end
|
178
|
+
|
135
179
|
it "removes a member from the board" do
|
136
|
-
client
|
180
|
+
expect(client)
|
181
|
+
.to receive(:delete)
|
182
|
+
.with("/boards/abcdef123456789123456789/members/id")
|
183
|
+
|
137
184
|
board.remove_member(member)
|
138
185
|
end
|
139
186
|
end
|
140
187
|
|
141
188
|
context "lists" do
|
142
|
-
|
143
|
-
client
|
144
|
-
|
189
|
+
before do
|
190
|
+
allow(client)
|
191
|
+
.to receive(:get)
|
192
|
+
.with("/boards/abcdef123456789123456789/lists", hash_including(filter: :open))
|
193
|
+
.and_return lists_payload
|
194
|
+
end
|
145
195
|
|
146
|
-
|
196
|
+
it "has a list of lists" do
|
197
|
+
expect(board).to be_has_lists
|
147
198
|
end
|
148
199
|
end
|
149
200
|
|
150
201
|
context "members" do
|
151
|
-
|
152
|
-
client
|
153
|
-
|
202
|
+
before do
|
203
|
+
allow(client)
|
204
|
+
.to receive(:get)
|
205
|
+
.with("/boards/abcdef123456789123456789/members", hash_including(filter: :all))
|
206
|
+
.and_return JSON.generate([user_details])
|
207
|
+
end
|
154
208
|
|
155
|
-
|
209
|
+
it "has a list of members" do
|
210
|
+
expect(board.members.count).to be > 0
|
156
211
|
end
|
157
212
|
end
|
158
213
|
|
159
214
|
context "organization" do
|
160
|
-
|
161
|
-
client
|
162
|
-
|
215
|
+
before do
|
216
|
+
allow(client)
|
217
|
+
.to receive(:get)
|
218
|
+
.with("/organizations/abcdef123456789123456789", {})
|
219
|
+
.and_return JSON.generate(orgs_details.first)
|
220
|
+
end
|
163
221
|
|
164
|
-
|
222
|
+
it "belongs to an organization" do
|
223
|
+
expect(board.organization).to_not be_nil
|
165
224
|
end
|
166
225
|
end
|
167
226
|
|
168
227
|
it "is not closed" do
|
169
|
-
expect(board
|
228
|
+
expect(board).not_to be_closed
|
170
229
|
end
|
171
|
-
|
172
|
-
|
173
|
-
expect(board
|
230
|
+
|
231
|
+
it "is not starred" do
|
232
|
+
expect(board).not_to be_starred
|
174
233
|
end
|
175
234
|
|
176
235
|
describe "#update_fields" do
|
@@ -192,12 +251,12 @@ module Trello
|
|
192
251
|
|
193
252
|
expected.each_pair do |key, value|
|
194
253
|
if board.respond_to?(key)
|
195
|
-
board.send(key).
|
254
|
+
expect(board.send(key)).to eq value
|
196
255
|
end
|
197
256
|
end
|
198
257
|
|
199
|
-
board.description.
|
200
|
-
board.organization_id.
|
258
|
+
expect(board.description).to eq expected['desc']
|
259
|
+
expect(board.organization_id).to eq expected['idOrganization']
|
201
260
|
end
|
202
261
|
|
203
262
|
it "sets any attributes supplied in the fields argument"
|
@@ -210,45 +269,47 @@ module Trello
|
|
210
269
|
JSON.generate(boards_details.first)
|
211
270
|
end
|
212
271
|
|
213
|
-
|
214
|
-
client
|
272
|
+
before do
|
273
|
+
allow(client)
|
274
|
+
.to receive(:put)
|
275
|
+
end
|
215
276
|
|
216
|
-
|
217
|
-
|
277
|
+
it "cannot currently save a new instance" do
|
278
|
+
expect(client).to_not receive(:put)
|
279
|
+
expect {
|
280
|
+
Board.new.save
|
281
|
+
}.to raise_error
|
218
282
|
end
|
219
283
|
|
220
284
|
it "puts all fields except id" do
|
221
285
|
expected_fields = %w{ name description closed starred idOrganization}.map { |s| s.to_sym }
|
222
286
|
|
223
|
-
client.
|
224
|
-
body.keys.
|
287
|
+
expect(client).to receive(:put) do |anything, body|
|
288
|
+
expect(body.keys).to match expected_fields
|
225
289
|
any_board_json
|
226
290
|
end
|
227
291
|
|
228
|
-
|
229
|
-
the_new_board.save
|
292
|
+
Board.new('id' => "xxx").save
|
230
293
|
end
|
231
294
|
|
232
295
|
it "mutates the current instance" do
|
233
|
-
client
|
296
|
+
allow(client)
|
297
|
+
.to receive(:put)
|
298
|
+
.and_return any_board_json
|
234
299
|
|
235
300
|
board = Board.new 'id' => "xxx"
|
236
|
-
|
237
|
-
the_result_of_save = board.save
|
238
|
-
|
239
|
-
the_result_of_save.should equal board
|
301
|
+
expect(board.save).to eq board
|
240
302
|
end
|
241
303
|
|
242
304
|
it "uses the correct resource" do
|
243
305
|
expected_resource_id = "xxx_board_id_xxx"
|
244
306
|
|
245
|
-
client.
|
246
|
-
path.
|
307
|
+
expect(client).to receive(:put) do |path, anything|
|
308
|
+
expect(path).to match(/#{expected_resource_id}\/\z/)
|
247
309
|
any_board_json
|
248
310
|
end
|
249
311
|
|
250
|
-
|
251
|
-
the_new_board.save
|
312
|
+
Board.new('id' => expected_resource_id).save
|
252
313
|
end
|
253
314
|
|
254
315
|
it "saves OR updates depending on whether or not it has an id set"
|
@@ -267,15 +328,18 @@ module Trello
|
|
267
328
|
board.name = "new name"
|
268
329
|
board.description = "new description"
|
269
330
|
board.closed = true
|
270
|
-
board.starred
|
271
|
-
|
272
|
-
client
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
331
|
+
board.starred = true
|
332
|
+
|
333
|
+
expect(client)
|
334
|
+
.to receive(:put)
|
335
|
+
.with("/boards/#{board.id}/", {
|
336
|
+
name: "new name",
|
337
|
+
description: "new description",
|
338
|
+
closed: true,
|
339
|
+
starred: true,
|
340
|
+
idOrganization: nil })
|
341
|
+
.and_return any_board_json
|
342
|
+
|
279
343
|
board.update!
|
280
344
|
end
|
281
345
|
end
|
@@ -289,26 +353,39 @@ module Trello
|
|
289
353
|
JSON.generate(boards_details.first)
|
290
354
|
end
|
291
355
|
|
356
|
+
before do
|
357
|
+
allow(client)
|
358
|
+
.to receive(:post)
|
359
|
+
end
|
360
|
+
|
292
361
|
it "creates a new board with whatever attributes are supplied " do
|
293
362
|
expected_attributes = { name: "Any new board name", description: "Any new board desription" }
|
294
363
|
sent_attributes = { name: expected_attributes[:name], desc: expected_attributes[:description] }
|
295
364
|
|
296
|
-
client
|
365
|
+
expect(client)
|
366
|
+
.to receive(:post)
|
367
|
+
.with("/boards", sent_attributes)
|
368
|
+
.and_return any_board_json
|
297
369
|
|
298
370
|
Board.create expected_attributes
|
299
371
|
end
|
300
372
|
|
301
373
|
it "posts to the boards collection" do
|
302
|
-
client
|
374
|
+
expect(client)
|
375
|
+
.to receive(:post)
|
376
|
+
.with("/boards", anything)
|
377
|
+
.and_return any_board_json
|
303
378
|
|
304
379
|
Board.create xxx: ""
|
305
380
|
end
|
306
381
|
|
307
382
|
it "returns a board" do
|
308
|
-
client
|
383
|
+
allow(client)
|
384
|
+
.to receive(:post)
|
385
|
+
.with("/boards", anything)
|
386
|
+
.and_return any_board_json
|
309
387
|
|
310
|
-
|
311
|
-
the_new_board.should be_a Board
|
388
|
+
expect(Board.create(xxx: "")).to be_a Board
|
312
389
|
end
|
313
390
|
|
314
391
|
it "at least name is required"
|