ruby-trello 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/hash_spec.rb CHANGED
@@ -5,7 +5,11 @@ describe Hash, '#jsoned_into' do
5
5
  include Helpers
6
6
 
7
7
  it "should convert a single parsed json into card" do
8
- Trello::Card.should_receive(:new).once.with(cards_details.first)
8
+ expect(Trello::Card)
9
+ .to receive(:new)
10
+ .once
11
+ .with(cards_details.first)
12
+
9
13
  cards_details.first.jsoned_into(Trello::Card)
10
14
  end
11
15
  end
data/spec/item_spec.rb CHANGED
@@ -2,36 +2,54 @@ require 'spec_helper'
2
2
 
3
3
  module Trello
4
4
  describe Item do
5
- before(:all) do
6
- @detail = {
5
+ let(:details) {
6
+ {
7
7
  'id' => 'abcdef123456789123456789',
8
8
  'name' => 'test item',
9
9
  'type' => 'check',
10
10
  'state' => 'complete',
11
11
  'pos' => 0
12
12
  }
13
+ }
13
14
 
14
- @item = Item.new(@detail)
15
- end
15
+ let(:item) { Item.new(details) }
16
16
 
17
17
  it 'gets its id' do
18
- @item.id.should == @detail['id']
18
+ expect(item.id).to eq details['id']
19
19
  end
20
20
 
21
21
  it 'gets its name' do
22
- @item.name.should == @detail['name']
22
+ expect(item.name).to eq details['name']
23
23
  end
24
24
 
25
25
  it 'knows its type' do
26
- @item.type.should == @detail['type']
26
+ expect(item.type).to eq details['type']
27
27
  end
28
28
 
29
29
  it 'knows its state' do
30
- @item.state.should == @detail['state']
30
+ expect(item.state).to eq details['state']
31
31
  end
32
32
 
33
33
  it 'knows its pos' do
34
- @item.pos.should == @detail['pos']
34
+ expect(item.pos).to eq details['pos']
35
+ end
36
+
37
+ describe '#complete?' do
38
+ before do
39
+ allow(item)
40
+ .to receive(:state)
41
+ .and_return state
42
+ end
43
+
44
+ context 'when complete' do
45
+ let(:state) { 'complete' }
46
+ it { expect(item).to be_complete }
47
+ end
48
+
49
+ context 'when complete' do
50
+ let(:state) { 'incomplete' }
51
+ it { expect(item).not_to be_complete }
52
+ end
35
53
  end
36
54
  end
37
55
  end
data/spec/label_spec.rb CHANGED
@@ -7,21 +7,26 @@ module Trello
7
7
  let(:label) { client.find(:label, 'abcdef123456789123456789') }
8
8
  let(:client) { Client.new }
9
9
 
10
- before(:each) do
11
- client.stub(:get).with("/labels/abcdef123456789123456789", {}).
12
- and_return JSON.generate(label_details.first)
10
+ before do
11
+ allow(client)
12
+ .to receive(:get)
13
+ .with("/labels/abcdef123456789123456789", {})
14
+ .and_return JSON.generate(label_details.first)
13
15
  end
14
16
 
15
17
  context "finding" do
16
18
  let(:client) { Trello.client }
17
19
 
18
20
  it "delegates to Trello.client#find" do
19
- client.should_receive(:find).with(:label, 'abcdef123456789123456789', {})
21
+ expect(client)
22
+ .to receive(:find)
23
+ .with(:label, 'abcdef123456789123456789', {})
24
+
20
25
  Label.find('abcdef123456789123456789')
21
26
  end
22
27
 
23
28
  it "is equivalent to client#find" do
24
- Label.find('abcdef123456789123456789').should eq(label)
29
+ expect(Label.find('abcdef123456789123456789')).to eq(label)
25
30
  end
26
31
  end
27
32
 
@@ -29,18 +34,15 @@ module Trello
29
34
  let(:client) { Trello.client }
30
35
 
31
36
  it "creates a new record" do
32
- label = Label.new(label_details.first)
33
- label.should be_valid
37
+ expect(Label.new(label_details.first)).to be_valid
34
38
  end
35
39
 
36
40
  it 'must not be valid if not given a name' do
37
- label = Label.new('idBoard' => lists_details.first['board_id'])
38
- label.should_not be_valid
41
+ expect(Label.new('idBoard' => lists_details.first['board_id'])).to_not be_valid
39
42
  end
40
43
 
41
44
  it 'must not be valid if not given a board id' do
42
- label = Label.new('name' => lists_details.first['name'])
43
- label.should_not be_valid
45
+ expect(Label.new('name' => lists_details.first['name'])).to_not be_valid
44
46
  end
45
47
 
46
48
  it 'creates a new record and saves it on Trello', refactor: true do
@@ -53,11 +55,14 @@ module Trello
53
55
 
54
56
  expected_payload = {name: "Test Label", color: nil, idBoard: "abcdef123456789123456789" }
55
57
 
56
- client.should_receive(:post).with("/labels", expected_payload).and_return result
58
+ expect(client)
59
+ .to receive(:post)
60
+ .with("/labels", expected_payload)
61
+ .and_return result
57
62
 
58
63
  label = Label.create(label_details.first.merge(payload.merge(board_id: boards_details.first['id'])))
59
64
 
60
- label.class.should be Label
65
+ expect(label).to be_a Label
61
66
  end
62
67
  end
63
68
 
@@ -69,7 +74,10 @@ module Trello
69
74
  name: expected_new_name,
70
75
  }
