enju_circulation 0.3.11 → 0.4.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) 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/checkouts_controller.rb +2 -2
  5. data/app/controllers/demands_controller.rb +1 -1
  6. data/app/controllers/manifestation_checkout_stats_controller.rb +2 -2
  7. data/app/controllers/manifestation_reserve_stats_controller.rb +2 -2
  8. data/app/controllers/reserves_controller.rb +2 -2
  9. data/app/controllers/user_checkout_stats_controller.rb +2 -2
  10. data/app/controllers/user_group_has_checkout_types_controller.rb +1 -1
  11. data/app/controllers/user_reserve_stats_controller.rb +2 -2
  12. data/app/helpers/items_helper.rb +3 -3
  13. data/app/models/checked_item.rb +7 -17
  14. data/app/models/checkin.rb +3 -2
  15. data/app/models/checkout.rb +2 -2
  16. data/app/models/checkout_stat_has_user.rb +1 -1
  17. data/app/models/checkout_type.rb +9 -7
  18. data/app/models/circulation_status.rb +9 -8
  19. data/app/models/concerns/enju_circulation/enju_item.rb +2 -46
  20. data/app/models/concerns/enju_circulation/enju_user_group.rb +0 -1
  21. data/app/models/concerns/enju_circulation/enju_withdraw.rb +1 -7
  22. data/app/models/manifestation_checkout_stat_transition.rb +1 -1
  23. data/app/models/manifestation_reserve_stat_transition.rb +1 -1
  24. data/app/models/reserve.rb +5 -5
  25. data/app/models/reserve_state_machine.rb +3 -2
  26. data/app/models/reserve_transition.rb +1 -1
  27. data/app/models/retain.rb +15 -0
  28. data/app/models/user_checkout_stat_transition.rb +1 -1
  29. data/app/models/user_group_has_checkout_type.rb +15 -37
  30. data/app/models/user_reserve_stat_transition.rb +1 -1
  31. data/app/views/carrier_type_has_checkout_types/_form.html.erb +2 -2
  32. data/app/views/carrier_type_has_checkout_types/index.html.erb +2 -2
  33. data/app/views/carrier_type_has_checkout_types/show.html.erb +2 -2
  34. data/app/views/carrier_types/_carrier_type_has_checkout_type_fields.html.erb +1 -1
  35. data/app/views/checked_items/new.html.erb +1 -1
  36. data/app/views/checkins/_checkin.html.erb +1 -1
  37. data/app/views/checkout_types/_form.html.erb +1 -1
  38. data/app/views/checkout_types/index.html.erb +1 -1
  39. data/app/views/checkout_types/show.html.erb +2 -2
  40. data/app/views/checkouts/_index_user.html.erb +1 -1
  41. data/app/views/checkouts/_list.html.erb +2 -9
  42. data/app/views/checkouts/index.atom.builder +1 -1
  43. data/app/views/checkouts/index.ics.erb +1 -1
  44. data/app/views/checkouts/index.rss.builder +1 -1
  45. data/app/views/checkouts/{index.text.ruby → index.txt.ruby} +0 -0
  46. data/app/views/circulation_statuses/_form.html.erb +1 -1
  47. data/app/views/circulation_statuses/index.html.erb +1 -1
  48. data/app/views/circulation_statuses/show.html.erb +1 -1
  49. data/app/views/item_has_use_restrictions/index.html.erb +1 -1
  50. data/app/views/item_has_use_restrictions/show.html.erb +1 -1
  51. data/app/views/manifestation_checkout_stats/_group_by_carrier_type.html.erb +3 -3
  52. data/app/views/manifestation_checkout_stats/_group_by_checkout_type.html.erb +3 -3
  53. data/app/views/manifestation_checkout_stats/{show.text.erb → show.txt.erb} +0 -0
  54. data/app/views/manifestation_reserve_stats/{show.text.erb → show.txt.erb} +0 -0
  55. data/app/views/manifestations/_circulation_status.html.erb +3 -3
  56. data/app/views/profiles/_submenu_checkout.html.erb +1 -1
  57. data/app/views/reserves/_new.html.erb +1 -1
  58. data/app/views/reserves/_new_user.html.erb +1 -1
  59. data/app/views/reserves/edit.html.erb +1 -1
  60. data/app/views/reserves/index.atom.builder +1 -1
  61. data/app/views/reserves/index.html.erb +1 -1
  62. data/app/views/reserves/index.rss.builder +1 -1
  63. data/app/views/reserves/{index.text.ruby → index.txt.ruby} +0 -0
  64. data/app/views/reserves/show.html.erb +1 -1
  65. data/app/views/use_restrictions/_form.html.erb +1 -1
  66. data/app/views/use_restrictions/index.html.erb +1 -1
  67. data/app/views/use_restrictions/show.html.erb +1 -1
  68. data/app/views/user_checkout_stats/{show.text.erb → show.txt.erb} +0 -0
  69. data/app/views/user_group_has_checkout_types/edit.html.erb +4 -4
  70. data/app/views/user_group_has_checkout_types/index.html.erb +2 -2
  71. data/app/views/user_group_has_checkout_types/new.html.erb +4 -4
  72. data/app/views/user_group_has_checkout_types/show.html.erb +4 -4
  73. data/app/views/user_groups/_user_group_has_checkout_type_fields.html.erb +2 -2
  74. data/app/views/user_reserve_stats/{show.text.erb → show.txt.erb} +0 -0
  75. data/config/locales/translation_en.yml +1 -14
  76. data/config/locales/translation_ja.yml +1 -14
  77. data/config/routes.rb +1 -2
  78. data/db/migrate/20110627122938_add_number_of_day_to_notify_overdue_to_user_group.rb +3 -3
  79. data/db/migrate/20190508160525_create_retains.rb +10 -0
  80. data/db/migrate/20190629134017_rename_user_group_has_checkout_type_due_date_before_to_due_date_after.rb +5 -0
  81. data/db/migrate/20190706052525_add_display_name_translations_to_circulation_status.rb +5 -0
  82. data/db/migrate/20190713114724_add_checkout_id_to_checkin.rb +5 -0
  83. data/db/migrate/20190814120827_add_display_name_translations_to_checkout_type.rb +5 -0
  84. data/lib/enju_circulation/version.rb +1 -1
  85. data/lib/generators/enju_circulation/setup/templates/db/fixtures/checkout_types.yml +3 -5
  86. data/lib/generators/enju_circulation/setup/templates/db/fixtures/circulation_statuses.yml +16 -48
  87. data/lib/tasks/enju_circulation_tasks.rake +7 -1
  88. data/spec/concerns/enju_accept_spec.rb +14 -14
  89. data/spec/controllers/accepts_controller_spec.rb +294 -0
  90. data/spec/controllers/baskets_controller_spec.rb +379 -0
  91. data/spec/controllers/checkins_controller_spec.rb +8 -130
  92. data/spec/controllers/checkouts_controller_spec.rb +5 -5
  93. data/spec/controllers/items_controller_spec.rb +23 -43
  94. data/spec/controllers/reserves_controller_spec.rb +9 -9
  95. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  96. data/spec/dummy/app/models/user.rb +1 -1
  97. data/spec/dummy/bin/bundle +1 -1
  98. data/spec/dummy/bin/setup +1 -3
  99. data/spec/dummy/bin/update +4 -2
  100. data/spec/dummy/bin/yarn +3 -3
  101. data/spec/dummy/config/database.yml +70 -9
  102. data/spec/dummy/config/initializers/assets.rb +1 -0
  103. data/spec/dummy/db/development.sqlite3 +0 -0
  104. data/spec/dummy/db/migrate/113_create_events.rb +2 -4
  105. data/spec/dummy/db/migrate/20081028093607_create_event_import_files.rb +2 -4
  106. data/spec/dummy/db/migrate/20090519203307_create_participates.rb +2 -4
  107. data/spec/dummy/db/migrate/20100925074639_create_event_import_results.rb +2 -2
  108. data/spec/dummy/db/migrate/20140720192418_add_default_library_id_to_event_import_file.rb +1 -1
  109. data/spec/dummy/db/migrate/20140812152348_create_event_export_files.rb +1 -1
  110. data/spec/dummy/db/migrate/20140814070854_add_default_event_category_id_to_event_import_file.rb +1 -1
  111. data/spec/dummy/db/migrate/20151128142913_create_places.rb +14 -0
  112. data/spec/dummy/db/migrate/20151201163718_add_place_id_to_event.rb +5 -0
  113. data/spec/dummy/db/migrate/20160703184258_add_most_recent_to_event_import_file_transitions.rb +9 -0
  114. data/spec/dummy/db/migrate/20160703184311_add_most_recent_to_event_export_file_transitions.rb +9 -0
  115. data/spec/dummy/db/migrate/20180107160726_add_constraints_to_most_recent_for_user_import_file_transitions.rb +1 -1
  116. data/spec/dummy/db/migrate/20180107160740_add_constraints_to_most_recent_for_user_export_file_transitions.rb +1 -1
  117. data/spec/dummy/db/migrate/20180107164558_add_constraints_to_most_recent_for_event_import_file_transitions.rb +13 -0
  118. data/spec/dummy/db/migrate/20180107164617_add_constraints_to_most_recent_for_event_export_file_transitions.rb +13 -0
  119. data/spec/dummy/db/migrate/20181119170645_add_foreign_key_to_events_referencing_event_categories.rb +5 -0
  120. data/spec/dummy/db/migrate/20190630113817_add_display_name_translations_to_library_group.rb +12 -0
  121. data/spec/dummy/db/migrate/20190630115523_add_login_banner_translations_to_library_group.rb +6 -0
  122. data/spec/dummy/db/migrate/20190630151446_add_display_name_translations_to_role.rb +5 -0
  123. data/spec/dummy/db/migrate/20190630153136_add_display_name_translations_to_event.rb +6 -0
  124. data/spec/dummy/db/migrate/20190712163038_add_display_name_translations_to_carrier_type.rb +21 -0
  125. data/spec/dummy/db/migrate/20190713114940_add_profile_id_to_user.rb +5 -0
  126. data/spec/dummy/db/migrate/20190713115451_add_full_name_translations_to_profile.rb +5 -0
  127. data/spec/dummy/db/schema.rb +221 -184
  128. data/spec/dummy/db/test.sqlite3 +0 -0
  129. data/spec/dummy/private/system/carrier_types/attachments/000/000/001/original/book.png +0 -0
  130. data/spec/dummy/private/system/carrier_types/attachments/000/000/001/thumb/book.png +0 -0
  131. data/spec/factories/accept.rb +1 -1
  132. data/spec/factories/item.rb +4 -4
  133. data/spec/factories/reserve.rb +1 -5
  134. data/spec/fixtures/carrier_types.yml +16 -15
  135. data/spec/fixtures/checkins.yml +2 -1
  136. data/spec/fixtures/checkout_stat_has_users.yml +1 -1
  137. data/spec/fixtures/checkout_types.yml +11 -10
  138. data/spec/fixtures/checkouts.yml +2 -2
  139. data/spec/fixtures/circulation_statuses.yml +26 -34
  140. data/spec/fixtures/content_types.yml +20 -31
  141. data/spec/fixtures/event_categories.yml +23 -23
  142. data/spec/fixtures/frequencies.yml +17 -25
  143. data/spec/fixtures/items.yml +1 -1
  144. data/spec/fixtures/libraries.yml +30 -31
  145. data/spec/fixtures/library_groups.yml +43 -20
  146. data/spec/fixtures/request_status_types.yml +14 -14
  147. data/spec/fixtures/request_types.yml +13 -13
  148. data/spec/fixtures/reserve_transitions.yml +1 -1
  149. data/spec/fixtures/reserves.yml +3 -3
  150. data/spec/fixtures/roles.yml +22 -5
  151. data/spec/fixtures/shelves.yml +16 -15
  152. data/spec/fixtures/user_group_has_checkout_types.yml +24 -24
  153. data/spec/fixtures/user_groups.yml +23 -3
  154. data/spec/helpers/items_helper_spec.rb +1 -1
  155. data/spec/models/checked_item_spec.rb +0 -11
  156. data/spec/models/checkin_spec.rb +2 -1
  157. data/spec/models/checkout_spec.rb +2 -2
  158. data/spec/models/checkout_stat_has_user_spec.rb +1 -1
  159. data/spec/models/checkout_type_spec.rb +8 -7
  160. data/spec/models/circulation_status_spec.rb +8 -7
  161. data/spec/models/item_spec.rb +6 -8
  162. data/spec/models/manifestation_spec.rb +15 -18
  163. data/spec/models/reserve_spec.rb +3 -3
  164. data/spec/models/resource_export_file_spec.rb +0 -15
  165. data/spec/models/retain_spec.rb +16 -0
  166. data/spec/models/user_group_has_checkout_type_spec.rb +15 -32
  167. data/spec/models/withdraw_spec.rb +4 -6
  168. data/spec/policies/manifestation_policy_spec.rb +2 -1
  169. data/spec/rails_helper.rb +10 -3
  170. data/spec/system/reserves_spec.rb +1 -1
  171. data/spec/views/items/index.html.erb_spec.rb +1 -4
  172. metadata +402 -452
  173. data/app/controllers/lending_policies_controller.rb +0 -106
  174. data/app/models/lending_policy.rb +0 -30
  175. data/app/views/lending_policies/_form.html.erb +0 -41
  176. data/app/views/lending_policies/edit.html.erb +0 -13
  177. data/app/views/lending_policies/index.html.erb +0 -42
  178. data/app/views/lending_policies/new.html.erb +0 -12
  179. data/app/views/lending_policies/show.html.erb +0 -50
  180. data/db/migrate/20090831220301_create_lending_policies.rb +0 -21
  181. data/spec/controllers/lending_policies_controller_spec.rb +0 -444
  182. data/spec/controllers/withdraws_controller_spec.rb +0 -26
  183. data/spec/dummy/config/locales/en.yml +0 -208
  184. data/spec/dummy/config/locales/ja.yml +0 -200
  185. data/spec/dummy/db/migrate/20190818075603_add_memo_to_manifestation.rb +0 -5
  186. data/spec/dummy/db/migrate/20190818075628_add_memo_to_item.rb +0 -5
  187. data/spec/dummy/db/migrate/20200425072340_create_manifestation_custom_properties.rb +0 -12
  188. data/spec/dummy/db/migrate/20200425072349_create_item_custom_properties.rb +0 -12
  189. data/spec/dummy/db/migrate/20200425074758_create_manifestation_custom_values.rb +0 -12
  190. data/spec/dummy/db/migrate/20200425074822_create_item_custom_values.rb +0 -12
  191. data/spec/fixtures/accepts.yml +0 -9
  192. data/spec/fixtures/bookstores.yml +0 -99
  193. data/spec/fixtures/budget_types.yml +0 -30
  194. data/spec/fixtures/exemplifies.yml +0 -168
  195. data/spec/fixtures/lending_policies.yml +0 -98
  196. data/spec/models/lending_policy_spec.rb +0 -23
  197. data/spec/system/items_spec.rb +0 -21
  198. data/spec/system/user_group_has_checkout_types.rb +0 -14
