edgarj 0.01.21 → 0.01.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 317f70ed3709d6a35763886431d0f77ff2ca7e3d
4
- data.tar.gz: 14fdce26cd0837305697830c4151bf6ae9f5106c
3
+ metadata.gz: b0eda9922434a94f760aad1bd2abc1a1dfc0f916
4
+ data.tar.gz: 7f6c4d0e0184a2f8744558a4ef0bbf965364c63b
5
5
  SHA512:
6
- metadata.gz: 4363e3aea59fefe7e6705b9851239d0a64819ff13aaa516fc0f525d4ef2fa06d6bbd4da3dbc2351e7657e17826e38f131d7374410e6669fd463668d3cd72e552
7
- data.tar.gz: 0a4b1b3ae101acf955e47bdae2afc3374b894bfa8f97c58a404d28a5b0b479b4b435b5a1307dcd44cb3ac820bd9d939c69194ca3179854b016e07ab326ebc869
6
+ metadata.gz: 2fd098c60063a214c6af73a74aabae7cd36018560edbc77aa86bb26dd7100163d6a82d92540a5ef5e1d88a93e1919fba026339954a96f2d5d6d96132ca3eee1b
7
+ data.tar.gz: 937b28340f7e2ce9477a2c032114fc53a1dc5d43193d88c8bf1187a2d6bc7f1f532a4e2a6d514b127ae4c00efc848ae8105771e796dc97655232808d7458b9c8
File without changes
@@ -1,8 +1,13 @@
1
1
  module Edgarj
2
2
  module Drawer
3
3
  # 'Mediator' to draw list and form of the model on the view.
4
+ #
5
+ # This collaborate with the following sub classes:
6
+ # Edgarj::ListDrawer::Normal:: for list
7
+ # Edgarj::FormDrawer::Base:: for data entry form
8
+ # Edgarj::FormDrawer::Search:: for search form
4
9
  class Base
5
- attr_accessor :vc
10
+ attr_accessor :vc, :params, :model, :page_info
6
11
 
7
12
  # * options
8
13
  # * list_drawer_options - options for Edgarj::ListDrawer::Normal
@@ -109,45 +114,6 @@ module Edgarj
109
114
  id_target: popup_field.id_target)
110
115
  end
111
116
 
112
- # draw sort link on list column header
113
- #
114
- # === INPUTS
115
- # col:: column data
116
- # options:: options to url_for
117
- def draw_sort(col, options={})
118
- label = @model.human_attribute_name(col.name)
119
- dir = 'asc'
120
- if @page_info.order_by == fullname(col)
121
- # toggle direction
122
- if @page_info.dir == 'asc' || @page_info.dir.blank?
123
- label += '▲'
124
- dir = 'desc'
125
- else
126
- label += '▼'
127
- end
128
- end
129
- @vc.link_to(label,
130
- {
131
- :controller => @params[:controller],
132
- :action => 'page_info_save',
133
- :id => @page_info.id,
134
- 'edgarj_page_info[order_by]' => fullname(col),
135
- 'edgarj_page_info[dir]' => dir
136
- }.merge(options),
137
- :remote => true,
138
- :method => :put)
139
- end
140
-
141
- # draw list column header for both usual list and popup list
142
- def draw_list_column_header(col, options={})
143
- parent = @model.belongs_to_AR(col)
144
- if parent then
145
- @vc.draw_belongs_to_label_sub(@model, col.name, parent)
146
- else
147
- draw_sort(col, options)
148
- end
149
- end
150
-
151
117
  def list_drawer_class
152
118
  Edgarj::ListDrawer::Normal
153
119
  end
@@ -162,9 +128,7 @@ module Edgarj
162
128
  @vc.content_tag(:tr) do
163
129
  ''.html_safe.tap do |result|
164
130
  for col in columns_for(list_columns) do
165
- result << @vc.content_tag(:th) do
166
- draw_list_column_header(col)
167
- end
131
+ result << d.draw_column_header(col)
168
132
  end
169
133
  end
170
134
  end +
File without changes
@@ -19,9 +19,7 @@ module Edgarj
19
19
  @vc.content_tag(:tr) do
20
20
  ''.html_safe.tap do |result|
21
21
  for col in columns_for(list_columns) do