71
76
 
72
- client.should_receive(:put).once.with("/labels/abcdef123456789123456789", payload)
77
+ expect(client)
78
+ .to receive(:put)
79
+ .once
80
+ .with("/labels/abcdef123456789123456789", payload)
73
81
 
74
82
  label.name = expected_new_name
75
83
  label.save
@@ -82,7 +90,10 @@ module Trello
82
90
  color: expected_new_color,
83
91
  }
84
92
 
85
- client.should_receive(:put).once.with("/labels/abcdef123456789123456789", payload)
93
+ expect(client)
94
+ .to receive(:put)
95
+ .once
96
+ .with("/labels/abcdef123456789123456789", payload)
86
97
 
87
98
  label.color = expected_new_color
88
99
  label.save
@@ -90,8 +101,11 @@ module Trello
90
101
 
91
102
  it "can update with any valid color" do
92
103
  %w(green yellow orange red purple blue sky lime pink black).each do |color|
93
- client.stub(:put).with("/labels/abcdef123456789123456789", {color: color}).
94
- and_return "not important"
104
+ allow(client)
105
+ .to receive(:put)
106
+ .with("/labels/abcdef123456789123456789", {color: color})
107
+ .and_return "not important"
108
+
95
109
  label.color = color
96
110
  label.save
97
111
  expect(label.errors).to be_empty
@@ -99,44 +113,55 @@ module Trello
99
113
  end
100
114
 
101
115
  it "throws an error when trying to update a label with an unknown colour" do
102
- client.stub(:put).with("/labels/abcdef123456789123456789", {}).
103
- and_return "not important"
116
+ allow(client)
117
+ .to receive(:put)
118
+ .with("/labels/abcdef123456789123456789", {})
119
+ .and_return "not important"
120
+
104
121
  label.color = 'mauve'
105
122
  label.save
123
+
106
124
  expect(label.errors.full_messages.to_sentence).to eq("Label color 'mauve' does not exist")
107
125
  end
108
126
  end
109
127
 
110
128
  context "deleting" do
111
129
  it "deletes the label" do
112
- client.should_receive(:delete).with("/labels/#{label.id}")
130
+ expect(client)
131
+ .to receive(:delete)
132
+ .with("/labels/#{label.id}")
133
+
113
134
  label.delete
114
135
  end
115
136
  end
116
137
 
117
138
  context "fields" do
118
139
  it "gets its id" do
119
- label.id.should_not be_nil
140
+ expect(label.id).to_not be_nil
120
141
  end
121
142
 
122
143
  it "gets its name" do
123
- label.name.should_not be_nil
144
+ expect(label.name).to_not be_nil
124
145
  end
125
146
 
126
147
  it "gets its usage" do
127
- label.uses.should_not be_nil
148
+ expect(label.uses).to_not be_nil
128
149
  end
