enju_circulation 0.3.9 → 0.4.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -3
  3. data/app/controllers/checkins_controller.rb +2 -2
  4. data/app/controllers/user_group_has_checkout_types_controller.rb +1 -1
  5. data/app/helpers/items_helper.rb +3 -3
  6. data/app/models/checked_item.rb +7 -17
  7. data/app/models/checkin.rb +3 -2
  8. data/app/models/checkout.rb +2 -2
  9. data/app/models/checkout_stat_has_user.rb +1 -1
  10. data/app/models/checkout_type.rb +9 -7
  11. data/app/models/circulation_status.rb +9 -8
  12. data/app/models/concerns/enju_circulation/enju_item.rb +2 -46
  13. data/app/models/concerns/enju_circulation/enju_user_group.rb +0 -1
  14. data/app/models/concerns/enju_circulation/enju_withdraw.rb +1 -7
  15. data/app/models/manifestation_checkout_stat_transition.rb +1 -1
  16. data/app/models/manifestation_reserve_stat_transition.rb +1 -1
  17. data/app/models/reserve.rb +5 -5
  18. data/app/models/reserve_state_machine.rb +3 -2
  19. data/app/models/reserve_transition.rb +1 -1
  20. data/app/models/retain.rb +15 -0
  21. data/app/models/user_checkout_stat_transition.rb +1 -1
  22. data/app/models/user_group_has_checkout_type.rb +15 -37
  23. data/app/models/user_reserve_stat_transition.rb +1 -1
  24. data/app/views/carrier_type_has_checkout_types/_form.html.erb +2 -2
  25. data/app/views/carrier_type_has_checkout_types/index.html.erb +2 -2
  26. data/app/views/carrier_type_has_checkout_types/show.html.erb +2 -2
  27. data/app/views/carrier_types/_carrier_type_has_checkout_type_fields.html.erb +1 -1
  28. data/app/views/checked_items/new.html.erb +1 -1
  29. data/app/views/checkins/_checkin.html.erb +1 -1
  30. data/app/views/checkout_types/_form.html.erb +1 -1
  31. data/app/views/checkout_types/index.html.erb +1 -1
  32. data/app/views/checkout_types/show.html.erb +2 -2
  33. data/app/views/checkouts/_index_user.html.erb +1 -1
  34. data/app/views/checkouts/_list.html.erb +2 -9
  35. data/app/views/checkouts/index.atom.builder +1 -1
  36. data/app/views/checkouts/index.ics.erb +1 -1
  37. data/app/views/checkouts/index.rss.builder +1 -1
  38. data/app/views/circulation_statuses/_form.html.erb +1 -1
  39. data/app/views/circulation_statuses/index.html.erb +1 -1
  40. data/app/views/circulation_statuses/show.html.erb +1 -1
  41. data/app/views/item_has_use_restrictions/index.html.erb +1 -1
  42. data/app/views/item_has_use_restrictions/show.html.erb +1 -1
  43. data/app/views/manifestation_checkout_stats/_group_by_carrier_type.html.erb +3 -3
  44. data/app/views/manifestation_checkout_stats/_group_by_checkout_type.html.erb +3 -3
  45. data/app/views/manifestations/_circulation_status.html.erb +3 -3
  46. data/app/views/profiles/_submenu_checkout.html.erb +1 -1
  47. data/app/views/reserves/_new.html.erb +1 -1
  48. data/app/views/reserves/_new_user.html.erb +1 -1
  49. data/app/views/reserves/edit.html.erb +1 -1
  50. data/app/views/reserves/index.atom.builder +1 -1
  51. data/app/views/reserves/index.html.erb +1 -1
  52. data/app/views/reserves/index.rss.builder +1 -1
  53. data/app/views/reserves/show.html.erb +1 -1
  54. data/app/views/use_restrictions/_form.html.erb +1 -1
  55. data/app/views/use_restrictions/index.html.erb +1 -1
  56. data/app/views/use_restrictions/show.html.erb +1 -1
  57. data/app/views/user_group_has_checkout_types/edit.html.erb +4 -4
  58. data/app/views/user_group_has_checkout_types/index.html.erb +2 -2
  59. data/app/views/user_group_has_checkout_types/new.html.erb +4 -4
  60. data/app/views/user_group_has_checkout_types/show.html.erb +4 -4
  61. data/app/views/user_groups/_user_group_has_checkout_type_fields.html.erb +2 -2
  62. data/config/locales/translation_en.yml +1 -14
  63. data/config/locales/translation_ja.yml +1 -14
  64. data/config/routes.rb +1 -2
  65. data/db/migrate/20110627122938_add_number_of_day_to_notify_overdue_to_user_group.rb +3 -3
  66. data/db/migrate/20190508160525_create_retains.rb +10 -0
  67. data/db/migrate/20190629134017_rename_user_group_has_checkout_type_due_date_before_to_due_date_after.rb +5 -0
  68. data/db/migrate/20190706052525_add_display_name_translations_to_circulation_status.rb +5 -0
  69. data/db/migrate/20190713114724_add_checkout_id_to_checkin.rb +5 -0
  70. data/db/migrate/20190814120827_add_display_name_translations_to_checkout_type.rb +5 -0
  71. data/lib/enju_circulation/version.rb +1 -1
  72. data/lib/generators/enju_circulation/setup/templates/db/fixtures/checkout_types.yml +3 -5
  73. data/lib/generators/enju_circulation/setup/templates/db/fixtures/circulation_statuses.yml +16 -48
  74. data/lib/tasks/enju_circulation_tasks.rake +7 -1
  75. data/spec/concerns/enju_accept_spec.rb +14 -14
  76. data/spec/controllers/accepts_controller_spec.rb +294 -0
  77. data/spec/controllers/baskets_controller_spec.rb +379 -0
  78. data/spec/controllers/checkins_controller_spec.rb +8 -130
  79. data/spec/controllers/items_controller_spec.rb +23 -43
  80. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  81. data/spec/dummy/app/models/user.rb +1 -1
  82. data/spec/dummy/bin/bundle +1 -1
  83. data/spec/dummy/bin/setup +1 -3
  84. data/spec/dummy/bin/update +4 -2
  85. data/spec/dummy/bin/yarn +3 -3
  86. data/spec/dummy/config/database.yml +70 -9
  87. data/spec/dummy/config/initializers/assets.rb +1 -0
  88. data/spec/dummy/db/development.sqlite3 +0 -0
  89. data/spec/dummy/db/migrate/113_create_events.rb +2 -4
  90. data/spec/dummy/db/migrate/20081028093607_create_event_import_files.rb +2 -4
  91. data/spec/dummy/db/migrate/20090519203307_create_participates.rb +2 -4
  92. data/spec/dummy/db/migrate/20100925074639_create_event_import_results.rb +2 -2
  93. data/spec/dummy/db/migrate/20140720192418_add_default_library_id_to_event_import_file.rb +1 -1
  94. data/spec/dummy/db/migrate/20140812152348_create_event_export_files.rb +1 -1
  95. data/spec/dummy/db/migrate/20140814070854_add_default_event_category_id_to_event_import_file.rb +1 -1
  96. data/spec/dummy/db/migrate/20151128142913_create_places.rb +14 -0
  97. data/spec/dummy/db/migrate/20151201163718_add_place_id_to_event.rb +5 -0
  98. data/spec/dummy/db/migrate/20160703184258_add_most_recent_to_event_import_file_transitions.rb +9 -0
  99. data/spec/dummy/db/migrate/20160703184311_add_most_recent_to_event_export_file_transitions.rb +9 -0
  100. data/spec/dummy/db/migrate/20180107160726_add_constraints_to_most_recent_for_user_import_file_transitions.rb +1 -1
  101. data/spec/dummy/db/migrate/20180107160740_add_constraints_to_most_recent_for_user_export_file_transitions.rb +1 -1
  102. data/spec/dummy/db/migrate/20180107164558_add_constraints_to_most_recent_for_event_import_file_transitions.rb +13 -0
  103. data/spec/dummy/db/migrate/20180107164617_add_constraints_to_most_recent_for_event_export_file_transitions.rb +13 -0
  104. data/spec/dummy/db/migrate/20181119170645_add_foreign_key_to_events_referencing_event_categories.rb +5 -0
  105. data/spec/dummy/db/migrate/20190630113817_add_display_name_translations_to_library_group.rb +12 -0
  106. data/spec/dummy/db/migrate/20190630115523_add_login_banner_translations_to_library_group.rb +6 -0
  107. data/spec/dummy/db/migrate/20190630151446_add_display_name_translations_to_role.rb +5 -0
  108. data/spec/dummy/db/migrate/20190630153136_add_display_name_translations_to_event.rb +6 -0
  109. data/spec/dummy/db/migrate/20190712163038_add_display_name_translations_to_carrier_type.rb +21 -0
  110. data/spec/dummy/db/migrate/20190713114940_add_profile_id_to_user.rb +5 -0
  111. data/spec/dummy/db/migrate/20190713115451_add_full_name_translations_to_profile.rb +5 -0
  112. data/spec/dummy/db/schema.rb +221 -184
  113. data/spec/dummy/db/test.sqlite3 +0 -0
  114. data/spec/dummy/private/system/carrier_types/attachments/000/000/001/original/book.png +0 -0
  115. data/spec/dummy/private/system/carrier_types/attachments/000/000/001/thumb/book.png +0 -0
  116. data/spec/factories/accept.rb +1 -1
  117. data/spec/factories/item.rb +4 -4
  118. data/spec/factories/reserve.rb +1 -5
  119. data/spec/fixtures/carrier_types.yml +16 -15
  120. data/spec/fixtures/checkins.yml +2 -1
  121. data/spec/fixtures/checkout_stat_has_users.yml +1 -1
  122. data/spec/fixtures/checkout_types.yml +11 -10
  123. data/spec/fixtures/checkouts.yml +2 -2
  124. data/spec/fixtures/circulation_statuses.yml +26 -34
  125. data/spec/fixtures/content_types.yml +20 -31
  126. data/spec/fixtures/event_categories.yml +23 -23
  127. data/spec/fixtures/frequencies.yml +17 -25
  128. data/spec/fixtures/items.yml +1 -1
  129. data/spec/fixtures/libraries.yml +30 -31
  130. data/spec/fixtures/library_groups.yml +43 -20
  131. data/spec/fixtures/request_status_types.yml +14 -14
  132. data/spec/fixtures/request_types.yml +13 -13
  133. data/spec/fixtures/reserve_transitions.yml +1 -1
  134. data/spec/fixtures/reserves.yml +3 -3
  135. data/spec/fixtures/roles.yml +22 -5
  136. data/spec/fixtures/shelves.yml +16 -15
  137. data/spec/fixtures/user_group_has_checkout_types.yml +24 -24
  138. data/spec/fixtures/user_groups.yml +23 -3
  139. data/spec/helpers/items_helper_spec.rb +1 -1
  140. data/spec/models/checkin_spec.rb +2 -1
  141. data/spec/models/checkout_spec.rb +2 -2
  142. data/spec/models/checkout_stat_has_user_spec.rb +1 -1
  143. data/spec/models/checkout_type_spec.rb +8 -7
  144. data/spec/models/circulation_status_spec.rb +8 -7
  145. data/spec/models/item_spec.rb +6 -8
  146. data/spec/models/manifestation_spec.rb +15 -18
  147. data/spec/models/reserve_spec.rb +3 -3
  148. data/spec/models/resource_export_file_spec.rb +0 -15
  149. data/spec/models/retain_spec.rb +16 -0
  150. data/spec/models/user_group_has_checkout_type_spec.rb +15 -32
  151. data/spec/models/withdraw_spec.rb +4 -6
  152. data/spec/policies/manifestation_policy_spec.rb +2 -1
  153. data/spec/rails_helper.rb +10 -3
  154. data/spec/views/items/index.html.erb_spec.rb +1 -4
  155. metadata +396 -446
  156. data/app/controllers/lending_policies_controller.rb +0 -106
  157. data/app/models/lending_policy.rb +0 -30
  158. data/app/views/lending_policies/_form.html.erb +0 -41
  159. data/app/views/lending_policies/edit.html.erb +0 -13
  160. data/app/views/lending_policies/index.html.erb +0 -42
  161. data/app/views/lending_policies/new.html.erb +0 -12
  162. data/app/views/lending_policies/show.html.erb +0 -50
  163. data/db/migrate/20090831220301_create_lending_policies.rb +0 -21
  164. data/spec/controllers/lending_policies_controller_spec.rb +0 -444
  165. data/spec/controllers/withdraws_controller_spec.rb +0 -26
  166. data/spec/dummy/config/locales/en.yml +0 -208
  167. data/spec/dummy/config/locales/ja.yml +0 -200
  168. data/spec/dummy/db/migrate/20190818075603_add_memo_to_manifestation.rb +0 -5
  169. data/spec/dummy/db/migrate/20190818075628_add_memo_to_item.rb +0 -5
  170. data/spec/dummy/db/migrate/20200425072340_create_manifestation_custom_properties.rb +0 -12
  171. data/spec/dummy/db/migrate/20200425072349_create_item_custom_properties.rb +0 -12
  172. data/spec/dummy/db/migrate/20200425074758_create_manifestation_custom_values.rb +0 -12
  173. data/spec/dummy/db/migrate/20200425074822_create_item_custom_values.rb +0 -12
  174. data/spec/fixtures/accepts.yml +0 -9
  175. data/spec/fixtures/bookstores.yml +0 -99
  176. data/spec/fixtures/budget_types.yml +0 -30
  177. data/spec/fixtures/exemplifies.yml +0 -168
  178. data/spec/fixtures/lending_policies.yml +0 -98
  179. data/spec/models/lending_policy_spec.rb +0 -23
  180. data/spec/system/items_spec.rb +0 -21
  181. data/spec/system/user_group_has_checkout_types.rb +0 -14