22
- result << @vc.content_tag(:th) do
23
- draw_list_column_header(col, id_target: @params[:id_target])
24
- end
22
+ result << d.draw_column_header(col, id_target: @params[:id_target])
25
23
  end
26
24
  end
27
25
  end +
@@ -8,6 +8,7 @@ module Edgarj
8
8
  class Base
9
9
  include ERB::Util
10
10
 
11
+ # * drawer - Edgarj::Drawer::Base object
11
12
  # * options
12
13
  # * namespace - namespace for path (ex: :admin)
13
14
  #
@@ -22,6 +23,12 @@ module Edgarj
22
23
  @belongs_to_link = false # doesn't make link on belongs_to
23
24
  end
24
25
 
26
+ def draw_column_header(col, options={})
27
+ @vc.content_tag(:th) do
28
+ draw_column_header_sub(col, options)
29
+ end
30
+ end
31
+
25
32
  def draw_column(rec, col)
26
33
  @parent_rec = rec.belongs_to_AR(col)
27
34
  @vc.content_tag(:td, td_options(rec, col)) do
@@ -85,6 +92,44 @@ module Edgarj
85
92
  s.join('')
86
93
  end
87
94
 
95
+ # draw sort link on list column header
96
+ #
97
+ # === INPUTS
98
+ # col:: column data
99
+ # options:: options to url_for
100
+ def draw_sort(col, options={})
101
+ label = @drawer.model.human_attribute_name(col.name)
102
+ dir = 'asc'
103
+ if @drawer.page_info.order_by == @drawer.fullname(col)
104
+ # toggle direction
105
+ if @drawer.page_info.dir == 'asc' || @drawer.page_info.dir.blank?
106
+ label += '▲'
107
+ dir = 'desc'
108
+ else
109
+ label += '▼'
110
+ end
111
+ end
112
+ @vc.link_to(label,
113
+ {
114
+ :controller => @drawer.params[:controller],
115
+ :action => 'page_info_save',
116
+ :id => @drawer.page_info.id,
117
+ 'edgarj_page_info[order_by]' => @drawer.fullname(col),
118
+ 'edgarj_page_info[dir]' => dir
119
+ }.merge(options),
120
+ :remote => true,
121
+ :method => :put)
122
+ end
123
+
124
+ # draw list column header for both usual list and popup list
125
+ def draw_column_header_sub(col, options={})
126
+ parent = @drawer.model.belongs_to_AR(col)
127
+ if parent then
128
+ @vc.draw_belongs_to_label_sub(@drawer.model, col.name, parent)
129
+ else
130
+ draw_sort(col, options)
131
+ end
132
+ end
88
133
 
89
134
  # draw rec.col other than 'belongs_to'
90
135
  # 1. DateTime format is YYYY-MM-DD hh:mm:ss.
@@ -1,3 +1,3 @@
1
1
  module Edgarj
2
- VERSION = "0.01.21"
2
+ VERSION = "0.01.22"
3
3
  end
@@ -13,6 +13,7 @@ class <%= controller_class_name %>PopupControllerTest < ActionController::TestCa
13
13
  id_target: "PARENT_MODEL_DOM_ID"
14
14
  assert_response :success
15
15
  assert_not_nil assigns(:list)
16
+ assert_no_app_error
16
17
  end
17
18
 
18
19
  should 'paginate' do
@@ -20,6 +21,7 @@ class <%= controller_class_name %>PopupControllerTest < ActionController::TestCa
20
21
  id_target: "PARENT_MODEL_DOM_ID"
21
22
  assert_response :success
22
23
  assert_not_nil assigns(:list)
24
+ assert_no_app_error
23
25
  end
24
26
 
25
27
  should 'sort' do
@@ -33,6 +35,7 @@ class <%= controller_class_name %>PopupControllerTest < ActionController::TestCa
33
35
  assert_not_nil assigns(:list)
34
36
  assert_equal 'asc', assigns(:page_info).dir
35
37
  assert_equal 'created_at', assigns(:page_info).order_by
38
+ assert_no_app_error
36
39
  end
37
40
 
38
41
  should 'search' do
@@ -40,6 +43,7 @@ class <%= controller_class_name %>PopupControllerTest < ActionController::TestCa
40
43
  id_target: "PARENT_MODEL_DOM_ID"
41
44
  assert_response :success