@@ -0,0 +1,5 @@
1
+ class RenameUserGroupHasCheckoutTypeDueDateBeforeToDueDateAfter < ActiveRecord::Migration[5.2]
2
+ def change
3
+ rename_column :user_group_has_checkout_types, :set_due_date_before_closing_day, :set_due_date_after_closing_day
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddDisplayNameTranslationsToCirculationStatus < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :circulation_statuses, :display_name_translations, :jsonb, default: {}, null: false
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddCheckoutIdToCheckin < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_reference :checkins, :checkin, foreign_key: true
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddDisplayNameTranslationsToCheckoutType < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :checkout_types, :display_name_translations, :jsonb, default: {}, null: false
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module EnjuCirculation
2
- VERSION = "0.3.11".freeze
2
+ VERSION = "0.4.0.beta.1"
3
3
  end
@@ -3,20 +3,18 @@
3
3
  checkout_type_00001:
4
4
  id: 1
5
5
  name: book
6
- display_name: "en: Book\r\n\
7
- ja: 図書"
6
+ display_name_translations: {"en": "Book", "ja": "図書"}
8
7
  note:
9
8
  position: 1
10
9
  checkout_type_00002:
11
10
  id: 2
12
11
  name: serial
13
- display_name: "en: Serial\r\n\
14
- ja: 定期刊行物"
12
+ display_name_translations: {"en": "Serial", "ja": "定期刊行物"}
15
13
  note:
