ruby-trello 2.0.1 → 3.0.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.
Files changed (305) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +61 -10
  3. data/lib/trello.rb +57 -36
  4. data/lib/trello/action.rb +31 -23
  5. data/lib/trello/association_builder/has_many.rb +17 -0
  6. data/lib/trello/association_builder/has_one.rb +16 -0
  7. data/lib/trello/association_fetcher/has_many.rb +26 -0
  8. data/lib/trello/association_fetcher/has_many/fetch.rb +47 -0
  9. data/lib/trello/association_fetcher/has_many/params.rb +56 -0
  10. data/lib/trello/association_fetcher/has_one.rb +25 -0
  11. data/lib/trello/association_fetcher/has_one/fetch.rb +49 -0
  12. data/lib/trello/association_fetcher/has_one/params.rb +36 -0
  13. data/lib/trello/association_infer_tool.rb +13 -0
  14. data/lib/trello/association_proxy.rb +1 -1
  15. data/lib/trello/attachment.rb +40 -27
  16. data/lib/trello/basic_data.rb +112 -50
  17. data/lib/trello/board.rb +91 -101
  18. data/lib/trello/card.rb +53 -200
  19. data/lib/trello/checklist.rb +17 -71
  20. data/lib/trello/comment.rb +32 -22
  21. data/lib/trello/cover_image.rb +20 -0
  22. data/lib/trello/custom_field.rb +78 -0
  23. data/lib/trello/custom_field_item.rb +76 -0
  24. data/lib/trello/custom_field_option.rb +49 -0
  25. data/lib/trello/item.rb +27 -16
  26. data/lib/trello/item_state.rb +7 -15
  27. data/lib/trello/json_utils.rb +1 -1
  28. data/lib/trello/label.rb +15 -84
  29. data/lib/trello/label_name.rb +22 -25
  30. data/lib/trello/list.rb +31 -44
  31. data/lib/trello/member.rb +77 -31
  32. data/lib/trello/notification.rb +27 -20
  33. data/lib/trello/organization.rb +53 -25
  34. data/lib/trello/plugin_datum.rb +11 -16
  35. data/lib/trello/schema.rb +31 -0
  36. data/lib/trello/schema/attribute/base.rb +79 -0
  37. data/lib/trello/schema/attribute/board_pref.rb +45 -0
  38. data/lib/trello/schema/attribute/custom_field_display.rb +45 -0
  39. data/lib/trello/schema/attribute/default.rb +45 -0
  40. data/lib/trello/schema/attribute_builder.rb +42 -0
  41. data/lib/trello/schema/attribute_registration.rb +47 -0
  42. data/lib/trello/schema/serializer/default.rb +17 -0
  43. data/lib/trello/schema/serializer/labels.rb +23 -0
  44. data/lib/trello/schema/serializer/time.rb +25 -0
  45. data/lib/trello/schema/serializer/webhooks.rb +25 -0
  46. data/lib/trello/token.rb +15 -12
  47. data/lib/trello/webhook.rb +18 -71
  48. data/spec/action_spec.rb +2 -3
  49. data/spec/basic_data_spec.rb +58 -0
  50. data/spec/board_spec.rb +53 -100
  51. data/spec/card_spec.rb +177 -66
  52. data/spec/cassettes/action_find_with_id_and_get_all_fields.yml +104 -0
  53. data/spec/cassettes/board_find_with_id_and_get_all_fields.yml +96 -0
  54. data/spec/cassettes/board_find_with_id_and_get_specific_fields.yml +96 -0
  55. data/spec/cassettes/can_add_a_file_from_url_on_a_card.yml +189 -0
  56. data/spec/cassettes/can_add_a_file_on_a_card.yml +200 -0
  57. data/spec/cassettes/can_add_a_member_to_a_board.yml +191 -0
  58. data/spec/cassettes/can_add_a_member_to_a_card.yml +190 -0
  59. data/spec/cassettes/can_add_label_on_a_card.yml +281 -0
  60. data/spec/cassettes/can_arvhice_all_cards_of_list.yml +397 -0
  61. data/spec/cassettes/can_close_bong_a_card.yml +189 -0
  62. data/spec/cassettes/can_get_actions.yml +196 -0
  63. data/spec/cassettes/can_get_actions_of_board.yml +188 -0
  64. data/spec/cassettes/can_get_actions_of_list.yml +202 -0
  65. data/spec/cassettes/can_get_actions_of_members.yml +199 -0
  66. data/spec/cassettes/can_get_actions_of_organization.yml +201 -0
  67. data/spec/cassettes/can_get_attachments.yml +187 -0
  68. data/spec/cassettes/can_get_boards_of_custom_field.yml +198 -0
  69. data/spec/cassettes/can_get_boards_of_label.yml +197 -0
  70. data/spec/cassettes/can_get_boards_of_organization.yml +207 -0
  71. data/spec/cassettes/can_get_cards_of_board.yml +193 -0
  72. data/spec/cassettes/can_get_cards_of_list.yml +201 -0
  73. data/spec/cassettes/can_get_cards_of_member.yml +204 -0
  74. data/spec/cassettes/can_get_checklists_of_board.yml +187 -0
  75. data/spec/cassettes/can_get_comments.yml +193 -0
  76. data/spec/cassettes/can_get_custom_field_options_of_custom_field.yml +197 -0
  77. data/spec/cassettes/can_get_custom_fields_of_board.yml +187 -0
  78. data/spec/cassettes/can_get_label_names_of_board.yml +187 -0
  79. data/spec/cassettes/can_get_labels_of_board.yml +187 -0
  80. data/spec/cassettes/can_get_lists_of_board.yml +187 -0
  81. data/spec/cassettes/can_get_members_of_board.yml +188 -0
  82. data/spec/cassettes/can_get_members_of_organization.yml +200 -0
  83. data/spec/cassettes/can_get_notifications_of_member.yml +199 -0
  84. data/spec/cassettes/can_get_organization_of_board.yml +189 -0
  85. data/spec/cassettes/can_get_organizations_of_member.yml +203 -0
  86. data/spec/cassettes/can_get_plugin_data_of_board.yml +187 -0
  87. data/spec/cassettes/can_move_a_card_to_another_board_with_specific_list.yml +373 -0
  88. data/spec/cassettes/can_move_a_card_to_another_board_without_specific_list.yml +281 -0
  89. data/spec/cassettes/can_move_a_card_to_another_list.yml +281 -0
  90. data/spec/cassettes/can_move_all_cards_to_another_list.yml +886 -0
  91. data/spec/cassettes/can_remove_a_member_from_a_card.yml +185 -0
  92. data/spec/cassettes/can_remove_an_attachment_on_a_card.yml +277 -0
  93. data/spec/cassettes/can_remove_an_upvote_on_a_card.yml +465 -0
  94. data/spec/cassettes/can_remove_label_on_a_card.yml +279 -0
  95. data/spec/cassettes/can_success_add_comment_to_a_card.yml +196 -0
  96. data/spec/cassettes/can_success_copy_checklist_to_a_card.yml +281 -0
  97. data/spec/cassettes/can_success_copy_checklist_to_a_card_without_name_pos.yml +281 -0
  98. data/spec/cassettes/can_success_create_a_board.yml +98 -0
  99. data/spec/cassettes/can_success_create_a_board_with_full_parameters.yml +97 -0
  100. data/spec/cassettes/can_success_create_a_board_without_clone_from_other.yml +98 -0
  101. data/spec/cassettes/can_success_create_a_card.yml +99 -0
  102. data/spec/cassettes/can_success_create_a_card_when_due_is_datetime.yml +98 -0
  103. data/spec/cassettes/can_success_create_a_card_when_due_is_time.yml +98 -0
  104. data/spec/cassettes/can_success_create_a_checklist.yml +102 -0
  105. data/spec/cassettes/can_success_create_a_custom_field.yml +102 -0
  106. data/spec/cassettes/can_success_create_a_custom_field_option.yml +102 -0
  107. data/spec/cassettes/can_success_create_a_label.yml +102 -0
  108. data/spec/cassettes/can_success_create_a_list.yml +102 -0
  109. data/spec/cassettes/can_success_create_a_list_with_full_parameters.yml +102 -0
  110. data/spec/cassettes/can_success_create_a_organization.yml +104 -0
  111. data/spec/cassettes/can_success_create_a_webhook.yml +102 -0
  112. data/spec/cassettes/can_success_create_new_checklist_to_a_card.yml +189 -0
  113. data/spec/cassettes/can_success_delete_a_custom_field_option.yml +389 -0
  114. data/spec/cassettes/can_success_delete_card.yml +185 -0
  115. data/spec/cassettes/can_success_delete_checklist.yml +284 -0
  116. data/spec/cassettes/can_success_get_card_of_board_by_card_id.yml +188 -0
  117. data/spec/cassettes/can_success_remove_member_from_board.yml +186 -0
  118. data/spec/cassettes/can_success_return_all_boards_of_current_user.yml +195 -0
  119. data/spec/cassettes/can_success_upate_a_board.yml +191 -0
  120. data/spec/cassettes/can_success_upate_a_card.yml +189 -0
  121. data/spec/cassettes/can_success_upate_a_list.yml +296 -0
  122. data/spec/cassettes/can_success_update_bong_a_board.yml +283 -0
  123. data/spec/cassettes/can_success_update_bong_a_board_with_specific_fields.yml +284 -0
  124. data/spec/cassettes/can_success_update_bong_a_card.yml +191 -0
  125. data/spec/cassettes/can_success_update_bong_a_checklist_with_specific_fields.yml +296 -0
  126. data/spec/cassettes/can_success_update_bong_a_custom_field.yml +200 -0
  127. data/spec/cassettes/can_success_update_bong_a_label.yml +200 -0
  128. data/spec/cassettes/can_success_update_bong_a_list.yml +199 -0
  129. data/spec/cassettes/can_success_update_bong_a_list_with_specific_fields.yml +296 -0
  130. data/spec/cassettes/can_success_update_bong_a_organization.yml +203 -0
  131. data/spec/cassettes/can_success_update_bong_a_webhook.yml +296 -0
  132. data/spec/cassettes/can_upvote_on_a_card.yml +469 -0
  133. data/spec/cassettes/card_find_with_id_and_get_all_fields.yml +95 -0
  134. data/spec/cassettes/card_find_with_id_and_get_specific_fields.yml +96 -0
  135. data/spec/cassettes/checklist_can_add_an_item.yml +296 -0
  136. data/spec/cassettes/checklist_can_update_the_item_state.yml +296 -0
  137. data/spec/cassettes/checklist_find_with_id_and_get_all_fields.yml +100 -0
  138. data/spec/cassettes/custom_field_find_with_id_and_get_all_fields.yml +100 -0
  139. data/spec/cassettes/custom_field_find_with_id_and_get_specific_fields.yml +100 -0
  140. data/spec/cassettes/custom_field_item_save_1.yml +97 -0
  141. data/spec/cassettes/custom_field_item_save_2.yml +281 -0
  142. data/spec/cassettes/custom_field_option_find_with_id.yml +100 -0
  143. data/spec/cassettes/get_board_of_card.yml +187 -0
  144. data/spec/cassettes/get_board_of_list.yml +197 -0
  145. data/spec/cassettes/get_boards_of_member.yml +207 -0
  146. data/spec/cassettes/get_check_item_states_of_card.yml +188 -0
  147. data/spec/cassettes/get_checklists_of_card.yml +187 -0
  148. data/spec/cassettes/get_cover_image_of_card.yml +187 -0
  149. data/spec/cassettes/get_custom_field_items_of_card.yml +187 -0
  150. data/spec/cassettes/get_list_of_card.yml +188 -0
  151. data/spec/cassettes/get_lists.yml +187 -0
  152. data/spec/cassettes/get_members_of_card.yml +189 -0
  153. data/spec/cassettes/get_plugin_data_of_card.yml +187 -0
  154. data/spec/cassettes/get_voters_of_card.yml +188 -0
  155. data/spec/cassettes/label_delete.yml +285 -0
  156. data/spec/cassettes/label_find_with_id.yml +100 -0
  157. data/spec/cassettes/list_find_with_id_and_get_all_fields.yml +100 -0
  158. data/spec/cassettes/list_find_with_id_and_get_specific_fields.yml +100 -0
  159. data/spec/cassettes/member_find_with_id_and_get_all_fields.yml +101 -0
  160. data/spec/cassettes/member_find_with_id_and_get_specific_fields.yml +100 -0
  161. data/spec/cassettes/notification_find_with_id.yml +103 -0
  162. data/spec/cassettes/organization_find_with_id_and_get_all_fields.yml +102 -0
  163. data/spec/cassettes/organization_find_with_id_and_get_specific_fields.yml +100 -0
  164. data/spec/cassettes/remove_upvote_on_a_card_when_have_not_voted.yml +366 -0
  165. data/spec/cassettes/revote_on_a_card.yml +464 -0
  166. data/spec/cassettes/token_find_with_token_string.yml +100 -0
  167. data/spec/cassettes/webhook_delete.yml +286 -0
  168. data/spec/cassettes/webhook_find_with_id.yml +100 -0
  169. data/spec/checklist_spec.rb +27 -43
  170. data/spec/custom_field_item_spec.rb +192 -0
  171. data/spec/custom_field_option_spec.rb +49 -0
  172. data/spec/custom_field_spec.rb +273 -0
  173. data/spec/integration/action/find_spec.rb +23 -0
  174. data/spec/integration/basic_data/many_spec.rb +127 -0
  175. data/spec/integration/basic_data/one_spec.rb +84 -0
  176. data/spec/integration/basic_data/schema_spec.rb +156 -0
  177. data/spec/integration/board/add_member_spec.rb +21 -0
  178. data/spec/integration/board/all_spec.rb +20 -0
  179. data/spec/integration/board/associations/actions_spec.rb +18 -0
  180. data/spec/integration/board/associations/cards_spec.rb +18 -0
  181. data/spec/integration/board/associations/checklists_spec.rb +18 -0
  182. data/spec/integration/board/associations/custom_fields_spec.rb +18 -0
  183. data/spec/integration/board/associations/label_names_spec.rb +17 -0
  184. data/spec/integration/board/associations/labels_spec.rb +18 -0
  185. data/spec/integration/board/associations/lists_spec.rb +18 -0
  186. data/spec/integration/board/associations/members_spec.rb +18 -0
  187. data/spec/integration/board/associations/organization_spec.rb +19 -0
  188. data/spec/integration/board/associations/plugin_data_spec.rb +18 -0
  189. data/spec/integration/board/create_spec.rb +95 -0
  190. data/spec/integration/board/find_card_spec.rb +18 -0
  191. data/spec/integration/board/find_spec.rb +42 -0
  192. data/spec/integration/board/remove_member_spec.rb +21 -0
  193. data/spec/integration/board/save_spec.rb +37 -0
  194. data/spec/integration/board/update!_spec.rb +62 -0
  195. data/spec/integration/board_lists_spec.rb +21 -0
  196. data/spec/integration/card/add_and_remove_attachment_spec.rb +45 -0
  197. data/spec/integration/card/add_and_remove_label_spec.rb +35 -0
  198. data/spec/integration/card/add_checklist_spec.rb +32 -0
  199. data/spec/integration/card/add_comment_spec.rb +19 -0
  200. data/spec/integration/card/add_memeber_spec.rb +19 -0
  201. data/spec/integration/card/associations/actions_spec.rb +17 -0
  202. data/spec/integration/card/associations/attachments_spec.rb +18 -0
  203. data/spec/integration/card/associations/board_spec.rb +17 -0
  204. data/spec/integration/card/associations/check_item_states_spec.rb +17 -0
  205. data/spec/integration/card/associations/checklists_spec.rb +18 -0
  206. data/spec/integration/card/associations/comments_spec.rb +19 -0
  207. data/spec/integration/card/associations/cover_image_spec.rb +18 -0
  208. data/spec/integration/card/associations/custom_field_items_spec.rb +18 -0
  209. data/spec/integration/card/associations/list_spec.rb +16 -0
  210. data/spec/integration/card/associations/members_spec.rb +18 -0
  211. data/spec/integration/card/associations/plugin_data_spec.rb +18 -0
  212. data/spec/integration/card/associations/voters_spec.rb +17 -0
  213. data/spec/integration/card/close!_spec.rb +16 -0
  214. data/spec/integration/card/create_new_check_list_spec.rb +19 -0
  215. data/spec/integration/card/create_spec.rb +84 -0
  216. data/spec/integration/card/delete_spec.rb +16 -0
  217. data/spec/integration/card/find_spec.rb +67 -0
  218. data/spec/integration/card/move_to_board_spec.rb +36 -0
  219. data/spec/integration/card/move_to_list_spec.rb +20 -0
  220. data/spec/integration/card/remove_member_spec.rb +19 -0
  221. data/spec/integration/card/save_spec.rb +61 -0
  222. data/spec/integration/card/update!_spec.rb +53 -0
  223. data/spec/integration/card/vote_spec.rb +50 -0
  224. data/spec/integration/checklist/add_item_spec.rb +20 -0
  225. data/spec/integration/checklist/create_spec.rb +23 -0
  226. data/spec/integration/checklist/delete_spec.rb +17 -0
  227. data/spec/integration/checklist/find_spec.rb +22 -0
  228. data/spec/integration/checklist/update!_spec.rb +21 -0
  229. data/spec/integration/checklist/update_item_state_spec.rb +20 -0
  230. data/spec/integration/custom_field/association/board_spec.rb +18 -0
  231. data/spec/integration/custom_field/association/custom_field_options_spec.rb +18 -0
  232. data/spec/integration/custom_field/create_spec.rb +29 -0
  233. data/spec/integration/custom_field/find_spec.rb +41 -0
  234. data/spec/integration/custom_field/update!_spec.rb +25 -0
  235. data/spec/integration/custom_field_item_spec.rb +47 -0
  236. data/spec/integration/custom_field_option/create_spec.rb +23 -0
  237. data/spec/integration/custom_field_option/delete_spec.rb +19 -0
  238. data/spec/integration/custom_field_option/find_spec.rb +21 -0
  239. data/spec/integration/label/association/board_spec.rb +18 -0
  240. data/spec/integration/label/create_spec.rb +23 -0
  241. data/spec/integration/label/delete_spec.rb +21 -0
  242. data/spec/integration/label/find_spec.rb +20 -0
  243. data/spec/integration/label/update!_spec.rb +25 -0
  244. data/spec/integration/list/archive_all_cards_spec.rb +20 -0
  245. data/spec/integration/list/associations/actions_spec.rb +18 -0
  246. data/spec/integration/list/associations/board_spec.rb +18 -0
  247. data/spec/integration/list/associations/cards_spec.rb +18 -0
  248. data/spec/integration/list/create_spec.rb +44 -0
  249. data/spec/integration/list/find_spec.rb +37 -0
  250. data/spec/integration/list/move_all_cards_spec.rb +31 -0
  251. data/spec/integration/list/save_spec.rb +40 -0
  252. data/spec/integration/list/update!_spec.rb +43 -0
  253. data/spec/integration/member/associations/actions_spec.rb +17 -0
  254. data/spec/integration/member/associations/boards_spec.rb +18 -0
  255. data/spec/integration/member/associations/cards_spec.rb +18 -0
  256. data/spec/integration/member/associations/notifications_spec.rb +18 -0
  257. data/spec/integration/member/associations/organizations_spec.rb +18 -0
  258. data/spec/integration/member/find_spec.rb +39 -0
  259. data/spec/integration/member/update!_spec.rb +18 -0
  260. data/spec/integration/notification/find_spec.rb +27 -0
  261. data/spec/integration/organization/associations/actions_spec.rb +18 -0
  262. data/spec/integration/organization/associations/boards_spec.rb +18 -0
  263. data/spec/integration/organization/associations/members_spec.rb +18 -0
  264. data/spec/integration/organization/create_spec.rb +23 -0
  265. data/spec/integration/organization/find_spec.rb +37 -0
  266. data/spec/integration/organization/update!_spec.rb +28 -0
  267. data/spec/integration/token/find_spec.rb +24 -0
  268. data/spec/integration/webhook/create_spec.rb +27 -0
  269. data/spec/integration/webhook/delete_spec.rb +21 -0
  270. data/spec/integration/webhook/find_spec.rb +22 -0
  271. data/spec/integration/webhook/update!_spec.rb +24 -0
  272. data/spec/item_spec.rb +2 -2
  273. data/spec/label_spec.rb +105 -28
  274. data/spec/list_spec.rb +32 -14
  275. data/spec/notification_spec.rb +3 -3
  276. data/spec/organization_spec.rb +6 -5
  277. data/spec/spec_helper.rb +118 -37
  278. data/spec/token_spec.rb +10 -11
  279. data/spec/unit/trello/association_builder/has_many_spec.rb +36 -0
  280. data/spec/unit/trello/association_builder/has_one_spec.rb +36 -0
  281. data/spec/unit/trello/association_fetcher/has_many/fetch_spec.rb +38 -0
  282. data/spec/unit/trello/association_fetcher/has_many/params_spec.rb +107 -0
  283. data/spec/unit/trello/association_fetcher/has_many_spec.rb +50 -0
  284. data/spec/unit/trello/association_fetcher/has_one/fetch_spec.rb +51 -0
  285. data/spec/unit/trello/association_fetcher/has_one/params_spec.rb +81 -0
  286. data/spec/unit/trello/association_fetcher/has_one_spec.rb +49 -0
  287. data/spec/unit/trello/association_infer_tool_spec.rb +41 -0
  288. data/spec/unit/trello/basic_data_spec.rb +113 -0
  289. data/spec/unit/trello/board/new_spec.rb +370 -0
  290. data/spec/unit/trello/board/save_spec.rb +49 -0
  291. data/spec/unit/trello/board/update_fields_spec.rb +129 -0
  292. data/spec/unit/trello/board/update_spec.rb +197 -0
  293. data/spec/unit/trello/card_spec.rb +103 -0
  294. data/spec/unit/trello/member/new_spec.rb +62 -0
  295. data/spec/unit/trello/member/update_fields_spec.rb +80 -0
  296. data/spec/unit/trello/schema/attribute/base_spec.rb +349 -0
  297. data/spec/unit/trello/schema/attribute/board_pref_spec.rb +208 -0
  298. data/spec/unit/trello/schema/attribute/default_spec.rb +236 -0
  299. data/spec/unit/trello/schema/attribute_builder_spec.rb +55 -0
  300. data/spec/unit/trello/schema/attribute_registration_spec.rb +59 -0
  301. data/spec/unit/trello/schema/serializer/default_spec.rb +19 -0
  302. data/spec/unit/trello/schema/serializer/time_spec.rb +39 -0
  303. data/spec/unit/trello/schema_spec.rb +25 -0
  304. data/spec/webhook_spec.rb +23 -7
  305. metadata +542 -29