129
150
 
130
151
  it "gets its color" do
131
- label.color.should_not be_nil
152
+ expect(label.color).to_not be_nil
132
153
  end
133
154
  end
134
155
 
135
156
  context "boards" do
136
157
  it "has a board" do
137
- client.stub(:get).with("/boards/abcdef123456789123456789", {}).and_return JSON.generate(boards_details.first)
138
- label.board.should_not be_nil
158
+ expect(client)
159
+ .to receive(:get)
160
+ .with("/boards/abcdef123456789123456789", {})
161
+ .and_return JSON.generate(boards_details.first)
162
+
163
+ expect(label.board).to_not be_nil
139
164
  end
140
165
  end
141
166
  end
142
- end
167
+ end
data/spec/list_spec.rb CHANGED
@@ -8,20 +8,30 @@ module Trello
8
8
  let(:client) { Client.new }
9
9
 
10
10
  before(:each) do
11
- client.stub(:get).with('/lists/abcdef123456789123456789', {}).and_return JSON.generate(lists_details.first)
12
- client.stub(:get).with('/boards/abcdef123456789123456789', {}).and_return JSON.generate(boards_details.first)
11
+ allow(client)
12
+ .to receive(:get)
13
+ .with('/lists/abcdef123456789123456789', {})
14
+ .and_return JSON.generate(lists_details.first)
15
+
16
+ allow(client)
17
+ .to receive(:get)
18
+ .with('/boards/abcdef123456789123456789', {})
19
+ .and_return JSON.generate(boards_details.first)
13
20
  end
14
21
 
15
22
  context 'finding' do
16
23
  let(:client) { Trello.client }
17
24
 
18
25
  it 'delegates to client#find' do
19
- client.should_receive(:find).with(:list, 'abcdef123456789123456789', {})
26
+ expect(client)
27
+ .to receive(:find)
28
+ .with(:list, 'abcdef123456789123456789', {})
29
+
20
30
  List.find('abcdef123456789123456789')
21
31
  end
22
32
 
23
33
  it 'is equivalent to client#find' do
24
- List.find('abcdef123456789123456789').should eq(list)
34
+ expect(List.find('abcdef123456789123456789')).to eq(list)
25
35
  end
26
36
  end
27
37
 
@@ -30,34 +40,36 @@ module Trello
30
40
 
31
41
  it 'creates a new record' do
32
42
  list = List.new(lists_details.first)
33
- list.should be_valid
43
+ expect(list).to be_valid
34
44
  end
35
45
 
36
46
  it 'must not be valid if not given a name' do
37
47
  list = List.new(lists_details.first.except('name'))
38
- list.should_not be_valid
48
+ expect(list).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
  list = List.new(lists_details.first.except('id'))
43
- list.should_not be_valid
53
+ expect(list).to_not be_valid
44
54
  end
45
55
 
46
56
  it 'creates a new record and saves it on Trello', refactor: true do
47
57
  payload = {
48
58
  name: 'Test List',
49
- board_id: 'abcdef123456789123456789'
59
+ board_id: 'abcdef123456789123456789',
60
+ pos: 42
50
61
  }
51
62
 
52
63
  result = JSON.generate(payload)
53
64
 
54
- expected_payload = {name: 'Test List', closed: false, idBoard: 'abcdef123456789123456789'}
65
+ expected_payload = {name: 'Test List', closed: false, idBoard: 'abcdef123456789123456789', pos: 42}
55
66
 
56
- client.should_receive(:post).with('/lists', expected_payload).and_return result
67
+ expect(client)
68
+ .to receive(:post)
69
+ .with('/lists', expected_payload).and_return result
57
70
 
58
71
  list = List.create(payload)
59
-
60
- list.class.should be List
72
+ expect(list).to be_a List
61
73
  end
62
74
  end
63
75
 
@@ -67,70 +79,115 @@ module Trello
67
79
 
68
80
  payload = {
69
81
  name: expected_new_name,
70
- closed: false
82
+ closed: false,
83
+ pos: list.pos
71
84
  }
72
85
 
