reviewlette 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,366 +2,70 @@ require 'spec_helper'
2
2
 
3
3
  describe Reviewlette do
4
4
 
5
- # set instance variable from local variable
6
- def instance_variable!(variable_name)
7
- Reviewlette.instance_variable_set("@#{variable_name}", send(variable_name.to_sym))
8
- end
9
-
10
- let(:number) { 23 }
11
- let(:title) { 'title' }
12
- let(:body) { 'body' }
13
- let(:githubname) { 'gitty' }
14
- let(:trelloname) { 'jschmid' }
15
- let(:github_stub) { github_stub }
16
- let(:board) { stub_boards_call }
17
- let(:repo) { 'repo/repo' }
18
- let(:id) { 23 }
19
- let(:card) { stub_card_call }
20
- let(:logger) { double 'logger' }
21
- let(:repos) { %w[repo/repo, repos/repos] }
22
- let(:trello_connection) { double 'trello_connection' }
23
- let(:reviewer) {double 'reviewer'}
24
- let(:db) {Reviewlette::Database.new}
25
- let(:github_connection) { double 'github_connection' }
26
- let(:full_comment) { @full_comment = "@#{trelloname} will review https://github.com/#{repo}/issues/#{number.to_s}" }
27
- let(:exp) { AlreadyAssignedException }
28
-
29
- describe '.spin' do
30
- before do
31
- instance_variable! :github_connection
32
- instance_variable! :repo
33
- instance_variable! :trello_connection
34
- instance_variable! :id
35
- instance_variable! :repos
36
- instance_variable! :title
37
- instance_variable! :body
38
- instance_variable! :number
39
- instance_variable! :logger
40
- instance_variable! :repos
41
- issue = { number: 1, title: 'Title', body: 'Body' }
42
- expect(Reviewlette).to receive(:setup)
43
- expect(Reviewlette).to receive(:get_available_repos).and_return [repo]
44
- expect(Reviewlette).to receive(:get_unassigned_github_issues).and_return [issue]
45
- expect(Reviewlette).to receive(:find_card).and_return true
46
- expect(Reviewlette).to receive(:update_vacations)
47
- end
48
-
49
- it 'spins until find_id' do
50
- expect(Reviewlette).to receive(:find_id).and_return false
51
- expect(Reviewlette).to_not receive(:set_reviewer)
52
- expect(Reviewlette).to_not receive(:transform_name)
53
- expect(Reviewlette).to_not receive(:add_reviewer_on_github)
54
- expect(Reviewlette).to_not receive(:comment_on_github)
55
- expect(Reviewlette).to_not receive(:add_to_trello_card)
56
- expect(Reviewlette).to_not receive(:comment_on_trello)
57
- expect(Reviewlette).to_not receive(:move_to_list)
58
- expect(Reviewlette).to_not receive(:comment_on_error)
59
- Reviewlette.spin
60
- end
61
-
62
- it 'spins until set_reviewer' do
63
- expect(Reviewlette).to receive(:find_id).and_return true
64
- expect(Reviewlette).to receive(:set_reviewer)
65
- expect(Reviewlette).to_not receive(:transform_name)
66
- expect(Reviewlette).to_not receive(:add_reviewer_on_github)
67
- expect(Reviewlette).to_not receive(:comment_on_github)
68
- expect(Reviewlette).to_not receive(:add_to_trello_card)
69
- expect(Reviewlette).to_not receive(:comment_on_trello)
70
- expect(Reviewlette).to_not receive(:move_to_list)
71
- expect(Reviewlette).to receive(:comment_on_error)
72
- Reviewlette.spin
73
- end
74
-
75
- it 'spins until set_reviewer' do
76
- expect(Reviewlette).to receive(:find_id).and_return true
77
- expect(Reviewlette).to receive(:set_reviewer).and_return true
78
- expect(Reviewlette).to receive(:transform_name)
79
- expect(Reviewlette).to receive(:add_reviewer_on_github)
80
- expect(Reviewlette).to receive(:comment_on_github)
81
- # expect(Reviewlette).to receive(:add_to_trello_card)
82
- expect(Reviewlette).to receive(:comment_on_trello)
83
- expect(Reviewlette).to receive(:move_to_list)
84
- Reviewlette.instance_variable_set(:@reviewer, 'hi')
85
- Reviewlette.instance_variable_set(:@db, db)
86
- allow(@reviewer).to receive(:username)
87
- expect(db).to receive(:add_pr_to_db).with('Title', @reviewer.username)
88
- expect(Reviewlette.instance_variable_set(:@reviewer, nil))
89
- expect(Reviewlette).to_not receive(:comment_on_error)
90
- Reviewlette.spin
91
- end
92
- end
93
-
94
- describe '.get_available_repos' do
95
-
96
- it 'pulls in an array on avaialble repos' do
97
-
98
- instance_variable! :repos
99
- expect(Reviewlette.instance_variable_get(:@repos)).to be_kind_of Array #ok
100
- Reviewlette.get_available_repos
101
- end
102
- end
103
-
104
- describe '#find_card' do
105
-
106
- it 'finds the card by Github title' do
107
- line = 'Review_1337_name_of_pr_trello_shortid_454'
108
- pulls = { number: 1 }
109
- expect(Reviewlette).to receive(:match_pr_id_with_issue_id).and_return [pulls]
110
- allow(Reviewlette.find_card(line)).to receive(:match_pr_id_with_issue_id).and_return Array
111
- end
112
-
113
- end
114
-
115
- describe '.fetch_branch' do
116
-
117
- it 'gets the branch_name from github' do
118
- branch_name = 'review_github_branch_name_trello_23'
119
- subject.instance_variable_set(:@pullreq_ids, {number: 1})
120
- split_branch_name = branch_name.split('_')
121
- instance_variable! :github_connection
122
- expect(Reviewlette.instance_variable_get(:@pullreq_ids)).to receive_message_chain(:values, :index => 0).and_return number
123
- expect(github_connection).to receive(:get_branch_name).and_return branch_name
124
- expect(branch_name).to receive(:split).with('_').and_return split_branch_name
125
- expect(split_branch_name).to receive_message_chain(:last, :to_i)
126
- Reviewlette.fetch_branch
127
- end
128
- end
129
-
130
- describe '.comment_on_error' do
131
- it 'posts a comment with the arror message on trello' do
132
- instance_variable! :trello_connection
133
- expect(trello_connection).to receive(:comment_on_card).with("Skipped Issue 1 because everyone on the team is assigned to the card", nil)
134
- Reviewlette.comment_on_error
135
- end
136
- end
137
-
138
- describe '.get_unassigned_github_issues' do
139
- it 'returns all unassigned issues' do
140
- instance_variable! :github_connection
141
- expect(github_connection).to receive_message_chain(:list_issues, :select)
142
- Reviewlette.get_unassigned_github_issues
143
- end
144
- end
145
-
146
- describe '.match_pr_id_with_issue_id' do
147
-
148
- it 'matches issue id with pr id' do
149
- instance_variable! :github_connection
150
- instance_variable! :repo
151
- pulls = {number: 1}
152
- allow(github_connection).to receive(:list_pulls).and_return [pulls]
153
- allow(pulls).to receive(:number).and_return [1]
154
- Reviewlette.match_pr_id_with_issue_id
155
- end
156
- end
157
-
158
-
159
- describe '.transform_name' do
160
- it 'transforms trelloname to github name' do
161
- instance_variable! :trelloname
162
- Reviewlette.transform_name
163
- expect(Reviewlette.instance_variable_get("@githubname")).to be_a_kind_of String
164
- end
165
- end
5
+ subject { Reviewlette }
6
+ let( :reviewlette ) { subject.new }
166
7
 