@@ -5,86 +5,33 @@ module Trello
5
5
  # @return [String]
6
6
  # @!attribute [r] description
7
7
  # @return [String]
8
- # @!attribute [r] id_model
8
+ # @!attribute [r] model_id
9
9
  # @return [String] A 24-character hex string
10
10
  # @!attribute [r] callback_url
11
11
  # @return [String]
12
12
  # @!attribute [r] active
13
13
  # @return [Boolean]
14
+ # @!attribute [r] consecutive_failures
15
+ # @return [Integer]
16
+ # @!attribute [r] first_consecutive_fail_date
17
+ # @return [Datetime]
14
18
  class Webhook < BasicData
15
- register_attributes :id, :description, :id_model, :callback_url, :active,
16
- readonly: [ :id ]
17
- validates_presence_of :id, :id_model, :callback_url
18
- validates_length_of :description, in: 1..16384
19
19
 
20
- class << self
21
- # Find a specific webhook by its ID.
22
- #
23
- # @raise [Trello::Error] if a Webhook with the given ID can't be found.
24
- # @return [Trello::Webhook] the Webhook with the given ID.
25
- def find(id, params = {})
26
- client.find(:webhook, id, params)
27
- end
28
-
29
- # Create a new webhook and save it to Trello.
30
- #
31
- # @param [Hash] options
32
- #
33
- # @option options [String] :description (optional) A string with a length from 0 to 16384
34
- # @option options [String] :callback_url (required) A valid URL that is
35
- # reachable with a HEAD request
36
- # @option options [String] :id_model (required) id of the model that should be hooked
37
- #
38
- # @raise [Trello::Error] if the Webhook could not be created.
39
- #
40
- # @return [Trello::Webhook]
41
- def create(options)
42
- client.create(:webhook,
43
- 'description' => options[:description],
44
- 'idModel' => options[:id_model],
45
- 'callbackURL' => options[:callback_url])
46
- end
47
- end
48
-
49
- # @return [Trello::Webhook] self
50
- def update_fields(fields)
51
- attributes[:id] = fields['id'] || attributes[:id]
52
- attributes[:description] = fields['description'] || fields[:description] || attributes[:description]
53
- attributes[:id_model] = fields['idModel'] || fields[:id_model] || attributes[:id_model]
54
- attributes[:callback_url] = fields['callbackURL'] || fields[:callback_url] || attributes[:callback_url]
55
- attributes[:active] = fields['active'] if fields.has_key?('active')
56
- self
20
+ schema do
21
+ # Readonly
22
+ attribute :id, readonly: true, primary_key: true
23
+ attribute :consecutive_failures, readonly: true, remote_key: 'consecutiveFailures'
24
+ attribute :first_consecutive_fail_date, readonly: true, remote_key: 'firstConsecutiveFailDate', serializer: 'Time'
25
+
26
+ # Writable
27
+ attribute :description
28
+ attribute :model_id, remote_key: 'idModel'
29
+ attribute :callback_url, remote_key: 'callbackURL'
30
+ attribute :active
57
31
  end