73
- client.should_receive(:put).once.with('/lists/abcdef123456789123456789', payload)
86
+ expect(client)
87
+ .to receive(:put)
88
+ .once
89
+ .with('/lists/abcdef123456789123456789', payload)
90
+
74
91
  list.name = expected_new_name
75
92
  list.save
76
93
  end
94
+
95
+ it 'updates position' do
96
+ new_position = 42
97
+ payload = {
98
+ name: list.name,
99
+ closed: list.closed,
100
+ pos: new_position
101
+ }
102
+
103
+ expect(client)
104
+ .to receive(:put)
105
+ .once
106
+ .with('/lists/abcdef123456789123456789', payload)
107
+
108
+ list.pos = new_position
109
+ list.save
110
+ end
77
111
  end
78
112
 
79
113
  context 'fields' do
80
114
  it 'gets its id' do
81
- list.id.should == lists_details.first['id']
115
+ expect(list.id).to eq lists_details.first['id']
82
116
  end
83
117
 
84
118
  it 'gets its name' do
85
- list.name.should == lists_details.first['name']
119
+ expect(list.name).to eq lists_details.first['name']
86
120
  end
87
121
 
88
122
  it 'knows if it is open or closed' do
89
- list.closed.should == lists_details.first['closed']
123
+ expect(list.closed).to eq lists_details.first['closed']
90
124
  end
91
125
 
92
126
  it 'has a board' do
93
- list.board.should == Board.new(boards_details.first)
127
+ expect(list.board).to eq Board.new(boards_details.first)
94
128
  end
95
129
 
96
130
  it 'gets its position' do
97
- list.pos.should == lists_details.first['pos']
131
+ expect(list.pos).to eq lists_details.first['pos']
98
132
  end
99
133
  end
100
134
 
101
135
  context 'actions' do
102
136
  it 'has a list of actions' do
103
- client.stub(:get).with('/lists/abcdef123456789123456789/actions', { filter: :all }).and_return actions_payload
104
- list.actions.count.should be > 0
137
+ allow(client)
138
+ .to receive(:get)
139
+ .with('/lists/abcdef123456789123456789/actions', { filter: :all })
140
+ .and_return actions_payload
141
+
142
+ expect(list.actions.count).to be > 0
105
143
  end
106
144
  end
107
145
 
108
146
  context 'cards' do
109
147
  it 'has a list of cards' do
110
- client.stub(:get).with('/lists/abcdef123456789123456789/cards', { filter: :open }).and_return cards_payload
111
- list.cards.count.should be > 0
148
+ allow(client)
149
+ .to receive(:get)
150
+ .with('/lists/abcdef123456789123456789/cards', { filter: :open })
151
+ .and_return cards_payload
152
+
153
+ expect(list.cards.count).to be > 0
154
+ end
155
+
156
+ it 'moves cards to another list' do
157
+ other_list = List.new(lists_details.first.merge(id: 'otherListID', cards: []))
158
+
159
+ allow(client)
160
+ .to receive(:post)
161
+ .with('/lists/abcdef123456789123456789/moveAllCards', { idBoard: other_list.board_id, idList: other_list.id })
162
+ .and_return cards_payload
163
+
164
+ expect(list.move_all_cards(other_list)).to eq cards_payload
112
165
  end
113
166
  end
114
167
 
115
168
  describe '#closed?' do
116
169
  it 'returns the closed attribute' do
117
- expect(list.closed?).not_to be(true)
170
+ expect(list).to_not be_closed
118
171
  end
119
172
  end
120
173
 
121
174
  describe '#close' do
122
175
  it 'updates the close attribute to true' do
123
176
  list.close
124
- expect(list.closed).to be(true)
177
+ expect(list).to be_closed
125
178
  end
126
179
  end
127
180
 
128
181
  describe '#close!' do
129
182
  it 'updates the close attribute to true and saves the list' do
130
- client.should_receive(:put).once.with('/lists/abcdef123456789123456789', {
131
- name: list.name,
132
- closed: true
133
- })
183
+ expect(client)
184
+ .to receive(:put)
185
+ .once
186
+ .with('/lists/abcdef123456789123456789', {
187
+ name: list.name,
188
+ closed: true,
189
+ pos: list.pos
190
+ })
134
191
 
135
192
  list.close!
136
193
  end