/
board_spec.rb
195 lines (145 loc) · 4.88 KB
/
board_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
require 'spec_helper'
module Trello
describe Board do
include Helpers
before(:each) do
Client.stub(:get).with("/boards/abcdef123456789123456789").
and_return JSON.generate(boards_details.first)
@board = Board.find('abcdef123456789123456789')
end
context "fields" do
it "gets an id" do
@board.id.should_not be_nil
end
it "gets a name" do
@board.name.should_not be_nil
end
it "gets the description" do
@board.description.should_not be_nil
end
it "knows if it is closed or open" do
@board.closed?.should_not be_nil
end
it "gets its url" do
@board.url.should_not be_nil
end
end
context "actions" do
it "has a list of actions" do
Client.stub(:get).with("/boards/abcdef123456789123456789/actions").
and_return actions_payload
@board.actions.count.should be > 0
end
end
context "cards" do
it "gets its list of cards" do
Client.stub(:get).with("/boards/abcdef123456789123456789/cards").
and_return cards_payload
@board.cards.count.should be > 0
end
end
context "lists" do
it "has a list of lists" do
Client.stub(:get).with("/boards/abcdef123456789123456789/lists", hash_including(:filter => :open)).
and_return lists_payload
@board.lists.count.should be > 0
end
end
context "members" do
it "has a list of members" do
Client.stub(:get).with("/boards/abcdef123456789123456789/members", hash_including(:filter => :all)).
and_return JSON.generate([user_details])
@board.members.count.should be > 0
end
end
context "organization" do
it "belongs to an organization" do
Client.stub(:get).with("/organizations/abcdef123456789123456789").
and_return JSON.generate(orgs_details.first)
@board.organization.should_not be_nil
end
end
it "is not closed" do
@board.closed?.should_not be_true
end
end
describe "#update_fields" do
it "does not set any fields when the fields argument is empty" do
expected = {
'id' => "id",
'name' => "name",
'desc' => "desc",
'closed' => false,
'url' => "url",
'idOrganization' => "org_id"
}
board = Board.new(expected)
board.update_fields({})
expected.each_pair do |key, value|
if board.respond_to?(key)
board.send(key).should == value
end
end
board.description.should == expected['desc']
board.organization_id.should == expected['idOrganization']
end
it "sets any attributes supplied in the fields argument"
end
describe "#save!" do
include Helpers
let(:any_board_json) do
JSON.generate(boards_details.first)
end
it "cannot currently save a new instance" do
Client.should_not_receive :put
the_new_board = Board.new
lambda{the_new_board.save!}.should raise_error "Cannot save new instance."
end
it "puts all fields except id" do
expected_fields = %w{name description closed url organisation_id}.map{|s| s.to_sym}
Client.should_receive(:put) do |anything, body|
body.keys.should =~ expected_fields
any_board_json
end
the_new_board = Board.new 'id' => "xxx"
the_new_board.save!
end
it "mutates the current instance" do
Client.stub(:put).and_return any_board_json
board = Board.new 'id' => "xxx"
the_result_of_save = board.save!
the_result_of_save.should equal board
end
it "uses the correct resource" do
expected_resource_id = "xxx_board_id_xxx"
Client.should_receive(:put) do |path, anything|
path.should =~ /#{expected_resource_id}\/$/
any_board_json
end
the_new_board = Board.new 'id' => expected_resource_id
the_new_board.save!
end
it "saves OR updates depending on whether or not it has an id set"
end
describe "Repository" do
include Helpers
let(:any_board_json) do
JSON.generate(boards_details.first)
end
it "creates a new board with whatever attributes are supplied " do
expected_attributes = { :name => "Any new board name", :description => "Any new board desription" }
Client.should_receive(:post).with(anything, expected_attributes).and_return any_board_json
Board.create expected_attributes
end
it "posts to the boards collection" do
Client.should_receive(:post).with("/boards/", anything).and_return any_board_json
Board.create :xxx => ""
end
it "returns a board" do
Client.stub(:post).with("/boards/", anything).and_return any_board_json
the_new_board = Board.create :xxx => ""
the_new_board.should be_a Board
end
it "at least name is required"
end
end