enju_library 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) hide show
  1. data/README.rdoc +2 -2
  2. data/app/controllers/shelves_controller.rb +2 -1
  3. data/app/helpers/shelves_helper.rb +9 -5
  4. data/app/models/library.rb +1 -2
  5. data/app/models/library_group.rb +7 -1
  6. data/app/models/shelf.rb +1 -0
  7. data/app/views/accepts/index.html.erb +2 -2
  8. data/app/views/bookstores/index.html.erb +3 -3
  9. data/app/views/bookstores/show.html.erb +1 -1
  10. data/app/views/budget_types/index.html.erb +2 -2
  11. data/app/views/libraries/_form.html.erb +1 -1
  12. data/app/views/libraries/index.html.erb +3 -3
  13. data/app/views/libraries/show.html.erb +1 -1
  14. data/app/views/library_groups/index.html.erb +1 -1
  15. data/app/views/request_status_types/index.html.erb +2 -2
  16. data/app/views/request_types/index.html.erb +2 -2
  17. data/app/views/search_engines/index.html.erb +2 -2
  18. data/app/views/shelves/_library_facet.html.erb +1 -4
  19. data/app/views/shelves/index.html.erb +2 -2
  20. data/app/views/shelves/show.mobile.erb +33 -0
  21. data/app/views/subscribes/index.html.erb +2 -2
  22. data/app/views/subscriptions/index.html.erb +2 -2
  23. data/app/views/subscriptions/show.html.erb +1 -1
  24. data/lib/enju_library/engine.rb +0 -8
  25. data/lib/enju_library/version.rb +1 -1
  26. data/lib/enju_library.rb +0 -2
  27. data/spec/controllers/bookstores_controller_spec.rb +447 -0
  28. data/spec/controllers/budget_types_controller_spec.rb +167 -0
  29. data/spec/controllers/libraries_controller_spec.rb +517 -0
  30. data/spec/controllers/library_groups_controller_spec.rb +133 -0
  31. data/spec/controllers/request_status_types_controller_spec.rb +447 -0
  32. data/spec/controllers/request_types_controller_spec.rb +447 -0
  33. data/spec/controllers/search_engines_controller_spec.rb +447 -0
  34. data/spec/controllers/shelves_controller_spec.rb +437 -0
  35. data/spec/controllers/subscribes_controller_spec.rb +441 -0
  36. data/spec/controllers/subscriptions_controller_spec.rb +442 -0
  37. data/{test → spec}/dummy/README.rdoc +0 -0
  38. data/{test → spec}/dummy/Rakefile +0 -0
  39. data/{test → spec}/dummy/app/assets/javascripts/application.js +0 -0
  40. data/{test → spec}/dummy/app/assets/stylesheets/application.css +0 -0
  41. data/spec/dummy/app/controllers/application_controller.rb +59 -0
  42. data/spec/dummy/app/helpers/application_helper.rb +13 -0
  43. data/spec/dummy/app/models/ability.rb +51 -0
  44. data/spec/dummy/app/models/picture_file.rb +49 -0
  45. data/spec/dummy/app/models/role.rb +46 -0
  46. data/spec/dummy/app/models/user.rb +94 -0
  47. data/spec/dummy/app/models/user_group.rb +40 -0
  48. data/spec/dummy/app/models/user_has_role.rb +5 -0
  49. data/{test → spec}/dummy/app/views/layouts/application.html.erb +0 -0
  50. data/spec/dummy/app/views/page/403.html.erb +9 -0
  51. data/spec/dummy/app/views/page/403.mobile.erb +5 -0
  52. data/spec/dummy/app/views/page/403.xml.erb +4 -0
  53. data/spec/dummy/app/views/page/404.html.erb +9 -0
  54. data/spec/dummy/app/views/page/404.mobile.erb +5 -0
  55. data/spec/dummy/app/views/page/404.xml.erb +4 -0
  56. data/{test → spec}/dummy/config/application.rb +3 -0
  57. data/{test → spec}/dummy/config/boot.rb +0 -0
  58. data/{test → spec}/dummy/config/database.yml +0 -0
  59. data/{test → spec}/dummy/config/environment.rb +0 -0
  60. data/{test → spec}/dummy/config/environments/development.rb +0 -0
  61. data/{test → spec}/dummy/config/environments/production.rb +0 -0
  62. data/{test → spec}/dummy/config/environments/test.rb +0 -0
  63. data/{test → spec}/dummy/config/initializers/backtrace_silencers.rb +0 -0
  64. data/spec/dummy/config/initializers/devise.rb +205 -0
  65. data/{test → spec}/dummy/config/initializers/inflections.rb +0 -0
  66. data/{test → spec}/dummy/config/initializers/mime_types.rb +0 -0
  67. data/{test → spec}/dummy/config/initializers/secret_token.rb +0 -0
  68. data/{test → spec}/dummy/config/initializers/session_store.rb +0 -0
  69. data/{test → spec}/dummy/config/initializers/wrap_parameters.rb +0 -0
  70. data/{test → spec}/dummy/config/locales/en.yml +0 -0
  71. data/{test → spec}/dummy/config/routes.rb +2 -0
  72. data/{test → spec}/dummy/config.ru +0 -0
  73. data/spec/dummy/db/development.sqlite3 +0 -0
  74. data/spec/dummy/db/migrate/001_create_patrons.rb +58 -0
  75. data/spec/dummy/db/migrate/005_create_manifestations.rb +61 -0
  76. data/spec/dummy/db/migrate/006_create_items.rb +31 -0
  77. data/spec/dummy/db/migrate/012_create_owns.rb +12 -0
  78. data/spec/dummy/db/migrate/015_create_creates.rb +12 -0
  79. data/spec/dummy/db/migrate/047_create_produces.rb +12 -0
  80. data/spec/dummy/db/migrate/073_create_carrier_types.rb +11 -0
  81. data/spec/dummy/db/migrate/077_create_user_groups.rb +16 -0
  82. data/spec/dummy/db/migrate/125_create_donates.rb +12 -0
  83. data/spec/dummy/db/migrate/20080830154109_create_realizes.rb +13 -0
  84. data/spec/dummy/db/migrate/20080830172106_create_exemplifies.rb +13 -0
  85. data/spec/dummy/db/migrate/20080905191442_create_patron_types.rb +12 -0
  86. data/spec/dummy/db/migrate/20081025083323_create_countries.rb +28 -0
  87. data/spec/dummy/db/migrate/20081025083905_create_languages.rb +23 -0
  88. data/spec/dummy/db/migrate/20081027150907_create_picture_files.rb +16 -0
  89. data/spec/dummy/db/migrate/20090705133942_add_attachments_picture_to_picture_file.rb +15 -0
  90. data/spec/dummy/db/migrate/20090812151902_create_patron_relationship_types.rb +12 -0
  91. data/spec/dummy/db/migrate/20091012101112_add_dcndl_schema.rb +27 -0
  92. data/spec/dummy/db/migrate/20091202124834_create_versions.rb +18 -0
  93. data/spec/dummy/db/migrate/20091214131723_create_series_statements.rb +13 -0
  94. data/spec/dummy/db/migrate/20100223121519_rename_series_statement_title_to_original_title.rb +13 -0
  95. data/spec/dummy/db/migrate/20100321235924_add_series_statement_identifier_to_series_statement.rb +10 -0
  96. data/spec/dummy/db/migrate/20100525124311_create_manifestation_relationships.rb +13 -0
  97. data/spec/dummy/db/migrate/20100606073747_create_patron_relationships.rb +13 -0
  98. data/spec/dummy/db/migrate/20100607044753_create_manifestation_relationship_types.rb +12 -0
  99. data/spec/dummy/db/migrate/20100814091104_add_position_to_patron_relationship.rb +11 -0
  100. data/spec/dummy/db/migrate/20101212070145_add_acquired_at_to_item.rb +9 -0
  101. data/spec/dummy/db/migrate/20110301035123_add_pub_date_to_manifestation.rb +9 -0
  102. data/spec/dummy/db/migrate/20110301121550_add_birth_date_and_death_date_to_patron.rb +11 -0
  103. data/spec/dummy/db/migrate/20110318183304_add_valid_period_for_new_user_to_user_group.rb +13 -0
  104. data/spec/dummy/db/migrate/20110425133109_add_issn_to_series_statement.rb +9 -0
  105. data/spec/dummy/db/migrate/20110618091240_add_periodical_to_series_statement.rb +9 -0
  106. data/spec/dummy/db/migrate/20110619064807_add_edition_string_to_manifestation.rb +9 -0
  107. data/{db → spec/dummy/db}/migrate/20110620173525_add_bookstore_id_to_item.rb +0 -0
  108. data/spec/dummy/db/migrate/20110627034940_create_series_statement_merge_lists.rb +9 -0
  109. data/spec/dummy/db/migrate/20110627035057_create_series_statement_merges.rb +12 -0
  110. data/spec/dummy/db/migrate/20110820131417_create_series_has_manifestations.rb +13 -0
  111. data/spec/dummy/db/migrate/20110916053430_rename_manifestation_number_list_to_number_string.rb +13 -0
  112. data/spec/dummy/db/migrate/20110916091020_add_volume_number_to_manifestation.rb +13 -0
  113. data/spec/dummy/db/migrate/20110916103953_add_manifestaiton_id_to_series_statement.rb +10 -0
  114. data/spec/dummy/db/migrate/20110918161853_rename_series_statement_manifestation_id_to_root_manifestation_id.rb +13 -0
  115. data/spec/dummy/db/migrate/20110918162329_add_note_to_series_statement.rb +9 -0
  116. data/spec/dummy/db/migrate/20111124110059_create_create_types.rb +12 -0
  117. data/spec/dummy/db/migrate/20111124110319_create_realize_types.rb +12 -0
  118. data/spec/dummy/db/migrate/20111124110355_create_produce_types.rb +12 -0
  119. data/spec/dummy/db/migrate/20111124112131_add_create_type_to_create.rb +7 -0
  120. data/spec/dummy/db/migrate/20111201121844_create_roles.rb +12 -0
  121. data/spec/dummy/db/migrate/20111201155456_create_users.rb +16 -0
  122. data/spec/dummy/db/migrate/20111201155513_add_devise_to_users.rb +44 -0
  123. data/spec/dummy/db/migrate/20111201163718_create_user_has_roles.rb +10 -0
  124. data/spec/dummy/db/migrate/20120125152919_add_title_subseries_transcription_to_series_statement.rb +6 -0
  125. data/spec/dummy/db/migrate/20120413072700_add_picture_meta_to_picture_file.rb +5 -0
  126. data/spec/dummy/db/migrate/20120413100352_add_fingerprint_to_picture_file.rb +5 -0
  127. data/spec/dummy/db/schema.rb +642 -0
  128. data/spec/dummy/db/test.sqlite3 +0 -0
  129. data/{test → spec}/dummy/public/404.html +0 -0
  130. data/{test → spec}/dummy/public/422.html +0 -0
  131. data/{test → spec}/dummy/public/500.html +0 -0
  132. data/{test → spec}/dummy/public/favicon.ico +0 -0
  133. data/{test → spec}/dummy/script/rails +0 -0
  134. data/spec/dummy/solr/conf/admin-extra.html +31 -0
  135. data/spec/dummy/solr/conf/elevate.xml +36 -0
  136. data/spec/dummy/solr/conf/mapping-ISOLatin1Accent.txt +246 -0
  137. data/spec/dummy/solr/conf/protwords.txt +21 -0
  138. data/spec/dummy/solr/conf/schema.xml +238 -0
  139. data/spec/dummy/solr/conf/scripts.conf +24 -0
  140. data/spec/dummy/solr/conf/solrconfig.xml +934 -0
  141. data/spec/dummy/solr/conf/spellings.txt +2 -0
  142. data/spec/dummy/solr/conf/stopwords.txt +58 -0
  143. data/spec/dummy/solr/conf/synonyms.txt +31 -0
  144. data/spec/dummy/solr/data/test/index/_k.fdt +0 -0
  145. data/spec/dummy/solr/data/test/index/_k.fdx +0 -0
  146. data/spec/dummy/solr/data/test/index/_k.fnm +3 -0
  147. data/spec/dummy/solr/data/test/index/_k.frq +1 -0
  148. data/spec/dummy/solr/data/test/index/_k.nrm +1 -0
  149. data/spec/dummy/solr/data/test/index/_k.prx +0 -0
  150. data/spec/dummy/solr/data/test/index/_k.tii +0 -0
  151. data/spec/dummy/solr/data/test/index/_k.tis +0 -0
  152. data/spec/dummy/solr/data/test/index/segments.gen +0 -0
  153. data/spec/dummy/solr/data/test/index/segments_18 +0 -0
  154. data/spec/dummy/solr/data/test/spellchecker/segments.gen +0 -0
  155. data/spec/dummy/solr/data/test/spellchecker/segments_1 +0 -0
  156. data/spec/dummy/tmp/cache/4AD/470/country_all +0 -0
  157. data/spec/factories/bookstore.rb +5 -0
  158. data/spec/factories/budget_types.rb +5 -0
  159. data/spec/factories/carrier_types.yml +51 -0
  160. data/spec/factories/library.rb +13 -0
  161. data/spec/factories/manifestation.rb +6 -0
  162. data/spec/factories/request_status_type.rb +5 -0
  163. data/spec/factories/request_type.rb +5 -0
  164. data/spec/factories/search_engine.rb +9 -0
  165. data/spec/factories/shelf.rb +6 -0
  166. data/spec/factories/subscribe.rb +8 -0
  167. data/spec/factories/subscription.rb +6 -0
  168. data/spec/factories/user.rb +37 -0
  169. data/spec/fixtures/bookstores.yml +107 -0
  170. data/spec/fixtures/budget_types.yml +29 -0
  171. data/spec/fixtures/carrier_types.yml +51 -0
  172. data/spec/fixtures/languages.yml +1901 -0
  173. data/spec/fixtures/libraries.yml +102 -0
  174. data/spec/fixtures/library_groups.yml +33 -0
  175. data/spec/fixtures/manifestations.yml +2022 -0
  176. data/spec/fixtures/request_status_types.yml +63 -0
  177. data/spec/fixtures/request_types.yml +55 -0
  178. data/spec/fixtures/roles.yml +21 -0
  179. data/spec/fixtures/search_engines.yml +41 -0
  180. data/spec/fixtures/shelves.yml +47 -0
  181. data/spec/fixtures/subscribes.yml +45 -0
  182. data/spec/fixtures/subscriptions.yml +27 -0
  183. data/spec/fixtures/user_groups.yml +31 -0
  184. data/spec/fixtures/user_has_roles.yml +41 -0
  185. data/spec/fixtures/users.yml +129 -0
  186. data/spec/models/bookstore_spec.rb +26 -0
  187. data/spec/models/budget_type_spec.rb +22 -0
  188. data/spec/models/library_group_spec.rb +33 -0
  189. data/spec/models/library_spec.rb +47 -0
  190. data/spec/models/request_status_type_spec.rb +21 -0
  191. data/spec/models/request_type_spec.rb +21 -0
  192. data/spec/models/search_engine_spec.rb +29 -0
  193. data/spec/models/shelf_spec.rb +29 -0
  194. data/spec/models/subscribe_spec.rb +21 -0
  195. data/spec/models/subscription_spec.rb +26 -0
  196. data/spec/routing/budget_types_routing_spec.rb +35 -0
  197. data/spec/routing/libraries_routing_spec.rb +35 -0
  198. data/spec/spec_helper.rb +55 -0
  199. data/spec/support/controller_macros.rb +46 -0
  200. data/spec/support/devise.rb +4 -0
  201. data/spec/support/vcr.rb +9 -0
  202. data/spec/views/budget_types/edit.html.erb_spec.rb +23 -0
  203. data/spec/views/budget_types/index.html.erb_spec.rb +28 -0
  204. data/spec/views/budget_types/new.html.erb_spec.rb +23 -0
  205. data/spec/views/budget_types/show.html.erb_spec.rb +24 -0
  206. metadata +372 -198
  207. data/lib/enju_library/master_model.rb +0 -19
  208. data/lib/enju_library/url_validator.rb +0 -10
  209. data/test/dummy/app/controllers/application_controller.rb +0 -3
  210. data/test/dummy/app/helpers/application_helper.rb +0 -2
  211. data/test/dummy/db/development.sqlite3 +0 -0
  212. data/test/dummy/db/test.sqlite3 +0 -0
  213. data/test/dummy/log/development.log +0 -0
  214. data/test/dummy/log/test.log +0 -0
  215. data/test/enju_library_test.rb +0 -7
  216. data/test/integration/navigation_test.rb +0 -10
  217. data/test/test_helper.rb +0 -15