58
32
 
59
- # Save the webhook.
60
- #
61
- # @raise [Trello::Error] if the Webhook could not be saved.
62
- #
63
- # @return [String] the JSON representation of the saved webhook.
64
- def save
65
- # If we have an id, just update our fields.
66
- return update! if id
67
-
68
- from_response client.post("/webhooks", {
69
- description: description,
70
- idModel: id_model,
71
- callbackURL: callback_url
72
- })
73
- end
74
-
75
- # Update the webhook.
76
- #
77
- # @raise [Trello::Error] if the Webhook could not be saved.
78
- #
79
- # @return [String] the JSON representation of the updated webhook.
80
- def update!
81
- client.put("/webhooks/#{id}", {
82
- description: description,
83
- idModel: id_model,
84
- callbackURL: callback_url,
85
- active: active
86
- })
87
- end
33
+ validates_presence_of :id, :model_id, :callback_url
34
+ validates_length_of :description, in: 1..16384
88
35
 
89
36
  # Delete this webhook
90
37
  #
@@ -116,7 +116,7 @@ module Trello
116
116
  before do
117
117
  allow(client)
118
118
  .to receive(:get)
119
- .with('/members/abcdef123456789123456789', {})
119
+ .with('/actions/4ee2482134a81a757a08af47/memberCreator')
120
120
  .and_return user_payload