@@ -0,0 +1,379 @@
1
+ require 'rails_helper'
2
+
3
+ describe BasketsController do
4
+ fixtures :all
5
+
6
+ describe 'GET index' do
7
+ describe 'When logged in as Administrator' do
8
+ login_fixture_admin
9
+
10
+ it 'assigns all baskets as @baskets' do
11
+ get :index, params: { user_id: users(:user1).username }
12
+ assigns(:baskets).should_not be_empty
13
+ response.should be_successful
14
+ end
15
+
16
+ it 'should get index without user_id' do
17
+ get :index
18
+ response.should be_successful
19
+ end
20
+ end
21
+
22
+ describe 'When logged in as Librarian' do
23
+ login_fixture_librarian
24
+
25
+ it 'assigns all baskets as @baskets' do
26
+ get :index, params: { user_id: users(:user1).username }
27
+ assigns(:baskets).should_not be_empty
28
+ response.should be_successful
29
+ end
30
+ end
31
+
32
+ describe 'When logged in as User' do
33
+ login_fixture_user
34
+
35
+ it 'assigns all baskets as @baskets' do
36
+ get :index, params: { user_id: users(:user1).username }
37
+ assigns(:baskets).should be_nil
38
+ response.should be_forbidden
39
+ end
40
+ end
41
+
42
+ describe 'When not logged in' do
43
+ it 'assigns all baskets as @baskets' do
44
+ get :index, params: { user_id: users(:user1).username }
45
+ assigns(:baskets).should be_nil
46
+ response.should redirect_to(new_user_session_url)
47
+ end
48
+ end
49
+ end
50
+
51
+ describe 'GET show' do
52
+ describe 'When logged in as Administrator' do
53
+ login_fixture_admin
54
+
55
+ it 'assigns the requested basket as @basket' do
56
+ get :show, params: { id: baskets(:basket_00001).id, user_id: users(:admin).username }
57
+ assigns(:basket).should eq(baskets(:basket_00001))
58
+ end
59
+ end
60
+
61
+ describe 'When logged in as Librarian' do
62
+ login_fixture_librarian
63
+
64
+ it 'assigns the requested basket as @basket' do
65
+ get :show, params: { id: baskets(:basket_00001).id, user_id: users(:admin).username }
66
+ assigns(:basket).should eq(baskets(:basket_00001))
67
+ end
68
+ end
69
+
70
+ describe 'When logged in as User' do
71
+ login_fixture_user
72
+
73
+ it 'assigns the requested basket as @basket' do
74
+ get :show, params: { id: baskets(:basket_00001).id, user_id: users(:admin).username }
75
+ assigns(:basket).should eq(baskets(:basket_00001))
76
+ response.should be_forbidden
77
+ end
78
+ end
79
+
80
+ describe 'When not logged in' do
81
+ it 'assigns the requested basket as @basket' do
82
+ get :show, params: { id: baskets(:basket_00001).id, user_id: users(:admin).username }
83
+ assigns(:basket).should eq(baskets(:basket_00001))
84
+ response.should redirect_to(new_user_session_url)
85
+ end
86
+ end
87
+ end
88
+
89
+ describe 'GET new' do
90
+ describe 'When logged in as Administrator' do
91
+ login_fixture_admin
92
+
93
+ it 'assigns the requested basket as @basket' do
94
+ get :new
95
+ assigns(:basket).should_not be_valid
96
+ end
97
+ end
98
+
99
+ describe 'When logged in as Librarian' do
100
+ login_fixture_librarian
101
+
102
+ it 'assigns the requested basket as @basket' do
103
+ get :new
104
+ assigns(:basket).should_not be_valid
105
+ end
106
+ end
107
+
108
+ describe 'When logged in as User' do
109
+ login_fixture_user
110
+
111
+ it 'should not assign the requested basket as @basket' do
112
+ get :new
113
+ assigns(:basket).should be_nil
114
+ response.should be_forbidden
115
+ end
116
+ end
117
+
118
+ describe 'When not logged in' do
119
+ it 'should not assign the requested basket as @basket' do
120
+ get :new
121
+ assigns(:basket).should be_nil
122
+ response.should redirect_to(new_user_session_url)
123
+ end
124
+ end
125
+ end
126
+
127
+ describe 'GET edit' do
128
+ describe 'When logged in as Administrator' do
129
+ login_fixture_admin
130
+ before(:each) do
131
+ @basket = baskets(:basket_00001)
132
+ end
133
+
134
+ it 'assigns the requested basket as @basket' do
135
+ get :edit, params: { id: @basket.id }
136
+ assigns(:basket).should eq(@basket)
137
+ end
138
+ end
139
+
140
+ describe 'When logged in as Librarian' do
141
+ login_fixture_librarian
142
+ before(:each) do
143
+ @basket = baskets(:basket_00001)
144
+ end
145
+
146
+ it 'assigns the requested basket as @basket' do
147
+ get :edit, params: { id: @basket.id }
148
+ assigns(:basket).should eq(@basket)
149
+ end
150
+ end
151
+
152
+ describe 'When logged in as User' do
153
+ login_fixture_user
154
+ before(:each) do
155
+ @basket = baskets(:basket_00001)
156
+ end
157
+
158
+ it 'should not assign the requested basket as @basket' do
159
+ get :edit, params: { id: @basket.id }
160
+ assigns(:basket).should eq(@basket)
161
+ response.should be_forbidden
162
+ end
163
+ end
164
+
165
+ describe 'When not logged in' do
166
+ before(:each) do
167
+ @basket = baskets(:basket_00001)
168
+ end
169
+
170
+ it 'should not assign the requested basket as @basket' do
171
+ get :edit, params: { id: @basket.id }
172
+ assigns(:basket).should eq(@basket)
173
+ response.should redirect_to new_user_session_url
174
+ end
175
+ end
176
+ end
177
+
178
+ describe 'POST create' do
179
+ before(:each) do
180
+ @attrs = { user_number: users(:user1).profile.user_number }
181
+ @invalid_attrs = { user_number: 'invalid' }
182
+ end
183
+
184
+ describe 'When logged in as Administrator' do
185
+ login_fixture_admin
186
+
187
+ describe 'with valid params' do
188
+ it 'assigns a newly created basket as @basket' do
189
+ post :create, params: { basket: { user_number: users(:user1).profile.user_number } }
190
+ assigns(:basket).should be_valid
191
+ end
192
+ end
193
+
194
+ describe 'with blank params' do
195
+ it 'assigns a newly created basket as @basket' do
196
+ post :create, params: { basket: { note: 'test' } }
197
+ assigns(:basket).should_not be_valid
198
+ end
199
+ end
200
+
201
+ describe 'with invalid params' do
202
+ it 'assigns a newly created basket as @basket' do
203
+ post :create, params: { basket: @invalid_attrs }
204
+ assigns(:basket).should_not be_valid
205
+ end
206
+ end
207
+ end
208
+
209
+ describe 'When logged in as Librarian' do
210
+ login_fixture_librarian
211
+
212
+ describe 'with valid params' do
213
+ it 'assigns a newly created basket as @basket' do
214
+ post :create, params: { basket: { user_number: users(:user1).profile.user_number } }
215
+ assigns(:basket).should be_valid
216
+ end
217
+ end
218
+
219
+ describe 'with blank params' do
220
+ it 'assigns a newly created basket as @basket' do
221
+ post :create, params: { basket: { note: 'test' } }
222
+ assigns(:basket).should_not be_valid
223
+ end
224
+ end
225
+
226
+ describe 'with invalid params' do
227
+ it 'assigns a newly created basket as @basket' do
228
+ post :create, params: { basket: @invalid_attrs }
229
+ assigns(:basket).should_not be_valid
230
+ end
231
+ end
232
+
233
+ it 'should not create basket when user is suspended' do
234
+ post :create, params: { basket: { user_number: users(:user4).profile.user_number } }
235
+ assigns(:basket).should_not be_valid
236
+ assigns(:basket).errors['base'].include?(I18n.t('basket.this_account_is_suspended')).should be_truthy
237
+ response.should be_successful
238
+ end
239
+
240
+ it 'should not create basket when user is not found' do
241
+ post :create, params: { basket: { user_number: 'not found' } }
242
+ assigns(:basket).should_not be_valid
243
+ assigns(:basket).errors['base'].include?(I18n.t('user.not_found')).should be_truthy
244
+ response.should be_successful
245
+ end
246
+
247
+ it 'should not create basket without user_number' do
248
+ post :create, params: { basket: { note: 'test' } }
249
+ assigns(:basket).should_not be_valid
250
+ response.should be_successful
251
+ end
252
+
253
+ it 'should create basket' do
254
+ post :create, params: { basket: { user_number: users(:user1).profile.user_number } }
255
+ assigns(:basket).should be_valid
256
+ response.should redirect_to new_checked_item_url(basket_id: assigns(:basket).id)
257
+ end
258
+
259
+ it 'should not create basket without user_number' do
260
+ post :create, params: { basket: { note: 'test' } }
261
+ assigns(:basket).should_not be_valid
262
+ response.should be_successful
263
+ end
264
+ end
265
+
266
+ describe 'When logged in as User' do
267
+ login_fixture_user
268
+
269
+ describe 'with valid params' do
270
+ it 'assigns a newly created basket as @basket' do
271
+ post :create, params: { basket: { user_number: users(:user1).profile.user_number } }
272
+ assigns(:basket).should be_nil
273
+ end
274
+
275
+ it 'should be forbidden' do
276
+ post :create, params: { basket: { user_number: users(:user1).profile.user_number } }
277
+ response.should be_forbidden
278
+ end
279
+ end
280
+
281
+ it 'should not create basket' do
282
+ post :create, params: { basket: { user_number: users(:user1).profile.user_number } }
283
+ response.should be_forbidden
284
+ end
285
+ end
286
+
287
+ describe 'When not logged in' do
288
+ describe 'with blank params' do
289
+ it 'assigns a newly created basket as @basket' do
290
+ post :create, params: { basket: { note: 'test' } }
291
+ assigns(:basket).should be_nil
292
+ end
293
+
294
+ it 'should be redirected to new_user_session_url' do
295
+ post :create, params: { basket: { note: 'test' } }
296
+ assigns(:basket).should be_nil
297
+ assert_response :redirect
298
+ response.should redirect_to new_user_session_url
299
+ end
300
+ end
301
+ end
302
+ end
303
+
304
+ describe 'PUT update' do
305
+ before(:each) do
306
+ @attrs = { user_id: users(:user1).username }
307
+ end
308
+
309
+ describe 'When logged in as Librarian' do
310
+ login_fixture_librarian
311
+
312
+ describe 'with valid params' do
313
+ it 'updates the requested basket' do
314
+ put :update, params: { id: baskets(:basket_00008).id, basket: @attrs }
315
+ end
316
+
317
+ it 'assigns the requested basket as @basket' do
318
+ put :update, params: { id: baskets(:basket_00008).id, basket: @attrs }
319
+ assigns(:basket).checkouts.order('created_at DESC').first.item.circulation_status.name.should eq 'On Loan'
320
+ response.should redirect_to(checkouts_url(user_id: assigns(:basket).user.username))
321
+ end
322
+ end
323
+ end
324
+ end
325
+
326
+ describe 'DELETE destroy' do
327
+ before(:each) do
328
+ @basket = FactoryBot.create(:basket)
329
+ end
330
+
331
+ describe 'When logged in as Administrator' do
332
+ login_fixture_admin
333
+
334
+ it 'should destroy basket without user_id' do
335
+ delete :destroy, params: { id: baskets(:basket_00001).id, basket: { user_id: nil }, user_id: users(:user1).username }
336
+ response.should redirect_to(checkouts_url(user_id: assigns(:basket).user.username))
337
+ end
338
+
339
+ it 'should destroy basket' do
340
+ delete :destroy, params: { id: baskets(:basket_00001).id, basket: {}, user_id: users(:user1).username }
341
+ response.should redirect_to(checkouts_url(user_id: assigns(:basket).user.username))
342
+ end
343
+ end
344
+
345
+ describe 'When logged in as Librarian' do
346
+ login_fixture_librarian
347
+
348
+ it 'should destroy basket without user_id' do
349
+ delete :destroy, params: { id: baskets(:basket_00001).id, basket: { user_id: nil }, user_id: users(:user1).username }
350
+ response.should redirect_to(checkouts_url(user_id: assigns(:basket).user.username))
351
+ end
352
+
353
+ it 'should destroy basket' do
354
+ delete :destroy, params: { id: baskets(:basket_00001).id, basket: {}, user_id: users(:user1).username }
355
+ response.should redirect_to(checkouts_url(user_id: assigns(:basket).user.username))
356
+ end
357
+ end
358
+
359
+ describe 'When logged in as User' do
360
+ login_fixture_user
361
+
362
+ it 'should not destroy basket' do
363
+ delete :destroy, params: { id: baskets(:basket_00003).id, user_id: users(:user1).username }
364
+ response.should be_forbidden
365
+ end
366
+ end
367
+
368
+ describe 'When not logged in' do
369
+ it 'destroys the requested basket' do
370
+ delete :destroy, params: { id: @basket.id }
371
+ end
372
+
373
+ it 'should be forbidden' do
374
+ delete :destroy, params: { id: @basket.id }
375
+ response.should redirect_to new_user_session_url
376
+ end
377
+ end
378
+ end
379
+ end
@@ -201,14 +201,14 @@ describe CheckinsController do
201
201
  it 'redirects to the created checkin' do