167
- describe '.find_id' do
168
- before do
169
- instance_variable! :id
170
- instance_variable! :trello_connection
171
- end
8
+ before {
9
+ allow(GithubConnection).to receive(:new).and_return GithubConnection
10
+ allow(TrelloConnection).to receive(:new).and_return TrelloConnection
11
+ }
172
12
 
173
- it 'finds the id' do
174
- expect(trello_connection).to receive(:find_card_by_id).with(id).and_return card
175
- Reviewlette.find_id
176
- end
177
13
 
178
- it 'does not find the id' do
179
- Reviewlette.instance_variable_set("@id", 0)
180
- Reviewlette.instance_variable_set("@logger", logger)
181
- expect(logger).to receive(:warn)
182
- expect(Reviewlette.find_id).to be false
14
+ describe '.new' do
15
+ it 'sets github and trello connections' do
16
+ expect(GithubConnection).to receive (:new)
17
+ expect(TrelloConnection).to receive (:new)
18
+ subject.new
183
19
  end
184
20
  end
185
21
 
186
- describe '.set_reviewer' do
22
+ describe '.run' do
187
23
 
188
- before do
189
- Reviewlette.instance_variable_set("@reviewer", nil)
190
- end
24
+ it 'iterates over all open pull requests and extracts trello ids from name' do
25
+ expect(GithubConnection).to receive(:unassigned_pull_requests).and_return([{number: 11, title: 'test_issue_12'}])
26
+ expect(TrelloConnection).to receive(:find_card_by_id).with(12)
191
27
 