42
45
  assert assigns(:list).count >= 1
46
+ assert_no_app_error
43
47
  end
44
48
  end
45
49
 
@@ -62,6 +66,7 @@ class <%= controller_class_name %>PopupControllerTest < ActionController::TestCa
62
66
  id_target: "PARENT_MODEL_DOM_ID"
63
67
  assert_response :success
64
68
  assert_not_nil assigns(:list)
69
+ assert_no_app_error
65
70
  end
66
71
 
67
72
  should 'paginate' do
@@ -70,6 +75,7 @@ class <%= controller_class_name %>PopupControllerTest < ActionController::TestCa
70
75
  id_target: "PARENT_MODEL_DOM_ID"
71
76
  assert_response :success
72
77
  assert_not_nil assigns(:list)
78
+ assert_no_app_error
73
79
  end
74
80
 
75
81
  should 'sort' do
@@ -84,6 +90,7 @@ class <%= controller_class_name %>PopupControllerTest < ActionController::TestCa
84
90
  assert_not_nil assigns(:list)
85
91
  assert_equal 'asc', assigns(:page_info).dir
86
92
  assert_equal 'created_at', assigns(:page_info).order_by
93
+ assert_no_app_error
87
94
  end
88
95
 
89
96
  should 'search' do
@@ -92,6 +99,7 @@ class <%= controller_class_name %>PopupControllerTest < ActionController::TestCa
92
99
  id_target: "PARENT_MODEL_DOM_ID"
93
100
  assert_response :success
94
101
  assert assigns(:list).count >= 1
102
+ assert_no_app_error
95
103
  end
96
104
  end
97
105
 
@@ -114,6 +122,7 @@ class <%= controller_class_name %>PopupControllerTest < ActionController::TestCa
114
122
  id_target: "PARENT_MODEL_DOM_ID"
115
123
  assert_response :success
116
124
  assert_equal 1, assigns(:list).count
125
+ assert_no_app_error
117
126
  end
118
127
 
119
128
  should 'not search since key is out-of-scope' do
@@ -122,6 +131,7 @@ class <%= controller_class_name %>PopupControllerTest < ActionController::TestCa
122
131
  id_target: "PARENT_MODEL_DOM_ID"
123
132
  assert_response :success
124
133
  assert_equal 0, assigns(:list).count
134
+ assert_no_app_error
125
135
  end
126
136
  end
127
137
 
