ruby-trello 2.3.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -2
  3. data/lib/trello.rb +13 -7
  4. data/lib/trello/action.rb +27 -21
  5. data/lib/trello/attachment.rb +40 -27
  6. data/lib/trello/basic_data.rb +104 -9
  7. data/lib/trello/board.rb +88 -102
  8. data/lib/trello/card.rb +34 -235
  9. data/lib/trello/checklist.rb +17 -71
  10. data/lib/trello/comment.rb +32 -22
  11. data/lib/trello/cover_image.rb +20 -0
  12. data/lib/trello/custom_field.rb +31 -84
  13. data/lib/trello/custom_field_item.rb +36 -58
  14. data/lib/trello/custom_field_option.rb +40 -13
  15. data/lib/trello/item.rb +27 -16
  16. data/lib/trello/item_state.rb +7 -15
  17. data/lib/trello/json_utils.rb +1 -1
  18. data/lib/trello/label.rb +14 -101
  19. data/lib/trello/label_name.rb +22 -25
  20. data/lib/trello/list.rb +31 -44
  21. data/lib/trello/member.rb +77 -32
  22. data/lib/trello/notification.rb +27 -20
  23. data/lib/trello/organization.rb +53 -25
  24. data/lib/trello/plugin_datum.rb +11 -16
  25. data/lib/trello/schema.rb +31 -0
  26. data/lib/trello/schema/attribute/base.rb +79 -0
  27. data/lib/trello/schema/attribute/board_pref.rb +45 -0
  28. data/lib/trello/schema/attribute/custom_field_display.rb +45 -0
  29. data/lib/trello/schema/attribute/default.rb +45 -0
  30. data/lib/trello/schema/attribute_builder.rb +42 -0
  31. data/lib/trello/schema/attribute_registration.rb +47 -0
  32. data/lib/trello/schema/serializer/default.rb +17 -0
  33. data/lib/trello/schema/serializer/labels.rb +23 -0
  34. data/lib/trello/schema/serializer/time.rb +25 -0
  35. data/lib/trello/schema/serializer/webhooks.rb +25 -0
  36. data/lib/trello/token.rb +15 -12
  37. data/lib/trello/webhook.rb +18 -71
  38. data/spec/action_spec.rb +1 -2
  39. data/spec/board_spec.rb +43 -103
  40. data/spec/card_spec.rb +51 -50
  41. data/spec/cassettes/action_find_with_id_and_get_all_fields.yml +104 -0
  42. data/spec/cassettes/board_find_with_id_and_get_all_fields.yml +96 -0
  43. data/spec/cassettes/board_find_with_id_and_get_specific_fields.yml +96 -0
  44. data/spec/cassettes/can_add_a_member_to_a_board.yml +191 -0
  45. data/spec/cassettes/can_arvhice_all_cards_of_list.yml +397 -0
  46. data/spec/cassettes/can_get_actions_of_board.yml +188 -0
  47. data/spec/cassettes/can_get_actions_of_list.yml +202 -0
  48. data/spec/cassettes/can_get_actions_of_members.yml +199 -0
  49. data/spec/cassettes/can_get_actions_of_organization.yml +201 -0
  50. data/spec/cassettes/can_get_boards_of_custom_field.yml +198 -0
  51. data/spec/cassettes/can_get_boards_of_label.yml +197 -0
  52. data/spec/cassettes/can_get_boards_of_organization.yml +207 -0
  53. data/spec/cassettes/can_get_cards_of_board.yml +193 -0
  54. data/spec/cassettes/can_get_cards_of_list.yml +201 -0
  55. data/spec/cassettes/can_get_cards_of_member.yml +204 -0
  56. data/spec/cassettes/can_get_checklists_of_board.yml +187 -0
  57. data/spec/cassettes/can_get_custom_field_options_of_custom_field.yml +197 -0
  58. data/spec/cassettes/can_get_custom_fields_of_board.yml +187 -0
  59. data/spec/cassettes/can_get_label_names_of_board.yml +187 -0
  60. data/spec/cassettes/can_get_labels_of_board.yml +187 -0
  61. data/spec/cassettes/can_get_lists_of_board.yml +187 -0
  62. data/spec/cassettes/can_get_members_of_board.yml +188 -0
  63. data/spec/cassettes/can_get_members_of_organization.yml +200 -0
  64. data/spec/cassettes/can_get_notifications_of_member.yml +199 -0
  65. data/spec/cassettes/can_get_organization_of_board.yml +189 -0
  66. data/spec/cassettes/can_get_organizations_of_member.yml +203 -0
  67. data/spec/cassettes/can_get_plugin_data_of_board.yml +187 -0
  68. data/spec/cassettes/can_move_all_cards_to_another_list.yml +886 -0
  69. data/spec/cassettes/can_success_create_a_board.yml +98 -0
  70. data/spec/cassettes/can_success_create_a_board_with_full_parameters.yml +97 -0
  71. data/spec/cassettes/can_success_create_a_board_without_clone_from_other.yml +98 -0
  72. data/spec/cassettes/can_success_create_a_card_when_due_is_datetime.yml +98 -0
  73. data/spec/cassettes/can_success_create_a_card_when_due_is_time.yml +98 -0
  74. data/spec/cassettes/can_success_create_a_checklist.yml +102 -0
  75. data/spec/cassettes/can_success_create_a_custom_field.yml +102 -0
  76. data/spec/cassettes/can_success_create_a_custom_field_option.yml +102 -0
  77. data/spec/cassettes/can_success_create_a_label.yml +102 -0
  78. data/spec/cassettes/can_success_create_a_list.yml +102 -0
  79. data/spec/cassettes/can_success_create_a_list_with_full_parameters.yml +102 -0
  80. data/spec/cassettes/can_success_create_a_organization.yml +104 -0
  81. data/spec/cassettes/can_success_create_a_webhook.yml +102 -0
  82. data/spec/cassettes/can_success_delete_a_custom_field_option.yml +389 -0
  83. data/spec/cassettes/can_success_delete_checklist.yml +284 -0
  84. data/spec/cassettes/can_success_get_card_of_board_by_card_id.yml +188 -0
  85. data/spec/cassettes/can_success_remove_member_from_board.yml +186 -0
  86. data/spec/cassettes/can_success_return_all_boards_of_current_user.yml +195 -0
  87. data/spec/cassettes/can_success_upate_a_board.yml +191 -0
  88. data/spec/cassettes/can_success_upate_a_list.yml +296 -0
  89. data/spec/cassettes/can_success_update_bong_a_board.yml +39 -39
  90. data/spec/cassettes/can_success_update_bong_a_board_with_specific_fields.yml +284 -0
  91. data/spec/cassettes/can_success_update_bong_a_checklist_with_specific_fields.yml +296 -0
  92. data/spec/cassettes/can_success_update_bong_a_custom_field.yml +200 -0
  93. data/spec/cassettes/can_success_update_bong_a_label.yml +200 -0
  94. data/spec/cassettes/can_success_update_bong_a_list.yml +199 -0
  95. data/spec/cassettes/can_success_update_bong_a_list_with_specific_fields.yml +296 -0
  96. data/spec/cassettes/can_success_update_bong_a_organization.yml +203 -0
  97. data/spec/cassettes/can_success_update_bong_a_webhook.yml +296 -0
  98. data/spec/cassettes/checklist_can_add_an_item.yml +296 -0
  99. data/spec/cassettes/checklist_can_update_the_item_state.yml +296 -0
  100. data/spec/cassettes/checklist_find_with_id_and_get_all_fields.yml +100 -0
  101. data/spec/cassettes/custom_field_find_with_id_and_get_all_fields.yml +100 -0
  102. data/spec/cassettes/custom_field_find_with_id_and_get_specific_fields.yml +100 -0
  103. data/spec/cassettes/custom_field_item_save_1.yml +1 -1
  104. data/spec/cassettes/custom_field_item_save_2.yml +1 -1
  105. data/spec/cassettes/custom_field_option_find_with_id.yml +100 -0
  106. data/spec/cassettes/get_board_of_list.yml +197 -0
  107. data/spec/cassettes/get_boards_of_member.yml +207 -0
  108. data/spec/cassettes/label_delete.yml +285 -0
  109. data/spec/cassettes/label_find_with_id.yml +100 -0
  110. data/spec/cassettes/list_find_with_id_and_get_all_fields.yml +100 -0
  111. data/spec/cassettes/list_find_with_id_and_get_specific_fields.yml +100 -0
  112. data/spec/cassettes/member_find_with_id_and_get_all_fields.yml +101 -0
  113. data/spec/cassettes/member_find_with_id_and_get_specific_fields.yml +100 -0
  114. data/spec/cassettes/notification_find_with_id.yml +103 -0
  115. data/spec/cassettes/organization_find_with_id_and_get_all_fields.yml +102 -0
  116. data/spec/cassettes/organization_find_with_id_and_get_specific_fields.yml +100 -0
  117. data/spec/cassettes/token_find_with_token_string.yml +100 -0
  118. data/spec/cassettes/webhook_delete.yml +286 -0
  119. data/spec/cassettes/webhook_find_with_id.yml +100 -0
  120. data/spec/checklist_spec.rb +27 -43
  121. data/spec/custom_field_item_spec.rb +2 -2
  122. data/spec/custom_field_option_spec.rb +2 -2
  123. data/spec/custom_field_spec.rb +25 -13
  124. data/spec/integration/action/find_spec.rb +23 -0
  125. data/spec/integration/basic_data/many_spec.rb +4 -0
  126. data/spec/integration/basic_data/schema_spec.rb +156 -0
  127. data/spec/integration/board/add_member_spec.rb +21 -0
  128. data/spec/integration/board/all_spec.rb +20 -0
  129. data/spec/integration/board/associations/actions_spec.rb +18 -0
  130. data/spec/integration/board/associations/cards_spec.rb +18 -0
  131. data/spec/integration/board/associations/checklists_spec.rb +18 -0
  132. data/spec/integration/board/associations/custom_fields_spec.rb +18 -0
  133. data/spec/integration/board/associations/label_names_spec.rb +17 -0
  134. data/spec/integration/board/associations/labels_spec.rb +18 -0
  135. data/spec/integration/board/associations/lists_spec.rb +18 -0
  136. data/spec/integration/board/associations/members_spec.rb +18 -0
  137. data/spec/integration/board/associations/organization_spec.rb +19 -0
  138. data/spec/integration/board/associations/plugin_data_spec.rb +18 -0
  139. data/spec/integration/board/create_spec.rb +95 -0
  140. data/spec/integration/board/find_card_spec.rb +18 -0
  141. data/spec/integration/board/find_spec.rb +42 -0
  142. data/spec/integration/board/remove_member_spec.rb +21 -0
  143. data/spec/integration/board/save_spec.rb +37 -0
  144. data/spec/integration/board/update!_spec.rb +33 -2
  145. data/spec/integration/card/associations/plugin_data_spec.rb +1 -1
  146. data/spec/integration/card/create_spec.rb +36 -2
  147. data/spec/integration/card/find_spec.rb +1 -1
  148. data/spec/integration/card/save_spec.rb +2 -2
  149. data/spec/integration/checklist/add_item_spec.rb +20 -0
  150. data/spec/integration/checklist/create_spec.rb +23 -0
  151. data/spec/integration/checklist/delete_spec.rb +17 -0
  152. data/spec/integration/checklist/find_spec.rb +22 -0
  153. data/spec/integration/checklist/update!_spec.rb +21 -0
  154. data/spec/integration/checklist/update_item_state_spec.rb +20 -0
  155. data/spec/integration/custom_field/association/board_spec.rb +18 -0
  156. data/spec/integration/custom_field/association/custom_field_options_spec.rb +18 -0
  157. data/spec/integration/custom_field/create_spec.rb +29 -0
  158. data/spec/integration/custom_field/find_spec.rb +41 -0
  159. data/spec/integration/custom_field/update!_spec.rb +25 -0
  160. data/spec/integration/custom_field_option/create_spec.rb +23 -0
  161. data/spec/integration/custom_field_option/delete_spec.rb +19 -0
  162. data/spec/integration/custom_field_option/find_spec.rb +21 -0
  163. data/spec/integration/label/association/board_spec.rb +18 -0
  164. data/spec/integration/label/create_spec.rb +23 -0
  165. data/spec/integration/label/delete_spec.rb +21 -0
  166. data/spec/integration/label/find_spec.rb +20 -0
  167. data/spec/integration/label/update!_spec.rb +25 -0
  168. data/spec/integration/list/archive_all_cards_spec.rb +20 -0
  169. data/spec/integration/list/associations/actions_spec.rb +18 -0
  170. data/spec/integration/list/associations/board_spec.rb +18 -0
  171. data/spec/integration/list/associations/cards_spec.rb +18 -0
  172. data/spec/integration/list/create_spec.rb +44 -0
  173. data/spec/integration/list/find_spec.rb +37 -0
  174. data/spec/integration/list/move_all_cards_spec.rb +31 -0
  175. data/spec/integration/list/save_spec.rb +40 -0
  176. data/spec/integration/list/update!_spec.rb +43 -0
  177. data/spec/integration/member/associations/actions_spec.rb +17 -0
  178. data/spec/integration/member/associations/boards_spec.rb +18 -0
  179. data/spec/integration/member/associations/cards_spec.rb +18 -0
  180. data/spec/integration/member/associations/notifications_spec.rb +18 -0
  181. data/spec/integration/member/associations/organizations_spec.rb +18 -0
  182. data/spec/integration/member/find_spec.rb +39 -0
  183. data/spec/integration/member/update!_spec.rb +18 -0
  184. data/spec/integration/notification/find_spec.rb +27 -0
  185. data/spec/integration/organization/associations/actions_spec.rb +18 -0
  186. data/spec/integration/organization/associations/boards_spec.rb +18 -0
  187. data/spec/integration/organization/associations/members_spec.rb +18 -0
  188. data/spec/integration/organization/create_spec.rb +23 -0
  189. data/spec/integration/organization/find_spec.rb +37 -0
  190. data/spec/integration/organization/update!_spec.rb +28 -0
  191. data/spec/integration/token/find_spec.rb +24 -0
  192. data/spec/integration/webhook/create_spec.rb +27 -0
  193. data/spec/integration/webhook/delete_spec.rb +21 -0
  194. data/spec/integration/webhook/find_spec.rb +22 -0
  195. data/spec/integration/webhook/update!_spec.rb +24 -0
  196. data/spec/item_spec.rb +2 -2
  197. data/spec/label_spec.rb +31 -33
  198. data/spec/list_spec.rb +32 -14
  199. data/spec/notification_spec.rb +3 -3
  200. data/spec/organization_spec.rb +6 -5
  201. data/spec/spec_helper.rb +22 -14
  202. data/spec/token_spec.rb +10 -11
  203. data/spec/unit/trello/basic_data_spec.rb +67 -8
  204. data/spec/unit/trello/board/new_spec.rb +370 -0
  205. data/spec/unit/trello/board/save_spec.rb +49 -0
  206. data/spec/unit/trello/board/update_fields_spec.rb +129 -0
  207. data/spec/unit/trello/board/update_spec.rb +197 -0
  208. data/spec/unit/trello/member/new_spec.rb +62 -0
  209. data/spec/unit/trello/member/update_fields_spec.rb +80 -0
  210. data/spec/unit/trello/schema/attribute/base_spec.rb +349 -0
  211. data/spec/unit/trello/schema/attribute/board_pref_spec.rb +208 -0
  212. data/spec/unit/trello/schema/attribute/default_spec.rb +236 -0
  213. data/spec/unit/trello/schema/attribute_builder_spec.rb +55 -0
  214. data/spec/unit/trello/schema/attribute_registration_spec.rb +59 -0
  215. data/spec/unit/trello/schema/serializer/default_spec.rb +19 -0
  216. data/spec/unit/trello/schema/serializer/time_spec.rb +39 -0
  217. data/spec/unit/trello/schema_spec.rb +25 -0
  218. data/spec/webhook_spec.rb +23 -7
  219. metadata +422 -102
  220. data/lib/trello/register_attributes.rb +0 -54
  221. data/spec/integration/basic_data/register_attributes_spec.rb +0 -75
