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,567 @@
1
+ require 'test_helper'
2
+
3
+ module Edgarj
4
+ class UserGroupUsersControllerTest < ActionController::TestCase
5
+ context 'root user' do
6
+ setup do
7
+ login_as(:root)
8
+ @user_group_user = edgarj_user_group_users(:role_admin)
9
+ @pi = create_page_info(@sssn, 'user_group_users', UserGroupUser)
10
+ end
11
+
12
+ should 'get index' do
13
+ get :index
14
+ assert_response :success
15
+ assert_not_nil assigns(:list)
16
+ end
17
+
18
+ should 'paginate' do
19
+ xhr :get, :index, page: 2
20
+ assert_response :success
21
+ assert_not_nil assigns(:list)
22
+ end
23
+
24
+ should 'sort' do
25
+ xhr :put, :page_info_save,
26
+ id: @pi.id,
27
+ edgarj_page_info: {
28
+ dir: 'asc',
29
+ order_by: 'created_at'
30
+ }
31
+ assert_response :success
32
+ assert_not_nil assigns(:list)
33
+ assert_equal 'asc', assigns(:page_info).dir
34
+ assert_equal 'created_at', assigns(:page_info).order_by
35
+ end
36
+
37
+ should 'create user_group_user' do
38
+ assert_difference('UserGroupUser.count') do
39
+ xhr :post, :create, edgarj_user_group_user: {
40
+ user_group_id: @user_group_user.user_group_id,
41
+ user_id: users(:book_admin).id,
42
+ }
43
+ end
44
+ assert_response :success
45
+ assert assigns(:record)
46
+ end
47
+
48
+ should 'not create invalid user_group_user' do
49
+ assert_no_difference('UserGroupUser.count') do
50
+ xhr :post, :create, edgarj_user_group_user: {
51
+ user_group_id: @user_group_user.user_group_id,
52
+ user_id: @user_group_user.user_id
53
+ # duplicated user_id
54
+ }
55
+ end
56
+ assert_response :success
57
+ assert assigns(:record)
58
+ end
59
+
60
+ # ここで 以下エラーが発生:
61
+ # ActionController::RoutingError No route matches {:controller=>"users", :action=>"show", :id=>..
62
+ # /ido/maeken/repo/edgarj/app/helpers/edgarj/assoc_helper.rb:206:in `draw_belongs_to_field'
63
+ should 'show user_group_user in HTML' do
64
+ skip 'hi'
65
+ get :show, id: @user_group_user
66
+ assert_response :success
67
+ assert_not_nil assigns(:record)
68
+ end
69
+
70
+ should 'show user_group_user in JS' do
71
+ xhr :get, :show, id: @user_group_user
72
+ assert_response :success
73
+ assert_not_nil assigns(:record)
74
+ end
75
+
76
+ should 'update user_group_user' do
77
+ xhr :put, :update, id: @user_group_user, edgarj_user_group_user: {
78
+ user_id: users(:book_admin).id
79
+ }
80
+ assert_response :success
81
+ assert assigns(:record)
82
+ end
83
+
84
+ should 'destroy user_group_user' do
85
+ assert_difference('UserGroupUser.count', -1) do
86
+ xhr :delete, :destroy, id: @user_group_user
87
+ end
88
+ assert_response :success
89
+ assert assigns(:record)
90
+ assert assigns(:list)
91
+ end
92
+
93
+ should 'clear user_group_user' do
94
+ assert_no_difference('UserGroupUser.count') do
95
+ xhr :get, :clear
96
+ end
97
+ assert_response :success
98
+ assert_not_nil assigns(:record)
99
+ end
100
+
101
+ should 'csv_download user_group_users' do
102
+ get :csv_download
103
+ assert_response :success
104
+ end
105
+
106
+ should 'search' do
107
+ xhr :get, :search, edgarj_search_form: {}
108
+ assert_response :success
109
+ assert assigns(:list).count >= 1
110
+ end
111
+
112
+ should 'search_clear user_group_user' do
113
+ xhr :get, :search_clear
114
+ assert_response :success
115
+ end
116
+
117
+ should 'search_save user_group_user' do
118
+ skip 'search_save'
119
+ end
120
+
121
+ should 'search_load user_group_user' do
122
+ skip 'search_load'
123
+ end
124
+ end
125
+
126
+ # All of tests in this context is skipped because it is required
127
+ # to prepare read-only user.
128
+ # When complete the preparation, delete the skip lines.
129
+ context 'read-only user' do
130
+ setup do
131
+ # prepare fixtures of model_permissions, user_groups, and
132
+ # user_group_users for read-only user of the
133
+ # UserGroupUsersController and login by him/her.
134
+ #
135
+ login_as(:user_group_user_reader)
136
+ @pi = create_page_info(@sssn, 'user_group_users', UserGroupUser)
137
+ end
138
+
139
+ should 'get index' do
140
+ skip 'get index'
141
+ get :index
142
+ assert_response :success
143
+ assert_not_nil assigns(:list)
144
+ end
145
+
146
+ should 'paginate' do
147
+ skip 'paginate'
148
+ xhr :get, :index, page: 2
149
+ assert_response :success
150
+ assert_not_nil assigns(:list)
151
+ end
152
+
153
+ should 'sort' do
154
+ skip 'sort'
155
+ xhr :put, :page_info_save,
156
+ id: @pi.id,
157
+ edgarj_page_info: {
158
+ dir: 'asc',
159
+ order_by: 'created_at'
160
+ }
161
+ assert_response :success
162
+ assert_not_nil assigns(:list)
163
+ assert_equal 'asc', assigns(:page_info).dir
164
+ assert_equal 'created_at', assigns(:page_info).order_by
165
+ end
166
+
167
+ should 'not create user_group_user' do
168
+ skip 'not create user_group_user'
169
+ assert_no_difference('UserGroupUser.count') do
170
+ xhr :post, :create, edgarj_user_group_user: { }
171
+ end
172
+ assert_template 'message_popup'
173
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
174
+ end
175
+
176
+ should 'not create invalid user_group_user' do
177
+ skip 'not create invalid user_group_user'
178
+ assert_no_difference('UserGroupUser.count') do
179
+ #xhr :post, :create, invalid resource attributes...
180
+ end
181
+ assert_template 'message_popup'
182
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
183
+ end
184
+
185
+ should 'show user_group_user in HTML' do
186
+ skip 'show user_group_user in HTML'
187
+ get :show, id: @user_group_user
188
+ assert_response :success
189
+ assert_not_nil assigns(:record)
190
+ end
191
+
192
+ should 'show user_group_user in JS' do
193
+ skip 'show user_group_user in JS'
194
+ xhr :get, :show, id: @user_group_user
195
+ assert_response :success
196
+ assert_not_nil assigns(:record)
197
+ end
198
+
199
+ should 'not update user_group_user' do
200
+ skip 'not update user_group_user'
201
+ xhr :put, :update, id: @user_group_user, edgarj_user_group_user: { }
202
+ assert_template 'message_popup'
203
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
204
+ old_user_group_user = @user_group_user
205
+ assert_equal(
206
+ old_user_group_user,
207
+ @user_group_user.reload)
208
+ end
209
+
210
+ should 'not destroy user_group_user' do
211
+ skip 'not destroy user_group_user'
212
+ assert_no_difference('UserGroupUser.count') do
213
+ xhr :delete, :destroy, id: @user_group_user
214
+ end
215
+ assert_template 'message_popup'
216
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
217
+ end
218
+
219
+ should 'clear user_group_user' do
220
+ skip 'clear user_group_user'
221
+ assert_no_difference('UserGroupUser.count') do
222
+ xhr :get, :clear
223
+ end
224
+ assert_response :success
225
+ assert_not_nil assigns(:record)
226
+ end
227
+
228
+ should 'csv_download user_group_users' do
229
+ skip 'csv_download user_group_users'
230
+ get :csv_download
231
+ assert_response :success
232
+ end
233
+
234
+ should 'search' do
235
+ skip 'search user_group_users'
236
+ xhr :get, :search, edgarj_search_form: {}
237
+ assert_response :success
238
+ assert assigns(:list).count >= 1
239
+ end
240
+
241
+ should 'search_clear user_group_user' do
242
+ skip 'search_clear user_group_user'
243
+ xhr :get, :search_clear
244
+ assert_response :success
245
+ end
246
+
247
+ should 'search_save user_group_user' do
248
+ skip 'search_save'
249
+ end
250
+
251
+ should 'search_load user_group_user' do
252
+ skip 'search_load'
253
+ end
254
+ end
255
+
256
+ # All of tests in this context is skipped because it is required
257
+ # to prepare 'permitted but user_scoped' user.
258
+ # When complete the preparation, delete the skip lines.
259
+ context 'permitted and user_scoped user' do
260
+ setup do
261
+ # prepare fixtures of model_permissions, user_groups, and
262
+ # user_group_users for permitted and user_scoped user of the
263
+ # UserGroupUsersController and login by him/her.
264
+ #
265
+ #login_as(:permitted_n_user_scoped_on_user_group_users)
266
+ #@pi = create_page_info(@sssn, 'user_group_users', UserGroupUser)
267
+
268
+ @user_group_user = edgarj_user_group_users(:role_user_group_user_reader)
269
+ @user_group_user_scoped_out = edgarj_user_group_users(:role_admin)
270
+ end
271
+
272
+ should 'search 1 hit since role and user_scoped satisfy' do
273
+ skip 'search 1 hit since role and user_scoped satisfy'
274
+ xhr :get, :search, edgarj_search_form: {_id: @user_group_user.id}
275
+ assert_response :success
276
+ assert_equal 1, assigns(:list).count
277
+ end
278
+
279
+ should 'not search 1 hit since key is out-of-scope' do
280
+ skip 'not search 1 hit since key is out-of-scope'
281
+ xhr :get, :search, edgarj_search_form: {_id: @user_group_user_scoped_out.id}
282
+ assert_response :success
283
+ assert_equal 0, assigns(:list).count
284
+ end
285
+
286
+ should 'show assigned user_group_user in HTML' do
287
+ skip 'show assigned user_group_user in HTML'
288
+ get :show, id: @user_group_user
289
+ assert_response :success
290
+ assert_not_nil assigns(:record)
291
+ end
292
+
293
+ should 'show assigned user_group_user in JS' do
294
+ skip 'show assigned user_group_user in JS'
295
+ xhr :get, :show, id: @user_group_user
296
+ assert_response :success
297
+ assert_not_nil assigns(:record)
298
+ end
299
+
300
+ should 'not show non-assigned user_group_user in HTML' do
301
+ skip 'not show non-assigned user_group_user in HTML'
302
+ get :show, id: @user_group_user_scoped_out
303
+ assert_response :redirect
304
+ assert_nil assigns(:record)
305
+ assert_equal I18n.t('edgarj.default.not_found'), flash[:error]
306
+ end
307
+
308
+ should 'not show non-assigned user_group_user in JS' do
309
+ skip 'not show non-assigned user_group_user in JS'
310
+ xhr :get, :show, id: @user_group_user_scoped_out
311
+ assert_response :success
312
+ assert_nil assigns(:record)
313
+ assert_equal I18n.t('edgarj.default.not_found'), flash[:error]
314
+ end
315
+
316
+ should 'update user_group_user' do
317
+ skip 'update user_group_user'
318
+ xhr :put, :update, id: @user_group_user, edgarj_user_group_user: { }
319
+ assert_response :success
320
+ assert assigns(:record)
321
+ end
322
+
323
+ should 'not update user_group_user' do
324
+ skip 'not update user_group_user'
325
+ xhr :put, :update, id: @user_group_user, edgarj_user_group_user: { }
326
+ assert_nil assigns(:record)
327
+ assert_equal I18n.t('edgarj.default.not_found'), flash[:error]
328
+ old_user_group_user = @user_group_user
329
+ assert_equal(
330
+ old_user_group_user,
331
+ @user_group_user.reload)
332
+ end
333
+
334
+ should 'destroy user_group_user' do
335
+ skip 'destroy user_group_user'
336
+ assert_difference('UserGroupUser.count', -1) do
337
+ xhr :delete, :destroy, id: @user_group_user
338
+ end
339
+ assert_response :success
340
+ assert assigns(:record)
341
+ assert assigns(:list)
342
+ end
343
+
344
+ should 'not destroy user_group_user' do
345
+ skip 'not destroy user_group_user'
346
+ assert_no_difference('UserGroupUser.count') do
347
+ xhr :delete, :destroy, id: @user_group_user_scoped_out
348
+ end
349
+ assert_equal I18n.t('edgarj.default.not_found'), flash[:error]
350
+ end
351
+ end
352
+
353
+ context 'not-permitted user' do
354
+ setup do
355
+ login_as(:not_permitted)
356
+ @user_group_user = edgarj_user_group_users(:role_admin)
357
+ end
358
+
359
+ should 'not get index' do
360
+ get :index
361
+
362
+ assert_redirected_to top_path
363
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
364
+ end
365
+
366
+ should 'not paginate' do
367
+ xhr :get, :index, page: 2
368
+
369
+ assert_template 'message_popup'
370
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
371
+ end
372
+
373
+ should 'not sort' do
374
+ xhr :put, :page_info_save,
375
+ id: edgarj_page_infos(:root_zip_address),
376
+ edgarj_page_info: {
377
+ dir: 'asc',
378
+ order_by: 'name'
379
+ }
380
+ assert_template 'message_popup'
381
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
382
+ end
383
+
384
+ should 'not create user_group_user' do
385
+ assert_no_difference('UserGroupUser.count') do
386
+ xhr :post, :create, edgarj_user_group_user: { }
387
+ end
388
+
389
+ assert_template 'message_popup'
390
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
391
+ end
392
+
393
+ should 'not show user_group_user in HTML' do
394
+ get :show, id: @user_group_user
395
+ assert_redirected_to top_path
396
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
397
+ end
398
+
399
+ should 'not show user_group_user in JS' do
400
+ xhr :get, :show, id: @user_group_user
401
+
402
+ assert_template 'message_popup'
403
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
404
+ end
405
+
406
+ should 'not update user_group_user' do
407
+ xhr :put, :update, id: @user_group_user, edgarj_user_group_user: { }
408
+ assert_template 'message_popup'
409
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
410
+ old_user_group_user = @user_group_user
411
+ assert_equal(
412
+ old_user_group_user,
413
+ @user_group_user.reload)
414
+ end
415
+
416
+ should 'not destroy user_group_user' do
417
+ assert_no_difference('UserGroupUser.count') do
418
+ xhr :delete, :destroy, id: @user_group_user
419
+ end
420
+ assert_template 'message_popup'
421
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
422
+ end
423
+
424
+ should 'not clear' do
425
+ assert_no_difference('UserGroupUser.count') do
426
+ xhr :get, :clear
427
+ end
428
+
429
+ assert_template 'message_popup'
430
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
431
+ end
432
+
433
+ should 'not csv_download' do
434
+ get :csv_download
435
+
436
+ assert_redirected_to top_path
437
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
438
+ end
439
+
440
+ should 'not search' do
441
+ xhr :get, :search, edgarj_search_form: {_id: @user_group_user.id}
442
+
443
+ assert_template 'message_popup'
444
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
445
+ end
446
+
447
+ should 'not search_clear' do
448
+ xhr :get, :search_clear
449
+
450
+ assert_template 'message_popup'
451
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
452
+ end
453
+
454
+ should 'not search_save' do
455
+ skip 'search_save'
456
+ end
457
+
458
+ should 'not search_load' do
459
+ skip 'search_load'
460
+ end
461
+
462
+ # test Edgarj::AuthenticationMixin
463
+
464
+ should 'current_user' do
465
+ get :index
466
+ assert_equal users(:not_permitted), @controller.send(:current_user)
467
+ end
468
+ end
469
+
470
+ context 'not-login' do
471
+ setup do
472
+ @user_group_user = edgarj_user_group_users(:role_admin)
473
+ end
474
+
475
+ should 'not get index' do
476
+ get :index
477
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
478
+ end
479
+
480
+ should 'not paginate' do
481
+ xhr :get, :index, page: 2
482
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
483
+ end
484
+
485
+ should 'not sort' do
486
+ xhr :put, :page_info_save,
487
+ # ensure what happens when not-login user puts with
488
+ # current edgarj_page_info-id
489
+ id: edgarj_page_infos(:root_zip_address),
490
+ edgarj_page_info: {
491
+ dir: 'asc',
492
+ order_by: 'name'
493
+ }
494
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
495
+ end
496
+
497
+ should 'not create user_group_user' do
498
+ assert_no_difference('UserGroupUser.count') do
499
+ xhr :post, :create, edgarj_user_group_user: { name: @user_group_user.name }
500
+ end
501
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
502
+ end
503
+
504
+ should 'not create user_group_user invalid' do
505
+ assert_no_difference('UserGroupUser.count') do
506
+ xhr :post, :create, edgarj_user_group_user: { name: nil }
507
+ end
508
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
509
+ end
510
+
511
+ should 'not show user_group_user in HTML' do
512
+ get :show, id: @user_group_user
513
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
514
+ end
515
+
516
+ should 'not show user_group_user in JS' do
517
+ xhr :get, :show, id: @user_group_user
518
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
519
+ end
520
+
521
+ should 'not update user_group_user' do
522
+ assert_no_difference('UserGroupUser.count') do
523
+ xhr :put, :update, id: @user_group_user, edgarj_user_group_user: { name: @user_group_user.name }
524
+ end
525
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
526
+ end
527
+
528
+ should 'not destroy user_group_user' do
529
+ assert_no_difference('UserGroupUser.count') do
530
+ xhr :delete, :destroy, id: @user_group_user
531
+ end
532
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
533
+ end
534
+
535
+ should 'not clear' do
536
+ assert_no_difference('UserGroupUser.count') do
537
+ xhr :get, :clear
538
+ end
539
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
540
+ end
541
+
542
+ should 'not csv_download' do
543
+ get :csv_download
544
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
545
+ end
546
+
547
+ should 'not search' do
548
+ xhr :get, :search, edgarj_search_form: {_id: edgarj_user_group_users(:role_admin).id}
549
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
550
+ end
551
+
552
+ should 'not search_clear' do
553
+ xhr :get, :search_clear
554
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
555
+ end
556
+
557
+ should 'not search_save' do
558
+ skip 'search_save'
559
+ end
560
+
561
+ should 'not search_load' do
562
+ skip 'search_load'
563
+ end
564
+ end
565
+ end
566
+ end
567
+
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ class NavigationTest < ActionDispatch::IntegrationTest
4
+ fixtures :all
5
+
6
+ # test "the truth" do
7
+ # assert true
8
+ # end
9
+ end
10
+
@@ -0,0 +1,23 @@
1
+ module Edgarj::ControllerSupporter
2
+ def login_as(user_symbol)
3
+ @sssn = edgarj_sssns(user_symbol)
4
+ @sssn.data # because need to Edgarj::Sssn#loaded? be true to
5
+ # 'save' not return false
6
+ @sssn.update_attribute(:session_id, @request.session_options[:id])
7
+ @request.session[:user_id] = user_symbol ? Edgarj::label(user_symbol) : nil
8
+ @request.session[:sssn] = true
9
+ end
10
+
11
+ def create_page_info(sssn, view, model_class)
12
+ pi = Edgarj::PageInfo.create!(
13
+ sssn_id: sssn.id,
14
+ view: view,
15
+ lines: 10,
16
+ order_by: '',
17
+ dir: '',
18
+ page: 1)
19
+ pi.record = Edgarj::SearchForm.new(model_class, {})
20
+ pi.save!
21
+ pi
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+ require 'shoulda-context'
7
+
8
+ Rails.backtrace_cleaner.remove_silencers!
9
+
10
+ # Load support files
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
12
+
13
+ # Load fixtures from the engine
14
+ # https://github.com/rails/rails/issues/4971#issuecomment-20129088
15
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
16
+
17
+ class ActiveSupport::TestCase
18
+ fixtures :all
19
+ end
20
+
21
+ class ActionController::TestCase
22
+ include Edgarj::ControllerSupporter
23
+ end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ class Edgarj::ModelPermissionTest < ActiveSupport::TestCase
4
+ test 'permitted?' do
5
+ f = Edgarj::ModelPermission::FlagsBitset
6
+ TESTS = [
7
+ # test pattern is as follows:
8
+ #
9
+ #expect fixture requested_flag(s)
10
+ #------ ------- -----------------
11
+ [true, :book_reader, f::READ], # exact match
12
+ [false, :book_reader, f::DELETE], # exact not match
13
+ [true, :customer_read_update, f::READ], # flag is included
14
+ [true, :customer_read_update, f::READ + f::UPDATE], # flags are included
15
+ [false, :customer_read_update, f::DELETE], # flag is not included
16
+ [false, :customer_read_update, f::READ + f::DELETE], # some flags are not included
17
+ # partially -> FALSE
18
+ ]
19
+
20
+ for t in TESTS do
21
+ assert_equal(
22
+ t[0],
23
+ !!edgarj_model_permissions(t[1]).permitted?(t[2]),
24
+ t.inspect)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class Edgarj::PageInfoTest < ActiveSupport::TestCase
4
+ test 'belongs_to' do
5
+ assert_equal edgarj_sssns(:root), edgarj_page_infos(:root_authors).sssn
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ module Edgarj
4
+ class Edgarj::SssnTest < ActiveSupport::TestCase
5
+ test 'belongs_to :user' do
6
+ pending 'now'
7
+ assert_equal edgarj_users(:root), edgarj_sssns(:root).user
8
+ end
9
+ end
10
+ end