16
14
  position: 2
17
15
  checkout_type_00003:
18
16
  id: 3
19
17
  name: cd
20
- display_name: CD
18
+ display_name_translations: {"en": "CD", "ja": "CD"}
21
19
  note:
22
20
  position: 3
@@ -1,129 +1,97 @@
1
1
  ---
2
2
  circulation_status_00001:
3
3
  name: Available For Pickup
4
- display_name: |-
5
- en: Available For Pickup
6
- ja: 持ち出し可能
4
+ display_name_translations: {"en": "Available For Pickup", "ja": "持ち出し可能"}
7
5
  id: 1
8
6
  note: ""
9
7
  position: 1
10
8
  circulation_status_00002:
11
9
  name: Available On Shelf
12
- display_name: |-
13
- en: Available On Shelf
14
- ja: 在架(利用可能)
10
+ display_name_translations: {"en": "Available on Shelf", "ja": "在架(利用可能)"}
15
11
  id: 2
16
12
  note: ""
17
13
  position: 2
18
14
  circulation_status_00003:
19
15
  name: Circulation Status Undefined
20
- display_name: |-
21
- en: Circulation Status Undefined
22
- ja: 貸出状態未定義
16
+ display_name_translations: {"en": "Circulation Status Undefined", "ja": "貸出状態未定義"}
23
17
  id: 3