192
- it 'sets the reviewer' do
193
- reviewer = double('reviewer')
194
- instance_variable! :trello_connection
195
- instance_variable! :card
196
- expect(trello_connection).to receive(:determine_reviewer).with(card).and_return reviewer
197
- expect(reviewer).to receive(:username).and_return String
198
- expect(reviewer).to receive(:username).and_return String
199
- Reviewlette.set_reviewer
28
+ reviewlette.run
200
29
  end
201
30
 
202
- it 'fails to set the reviewer because everyone on the team is assigned to the card' do
203
- reviewer = double('reviewer')
204
- instance_variable! :trello_connection
205
- instance_variable! :card
206
- Reviewlette.instance_variable_set("@logger", logger)
207
- expect(trello_connection).to receive(:determine_reviewer).with(card).and_raise(Reviewlette::AlreadyAssignedException)
208
- allow(card).to receive(:short_id).and_return 3
209
- expect($stdout).to receive(:puts)
210
- expect(logger).to receive(:warn)
211
- expect(Reviewlette.set_reviewer).to eq false
212
- end
213
- end
31
+ it 'adds assignee and reviewer comment on github, adds comment on trello and moves card' do
32
+ card = Trello::Card.new
33
+ expect(GithubConnection).to receive(:unassigned_pull_requests).and_return([{number: 11, title: 'test_issue_12'}])
34
+ expect(TrelloConnection).to receive(:find_card_by_id).with(12).and_return(card)
35
+ expect(reviewlette).to receive(:select_reviewer).and_return({'suse_username' => 'test', 'github_username' => 'testgit'})
214
36
 
215
- describe '.add_reviewer_on_github' do
216
- it 'adds the reviewer on github as assignee' do
217
- instance_variable! :github_connection
218
- instance_variable! :title
219
- instance_variable! :body
220
- instance_variable! :number
221
- instance_variable! :githubname
222
- expect(github_connection).to receive(:add_assignee).with('repo/repo', 23, 'title', 'body', 'gitty').and_return true
223
- Reviewlette.add_reviewer_on_github
224
- end
225
- end
37
+ expect(GithubConnection).to receive(:add_assignee).with(11, 'testgit')
38
+ expect(GithubConnection).to receive(:reviewer_comment).with(11, 'testgit', card)
39
+ expect(GithubConnection).to receive(:repo).and_return('SUSE/test')
226
40
 
227
- describe '.comment_on_github' do
228
- it 'comments on the issue' do
229
- instance_variable! :card
230
- instance_variable! :number
231
- instance_variable! :githubname
232
- instance_variable! :github_connection
233
- expect(card).to receive(:url).and_return 'www.example.url'
234
- expect(github_connection).to receive(:comment_on_issue).with('repo/repo', 23, 'gitty', 'www.example.url').and_return true
235
- Reviewlette.comment_on_github
236
- end
237
- end
41
+ expect(TrelloConnection).to receive(:comment_on_card).with("@ will review https://github.com/SUSE/test/issues/11", card)
42
+ expect(TrelloConnection).to receive(:move_card_to_list).with(card, 'In review')
238
43
 
