enju_message 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (231) hide show
  1. data/config/locales/translation_en.yml +51 -0
  2. data/config/locales/translation_ja.yml +51 -0
  3. data/lib/enju_message/version.rb +1 -1
  4. data/spec/controllers/message_requests_controller_spec.rb +275 -0
  5. data/spec/controllers/message_templates_controller_spec.rb +443 -0
  6. data/spec/controllers/messages_controller_spec.rb +439 -0
  7. data/{test → spec}/dummy/Rakefile +0 -0
  8. data/{test → spec}/dummy/app/assets/javascripts/application.js +0 -0
  9. data/{test → spec}/dummy/app/assets/stylesheets/application.css +0 -0
  10. data/spec/dummy/app/controllers/application_controller.rb +45 -0
  11. data/{test → spec}/dummy/app/helpers/application_helper.rb +0 -0
  12. data/spec/dummy/app/mailers/notifier.rb +28 -0
  13. data/spec/dummy/app/models/ability.rb +30 -0
  14. data/spec/dummy/app/models/library_group.rb +86 -0
  15. data/spec/dummy/app/models/patron.rb +167 -0
  16. data/spec/dummy/app/models/patron_type.rb +19 -0
  17. data/spec/dummy/app/models/role.rb +8 -0
  18. data/spec/dummy/app/models/user.rb +53 -0
  19. data/spec/dummy/app/models/user_group.rb +2 -0
  20. data/spec/dummy/app/models/user_has_role.rb +4 -0
  21. data/{test → spec}/dummy/app/views/layouts/application.html.erb +0 -0
  22. data/spec/dummy/app/views/page/403.html.erb +9 -0
  23. data/spec/dummy/app/views/page/403.mobile.erb +5 -0
  24. data/spec/dummy/app/views/page/403.xml.erb +4 -0
  25. data/spec/dummy/app/views/page/404.html.erb +9 -0
  26. data/spec/dummy/app/views/page/404.mobile.erb +5 -0
  27. data/spec/dummy/app/views/page/404.xml.erb +4 -0
  28. data/{test → spec}/dummy/config/application.rb +1 -0
  29. data/{test → spec}/dummy/config/boot.rb +0 -0
  30. data/{test → spec}/dummy/config/database.yml +0 -0
  31. data/{test → spec}/dummy/config/environment.rb +0 -0
  32. data/{test → spec}/dummy/config/environments/development.rb +0 -0
  33. data/{test → spec}/dummy/config/environments/production.rb +0 -0
  34. data/{test → spec}/dummy/config/environments/test.rb +0 -0
  35. data/{test → spec}/dummy/config/initializers/backtrace_silencers.rb +0 -0
  36. data/spec/dummy/config/initializers/devise.rb +209 -0
  37. data/{test → spec}/dummy/config/initializers/inflections.rb +0 -0
  38. data/{test → spec}/dummy/config/initializers/mime_types.rb +1 -0
  39. data/{test → spec}/dummy/config/initializers/secret_token.rb +0 -0
  40. data/{test → spec}/dummy/config/initializers/session_store.rb +0 -0
  41. data/{test → spec}/dummy/config/initializers/wrap_parameters.rb +0 -0
  42. data/{test → spec}/dummy/config/locales/en.yml +0 -0
  43. data/{test → spec}/dummy/config/routes.rb +2 -0
  44. data/{test → spec}/dummy/config.ru +0 -0
  45. data/{test/dummy/public/favicon.ico → spec/dummy/db/development.sqlite3} +0 -0
  46. data/spec/dummy/db/migrate/001_create_patrons.rb +62 -0
  47. data/spec/dummy/db/migrate/080_create_library_groups.rb +25 -0
  48. data/spec/dummy/db/migrate/20080905191442_create_patron_types.rb +16 -0
  49. data/spec/dummy/db/migrate/20100211105551_add_admin_networks_to_library_group.rb +9 -0
  50. data/spec/dummy/db/migrate/20100222124420_add_allow_bookmark_external_url_to_library_group.rb +9 -0
  51. data/spec/dummy/db/migrate/20100527113752_create_delayed_jobs.rb +21 -0
  52. data/spec/dummy/db/migrate/20110115022329_add_position_to_library_group.rb +9 -0
  53. data/spec/dummy/db/migrate/20110222073537_add_url_to_library_group.rb +9 -0
  54. data/spec/dummy/db/migrate/20111020063828_remove_dsbl_from_library_group.rb +11 -0
  55. data/spec/dummy/db/migrate/20111201121636_create_languages.rb +16 -0
  56. data/spec/dummy/db/migrate/20111201121844_create_roles.rb +12 -0
  57. data/spec/dummy/db/migrate/20111201155456_create_users.rb +14 -0
  58. data/spec/dummy/db/migrate/20111201155513_add_devise_to_users.rb +31 -0
  59. data/spec/dummy/db/migrate/20111201163342_create_user_groups.rb +12 -0
  60. data/spec/dummy/db/migrate/20111201163718_create_user_has_roles.rb +10 -0
  61. data/spec/dummy/db/schema.rb +225 -0
  62. data/spec/dummy/db/test.sqlite3 +0 -0
  63. data/spec/dummy/lib/enju_leaf/localized_name.rb +13 -0
  64. data/spec/dummy/lib/enju_leaf/master_model.rb +41 -0
  65. data/spec/dummy/lib/enju_leaf/url_validator.rb +10 -0
  66. data/spec/dummy/lib/enju_leaf.rb +4 -0
  67. data/spec/dummy/log/development.log +106 -0
  68. data/spec/dummy/log/sunspot-solr-test.log +232 -0
  69. data/spec/dummy/log/test.log +145040 -0
  70. data/{test → spec}/dummy/public/404.html +0 -0
  71. data/{test → spec}/dummy/public/422.html +0 -0
  72. data/{test → spec}/dummy/public/500.html +0 -0
  73. data/spec/dummy/public/favicon.ico +0 -0
  74. data/{test → spec}/dummy/script/rails +0 -0
  75. data/spec/dummy/solr/conf/admin-extra.html +31 -0
  76. data/spec/dummy/solr/conf/elevate.xml +36 -0
  77. data/spec/dummy/solr/conf/mapping-ISOLatin1Accent.txt +246 -0
  78. data/spec/dummy/solr/conf/protwords.txt +21 -0
  79. data/spec/dummy/solr/conf/schema.xml +238 -0
  80. data/spec/dummy/solr/conf/scripts.conf +24 -0
  81. data/spec/dummy/solr/conf/solrconfig.xml +934 -0
  82. data/spec/dummy/solr/conf/spellings.txt +2 -0
  83. data/spec/dummy/solr/conf/stopwords.txt +58 -0
  84. data/spec/dummy/solr/conf/synonyms.txt +31 -0
  85. data/spec/dummy/solr/data/test/index/segments.gen +0 -0
  86. data/spec/dummy/solr/data/test/index/segments_1 +0 -0
  87. data/spec/dummy/solr/data/test/spellchecker/segments.gen +0 -0
  88. data/spec/dummy/solr/data/test/spellchecker/segments_1 +0 -0
  89. data/spec/factories/message.rb +8 -0
  90. data/spec/factories/message_request.rb +7 -0
  91. data/spec/factories/message_template.rb +7 -0
  92. data/spec/factories/user.rb +34 -0
  93. data/spec/fixtures/library_groups.yml +34 -0
  94. data/spec/fixtures/message_requests.yml +30 -0
  95. data/spec/fixtures/message_templates.yml +65 -0
  96. data/spec/fixtures/messages.yml +62 -0
  97. data/spec/fixtures/patrons.yml +338 -0
  98. data/spec/fixtures/roles.yml +21 -0
  99. data/spec/fixtures/user_groups.yml +25 -0
  100. data/spec/fixtures/user_has_roles.yml +41 -0
  101. data/spec/fixtures/users.yml +69 -0
  102. data/spec/models/message_request_spec.rb +24 -0
  103. data/spec/models/message_spec.rb +59 -0
  104. data/spec/models/message_template_spec.rb +24 -0
  105. data/spec/spec_helper.rb +46 -0
  106. data/spec/support/controller_macros.rb +48 -0
  107. data/spec/support/devise.rb +4 -0
  108. metadata +273 -220
  109. data/app/views/baskets/edit.html.erb +0 -30
  110. data/app/views/baskets/index.html.erb +0 -31
  111. data/app/views/baskets/new.html.erb +0 -29
  112. data/app/views/baskets/show.html.erb +0 -23
  113. data/app/views/carrier_type_has_checkout_types/_form.html.erb +0 -19
  114. data/app/views/carrier_type_has_checkout_types/edit.html.erb +0 -13
  115. data/app/views/carrier_type_has_checkout_types/index.html.erb +0 -33
  116. data/app/views/carrier_type_has_checkout_types/new.html.erb +0 -12
  117. data/app/views/carrier_type_has_checkout_types/show.html.erb +0 -29
  118. data/app/views/checked_items/_checkouts.html.erb +0 -20
  119. data/app/views/checked_items/_list.html.erb +0 -39
  120. data/app/views/checked_items/edit.html.erb +0 -21
  121. data/app/views/checked_items/index.html.erb +0 -32
  122. data/app/views/checked_items/index.js.erb +0 -1
  123. data/app/views/checked_items/new.html.erb +0 -20
  124. data/app/views/checked_items/show.html.erb +0 -24
  125. data/app/views/checkins/_form.html.erb +0 -24
  126. data/app/views/checkins/_list.html.erb +0 -51
  127. data/app/views/checkins/edit.html.erb +0 -26
  128. data/app/views/checkins/index.html.erb +0 -16
  129. data/app/views/checkins/index.js.erb +0 -1
  130. data/app/views/checkins/new.html.erb +0 -14
  131. data/app/views/checkins/show.html.erb +0 -24
  132. data/app/views/checkout_stat_has_manifestations/_form.html.erb +0 -15
  133. data/app/views/checkout_stat_has_manifestations/edit.html.erb +0 -13
  134. data/app/views/checkout_stat_has_manifestations/index.html.erb +0 -33
  135. data/app/views/checkout_stat_has_manifestations/new.html.erb +0 -12
  136. data/app/views/checkout_stat_has_manifestations/show.html.erb +0 -28
  137. data/app/views/checkout_stat_has_users/_form.html.erb +0 -15
  138. data/app/views/checkout_stat_has_users/edit.html.erb +0 -13
  139. data/app/views/checkout_stat_has_users/index.html.erb +0 -33
  140. data/app/views/checkout_stat_has_users/new.html.erb +0 -12
  141. data/app/views/checkout_stat_has_users/show.html.erb +0 -28
  142. data/app/views/checkout_types/_form.html.erb +0 -19
  143. data/app/views/checkout_types/edit.html.erb +0 -13
  144. data/app/views/checkout_types/index.html.erb +0 -50
  145. data/app/views/checkout_types/new.html.erb +0 -12
  146. data/app/views/checkout_types/show.html.erb +0 -38
  147. data/app/views/checkouts/_form.html.erb +0 -28
  148. data/app/views/checkouts/_index.html.erb +0 -23
  149. data/app/views/checkouts/_index_overdue.html.erb +0 -33
  150. data/app/views/checkouts/_index_user.html.erb +0 -44
  151. data/app/views/checkouts/_list.html.erb +0 -45
  152. data/app/views/checkouts/edit.html.erb +0 -51
  153. data/app/views/checkouts/index.atom.builder +0 -14
  154. data/app/views/checkouts/index.csv.erb +0 -4
  155. data/app/views/checkouts/index.html.erb +0 -11
  156. data/app/views/checkouts/index.ics.erb +0 -13
  157. data/app/views/checkouts/index.rss.builder +0 -38
  158. data/app/views/checkouts/new.html.erb +0 -20
  159. data/app/views/checkouts/show.html.erb +0 -35
  160. data/app/views/circulation_statuses/_form.html.erb +0 -19
  161. data/app/views/circulation_statuses/edit.html.erb +0 -13
  162. data/app/views/circulation_statuses/index.html.erb +0 -43
  163. data/app/views/circulation_statuses/new.html.erb +0 -12
  164. data/app/views/circulation_statuses/show.html.erb +0 -29
  165. data/app/views/item_has_use_restrictions/edit.html.erb +0 -27
  166. data/app/views/item_has_use_restrictions/index.html.erb +0 -32
  167. data/app/views/item_has_use_restrictions/new.html.erb +0 -25
  168. data/app/views/item_has_use_restrictions/show.html.erb +0 -29
  169. data/app/views/lending_policies/_form.html.erb +0 -41
  170. data/app/views/lending_policies/edit.html.erb +0 -13
  171. data/app/views/lending_policies/index.html.erb +0 -42
  172. data/app/views/lending_policies/new.html.erb +0 -12
  173. data/app/views/lending_policies/show.html.erb +0 -50
  174. data/app/views/manifestation_checkout_stats/_form.html.erb +0 -19
  175. data/app/views/manifestation_checkout_stats/edit.html.erb +0 -13
  176. data/app/views/manifestation_checkout_stats/index.html.erb +0 -35
  177. data/app/views/manifestation_checkout_stats/new.html.erb +0 -12
  178. data/app/views/manifestation_checkout_stats/show.csv.erb +0 -4
  179. data/app/views/manifestation_checkout_stats/show.html.erb +0 -55
  180. data/app/views/manifestation_reserve_stats/_form.html.erb +0 -19
  181. data/app/views/manifestation_reserve_stats/edit.html.erb +0 -13
  182. data/app/views/manifestation_reserve_stats/index.html.erb +0 -35
  183. data/app/views/manifestation_reserve_stats/new.html.erb +0 -12
  184. data/app/views/manifestation_reserve_stats/show.csv.erb +0 -4
  185. data/app/views/manifestation_reserve_stats/show.html.erb +0 -55
  186. data/app/views/reserve_stat_has_manifestations/_form.html.erb +0 -15
  187. data/app/views/reserve_stat_has_manifestations/edit.html.erb +0 -13
  188. data/app/views/reserve_stat_has_manifestations/index.html.erb +0 -33
  189. data/app/views/reserve_stat_has_manifestations/new.html.erb +0 -12
  190. data/app/views/reserve_stat_has_manifestations/show.html.erb +0 -28
  191. data/app/views/reserve_stat_has_users/_form.html.erb +0 -15
  192. data/app/views/reserve_stat_has_users/edit.html.erb +0 -13
  193. data/app/views/reserve_stat_has_users/index.html.erb +0 -33
  194. data/app/views/reserve_stat_has_users/new.html.erb +0 -12
  195. data/app/views/reserve_stat_has_users/show.html.erb +0 -28
  196. data/app/views/reserves/_form.html.erb +0 -49
  197. data/app/views/reserves/_new.html.erb +0 -44
  198. data/app/views/reserves/_new_user.html.erb +0 -50
  199. data/app/views/reserves/_title.html.erb +0 -19
  200. data/app/views/reserves/edit.html.erb +0 -42
  201. data/app/views/reserves/index.atom.builder +0 -14
  202. data/app/views/reserves/index.csv.erb +0 -4
  203. data/app/views/reserves/index.html.erb +0 -75
  204. data/app/views/reserves/index.rss.builder +0 -41
  205. data/app/views/reserves/new.html.erb +0 -5
  206. data/app/views/reserves/show.html.erb +0 -61
  207. data/app/views/use_restrictions/_form.html.erb +0 -19
  208. data/app/views/use_restrictions/edit.html.erb +0 -13
  209. data/app/views/use_restrictions/index.html.erb +0 -43
  210. data/app/views/use_restrictions/new.html.erb +0 -12
  211. data/app/views/use_restrictions/show.html.erb +0 -29
  212. data/app/views/user_checkout_stats/_form.html.erb +0 -19
  213. data/app/views/user_checkout_stats/edit.html.erb +0 -13
  214. data/app/views/user_checkout_stats/index.html.erb +0 -35
  215. data/app/views/user_checkout_stats/new.html.erb +0 -12
  216. data/app/views/user_checkout_stats/show.csv.erb +0 -4
  217. data/app/views/user_checkout_stats/show.html.erb +0 -55
  218. data/app/views/user_group_has_checkout_types/edit.html.erb +0 -63
  219. data/app/views/user_group_has_checkout_types/index.html.erb +0 -32
  220. data/app/views/user_group_has_checkout_types/new.html.erb +0 -62
  221. data/app/views/user_group_has_checkout_types/show.html.erb +0 -64
  222. data/app/views/user_reserve_stats/_form.html.erb +0 -19
  223. data/app/views/user_reserve_stats/edit.html.erb +0 -13
  224. data/app/views/user_reserve_stats/index.html.erb +0 -35
  225. data/app/views/user_reserve_stats/new.html.erb +0 -12
  226. data/app/views/user_reserve_stats/show.csv.erb +0 -4
  227. data/app/views/user_reserve_stats/show.html.erb +0 -54
  228. data/test/dummy/app/controllers/application_controller.rb +0 -3
  229. data/test/enju_message_test.rb +0 -7
  230. data/test/integration/navigation_test.rb +0 -10
  231. data/test/test_helper.rb +0 -10