24
18
  note: ""
25
19
  position: 3
26
20
  circulation_status_00004:
27
21
  name: Claimed Returned Or Never Borrowed
28
- display_name: |-
29
- en: Claimed Returned Or Never Borrowed
30
- ja: 利用者が返却済み、または未貸出と主張
22
+ display_name_translations: {"en": "Claimed Returned Or Never Borrowed", "ja": "利用者が返却済み、または未貸出と主張"}
31
23
  id: 4
32
24
  note: ""
33
25
  position: 4
34
26
  circulation_status_00005:
35
27
  name: In Process
36
- display_name: |-
37
- en: In Process
38
- ja: 作業中
28
+ display_name_translations: {"en": "In Process", "ja": "作業中"}
39
29
  id: 5
40
30
  note: ""
41
31
  position: 5
42
32
  circulation_status_00006:
43
33
  name: In Transit Between Library Locations
44
- display_name: |-
45
- en: In Transit Between Library Locations
46
- ja: 移動中
34
+ display_name_translations: {"en": "In Transit Between Library Locations", "ja": "移動中"}
47
35
  id: 6
48
36
  note: ""
49
37
  position: 6
50
38
  circulation_status_00007:
51
39
  name: Lost
52
- display_name: |-
53
- en: Lost
54
- ja: 紛失
40
+ display_name_translations: {"en": "Lost", "ja": "紛失"}
55
41
  id: 7
