edgarj 0.01.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +23 -0
- data/Rakefile +40 -0
- data/app/assets/javascripts/edgarj/base.js +49 -0
- data/app/assets/javascripts/edgarj/menu.js +39 -0
- data/app/assets/javascripts/edgarj/operator_selection.js +133 -0
- data/app/assets/stylesheets/edgarj/base.css +304 -0
- data/app/assets/stylesheets/edgarj/menu.css +65 -0
- data/app/controllers/edgarj/authentication_mixin.rb.sample +30 -0
- data/app/controllers/edgarj/controller_mixin_common.rb +80 -0
- data/app/controllers/edgarj/controller_mixin_for_app.rb +71 -0
- data/app/controllers/edgarj/edgarj_controller.rb +535 -0
- data/app/controllers/edgarj/model_permissions_controller.rb +8 -0
- data/app/controllers/edgarj/permission_mixin.rb +84 -0
- data/app/controllers/edgarj/popup_controller.rb +128 -0
- data/app/controllers/edgarj/rescue_mixin.rb +37 -0
- data/app/controllers/edgarj/user_group_users_controller.rb +8 -0
- data/app/controllers/edgarj/user_groups_controller.rb +9 -0
- data/app/controllers/edgarj/user_groups_popup_controller.rb +8 -0
- data/app/helpers/edgarj/assoc_helper.rb +369 -0
- data/app/helpers/edgarj/common_helper.rb +37 -0
- data/app/helpers/edgarj/edgarj_helper.rb +20 -0
- data/app/helpers/edgarj/field_helper.rb +397 -0
- data/app/helpers/edgarj/form_drawer.rb +322 -0
- data/app/helpers/edgarj/list_drawer.rb +169 -0
- data/app/helpers/edgarj/menu_helper.rb +92 -0
- data/app/helpers/edgarj/model_permissions_helper.rb +9 -0
- data/app/helpers/edgarj/popup_helper.rb +40 -0
- data/app/helpers/edgarj/search_helper.rb +14 -0
- data/app/helpers/edgarj/sessions_helper.rb +9 -0
- data/app/helpers/edgarj/user_group_users_helper.rb +9 -0
- data/app/helpers/edgarj/user_groups_helper.rb +9 -0
- data/app/helpers/edgarj/user_groups_popup_helper.rb +9 -0
- data/app/models/edgarj/drawer/base.rb +234 -0
- data/app/models/edgarj/drawer/normal.rb +6 -0
- data/app/models/edgarj/drawer/popup.rb +47 -0
- data/app/models/edgarj/drawer.rb +13 -0
- data/app/models/edgarj/model_permission.rb +41 -0
- data/app/models/edgarj/page_info.rb +47 -0
- data/app/models/edgarj/search.rb +81 -0
- data/app/models/edgarj/search_form.rb +255 -0
- data/app/models/edgarj/search_popup.rb +44 -0
- data/app/models/edgarj/sssn.rb +120 -0
- data/app/models/edgarj/user_group.rb +67 -0
- data/app/models/edgarj/user_group_user.rb +18 -0
- data/app/models/edgarj.rb +5 -0
- data/app/views/edgarj/edgarj/_form.html.erb +25 -0
- data/app/views/edgarj/edgarj/_list.html.erb +52 -0
- data/app/views/edgarj/edgarj/_message_popup.html.erb +15 -0
- data/app/views/edgarj/edgarj/_search_form.html.erb +64 -0
- data/app/views/edgarj/edgarj/_search_operator.html.erb +17 -0
- data/app/views/edgarj/edgarj/_search_operator_selection.html.erb +12 -0
- data/app/views/edgarj/edgarj/clear.js.erb +1 -0
- data/app/views/edgarj/edgarj/create.js.erb +4 -0
- data/app/views/edgarj/edgarj/destroy.js.erb +2 -0
- data/app/views/edgarj/edgarj/index.html.erb +37 -0
- data/app/views/edgarj/edgarj/index.js.erb +1 -0
- data/app/views/edgarj/edgarj/message_popup.js.erb +3 -0
- data/app/views/edgarj/edgarj/page_info_save.js.erb +1 -0
- data/app/views/edgarj/edgarj/search.js.erb +4 -0
- data/app/views/edgarj/edgarj/search_clear.js.erb +1 -0
- data/app/views/edgarj/edgarj/show.js.erb +1 -0
- data/app/views/edgarj/edgarj/top.html.erb +4 -0
- data/app/views/edgarj/edgarj/update.js.erb +4 -0
- data/app/views/edgarj/popup/_index.html.erb +16 -0
- data/app/views/edgarj/popup/_list.html.erb +42 -0
- data/app/views/edgarj/popup/_message_popup.html.erb +15 -0
- data/app/views/edgarj/popup/_search.html.erb +42 -0
- data/app/views/edgarj/popup/_search_save_popup.html.erb +16 -0
- data/app/views/edgarj/popup/index.js.erb +5 -0
- data/app/views/edgarj/popup/message_popup.js.erb +3 -0
- data/app/views/edgarj/popup/page_info_save.js.erb +1 -0
- data/app/views/edgarj/popup/search.js.erb +15 -0
- data/app/views/edgarj/popup/view_status_save.js.erb +1 -0
- data/config/routes.rb +15 -0
- data/config/settings.yml +5 -0
- data/db/migrate/20131118084600_create_edgar_sssns.rb +14 -0
- data/db/migrate/20131123124730_create_edgar_page_infos.rb +15 -0
- data/db/migrate/20140116062252_create_edgar_user_groups.rb +18 -0
- data/db/migrate/20140116062327_create_edgar_user_group_users.rb +10 -0
- data/db/migrate/20140206222308_create_edgar_model_permissions.rb +14 -0
- data/db/migrate/20141209053055_rename_edgar_to_edgarj.rb +17 -0
- data/lib/core_ext/active_record.rb +123 -0
- data/lib/core_ext/resources.rb +71 -0
- data/lib/edgarj/engine.rb +64 -0
- data/lib/edgarj/enum_cache.rb +46 -0
- data/lib/edgarj/templates/rails/helper/helper.rb +10 -0
- data/lib/edgarj/templates/test_unit/scaffold/functional_test.rb +575 -0
- data/lib/edgarj/version.rb +3 -0
- data/lib/edgarj.rb +14 -0
- data/lib/generators/edgarj/popup_scaffold/USAGE +6 -0
- data/lib/generators/edgarj/popup_scaffold/popup_scaffold_generator.rb +35 -0
- data/lib/generators/edgarj/popup_scaffold/templates/controller.rb +13 -0
- data/lib/generators/edgarj/popup_scaffold/templates/functional_test.rb +197 -0
- data/lib/generators/edgarj/popup_scaffold/templates/helper.rb +9 -0
- data/lib/generators/edgarj/scaffold/USAGE +17 -0
- data/lib/generators/edgarj/scaffold/scaffold_generator.rb +40 -0
- data/lib/generators/edgarj/scaffold/templates/controller.rb +13 -0
- data/lib/tasks/edgarj_tasks.rake +32 -0
- data/lib/tasks/pakcage.rake +18 -0
- data/locale/en.yml +94 -0
- data/locale/ja.yml +100 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +21 -0
- data/test/dummy/app/assets/javascripts/authors.js +2 -0
- data/test/dummy/app/assets/stylesheets/application.css +16 -0
- data/test/dummy/app/assets/stylesheets/authors.css +4 -0
- data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/test/dummy/app/controllers/application_controller.rb +15 -0
- data/test/dummy/app/controllers/authors_controller.rb +6 -0
- data/test/dummy/app/controllers/authors_popup_controller.rb +6 -0
- data/test/dummy/app/controllers/books_controller.rb +6 -0
- data/test/dummy/app/controllers/dummy_auth_mixin.rb +36 -0
- data/test/dummy/app/decorators/models/edgarj/user_group_decorator.rb +1 -0
- data/test/dummy/app/helpers/application_helper.rb +3 -0
- data/test/dummy/app/helpers/authors_helper.rb +7 -0
- data/test/dummy/app/helpers/authors_popup_helper.rb +7 -0
- data/test/dummy/app/helpers/books_helper.rb +7 -0
- data/test/dummy/app/models/author.rb +32 -0
- data/test/dummy/app/models/book.rb +5 -0
- data/test/dummy/app/models/user.rb +13 -0
- data/test/dummy/app/views/layouts/application.html.erb +32 -0
- data/test/dummy/app/views/layouts/login.html.erb +20 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +15 -0
- data/test/dummy/config/edgarj/menu_config.rb +28 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +42 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +34 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/strong_parameter.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +26 -0
- data/test/dummy/config/routes.rb +60 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/migrate/20131107120635_create_authors.rb +9 -0
- data/test/dummy/db/migrate/20131218011851_create_books.rb +10 -0
- data/test/dummy/db/migrate/20140201000000_add_user_group_id_to_authors.rb +5 -0
- data/test/dummy/db/migrate/20140807065420_create_users.rb +10 -0
- data/test/dummy/db/schema.rb +93 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/functional/authors_controller_test.rb +631 -0
- data/test/dummy/test/functional/books_controller_test.rb +516 -0
- data/test/dummy/test/helpers/authors_helper_test.rb +4 -0
- data/test/dummy/test/unit/author_test.rb +7 -0
- data/test/dummy/test/unit/book_test.rb +7 -0
- data/test/edgar_test.rb +7 -0
- data/test/fixtures/authors.yml +32 -0
- data/test/fixtures/books.yml +56 -0
- data/test/fixtures/edgarj/model_permissions.yml +97 -0
- data/test/fixtures/edgarj/page_infos.yml +84 -0
- data/test/fixtures/edgarj/sssns.yml +38 -0
- data/test/fixtures/edgarj/user_group_users.yml +114 -0
- data/test/fixtures/edgarj/user_groups.yml +95 -0
- data/test/fixtures/users.yml +49 -0
- data/test/functional/edgarj/edgarj_controller_test.rb +24 -0
- data/test/functional/edgarj/model_permissions_controller_test.rb +554 -0
- data/test/functional/edgarj/user_group_users_controller_test.rb +567 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/support/edgarj/controller_supporter.rb +23 -0
- data/test/test_helper.rb +23 -0
- data/test/unit/edgarj/model_permission_test.rb +27 -0
- data/test/unit/edgarj/page_info_test.rb +7 -0
- data/test/unit/edgarj/sssn_test.rb +10 -0
- data/test/unit/edgarj/user_group_test.rb +32 -0
- data/test/unit/edgarj/user_group_user_test.rb +9 -0
- data/test/unit/helpers/edgarj/model_permissions_helper_test.rb +6 -0
- data/test/unit/helpers/edgarj/user_group_users_helper_test.rb +6 -0
- metadata +456 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
module Edgarj
|
2
|
+
# build map: value -> label on-the-fly
|
3
|
+
class EnumCache
|
4
|
+
include Singleton
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@enum_map = {}
|
8
|
+
|
9
|
+
# for stat
|
10
|
+
@hit = @out = @out_of_enum = 0
|
11
|
+
end
|
12
|
+
|
13
|
+
# return label of 'rec.attr', where attr is enum value.
|
14
|
+
def label(rec, attr, enum = nil)
|
15
|
+
if !enum
|
16
|
+
enum = rec.class.const_get(attr.to_s.camelize)
|
17
|
+
raise(NameError, "wrong constant name #{attr}") if !enum
|
18
|
+
end
|
19
|
+
if !@enum_map[enum]
|
20
|
+
@enum_map[enum] = {}
|
21
|
+
end
|
22
|
+
value = rec.attributes[attr.to_s]
|
23
|
+
if label = @enum_map[enum][value]
|
24
|
+
@hit += 1
|
25
|
+
label
|
26
|
+
else
|
27
|
+
member = enum.constants.detect{|m|
|
28
|
+
enum.const_get(m) == value
|
29
|
+
}
|
30
|
+
@enum_map[enum][value] =
|
31
|
+
if member
|
32
|
+
@out += 1
|
33
|
+
rec.class.human_const_name(enum, member)
|
34
|
+
else
|
35
|
+
@out_of_enum += 1
|
36
|
+
'??'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# return statistic information of hit, out, out_of_enum.
|
42
|
+
def stat
|
43
|
+
[@hit, @out, @out_of_enum]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<% model_name = class_name.singularize -%>
|
2
|
+
<% module_namespacing do -%>
|
3
|
+
module <%= class_name %>Helper
|
4
|
+
class <%= model_name %>Drawer < Edgarj::Drawer::Normal
|
5
|
+
def initialize(view_context, params, page_info, model_class = <%= model_name %>)
|
6
|
+
super
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
<% end -%>
|
@@ -0,0 +1,575 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
<% module_namespacing do -%>
|
4
|
+
# Edgarj chooses traditional testing framework(TestUnit) with
|
5
|
+
# shoulda-context and fixture rather than rspec.
|
6
|
+
#
|
7
|
+
# EdgarjController assumes authentication, model_permission, and
|
8
|
+
# user_scoped so that functional test should cover the following
|
9
|
+
# combinations:
|
10
|
+
#
|
11
|
+
# 1. methods for CRUD, clear, search, search_clear, search_save, search_load,
|
12
|
+
# csv_download, and file_download.
|
13
|
+
# 2. authenticated or not.
|
14
|
+
# 3. User has enough role (model_permission) or not.
|
15
|
+
# 4. User is in user_scoped or not.
|
16
|
+
#
|
17
|
+
# This edgarj:scaffold generated functional test just covers 1 and 2 above
|
18
|
+
# because 3 and 4 require to prepare fixtures. For the latter cases,
|
19
|
+
# skipping tests are provided.
|
20
|
+
#
|
21
|
+
# Please read the file below as a reference:
|
22
|
+
#
|
23
|
+
# edgarj/test/dummy/test/functional/authors_controller_test.rb
|
24
|
+
#
|
25
|
+
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
26
|
+
context 'root user' do
|
27
|
+
setup do
|
28
|
+
login_as(:root)
|
29
|
+
@<%= singular_table_name %> = <%= table_name %>(:one)
|
30
|
+
@pi = create_page_info(@sssn, '<%= table_name %>', <%= class_name %>)
|
31
|
+
end
|
32
|
+
|
33
|
+
should 'get index' do
|
34
|
+
get :index
|
35
|
+
assert_response :success
|
36
|
+
assert_not_nil assigns(:list)
|
37
|
+
end
|
38
|
+
|
39
|
+
should 'paginate' do
|
40
|
+
xhr :get, :index, page: 2
|
41
|
+
assert_response :success
|
42
|
+
assert_not_nil assigns(:list)
|
43
|
+
end
|
44
|
+
|
45
|
+
should 'sort' do
|
46
|
+
xhr :put, :page_info_save,
|
47
|
+
id: @pi.id,
|
48
|
+
edgarj_page_info: {
|
49
|
+
dir: 'asc',
|
50
|
+
order_by: 'created_at'
|
51
|
+
}
|
52
|
+
assert_response :success
|
53
|
+
assert_not_nil assigns(:list)
|
54
|
+
assert_equal 'asc', assigns(:page_info).dir
|
55
|
+
assert_equal 'created_at', assigns(:page_info).order_by
|
56
|
+
end
|
57
|
+
|
58
|
+
should 'create <%= singular_table_name %>' do
|
59
|
+
assert_difference('<%= class_name %>.count') do
|
60
|
+
xhr :post, :create, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
|
61
|
+
end
|
62
|
+
assert_response :success
|
63
|
+
assert assigns(:record)
|
64
|
+
end
|
65
|
+
|
66
|
+
should 'not create invalid <%= singular_table_name %>' do
|
67
|
+
skip 'not create invalid <%= singular_table_name %>'
|
68
|
+
assert_no_difference('<%= class_name %>.count') do
|
69
|
+
#xhr :post, :create, invalid resource attributes...
|
70
|
+
end
|
71
|
+
assert_response :success
|
72
|
+
assert assigns(:record)
|
73
|
+
end
|
74
|
+
|
75
|
+
should 'show <%= singular_table_name %> in HTML' do
|
76
|
+
get :show, id: <%= "@#{singular_table_name}" %>
|
77
|
+
assert_response :success
|
78
|
+
assert_not_nil assigns(:record)
|
79
|
+
end
|
80
|
+
|
81
|
+
should 'show <%= singular_table_name %> in JS' do
|
82
|
+
xhr :get, :show, id: <%= "@#{singular_table_name}" %>
|
83
|
+
assert_response :success
|
84
|
+
assert_not_nil assigns(:record)
|
85
|
+
end
|
86
|
+
|
87
|
+
should 'update <%= singular_table_name %>' do
|
88
|
+
xhr :put, :update, id: <%= "@#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
|
89
|
+
assert_response :success
|
90
|
+
assert assigns(:record)
|
91
|
+
end
|
92
|
+
|
93
|
+
should 'destroy <%= singular_table_name %>' do
|
94
|
+
assert_difference('<%= class_name %>.count', -1) do
|
95
|
+
xhr :delete, :destroy, id: <%= "@#{singular_table_name}" %>
|
96
|
+
end
|
97
|
+
assert_response :success
|
98
|
+
assert assigns(:record)
|
99
|
+
assert assigns(:list)
|
100
|
+
end
|
101
|
+
|
102
|
+
should 'clear <%= singular_table_name %>' do
|
103
|
+
assert_no_difference('<%= class_name %>.count') do
|
104
|
+
xhr :get, :clear
|
105
|
+
end
|
106
|
+
assert_response :success
|
107
|
+
assert_not_nil assigns(:record)
|
108
|
+
end
|
109
|
+
|
110
|
+
should 'csv_download <%= table_name %>' do
|
111
|
+
get :csv_download
|
112
|
+
assert_response :success
|
113
|
+
end
|
114
|
+
|
115
|
+
should 'search' do
|
116
|
+
xhr :get, :search, edgarj_search_form: {}
|
117
|
+
assert_response :success
|
118
|
+
assert assigns(:list).count >= 1
|
119
|
+
end
|
120
|
+
|
121
|
+
should 'search_clear <%= singular_table_name %>' do
|
122
|
+
xhr :get, :search_clear
|
123
|
+
assert_response :success
|
124
|
+
end
|
125
|
+
|
126
|
+
should 'search_save <%= singular_table_name %>' do
|
127
|
+
skip 'search_save'
|
128
|
+
end
|
129
|
+
|
130
|
+
should 'search_load <%= singular_table_name %>' do
|
131
|
+
skip 'search_load'
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# All of tests in this context is skipped because it is required
|
136
|
+
# to prepare read-only user.
|
137
|
+
# When complete the preparation, delete the skip lines.
|
138
|
+
context 'read-only user' do
|
139
|
+
setup do
|
140
|
+
# prepare fixtures of model_permissions, user_groups, and
|
141
|
+
# user_group_users for read-only user of the
|
142
|
+
# <%= controller_class_name %>Controller and login by him/her.
|
143
|
+
#
|
144
|
+
login_as(:<%= singular_table_name %>_reader)
|
145
|
+
@pi = create_page_info(@sssn, '<%= table_name %>', <%= class_name %>)
|
146
|
+
end
|
147
|
+
|
148
|
+
should 'get index' do
|
149
|
+
skip 'get index'
|
150
|
+
get :index
|
151
|
+
assert_response :success
|
152
|
+
assert_not_nil assigns(:list)
|
153
|
+
end
|
154
|
+
|
155
|
+
should 'paginate' do
|
156
|
+
skip 'paginate'
|
157
|
+
xhr :get, :index, page: 2
|
158
|
+
assert_response :success
|
159
|
+
assert_not_nil assigns(:list)
|
160
|
+
end
|
161
|
+
|
162
|
+
should 'sort' do
|
163
|
+
skip 'sort'
|
164
|
+
xhr :put, :page_info_save,
|
165
|
+
id: @pi.id,
|
166
|
+
edgarj_page_info: {
|
167
|
+
dir: 'asc',
|
168
|
+
order_by: 'created_at'
|
169
|
+
}
|
170
|
+
assert_response :success
|
171
|
+
assert_not_nil assigns(:list)
|
172
|
+
assert_equal 'asc', assigns(:page_info).dir
|
173
|
+
assert_equal 'created_at', assigns(:page_info).order_by
|
174
|
+
end
|
175
|
+
|
176
|
+
should 'not create <%= singular_table_name %>' do
|
177
|
+
skip 'not create <%= singular_table_name %>'
|
178
|
+
assert_no_difference('<%= class_name %>.count') do
|
179
|
+
xhr :post, :create, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
|
180
|
+
end
|
181
|
+
assert_template 'message_popup'
|
182
|
+
assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
|
183
|
+
end
|
184
|
+
|
185
|
+
should 'not create invalid <%= singular_table_name %>' do
|
186
|
+
skip 'not create invalid <%= singular_table_name %>'
|
187
|
+
assert_no_difference('<%= class_name %>.count') do
|
188
|
+
#xhr :post, :create, invalid resource attributes...
|
189
|
+
end
|
190
|
+
assert_template 'message_popup'
|
191
|
+
assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
|
192
|
+
end
|
193
|
+
|
194
|
+
should 'show <%= singular_table_name %> in HTML' do
|
195
|
+
skip 'show <%= singular_table_name %> in HTML'
|
196
|
+
get :show, id: <%= "@#{singular_table_name}" %>
|
197
|
+
assert_response :success
|
198
|
+
assert_not_nil assigns(:record)
|
199
|
+
end
|
200
|
+
|
201
|
+
should 'show <%= singular_table_name %> in JS' do
|
202
|
+
skip 'show <%= singular_table_name %> in JS'
|
203
|
+
xhr :get, :show, id: <%= "@#{singular_table_name}" %>
|
204
|
+
assert_response :success
|
205
|
+
assert_not_nil assigns(:record)
|
206
|
+
end
|
207
|
+
|
208
|
+
should 'not update <%= singular_table_name %>' do
|
209
|
+
skip 'not update <%= singular_table_name %>'
|
210
|
+
xhr :put, :update, id: <%= "@#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
|
211
|
+
assert_template 'message_popup'
|
212
|
+
assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
|
213
|
+
old_<%= singular_table_name %> = @<%= singular_table_name %>
|
214
|
+
assert_equal(
|
215
|
+
old_<%= singular_table_name %>,
|
216
|
+
@<%= singular_table_name %>.reload)
|
217
|
+
end
|
218
|
+
|
219
|
+
should 'not destroy <%= singular_table_name %>' do
|
220
|
+
skip 'not destroy <%= singular_table_name %>'
|
221
|
+
assert_no_difference('<%= class_name %>.count') do
|
222
|
+
xhr :delete, :destroy, id: <%= "@#{singular_table_name}" %>
|
223
|
+
end
|
224
|
+
assert_template 'message_popup'
|
225
|
+
assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
|
226
|
+
end
|
227
|
+
|
228
|
+
should 'clear <%= singular_table_name %>' do
|
229
|
+
skip 'clear <%= singular_table_name %>'
|
230
|
+
assert_no_difference('<%= class_name %>.count') do
|
231
|
+
xhr :get, :clear
|
232
|
+
end
|
233
|
+
assert_response :success
|
234
|
+
assert_not_nil assigns(:record)
|
235
|
+
end
|
236
|
+
|
237
|
+
should 'csv_download <%= table_name %>' do
|
238
|
+
skip 'csv_download <%= table_name %>'
|
239
|
+
get :csv_download
|
240
|
+
assert_response :success
|
241
|
+
end
|
242
|
+
|
243
|
+
should 'search' do
|
244
|
+
skip 'search <%= table_name %>'
|
245
|
+
xhr :get, :search, edgarj_search_form: {}
|
246
|
+
assert_response :success
|
247
|
+
assert assigns(:list).count >= 1
|
248
|
+
end
|
249
|
+
|
250
|
+
should 'search_clear <%= singular_table_name %>' do
|
251
|
+
skip 'search_clear <%= singular_table_name %>'
|
252
|
+
xhr :get, :search_clear
|
253
|
+
assert_response :success
|
254
|
+
end
|
255
|
+
|
256
|
+
should 'search_save <%= singular_table_name %>' do
|
257
|
+
skip 'search_save'
|
258
|
+
end
|
259
|
+
|
260
|
+
should 'search_load <%= singular_table_name %>' do
|
261
|
+
skip 'search_load'
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
# All of tests in this context is skipped because it is required
|
266
|
+
# to prepare 'permitted but user_scoped' user.
|
267
|
+
# When complete the preparation, delete the skip lines.
|
268
|
+
context 'permitted and user_scoped user' do
|
269
|
+
setup do
|
270
|
+
# prepare fixtures of model_permissions, user_groups, and
|
271
|
+
# user_group_users for permitted and user_scoped user of the
|
272
|
+
# <%= controller_class_name %>Controller and login by him/her.
|
273
|
+
#
|
274
|
+
#login_as(:permitted_n_user_scoped_on_<%= table_name %>)
|
275
|
+
#@pi = create_page_info(@sssn, '<%= table_name %>', <%= class_name %>)
|
276
|
+
|
277
|
+
@<%= singular_table_name %> = <%= table_name %>(:one)
|
278
|
+
@<%= singular_table_name %>_scoped_out = <%= table_name %>(:two)
|
279
|
+
end
|
280
|
+
|
281
|
+
should 'search 1 hit since role and user_scoped satisfy' do
|
282
|
+
skip 'search 1 hit since role and user_scoped satisfy'
|
283
|
+
xhr :get, :search, edgarj_search_form: {_id: @<%= singular_table_name %>.id}
|
284
|
+
assert_response :success
|
285
|
+
assert_equal 1, assigns(:list).count
|
286
|
+
end
|
287
|
+
|
288
|
+
should 'not search 1 hit since key is out-of-scope' do
|
289
|
+
skip 'not search 1 hit since key is out-of-scope'
|
290
|
+
xhr :get, :search, edgarj_search_form: {_id: @<%= singular_table_name %>_scoped_out.id}
|
291
|
+
assert_response :success
|
292
|
+
assert_equal 0, assigns(:list).count
|
293
|
+
end
|
294
|
+
|
295
|
+
should 'show assigned <%= singular_table_name %> in HTML' do
|
296
|
+
skip 'show assigned <%= singular_table_name %> in HTML'
|
297
|
+
get :show, id: <%= "@#{singular_table_name}" %>
|
298
|
+
assert_response :success
|
299
|
+
assert_not_nil assigns(:record)
|
300
|
+
end
|
301
|
+
|
302
|
+
should 'show assigned <%= singular_table_name %> in JS' do
|
303
|
+
skip 'show assigned <%= singular_table_name %> in JS'
|
304
|
+
xhr :get, :show, id: <%= "@#{singular_table_name}" %>
|
305
|
+
assert_response :success
|
306
|
+
assert_not_nil assigns(:record)
|
307
|
+
end
|
308
|
+
|
309
|
+
should 'not show non-assigned <%= singular_table_name %> in HTML' do
|
310
|
+
skip 'not show non-assigned <%= singular_table_name %> in HTML'
|
311
|
+
get :show, id: <%= "@#{singular_table_name}_scoped_out" %>
|
312
|
+
assert_response :redirect
|
313
|
+
assert_nil assigns(:record)
|
314
|
+
assert_equal I18n.t('edgarj.default.not_found'), flash[:error]
|
315
|
+
end
|
316
|
+
|
317
|
+
should 'not show non-assigned <%= singular_table_name %> in JS' do
|
318
|
+
skip 'not show non-assigned <%= singular_table_name %> in JS'
|
319
|
+
xhr :get, :show, id: <%= "@#{singular_table_name}_scoped_out" %>
|
320
|
+
assert_response :success
|
321
|
+
assert_nil assigns(:record)
|
322
|
+
assert_equal I18n.t('edgarj.default.not_found'), flash[:error]
|
323
|
+
end
|
324
|
+
|
325
|
+
should 'update <%= singular_table_name %>' do
|
326
|
+
skip 'update <%= singular_table_name %>'
|
327
|
+
xhr :put, :update, id: <%= "@#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
|
328
|
+
assert_response :success
|
329
|
+
assert assigns(:record)
|
330
|
+
end
|
331
|
+
|
332
|
+
should 'not update non-assigned <%= singular_table_name %>' do
|
333
|
+
skip 'not update non-assigned <%= singular_table_name %>'
|
334
|
+
xhr :put, :update, id: <%= "@#{singular_table_name}_scoped_out" %>, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
|
335
|
+
assert_nil assigns(:record)
|
336
|
+
assert_equal I18n.t('edgarj.default.not_found'), flash[:error]
|
337
|
+
old_<%= singular_table_name %> = @<%= singular_table_name %>_scoped_out
|
338
|
+
assert_equal(
|
339
|
+
old_<%= singular_table_name %>,
|
340
|
+
@<%= singular_table_name %>_scoped_out.reload)
|
341
|
+
end
|
342
|
+
|
343
|
+
should 'destroy <%= singular_table_name %>' do
|
344
|
+
skip 'destroy <%= singular_table_name %>'
|
345
|
+
assert_difference('<%= class_name %>.count', -1) do
|
346
|
+
xhr :delete, :destroy, id: <%= "@#{singular_table_name}" %>
|
347
|
+
end
|
348
|
+
assert_response :success
|
349
|
+
assert assigns(:record)
|
350
|
+
assert assigns(:list)
|
351
|
+
end
|
352
|
+
|
353
|
+
should 'not destroy non-assigned <%= singular_table_name %>' do
|
354
|
+
skip 'not destroy non-assigned <%= singular_table_name %>'
|
355
|
+
assert_no_difference('<%= class_name %>.count') do
|
356
|
+
xhr :delete, :destroy, id: <%= "@#{singular_table_name}_scoped_out" %>
|
357
|
+
end
|
358
|
+
assert_equal I18n.t('edgarj.default.not_found'), flash[:error]
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
context 'not-permitted user' do
|
363
|
+
setup do
|
364
|
+
login_as(:not_permitted)
|
365
|
+
@<%= singular_table_name %> = <%= table_name %>(:one)
|
366
|
+
end
|
367
|
+
|
368
|
+
should 'not get index' do
|
369
|
+
get :index
|
370
|
+
|
371
|
+
assert_redirected_to top_path
|
372
|
+
assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
|
373
|
+
end
|
374
|
+
|
375
|
+
should 'not paginate' do
|
376
|
+
xhr :get, :index, page: 2
|
377
|
+
|
378
|
+
assert_template 'message_popup'
|
379
|
+
assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
|
380
|
+
end
|
381
|
+
|
382
|
+
should 'not sort' do
|
383
|
+
xhr :put, :page_info_save,
|
384
|
+
id: edgarj_page_infos(:root_zip_address),
|
385
|
+
edgarj_page_info: {
|
386
|
+
dir: 'asc',
|
387
|
+
order_by: 'name'
|
388
|
+
}
|
389
|
+
assert_template 'message_popup'
|
390
|
+
assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
|
391
|
+
end
|
392
|
+
|
393
|
+
should 'not create <%= singular_table_name %>' do
|
394
|
+
assert_no_difference('<%= class_name %>.count') do
|
395
|
+
xhr :post, :create, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
|
396
|
+
end
|
397
|
+
|
398
|
+
assert_template 'message_popup'
|
399
|
+
assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
|
400
|
+
end
|
401
|
+
|
402
|
+
should 'not show <%= singular_table_name %> in HTML' do
|
403
|
+
get :show, id: @<%= singular_table_name %>
|
404
|
+
assert_redirected_to top_path
|
405
|
+
assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
|
406
|
+
end
|
407
|
+
|
408
|
+
should 'not show <%= singular_table_name %> in JS' do
|
409
|
+
xhr :get, :show, id: @<%= singular_table_name %>
|
410
|
+
|
411
|
+
assert_template 'message_popup'
|
412
|
+
assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
|
413
|
+
end
|
414
|
+
|
415
|
+
should 'not update <%= singular_table_name %>' do
|
416
|
+
xhr :put, :update, id: <%= "@#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
|
417
|
+
assert_template 'message_popup'
|
418
|
+
assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
|
419
|
+
old_<%= singular_table_name %> = @<%= singular_table_name %>
|
420
|
+
assert_equal(
|
421
|
+
old_<%= singular_table_name %>,
|
422
|
+
@<%= singular_table_name %>.reload)
|
423
|
+
end
|
424
|
+
|
425
|
+
should 'not destroy <%= singular_table_name %>' do
|
426
|
+
assert_no_difference('<%= class_name %>.count') do
|
427
|
+
xhr :delete, :destroy, id: @<%= singular_table_name %>
|
428
|
+
end
|
429
|
+
assert_template 'message_popup'
|
430
|
+
assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
|
431
|
+
end
|
432
|
+
|
433
|
+
should 'not clear' do
|
434
|
+
assert_no_difference('<%= class_name %>.count') do
|
435
|
+
xhr :get, :clear
|
436
|
+
end
|
437
|
+
|
438
|
+
assert_template 'message_popup'
|
439
|
+
assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
|
440
|
+
end
|
441
|
+
|
442
|
+
should 'not csv_download' do
|
443
|
+
get :csv_download
|
444
|
+
|
445
|
+
assert_redirected_to top_path
|
446
|
+
assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
|
447
|
+
end
|
448
|
+
|
449
|
+
should 'not search' do
|
450
|
+
xhr :get, :search, edgarj_search_form: {_id: @<%= singular_table_name %>.id}
|
451
|
+
|
452
|
+
assert_template 'message_popup'
|
453
|
+
assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
|
454
|
+
end
|
455
|
+
|
456
|
+
should 'not search_clear' do
|
457
|
+
xhr :get, :search_clear
|
458
|
+
|
459
|
+
assert_template 'message_popup'
|
460
|
+
assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
|
461
|
+
end
|
462
|
+
|
463
|
+
should 'not search_save' do
|
464
|
+
skip 'search_save'
|
465
|
+
end
|
466
|
+
|
467
|
+
should 'not search_load' do
|
468
|
+
skip 'search_load'
|
469
|
+
end
|
470
|
+
|
471
|
+
# test Edgarj::AuthenticationMixin
|
472
|
+
|
473
|
+
should 'current_user' do
|
474
|
+
get :index
|
475
|
+
assert_equal users(:not_permitted), @controller.send(:current_user)
|
476
|
+
end
|
477
|
+
end
|
478
|
+
|
479
|
+
context 'not-login' do
|
480
|
+
setup do
|
481
|
+
@<%= singular_table_name %> = <%= table_name %>(:one)
|
482
|
+
end
|
483
|
+
|
484
|
+
should 'not get index' do
|
485
|
+
get :index
|
486
|
+
assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
|
487
|
+
end
|
488
|
+
|
489
|
+
should 'not paginate' do
|
490
|
+
xhr :get, :index, page: 2
|
491
|
+
assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
|
492
|
+
end
|
493
|
+
|
494
|
+
should 'not sort' do
|
495
|
+
xhr :put, :page_info_save,
|
496
|
+
# ensure what happens when not-login user puts with
|
497
|
+
# current edgarj_page_info-id
|
498
|
+
id: edgarj_page_infos(:root_zip_address),
|
499
|
+
edgarj_page_info: {
|
500
|
+
dir: 'asc',
|
501
|
+
order_by: 'name'
|
502
|
+
}
|
503
|
+
assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
|
504
|
+
end
|
505
|
+
|
506
|
+
should 'not create <%= singular_table_name %>' do
|
507
|
+
assert_no_difference('<%= class_name %>.count') do
|
508
|
+
xhr :post, :create, <%= singular_table_name %>: { name: @<%= singular_table_name %>.name }
|
509
|
+
end
|
510
|
+
assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
|
511
|
+
end
|
512
|
+
|
513
|
+
should 'not create <%= singular_table_name %> invalid' do
|
514
|
+
assert_no_difference('<%= class_name %>.count') do
|
515
|
+
xhr :post, :create, <%= singular_table_name %>: { name: nil }
|
516
|
+
end
|
517
|
+
assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
|
518
|
+
end
|
519
|
+
|
520
|
+
should 'not show <%= singular_table_name %> in HTML' do
|
521
|
+
get :show, id: @<%= singular_table_name %>
|
522
|
+
assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
|
523
|
+
end
|
524
|
+
|
525
|
+
should 'not show <%= singular_table_name %> in JS' do
|
526
|
+
xhr :get, :show, id: @<%= singular_table_name %>
|
527
|
+
assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
|
528
|
+
end
|
529
|
+
|
530
|
+
should 'not update <%= singular_table_name %>' do
|
531
|
+
assert_no_difference('<%= class_name %>.count') do
|
532
|
+
xhr :put, :update, id: @<%= singular_table_name %>, <%= singular_table_name %>: { name: @<%= singular_table_name %>.name }
|
533
|
+
end
|
534
|
+
assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
|
535
|
+
end
|
536
|
+
|
537
|
+
should 'not destroy <%= singular_table_name %>' do
|
538
|
+
assert_no_difference('<%= class_name %>.count') do
|
539
|
+
xhr :delete, :destroy, id: @<%= singular_table_name %>
|
540
|
+
end
|
541
|
+
assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
|
542
|
+
end
|
543
|
+
|
544
|
+
should 'not clear' do
|
545
|
+
assert_no_difference('<%= class_name %>.count') do
|
546
|
+
xhr :get, :clear
|
547
|
+
end
|
548
|
+
assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
|
549
|
+
end
|
550
|
+
|
551
|
+
should 'not csv_download' do
|
552
|
+
get :csv_download
|
553
|
+
assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
|
554
|
+
end
|
555
|
+
|
556
|
+
should 'not search' do
|
557
|
+
xhr :get, :search, edgarj_search_form: {_id: <%= table_name %>(:one).id}
|
558
|
+
assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
|
559
|
+
end
|
560
|
+
|
561
|
+
should 'not search_clear' do
|
562
|
+
xhr :get, :search_clear
|
563
|
+
assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
|
564
|
+
end
|
565
|
+
|
566
|
+
should 'not search_save' do
|
567
|
+
skip 'search_save'
|
568
|
+
end
|
569
|
+
|
570
|
+
should 'not search_load' do
|
571
|
+
skip 'search_load'
|
572
|
+
end
|
573
|
+
end
|
574
|
+
end
|
575
|
+
<% end -%>
|
data/lib/edgarj.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "edgarj/engine"
|
2
|
+
|
3
|
+
module Edgarj
|
4
|
+
class EdgarjError < StandardError; end
|
5
|
+
class NoPopupTarget < EdgarjError; end
|
6
|
+
|
7
|
+
LINES_PER_PAGE = [2, 5, 10,20,50,100,200].freeze
|
8
|
+
LIST_TEXT_MAX_LEN = 20
|
9
|
+
|
10
|
+
# ActiveRecord::Fixtures.identify へのショートカット
|
11
|
+
def self.label(label)
|
12
|
+
ActiveRecord::Fixtures.identify(label)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Edgarj
|
4
|
+
class PopupScaffoldGenerator < Rails::Generators::NamedBase
|
5
|
+
include Rails::Generators::ResourceHelpers
|
6
|
+
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
|
9
|
+
def add_edgarj_routes
|
10
|
+
route "edgarj_popup_resources :#{file_name.pluralize}_popup"
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_controller_files
|
14
|
+
template 'controller.rb', File.join('app/controllers',
|
15
|
+
class_path, "#{controller_file_name}_popup_controller.rb")
|
16
|
+
end
|
17
|
+
|
18
|
+
=begin
|
19
|
+
hook_for :test_framework, as: :popup_scaffold
|
20
|
+
hook_for :helper, in: :rails, as: :popup_scaffold do |invoked|
|
21
|
+
invoke invoked, [ controller_name ]
|
22
|
+
end
|
23
|
+
=end
|
24
|
+
|
25
|
+
def create_test
|
26
|
+
template 'functional_test.rb', File.join('test/functional',
|
27
|
+
class_path, "#{controller_file_name}_popup_controller_test.rb")
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_helper
|
31
|
+
template 'helper.rb', File.join('app/helpers',
|
32
|
+
class_path, "#{controller_file_name}_popup_helper.rb")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|