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,197 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Trello::Board#update!' do
4
+
5
+ let(:client) { Trello.client }
6
+ let(:board) { Trello::Board.new(id: 'abc123') }
7
+
8
+ before { allow(board).to receive(:from_response) }
9
+
10
+ it 'can update name through client' do
11
+ board.name = 'Board 1'
12
+
13
+ expect(client)
14
+ .to receive(:put)
15
+ .with('/boards/abc123', {
16
+ 'name' => 'Board 1'
17
+ })
18
+
19
+ board.update!
20
+ end
21
+
22
+ it 'can update description through client' do
23
+ board.description = 'description ...'
24
+
25
+ expect(client)
26
+ .to receive(:put)
27
+ .with('/boards/abc123', {
28
+ 'desc' => 'description ...'
29
+ })
30
+
31
+ board.update!
32
+ end
33
+
34
+ it 'can update closed through client' do
35
+ board.closed = true
36
+
37
+ expect(client)
38
+ .to receive(:put)
39
+ .with('/boards/abc123', {
40
+ 'closed' => true
41
+ })
42
+
43
+ board.update!
44
+ end
45
+
46
+ # it 'can update subscribed through client' do
47
+ # end
48
+
49
+ it 'can update organization_id through client' do
50
+ board.organization_id = 123
51
+
52
+ expect(client)
53
+ .to receive(:put)
54
+ .with('/boards/abc123', {
55
+ 'idOrganization' => 123
56
+ })
57
+
58
+ board.update!
59
+ end
60
+
61
+ it 'can update visibility_level through client' do
62
+ board.visibility_level = 'org'
63
+
64
+ expect(client)
65
+ .to receive(:put)
66
+ .with('/boards/abc123', {
67
+ 'prefs/permissionLevel' => 'org'
68
+ })
69
+
70
+ board.update!
71
+ end
72
+
73
+ it 'can update enable_self_join through client' do
74
+ board.enable_self_join = true
75
+
76
+ expect(client)
77
+ .to receive(:put)
78
+ .with('/boards/abc123', {
79
+ 'prefs/selfJoin' => true
80
+ })
81
+
82
+ board.update!
83
+ end
84
+
85
+ it 'can update enable_card_covers through client' do
86
+ board.enable_card_covers = true
87
+
88
+ expect(client)
89
+ .to receive(:put)
90
+ .with('/boards/abc123', {
91
+ 'prefs/cardCovers' => true
92
+ })
93
+
94
+ board.update!
95
+ end
96
+
97
+ # it 'can update hide_votes through client' do
98
+ # end
99
+
100
+ it 'can update invitation_permission_level through client' do
101
+ board.invitation_permission_level = 'org'
102
+
103
+ expect(client)
104
+ .to receive(:put)
105
+ .with('/boards/abc123', {
106
+ 'prefs/invitations' => 'org'
107
+ })
108
+
109
+ board.update!
110
+ end
111
+
112
+ it 'can update voting_permission_level through client' do
113
+ board.voting_permission_level = 'org'
114
+
115
+ expect(client)
116
+ .to receive(:put)
117
+ .with('/boards/abc123', {
118
+ 'prefs/voting' => 'org'
119
+ })
120
+
121
+ board.update!
122
+ end
123
+
124
+ it 'can update comment_permission_level through client' do
125
+ board.comment_permission_level = 'org'
126
+
127
+ expect(client)
128
+ .to receive(:put)
129
+ .with('/boards/abc123', {
130
+ 'prefs/comments' => 'org'
131
+ })
132
+
133
+ board.update!
134
+ end
135
+
136
+ it 'can update background_color through client' do
137
+ board.background_color = 'blue'
138
+
139
+ expect(client)
140
+ .to receive(:put)
141
+ .with('/boards/abc123', {
142
+ 'prefs/background' => 'blue'
143
+ })
144
+
145
+ board.update!
146
+ end
147
+
148
+ it 'can update card_aging_type through client' do
149
+ board.card_aging_type = 'pirate'
150
+
151
+ expect(client)
152
+ .to receive(:put)
153
+ .with('/boards/abc123', {
154
+ 'prefs/cardAging' => 'pirate'
155
+ })
156
+
157
+ board.update!
158
+ end
159
+
160
+ # it 'can update enable_calendar_feed through client' do
161
+ # end
162
+
163
+ it 'can update all through client' do
164
+ board.name = 'Board 1'
165
+ board.description = 'description ...'
166
+ board.closed = true
167
+ board.organization_id = 123
168
+ board.visibility_level = 'org'
169
+ board.enable_self_join = true
170
+ board.enable_card_covers = true
171
+ board.invitation_permission_level = 'org'
172
+ board.voting_permission_level = 'org'
173
+ board.comment_permission_level = 'org'
174
+ board.background_color = 'blue'
175
+ board.card_aging_type = 'pirate'
176
+
177
+ expect(client)
178
+ .to receive(:put)
179
+ .with('/boards/abc123', {
180
+ 'name' => 'Board 1',
181
+ 'desc' => 'description ...',
182
+ 'closed' => true,
183
+ 'idOrganization' => 123,
184
+ 'prefs/permissionLevel' => 'org',
185
+ 'prefs/selfJoin' => true,
186
+ 'prefs/cardCovers' => true,
187
+ 'prefs/invitations' => 'org',
188
+ 'prefs/voting' => 'org',
189
+ 'prefs/comments' => 'org',
190
+ 'prefs/background' => 'blue',
191
+ 'prefs/cardAging' => 'pirate'
192
+ })
193
+
194
+ board.update!
195
+ end
196
+
197
+ end
@@ -0,0 +1,62 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'Trello::Member#new' do
5
+
6
+ let(:member) { Trello::Member.new(data) }
7
+
8
+ describe 'parse #id (readonly primary_key)' do
9
+ context 'with Trello API respone data' do
10
+ let(:data) { { 'id' => '5e93ba98614ac22d22f085c4' } }
11
+
12
+ it "parse from data['id']" do
13
+ expect(member.id).to eq('5e93ba98614ac22d22f085c4')
14
+ end
15
+ end
16
+
17
+ context 'with Ruby-like data' do
18
+ let(:data) { { id: '5e93ba98614ac22d22f085c4' } }
19
+
20
+ it 'parse from data[:id]' do
21
+ expect(member.id).to eq('5e93ba98614ac22d22f085c4')
22
+ end
23
+ end
24
+ end
25
+
26
+ describe 'parse #username (writable)' do
27
+ context 'with Trello API respone data' do
28
+ let(:data) { { 'username' => 'hoppertest' } }
29
+
30
+ it "parse from data['username']" do
31
+ expect(member.username).to eq('hoppertest')
32
+ end
33
+ end
34
+
35
+ context 'with Ruby-like data' do
36
+ let(:data) { { username: 'hoppertest' } }
37
+
38
+ it 'parse from data[:id]' do
39
+ expect(member.username).to eq('hoppertest')
40
+ end
41
+ end
42
+ end
43
+
44
+ describe 'parse #full_name (writable)' do
45
+ context 'with Trello API respone data' do
46
+ let(:data) { { 'fullName' => 'hoppertest' } }
47
+
48
+ it "parse from data['fullName']" do
49
+ expect(member.full_name).to eq('hoppertest')
50
+ end
51
+ end
52
+
53
+ context 'with Ruby-like data' do
54
+ let(:data) { { full_name: 'hoppertest' } }
55
+
56
+ it 'parse from data[:full_name]' do
57
+ expect(member.full_name).to eq('hoppertest')
58
+ end
59
+ end
60
+ end
61
+
62
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Trello::Member#update_fields' do
4
+
5
+ let(:member_params) { {
6
+ 'id' => '5e93ba403f1ab3603ba81a09',
7
+ 'bio' => 'test',
8
+ 'username' => 'hoppertest',
9
+ 'email' => 'test@test.com'
10
+ } }
11
+
12
+ let(:member) { Trello::Member.new(member_params) }
13
+
14
+ context 'when the fields argument is empty' do
15
+ let(:fields) { {} }
16
+
17
+ it 'member does not set any fields' do
18
+ member.update_fields(fields)
19
+
20
+ expect(member.changed?).to be_falsy
21
+ expect(member.id).to eq(member_params['id'])
22
+ expect(member.username).to eq(member_params['username'])
23
+ expect(member.email).to eq(member_params['email'])
24
+ end
25
+ end
26
+
27
+ context 'when the fields argument has at least one field' do
28
+
29
+ context 'and the field does changed' do
30
+ let(:fields) { { username: 'hopperchange' } }
31
+
32
+ it 'member does set the changed fields' do
33
+ member.update_fields(fields)
34
+
35
+ expect(member.username).to eq('hopperchange')
36
+ end
37
+
38
+ it 'member has been mark as changed' do
39
+ member.update_fields(fields)
40
+
41
+ expect(member.changed?).to be_truthy
42
+ end
43
+ end
44
+
45
+ context "and the field doesn't changed" do
46
+ let(:fields) { { username: member_params['username'] } }
47
+
48
+ it "member attributes doesn't changed" do
49
+ member.update_fields(fields)
50
+
51
+ expect(member.username).to eq(member_params['username'])
52
+ end
53
+
54
+ it "member hasn't been mark as changed" do
55
+ member.update_fields(fields)
56
+
57
+ expect(member.changed?).to be_falsy
58
+ end
59
+ end
60
+
61
+ context "and the field isn't a correct attributes of the card" do
62
+ let(:fields) { { abc: 'abc' } }
63
+
64
+ it "card attributes doesn't changed" do
65
+ member.update_fields(fields)
66
+
67
+ expect(member.id).to eq(member_params['id'])
68
+ expect(member.username).to eq(member_params['username'])
69
+ expect(member.email).to eq(member_params['email'])
70
+ end
71
+
72
+ it "card hasn't been mark as changed" do
73
+ member.update_fields(fields)
74
+
75
+ expect(member.changed?).to be_falsy
76
+ end
77
+ end
78
+ end
79
+
80
+ end
@@ -0,0 +1,349 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Trello::Schema::Attribute::Base' do
4
+
5
+ let(:attribute) { Trello::Schema::Attribute::Base.new(name: name, options: options, serializer: serializer) }
6
+
7
+ describe '#name' do
8
+ let(:options) { nil }
9
+ let(:serializer) { Trello::Schema::Serializer::Default }
10
+
11
+ context 'when name is a symbol' do
12
+ let(:name) { :name }
13
+
14
+ it 'directly return the name' do
15
+ expect(attribute.name).to eq(:name)
16
+ end
17
+ end
18
+
19
+ context 'when name is a string' do
20
+ let(:name) { 'name' }
21
+
22
+ it 'directly return the symbolize name' do
23
+ expect(attribute.name).to eq(:name)
24
+ end
25
+ end
26
+ end
27
+
28
+ describe '#primary_key?' do
29
+ let(:name) { :name }
30
+ let(:serializer) { Trello::Schema::Serializer::Default }
31
+
32
+ context 'when explict pass primary_key' do
33
+ let(:options) { { primary_key: true } }
34
+
35
+ it 'direct return the primary_key value' do
36
+ expect(attribute.primary_key?).to eq(true)
37
+ end
38
+ end
39
+
40
+ context 'when does not explict pass primary_key' do
41
+ let(:options) { nil }
42
+
43
+ it 'return false' do
44
+ expect(attribute.primary_key?).to eq(false)
45
+ end
46
+ end
47
+ end
48
+
49
+ describe '#readlonly?' do
50
+ let(:name) { :name }
51
+ let(:serializer) { Trello::Schema::Serializer::Default }
52
+
53
+ context 'when does not explict pass readonly parameter' do
54
+ let(:options) { nil }
55
+
56
+ it 'return false' do
57
+ expect(attribute.readonly?).to eq(false)
58
+ end
59
+ end
60
+
61
+ context 'when does explict pass readonly parameter' do
62
+ context 'and readonly is true' do
63
+ let(:options) { { readonly: true } }
64
+
65
+ it 'return true' do
66
+ expect(attribute.readonly?).to eq(true)
67
+ end
68
+ end
69
+
70
+ context 'and readonly is false' do
71
+ let(:options) { { readonly: false } }
72
+
73
+ it 'return false' do
74
+ expect(attribute.readonly?).to eq(false)
75
+ end
76
+ end
77
+
78
+ context 'and readonly is not a boolean' do
79
+ let(:options) { { readonly: 'other' } }
80
+
81
+ it 'return false' do
82
+ expect(attribute.readonly?).to eq(false)
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ describe '#update_only?' do
89
+ let(:name) { :name }
90
+ let(:serializer) { Trello::Schema::Serializer::Default }
91
+
92
+ context 'when does not explict pass update_only parameter' do
93
+ let(:options) { nil }
94
+
95
+ it 'return false' do
96
+ expect(attribute.update_only?).to eq(false)
97
+ end
98
+ end
99
+
100
+ context 'when does explict pass update_only parameter' do
101
+ context 'and update_only is true' do
102
+ let(:options) { { update_only: true } }
103
+
104
+ it 'return true' do
105
+ expect(attribute.update_only?).to eq(true)
106
+ end
107
+ end
108
+
109
+ context 'and update_only is false' do
110
+ let(:options) { { update_only: false } }
111
+
112
+ it 'return false' do
113
+ expect(attribute.update_only?).to eq(false)
114
+ end
115
+ end
116
+
117
+ context 'and update_only is not a boolean' do
118
+ let(:options) { { update_only: 'other' } }
119
+
120
+ it 'return false' do
121
+ expect(attribute.update_only?).to eq(false)
122
+ end
123
+ end
124
+ end
125
+ end
126
+
127
+ describe '#create_only?' do
128
+ let(:name) { :name }
129
+ let(:serializer) { Trello::Schema::Serializer::Default }
130
+
131
+ context 'when does not explict pass create_only parameter' do
132
+ let(:options) { nil }
133
+
134
+ it 'return false' do
135
+ expect(attribute.create_only?).to eq(false)
136
+ end
137
+ end
138
+
139
+ context 'when does explict pass create_only parameter' do
140
+ context 'and create_only is true' do
141
+ let(:options) { { create_only: true } }
142
+
143
+ it 'return true' do
144
+ expect(attribute.create_only?).to eq(true)
145
+ end
146
+ end
147
+
148
+ context 'and create_only is false' do
149
+ let(:options) { { create_only: false } }
150
+
151
+ it 'return false' do
152
+ expect(attribute.create_only?).to eq(false)
153
+ end
154
+ end
155
+
156
+ context 'and create_only is not a boolean' do
157
+ let(:options) { { create_only: 'other' } }
158
+
159
+ it 'return false' do
160
+ expect(attribute.create_only?).to eq(false)
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+ describe '#for_action?' do
167
+ let(:name) { :name }
168
+ let(:serializer) { Trello::Schema::Serializer::Default }
169
+
170
+ context 'when it is a primary_key' do
171
+ let(:options) { { primary_key: true } }
172
+
173
+ context 'pass in :create' do
174
+ it 'return false' do
175
+ expect(attribute.for_action?(:create)).to eq(false)
176
+ end
177
+ end
178
+
179
+ context 'pass in :update' do
180
+ it 'return true' do
181
+ expect(attribute.for_action?(:update)).to eq(true)
182
+ end
183
+ end
184
+ end
185
+
186
+ context 'when it is a update_only attribute' do
187
+ let(:options) { { update_only: true } }
188
+
189
+ context 'pass in :create' do
190
+ it 'return false' do
191
+ expect(attribute.for_action?(:create)).to eq(false)
192
+ end
193
+ end
194
+
195
+ context 'pass in :update' do
196
+ it 'return true' do
197
+ expect(attribute.for_action?(:update)).to eq(true)
198
+ end
199
+ end
200
+ end
201
+
202
+ context 'when it is a create_only attribute' do
203
+ let(:options) { { create_only: true } }
204
+
205
+ context 'pass in :create' do
206
+ it 'return true' do
207
+ expect(attribute.for_action?(:create)).to eq(true)
208
+ end
209
+ end
210
+
211
+ context 'pass in :update' do
212
+ it 'return false' do
213
+ expect(attribute.for_action?(:update)).to eq(false)
214
+ end
215
+ end
216
+ end
217
+
218
+ context 'when it is a readonly attribute' do
219
+ context 'and it is a primary_key' do
220
+ let(:options) { { readonly: true, primary_key: true } }
221
+
222
+ context 'pass in :create' do
223
+ it 'return false' do
224
+ expect(attribute.for_action?(:create)).to eq(false)
225
+ end
226
+ end
227
+
228
+ context 'pass in :update' do
229
+ it 'return true' do
230
+ expect(attribute.for_action?(:update)).to eq(true)
231
+ end
232
+ end
233
+ end
234
+
235
+ context 'and it is not a primary_key' do
236
+ let(:options) { { readonly: true } }
237
+
238
+ context 'pass in :create' do
239
+ it 'return false' do
240
+ expect(attribute.for_action?(:create)).to eq(false)
241
+ end
242
+ end
243
+
244
+ context 'pass in :update' do
245
+ it 'return false' do
246
+ expect(attribute.for_action?(:update)).to eq(false)
247
+ end
248
+ end
249
+ end
250
+ end
251
+ end
252
+
253
+ describe '#remote_key' do
254
+ let(:name) { :date_create_utc }
255
+ let(:serializer) { double('serializer') }
256
+
257
+ context 'when explict pass in remote_key' do
258
+ context 'and remote_key is a string' do
259
+ let(:options) { { remote_key: 'dateCreateUTC' } }
260
+
261
+ it 'directly return the stringify remote_key' do
262
+ expect(attribute.remote_key).to eq('dateCreateUTC')
263
+ end
264
+ end
265
+
266
+ context 'and remote_key is a symbol' do
267
+ let(:options) { { remote_key: :dateCreateUTC } }
268
+
269
+ it 'directly return the stringify remote_key' do
270
+ expect(attribute.remote_key).to eq('dateCreateUTC')
271
+ end
272
+ end
273
+ end
274
+
275
+ context 'when does not explict pass in remote_key' do
276
+ let(:options) { {} }
277
+
278
+ it 'return the stringify name' do
279
+ expect(attribute.remote_key).to eq('date_create_utc')
280
+ end
281
+ end
282
+ end
283
+
284
+ describe '#default' do
285
+ let(:name) { :closed }
286
+ let(:serializer) { double('serializer') }
287
+
288
+ context 'when explicit pass in default' do
289
+ let(:options) { { default: false } }
290
+
291
+ it 'directly return the default value' do
292
+ expect(attribute.default).to eq(false)
293
+ end
294
+ end
295
+
296
+ context 'when does not explict pass in default' do
297
+ let(:options) { {} }
298
+
299
+ it 'return nil' do
300
+ expect(attribute.default).to eq(nil)
301
+ end
302
+ end
303
+ end
304
+
305
+ describe '#build_attributes' do
306
+ let(:name) { :date_create_utc }
307
+ let(:serializer) { double('serializer') }
308
+ let(:options) { nil }
309
+
310
+ it 'will raise exception' do
311
+ expect{ attribute.build_attributes({}, {}) }.to raise_error('Need override')
312
+ end
313
+ end
314
+
315
+ describe '#build_payload_for_create' do
316
+ let(:name) { :date_create_utc }
317
+ let(:serializer) { double('serializer') }
318
+ let(:options) { nil }
319
+
320
+ it 'will raise exception' do
321
+ expect{ attribute.build_payload_for_create({}, {}) }.to raise_error('Need override')
322
+ end
323
+ end
324
+
325
+ describe '#build_payload_for_update' do
326
+ let(:name) { :date_create_utc }
327
+ let(:serializer) { double('serializer') }
328
+ let(:options) { nil }
329
+
330
+ it 'will raise exception' do
331
+ expect{ attribute.build_payload_for_update({}, {}) }.to raise_error('Need override')
332
+ end
333
+ end
334
+
335
+ describe '#register' do
336
+ let(:name) { :date_create_utc }
337
+ let(:serializer) { double('serializer') }
338
+ let(:options) { nil }
339
+
340
+ let(:board_klass) { double('Trello::Board') }
341
+
342
+ it 'call register on AttributeRegistration' do
343
+ expect(Trello::Schema::AttributeRegistration).to receive(:register).with(board_klass, attribute)
344
+
345
+ attribute.register(board_klass)
346
+ end
347
+ end
348
+
349
+ end