56
42
  note: ""
57
43
  position: 7
58
44
  circulation_status_00008:
59
45
  name: Missing
60
- display_name: |-
61
- en: Missing
62
- ja: 行方不明
46
+ display_name_translations: {"en": "Missing", "ja": "行方不明"}
63
47
  id: 8
64
48
  note: ""
65
49
  position: 8
66
50
  circulation_status_00009:
67
51
  name: Not Available
68
- display_name: |-
69
- en: Not Available
70
- ja: 利用不可
52
+ display_name_translations: {"en": "Not Available", "ja": "利用不可"}
71
53
  id: 9
72
54
  note: ""
73
55
  position: 9
74
56
  circulation_status_00010:
75
57
  name: On Loan
76
- display_name: |-
77
- en: On Loan
78
- ja: 貸出中
58
+ display_name_translations: {"en": "On Loan", "ja": "貸出中"}
79
59
  id: 10
80
60
  note: ""
81
61
  position: 10
82
62
  circulation_status_00011:
83
63
  name: On Order
84
- display_name: |-
85
- en: On Order
86
- ja: 発注中
64
+ display_name_translations: {"en": "On Order", "ja": "発注中"}
87
65
  id: 11
88
66
  note: ""
89
67
  position: 11
90
68
  circulation_status_00012:
91
69
  name: Pending Transfer
92
- display_name: |-
93
- en: Pending Transfer
94
- ja: 移動予定
70
+ display_name_translations: {"en": "Pending Transfer", "ja": "移動予定"}
95
71
  id: 12
96
72
  note: ""
97
73
  position: 12
98
74
  circulation_status_00013:
99
75
  name: Recalled
100
- display_name: |-
101
- en: Recalled
102
- ja: 返却依頼中
76
+ display_name_translations: {"en": "Recalled", "ja": "返却依頼中"}
103
77
  id: 13
104
78
  note: ""
105
79
  position: 13
106
80
  circulation_status_00014:
107
81
  name: Waiting To Be Reshelved
108
- display_name: |-
109
- en: Waiting To Be Reshelved
110
- ja: 再配架待ち
82
+ display_name_translations: {"en": "Waiting To Be Reshelved", "ja": "再配架待ち"}
111
83
  id: 14
112
84
  note: ""
113
85
  position: 14
114
86
  circulation_status_00015:
115
87
  name: Not arrived
116
- display_name: |-
117
- en: Not arrived
118
- ja: 未着
88
+ display_name_translations: {"en": "Not arrived", "ja": "未着"}
119
89
  id: 15
120
90
  note: ""
121
91
  position: 15
122
92
  circulation_status_00016:
123
93
  name: Removed