121
121
  end
122
122
 
@@ -131,8 +131,7 @@ module Trello
131
131
  'id' => 'id',
132
132
  'type' => 'type',
133
133
  'data' => 'data',
134
- 'idMemberCreator' => 'member_creator_id',
135
- 'member' => 'member_participant'
134
+ 'idMemberCreator' => 'creator_id'
136
135
  }
137
136
 
138
137
  action = Action.new(expected)
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ module Trello
4
+ describe BasicData do
5
+ describe "equality" do
6
+ specify "two objects of the same type are equal if their id values are equal" do
7
+ data_object = Card.new('id' => 'abc123')
8
+ other_data_object = Card.new('id' => 'abc123')
9
+
10
+ expect(data_object).to eq(other_data_object)
11
+ end
12
+
13
+ specify "two object of the samy type are not equal if their id values are different" do
14
+ data_object = Card.new('id' => 'abc123')
15
+ other_data_object = Card.new('id' => 'def456')
16
+
17
+ expect(data_object).not_to eq(other_data_object)
18
+ end
19
+
20
+ specify "two object of different types are not equal even if their id values are equal" do
21
+ card = Card.new('id' => 'abc123')
22
+ list = List.new('id' => 'abc123')
23
+
24
+ expect(card.id).to eq(list.id)
25
+ expect(card).to_not eq(list)
26
+ end
27
+ end
28
+
29
+ describe "hash equality" do
30
+ specify "two objects of the same type point to the same hash key" do
31
+ data_object = Card.new('id' => 'abc123')
32
+ other_data_object = Card.new('id' => 'abc123')
33
+
34
+ hash = {data_object => 'one'}
35
+
36
+ expect(hash[other_data_object]).to eq('one')
37
+ end
38
+
39
+ specify "two object of the same type with different ids do not point to the same hash key" do
40
+ data_object = Card.new('id' => 'abc123')
41
+ other_data_object = Card.new('id' => 'def456')
42
+
43
+ hash = {data_object => 'one'}
44
+
45
+ expect(hash[other_data_object]).to be_nil
46
+ end
47
+
48
+ specify "two object of different types with same ids do not point to the same hash key" do
49
+ card = Card.new('id' => 'abc123')
50
+ list = List.new('id' => 'abc123')
51
+
52
+ hash = {card => 'one'}
53
+
54
+ expect(hash[list]).to be_nil
55
+ end
56
+ end
57
+ end
58
+ end
@@ -6,7 +6,7 @@ module Trello
6
6
 