202
202
  post :create, params: { checkin: @attrs, basket_id: 9 }
203
203
  response.should redirect_to(checkins_url(basket_id: assigns(:checkin).basket_id))
204
- assigns(:checkin).checkout.item.circulation_status.name.should eq 'Available On Shelf'
204
+ assigns(:checkin).item.circulation_status.name.should eq 'Available On Shelf'
205
205
  end
206
206
 
207
207
  it 'should checkin the overdue item' do
208
208
  post :create, params: { checkin: { item_identifier: '00014' }, basket_id: 9 }
209
209
  response.should redirect_to(checkins_url(basket_id: assigns(:checkin).basket_id))
210
210
  assigns(:checkin).checkout.should be_valid
211
- assigns(:checkin).checkout.item.circulation_status.name.should eq 'Available On Shelf'
211
+ assigns(:checkin).item.circulation_status.name.should eq 'Available On Shelf'
212
212
  end
213
213
  end
214
214
  end
@@ -249,14 +249,14 @@ describe CheckinsController do
249
249
  it 'should show notification when it is reserved' do
250
250
  post :create, params: { checkin: { item_identifier: '00008' }, basket_id: 9 }
251
251
  flash[:message].to_s.index(I18n.t('item.this_item_is_reserved')).should be_truthy
252
- assigns(:checkin).checkout.item.should be_retained
253
- assigns(:checkin).checkout.item.circulation_status.name.should eq 'Available On Shelf'
252
+ assigns(:checkin).item.should be_retained
253
+ assigns(:checkin).item.circulation_status.name.should eq 'Available On Shelf'
254
254
  response.should redirect_to(checkins_url(basket_id: assigns(:basket).id))
