edgarj 0.01.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +23 -0
  4. data/Rakefile +40 -0
  5. data/app/assets/javascripts/edgarj/base.js +49 -0
  6. data/app/assets/javascripts/edgarj/menu.js +39 -0
  7. data/app/assets/javascripts/edgarj/operator_selection.js +133 -0
  8. data/app/assets/stylesheets/edgarj/base.css +304 -0
  9. data/app/assets/stylesheets/edgarj/menu.css +65 -0
  10. data/app/controllers/edgarj/authentication_mixin.rb.sample +30 -0
  11. data/app/controllers/edgarj/controller_mixin_common.rb +80 -0
  12. data/app/controllers/edgarj/controller_mixin_for_app.rb +71 -0
  13. data/app/controllers/edgarj/edgarj_controller.rb +535 -0
  14. data/app/controllers/edgarj/model_permissions_controller.rb +8 -0
  15. data/app/controllers/edgarj/permission_mixin.rb +84 -0
  16. data/app/controllers/edgarj/popup_controller.rb +128 -0
  17. data/app/controllers/edgarj/rescue_mixin.rb +37 -0
  18. data/app/controllers/edgarj/user_group_users_controller.rb +8 -0
  19. data/app/controllers/edgarj/user_groups_controller.rb +9 -0
  20. data/app/controllers/edgarj/user_groups_popup_controller.rb +8 -0
  21. data/app/helpers/edgarj/assoc_helper.rb +369 -0
  22. data/app/helpers/edgarj/common_helper.rb +37 -0
  23. data/app/helpers/edgarj/edgarj_helper.rb +20 -0
  24. data/app/helpers/edgarj/field_helper.rb +397 -0
  25. data/app/helpers/edgarj/form_drawer.rb +322 -0
  26. data/app/helpers/edgarj/list_drawer.rb +169 -0
  27. data/app/helpers/edgarj/menu_helper.rb +92 -0
  28. data/app/helpers/edgarj/model_permissions_helper.rb +9 -0
  29. data/app/helpers/edgarj/popup_helper.rb +40 -0
  30. data/app/helpers/edgarj/search_helper.rb +14 -0
  31. data/app/helpers/edgarj/sessions_helper.rb +9 -0
  32. data/app/helpers/edgarj/user_group_users_helper.rb +9 -0
  33. data/app/helpers/edgarj/user_groups_helper.rb +9 -0
  34. data/app/helpers/edgarj/user_groups_popup_helper.rb +9 -0
  35. data/app/models/edgarj/drawer/base.rb +234 -0
  36. data/app/models/edgarj/drawer/normal.rb +6 -0
  37. data/app/models/edgarj/drawer/popup.rb +47 -0
  38. data/app/models/edgarj/drawer.rb +13 -0
  39. data/app/models/edgarj/model_permission.rb +41 -0
  40. data/app/models/edgarj/page_info.rb +47 -0
  41. data/app/models/edgarj/search.rb +81 -0
  42. data/app/models/edgarj/search_form.rb +255 -0
  43. data/app/models/edgarj/search_popup.rb +44 -0
  44. data/app/models/edgarj/sssn.rb +120 -0
  45. data/app/models/edgarj/user_group.rb +67 -0
  46. data/app/models/edgarj/user_group_user.rb +18 -0
  47. data/app/models/edgarj.rb +5 -0
  48. data/app/views/edgarj/edgarj/_form.html.erb +25 -0
  49. data/app/views/edgarj/edgarj/_list.html.erb +52 -0
  50. data/app/views/edgarj/edgarj/_message_popup.html.erb +15 -0
  51. data/app/views/edgarj/edgarj/_search_form.html.erb +64 -0
  52. data/app/views/edgarj/edgarj/_search_operator.html.erb +17 -0
  53. data/app/views/edgarj/edgarj/_search_operator_selection.html.erb +12 -0
  54. data/app/views/edgarj/edgarj/clear.js.erb +1 -0
  55. data/app/views/edgarj/edgarj/create.js.erb +4 -0
  56. data/app/views/edgarj/edgarj/destroy.js.erb +2 -0
  57. data/app/views/edgarj/edgarj/index.html.erb +37 -0
  58. data/app/views/edgarj/edgarj/index.js.erb +1 -0
  59. data/app/views/edgarj/edgarj/message_popup.js.erb +3 -0
  60. data/app/views/edgarj/edgarj/page_info_save.js.erb +1 -0
  61. data/app/views/edgarj/edgarj/search.js.erb +4 -0
  62. data/app/views/edgarj/edgarj/search_clear.js.erb +1 -0
  63. data/app/views/edgarj/edgarj/show.js.erb +1 -0
  64. data/app/views/edgarj/edgarj/top.html.erb +4 -0
  65. data/app/views/edgarj/edgarj/update.js.erb +4 -0
  66. data/app/views/edgarj/popup/_index.html.erb +16 -0
  67. data/app/views/edgarj/popup/_list.html.erb +42 -0
  68. data/app/views/edgarj/popup/_message_popup.html.erb +15 -0
  69. data/app/views/edgarj/popup/_search.html.erb +42 -0
  70. data/app/views/edgarj/popup/_search_save_popup.html.erb +16 -0
  71. data/app/views/edgarj/popup/index.js.erb +5 -0
  72. data/app/views/edgarj/popup/message_popup.js.erb +3 -0
  73. data/app/views/edgarj/popup/page_info_save.js.erb +1 -0
  74. data/app/views/edgarj/popup/search.js.erb +15 -0
  75. data/app/views/edgarj/popup/view_status_save.js.erb +1 -0
  76. data/config/routes.rb +15 -0
  77. data/config/settings.yml +5 -0
  78. data/db/migrate/20131118084600_create_edgar_sssns.rb +14 -0
  79. data/db/migrate/20131123124730_create_edgar_page_infos.rb +15 -0
  80. data/db/migrate/20140116062252_create_edgar_user_groups.rb +18 -0
  81. data/db/migrate/20140116062327_create_edgar_user_group_users.rb +10 -0
  82. data/db/migrate/20140206222308_create_edgar_model_permissions.rb +14 -0
  83. data/db/migrate/20141209053055_rename_edgar_to_edgarj.rb +17 -0
  84. data/lib/core_ext/active_record.rb +123 -0
  85. data/lib/core_ext/resources.rb +71 -0
  86. data/lib/edgarj/engine.rb +64 -0
  87. data/lib/edgarj/enum_cache.rb +46 -0
  88. data/lib/edgarj/templates/rails/helper/helper.rb +10 -0
  89. data/lib/edgarj/templates/test_unit/scaffold/functional_test.rb +575 -0
  90. data/lib/edgarj/version.rb +3 -0
  91. data/lib/edgarj.rb +14 -0
  92. data/lib/generators/edgarj/popup_scaffold/USAGE +6 -0
  93. data/lib/generators/edgarj/popup_scaffold/popup_scaffold_generator.rb +35 -0
  94. data/lib/generators/edgarj/popup_scaffold/templates/controller.rb +13 -0
  95. data/lib/generators/edgarj/popup_scaffold/templates/functional_test.rb +197 -0
  96. data/lib/generators/edgarj/popup_scaffold/templates/helper.rb +9 -0
  97. data/lib/generators/edgarj/scaffold/USAGE +17 -0
  98. data/lib/generators/edgarj/scaffold/scaffold_generator.rb +40 -0
  99. data/lib/generators/edgarj/scaffold/templates/controller.rb +13 -0
  100. data/lib/tasks/edgarj_tasks.rake +32 -0
  101. data/lib/tasks/pakcage.rake +18 -0
  102. data/locale/en.yml +94 -0
  103. data/locale/ja.yml +100 -0
  104. data/test/dummy/README.rdoc +28 -0
  105. data/test/dummy/Rakefile +6 -0
  106. data/test/dummy/app/assets/javascripts/application.js +21 -0
  107. data/test/dummy/app/assets/javascripts/authors.js +2 -0
  108. data/test/dummy/app/assets/stylesheets/application.css +16 -0
  109. data/test/dummy/app/assets/stylesheets/authors.css +4 -0
  110. data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
  111. data/test/dummy/app/controllers/application_controller.rb +15 -0
  112. data/test/dummy/app/controllers/authors_controller.rb +6 -0
  113. data/test/dummy/app/controllers/authors_popup_controller.rb +6 -0
  114. data/test/dummy/app/controllers/books_controller.rb +6 -0
  115. data/test/dummy/app/controllers/dummy_auth_mixin.rb +36 -0
  116. data/test/dummy/app/decorators/models/edgarj/user_group_decorator.rb +1 -0
  117. data/test/dummy/app/helpers/application_helper.rb +3 -0
  118. data/test/dummy/app/helpers/authors_helper.rb +7 -0
  119. data/test/dummy/app/helpers/authors_popup_helper.rb +7 -0
  120. data/test/dummy/app/helpers/books_helper.rb +7 -0
  121. data/test/dummy/app/models/author.rb +32 -0
  122. data/test/dummy/app/models/book.rb +5 -0
  123. data/test/dummy/app/models/user.rb +13 -0
  124. data/test/dummy/app/views/layouts/application.html.erb +32 -0
  125. data/test/dummy/app/views/layouts/login.html.erb +20 -0
  126. data/test/dummy/bin/bundle +3 -0
  127. data/test/dummy/bin/rails +4 -0
  128. data/test/dummy/bin/rake +4 -0
  129. data/test/dummy/config/application.rb +59 -0
  130. data/test/dummy/config/boot.rb +10 -0
  131. data/test/dummy/config/database.yml +15 -0
  132. data/test/dummy/config/edgarj/menu_config.rb +28 -0
  133. data/test/dummy/config/environment.rb +5 -0
  134. data/test/dummy/config/environments/development.rb +42 -0
  135. data/test/dummy/config/environments/production.rb +79 -0
  136. data/test/dummy/config/environments/test.rb +34 -0
  137. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  138. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  139. data/test/dummy/config/initializers/inflections.rb +16 -0
  140. data/test/dummy/config/initializers/mime_types.rb +5 -0
  141. data/test/dummy/config/initializers/secret_token.rb +12 -0
  142. data/test/dummy/config/initializers/session_store.rb +3 -0
  143. data/test/dummy/config/initializers/strong_parameter.rb +3 -0
  144. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  145. data/test/dummy/config/locales/en.yml +26 -0
  146. data/test/dummy/config/routes.rb +60 -0
  147. data/test/dummy/config.ru +4 -0
  148. data/test/dummy/db/migrate/20131107120635_create_authors.rb +9 -0
  149. data/test/dummy/db/migrate/20131218011851_create_books.rb +10 -0
  150. data/test/dummy/db/migrate/20140201000000_add_user_group_id_to_authors.rb +5 -0
  151. data/test/dummy/db/migrate/20140807065420_create_users.rb +10 -0
  152. data/test/dummy/db/schema.rb +93 -0
  153. data/test/dummy/public/404.html +58 -0
  154. data/test/dummy/public/422.html +58 -0
  155. data/test/dummy/public/500.html +57 -0
  156. data/test/dummy/public/favicon.ico +0 -0
  157. data/test/dummy/script/rails +6 -0
  158. data/test/dummy/test/functional/authors_controller_test.rb +631 -0
  159. data/test/dummy/test/functional/books_controller_test.rb +516 -0
  160. data/test/dummy/test/helpers/authors_helper_test.rb +4 -0
  161. data/test/dummy/test/unit/author_test.rb +7 -0
  162. data/test/dummy/test/unit/book_test.rb +7 -0
  163. data/test/edgar_test.rb +7 -0
  164. data/test/fixtures/authors.yml +32 -0
  165. data/test/fixtures/books.yml +56 -0
  166. data/test/fixtures/edgarj/model_permissions.yml +97 -0
  167. data/test/fixtures/edgarj/page_infos.yml +84 -0
  168. data/test/fixtures/edgarj/sssns.yml +38 -0
  169. data/test/fixtures/edgarj/user_group_users.yml +114 -0
  170. data/test/fixtures/edgarj/user_groups.yml +95 -0
  171. data/test/fixtures/users.yml +49 -0
  172. data/test/functional/edgarj/edgarj_controller_test.rb +24 -0
  173. data/test/functional/edgarj/model_permissions_controller_test.rb +554 -0
  174. data/test/functional/edgarj/user_group_users_controller_test.rb +567 -0
  175. data/test/integration/navigation_test.rb +10 -0
  176. data/test/support/edgarj/controller_supporter.rb +23 -0
  177. data/test/test_helper.rb +23 -0
  178. data/test/unit/edgarj/model_permission_test.rb +27 -0
  179. data/test/unit/edgarj/page_info_test.rb +7 -0
  180. data/test/unit/edgarj/sssn_test.rb +10 -0
  181. data/test/unit/edgarj/user_group_test.rb +32 -0
  182. data/test/unit/edgarj/user_group_user_test.rb +9 -0
  183. data/test/unit/helpers/edgarj/model_permissions_helper_test.rb +6 -0
  184. data/test/unit/helpers/edgarj/user_group_users_helper_test.rb +6 -0
  185. metadata +456 -0