124
- display_name: |-
125
- en: Removed
126
- ja: 除籍済み
94
+ display_name_translations: {"en": "Removed", "ja": "除籍済み"}
127
95
  id: 16
128
96
  note: ""
129
97
  position: 16
@@ -74,8 +74,14 @@ namespace :enju_circulation do
74
74
  c.user.try(:profile).try(:full_name),
75
75
  c.user.try(:profile).try(:user_number),
76
76
  ].join("\t")
77
- end
77
+ end
78
78
  end
79
79
  end
80
80
  end
81
+
82
+ desc "upgrade enju_circulation to enju_leaf 2.0"
83
+ task upgrade_20: :environment do
84
+ sql = 'UPDATE checkins SET checkout_id = checkouts.id FROM checkouts WHERE checkouts.checkin_id = checkins.id;'
85
+ ActiveRecord::Base.connection.execute(sql)
86
+ end
81
87
  end
@@ -1,32 +1,32 @@
1
1
  require 'rails_helper'
2
2
 
3
+ class MyAccept < Accept
4
+ include EnjuCirculation::EnjuAccept
5
+ end
6
+
3
7
  describe EnjuCirculation::EnjuAccept do
4
8
  fixtures :all
5
9
 
6
10
  it "should successfully accept" do
7
- accept = Accept.new(FactoryBot.attributes_for(:accept))
8
- accept.item = FactoryBot.create(:item)
11
+ accept = MyAccept.new(FactoryBot.attributes_for(:accept))
12
+ expect(accept.item).to be_truthy
13
+ expect(accept.item.circulation_status.name).to eq "In Process"
9
14
  accept.save!
10
15
  expect(accept.item.circulation_status.name).to eq "Available On Shelf"
11
16
  expect(accept.item.use_restriction.name).to eq "Limited Circulation, Normal Loan Period"
12
17
  end
13
18
 
14
19
  it "should reflect to items list", solr: true do
15
- Item.reindex
16
-
17
20
  3.times do
18
- FactoryBot.create(:item, circulation_status: CirculationStatus.find_by(name: 'In Process'))
21
+ FactoryBot.create(:item)
19
22
  end
20
-
21
- result = Item.search.build { facet :circulation_status }.execute
22
- inprocess_count = result.facet(:circulation_status).rows.find{|e| e.value == "In Process" }.count
23
- onshelf_count = result.facet(:circulation_status).rows.find{|e| e.value == "Available On Shelf" }.try(:count) || 0
24
-
25
- accept = Accept.new(FactoryBot.attributes_for(:accept))
26
- accept.item = FactoryBot.create(:item)
23
+ result = Item.count
24
+ inprocess_count = Item.where(circulation_status: CirculationStatus.find_by(name: "In Process")).count
25
+ onshelf_count = Item.where(circulation_status: CirculationStatus.find_by(name: "Available On Shelf")).count
26
+ accept = MyAccept.new(FactoryBot.attributes_for(:accept))
27
27
  accept.save!
28
28
  result = Item.search.build { facet :circulation_status }.execute
29
- expect(result.facet(:circulation_status).rows.find{|e| e.value == "In Process" }.count).to eq inprocess_count
30
- expect(result.facet(:circulation_status).rows.find{|e| e.value == "Available On Shelf" }.try(:count)).to eq onshelf_count + 1
29
+ expect(Item.where(circulation_status: CirculationStatus.find_by(name: "In Process")).count).to eq inprocess_count
30
+ expect(Item.where(circulation_status: CirculationStatus.find_by(name: "Available On Shelf")).count).to eq onshelf_count + 1
31
31
  end
32
32
  end