7
7
  let(:board) { client.find(:board, 'abcdef123456789123456789') }
8
8
  let(:client) { Client.new }
9
- let(:member) { Member.new(user_payload) }
9
+ let(:member) { Member.new(JSON.parse(user_payload)) }
10
10
 
11
11
  before do
12
12
  allow(client)
@@ -21,7 +21,7 @@ module Trello
21
21
  it "delegates to client#find" do
22
22
  expect(client)
23
23
  .to receive(:find)
24
- .with(:board, 'abcdef123456789123456789', {})
24
+ .with('board', 'abcdef123456789123456789', {})
25
25
 
26
26
  Board.find('abcdef123456789123456789')
27
27
  end
@@ -31,6 +31,35 @@ module Trello
31
31
  end
32
32
  end
33
33
 
34
+ describe '.create' do
35
+ before { allow(Board).to receive(:client).and_return(client) }
36
+
37
+ it 'will call create on client with correct parameters' do
38
+ params = {
39
+ name: 'Board Name',
40
+ use_default_labels: true,
41
+ use_default_lists: true,
42
+ description: 'description...',
43
+ organization_id: 11111,
44
+ source_board_id: 22222,
45
+ keep_cards_from_source: true,
46
+ power_ups: 'all',
47
+ visibility_level: 'org',
48
+ voting_permission_level: 'org',
49
+ comment_permission_level: 'org',
50
+ invitation_permission_level: 'admins',
51
+ enable_self_join: true,
52
+ enable_card_covers: true,
53
+ background_color: 'orange',
54
+ card_aging_type: 'pirate'
55
+ }
56
+
57
+ expect(client).to receive(:create).with('board', params)
58
+
59
+ Board.create(params)
60
+ end
61
+ end
62
+
34
63
  context "self.all" do
35
64
  let(:client) { Trello.client }
36
65
 
@@ -133,12 +162,10 @@ module Trello
133
162
  expect(labels[2].id).to eq('cbcdef123456789123456789')
134
163
  expect(labels[2].board_id).to eq('abcdef123456789123456789')
135
164
  expect(labels[2].name).to eq('deploy')
136
- expect(labels[2].uses).to eq(2)
137
165
  expect(labels[3].color).to eq('blue')
138
166
  expect(labels[3].id).to eq('dbcdef123456789123456789')
139
167
  expect(labels[3].board_id).to eq('abcdef123456789123456789')
140
168
  expect(labels[3].name).to eq('on hold')
141
- expect(labels[3].uses).to eq(6)
142
169
  end
143
170
 
144
171
  it "passes the label limit" do
@@ -170,7 +197,7 @@ module Trello
170
197
  it "adds a member to the board as a normal user (default)" do
171
198
  expect(client)
172
199
  .to receive(:put)
173
- .with("/boards/abcdef123456789123456789/members/id", type: :normal)
200
+ .with("/boards/abcdef123456789123456789/members/#{member.id}", type: :normal)
174
201
 
175
202
  board.add_member(member)
176
203
  end
@@ -178,7 +205,7 @@ module Trello
178
205
  it "adds a member to the board as an admin" do
179
206
  expect(client)
180
207
  .to receive(:put)
181
- .with("/boards/abcdef123456789123456789/members/id", type: :admin)
208
+ .with("/boards/abcdef123456789123456789/members/#{member.id}", type: :admin)
182
209
 
183
210
  board.add_member(member, :admin)
184
211
  end
@@ -193,7 +220,7 @@ module Trello
193
220
  it "removes a member from the board" do
194
221
  expect(client)
195
222
  .to receive(:delete)
196
- .with("/boards/abcdef123456789123456789/members/id")
223
+ .with("/boards/abcdef123456789123456789/members/#{member.id}")
197
224
 
198
225
  board.remove_member(member)
199
226
  end
@@ -251,62 +278,28 @@ module Trello
251
278
  end
252
279
  end
253
280
 
254
- it "is not closed" do
255
- expect(board).not_to be_closed
256
- end
257
-
258
- it "is not starred" do
259
- expect(board).not_to be_starred
260
- end
261
-
262
- describe "#update_fields" do
263
- it "does not set any fields when the fields argument is empty" do
264
- expected = {
265
- 'id' => "id",
266
- 'name' => "name",
267
- 'desc' => "desc",
268
- 'closed' => false,
269
- 'starred' => false,
270
- 'url' => "url",
271
- 'idOrganization' => "org_id"
272
- }
273
-
274
- board = Board.new(expected)
275
- board.client = client
276
-
277
- board.update_fields({})
278
-
279
- expected.each_pair do |key, value|
280
- if board.respond_to?(key)
281
- expect(board.send(key)).to eq value
282
- end
283
- end
281
+ context "custom fields" do
282
+ before do
283
+ allow(client)
284
+ .to receive(:get)
285
+ .with("/boards/abcdef123456789123456789/customFields", {})
286
+ .and_return JSON.generate([custom_fields_details.first])
287
+ end
284
288
 
285
- expect(board.description).to eq expected['desc']
286
- expect(board.organization_id).to eq expected['idOrganization']
289
+ it "has custom fields" do
290
+ expect(board.custom_fields.count).to be > 0
287
291
  end
292
+ end
288
293
 
289
- it "initializes all fields from response-like formatted hash" do
290
- board_details = boards_details.first
291
- board = Board.new(board_details)
292
- expect(board.id).to eq board_details['id']
293
- expect(board.name).to eq board_details['name']
294
- expect(board.description).to eq board_details['desc']
295
- expect(board.closed).to eq board_details['closed']
296
- expect(board.starred).to eq board_details['starred']
297
- expect(board.organization_id).to eq board_details['idOrganization']
298
- expect(board.url).to eq board_details['url']
299
- expect(board.last_activity_date).to eq board_details['dateLastActivity']
294
+ describe '#closed?' do
295
+ it "returns the closed attribute" do
296
+ expect(board.closed?).to be_falsy
300
297
  end
298
+ end
301
299
 
302
- it "initializes all fields from options-like formatted hash" do
303
- board_details = boards_details[1]
304
- board = Board.new(board_details)
305
- expect(board.name).to eq board_details[:name]
306
- expect(board.description).to eq board_details[:desc]
307
- expect(board.closed).to eq board_details[:closed]
308
- expect(board.starred).to eq board_details[:starred]
309
- expect(board.organization_id).to eq board_details[:organization_id]
300
+ describe '#starred?' do
301
+ it "returns the starred attribute" do
302
+ expect(board.starred?).to be_falsy
310
303
  end
311
304
  end
312
305
 
@@ -329,17 +322,6 @@ module Trello
329
322
  }.to raise_error(Trello::ConfigurationError)
330
323
  end
331
324
 