@@ -0,0 +1,631 @@
1
+ require 'test_helper'
2
+
3
+ class AuthorsControllerTest < ActionController::TestCase
4
+ context 'root user' do
5
+ setup do
6
+ login_as(:root)
7
+ @author = authors(:m_polanyi)
8
+ pi = edgarj_page_infos(:root_authors)
9
+ pi.record = Edgarj::SearchForm.new(Author, {})
10
+ pi.save!
11
+ end
12
+
13
+ should 'get index' do
14
+ get :index
15
+ assert_response :success
16
+ assert_not_nil assigns(:list)
17
+ end
18
+
19
+ should 'paginate' do
20
+ xhr :get, :index, page: 2
21
+ assert_response :success
22
+ assert_not_nil assigns(:list)
23
+ assert_equal 2, assigns(:page_info).page
24
+ end
25
+
26
+ should 'sort' do
27
+ xhr :put, :page_info_save,
28
+ id: edgarj_page_infos(:root_authors).id,
29
+ edgarj_page_info: {
30
+ dir: 'asc',
31
+ order_by: 'name'
32
+ }
33
+ assert_response :success
34
+ assert_not_nil assigns(:list)
35
+ assert_equal 'asc', assigns(:page_info).dir
36
+ assert_equal 'name', assigns(:page_info).order_by
37
+
38
+ xhr :put, :page_info_save,
39
+ id: edgarj_page_infos(:root_authors).id,
40
+ edgarj_page_info: {
41
+ dir: 'desc',
42
+ order_by: 'created_at'
43
+ }
44
+ assert_equal 'desc', assigns(:page_info).reload.dir
45
+ assert_equal 'created_at', assigns(:page_info).reload.order_by
46
+ end
47
+
48
+ should 'create author' do
49
+ assert_difference('Author.count') do
50
+ xhr :post, :create, author: { name: @author.name }
51
+ end
52
+ assert_response :success
53
+ assert assigns(:record)
54
+ end
55
+
56
+ should 'not create invalid author' do
57
+ assert_no_difference('Author.count') do
58
+ xhr :post, :create, author: { name: nil }
59
+ end
60
+ assert_response :success
61
+ assert assigns(:record)
62
+ end
63
+
64
+ should 'show author in HTML' do
65
+ get :show, id: @author
66
+ assert_response :success
67
+ assert_not_nil assigns(:record)
68
+ end
69
+
70
+ should 'show author in JS' do
71
+ xhr :get, :show, id: @author
72
+ assert_response :success
73
+ assert_not_nil assigns(:record)
74
+ end
75
+
76
+ should 'update author' do
77
+ assert_no_difference('Author.count') do
78
+ xhr :put, :update, id: @author, author: { name: 'X' }
79
+ end
80
+ assert_response :success
81
+ assert assigns(:record)
82
+ assert_equal 'X', @author.reload.name
83
+ end
84
+
85
+ should 'destroy author' do
86
+ assert_difference('Author.count', -1) do
87
+ xhr :delete, :destroy, id: @author
88
+ end
89
+ assert_response :success
90
+ assert assigns(:record)
91
+ assert assigns(:list)
92
+ end
93
+
94
+ should 'clear' do
95
+ assert_no_difference('Author.count') do
96
+ xhr :get, :clear
97
+ end
98
+ assert_response :success
99
+ assert_not_nil assigns(:record)
100
+ end
101
+
102
+ context 'search' do
103
+ should 'search' do
104
+ xhr :get, :search, edgarj_search_form: {_id: @author.id}
105
+ assert_response :success
106
+ assert_equal 1, assigns(:list).count
107
+ end
108
+
109
+ should 'search with operator' do
110
+ xhr :get, :search, edgarj_search_form: {_id: @author.id},
111
+ edgarj_search_form: {
112
+ edgarj_search_form_operator: {
113
+ _id: '<>'
114
+ }
115
+ }
116
+ assert_response :success
117
+ assert assigns(:list).count > 1
118
+ end
119
+
120
+ should 'search with timezone' do
121
+ xhr :get, :search, edgarj_search_form: {
122
+ created_at: '2012/09/30',
123
+ edgarj_search_form: {
124
+ edgarj_search_form_operator: {
125
+ created_at: '='
126
+ }
127
+ }
128
+ }
129
+ assert_response :success
130
+ assert assigns(:list).count == 1
131
+ end
132
+
133
+ should 'not search by invalid condition' do
134
+ xhr :get, :search, edgarj_search_form: {_id: 'a'}
135
+ assert_response :success
136
+ assert ((l = assigns(:list))== nil || l.count == 0)
137
+ assert !assigns(:search).valid?
138
+ end
139
+
140
+ should 'search_clear' do
141
+ xhr :get, :search_clear
142
+ assert_response :success
143
+ end
144
+ end
145
+
146
+ # test Edgarj::AuthenticationMixin
147
+
148
+ should 'current_user' do
149
+ get :index
150
+ assert_equal users(:root), @controller.send(:current_user)
151
+ end
152
+ end
153
+
154
+ context 'read-only user' do
155
+ setup do
156
+ login_as(:author_reader)
157
+ @author = authors(:m_polanyi)
158
+ pi = edgarj_page_infos(:author_reader_authors)
159
+ pi.record = Edgarj::SearchForm.new(Author, {})
160
+ pi.save!
161
+ end
162
+
163
+ should "get index" do
164
+ get :index
165
+ assert_response :success
166
+ assert_not_nil assigns(:list)
167
+ end
168
+
169
+ should "paginate" do
170
+ xhr :get, :index, page: 2
171
+ assert_response :success
172
+ assert_not_nil assigns(:list)
173
+ end
174
+
175
+ should "sort" do
176
+ xhr :put, :page_info_save,
177
+ id: edgarj_page_infos(:author_reader_authors).id,
178
+ edgarj_page_info: {
179
+ dir: 'asc',
180
+ order_by: 'name'
181
+ }
182
+ assert_response :success
183
+ assert_not_nil assigns(:list)
184
+ assert_equal 'asc', assigns(:page_info).dir
185
+ assert_equal 'name', assigns(:page_info).order_by
186
+ end
187
+
188
+ should "not create author" do
189
+ assert_no_difference('Author.count') do
190
+ xhr :post, :create, author: { name: @author.name }
191
+ end
192
+ assert_template 'message_popup'
193
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
194
+ end
195
+
196
+ should "not create author invalid" do
197
+ assert_no_difference('Author.count') do
198
+ xhr :post, :create, author: { name: nil }
199
+ end
200
+ assert_template 'message_popup'
201
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
202
+ end
203
+
204
+ should "show author in HTML" do
205
+ get :show, id: @author
206
+ assert_response :success
207
+ assert_not_nil assigns(:record)
208
+ end
209
+
210
+ should "show author in JS" do
211
+ xhr :get, :show, id: @author
212
+ assert_response :success
213
+ assert_not_nil assigns(:record)
214
+ end
215
+
216
+ should "not update author" do
217
+ assert_no_difference('Author.count') do
218
+ xhr :put, :update, id: @author, author: { name: 'X' }
219
+ end
220
+ assert_template 'message_popup'
221
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
222
+ assert_not_equal 'X', @author.reload.name
223
+ end
224
+
225
+ should "not destroy author" do
226
+ assert_no_difference('Author.count') do
227
+ xhr :delete, :destroy, id: @author
228
+ end
229
+ assert_template 'message_popup'
230
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
231
+ end
232
+
233
+ # additional routes tests
234
+
235
+ should "clear" do
236
+ assert_no_difference('Author.count') do
237
+ xhr :get, :clear
238
+ end
239
+ assert_response :success
240
+ assert_not_nil assigns(:record)
241
+ end
242
+
243
+ should "csv_download" do
244
+ get :csv_download
245
+ assert_response :success
246
+ end
247
+
248
+
249
+ should 'search' do
250
+ xhr :get, :search, edgarj_search_form: {_id: authors(:m_hagio).id}
251
+ assert_response :success
252
+ assert_equal 1, assigns(:list).count
253
+ end
254
+
255
+ should 'search_clear' do
256
+ xhr :get, :search_clear
257
+ assert_response :success
258
+ end
259
+
260
+ should 'search_save' do
261
+ skip 'search_save'
262
+ end
263
+
264
+ should 'search_load' do
265
+ skip 'search_load'
266
+ end
267
+
268
+ =begin
269
+ should 'zip_complete' do
270
+ xhr :get, :zip_complete,
271
+ zip: '1000000',
272
+ adrs_prefix: :author_adrs_attributes_
273
+ assert_response :success
274
+ assert_equal 'Tokyo', assigns(:address).prefecture
275
+ end
276
+ =end
277
+
278
+ # test Edgarj::AuthenticationMixin
279
+
280
+ should 'current_user' do
281
+ get :index
282
+
283
+ assert_equal users(:author_reader), @controller.send(:current_user)
284
+ end
285
+ end
286
+
287
+ context 'permitted and user_scoped user' do
288
+ setup do
289
+ login_as(:comic_rep_01)
290
+ @author = authors(:m_hagio)
291
+ @author_scoped_out = authors(:m_polanyi)
292
+ pi = edgarj_page_infos(:comic_rep_01_authors)
293
+ pi.record = Edgarj::SearchForm.new(Author, {})
294
+ pi.save!
295
+ end
296
+
297
+ should 'search 1 hit since role and user_scoped satisfy' do
298
+ xhr :get, :search, edgarj_search_form: {_id: @author.id}
299
+ assert_response :success
300
+ assert_equal 1, assigns(:list).count
301
+ end
302
+
303
+ should 'not search 1 hit since key is out-of-scope' do
304
+ xhr :get, :search, edgarj_search_form: {_id: @author_scoped_out.id}
305
+ assert_response :success
306
+ assert_equal 0, assigns(:list).count
307
+ end
308
+
309
+ should "show assigned author in HTML" do
310
+ get :show, id: @author
311
+ assert_response :success
312
+ assert_not_nil assigns(:record)
313
+ end
314
+
315
+ should "show assigned author in JS" do
316
+ xhr :get, :show, id: @author
317
+ assert_response :success
318
+ assert_not_nil assigns(:record)
319
+ end
320
+
321
+ should "not show non-assigned author in HTML" do
322
+ get :show, id: @author_scoped_out
323
+ assert_response :redirect
324
+ assert_nil assigns(:record)
325
+ assert_equal I18n.t('edgarj.default.not_found'), flash[:error]
326
+ end
327
+
328
+ should "not show non-assigned author in JS" do
329
+ xhr :get, :show, id: @author_scoped_out
330
+ assert_response :success
331
+ assert_nil assigns(:record)
332
+ assert_equal I18n.t('edgarj.default.not_found'), flash[:error]
333
+ end
334
+
335
+ should "update author" do
336
+ assert_no_difference('Author.count') do
337
+ xhr :put, :update, id: @author, author: { name: 'X' }
338
+ end
339
+ assert_response :success
340
+ assert assigns(:record)
341
+ assert_equal 'X', @author.reload.name
342
+ end
343
+
344
+ should "not update non-assigned author" do
345
+ assert_no_difference('Author.count') do
346
+ xhr :put, :update, id: @author_scoped_out, author: { name: 'X' }
347
+ end
348
+ assert_response :success
349
+ assert_nil assigns(:record)
350
+ assert_not_equal 'X', @author.reload.name
351
+ end
352
+
353
+ should "destroy author" do
354
+ assert_difference('Author.count', -1) do
355
+ xhr :delete, :destroy, id: @author
356
+ end
357
+ assert_response :success
358
+ assert assigns(:record)
359
+ assert assigns(:list)
360
+ end
361
+
362
+ should "not destroy non-assigned author" do
363
+ assert_no_difference('Author.count') do
364
+ xhr :delete, :destroy, id: @author_scoped_out
365
+ end
366
+ assert_response :success
367
+ assert_nil assigns(:record)
368
+ assert_nil assigns(:list)
369
+ end
370
+
371
+ =begin
372
+ should 'zip_complete' do
373
+ xhr :get, :zip_complete,
374
+ zip: '1000000',
375
+ adrs_prefix: :author_adrs_attributes_
376
+ assert_response :success
377
+ assert_equal 'Tokyo', assigns(:address).prefecture
378
+ end
379
+ =end
380
+
381
+ end
382
+
383
+ context 'not-permitted user' do
384
+ setup do
385
+ login_as(:not_permitted)
386
+ @author = authors(:m_polanyi)
387
+ end
388
+
389
+ should "not get index" do
390
+ get :index
391
+ assert_redirected_to top_path
392
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
393
+ end
394
+
395
+ should "not paginate" do
396
+ xhr :get, :index, page: 2
397
+ assert_template 'message_popup'
398
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
399
+ end
400
+
401
+ should "not sort" do
402
+ xhr :put, :page_info_save,
403
+ id: edgarj_page_infos(:book_reader_authors).id,
404
+ edgarj_page_info: {
405
+ dir: 'asc',
406
+ order_by: 'name'
407
+ }
408
+ assert_template 'message_popup'
409
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
410
+ end
411
+
412
+ should "not create author" do
413
+ assert_no_difference('Author.count') do
414
+ xhr :post, :create, author: { name: @author.name }
415
+ end
416
+ assert_template 'message_popup'
417
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
418
+ end
419
+
420
+ should "not create author invalid" do
421
+ assert_no_difference('Author.count') do
422
+ xhr :post, :create, author: { name: nil }
423
+ end
424
+
425
+ assert_template 'message_popup'
426
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
427
+ end
428
+
429
+ should "not show author in HTML" do
430
+ get :show, id: @author
431
+ assert_redirected_to top_path
432
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
433
+ end
434
+
435
+ should "not show author in JS" do
436
+ xhr :get, :show, id: @author
437
+ assert_template 'message_popup'
438
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
439
+ end
440
+
441
+ should "not update author" do
442
+ assert_no_difference('Author.count') do
443
+ xhr :put, :update, id: @author, author: { name: @author.name }
444
+ end
445
+ assert_template 'message_popup'
446
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
447
+ assert_not_equal 'X', @author.reload.name
448
+ end
449
+
450
+ should "not destroy author" do
451
+ assert_no_difference('Author.count') do
452
+ xhr :delete, :destroy, id: @author
453
+ end
454
+ assert_template 'message_popup'
455
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
456
+ end
457
+
458
+ # additional routes tests
459
+
460
+ should "not clear" do
461
+ assert_no_difference('Author.count') do
462
+ xhr :get, :clear
463
+ end
464
+ assert_template 'message_popup'
465
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
466
+ end
467
+
468
+ should "not csv_download" do
469
+ get :csv_download
470
+ assert_redirected_to top_path
471
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
472
+ end
473
+
474
+ should 'not search' do
475
+ xhr :get, :search, edgarj_search_form: {_id: authors(:m_hagio).id}
476
+ assert_template 'message_popup'
477
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
478
+ end
479
+
480
+ should 'not search_clear' do
481
+ xhr :get, :search_clear
482
+ assert_template 'message_popup'
483
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
484
+ end
485
+
486
+ should 'not search_save' do
487
+ skip 'search_save'
488
+ end
489
+
490
+ should 'not search_load' do
491
+ skip 'search_load'
492
+ end
493
+
494
+ =begin
495
+ should 'not zip_complete' do
496
+ xhr :get, :zip_complete,
497
+ zip: '1000000',
498
+ adrs_prefix: :author_adrs_attributes_
499
+ assert_nil assigns(:address)
500
+ assert_template 'message_popup'
501
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
502
+ end
503
+ =end
504
+
505
+ # test Edgarj::AuthenticationMixin
506
+
507
+ should 'current_user' do
508
+ get :index
509
+ assert_equal users(:not_permitted), @controller.send(:current_user)
510
+ end
511
+ end
512
+
513
+ context 'not-login' do
514
+ setup do
515
+ @author = authors(:m_polanyi)
516
+ end
517
+
518
+ should "not get index" do
519
+ get :index
520
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
521
+ end
522
+
523
+ should "not paginate" do
524
+ xhr :get, :index, page: 2
525
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
526
+ end
527
+
528
+ should "not sort" do
529
+ xhr :put, :page_info_save,
530
+ id: edgarj_page_infos(:book_reader_authors).id,
531
+ edgarj_page_info: {
532
+ dir: 'asc',
533
+ order_by: 'name'
534
+ }
535
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
536
+ end
537
+
538
+ should "not create author" do
539
+ assert_no_difference('Author.count') do
540
+ xhr :post, :create, author: { name: @author.name }
541
+ end
542
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
543
+ end
544
+
545
+ should "not create author invalid" do
546
+ assert_no_difference('Author.count') do
547
+ xhr :post, :create, author: { name: nil }
548
+ end
549
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
550
+ end
551
+
552
+ should "not show author in HTML" do
553
+ get :show, id: @author
554
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
555
+ end
556
+
557
+ should "not show author in JS" do
558
+ xhr :get, :show, id: @author
559
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
560
+ end
561
+
562
+ should "not update author" do
563
+ assert_no_difference('Author.count') do
564
+ xhr :put, :update, id: @author, author: { name: @author.name }
565
+ end
566
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
567
+ end
568
+
569
+ should "not destroy author" do
570
+ assert_no_difference('Author.count') do
571
+ xhr :delete, :destroy, id: @author
572
+ end
573
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
574
+ end
575
+
576
+ # additional routes tests
577
+
578
+ should "not clear" do
579
+ assert_no_difference('Author.count') do
580
+ xhr :get, :clear
581
+ end
582
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
583
+ end
584
+
585
+ should "not csv_download" do
586
+ get :csv_download
587
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
588
+ end
589
+
590
+ should 'not search' do
591
+ xhr :get, :search, edgarj_search_form: {_id: authors(:m_hagio).id}
592
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
593
+ end
594
+
595
+ should 'not search_clear' do
596
+ xhr :get, :search_clear
597
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
598
+ end
599
+
600
+ should 'not search_save' do
601
+ skip 'search_save'
602
+ end
603
+
604
+ should 'not search_load' do
605
+ skip 'search_load'
606
+ end
607
+
608
+ =begin
609
+ should 'not zip_complete' do
610
+ xhr :get, :zip_complete,
611
+ zip: '1000000',
612
+ adrs_prefix: :author_adrs_attributes_
613
+ assert_template 'edgarj/sssns/new'
614
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
615
+ end
616
+ =end
617
+
618
+ # test Edgarj::AuthenticationMixin
619
+
620
+ should 'be nil current_user' do
621
+ get :index
622
+ assert_nil @controller.send(:current_user)
623
+ end
624
+ end
625
+
626
+ # test Edgarj::ControllerMixinForApp
627
+
628
+ test 'v' do
629
+ assert_equal 'Test Word!', @controller.send(:v, 'test_word')
630
+ end
631
+ end