239
- describe '.add_to_trello_card' do
240
- it 'adds a reviewer to the right trello card' do
241
- instance_variable! :trello_connection
242
- instance_variable! :reviewer
243
- instance_variable! :card
244
- expect(trello_connection).to receive(:add_reviewer_to_card).with(reviewer, card).and_return true
245
- Reviewlette.add_to_trello_card
44
+ reviewlette.run
246
45
  end
247
46
 
248
- it 'rescues with: already assigned' do
249
- instance_variable! :trello_connection
250
- expect{Reviewlette.add_to_trello_card}.to raise_exception
251
- # Reviewlette.add_to_trello_card
252
- end
253
47
  end
254
48
 
255
- describe '.comment_on_trello' do
256
- before do
257
- instance_variable! :repo
258
- instance_variable! :trelloname
259
- instance_variable! :number
260
- instance_variable! :trello_connection
261
- instance_variable! :full_comment
262
- instance_variable! :card
263
- end
264
-
265
- it 'puts a comment on the trello card ' do
266
- expect(full_comment).to eq '@jschmid will review https://github.com/repo/repo/issues/23'
267
- end
49
+ describe '.select_reviewer' do
268
50
 
269
- it 'actually posts' do
270
- expect(trello_connection).to receive(:comment_on_card).with(full_comment, card).and_return true
271
- Reviewlette.comment_on_trello
272
- end
273
- end
51
+ MEMBERS_CONFIG['members'] = [{'suse_username' => 'test1', 'trello_username' => 'trellotest1'},
52
+ {'suse_username' => 'test2', 'trello_username' => 'trellotest2'}]
274
53
 
275
- describe '.move_to_list' do
276
- before do
277
- instance_variable! :github_connection
278
- instance_variable! :trello_connection
279
- instance_variable! :card
280
- instance_variable! :repo
281
- instance_variable! :id
54
+ it 'excludes members on vacation' do
55
+ card = Trello::Card.new
56
+ allow(card).to receive(:members).and_return([])
57
+ expect(Vacations).to receive(:members_on_vacation).and_return(MEMBERS_CONFIG['members'].first['suse_username'])
58
+ expect(reviewlette.select_reviewer(nil, card)).to eq(MEMBERS_CONFIG['members'].last)
282
59
  end
283
60
 
284
- it 'moves the card to #Done list if the pull is merged' do
285
- expect(trello_connection).to receive(:find_column).with('Done').and_return 'Done'
286
- expect(trello_connection).to receive(:move_card_to_list).with(card,'Done').and_return Object
287
- expect(github_connection).to receive(:pull_merged?).with(repo, id).and_return true
288
- Reviewlette.move_to_list
61
+ it 'excludes the owner of the trello card' do
62
+ card = Trello::Card.new
63
+ allow(card).to receive_message_chain(:members, :map).and_return(['trellotest1'])
64
+ expect(Vacations).to receive(:members_on_vacation).and_return([])
65
+ expect(reviewlette.select_reviewer(nil, card)).to eq(MEMBERS_CONFIG['members'].last)
289
66
  end
290
67
 
291
- it 'moves the card to #in-Review list if the pull is not merged' do
292
- expect(trello_connection).to receive(:find_column).with('In review').and_return 'In review'
293
- expect(trello_connection).to receive(:move_card_to_list).with(card,'In review').and_return Object
294
- expect(github_connection).to receive(:pull_merged?).with(repo, id).and_return false
295
- Reviewlette.move_to_list
296
- end
297
68
  end
298
69
 
299
- describe '.setup' do
300
- before do
301
- instance_variable! :github_connection
302
- instance_variable! :trello_connection
303
- instance_variable! :board
304
- instance_variable! :repo
305
- end
306
-
307
- it 'sets up repo variable' do
308
- Reviewlette.setup
309
- expect(Reviewlette.instance_variable_get('@repo')).to be_kind_of String #ok
310
- end
311
- it 'sets up the github_connection' do
312
- Reviewlette.setup
313
- expect(github_connection).to be_kind_of Object #how to call this kind of structure
314
- end
315
70
 