@@ -0,0 +1,294 @@
1
+ require 'rails_helper'
2
+
3
+ describe AcceptsController do
4
+ fixtures :all
5
+
6
+ def mock_user(stubs = {})
7
+ (@mock_user ||= mock_model(Accept).as_null_object).tap do |user|
8
+ user.stub(stubs) unless stubs.empty?
9
+ end
10
+ end
11
+
12
+ describe 'GET index' do
13
+ describe 'When logged in as Administrator' do
14
+ login_fixture_admin
15
+
16
+ it 'assigns all accepts as @accepts' do
17
+ get :index
18
+ assigns(:accepts).should_not be_nil
19
+ response.should be_successful
20
+ end
21
+
22
+ describe 'When basket_id is specified' do
23
+ it 'assigns all accepts as @accepts' do
24
+ get :index, params: { basket_id: baskets(:basket_00010).id }
25
+ assigns(:accepts).should eq baskets(:basket_00010).accepts.order('accepts.created_at DESC').page(1)
26
+ response.should be_successful
27
+ end
28
+ end
29
+ end
30
+
31
+ describe 'When logged in as Librarian' do
32
+ login_fixture_librarian
33
+
34
+ it 'assigns all accepts as @accepts' do
35
+ get :index
36
+ assigns(:accepts).should_not be_nil
37
+ response.should be_successful
38
+ end
39
+
40
+ describe 'When basket_id is specified' do
41
+ it 'assigns all accepts as @accepts' do
42
+ get :index, params: { basket_id: baskets(:basket_00009).id }
43
+ assigns(:accepts).should eq baskets(:basket_00009).accepts.order('accepts.created_at DESC').page(1)
44
+ response.should be_successful
45
+ end
46
+ end
47
+ end
48
+
49
+ describe 'When logged in as User' do
50
+ login_fixture_user
51
+
52
+ it 'should not assign all accepts as @accepts' do
53
+ get :index
54
+ assigns(:accepts).should be_nil
55
+ response.should be_forbidden
56
+ end
57
+ end
58
+ end
59
+
60
+ describe 'GET show' do
61
+ describe 'When logged in as Administrator' do
62
+ login_fixture_admin
63
+
64
+ it 'assigns the requested accept as @accept' do
65
+ accept = FactoryBot.create(:accept)
66
+ get :show, params: { id: accept.id }
67
+ assigns(:accept).should eq(accept)
68
+ end
69
+ end
70
+
71
+ describe 'When logged in as Librarian' do
72
+ login_fixture_librarian
73
+
74
+ it 'assigns the requested accept as @accept' do
75
+ accept = FactoryBot.create(:accept)
76
+ get :show, params: { id: accept.id }
77
+ assigns(:accept).should eq(accept)
78
+ end
79
+ end
80
+
81
+ describe 'When logged in as User' do
82
+ login_fixture_user
83
+
84
+ it 'assigns the requested accept as @accept' do
85
+ accept = FactoryBot.create(:accept)
86
+ get :show, params: { id: accept.id }
87
+ assigns(:accept).should eq(accept)
88
+ response.should be_forbidden
89
+ end
90
+ end
91
+
92
+ describe 'When not logged in' do
93
+ it 'assigns the requested accept as @accept' do
94
+ accept = FactoryBot.create(:accept)
95
+ get :show, params: { id: accept.id }
96
+ assigns(:accept).should eq(accept)
97
+ response.should redirect_to new_user_session_url
98
+ end
99
+ end
100
+ end
101
+
102
+ describe 'GET new' do
103
+ describe 'When logged in as Administrator' do
104
+ login_fixture_admin
105
+
106
+ it 'assigns the requested accept as @accept' do
107
+ get :new
108
+ assigns(:accept).should_not be_valid
109
+ end
110
+ end
111
+
112
+ describe 'When logged in as Librarian' do
113
+ login_fixture_librarian
114
+
115
+ it 'assigns the requested accept as @accept' do
116
+ get :new
117
+ assigns(:accept).should_not be_valid
118
+ end
119
+ end
120
+
121
+ describe 'When logged in as User' do
122
+ login_fixture_user
123
+
124
+ it 'should not assign the requested accept as @accept' do
125
+ get :new
126
+ assigns(:accept).should be_nil
127
+ response.should be_forbidden
128
+ end
129
+ end
130
+
131
+ describe 'When not logged in' do
132
+ it 'should not assign the requested accept as @accept' do
133
+ get :new
134
+ assigns(:accept).should be_nil
135
+ response.should redirect_to(new_user_session_url)
136
+ end
137
+ end
138
+ end
139
+
140
+ describe 'POST create' do
141
+ before(:each) do
142
+ @attrs = { item_identifier: '00003' }
143
+ @invalid_attrs = { item_identifier: 'invalid' }
144
+ end
145
+
146
+ describe 'When logged in as Administrator' do
147
+ login_fixture_admin
148
+
149
+ describe 'with valid params' do
150
+ it 'assigns a newly created accept as @accept' do
151
+ post :create, params: { accept: @attrs }
152
+ assigns(:accept).should be_nil
153
+ end
154
+
155
+ it 'should not create a new accept without basket_id' do
156
+ post :create, params: { accept: @attrs }
157
+ response.should be_forbidden
158
+ end
159
+
160
+ describe 'When basket_id is specified' do
161
+ it 'redirects to the created accept' do
162
+ post :create, params: { accept: @attrs, basket_id: baskets(:basket_00009).id }
163
+ response.should redirect_to(accepts_url(basket_id: assigns(:accept).basket.id))
164
+ assigns(:accept).item.circulation_status.name.should eq 'Available On Shelf'
165
+ end
166
+ end
167
+ end
168
+
169
+ describe 'with invalid params' do
170
+ it 'assigns a newly created but unsaved accept as @accept' do
171
+ post :create, params: { accept: @invalid_attrs }
172
+ assigns(:accept).should be_nil
173
+ end
174
+
175
+ it 'should be forbidden' do
176
+ post :create, params: { accept: @invalid_attrs }
177
+ response.should be_forbidden
178
+ end
179
+ end
180
+
181
+ it 'should not create accept without item_id' do
182
+ post :create, params: { accept: { item_identifier: nil }, basket_id: baskets(:basket_00009).id }
183
+ assigns(:accept).should_not be_valid
184
+ response.should be_successful
185
+ end
186
+ end
187
+
188
+ describe 'When logged in as Librarian' do
189
+ login_fixture_librarian
190
+
191
+ describe 'with valid params' do
192
+ it 'assigns a newly created accept as @accept' do
193
+ post :create, params: { accept: @attrs }
194
+ assigns(:accept).should be_nil
195
+ end
196
+
197
+ it 'should not create a new accept without basket_id' do
198
+ post :create, params: { accept: @attrs }
199
+ response.should be_forbidden
200
+ end
201
+ end
202
+ end
203
+
204
+ describe 'When logged in as User' do
205
+ login_fixture_user
206
+
207
+ describe 'with valid params' do
208
+ it 'assigns a newly created accept as @accept' do
209
+ post :create, params: { accept: @attrs }
210
+ assigns(:accept).should be_nil
211
+ end
212
+
213
+ it 'should be forbidden' do
214
+ post :create, params: { accept: @attrs }
215
+ response.should be_forbidden
216
+ end
217
+ end
218
+ end
219
+
220
+ describe 'When not logged in' do
221
+ before(:each) do
222
+ @attrs = { item_identifier: '00003' }
223
+ @invalid_attrs = { item_identifier: 'invalid' }
224
+ end
225
+
226
+ describe 'with valid params' do
227
+ it 'assigns a newly created accept as @accept' do
228
+ post :create, params: { accept: @attrs }
229
+ end
230
+
231
+ it 'should redirect to new session url' do
232
+ post :create, params: { accept: @attrs }
233
+ response.should redirect_to new_user_session_url
234
+ end
235
+ end
236
+ end
237
+ end
238
+
239
+ describe 'DELETE destroy' do
240
+ before(:each) do
241
+ @accept = FactoryBot.create(:accept)
242
+ end
243
+
244
+ describe 'When logged in as Administrator' do
245
+ login_fixture_admin
246
+
247
+ it 'destroys the requested accept' do
248
+ delete :destroy, params: { id: @accept.id }
249
+ end
250
+
251
+ it 'redirects to the accepts list' do
252
+ delete :destroy, params: { id: @accept.id }
253
+ response.should redirect_to(accepts_url)
254
+ end
255
+ end
256
+
257
+ describe 'When logged in as Librarian' do
258
+ login_fixture_librarian
259
+
260
+ it 'destroys the requested accept' do
261
+ delete :destroy, params: { id: @accept.id }
262
+ end
263
+
264
+ it 'redirects to the accepts list' do
265
+ delete :destroy, params: { id: @accept.id }
266
+ response.should redirect_to(accepts_url)
267
+ end
268
+ end
269
+
270
+ describe 'When logged in as User' do
271
+ login_fixture_user
272
+
273
+ it 'destroys the requested accept' do
274
+ delete :destroy, params: { id: @accept.id }
275
+ end
276
+
277
+ it 'should be forbidden' do
278
+ delete :destroy, params: { id: @accept.id }
279
+ response.should be_forbidden
280
+ end
281
+ end
282
+
283
+ describe 'When not logged in' do
284
+ it 'destroys the requested accept' do
285
+ delete :destroy, params: { id: @accept.id }
286
+ end
287
+
288
+ it 'should be forbidden' do
289
+ delete :destroy, params: { id: @accept.id }
290
+ response.should redirect_to(new_user_session_url)
291
+ end
292
+ end
293
+ end
294
+ end