@@ -0,0 +1,205 @@
1
+ require 'test_helper'
2
+
3
+ class AuthorsPopupControllerTest < ActionController::TestCase
4
+ context 'root user' do
5
+ setup do
6
+ login_as(:root)
7
+ @pi = create_page_info(@sssn, 'authors', Author)
8
+ end
9
+
10
+ should 'get index' do
11
+ xhr :get, :index,
12
+ id_target: "PARENT_MODEL_DOM_ID"
13
+ assert_response :success
14
+ assert_not_nil assigns(:list)
15
+ assert_no_app_error
16
+ end
17
+
18
+ should 'paginate' do
19
+ xhr :get, :index, page: 2,
20
+ id_target: "PARENT_MODEL_DOM_ID"
21
+ assert_response :success
22
+ assert_not_nil assigns(:list)
23
+ assert_no_app_error
24
+ end
25
+
26
+ should 'sort' do
27
+ xhr :put, :page_info_save, id: @pi.id,
28
+ id_target: "PARENT_MODEL_DOM_ID",
29
+ edgarj_page_info: {
30
+ dir: 'asc',
31
+ order_by: 'created_at'
32
+ }
33
+ assert_response :success
34
+ assert_not_nil assigns(:list)
35
+ assert_equal 'asc', assigns(:page_info).dir
36
+ assert_equal 'created_at', assigns(:page_info).order_by
37
+ assert_no_app_error
38
+ end
39
+
40
+ should 'search' do
41
+ xhr :get, :search, edgarj_search_form: {},
42
+ id_target: "PARENT_MODEL_DOM_ID"
43
+ assert_response :success
44
+ assert assigns(:list).count >= 1
45
+ assert_no_app_error
46
+ end
47
+ end
48
+
49
+ # All of tests in this context is skipped because it is required
50
+ # to prepare read-only user.
51
+ # When complete the preparation, delete the skip lines.
52
+ context 'read-only user' do
53
+ setup do
54
+ # prepare fixtures of model_permissions, user_groups, and
55
+ # user_group_users for read-only user of the
56
+ # AuthorsController and login by him/her.
57
+ #
58
+ login_as(:author_reader)
59
+ @pi = create_page_info(@sssn, 'authors', Author)
60
+ end
61
+
62
+ should 'get index' do
63
+ skip 'get index'
64
+ xhr :get, :index,
65
+ id_target: "PARENT_MODEL_DOM_ID"
66
+ assert_response :success
67
+ assert_not_nil assigns(:list)
68
+ assert_no_app_error
69
+ end
70
+
71
+ should 'paginate' do
72
+ skip 'get paginate'
73
+ xhr :get, :index, page: 2,
74
+ id_target: "PARENT_MODEL_DOM_ID"
75
+ assert_response :success
76
+ assert_not_nil assigns(:list)
77
+ assert_no_app_error
78
+ end
79
+
80
+ should 'sort' do
81
+ skip 'sort'
82
+ xhr :put, :page_info_save, id: @pi.id,
83
+ id_target: "PARENT_MODEL_DOM_ID",
84
+ edgarj_page_info: {
85
+ dir: 'asc',
86
+ order_by: 'created_at'
87
+ }
88
+ assert_response :success
89
+ assert_not_nil assigns(:list)
90
+ assert_equal 'asc', assigns(:page_info).dir
91
+ assert_equal 'created_at', assigns(:page_info).order_by
92
+ assert_no_app_error
93
+ end
94
+
95
+ should 'search' do
96
+ skip 'search'
97
+ xhr :get, :search, edgarj_search_form: {},
98
+ id_target: "PARENT_MODEL_DOM_ID"
99
+ assert_response :success
100
+ assert assigns(:list).count >= 1
101
+ assert_no_app_error
102
+ end
103
+ end
104
+
105
+ # All of tests in this context is skipped because it is required
106
+ # to prepare 'permitted but user_scoped' user.
107
+ # When complete the preparation, delete the skip lines.
108
+ context 'permitted and user_scoped user' do
109
+ setup do
110
+ # prepare fixtures of model_permissions, user_groups, and
111
+ # user_group_users for read-only user of the
112
+ #login_as(:permitted_n_user_scoped_on_authors)
113
+ #@pi = create_page_info(@sssn, 'authors', Author)
114
+ @author = authors(:m_polanyi)
115
+ @author_scoped_out = authors(:t_nangou)
116
+ end
117
+
118
+ should 'search since role and user_scoped satisfy' do
119
+ skip 'search since role and user_scoped satisfy'
120
+ xhr :get, :search, edgarj_search_form: {col: 'id', val: @author.id},
121
+ id_target: "PARENT_MODEL_DOM_ID"
122
+ assert_response :success
123
+ assert_equal 1, assigns(:list).count
124
+ assert_no_app_error
125
+ end
126
+
127
+ should 'not search since key is out-of-scope' do
128
+ skip 'not search since key is out-of-scope'
129
+ xhr :get, :search, edgarj_search_form: {col: 'id', val: @author_scoped_out.id},
130
+ id_target: "PARENT_MODEL_DOM_ID"
131
+ assert_response :success
132
+ assert_equal 0, assigns(:list).count
133
+ assert_no_app_error
134
+ end
135
+ end
136
+
137
+ context 'not-permitted user' do
138
+ setup do
139
+ login_as(:not_permitted)
140
+ @pi = create_page_info(@sssn, 'authors', Author)
141
+ end
142
+
143
+ should 'not get index' do
144
+ xhr :get, :index,
145
+ id_target: "PARENT_MODEL_DOM_ID"
146
+ assert_template 'message_popup'
147
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
148
+ end
149
+
150
+ should 'not paginate' do
151
+ xhr :get, :index, page: 2,
152
+ id_target: "PARENT_MODEL_DOM_ID"
153
+ assert_template 'message_popup'
154
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
155
+ end
156
+
157
+ should 'not sort' do
158
+ xhr :put, :page_info_save, id: @pi.id,
159
+ id_target: "PARENT_MODEL_DOM_ID",
160
+ edgarj_page_info: {
161
+ dir: 'asc',
162
+ order_by: 'created_at'
163
+ }
164
+ assert_template 'message_popup'
165
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
166
+ end
167
+
168
+ should 'not search' do
169
+ xhr :get, :search, edgarj_search_form: {},
170
+ id_target: "PARENT_MODEL_DOM_ID"
171
+ assert_template 'message_popup'
172
+ assert_equal I18n.t('edgarj.default.permission_no'), flash[:error]
173
+ end
174
+ end
175
+
176
+ context 'not-login' do
177
+ should 'not get index' do
178
+ xhr :get, :index,
179
+ id_target: "PARENT_MODEL_DOM_ID"
180
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
181
+ end
182
+
183
+ should 'not paginate' do
184
+ xhr :get, :index, page: 2,
185
+ id_target: "PARENT_MODEL_DOM_ID"
186
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
187
+ end
188
+
189
+ should 'not sort' do
190
+ xhr :put, :page_info_save, id: 0,
191
+ id_target: "PARENT_MODEL_DOM_ID",
192
+ edgarj_page_info: {
193
+ dir: 'asc',
194
+ order_by: 'created_at'
195
+ }
196
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
197
+ end
198
+
199
+ should 'not search' do
200
+ xhr :get, :search, edgarj_search_form: {},
201
+ id_target: "PARENT_MODEL_DOM_ID"
202
+ assert_equal I18n.t('edgarj.default.login_failed'), flash[:error]
203
+ end
204
+ end
205
+ end
@@ -20,4 +20,14 @@ module Edgarj::ControllerSupporter
20
20
  pi.save!