255
255
  end
256
256
 
257
257
  it 'should show notification when an item includes supplements' do
258
258
  post :create, params: { checkin: { item_identifier: '00004' }, basket_id: 9 }
259
- assigns(:checkin).checkout.item.circulation_status.name.should eq 'Available On Shelf'
259
+ assigns(:checkin).item.circulation_status.name.should eq 'Available On Shelf'
260
260
  flash[:message].to_s.index(I18n.t('item.this_item_include_supplement')).should be_truthy
261
261
  response.should redirect_to(checkins_url(basket_id: assigns(:basket).id))
262
262
  end
@@ -306,128 +306,6 @@ describe CheckinsController do
306
306
  end
307
307
  end
308
308
 
309
- describe 'POST create (json format)' do
310
- before(:each) do
311
- @attrs = { item_identifier: '00003' }
312
- @invalid_attrs = { item_identifier: 'invalid' }
313
- request.env["HTTP_ACCEPT"] = 'application/json'
314
- end
315
-
316
- describe 'When logged in as Administrator' do
317
- login_fixture_admin
318
-
319
- describe 'with valid params' do
320
- it 'assigns a newly created checkin as @checkin' do
321
- post :create, params: { checkin: @attrs }
322
- assigns(:checkin).should be_nil
323
- end
324
-
325
- it 'should not create checkin without basket_id' do
326
- post :create, params: { checkin: @attrs }
327
- json = JSON.parse(response.body)
328
- expect(json['error']).to eq('forbidden')
329
- end
330
-
331
- describe 'When basket_id is specified' do
332
- it 'redirects to the created checkin' do
333
- post :create, params: { checkin: @attrs, basket_id: 9 }
334
- expect(response).to have_http_status(:created)
335
- json = JSON.parse(response.body)
336
- expect(json['result']['basket_id']).to eq(9)
337
- assigns(:checkin).checkout.item.circulation_status.name.should eq 'Available On Shelf'
338
- end
339
-
340
- it 'should checkin the overdue item' do
341
- post :create, params: { checkin: { item_identifier: '00014' }, basket_id: 9 }
342
- expect(response).to have_http_status(:created)
343
- assigns(:checkin).checkout.should be_valid
344
- assigns(:checkin).checkout.item.circulation_status.name.should eq 'Available On Shelf'
345
- end
346
- end
347
- end
348
-
349
- describe 'with invalid params' do
350
- it 'assigns a newly created but unsaved checkin as @checkin' do
351
- post :create, params: { checkin: @invalid_attrs }
352
- assigns(:checkin).should be_nil
353
- end
354
-
355
- it 'should be forbidden' do
356
- post :create, params: { checkin: @invalid_attrs }
357
- json = JSON.parse(response.body)
358
- expect(json['error']).to eq('forbidden')
359
- end
360
- end
361
-
362
- it 'should not create checkin without item_id' do
363
- post :create, params: { checkin: { item_identifier: nil }, basket_id: 9 }
364
- assigns(:checkin).should_not be_valid
365
- expect(response).to have_http_status(:unprocessable_entity)
366
- json = JSON.parse(response.body)
367
- expect(json['messages']['base']).to match_array([I18n.t('checkin.item_not_found')])
368
- expect(json['messages']['item_id']).to match_array([I18n.t('errors.messages.blank')])
369
- end
370
- end
371
-
372
- describe 'When logged in as Librarian' do
373
- login_fixture_librarian
374
-
375
- describe 'with valid params' do
376
- it 'assigns a newly created checkin as @checkin' do
377
- post :create, params: { checkin: @attrs }
378
- assigns(:checkin).should be_nil
379
- end
380
-
381
- it 'should not create checkin without basket_id' do
382
- post :create, params: { checkin: @attrs }
383
- json = JSON.parse(response.body)
384
- expect(json['error']).to eq('forbidden')
385
- end
386
-
387
- it 'should show notification when it is reserved' do
388
- post :create, params: { checkin: { item_identifier: '00008' }, basket_id: 9 }
389
- flash[:message].to_s.index(I18n.t('item.this_item_is_reserved')).should be_truthy
390
- assigns(:checkin).checkout.item.should be_retained
391
- assigns(:checkin).checkout.item.circulation_status.name.should eq 'Available On Shelf'
392
- expect(response).to have_http_status(:created)
393
- end
394
-
395
- it 'should show notification when an item includes supplements' do
396
- post :create, params: { checkin: { item_identifier: '00004' }, basket_id: 9 }
397
- assigns(:checkin).checkout.item.circulation_status.name.should eq 'Available On Shelf'
398
- flash[:message].to_s.index(I18n.t('item.this_item_include_supplement')).should be_truthy
399
- expect(response).to have_http_status(:created)
400
- end
401
- end
402
-
403
- it "should show notice when other library's item is checked in" do
404
- sign_in users(:librarian2)
405
- post :create, params: { checkin: { item_identifier: '00009' }, basket_id: 9 }
406
- assigns(:checkin).should be_valid
407
- flash[:message].to_s.index(I18n.t('checkin.other_library_item')).should be_truthy
408
- expect(response).to have_http_status(:created)
409
- end
410
- end
411
-
412
- describe 'When not logged in' do
413
- before(:each) do
414
- @attrs = { item_identifier: '00003' }
415
- @invalid_attrs = { item_identifier: 'invalid' }
416
- end
417
-
418
- describe 'with valid params' do
419
- it 'assigns a newly created checkin as @checkin' do
420
- post :create, params: { checkin: @attrs }
421
- end
422
-
423
- it 'should redirect to new session url' do
424
- post :create, params: { checkin: @attrs }
425
- expect(response).to have_http_status(:ok)
426
- end
427
- end
428
- end
429
- end
430
-
431
309
  describe 'PUT update' do