@@ -0,0 +1,517 @@
1
+ require 'spec_helper'
2
+
3
+ describe LibrariesController do
4
+ fixtures :all
5
+
6
+ describe "GET index", :solr => true do
7
+ before do
8
+ Library.reindex
9
+ end
10
+
11
+ describe "When logged in as Administrator" do
12
+ login_admin
13
+
14
+ it "assigns all libraries as @libraries" do
15
+ get :index
16
+ assigns(:libraries).should_not be_empty
17
+ end
18
+ end
19
+
20
+ describe "When logged in as Librarian" do
21
+ login_librarian
22
+
23
+ it "assigns all libraries as @libraries" do
24
+ get :index
25
+ assigns(:libraries).should_not be_empty
26
+ end
27
+ end
28
+
29
+ describe "When logged in as User" do
30
+ login_user
31
+
32
+ it "assigns all libraries as @libraries" do
33
+ get :index
34
+ assigns(:libraries).should_not be_empty
35
+ end
36
+ end
37
+
38
+ describe "When not logged in" do
39
+ it "assigns all libraries as @libraries" do
40
+ get :index
41
+ assigns(:libraries).should_not be_empty
42
+ end
43
+
44
+ it "should get index with query" do
45
+ get :index, :query => 'kamata'
46
+ response.should be_success
47
+ assigns(:libraries).include?(Library.find('kamata')).should be_true
48
+ end
49
+ end
50
+ end
51
+
52
+ describe "GET show", :solr => true do
53
+ describe "When logged in as Administrator" do
54
+ login_admin
55
+
56
+ it "assigns the requested library as @library" do
57
+ get :show, :id => 1
58
+ assigns(:library).should eq(libraries(:library_00001))
59
+ end
60
+
61
+ it "assigns nil as @library if id is missing" do
62
+ get :show, :id => 'missing'
63
+ assigns(:library).should be_nil
64
+ response.should be_missing
65
+ end
66
+ end
67
+
68
+ describe "When logged in as Librarian" do
69
+ login_librarian
70
+
71
+ it "assigns the requested library as @library" do
72
+ get :show, :id => 1
73
+ assigns(:library).should eq(libraries(:library_00001))
74
+ end
75
+ end
76
+
77
+ describe "When logged in as User" do
78
+ login_user
79
+
80
+ it "assigns the requested library as @library" do
81
+ get :show, :id => 1
82
+ assigns(:library).should eq(libraries(:library_00001))
83
+ end
84
+ end
85
+
86
+ describe "When not logged in" do
87
+ it "assigns the requested library as @library" do
88
+ get :show, :id => 1
89
+ assigns(:library).should eq(libraries(:library_00001))
90
+ end
91
+ end
92
+ end
93
+
94
+ describe "GET new" do
95
+ describe "When logged in as Administrator" do
96
+ login_admin
97
+
98
+ it "assigns the requested library as @library" do
99
+ get :new
100
+ assigns(:library).should_not be_valid
101
+ end
102
+ end
103
+
104
+ describe "When logged in as Librarian" do
105
+ login_librarian
106
+
107
+ it "assigns the requested library as @library" do
108
+ get :new
109
+ assigns(:library).should_not be_valid
110
+ end
111
+ end
112
+
113
+ describe "When logged in as User" do
114
+ login_user
115
+
116
+ it "should not assign the requested library as @library" do
117
+ get :new
118
+ assigns(:library).should_not be_valid
119
+ response.should be_forbidden
120
+ end
121
+ end
122
+
123
+ describe "When not logged in" do
124
+ it "should not assign the requested library as @library" do
125
+ get :new
126
+ assigns(:library).should_not be_valid
127
+ response.should redirect_to(new_user_session_url)
128
+ end
129
+ end
130
+ end
131
+
132
+ describe "GET edit" do
133
+ describe "When logged in as Administrator" do
134
+ login_admin
135
+
136
+ it "assigns the requested library as @library" do
137
+ library = FactoryGirl.create(:library)
138
+ get :edit, :id => library.id
139
+ assigns(:library).should eq(library)
140
+ end
141
+ end
142
+
143
+ describe "When logged in as Librarian" do
144
+ login_librarian
145
+
146
+ it "assigns the requested library as @library" do
147
+ library = FactoryGirl.create(:library)
148
+ get :edit, :id => library.id
149
+ response.should be_forbidden
150
+ end
151
+ end
152
+
153
+ describe "When logged in as User" do
154
+ login_user
155
+
156
+ it "assigns the requested library as @library" do
157
+ library = FactoryGirl.create(:library)
158
+ get :edit, :id => library.id
159
+ response.should be_forbidden
160
+ end
161
+ end
162
+
163
+ describe "When not logged in" do
164
+ it "should not assign the requested library as @library" do
165
+ library = FactoryGirl.create(:library)
166
+ get :edit, :id => library.id
167
+ response.should redirect_to(new_user_session_url)
168
+ end
169
+ end
170
+ end
171
+
172
+ describe "POST create" do
173
+ before(:each) do
174
+ @attrs = FactoryGirl.attributes_for(:library)
175
+ @invalid_attrs = {:name => ''}
176
+ end
177
+
178
+ describe "When logged in as Administrator" do
179
+ login_admin
180
+
181
+ describe "with valid params" do
182
+ it "assigns a newly created library as @library" do
183
+ post :create, :library => @attrs
184
+ assigns(:library).should be_valid
185
+ end
186
+
187
+ it "redirects to the created patron" do
188
+ post :create, :library => @attrs
189
+ response.should redirect_to(assigns(:library))
190
+ end
191
+ end
192
+
193
+ describe "with invalid params" do
194
+ it "assigns a newly created but unsaved library as @library" do
195
+ post :create, :library => @invalid_attrs
196
+ assigns(:library).should_not be_valid
197
+ end
198
+
199
+ it "should be successful" do
200
+ post :create, :library => @invalid_attrs
201
+ response.should be_success
202
+ end
203
+
204
+ it "should not create library without short_display_name" do
205
+ post :create, :library => { :name => 'fujisawa', :short_display_name => '' }
206
+ response.should be_success
207
+ end
208
+ end
209
+ end
210
+
211
+ describe "When logged in as Librarian" do
212
+ login_librarian
213
+
214
+ describe "with valid params" do
215
+ it "assigns a newly created library as @library" do
216
+ post :create, :library => @attrs
217
+ assigns(:library).should be_valid
218
+ end
219
+
220
+ it "should be forbidden" do
221
+ post :create, :library => @attrs
222
+ response.should be_forbidden
223
+ end
224
+ end
225
+
226
+ describe "with invalid params" do
227
+ it "assigns a newly created but unsaved library as @library" do
228
+ post :create, :library => @invalid_attrs
229
+ assigns(:library).should_not be_valid
230
+ end
231
+
232
+ it "should be forbidden" do
233
+ post :create, :library => @invalid_attrs
234
+ response.should be_forbidden
235
+ end
236
+ end
237
+ end
238
+
239
+ describe "When logged in as User" do
240
+ login_user
241
+
242
+ describe "with valid params" do
243
+ it "assigns a newly created library as @library" do
244
+ post :create, :library => @attrs
245
+ assigns(:library).should be_valid
246
+ end
247
+
248
+ it "should be forbidden" do
249
+ post :create, :library => @attrs
250
+ response.should be_forbidden
251
+ end
252
+ end
253
+
254
+ describe "with invalid params" do
255
+ it "assigns a newly created but unsaved library as @library" do
256
+ post :create, :library => @invalid_attrs
257
+ assigns(:library).should_not be_valid
258
+ end
259
+
260
+ it "should be forbidden" do
261
+ post :create, :library => @invalid_attrs
262
+ response.should be_forbidden
263
+ end
264
+ end
265
+ end
266
+
267
+ describe "When not logged in" do
268
+ describe "with valid params" do
269
+ it "assigns a newly created library as @library" do
270
+ post :create, :library => @attrs
271
+ assigns(:library).should be_valid
272
+ end
273
+
274
+ it "should be redirected to new session url" do
275
+ post :create, :library => @attrs
276
+ response.should redirect_to(new_user_session_url)
277
+ end
278
+ end
279
+
280
+ describe "with invalid params" do
281
+ it "assigns a newly created but unsaved library as @library" do
282
+ post :create, :library => @invalid_attrs
283
+ assigns(:library).should_not be_valid
284
+ end
285
+
286
+ it "should be redirected to new session url" do
287
+ post :create, :library => @invalid_attrs
288
+ response.should redirect_to(new_user_session_url)
289
+ end
290
+ end
291
+ end
292
+ end
293
+
294
+ describe "PUT update" do
295
+ before(:each) do
296
+ @library = libraries(:library_00001)
297
+ @attrs = {:name => 'example'}
298
+ @invalid_attrs = {:name => ''}
299
+ end
300
+
301
+ describe "When logged in as Administrator" do
302
+ login_admin
303
+
304
+ describe "with valid params" do
305
+ it "updates the requested library" do
306
+ put :update, :id => @library.id, :library => @attrs
307
+ end
308
+
309
+ it "assigns the requested library as @library" do
310
+ put :update, :id => @library.id, :library => @attrs
311
+ assigns(:library).should eq(@library)
312
+ end
313
+
314
+ it "moves its position when specified" do
315
+ put :update, :id => @library.id, :library => @attrs, :move => 'lower'
316
+ response.should redirect_to(libraries_url)
317
+ end
318
+ end
319
+
320
+ describe "with invalid params" do
321
+ it "assigns the requested library as @library" do
322
+ put :update, :id => @library.id, :library => @invalid_attrs
323
+ response.should render_template("edit")
324
+ end
325
+ end
326
+ end
327
+
328
+ describe "When logged in as Librarian" do
329
+ login_librarian
330
+
331
+ describe "with valid params" do
332
+ it "updates the requested library" do
333
+ put :update, :id => @library.id, :library => @attrs
334
+ end
335
+
336
+ it "should be forbidden" do
337
+ put :update, :id => @library.id, :library => @attrs
338
+ response.should be_forbidden
339
+ end
340
+ end
341
+
342
+ describe "with invalid params" do
343
+ it "should be forbidden" do
344
+ put :update, :id => @library.id, :library => @invalid_attrs
345
+ response.should be_forbidden
346
+ end
347
+ end
348
+ end
349
+
350
+ describe "When logged in as User" do
351
+ login_user
352
+
353
+ describe "with valid params" do
354
+ it "updates the requested library" do
355
+ put :update, :id => @library.id, :library => @attrs
356
+ end
357
+
358
+ it "should be forbidden" do
359
+ put :update, :id => @library.id, :library => @attrs
360
+ response.should be_forbidden
361
+ end
362
+ end
363
+
364
+ describe "with invalid params" do
365
+ it "should be forbidden" do
366
+ put :update, :id => @library.id, :library => @invalid_attrs
367
+ response.should be_forbidden
368
+ end
369
+ end
370
+ end
371
+
372
+ describe "When not logged in" do
373
+ describe "with valid params" do
374
+ it "updates the requested library" do
375
+ put :update, :id => @library.id, :library => @attrs
376
+ end
377
+
378
+ it "should be forbidden" do
379
+ put :update, :id => @library.id, :library => @attrs
380
+ response.should redirect_to(new_user_session_url)
381
+ end
382
+ end
383
+
384
+ describe "with invalid params" do
385
+ it "assigns the requested library as @library" do
386
+ put :update, :id => @library.id, :library => @invalid_attrs
387
+ response.should redirect_to(new_user_session_url)
388
+ end
389
+ end
390
+ end
391
+ end
392
+
393
+ describe "DELETE destroy" do
394
+ describe "Web" do
395
+ before(:each) do
396
+ @library = libraries(:library_00001)
397
+ end
398
+
399
+ describe "When logged in as Administrator" do
400
+ login_admin
401
+
402
+ it "destroys the requested library" do
403
+ delete :destroy, :id => @library.id
404
+ end
405
+
406
+ it "should be forbidden" do
407
+ delete :destroy, :id => @library.id
408
+ response.should be_forbidden
409
+ end
410
+
411
+ it "should not destroy library_id 1" do
412
+ delete :destroy, :id => 'web'
413
+ response.should be_forbidden
414
+ end
415
+
416
+ it "should not destroy library that contains shelves" do
417
+ delete :destroy, :id => 'kamata'
418
+ response.should be_forbidden
419
+ end
420
+ end
421
+
422
+ describe "When logged in as Librarian" do
423
+ login_librarian
424
+
425
+ it "destroys the requested library" do
426
+ delete :destroy, :id => @library.id
427
+ end
428
+
429
+ it "should be forbidden" do
430
+ delete :destroy, :id => @library.id
431
+ response.should be_forbidden
432
+ end
433
+ end
434
+
435
+ describe "When logged in as User" do
436
+ login_user
437
+
438
+ it "destroys the requested library" do
439
+ delete :destroy, :id => @library.id
440
+ end
441
+
442
+ it "should be forbidden" do
443
+ delete :destroy, :id => @library.id
444
+ response.should be_forbidden
445
+ end
446
+ end
447
+
448
+ describe "When not logged in" do
449
+ it "destroys the requested library" do
450
+ delete :destroy, :id => @library.id
451
+ end
452
+
453
+ it "should be forbidden" do
454
+ delete :destroy, :id => @library.id
455
+ response.should redirect_to(new_user_session_url)
456
+ end
457
+ end
458
+ end
459
+
460
+ describe "Library" do
461
+ before(:each) do
462
+ @library = FactoryGirl.create(:library)
463
+ @library.shelves.first.destroy
464
+ end
465
+
466
+ describe "When logged in as Administrator" do
467
+ login_admin
468
+
469
+ it "destroys the requested library" do
470
+ delete :destroy, :id => @library.id
471
+ end
472
+
473
+ it "redirects to the libraries list" do
474
+ delete :destroy, :id => @library.id
475
+ response.should redirect_to(libraries_url)
476
+ end
477
+ end
478
+
479
+ describe "When logged in as Librarian" do
480
+ login_librarian
481
+
482
+ it "destroys the requested library" do
483
+ delete :destroy, :id => @library.id
484
+ end
485
+
486
+ it "should be forbidden" do
487
+ delete :destroy, :id => @library.id
488
+ response.should be_forbidden
489
+ end
490
+ end
491
+
492
+ describe "When logged in as User" do
493
+ login_user
494
+
495
+ it "destroys the requested library" do
496
+ delete :destroy, :id => @library.id
497
+ end
498
+
499
+ it "should be forbidden" do
500
+ delete :destroy, :id => @library.id
501
+ response.should be_forbidden
502
+ end
503
+ end
504
+
505
+ describe "When not logged in" do
506
+ it "destroys the requested library" do
507
+ delete :destroy, :id => @library.id
508
+ end
509
+
510
+ it "should be forbidden" do
511
+ delete :destroy, :id => @library.id
512
+ response.should redirect_to(new_user_session_url)
513
+ end
514
+ end
515
+ end
516
+ end
517
+ end
@@ -0,0 +1,133 @@
1
+ require 'spec_helper'
2
+
3
+ describe LibraryGroupsController do
4
+ fixtures :all
5
+
6
+ describe "GET index" do
7
+ describe "When logged in as Administrator" do
8
+ login_admin
9
+
10
+ it "assigns all library_groups as @library_groups" do
11
+ get :index
12
+ assigns(:library_groups).should_not be_empty
13
+ end
14
+ end
15
+
16
+ describe "When not logged in" do
17
+ it "assigns all library_groups as @library_groups" do
18
+ get :index
19
+ assigns(:library_groups).should_not be_empty
20
+ response.should be_success
21
+ end
22
+ end
23
+ end
24
+
25
+ describe "GET show" do
26
+ describe "When logged in as Administrator" do
27
+ login_admin
28
+
29
+ it "assigns the requested library_group as @library_group" do
30
+ get :show, :id => 1
31
+ assigns(:library_group).should eq(LibraryGroup.find(1))
32
+ end
33
+ end
34
+
35
+ describe "When not logged in" do
36
+ it "assigns the requested library_group as @library_group" do
37
+ get :show, :id => 1
38
+ assigns(:library_group).should eq(LibraryGroup.find(1))
39
+ response.should be_success
40
+ end
41
+ end
42
+ end
43
+
44
+ describe "GET edit" do
45
+ describe "When logged in as Administrator" do
46
+ login_admin
47
+
48
+ it "assigns the requested library_group as @library_group" do
49
+ library_group = LibraryGroup.find(1)
50
+ get :edit, :id => library_group.id
51
+ assigns(:library_group).should eq(library_group)
52
+ end
53
+ end
54
+
55
+ describe "When logged in as Librarian" do
56
+ login_librarian
57
+
58
+ it "should not assign the requested library_group as @library_group" do
59
+ library_group = LibraryGroup.find(1)
60
+ get :edit, :id => library_group.id
61
+ response.should be_forbidden
62
+ end
63
+ end
64
+
65
+ describe "When logged in as User" do
66
+ login_user
67
+
68
+ it "should not assign the requested library_group as @library_group" do
69
+ library_group = LibraryGroup.find(1)
70
+ get :edit, :id => library_group.id
71
+ response.should be_forbidden
72
+ end
73
+ end
74
+
75
+ describe "When not logged in" do
76
+ it "should not assign the requested library_group as @library_group" do
77
+ library_group = LibraryGroup.find(1)
78
+ get :edit, :id => library_group.id
79
+ response.should redirect_to(new_user_session_url)
80
+ end
81
+ end
82
+ end
83
+
84
+ describe "PUT update" do
85
+ before(:each) do
86
+ @library_group = LibraryGroup.find(1)
87
+ @attrs = {:name => 'example', :email => 'library@example.jp'}
88
+ @invalid_attrs = {:name => ''}
89
+ end
90
+
91
+ describe "When logged in as Administrator" do
92
+ login_admin
93
+
94
+ describe "with valid params" do
95
+ it "updates the requested library_group" do
96
+ put :update, :id => @library_group.id, :library_group => @attrs
97
+ end
98
+
99
+ it "assigns the requested library_group as @library_group" do
100
+ put :update, :id => @library_group.id, :library_group => @attrs
101
+ assigns(:library_group).should eq(@library_group)
102
+ end
103
+ end
104
+
105
+ describe "with invalid params" do
106
+ it "assigns the requested library_group as @library_group" do
107
+ put :update, :id => @library_group.id, :library_group => @invalid_attrs
108
+ response.should render_template("edit")
109
+ end
110
+ end
111
+ end
112
+
113
+ describe "When not logged in" do
114
+ describe "with valid params" do
115
+ it "updates the requested library_group" do
116
+ put :update, :id => @library_group.id, :library_group => @attrs
117
+ end
118
+
119
+ it "should be forbidden" do
120
+ put :update, :id => @library_group.id, :library_group => @attrs
121
+ response.should redirect_to(new_user_session_url)
122
+ end
123
+ end
124
+
125
+ describe "with invalid params" do
126
+ it "assigns the requested library_group as @library_group" do
127
+ put :update, :id => @library_group.id, :library_group => @invalid_attrs
128
+ response.should redirect_to(new_user_session_url)
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end