316
- it 'sets up the trello_connection' do
317
- Reviewlette.setup
318
- expect(Reviewlette.instance_variable_get('@trello_connection')).to be_kind_of Object #same
319
- end
320
-
321
- it 'sets up the board' do
322
- Reviewlette.setup
323
- expect(Reviewlette.instance_variable_get('@board')).to be_kind_of Object #same
324
- end
325
- end
326
-
327
- describe '.update_vacations' do
328
-
329
- it 'updates vacationsstatus based on tel vacation output' do
330
- vacations = ['2015-01-07', '2015-01-25']
331
- instance_variable_set(:@vacations, vacations)
332
- instance_variable_set(:@db, db)
333
- expect(Reviewlette::Vacations).to receive(:find_vacations).at_least(:once)
334
- expect(Reviewlette).to receive(:evaluate_vacations).at_least(:once)
335
- Reviewlette.update_vacations
336
- end
337
- end
338
-
339
- describe '.evaluate_vacations' do
340
-
341
- it 'checks if vacation state is true' do
342
- today = Date.today
343
- allow(subject).to receive(:parse_vacations).and_return [[today]]
344
- subject.evaluate_vacations('jschmid')
345
- end
346
-
347
- it 'checks if vacation state is false' do
348
- allow(subject).to receive(:parse_vacations).and_return [1,2]
349
- subject.evaluate_vacations('jschmid')
350
- end
351
- end
352
-
353
-
354
- describe '.parse_vacations' do
355
-
356
- it 'parses Date in proper format' do
357
- # vacations = ["2014-08-23 - 2014-09-14", "2014-10-03 - 2014-10-05", "2014-12-24 - 2014-12-28"]
358
- # split = [["2014-08-23", "2014-09-14"], ["2014-10-03", "2014-10-05"], ["2014-12-24", "2014-12-28"]]
359
- # ret = [['Sat, 23 Aug 2014', 'Sun, 14 Sep 2014'], ['Fri, 03 Oct 2014', 'Sun, 05 Oct 2014'], ['Wed, 24 Dec 2014', 'Sun, 28 Dec 2014']]
360
- # instance_variable_set(:@vacations, vacations)
361
- # instance_variable_set(:@split, split)
362
- # expect(instance_variable_get(:@vacations)).to receive(:map).and_return split
363
- # expect(instance_variable_get(:@split)).to receive(:map).and_return ret
364
- # subject.parse_vacations
365
- end
366
- end
367
71
  end
data/spec/spec_helper.rb CHANGED
@@ -7,17 +7,10 @@ require 'simplecov'
7
7
  SimpleCov.minimum_coverage 80
8
8
  SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
9
9
  SimpleCov.start do
10
- add_filter '/spec/'
11
- #add_filter 'vendor'
10
+ add_filter '/spec'
12
11
  end
13
12
 
14
13
 
15
14
  require 'webmock/rspec'
16
15
  require 'rspec'
17
- require_relative '../lib/reviewlette/exceptions'
18
- require_relative '../lib/reviewlette/vacations'
19
- require_relative '../lib/reviewlette/database'
20
16
  require 'reviewlette'
21
- require 'support/request_stubbing'
22
-
23
-
@@ -1,202 +1,67 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Reviewlette::TrelloConnection do
3
+ describe TrelloConnection do
4
4
 
5
- subject { Reviewlette::TrelloConnection }
5
+ TRELLO_CONFIG = { :consumerkey => '4a6', :consumersecret => '899', :oauthtoken => 'a8e', :board_id => 'T5S' }
6
+ subject { TrelloConnection }
7
+ let (:trello) { subject.new }
8
+ let (:card) { Trello::Card.new }
6
9
 
7
- describe '.new' do
8
-
9
- it 'populates board variable with instance of Trello::Board' do
10
- stub_boards_call
11
- expect(subject.new.board).to be_kind_of Trello::Board
12
- end
13
-
14
- it 'sets up trello' do
15
- allow(Trello::Board).to receive(:find).and_return nil
16
- config = Reviewlette::TRELLO_CONFIG1
17
- expect_any_instance_of(Trello::Configuration).to receive(:developer_public_key=).with(config['consumerkey']).and_call_original
18
- subject.new
19
- end
10
+ before {
11
+ allow(Trello::Board).to receive(:find).and_return(Trello::Board.new)
12
+ }
20
13
 