432
310
  before(:each) do
433
311
  @checkin = checkins(:checkin_00001)
@@ -457,7 +335,7 @@ describe CheckinsController do
457
335
 
458
336
  it "re-renders the 'edit' template" do
459
337
  put :update, params: { id: @checkin.id, checkin: @invalid_attrs }
460
- expect(response).to be_successful
338
+ response.should render_template('edit')
461
339
  end
462
340
 
463
341
  it 'should not update checkin without item_identifier' do
@@ -486,12 +364,12 @@ describe CheckinsController do
486
364
  describe 'with invalid params' do
487
365
  it 'assigns the checkin as @checkin' do
488
366
  put :update, params: { id: @checkin.id, checkin: @invalid_attrs }
489
- expect(assigns(:checkin)).not_to be_valid
367
+ assigns(:checkin).should_not be_valid
490
368
  end
491
369
 
492
370
  it "re-renders the 'edit' template" do
493
371
  put :update, params: { id: @checkin.id, checkin: @invalid_attrs }
494
- expect(response).to be_successful
372
+ response.should render_template('edit')
495
373
  end
496
374
  end
497
375
  end
@@ -3,6 +3,10 @@ require 'rails_helper'
3
3
  describe ItemsController do
4
4
  fixtures :all
5
5
 
6
+ def valid_attributes
7
+ FactoryBot.attributes_for(:item)
8
+ end
9
+
6
10
  describe 'POST create' do