@@ -0,0 +1,439 @@
1
+ require 'spec_helper'
2
+
3
+ describe MessagesController do
4
+ fixtures :all
5
+
6
+ describe "GET index", :solr => true do
7
+ describe "When logged in as Administrator" do
8
+ before(:each) do
9
+ @user = FactoryGirl.create(:admin)
10
+ sign_in @user
11
+ end
12
+
13
+ it "should get its own messages" do
14
+ get :index
15
+ assigns(:messages).should_not be_nil
16
+ response.should be_success
17
+ end
18
+
19
+ describe "When user_id is specified" do
20
+ it "assigns all messages as @messages" do
21
+ get :index, :user_id => @user.username
22
+ assigns(:messages).should_not be_nil
23
+ end
24
+ end
25
+ end
26
+
27
+ describe "When logged in as Librarian" do
28
+ before(:each) do
29
+ @user = FactoryGirl.create(:librarian)
30
+ sign_in @user
31
+ end
32
+
33
+ it "should get its own messages" do
34
+ get :index
35
+ assigns(:messages).should_not be_nil
36
+ response.should be_success
37
+ end
38
+
39
+ describe "When user_id is specified" do
40
+ it "assigns all messages as @messages" do
41
+ get :index, :user_id => @user.username
42
+ assigns(:messages).should_not be_nil
43
+ end
44
+ end
45
+ end
46
+
47
+ describe "When logged in as User" do
48
+ login_fixture_user
49
+
50
+ describe "When user_id is specified" do
51
+ it "assigns all messages as @messages" do
52
+ get :index
53
+ assigns(:messages).should_not be_nil
54
+ end
55
+ end
56
+
57
+ it "should get its own messages" do
58
+ get :index
59
+ assigns(:messages).should_not be_nil
60
+ response.should be_success
61
+ end
62
+
63
+ it "should get index with query" do
64
+ get :index, :query => 'you'
65
+ assigns(:messages).first.receiver.should eq users(:user1)
66
+ response.should be_success
67
+ end
68
+ end
69
+
70
+ describe "When not logged in" do
71
+ it "assigns all messages as @messages" do
72
+ get :index
73
+ assigns(:messages).should be_nil
74
+ response.should redirect_to(new_user_session_url)
75
+ end
76
+ end
77
+ end
78
+
79
+ describe "GET show" do
80
+ describe "When logged in as Administrator" do
81
+ login_fixture_admin
82
+
83
+ it "assigns the requested message as @message" do
84
+ message = messages(:user1_to_user2_1)
85
+ get :show, :id => message.id
86
+ assigns(:message).should eq(message)
87
+ response.should be_missing
88
+ end
89
+ end
90
+
91
+ describe "When logged in as Librarian" do
92
+ login_fixture_librarian
93
+
94
+ it "assigns the requested message as @message" do
95
+ message = messages(:user1_to_user2_1)
96
+ get :show, :id => message.id
97
+ assigns(:message).should eq(message)
98
+ response.should be_forbidden
99
+ end
100
+ end
101
+
102
+ describe "When logged in as Librarian" do
103
+ login_fixture_user
104
+
105
+ it "should show my message" do
106
+ get :show, :id => messages(:user2_to_user1_1).id
107
+ response.should be_success
108
+ end
109
+
110
+ it "should should not show other user's message" do
111
+ get :show, :id => messages(:user1_to_user2_1).id
112
+ response.should be_forbidden
113
+ end
114
+ end
115
+
116
+ describe "When not logged in" do
117
+ it "assigns the requested message as @message" do
118
+ get :show, :id => messages(:user1_to_user2_1).id
119
+ response.should redirect_to new_user_session_url
120
+ end
121
+ end
122
+ end
123
+
124
+ describe "GET new" do
125
+ describe "When logged in as Administrator" do
126
+ login_admin
127
+
128
+ it "assigns the requested message as @message" do
129
+ get :new
130
+ assigns(:message).should_not be_valid
131
+ end
132
+ end
133
+
134
+ describe "When logged in as Librarian" do
135
+ login_librarian
136
+
137
+ it "should not assign the requested message as @message" do
138
+ get :new
139
+ assigns(:message).should_not be_valid
140
+ response.should be_success
141
+ end
142
+ end
143
+
144
+ describe "When logged in as User" do
145
+ login_fixture_user
146
+
147
+ it "should not assign the requested message as @message" do
148
+ get :new
149
+ assigns(:message).should_not be_valid
150
+ response.should be_forbidden
151
+ end
152
+
153
+ it "should not get new template without parent_id" do
154
+ get :new
155
+ response.should be_forbidden
156
+ end
157
+
158
+ it "should not get new template with invalid parent_id" do
159
+ get :new, :parent_id => 1
160
+ response.should be_forbidden
161
+ end
162
+
163
+ it "should not get new template with valid parent_id" do
164
+ get :new, :parent_id => 2
165
+ response.should be_forbidden
166
+ end
167
+ end
168
+
169
+ describe "When not logged in" do
170
+ it "should not assign the requested message as @message" do
171
+ get :new
172
+ assigns(:message).should_not be_valid
173
+ response.should redirect_to(new_user_session_url)
174
+ end
175
+ end
176
+ end
177
+
178
+ describe "GET edit" do
179
+ describe "When logged in as Administrator" do
180
+ login_admin
181
+
182
+ it "assigns the requested message as @message" do
183
+ message = messages(:user1_to_user2_1)
184
+ get :edit, :id => message.id
185
+ assigns(:message).should eq(message)
186
+ response.should be_missing
187
+ end
188
+ end
189
+
190
+ describe "When logged in as Librarian" do
191
+ login_librarian
192
+
193
+ it "assigns the requested message as @message" do
194
+ message = messages(:user1_to_user2_1)
195
+ get :edit, :id => message.id
196
+ assigns(:message).should eq(message)
197
+ response.should be_forbidden
198
+ end
199
+ end
200
+
201
+ describe "When logged in as User" do
202
+ login_fixture_user
203
+
204
+ it "assigns the requested message as @message" do
205
+ message = messages(:user1_to_user2_1)
206
+ get :edit, :id => message.id
207
+ assigns(:message).should eq(message)
208
+ response.should be_forbidden
209
+ end
210
+ end
211
+
212
+ describe "When not logged in" do
213
+ it "assigns the requested message as @message" do
214
+ message = FactoryGirl.create(:message)
215
+ get :edit, :id => message.id
216
+ assigns(:message).should eq(message)
217
+ response.should redirect_to new_user_session_url
218
+ end
219
+ end
220
+ end
221
+
222
+ describe "POST create" do
223
+ before(:each) do
224
+ @attrs = {:recipient => users(:user1).username, :subject => 'test',:body => 'test'}
225
+ @invalid_attrs = {:recipient => users(:user1).username, :subject => 'test', :body => ''}
226
+ end
227
+
228
+ describe "When logged in as Administrator" do
229
+ login_admin
230
+
231
+ describe "with valid params" do
232
+ it "assigns a newly created message as @message" do
233
+ post :create, :message => @attrs, :user_id => users(:user1).username
234
+ assigns(:message).should be_valid
235
+ end
236
+
237
+ it "redirects to the created message" do
238
+ post :create, :message => @attrs, :user_id => users(:user1).username
239
+ response.should redirect_to(messages_url)
240
+ end
241
+ end
242
+
243
+ describe "with invalid params" do
244
+ it "assigns a newly created but unsaved message as @message" do
245
+ post :create, :message => @invalid_attrs, :user_id => users(:user1).username
246
+ assigns(:message).should_not be_valid
247
+ end
248
+
249
+ it "re-renders the 'new' template" do
250
+ post :create, :message => @invalid_attrs, :user_id => users(:user1).username
251
+ response.should render_template("new")
252
+ response.should be_success
253
+ end
254
+ end
255
+ end
256
+
257
+ describe "When logged in as Librarian" do
258
+ login_fixture_librarian
259
+
260
+ it "should create message without parent_id" do
261
+ post :create, :message => {:recipient => 'user2', :subject => "test", :body => "test", :parent_id => 2}
262
+ response.should redirect_to messages_url
263
+ end
264
+ end
265
+
266
+ describe "When logged in as User" do
267
+ login_fixture_user
268
+
269
+ it "should not create message without parent_id" do
270
+ post :create, :message => {:recipient => 'user2', :subject => "test", :body => "test"}
271
+ response.should be_forbidden
272
+ end
273
+
274
+ it "should not create message with parent_id" do
275
+ post :create, :message => {:recipient => 'user2', :subject => "test", :body => "test", :parent_id => 2}
276
+ response.should be_forbidden
277
+ end
278
+ end
279
+
280
+ describe "When not logged in" do
281
+ describe "with valid params" do
282
+ it "assigns a newly created message as @message" do
283
+ post :create, :message => @attrs
284
+ assigns(:message).should be_valid
285
+ end
286
+
287
+ it "should redirect to new_user_session_url" do
288
+ post :create, :message => @attrs
289
+ response.should redirect_to(new_user_session_url)
290
+ end
291
+ end
292
+
293
+ describe "with invalid params" do
294
+ it "assigns a newly created but unsaved message as @message" do
295
+ post :create, :message => @invalid_attrs
296
+ assigns(:message).should_not be_valid
297
+ end
298
+
299
+ it "should redirect to new_user_session_url" do
300
+ post :create, :message => @invalid_attrs
301
+ response.should redirect_to(new_user_session_url)
302
+ end
303
+ end
304
+ end
305
+ end
306
+
307
+ describe "PUT update" do
308
+ before(:each) do
309
+ @message = messages(:user1_to_user2_1)
310
+ @attrs = FactoryGirl.attributes_for(:message)
311
+ @invalid_attrs = {:sender_id => ''}
312
+ end
313
+
314
+ describe "When logged in as Administrator" do
315
+ login_fixture_admin
316
+
317
+ describe "with valid params" do
318
+ it "updates the requested message" do
319
+ put :update, :id => @message.id, :message => @attrs
320
+ end
321
+
322
+ it "assigns the requested message as @message" do
323
+ put :update, :id => @message.id, :message => @attrs
324
+ assigns(:message).should eq(@message)
325
+ response.should be_missing
326
+ end
327
+ end
328
+
329
+ describe "with invalid params" do
330
+ it "assigns the requested message as @message" do
331
+ put :update, :id => @message.id, :message => @invalid_attrs
332
+ end
333
+
334
+ it "re-renders the 'edit' template" do
335
+ put :update, :id => @message.id, :message => @invalid_attrs
336
+ response.should be_missing
337
+ end
338
+ end
339
+ end
340
+
341
+ describe "When logged in as Librarian" do
342
+ login_fixture_librarian
343
+
344
+ describe "with valid params" do
345
+ it "updates the requested message" do
346
+ put :update, :id => @message.id, :message => @attrs
347
+ end
348
+
349
+ it "assigns the requested message as @message" do
350
+ put :update, :id => @message.id, :message => @attrs
351
+ assigns(:message).should eq(@message)
352
+ response.should be_forbidden
353
+ end
354
+ end
355
+
356
+ describe "with invalid params" do
357
+ it "assigns the requested message as @message" do
358
+ put :update, :id => @message.id, :message => @invalid_attrs
359
+ end
360
+
361
+ it "re-renders the 'edit' template" do
362
+ put :update, :id => @message.id, :message => @invalid_attrs
363
+ response.should be_forbidden
364
+ end
365
+ end
366
+ end
367
+
368
+ describe "When logged in as User" do
369
+ login_fixture_user
370
+
371
+ describe "with valid params" do
372
+ it "updates the requested message" do
373
+ put :update, :id => @message.id, :message => @attrs
374
+ end
375
+
376
+ it "assigns the requested message as @message" do
377
+ put :update, :id => @message.id, :message => @attrs
378
+ assigns(:message).should eq(@message)
379
+ response.should be_forbidden
380
+ end
381
+ end
382
+
383
+ describe "with invalid params" do
384
+ it "assigns the requested message as @message" do
385
+ put :update, :id => @message.id, :message => @invalid_attrs
386
+ end
387
+
388
+ it "re-renders the 'edit' template" do
389
+ put :update, :id => @message.id, :message => @invalid_attrs
390
+ response.should be_forbidden
391
+ end
392
+ end
393
+
394
+ it "should not update my message" do
395
+ put :update, :id => 2, :message => { }
396
+ response.should be_forbidden
397
+ end
398
+
399
+ it "should not update other user's message" do
400
+ put :update, :id => 1, :message => { }
401
+ response.should be_forbidden
402
+ end
403
+ end
404
+
405
+ describe "When not logged in" do
406
+ it "assigns the requested message as @message" do
407
+ put :update, :id => 2, :message => { }
408
+ response.should redirect_to new_user_session_url
409
+ end
410
+ end
411
+ end
412
+
413
+ describe "DELETE destroy" do
414
+ describe "When logged in as User" do
415
+ login_fixture_user
416
+
417
+ it "should destroy own message" do
418
+ delete :destroy, :id => 2
419
+ response.should redirect_to messages_url
420
+ end
421
+
422
+ it "should not destroy other user's message" do
423
+ delete :destroy, :id => 1
424
+ response.should be_forbidden
425
+ end
426
+ end
427
+
428
+ describe "When not logged in" do
429
+ it "destroys the requested message" do
430
+ delete :destroy, :id => 1
431
+ end
432
+
433
+ it "should be redirected to new_user_session_url" do
434
+ delete :destroy, :id => 1
435
+ response.should redirect_to(new_user_session_url)
436
+ end
437
+ end
438
+ end
439
+ end
File without changes
@@ -0,0 +1,45 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+
4
+ rescue_from CanCan::AccessDenied, :with => :render_403
5
+ rescue_from ActiveRecord::RecordNotFound, :with => :render_404
6
+
7
+ private
8
+ def render_403
9
+ return if performed?
10
+ if user_signed_in?
11
+ respond_to do |format|
12
+ format.html {render :template => 'page/403', :status => 403}
13
+ format.mobile {render :template => 'page/403', :status => 403}
14
+ format.xml {render :template => 'page/403', :status => 403}
15
+ format.json
16
+ end
17
+ else
18
+ respond_to do |format|
19
+ format.html {redirect_to new_user_session_url}
20
+ format.mobile {redirect_to new_user_session_url}
21
+ format.xml {render :template => 'page/403', :status => 403}
22
+ format.json
23
+ end
24
+ end
25
+ end
26
+
27
+ def render_404
28
+ return if performed?
29
+ respond_to do |format|
30
+ format.html {render :template => 'page/404', :status => 404}
31
+ format.mobile {render :template => 'page/404', :status => 404}
32
+ format.xml {render :template => 'page/404', :status => 404}
33
+ format.json
34
+ end
35
+ end
36
+
37
+ def get_user_if_nil
38
+ @user = User.where(:username => params[:user_id]).first if params[:user_id]
39
+ #authorize! :show, @user if @user
40
+ end
41
+
42
+ def solr_commit
43
+ Sunspot.commit
44
+ end
45
+ end
@@ -0,0 +1,28 @@
1
+ class Notifier < ActionMailer::Base
2
+ if LibraryGroup.site_config.try(:url)
3
+ uri = Addressable::URI.parse(LibraryGroup.site_config.url)
4
+ default_url_options[:host] = uri.host
5
+ default_url_options[:port] = uri.port if configatron.enju.web_port_number != 80
6
+ else
7
+ default_url_options[:host] = configatron.enju.web_hostname
8
+ default_url_options[:port] = configatron.enju.web_port_number if configatron.enju.web_port_number != 80
9
+ end
10
+
11
+ def message_notification(message)
12
+ I18n.locale = message.receiver.locale.try(:to_sym) || I18n.default_locale
13
+ from = "#{LibraryGroup.system_name(message.receiver.locale)} <#{LibraryGroup.site_config.email}>"
14
+ if message.subject
15
+ subject = message.subject
16
+ else
17
+ subject = I18n.t('message.new_message_from_library', :library => LibraryGroup.system_name(message.receiver.user.locale))
18
+ end
19
+ if message.sender
20
+ @sender_name = message.sender.patron.full_name
21
+ else
22
+ @sender_name = LibraryGroup.system_name(message.receiver.locale)
23
+ end
24
+ @message = message
25
+ @locale = message.receiver.locale
26
+ mail(:from => from, :to => message.receiver.email, :subject => subject)
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ class Ability
2
+ include CanCan::Ability
3
+
4
+ def initialize(user)
5
+ case user.try(:role).try(:name)
6
+ when 'Administrator'
7
+ can :manage, Message
8
+ can [:read, :update, :destroy], MessageRequest
9
+ can [:read, :update], MessageTemplate
10
+ when 'Librarian'
11
+ can [:index, :create], Message
12
+ can [:update], Message do |message|
13
+ message.sender == user
14
+ end
15
+ can [:show, :destroy], Message do |message|
16
+ message.receiver == user
17
+ end
18
+ can [:read, :update, :destroy], MessageRequest
19
+ can :read, MessageTemplate
20
+ when 'User'
21
+ can [:read, :destroy], Message do |message|
22
+ message.receiver == user
23
+ end
24
+ can :index, Message
25
+ can :show, Message do |message|
26
+ message.receiver == user
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,86 @@
1
+ # -*- encoding: utf-8 -*-
2
+ class LibraryGroup < ActiveRecord::Base
3
+ #include Singleton
4
+ #include Configurator
5
+ include MasterModel
6
+
7
+ has_many :libraries
8
+ has_many :search_engines
9
+ #has_many :news_feeds
10
+ belongs_to :country
11
+
12
+ validates :email, :format => {:with => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i}, :presence => true
13
+ validates :url, :presence => true, :url => true
14
+ after_save :clear_site_config_cache
15
+
16
+ def clear_site_config_cache
17
+ Rails.cache.delete('library_site_config')
18
+ end
19
+
20
+ def self.site_config
21
+ #if Rails.env == 'production'
22
+ # Rails.cache.fetch('library_site_config'){LibraryGroup.find(1)}
23
+ #else
24
+ LibraryGroup.find(1)
25
+ #end
26
+ rescue
27
+ nil
28
+ end
29
+
30
+ def self.system_name(locale = I18n.locale)
31
+ LibraryGroup.site_config.display_name.localize(locale)
32
+ end
33
+
34
+ def config?
35
+ true if self == LibraryGroup.site_config
36
+ end
37
+
38
+ def real_libraries
39
+ # 物理的な図書館 = IDが1以外
40
+ libraries.where('id != 1').all
41
+ end
42
+
43
+ def network_access_allowed?(ip_address, options = {})
44
+ options = {:network_type => :lan}.merge(options)
45
+ client_ip = IPAddr.new(ip_address)
46
+ case options[:network_type]
47
+ when :admin
48
+ allowed_networks = self.admin_networks.to_s.split
49
+ else
50
+ allowed_networks = self.my_networks.to_s.split
51
+ end
52
+ allowed_networks.each do |allowed_network|
53
+ begin
54
+ network = IPAddr.new(allowed_network)
55
+ return true if network.include?(client_ip)
56
+ rescue ArgumentError
57
+ nil
58
+ end
59
+ end
60
+ return false
61
+ end
62
+ end
63
+
64
+
65
+ # == Schema Information
66
+ #
67
+ # Table name: library_groups
68
+ #
69
+ # id :integer not null, primary key
70
+ # name :string(255) not null
71
+ # display_name :text
72
+ # short_name :string(255) not null
73
+ # email :string(255)
74
+ # my_networks :text
75
+ # login_banner :text
76
+ # note :text
77
+ # post_to_union_catalog :boolean default(FALSE), not null
78
+ # country_id :integer
79
+ # created_at :datetime
80
+ # updated_at :datetime
81
+ # admin_networks :text
82
+ # allow_bookmark_external_url :boolean default(FALSE), not null
83
+ # position :integer
84
+ # url :string(255) default("http://localhost:3000/")
85
+ #
86
+