14
+ describe '.new' do
21
15
  it 'sets up trello' do
22
- allow(Trello::Board).to receive(:find).and_return nil
23
- config = Reviewlette::TRELLO_CONFIG1
24
- expect_any_instance_of(Trello::Configuration).to receive(:member_token=).with(config['oauthtoken']).and_call_original
16
+ expect_any_instance_of(Trello::Configuration).to receive(:developer_public_key=).with(TRELLO_CONFIG['consumerkey'])
17
+ expect_any_instance_of(Trello::Configuration).to receive(:member_token=).with(TRELLO_CONFIG['oauthtoken'])
25
18
  subject.new
26
19
  end
27
-
28
- end
29
-
30
-
31
- describe '#find_member_by_id(id)' do
32
- let( :trello_connection ) { subject.new }
33
-
34
- before do
35
- allow_any_instance_of(subject).to receive(:setup_trello).and_return true
36
- allow(subject).to receive(:find_card_by_id).and_return :id
37
- end
38
-
39
- it "finds the right card based on the trello id" do
40
- board = double('board')
41
- trello_connection.board = board
42
- expect(board).to receive_message_chain(:cards, :find)
43
- trello_connection.send(:find_card_by_id, 42)
44
- #privates with send
45
- end
46
- end
47
-
48
- describe '#find_member_by_username' do
49
- let( :trello_connection ) { subject.new }
50
-
51
- before do
52
- allow_any_instance_of(subject).to receive(:setup_trello).and_return true
53
- allow(subject).to receive(:find_member_by_username).and_return :username
54
- end
55
-
56
- it "finds a member based on a username and returns a trello member object" do
57
- board = double('board')
58
- trello_connection.board = board
59
- expect(board).to receive_message_chain(:members, :find)
60
- trello_connection.send(:find_member_by_username, 'art')
61
- end
62
- end
63
-
64
- describe '#find_member_by_id' do
65
- let( :trello_connection ) { subject.new }
66
-
67
- before do
68
- allow_any_instance_of(subject).to receive(:setup_trello).and_return true
69
- allow(subject).to receive(:find_member_by_id).and_return :id
70
- end
71
-
72
- it "finds the right member based on the trello id and returns a trello member object" do
73
- board = double('board')
74
- trello_connection.board = board
75
- expect(board).to receive_message_chain(:members, :find)
76
- trello_connection.send(:find_member_by_id, 42)
77
- end
78
20
  end
79
21
 
80
22
  describe '#add_reviewer_to_card' do
81
- let ( :trello_connection ) { subject.new }
82
-
83
- before do
84
- allow_any_instance_of(subject).to receive(:setup_trello).and_return true
85
- end
86
-
87
23
  it "adds the valid member to the trello card and comments it" do
88
- card = double('card')
89
- allow(card).to receive(:add_member).and_return true
90
- expect(trello_connection.add_reviewer_to_card('asd', card)).to eq true
24
+ expect(trello).to receive(:find_member_by_username).with('testuser1').and_return 'testuser1'
25
+ expect_any_instance_of(Trello::Card).to receive(:add_member).with('testuser1')
26
+ trello.add_reviewer_to_card('testuser1', card)
91
27
  end
92
28
  end
93
29
 
94
30
  describe '#comment_on_card' do
95
- let ( :trello_connection ) { subject.new }
96
-
97
- before do
98
- allow_any_instance_of(subject).to receive(:setup_trello).and_return true
99
- end
100
-
101
31
  it "comments on the assigned trello card " do
102
- card = double('card')
103
- allow(card).to receive(:add_comment).with('username').and_return true
104
- expect(trello_connection.comment_on_card('username', card)).to eq true
105
- end
106
- end
107
-
108
- describe '#team' do
109
- let ( :trello_connection ) { subject.new }
110
-
111
- before do
112
- allow_any_instance_of(subject).to receive(:setup_trello).and_return true
113
- end
114
-
115
- it "builds the team member list" do
116
- expect(trello_connection.team).to be_a_kind_of Array
32
+ allow(card).to receive(:add_comment).with('comment').and_return true
33
+ expect(trello.comment_on_card('comment', card)).to eq true
117
34
  end