21
21
  pi
22
22
  end
23
+
24
+ # error is raised during controller-action
25
+ def assert_app_error(format = :html)
26
+ assert_not_nil flash[:error]
27
+ end
28
+
29
+ # error is not raised during controller-action
30
+ def assert_no_app_error
31
+ assert_nil flash[:error]
32
+ end
23
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edgarj
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.01.21
4
+ version: 0.01.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fuminori Ido
@@ -213,6 +213,10 @@ files:
213
213
  - app/controllers/edgarj/user_groups_popup_controller.rb
214
214
  - app/helpers/edgarj/assoc_helper.rb
215
215
  - app/helpers/edgarj/common_helper.rb
216
+ - app/helpers/edgarj/drawer.rb
217
+ - app/helpers/edgarj/drawer/base.rb
218
+ - app/helpers/edgarj/drawer/normal.rb
219
+ - app/helpers/edgarj/drawer/popup.rb
216
220
  - app/helpers/edgarj/edgarj_helper.rb
217
221
  - app/helpers/edgarj/field_helper.rb
218
222
  - app/helpers/edgarj/form_drawer.rb
@@ -226,10 +230,6 @@ files:
226
230
  - app/helpers/edgarj/user_groups_helper.rb
227
231
  - app/helpers/edgarj/user_groups_popup_helper.rb
228
232
  - app/models/edgarj.rb
229
- - app/models/edgarj/drawer.rb
230
- - app/models/edgarj/drawer/base.rb
231
- - app/models/edgarj/drawer/normal.rb
232
- - app/models/edgarj/drawer/popup.rb
233
233
  - app/models/edgarj/model_permission.rb
234
234
  - app/models/edgarj/page_info.rb
235
235
  - app/models/edgarj/search.rb
@@ -352,6 +352,7 @@ files:
352
352
  - test/dummy/public/favicon.ico
353
353
  - test/dummy/script/rails
354
354
  - test/dummy/test/functional/authors_controller_test.rb
355
+ - test/dummy/test/functional/authors_popup_controller_test.rb
355
356
  - test/dummy/test/functional/books_controller_test.rb
356
357
  - test/dummy/test/helpers/authors_helper_test.rb
357
358
  - test/dummy/test/unit/author_test.rb
@@ -471,6 +472,7 @@ test_files:
471
472
  - test/dummy/test/unit/rails_config_test.rb
472
473
  - test/dummy/test/unit/book_test.rb
473
474
  - test/dummy/test/functional/books_controller_test.rb
475
+ - test/dummy/test/functional/authors_popup_controller_test.rb
474
476
  - test/dummy/test/functional/authors_controller_test.rb
475
477
  - test/dummy/test/helpers/authors_helper_test.rb
476
478
  - test/dummy/script/rails