332
- it "puts all fields except id" do
333
- expected_fields = %w{ name description closed starred idOrganization}.map { |s| s.to_sym }
334
-
335
- expect(client).to receive(:put) do |anything, body|
336
- expect(body.keys).to match expected_fields
337
- any_board_json
338
- end
339
-
340
- Board.new('id' => "xxx").save
341
- end
342
-
343
325
  it "mutates the current instance" do
344
326
  allow(client)
345
327
  .to receive(:put)
@@ -353,7 +335,7 @@ module Trello
353
335
  expected_resource_id = "xxx_board_id_xxx"
354
336
 
355
337
  expect(client).to receive(:put) do |path, anything|
356
- expect(path).to match(/#{expected_resource_id}\/\z/)
338
+ expect(path).to match(/#{expected_resource_id}\z/)
357
339
  any_board_json
358
340
  end
359
341
 
@@ -363,35 +345,6 @@ module Trello
363
345
  it "saves OR updates depending on whether or not it has an id set"
364
346
  end
365
347
 
366
- describe '#update!' do
367
- let(:client) { Trello.client }
368
-
369
- let(:any_board_json) do
370
- JSON.generate(boards_details.first)
371
- end
372
-
373
- it "puts basic attributes" do
374
- board = Board.new 'id' => "board_id"
375
-
376
- board.name = "new name"
377
- board.description = "new description"
378
- board.closed = true
379
- board.starred = true
380
-
381
- expect(client)
382
- .to receive(:put)
383
- .with("/boards/#{board.id}/", {
384
- name: "new name",
385
- description: "new description",
386
- closed: true,
387
- starred: true,
388
- idOrganization: nil })
389
- .and_return any_board_json
390
-
391
- board.update!
392
- end
393
- end
394
-
395
348
  describe "Repository" do
396
349
  include Helpers
397
350
 
@@ -408,7 +361,7 @@ module Trello
408
361
 
409
362
  it "creates a new board with whatever attributes are supplied " do
410
363
  expected_attributes = { name: "Any new board name", description: "Any new board desription" }
411
- sent_attributes = { name: expected_attributes[:name], desc: expected_attributes[:description] }
364
+ sent_attributes = { 'name' => expected_attributes[:name], 'desc' => expected_attributes[:description] }
412
365
 
413
366
  expect(client)
414
367
  .to receive(:post)
@@ -25,7 +25,7 @@ module Trello
25
25
  it "delegates to Trello.client#find" do
26
26
  expect(client)
27
27
  .to receive(:find)
28
- .with(:card, 'abcdef123456789123456789', {})
28
+ .with('card', 'abcdef123456789123456789', {})
29
29
 
30
30
  Card.find('abcdef123456789123456789')
31
31
  end
@@ -62,7 +62,8 @@ module Trello
62
62
  expect(card.url).to eq(card_details['url'])
63
63
  expect(card.short_url).to eq(card_details['shortUrl'])
64
64
  expect(card.pos).to eq(card_details['pos'])
65
- expect(card.last_activity_date).to eq(card_details['dateLastActivity'])
65
+ expect(card.last_activity_date).to be_a(Time)
66
+ expect(card.last_activity_date).to eq(Time.iso8601(card_details['dateLastActivity']))
66
67
  end
67
68
 
68
69
  it 'properly initializes all fields from options-like formatted hash' do
@@ -73,7 +74,7 @@ module Trello
73
74
  expect(card.desc).to eq(card_details[:desc])
74
75
  expect(card.member_ids).to eq(card_details[:member_ids])
75
76
  expect(card.card_labels).to eq(card_details[:card_labels])
76
- expect(card.due).to eq(card_details[:due])
77
+ expect(card.due).to eq(card_details[:due].to_time)
77
78
  expect(card.pos).to eq(card_details[:pos])
78
79
  expect(card.source_card_id).to eq(card_details[:source_card_id])
79
80
  expect(card.source_card_properties).to eq(card_details[:source_card_properties])
@@ -96,17 +97,18 @@ module Trello
96
97
  card_labels: "abcdef123456789123456789"
97
98
  }
98
99
 
99
- result = JSON.generate(cards_details.first.merge(payload.merge(idList: lists_details.first['id'])))
100
-
101
- expected_payload = {name: "Test Card", desc: nil, idList: "abcdef123456789123456789",
102
- idMembers: nil, idLabels: "abcdef123456789123456789", pos: nil, due: nil, dueComplete: false, idCardSource: nil, keepFromSource: 'all'}
100
+ expected_payload = {
101
+ 'name' => "Test Card",
102
+ 'idList' => "abcdef123456789123456789",
103
+ 'idLabels' => "abcdef123456789123456789",
104
+ }
103
105
 
104
106
  expect(client)
105
107
  .to receive(:post)
106
108
  .with("/cards", expected_payload)
107
- .and_return result
109
+ .and_return JSON.generate(cards_details.first.merge(payload.merge(idList: lists_details.first['id'])))
108
110
 
109
- card = Card.create(cards_details.first.merge(payload.merge(list_id: lists_details.first['id'])))
111
+ card = Card.create(payload.merge(list_id: lists_details.first['id']))
110
112
 
111
113
  expect(card).to be_a Card
112
114
  end
@@ -118,15 +120,17 @@ module Trello
118
120
 
119
121
  result = JSON.generate(cards_details.first.merge(payload.merge(idList: lists_details.first['id'])))
120
122
 
121
- expected_payload = {name: nil, desc: nil, idList: "abcdef123456789123456789",
122
- idMembers: nil, idLabels: nil, pos: nil, due: nil, dueComplete: false, idCardSource: cards_details.first['id'], keepFromSource: 'all'}
123
+ expected_payload = {
124
+ 'idList' => "abcdef123456789123456789",
125
+ 'idCardSource' => cards_details.first['id'],
126
+ }
123
127
 
124
128
  expect(client)
125
129
  .to receive(:post)
126
130
  .with("/cards", expected_payload)
127
131
  .and_return result
128
132
 
129
- card = Card.create(cards_details.first.merge(payload.merge(list_id: lists_details.first['id'])))
133
+ card = Card.create(payload.merge(list_id: lists_details.first['id']))
130
134
 
131
135
  expect(card).to be_a Card
132
136
  end
@@ -139,15 +143,18 @@ module Trello
139
143
 
140
144
  result = JSON.generate(cards_details.first.merge(payload.merge(idList: lists_details.first['id'])))
141
145
 
142
- expected_payload = {name: nil, desc: nil, idList: "abcdef123456789123456789",
143
- idMembers: nil, idLabels: nil, pos: nil, due: nil, dueComplete: false, idCardSource: cards_details.first['id'], keepFromSource: ['due', 'checklists']}
146
+ expected_payload = {
147
+ 'idList' => "abcdef123456789123456789",
148
+ 'idCardSource' => cards_details.first['id'],
149
+ 'keepFromSource' => ['due', 'checklists']
150
+ }
144
151
 
145
152
  expect(client)
146
153
  .to receive(:post)
147
154
  .with("/cards", expected_payload)
148
155
  .and_return result
149
156
 
150
- card = Card.create(cards_details.first.merge(payload.merge(list_id: lists_details.first['id'])))
157
+ card = Card.create(payload.merge(list_id: lists_details.first['id']))
151
158
 
152
159
  expect(card).to be_a Card
153
160
  end
@@ -160,15 +167,17 @@ module Trello
160
167
 
161
168
  result = JSON.generate(cards_details.first.merge(payload.merge(idList: lists_details.first['id'])))
162
169
 
163
- expected_payload = {name: nil, desc: nil, idList: "abcdef123456789123456789",
164
- idMembers: nil, idLabels: nil, pos: nil, due: nil, dueComplete: false, idCardSource: cards_details.first['id'], keepFromSource: nil}
170
+ expected_payload = {
171
+ 'idList' => "abcdef123456789123456789",
172
+ 'idCardSource' => cards_details.first['id'],
173
+ }
165
174
 
166
175
  expect(client)
167
176
  .to receive(:post)
168
177
  .with("/cards", expected_payload)
169
178
  .and_return result
170
179
 
171
- card = Card.create(cards_details.first.merge(payload.merge(list_id: lists_details.first['id'])))
180
+ card = Card.create(payload.merge(list_id: lists_details.first['id']))
172
181
 
173
182
  expect(card).to be_a Card
174
183
  end
@@ -180,13 +189,14 @@ module Trello
180
189
  expected_new_name = "xxx"
181
190
 
182
191
  payload = {
183
- name: expected_new_name,
192
+ 'name' => expected_new_name,
184
193
  }
185
194
 
186
195
  expect(client)
187
196
  .to receive(:put)
188
197
  .once
189
198
  .with("/cards/abcdef123456789123456789", payload)
199
+ .and_return(payload.to_json)
190
200
 
191
201
  card.name = expected_new_name
192
202
  card.save
@@ -196,10 +206,13 @@ module Trello
196
206
  expected_new_desc = "xxx"
197
207
 
198
208
  payload = {
199
- desc: expected_new_desc,
209
+ 'desc' => expected_new_desc,
200
210
  }
201
211
 
202
- expect(client).to receive(:put).once.with("/cards/abcdef123456789123456789", payload)
212
+ expect(client)
213
+ .to receive(:put).once
214
+ .with("/cards/abcdef123456789123456789", payload)
215
+ .and_return(payload.to_json)
203
216
 
204
217
  card.desc = expected_new_desc
205
218
  card.save
@@ -257,7 +270,6 @@ module Trello
257
270
  expect(card.pos).to_not be_nil
258
271
  end
259
272
 
260
-
261
273
  it 'gets its creation time' do
262
274
  expect(card.created_at).to be_kind_of Time
263
275
  end
@@ -308,7 +320,7 @@ module Trello
308
320
  before do
309
321
  allow(client)
310
322
  .to receive(:get)
311
- .with("/attachments/abcdef123456789123456789", {})
323
+ .with("/cards/#{card.id}/attachments/abcdef123456789123456789", {})
312
324
  .and_return JSON.generate(attachments_details.first)
313
325
  end
314
326
 
@@ -338,6 +350,50 @@ module Trello
338
350
  end
339
351
  end
340
352
 
353
+ context "custom field items" do
354
+ before do
355
+ allow(client)
356
+ .to receive(:get)
357
+ .with("/cards/abcdef123456789123456789/customFieldItems", {})
358
+ .and_return JSON.generate([custom_field_item_details])
359
+ end
360
+
361
+ it "has a list of custom field items" do
362
+ expect(card.custom_field_items.count).to be > 0
363
+ end
364
+
365
+ it "clears the custom field value on a card" do
366
+ params = { value: {} }
367
+
368
+ expect(client)
369
+ .to receive(:put)
370
+ .with("/cards/abcdef123456789123456789/customField/abcdef123456789123456789/item", params)
371
+
372
+ card.custom_field_items.last.remove
373
+ end
374
+
375
+ it "updates a custom field value" do
376
+ payload = { 'value' => { 'text' => 'Test Text' } }
377
+
378
+ expect(client)
379
+ .to receive(:put)
380
+ .with("/cards/abcdef123456789123456789/customField/abcdef123456789123456789/item", payload)
381
+ .and_return(JSON.generate({
382
+ "id" => "5e68e885e4baf545ec8ce7ba",
383
+ "value" => {
384
+ "text" => "Test Text"
385
+ },
386
+ "idCustomField" => "abcdef123456789123456789",
387
+ "idModel" => "abcdef123456789123456789",
388
+ "modelType" => "card"
389
+ }))
390
+
391
+ text_custom_field = card.custom_field_items.last
392
+ text_custom_field.value = { text: 'Test Text' }
393
+ text_custom_field.save
394
+ end
395
+ end
396
+
341
397
  context "list" do
342
398
  before do
343
399
  allow(client)
@@ -345,6 +401,7 @@ module Trello
345
401
  .with("/lists/abcdef123456789123456789", {})
346
402
  .and_return JSON.generate(lists_details.first)
347
403
  end
404
+
348
405
  it 'has a list' do
349
406
  expect(card.list).to_not be_nil
350
407
  end
@@ -438,7 +495,7 @@ module Trello
438
495
  card.move_to_list_on_any_board(other_list.id)
439
496
  end
440
497
 
441
- it 'should not be moved if new board is identical with old board', focus: true do
498
+ it 'should not be moved if new board is identical with old board' do
442
499
  other_board = double(id: 'abcdef123456789123456789')
443
500
  expect(client).to_not receive(:put)
444
501
  card.move_to_board(other_board)
@@ -454,7 +511,7 @@ module Trello
454
511
 
455
512
  allow(client)
456
513
  .to receive(:get)
457
- .with("/members/abcdef123456789123456789")
514
+ .with("/cards/abcdef123456789123456789/members")
458
515
  .and_return user_payload
459
516
  end
460
517
 
@@ -471,7 +528,7 @@ module Trello
471
528
 
472
529
  expect(client)
473
530
  .to receive(:post)
474
- .with("/cards/abcdef123456789123456789/members", payload)
531
+ .with("/cards/abcdef123456789123456789/idMembers", payload)
475
532
 
476
533
  card.add_member(new_member)
477
534
  end
@@ -481,7 +538,7 @@ module Trello
481
538
 
482
539
  expect(client)
483
540
  .to receive(:delete)
484
- .with("/cards/abcdef123456789123456789/members/#{existing_member.id}")
541
+ .with("/cards/abcdef123456789123456789/idMembers/#{existing_member.id}")
485
542
 
486
543
  card.remove_member(existing_member)
487
544
  end
@@ -556,7 +613,6 @@ module Trello
556
613
  end
557
614
  end
558
615
 
559
-
560
616
  context "comments" do
561
617
  it "posts a comment" do
562
618
  expect(client)
@@ -588,12 +644,10 @@ module Trello
588
644
  expect(labels[0].id).to eq('abcdef123456789123456789')
589
645
  expect(labels[0].board_id).to eq('abcdef123456789123456789')
590
646
  expect(labels[0].name).to eq('iOS')
591
- expect(labels[0].uses).to eq(3)
592
647
  expect(labels[1].color).to eq('purple')
593
648
  expect(labels[1].id).to eq('bbcdef123456789123456789')
594
649
  expect(labels[1].board_id).to eq('abcdef123456789123456789')
595
650
  expect(labels[1].name).to eq('Issue or bug')
596
- expect(labels[1].uses).to eq(1)
597
651
  end
598
652
 
599
653
  it "includes label ids list" do
@@ -653,18 +707,18 @@ module Trello
653
707
 
654
708
  first_plugin = card.plugin_data.first
655
709
  expect(first_plugin.id).to eq plugin_data_details[0]["id"]
656
- expect(first_plugin.idPlugin).to eq plugin_data_details[0]["idPlugin"]
710
+ expect(first_plugin.plugin_id).to eq plugin_data_details[0]["idPlugin"]
657
711
  expect(first_plugin.scope).to eq plugin_data_details[0]["scope"]
658
- expect(first_plugin.idModel).to eq plugin_data_details[0]["idModel"]
659
- expect(first_plugin.value).to eq JSON.parse plugin_data_details[0]["value"]
712
+ expect(first_plugin.model_id).to eq plugin_data_details[0]["idModel"]
713
+ expect(first_plugin.value).to eq plugin_data_details[0]["value"]
660
714
  expect(first_plugin.access).to eq plugin_data_details[0]["access"]
661
715
 
662
716
  second_plugin = card.plugin_data[1]
663
717
  expect(second_plugin.id).to eq plugin_data_details[1]["id"]
664
- expect(second_plugin.idPlugin).to eq plugin_data_details[1]["idPlugin"]
718
+ expect(second_plugin.plugin_id).to eq plugin_data_details[1]["idPlugin"]
665
719
  expect(second_plugin.scope).to eq plugin_data_details[1]["scope"]
666
- expect(second_plugin.idModel).to eq plugin_data_details[1]["idModel"]
667
- expect(second_plugin.value).to eq JSON.parse plugin_data_details[1]["value"]
720
+ expect(second_plugin.model_id).to eq plugin_data_details[1]["idModel"]
721
+ expect(second_plugin.value).to eq plugin_data_details[1]["value"]
668
722
  expect(second_plugin.access).to eq plugin_data_details[1]["access"]
669
723
 
670
724
  end
@@ -748,12 +802,13 @@ module Trello
748
802
 
749
803
  describe "#close!" do
750
804
  it "updates the close attribute to true and saves the list" do
751
- payload = { closed: true }
805
+ payload = { 'closed' => true }
752
806
 
753
807
  expect(client)
754
808
  .to receive(:put)
755
809
  .once
756
810
  .with("/cards/abcdef123456789123456789", payload)
811
+ .and_return(payload.to_json)
757
812
 
758
813
  card.close!
759
814
  end
@@ -764,57 +819,113 @@ module Trello
764
819
  due_date = Time.now
765
820
 
766
821
  payload = {
767
- due: due_date,
822
+ 'due' => due_date.strftime('%FT%T.%LZ'),
768
823
  }
769
824
 
770
825
  expect(client)
771
826
  .to receive(:put)
772
827
  .once
773
828
  .with("/cards/abcdef123456789123456789", payload)
829
+ .and_return(payload.to_json)
774
830
 
775
831
  card.due = due_date
776
832
  card.save
777
833
 
778
834
  expect(card.due).to_not be_nil
835
+ end
836
+ end
779
837
 
780
- payload = {
781
- dueComplete: true
782
- }
838
+ describe '#update_fields' do
839
+ context 'when the fields argument is empty' do
840
+ let(:fields) { {} }
783
841
 
784
- expect(client)
785
- .to receive(:put)
786
- .once
787
- .with("/cards/abcdef123456789123456789", payload)
842
+ it 'card does not set any fields' do
843
+ expected = cards_details.first
788
844
 
789
- card.due_complete = true
790
- card.save
845
+ card = Card.new(expected)
846
+ card.client = client
847
+
848
+ card.update_fields(fields)
791
849
 
792
- expect(card.due_complete).to be true
850
+ expected.each do |key, value|
851
+ if card.respond_to?(key) && key != 'labels'
852
+ expect(card.send(key)).to eq value
853
+ end
854
+
855
+ expect(card.labels).to eq expected['labels'].map { |lbl| Trello::Label.new(lbl) }
856
+ expect(card.short_id).to eq expected['idShort']
857
+ expect(card.short_url).to eq expected['shortUrl']
858
+ expect(card.board_id).to eq expected['idBoard']
859
+ expect(card.member_ids).to eq expected['idMembers']
860
+ expect(card.cover_image_id).to eq expected['idAttachmentCover']
861
+ expect(card.list_id).to eq expected['idList']
862
+ expect(card.card_labels).to eq expected['idLabels']
863
+ end
864
+ end
793
865
  end
794
- end
795
866
 
796
- describe "#update_fields" do
797
- it "does not set any fields when the fields argument is empty" do
798
- expected = cards_details.first
867
+ context 'when the fields argument has at least one field' do
868
+ let(:expected) { cards_details.first }
869
+ let(:card) {
870
+ card = Card.new(expected)
871
+ card.client = client
872
+ card
873
+ }
799
874
 
800
- card = Card.new(expected)
801
- card.client = client
875
+ context 'and the field does changed' do
876
+ let(:fields) { { desc: 'Awesome things have changed.' } }
802
877
 
803
- card.update_fields({})
878
+ it 'card does set the changed fields' do
879
+ card.update_fields(fields)
804
880
 
805
- expected.each do |key, value|
806
- if card.respond_to?(key) && key != 'labels'
807
- expect(card.send(key)).to eq value
881
+ expect(card.desc).to eq('Awesome things have changed.')
808
882
  end
809
883
 
810
- expect(card.labels).to eq expected['labels'].map { |lbl| Trello::Label.new(lbl) }
811
- expect(card.short_id).to eq expected['idShort']
812
- expect(card.short_url).to eq expected['shortUrl']
813
- expect(card.board_id).to eq expected['idBoard']
814
- expect(card.member_ids).to eq expected['idMembers']
815
- expect(card.cover_image_id).to eq expected['idAttachmentCover']
816
- expect(card.list_id).to eq expected['idList']
817
- expect(card.card_labels).to eq expected['idLabels']
884
+ it 'card has been mark as changed' do
885
+ card.update_fields(fields)
886
+
887
+ expect(card.changed?).to be_truthy
888
+ end
889
+ end
890
+
891
+ context "and the field doesn't changed" do
892
+ let(:fields) { { desc: expected['desc'] } }
893
+
894
+ it "card attributes doesn't changed" do
895
+ card.update_fields(fields)
896
+
897
+ expect(card.desc).to eq(expected['desc'])
898
+ end
899
+
900
+ it "card hasn't been mark as changed" do
901
+ card.update_fields(fields)
902
+
903
+ expect(card.changed?).to be_falsy
904
+ end
905
+ end
906
+
907
+ context "and the field isn't a correct attributes of the card" do
908
+ let(:fields) { { abc: 'abc' } }
909
+
910
+ it "card attributes doesn't changed" do
911
+ card.update_fields(fields)
912
+
913
+ expect(card.labels).to eq expected['labels'].map { |lbl| Trello::Label.new(lbl) }
914
+ expect(card.short_id).to eq expected['idShort']
915
+ expect(card.short_url).to eq expected['shortUrl']
916
+ expect(card.board_id).to eq expected['idBoard']
917
+ expect(card.member_ids).to eq expected['idMembers']
918
+ expect(card.cover_image_id).to eq expected['idAttachmentCover']
919
+ expect(card.list_id).to eq expected['idList']
920
+ expect(card.card_labels).to eq expected['idLabels']
921
+ expect(card.desc).to eq expected['desc']
922
+ end
923
+
924
+ it "card hasn't been mark as changed" do
925
+ card.update_fields(fields)
926
+
927
+ expect(card.changed?).to be_falsy
928
+ end
818
929
  end
819
930
  end
820
931
  end