7
11
  before(:each) do
8
12
  manifestation = FactoryBot.create(:manifestation)
@@ -13,58 +17,34 @@ describe ItemsController do
13
17
  describe 'When logged in as Administrator' do
14
18
  login_fixture_admin
15
19
 
16
- describe 'with valid params' do
17
- it 'should create reserved item' do
18
- post :create, params: { item: { circulation_status_id: 1, manifestation_id: 2 } }
19
- expect(assigns(:item)).to be_valid
20
-
21
- expect(response).to redirect_to item_url(assigns(:item))
22
- flash[:message].should eq I18n.t('item.this_item_is_reserved')
23
- assigns(:item).manifestation.should eq Manifestation.find(2)
24
- assigns(:item).should be_retained
25
- end
26
-
27
- it "should create another item with already retained" do
28
- reserve = FactoryBot.create(:reserve)
29
- reserve.transition_to!(:requested)
30
- post :create, params: { item: FactoryBot.attributes_for(:item, manifestation_id: reserve.manifestation.id) }
31
- expect(assigns(:item)).to be_valid
32
- expect(response).to redirect_to item_url(assigns(:item))
33
- post :create, params: { item: FactoryBot.attributes_for(:item, manifestation_id: reserve.manifestation.id) }
34
- expect(assigns(:item)).to be_valid
35
- expect(response).to redirect_to item_url(assigns(:item))
36
- end
37
-
38
- it 'should create a lending policy' do
39
- old_lending_policy_count = LendingPolicy.count
40
- post :create, params: { item: @attrs }
41
- LendingPolicy.count.should eq old_lending_policy_count
42
- end
43
- end
44
- end
45
- end
46
-
47
- describe 'PUT update' do
48
- describe 'When logged in as Administrator' do
49
- login_fixture_admin
20
+ it 'should create reserved item' do
21
+ post :create, params: { item: { circulation_status_id: 1, manifestation_id: 2 } }
22
+ expect(assigns(:item)).to be_valid
50
23
 