@@ -0,0 +1,370 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Trello::Board#new' do
4
+
5
+ let(:board) { Trello::Board.new(data) }
6
+
7
+ describe 'parse #id (writable)' do
8
+ context 'with Trello API respone data' do
9
+ let(:data) { { 'id' => '5e93ba98614ac22d22f085c4' } }
10
+
11
+ it "parse from data['id']" do
12
+ expect(board.id).to eq('5e93ba98614ac22d22f085c4')
13
+ end
14
+ end
15
+
16
+ context 'with Ruby-like data' do
17
+ let(:data) { { id: '5e93ba98614ac22d22f085c4' } }
18
+
19
+ it 'parse from data[:id]' do
20
+ expect(board.id).to eq('5e93ba98614ac22d22f085c4')
21
+ end
22
+ end
23
+ end
24
+
25
+ describe 'parse #name (writable)' do
26
+ context 'with Trello API respone data' do
27
+ let(:data) { { 'name' => 'Board Name' } }
28
+
29
+ it "parse from data['name']" do
30
+ expect(board.name).to eq('Board Name')
31
+ end
32
+ end
33
+
34
+ context 'with Ruby-like data' do
35
+ let(:data) { { name: 'Board Name' } }
36
+
37
+ it 'parse from data[:name]' do
38
+ expect(board.name).to eq('Board Name')
39
+ end
40
+ end
41
+ end
42
+
43
+ describe 'parse #description (writable)' do
44
+ context 'with Trello API respone data' do
45
+ let(:data) { { 'desc' => 'Board Name' } }
46
+
47
+ it "parse from data['desc']" do
48
+ expect(board.description).to eq('Board Name')
49
+ end
50
+ end
51
+
52
+ context 'with Ruby-like data' do
53
+ let(:data) { { description: 'Board Name' } }
54
+
55
+ it 'parse from data[:desc]' do
56
+ expect(board.description).to eq('Board Name')
57
+ end
58
+ end
59
+ end
60
+
61
+ describe 'parse #description_data (readonly)' do
62
+ context 'with Trello API respone data' do
63
+ let(:data) { { 'descData' => 'description data...' } }
64
+
65
+ it "parse from data['descData']" do
66
+ expect(board.description_data).to eq('description data...')
67
+ end
68
+ end
69
+
70
+ context 'with Ruby-like data' do
71
+ let(:data) { { description_data: 'description data...' } }
72
+
73
+ it "will parse from data[:description_data]" do
74
+ expect(board.description_data).to eq('description data...')
75
+ end
76
+ end
77
+ end
78
+
79
+ describe 'parse #closed (writable)' do
80
+ context 'with Trello API respone data' do
81
+ let(:data) { { 'closed' => true } }
82
+
83
+ it "parse from data['closed']" do
84
+ expect(board.closed).to eq(true)
85
+ end
86
+ end
87
+
88
+ context 'with Ruby-like data' do
89
+ let(:data) { { closed: true } }
90
+
91
+ it 'parse from data[:description_data]' do
92
+ expect(board.closed).to eq(true)
93
+ end
94
+ end
95
+ end
96
+
97
+ describe 'parse #organization_id (writable)' do
98
+ context 'with Trello API respone data' do
99
+ let(:data) { { 'idOrganization' => 'abc123' } }
100
+
101
+ it "parse from data['idOrganization']" do
102
+ expect(board.organization_id).to eq('abc123')
103
+ end
104
+ end
105
+
106
+ context 'with Ruby-like data' do
107
+ let(:data) { { organization_id: 'abc123' } }
108
+
109
+ it 'parse from data[:description_data]' do
110
+ expect(board.organization_id).to eq('abc123')
111
+ end
112
+ end
113
+ end
114
+
115
+ describe 'parse #enterprise_id (readonly)' do
116
+ context 'with Trello API respone data' do
117
+ let(:data) { { 'idEnterprise' => 'abc123' } }
118
+
119
+ it "parse from data['idEnterprise']" do
120
+ expect(board.enterprise_id).to eq('abc123')
121
+ end
122
+ end
123
+
124
+ context 'with Ruby-like data' do
125
+ let(:data) { { enterprise_id: 'abc123' } }
126
+
127
+ it "will parse from data[:enterprise_id]" do
128
+ expect(board.enterprise_id).to eq('abc123')
129
+ end
130
+ end
131
+ end
132
+
133
+ describe 'parse #pinned (readonly)' do
134
+ context 'with Trello API respone data' do
135
+ let(:data) { { 'pinned' => false } }
136
+
137
+ it "parse from data['pinned']" do
138
+ expect(board.pinned).to eq(false)
139
+ end
140
+ end
141
+
142
+ context 'with Ruby-like data' do
143
+ let(:data) { { pinned: false } }
144
+
145
+ it "won't parse from data[:pinned]" do
146
+ expect(board.pinned).to eq(false)
147
+ end
148
+ end
149
+ end
150
+
151
+ describe 'parse #url (readonly)' do
152
+ context 'with Trello API respone data' do
153
+ let(:data) { { 'url' => 'https://trello.com/b/y1TF9GTa/board-1' } }
154
+
155
+ it "parse from data['url']" do
156
+ expect(board.url).to eq('https://trello.com/b/y1TF9GTa/board-1')
157
+ end
158
+ end
159
+
160
+ context 'with Ruby-like data' do
161
+ let(:data) { { url: 'https://trello.com/b/y1TF9GTa/board-1' } }
162
+
163
+ it "won't parse from data[:url]" do
164
+ expect(board.url).to eq('https://trello.com/b/y1TF9GTa/board-1')
165
+ end
166
+ end
167
+ end
168
+
169
+ describe 'parse #short_url (readonly)' do
170
+ context 'with Trello API respone data' do
171
+ let(:data) { { 'shortUrl' => 'https://trello.com/b/y1TF9GTa' } }
172
+
173
+ it "parse from data['shortUrl']" do
174
+ expect(board.short_url).to eq('https://trello.com/b/y1TF9GTa')
175
+ end
176
+ end
177
+
178
+ context 'with Ruby-like data' do
179
+ let(:data) { { short_url: 'https://trello.com/b/y1TF9GTa' } }
180
+
181
+ it "parse from data[:short_url]" do
182
+ expect(board.short_url).to eq('https://trello.com/b/y1TF9GTa')
183
+ end
184
+ end
185
+ end
186
+
187
+ # it "parse #label_names from response['labelNames']" do
188
+ # end
189
+
190
+ describe 'parse #visibility_level (writable)' do
191
+ context 'with Trello API respone data' do
192
+ let(:data) { { 'prefs' => { 'permissionLevel' => 'org' } } }
193
+
194
+ it "parse from data['prefs']['permissionLevel']" do
195
+ expect(board.visibility_level).to eq('org')
196
+ end
197
+ end
198
+
199
+ context 'with Ruby-like data' do
200
+ let(:data) { { visibility_level: 'org' } }
201
+
202
+ it 'parse from data[:visibility_level]' do
203
+ expect(board.visibility_level).to eq('org')
204
+ end
205
+ end
206
+ end
207
+
208
+ describe 'parse #voting_permission_level (writable)' do
209
+ context 'with Trello API respone data' do
210
+ let(:data) { { 'prefs' => { 'voting' => 'org' } } }
211
+
212
+ it "parse from data['prefs']['voting']" do
213
+ expect(board.voting_permission_level).to eq('org')
214
+ end
215
+ end
216
+
217
+ context 'with Ruby-like data' do
218
+ let(:data) { { voting_permission_level: 'org' } }
219
+
220
+ it 'parse from data[:voting_permission_level]' do
221
+ expect(board.voting_permission_level).to eq('org')
222
+ end
223
+ end
224
+ end
225
+
226
+ describe 'parse #comment_permission_level (writable)' do
227
+ context 'with Trello API respone data' do
228
+ let(:data) { { 'prefs' => { 'comments' => 'org' } } }
229
+
230
+ it "parse from data['prefs']['comments']" do
231
+ expect(board.comment_permission_level).to eq('org')
232
+ end
233
+ end
234
+
235
+ context 'with Ruby-like data' do
236
+ let(:data) { { comment_permission_level: 'org' } }
237
+
238
+ it 'parse from data[:voting_permission_level]' do
239
+ expect(board.comment_permission_level).to eq('org')
240
+ end
241
+ end
242
+ end
243
+
244
+ describe 'parse #invitation_permission_level (writable)' do
245
+ context 'with Trello API respone data' do
246
+ let(:data) { { 'prefs' => { 'invitations' => 'org' } } }
247
+
248
+ it "parse from data['prefs']['invitations']" do
249
+ expect(board.invitation_permission_level).to eq('org')
250
+ end
251
+ end
252
+
253
+ context 'with Ruby-like data' do
254
+ let(:data) { { invitation_permission_level: 'org' } }
255
+
256
+ it 'parse from data[:invitation_permission_level]' do
257
+ expect(board.invitation_permission_level).to eq('org')
258
+ end
259
+ end
260
+ end
261
+
262
+ describe 'parse #enable_self_join (writable)' do
263
+ context 'with Trello API respone data' do
264
+ let(:data) { { 'prefs' => { 'selfJoin' => true } } }
265
+
266
+ it "parse from data['prefs']['selfJoin']" do
267
+ expect(board.enable_self_join).to eq(true)
268
+ end
269
+ end
270
+
271
+ context 'with Ruby-like data' do
272
+ let(:data) { { enable_self_join: true } }
273
+
274
+ it 'parse from data[:enable_self_join]' do
275
+ expect(board.enable_self_join).to eq(true)
276
+ end
277
+ end
278
+ end
279
+
280
+ describe 'parse #enable_card_covers (writable)' do
281
+ context 'with Trello API respone data' do
282
+ let(:data) { { 'prefs' => { 'cardCovers' => true } } }
283
+
284
+ it "parse from data['prefs']['cardCovers']" do
285
+ expect(board.enable_card_covers).to eq(true)
286
+ end
287
+ end
288
+
289
+ context 'with Ruby-like data' do
290
+ let(:data) { { enable_card_covers: true } }
291
+
292
+ it 'parse from data[:enable_card_covers]' do
293
+ expect(board.enable_card_covers).to eq(true)
294
+ end
295
+ end
296
+ end
297
+
298
+ describe 'parse #background_color (writable)' do
299
+ context 'with Trello API respone data' do
300
+ let(:data) { { 'prefs' => { 'background' => 'blue' } } }
301
+
302
+ it "parse from data['prefs']['background']" do
303
+ expect(board.background_color).to eq('blue')
304
+ end
305
+ end
306
+
307
+ context 'with Ruby-like data' do
308
+ let(:data) { { background_color: 'blue' } }
309
+
310
+ it 'parse from data[:background_color]' do
311
+ expect(board.background_color).to eq('blue')
312
+ end
313
+ end
314
+ end
315
+
316
+ describe 'parse #background_image (writable)' do
317
+ context 'with Trello API respone data' do
318
+ let(:data) { { 'prefs' => { 'backgroundImage' => 'https://image_url' } } }
319
+
320
+ it "parse from data['prefs']['background']" do
321
+ expect(board.background_image).to eq('https://image_url')
322
+ end
323
+ end
324
+
325
+ context 'with Ruby-like data' do
326
+ let(:data) { { background_image: 'https://image_url' } }
327
+
328
+ it 'parse from data[:background_image]' do
329
+ expect(board.background_image).to eq('https://image_url')
330
+ end
331
+ end
332
+ end
333
+
334
+ describe 'parse #card_aging_type (writable)' do
335
+ context 'with Trello API respone data' do
336
+ let(:data) { { 'prefs' => { 'cardAging' => 'pirate' } } }
337
+
338
+ it "parse from data['prefs']['cardAging']" do
339
+ expect(board.card_aging_type).to eq('pirate')
340
+ end
341
+ end
342
+
343
+ context 'with Ruby-like data' do
344
+ let(:data) { { card_aging_type: 'pirate' } }
345
+
346
+ it 'parse from data[:card_aging_type]' do
347
+ expect(board.card_aging_type).to eq('pirate')
348
+ end
349
+ end
350
+ end
351
+
352
+ describe 'parse #prefs (readonly)' do
353
+ context 'with Trello API respone data' do
354
+ let(:data) { { 'prefs' => { 'permissionLevel' => 'org' } } }
355
+
356
+ it "parse from data['prefs']" do
357
+ expect(board.prefs).to eq({ 'permissionLevel' => 'org' })
358
+ end
359
+ end
360
+
361
+ context 'with Ruby-like data' do
362
+ let(:data) { { prefs: { 'permissionLevel' => 'org' } } }
363
+
364
+ it 'will parse from data[:prefs]' do
365
+ expect(board.prefs).to eq({ 'permissionLevel' => 'org' })
366
+ end
367
+ end
368
+ end
369
+
370
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Trello::Board' do
4
+
5
+ context 'when id exists' do
6
+ let(:board) { Trello::Board.new(id: 1) }
7
+
8
+ it 'call #update! on board' do
9
+ expect(board).to receive(:update!)
10
+
11
+ board.save
12
+ end
13
+ end
14
+
15
+ context 'when id does not exist' do
16
+ let(:board) { Trello::Board.new(
17
+ name: 'IT 1',
18
+ description: 'description ...',
19
+ organization_id: 1111,
20
+ visibility_level: 'org',
21
+ voting_permission_level: 'org',
22
+ comment_permission_level: 'org',
23
+ invitation_permission_level: 'org',
24
+ enable_self_join: true,
25
+ enable_card_covers: true,
26
+ background_color: 'blue',
27
+ card_aging_type: 'pirate'
28
+ ) }
29
+
30
+ it 'call #create on board with correct parameters' do
31
+ expect(board).to receive(:post).with('/boards', {
32
+ 'name' => 'IT 1',
33
+ 'desc' => 'description ...',
34
+ 'idOrganization' => 1111,
35
+ 'prefs_permissionLevel' => 'org',
36
+ 'prefs_voting' => 'org',
37
+ 'prefs_comments' => 'org',
38
+ 'prefs_invitations' => 'org',
39
+ 'prefs_selfJoin' => true,
40
+ 'prefs_cardCovers' => true,
41
+ 'prefs_background' => 'blue',
42
+ 'prefs_cardAging' => 'pirate'
43
+ })
44
+
45
+ board.save
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,129 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Trello::Board#update_fields' do
4
+
5
+ let(:board_params) { {
6
+ 'id' => '5e93ba403f1ab3603ba81a09',
7
+ 'name' => 'IT 1',
8
+ 'desc' => 'This is a test board called IT 1',
9
+ 'descData' => { 'emoji': {} },
10
+ 'closed' => false,
11
+ 'idOrganization' => "5e93ba154634282b6df23bcc",
12
+ 'idEnterprise' => nil,
13
+ 'pinned' => false,
14
+ 'url' => 'https://trello.com/b/0zx7ive1/it-1',
15
+ 'shortUrl' => 'https://trello.com/b/0zx7ive1',
16
+ 'prefs' => {
17
+ 'permissionLevel' => 'org',
18
+ 'voting' => 'disabled',
19
+ 'comments' => 'members',
20
+ 'invitations' => 'members',
21
+ 'selfJoin' => true,
22
+ 'cardCovers' => true,
23
+ 'cardAging' => 'regular',
24
+ 'background' => 'blue' ,
25
+ 'backgroundImage' => nil
26
+ }
27
+ } }
28
+
29
+ let(:board) { Trello::Board.new(board_params) }
30
+
31
+ context 'when the fields argument is empty' do
32
+ let(:fields) { {} }
33
+
34
+ it 'board does not set any fields' do
35
+ board.update_fields(fields)
36
+
37
+ expect(board.changed?).to be_falsy
38
+ expect(board.id).to eq(board_params['id'])
39
+ expect(board.name).to eq(board_params['name'])
40
+ expect(board.description).to eq(board_params['desc'])
41
+ expect(board.description_data).to match_hash_with_indifferent_access(board_params['descData'])
42
+ expect(board.closed).to eq(board_params['closed'])
43
+ expect(board.organization_id).to eq(board_params['idOrganization'])
44
+ expect(board.enterprise_id).to eq(board_params['idEnterprise'])
45
+ expect(board.pinned).to eq(board_params['pinned'])
46
+ expect(board.url).to eq(board_params['url'])
47
+ expect(board.short_url).to eq(board_params['shortUrl'])
48
+ expect(board.visibility_level).to eq(board_params['prefs']['permissionLevel'])
49
+ expect(board.voting_permission_level).to eq(board_params['prefs']['voting'])
50
+ expect(board.comment_permission_level).to eq(board_params['prefs']['comments'])
51
+ expect(board.invitation_permission_level).to eq(board_params['prefs']['invitations'])
52
+ expect(board.enable_self_join).to eq(board_params['prefs']['selfJoin'])
53
+ expect(board.enable_card_covers).to eq(board_params['prefs']['cardCovers'])
54
+ expect(board.card_aging_type).to eq(board_params['prefs']['cardAging'])
55
+ expect(board.background_color).to eq(board_params['prefs']['background'])
56
+ expect(board.background_image).to eq(board_params['prefs']['backgroundImage'])
57
+ end
58
+ end
59
+
60
+ context 'when the fields argument has at least one field' do
61
+
62
+ context 'and the field does changed' do
63
+ let(:fields) { { description: 'Awesome things have changed.' } }
64
+
65
+ it 'board does set the changed fields' do
66
+ board.update_fields(fields)
67
+
68
+ expect(board.description).to eq('Awesome things have changed.')
69
+ end
70
+
71
+ it 'board has been mark as changed' do
72
+ board.update_fields(fields)
73
+
74
+ expect(board.changed?).to be_truthy
75
+ end
76
+ end
77
+
78
+ context "and the field doesn't changed" do
79
+ let(:fields) { { desc: board_params['desc'] } }
80
+
81
+ it "board attributes doesn't changed" do
82
+ board.update_fields(fields)
83
+
84
+ expect(board.description).to eq(board_params['desc'])
85
+ end
86
+
87
+ it "board hasn't been mark as changed" do
88
+ board.update_fields(fields)
89
+
90
+ expect(board.changed?).to be_falsy
91
+ end
92
+ end
93
+
94
+ context "and the field isn't a correct attributes of the card" do
95
+ let(:fields) { { abc: 'abc' } }
96
+
97
+ it "card attributes doesn't changed" do
98
+ board.update_fields(fields)
99
+
100
+ expect(board.id).to eq(board_params['id'])
101
+ expect(board.name).to eq(board_params['name'])
102
+ expect(board.description).to eq(board_params['desc'])
103
+ expect(board.description_data).to match_hash_with_indifferent_access(board_params['descData'])
104
+ expect(board.closed).to eq(board_params['closed'])
105
+ expect(board.organization_id).to eq(board_params['idOrganization'])
106
+ expect(board.enterprise_id).to eq(board_params['idEnterprise'])
107
+ expect(board.pinned).to eq(board_params['pinned'])
108
+ expect(board.url).to eq(board_params['url'])
109
+ expect(board.short_url).to eq(board_params['shortUrl'])
110
+ expect(board.visibility_level).to eq(board_params['prefs']['permissionLevel'])
111
+ expect(board.voting_permission_level).to eq(board_params['prefs']['voting'])
112
+ expect(board.comment_permission_level).to eq(board_params['prefs']['comments'])
113
+ expect(board.invitation_permission_level).to eq(board_params['prefs']['invitations'])
114
+ expect(board.enable_self_join).to eq(board_params['prefs']['selfJoin'])
115
+ expect(board.enable_card_covers).to eq(board_params['prefs']['cardCovers'])
116
+ expect(board.card_aging_type).to eq(board_params['prefs']['cardAging'])
117
+ expect(board.background_color).to eq(board_params['prefs']['background'])
118
+ expect(board.background_image).to eq(board_params['prefs']['backgroundImage'])
119
+ end
120
+
121
+ it "card hasn't been mark as changed" do
122
+ board.update_fields(fields)
123
+
124
+ expect(board.changed?).to be_falsy
125
+ end
126
+ end
127
+ end
128
+
129
+ end