118
35
  end
119
36
 
120
37
  describe '#move_card_to_list' do
121
- let( :trello_connection ) { subject.new }
122
-
123
- before do
124
- allow_any_instance_of(subject).to receive(:setup_trello).and_return true
125
- end
126
-
127
38
  it 'move cards to its certain column' do
128
- card = double('card')
129
- allow(card).to receive(:move_to_list).with('Done').and_return true
130
- expect(trello_connection.move_card_to_list(card, 'Done')).to be true
131
- end
132
-
133
- it 'fails to move cards to its certain column' do
134
- card = double('card')
135
- allow(card).to receive(:move_to_list).with('Done').and_return false
136
- expect(trello_connection.move_card_to_list(card, 'Done')).to be false
39
+ expect(trello).to receive(:find_column).with('Done').and_return 'column'
40
+ expect(card).to receive(:move_to_list).with('column').and_return true
41
+ expect(trello.move_card_to_list(card, 'Done')).to be true
137
42
  end
138
43
  end
139
44
 
140
45
  describe '#find_column' do
141
- let( :trello_connection ) { subject.new }
142
-
143
- before do
144
- allow_any_instance_of(subject).to receive(:setup_trello).and_return true
145
- end
146
-
147
46
  it 'detects columns' do
148
- board = double('board')
149
- trello_connection.board = board
150
- expect(board).to receive_message_chain(:lists, :find)
151
- trello_connection.send(:find_column, 'Done')
47
+ expect_any_instance_of(Trello::Board).to receive_message_chain(:lists, :find)
48
+ trello.find_column('Done')
152
49
  end
153
50
  end
154
51
 
155
- describe '#sample_reviewer' do
156
- let ( :trello_connection ) { subject.new }
157
-
158
- before do
159
- allow_any_instance_of(subject).to receive(:setup_trello).and_return true
160
- end
161
- it 'randomly selects a teammember' do
162
- card = double('card')
163
- expect(card).to receive_message_chain(:assignees, :map).and_return ['funny','names']
164
- trello_connection.sample_reviewer(card)
52
+ describe '#find_member_by_username' do
53
+ it "finds a member based on a username and returns a trello member object" do
54
+ expect_any_instance_of(Trello::Board).to receive_message_chain(:members, :find)
55
+ trello.find_member_by_username('testuser')
165
56
  end
166
57
  end
167
58
 
168
- describe '#reviewer_exception_handler' do
169
- let ( :trello_connection ) { subject.new }
170
-
171
- before do
172
- allow_any_instance_of(subject).to receive(:setup_trello).and_return true
173
- end
174
- it 'checks sum of for card assignees' do
175
- card = double('card')
176
- expect(card).to receive_message_chain(:assignees, :map).and_return [1,2,3]
177
- trello_connection.reviewer_exception_handler(card)
59
+ describe '#find_card_by_id(id)' do
60
+ it "finds the right card based on the trello id" do
61
+ expect_any_instance_of(Trello::Board).to receive_message_chain(:cards, :find)
62
+ trello.find_card_by_id(123)
178
63
  end
179
64
  end
180
65
 
181
- describe '#determine_reviewer' do
182
- let ( :trello_connection ) { subject.new }
183
-
184
- before do
185
- allow_any_instance_of(subject).to receive(:setup_trello).and_return true
186
- end
187
-
188
- it 'fails to holds an array of the available reveiewers' do
189
- card = double('card')
190
- expect(trello_connection).to receive(:reviewer_exception_handler).with(card).and_return true
191
- expect{trello_connection.determine_reviewer(card)}.to raise_error(Exception, 'Everyone on the team is assigned to the Card.')
192
- end
193
66
 
194
- it 'holds an array of the available reveiewers' do
195
- card = double('card')
196
- expect(trello_connection).to receive(:reviewer_exception_handler).with(card).and_return false
197
- expect(trello_connection).to receive(:sample_reviewer).and_return true
198
- expect(trello_connection).to receive(:find_member_by_username).and_return 'name'
199
- expect(trello_connection.determine_reviewer(card)).to eq 'name'
200
- end
201
- end
202
67
  end