51
- it 'should remove an item' do
52
- item = FactoryBot.create(:item)
53
- put :update, params: { id: item.id, item: {circulation_status_id: CirculationStatus.find_by(name: 'Removed').id } }
54
- expect(assigns(:item).valid?).to be_truthy
55
24
  expect(response).to redirect_to item_url(assigns(:item))
25
+ flash[:message].should eq I18n.t('item.this_item_is_reserved')
26
+ assigns(:item).manifestation.should eq Manifestation.find(2)
27
+ assigns(:item).should be_retained
56
28
  end
57
29
 
58
- it 'should not remove a reserved item' do
59
- item = FactoryBot.create(:reserve).item
60
- put :update, params: { id: item.id, item: {circulation_status_id: CirculationStatus.find_by(name: 'Removed').id } }
61
- expect(assigns(:item).valid?).to be_falsy
62
- expect(response).to be_successful
30
+ it "should create another item with already retained" do
31
+ reserve = FactoryBot.create(:reserve)
32
+ reserve.transition_to!(:requested)
33
+ post :create, params: { item: FactoryBot.attributes_for(:item, manifestation_id: reserve.manifestation.id) }
34
+ expect(assigns(:item)).to be_valid
35
+ expect(response).to redirect_to item_url(assigns(:item))
36
+ post :create, params: { item: FactoryBot.attributes_for(:item, manifestation_id: reserve.manifestation.id) }
37
+ expect(assigns(:item)).to be_valid
38
+ expect(response).to redirect_to item_url(assigns(:item))
63
39
  end
64
40
  end
65
41
  end
66
42
 
67
43
  describe 'DELETE destroy' do
44
+ before(:each) do
45
+ @item = FactoryBot.create(:item)
46
+ end
47
+
68
48
  describe 'When logged in as Administrator' do
69
49
  login_fixture_admin
70
50
 
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ end
4
+
@@ -9,9 +9,9 @@ class User < ApplicationRecord
9
9
  include EnjuCirculation::EnjuUser
10
10
  end
11
11
 
12
- Accept.include(EnjuCirculation::EnjuAccept)
13
12
  Basket.include(EnjuCirculation::EnjuBasket)
14
13
  Manifestation.include(EnjuCirculation::EnjuManifestation)
14
+ Manifestation.include(EnjuManifestationViewer::EnjuManifestation)
15
15
  Item.include(EnjuCirculation::EnjuItem)
16
16
  Item.include(EnjuLibrary::EnjuItem)
17
17
  Profile.include(EnjuCirculation::EnjuProfile)
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
3
3
  load Gem.bin_path('bundler', 'bundle')