much-rails 0.2.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/much-rails/action.rb +16 -7
- data/lib/much-rails/action/base_router.rb +19 -1
- data/lib/much-rails/action/controller.rb +12 -10
- data/lib/much-rails/action/router.rb +32 -13
- data/lib/much-rails/input_value.rb +1 -1
- data/lib/much-rails/version.rb +1 -1
- data/much-rails.gemspec +1 -1
- data/test/support/actions/show.rb +2 -0
- data/test/support/fake_action_controller.rb +17 -6
- data/test/unit/action/base_router_tests.rb +24 -0
- data/test/unit/action/controller_tests.rb +25 -9
- data/test/unit/action/router_tests.rb +23 -17
- data/test/unit/action/unprocessable_entity_result_tests.rb +1 -1
- data/test/unit/action_tests.rb +74 -10
- data/test/unit/change_action_tests.rb +7 -50
- data/test/unit/destroy_action_tests.rb +1 -7
- data/test/unit/input_value_tests.rb +10 -1
- data/test/unit/save_action_tests.rb +1 -7
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba7d46f07c2592e152fe836a0cff5a7bf8061e9f531aac1c6a748f1365cc383b
|
4
|
+
data.tar.gz: 19e41c6e470a0021b6b78ea9c7eff7e6e530758d0522a591b4f8623b610f9fa2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37bdf6aa9a624f270cd53e5ba22f3e400f331b9b91c29aed2c6169627350f9c49e2f929ff6b9bc83665c789953559f67f546c11fd4cc9660814b46f61bfb2bb9
|
7
|
+
data.tar.gz: eb78925cf707aef2f6484665963da6dee38f495cad04de680f7ea349292eae41b77bdd36f014b05a2e5fcda48e8c8d03b23485f60786020100794f4d1cb3c15f
|
data/lib/much-rails/action.rb
CHANGED
@@ -31,7 +31,7 @@ module MuchRails::Action
|
|
31
31
|
|
32
32
|
add_config :much_rails_action
|
33
33
|
|
34
|
-
attr_reader :params, :
|
34
|
+
attr_reader :params, :request, :errors
|
35
35
|
end
|
36
36
|
|
37
37
|
mixin_class_methods do
|
@@ -107,17 +107,13 @@ module MuchRails::Action
|
|
107
107
|
|
108
108
|
def default_action_template_name
|
109
109
|
@default_action_template_name ||=
|
110
|
-
to_s
|
111
|
-
.remove(/\A#{MuchRails.config.action.namespace}/)
|
112
|
-
.tableize
|
113
|
-
.singularize
|
110
|
+
to_s.remove(/\A#{MuchRails.config.action.namespace}/).underscore
|
114
111
|
end
|
115
112
|
end
|
116
113
|
|
117
114
|
mixin_instance_methods do
|
118
|
-
def initialize(params: nil,
|
115
|
+
def initialize(params: nil, request: nil)
|
119
116
|
@params = params.to_h.with_indifferent_access
|
120
|
-
@current_user = current_user
|
121
117
|
@request = request
|
122
118
|
@errors = Hash.new{ |hash, key| hash[key] = [] }
|
123
119
|
end
|
@@ -153,8 +149,17 @@ module MuchRails::Action
|
|
153
149
|
@much_rails_successful_action
|
154
150
|
end
|
155
151
|
|
152
|
+
def controller_session=(value)
|
153
|
+
@controller_session = value
|
154
|
+
end
|
155
|
+
|
156
156
|
private
|
157
157
|
|
158
|
+
def controller_session
|
159
|
+
@controller_session ||=
|
160
|
+
request&.env&.[]("action_controller.instance")&.session
|
161
|
+
end
|
162
|
+
|
158
163
|
def default_action_success_result
|
159
164
|
MuchRails::Action::HeadResult.new(:ok)
|
160
165
|
end
|
@@ -257,6 +262,10 @@ module MuchRails::Action
|
|
257
262
|
template: template || default_action_template_name,
|
258
263
|
}.merge(**kargs)
|
259
264
|
|
265
|
+
if view_model&.respond_to?(:much_rails_action=)
|
266
|
+
view_model.much_rails_action = self
|
267
|
+
end
|
268
|
+
|
260
269
|
@much_rails_action_result =
|
261
270
|
MuchRails::Action::RenderResult.new(view_model, *args, **result_kargs)
|
262
271
|
halt
|
@@ -149,7 +149,7 @@ class MuchRails::Action::BaseRouter
|
|
149
149
|
# get "/new", "Root::New"
|
150
150
|
# post "/", "Root::Create"
|
151
151
|
# get "/edit", "Root::Edit"
|
152
|
-
# put "/", "Root::
|
152
|
+
# put "/", "Root::Upsert"
|
153
153
|
# patch "/", "Root::Update"
|
154
154
|
# get "/remove", "Root::Remove"
|
155
155
|
# delete "/", "Root::Destroy"
|
@@ -301,6 +301,14 @@ class MuchRails::Action::BaseRouter
|
|
301
301
|
def constraints_lambda
|
302
302
|
request_type.constraints_lambda
|
303
303
|
end
|
304
|
+
|
305
|
+
def class_constant
|
306
|
+
@class_constant ||= class_name.constantize
|
307
|
+
end
|
308
|
+
|
309
|
+
def format
|
310
|
+
class_constant.format
|
311
|
+
end
|
304
312
|
end
|
305
313
|
|
306
314
|
class URLSet
|
@@ -460,6 +468,16 @@ class MuchRails::Action::BaseRouter
|
|
460
468
|
!@default_action_class_name.nil?
|
461
469
|
end
|
462
470
|
|
471
|
+
def default_action_class_constant
|
472
|
+
return unless has_default_action_class_name?
|
473
|
+
|
474
|
+
@default_action_class_constant ||= default_action_class_name.constantize
|
475
|
+
end
|
476
|
+
|
477
|
+
def default_action_format
|
478
|
+
default_action_class_constant&.format
|
479
|
+
end
|
480
|
+
|
463
481
|
def ==(other)
|
464
482
|
return super unless other.is_a?(self.class)
|
465
483
|
|
@@ -9,30 +9,31 @@ module MuchRails::Action; end
|
|
9
9
|
# MuchRails::Action::Controller defines the behaviors for controllers processing
|
10
10
|
# MuchRails::Actions.
|
11
11
|
module MuchRails::Action::Controller
|
12
|
-
DEFAULT_ACTION_CLASS_FORMAT = :any
|
13
|
-
|
14
12
|
include MuchRails::Mixin
|
15
13
|
|
14
|
+
def self.DEFAULT_ACTION_CLASS_FORMAT
|
15
|
+
:any
|
16
|
+
end
|
17
|
+
|
16
18
|
mixin_included do
|
17
19
|
attr_reader :much_rails_action_class
|
18
20
|
|
19
|
-
|
21
|
+
prepend_before_action(
|
20
22
|
:require_much_rails_action_class,
|
21
|
-
only: MuchRails::Action::Router
|
23
|
+
only: MuchRails::Action::Router.CONTROLLER_CALL_ACTION_METHOD_NAME,
|
22
24
|
)
|
23
25
|
before_action :permit_all_much_rails_action_params
|
24
26
|
end
|
25
27
|
|
26
28
|
mixin_instance_methods do
|
27
29
|
define_method(
|
28
|
-
MuchRails::Action::Router
|
30
|
+
MuchRails::Action::Router.CONTROLLER_CALL_ACTION_METHOD_NAME,
|
29
31
|
) do
|
30
32
|
respond_to do |format|
|
31
33
|
format.public_send(much_rails_action_class_format) do
|
32
34
|
result =
|
33
35
|
much_rails_action_class.call(
|
34
36
|
params: much_rails_action_params,
|
35
|
-
current_user: current_user,
|
36
37
|
request: request,
|
37
38
|
)
|
38
39
|
instance_exec(result, &result.execute_block)
|
@@ -41,7 +42,7 @@ module MuchRails::Action::Controller
|
|
41
42
|
end
|
42
43
|
|
43
44
|
define_method(
|
44
|
-
MuchRails::Action::Router
|
45
|
+
MuchRails::Action::Router.CONTROLLER_NOT_FOUND_METHOD_NAME,
|
45
46
|
) do
|
46
47
|
respond_to do |format|
|
47
48
|
format.html do
|
@@ -51,11 +52,12 @@ module MuchRails::Action::Controller
|
|
51
52
|
end
|
52
53
|
|
53
54
|
def much_rails_action_class_name
|
54
|
-
"::#{params[MuchRails::Action::Router
|
55
|
+
"::#{params[MuchRails::Action::Router.ACTION_CLASS_PARAM_NAME]}"
|
55
56
|
end
|
56
57
|
|
57
58
|
def much_rails_action_class_format
|
58
|
-
much_rails_action_class.format ||
|
59
|
+
much_rails_action_class.format ||
|
60
|
+
MuchRails::Action::Controller.DEFAULT_ACTION_CLASS_FORMAT
|
59
61
|
end
|
60
62
|
|
61
63
|
def much_rails_action_params
|
@@ -67,7 +69,7 @@ module MuchRails::Action::Controller
|
|
67
69
|
params
|
68
70
|
.to_h
|
69
71
|
.except(
|
70
|
-
MuchRails::Action::Router
|
72
|
+
MuchRails::Action::Router.ACTION_CLASS_PARAM_NAME,
|
71
73
|
:controller,
|
72
74
|
:action,
|
73
75
|
),
|
@@ -6,10 +6,21 @@ module MuchRails; end
|
|
6
6
|
module MuchRails::Action; end
|
7
7
|
|
8
8
|
class MuchRails::Action::Router < MuchRails::Action::BaseRouter
|
9
|
-
DEFAULT_CONTROLLER_NAME
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
def self.DEFAULT_CONTROLLER_NAME
|
10
|
+
"application"
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.CONTROLLER_CALL_ACTION_METHOD_NAME
|
14
|
+
:much_rails_call_action
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.CONTROLLER_NOT_FOUND_METHOD_NAME
|
18
|
+
:much_rails_not_found
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.ACTION_CLASS_PARAM_NAME
|
22
|
+
:much_rails_action_class_name
|
23
|
+
end
|
13
24
|
|
14
25
|
def self.url_class
|
15
26
|
MuchRails::Action::Router::URL
|
@@ -38,7 +49,7 @@ class MuchRails::Action::Router < MuchRails::Action::BaseRouter
|
|
38
49
|
def initialize(name = nil, controller_name: nil, &block)
|
39
50
|
super(name, &block)
|
40
51
|
|
41
|
-
@controller_name = controller_name || DEFAULT_CONTROLLER_NAME
|
52
|
+
@controller_name = controller_name || self.class.DEFAULT_CONTROLLER_NAME
|
42
53
|
end
|
43
54
|
|
44
55
|
# Example:
|
@@ -49,8 +60,12 @@ class MuchRails::Action::Router < MuchRails::Action::BaseRouter
|
|
49
60
|
# end
|
50
61
|
def apply_to(application_routes_draw_scope)
|
51
62
|
validate!
|
52
|
-
draw_url_to
|
53
|
-
|
63
|
+
draw_url_to =
|
64
|
+
"#{controller_name}##{self.class.CONTROLLER_NOT_FOUND_METHOD_NAME}"
|
65
|
+
draw_route_to =
|
66
|
+
"#{controller_name}##{self.class.CONTROLLER_CALL_ACTION_METHOD_NAME}"
|
67
|
+
|
68
|
+
definition_names = Set.new
|
54
69
|
|
55
70
|
definitions.each do |definition|
|
56
71
|
definition.request_type_actions.each do |request_type_action|
|
@@ -58,10 +73,12 @@ class MuchRails::Action::Router < MuchRails::Action::BaseRouter
|
|
58
73
|
definition.http_method,
|
59
74
|
definition.path,
|
60
75
|
to: draw_route_to,
|
61
|
-
as: definition.name,
|
76
|
+
as: (definition.name if definition_names.add?(definition.name)),
|
62
77
|
defaults:
|
63
78
|
definition.default_params.merge({
|
64
|
-
ACTION_CLASS_PARAM_NAME =>
|
79
|
+
self.class.ACTION_CLASS_PARAM_NAME =>
|
80
|
+
request_type_action.class_name,
|
81
|
+
"format" => request_type_action.format,
|
65
82
|
}),
|
66
83
|
constraints: request_type_action.constraints_lambda,
|
67
84
|
)
|
@@ -73,10 +90,12 @@ class MuchRails::Action::Router < MuchRails::Action::BaseRouter
|
|
73
90
|
definition.http_method,
|
74
91
|
definition.path,
|
75
92
|
to: draw_route_to,
|
76
|
-
as: definition.name,
|
93
|
+
as: (definition.name if definition_names.add?(definition.name)),
|
77
94
|
defaults:
|
78
95
|
definition.default_params.merge({
|
79
|
-
ACTION_CLASS_PARAM_NAME =>
|
96
|
+
self.class.ACTION_CLASS_PARAM_NAME =>
|
97
|
+
definition.default_action_class_name,
|
98
|
+
"format" => definition.default_action_format,
|
80
99
|
}),
|
81
100
|
)
|
82
101
|
end
|
@@ -93,14 +112,14 @@ class MuchRails::Action::Router < MuchRails::Action::BaseRouter
|
|
93
112
|
def path_for(**kargs)
|
94
113
|
MuchRails::RailsRoutes.instance.public_send(
|
95
114
|
"#{name}_path",
|
96
|
-
**kargs.symbolize_keys,
|
115
|
+
**kargs.symbolize_keys.except(:format),
|
97
116
|
)
|
98
117
|
end
|
99
118
|
|
100
119
|
def url_for(**kargs)
|
101
120
|
MuchRails::RailsRoutes.instance.public_send(
|
102
121
|
"#{name}_url",
|
103
|
-
**kargs.symbolize_keys,
|
122
|
+
**kargs.symbolize_keys.except(:format),
|
104
123
|
)
|
105
124
|
end
|
106
125
|
end
|
data/lib/much-rails/version.rb
CHANGED
data/much-rails.gemspec
CHANGED
@@ -37,6 +37,6 @@ Gem::Specification.new do |gem|
|
|
37
37
|
gem.add_dependency("much-mixin", ["~> 0.2.4"])
|
38
38
|
gem.add_dependency("much-not-given", ["~> 0.1.2"])
|
39
39
|
gem.add_dependency("much-result", ["~> 0.1.3"])
|
40
|
-
gem.add_dependency("much-slug", ["~> 0.1.
|
40
|
+
gem.add_dependency("much-slug", ["~> 0.1.2"])
|
41
41
|
gem.add_dependency("oj", ["~> 3.10"])
|
42
42
|
end
|
@@ -13,20 +13,31 @@ module FakeActionController
|
|
13
13
|
end
|
14
14
|
|
15
15
|
mixin_class_methods do
|
16
|
-
def before_action(
|
17
|
-
|
16
|
+
def before_action(*args, &block)
|
17
|
+
before_action_calls << Assert::StubCall.new(*args, &block)
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
21
|
-
|
20
|
+
def prepend_before_action(*args, &block)
|
21
|
+
prepend_before_action_calls << Assert::StubCall.new(*args, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def before_action_calls
|
25
|
+
@before_action_calls ||= []
|
26
|
+
end
|
27
|
+
|
28
|
+
def prepend_before_action_calls
|
29
|
+
@prepend_before_action_calls ||= []
|
22
30
|
end
|
23
31
|
end
|
24
32
|
|
25
33
|
mixin_instance_methods do
|
26
34
|
def initialize(params)
|
27
35
|
@params = FakeParams.new(params)
|
28
|
-
self.class.
|
29
|
-
public_send(
|
36
|
+
self.class.prepend_before_action_calls.each do |before_action_call|
|
37
|
+
public_send(before_action_call.args.first)
|
38
|
+
end
|
39
|
+
self.class.before_action_calls.each do |before_action_call|
|
40
|
+
public_send(before_action_call.args.first)
|
30
41
|
end
|
31
42
|
end
|
32
43
|
|
@@ -296,20 +296,30 @@ class MuchRails::Action::BaseRouter
|
|
296
296
|
desc "when init"
|
297
297
|
subject{ request_type_action_class.new(request_type1, action_class_name1) }
|
298
298
|
|
299
|
+
setup do
|
300
|
+
Assert.stub(action_class_name1, :constantize){ action_class1 }
|
301
|
+
end
|
302
|
+
|
299
303
|
let(:name1){ Factory.symbol }
|
300
304
|
let(:constraints_lambda1){ ->(request){} }
|
301
305
|
let(:request_type1) do
|
302
306
|
unit_class::RequestType.new(name1, constraints_lambda1)
|
303
307
|
end
|
304
308
|
let(:action_class_name1){ Factory.string }
|
309
|
+
let(:action_class1) do
|
310
|
+
Struct.new(:format).new([:html, :any].sample)
|
311
|
+
end
|
305
312
|
|
306
313
|
should have_imeths :request_type, :class_name, :constraints_lambda
|
314
|
+
should have_imeths :class_constant, :format
|
307
315
|
|
308
316
|
should "know its attributes" do
|
309
317
|
assert_that(subject.request_type).equals(request_type1)
|
310
318
|
assert_that(subject.class_name).equals(action_class_name1)
|
311
319
|
assert_that(subject.constraints_lambda)
|
312
320
|
.equals(request_type1.constraints_lambda)
|
321
|
+
assert_that(subject.class_constant).equals(action_class1)
|
322
|
+
assert_that(subject.format).equals(subject.class_constant.format)
|
313
323
|
end
|
314
324
|
end
|
315
325
|
|
@@ -506,6 +516,15 @@ class MuchRails::Action::BaseRouter
|
|
506
516
|
)
|
507
517
|
end
|
508
518
|
|
519
|
+
setup do
|
520
|
+
Assert.stub(default_action_class_name1, :constantize) do
|
521
|
+
default_action_class1
|
522
|
+
end
|
523
|
+
end
|
524
|
+
|
525
|
+
let(:default_action_class1) do
|
526
|
+
Struct.new(:format).new([:html, :any].sample)
|
527
|
+
end
|
509
528
|
let(:default_params1) do
|
510
529
|
{ Factory.string => Factory.string }
|
511
530
|
end
|
@@ -514,6 +533,7 @@ class MuchRails::Action::BaseRouter
|
|
514
533
|
should have_readers :default_action_class_name, :request_type_actions
|
515
534
|
should have_readers :called_from
|
516
535
|
should have_imeths :path, :name, :has_default_action_class_name?
|
536
|
+
should have_imeths :default_action_class_constant, :default_action_format
|
517
537
|
|
518
538
|
should "know its attributes" do
|
519
539
|
assert_that(subject.http_method).equals(http_method1)
|
@@ -525,6 +545,10 @@ class MuchRails::Action::BaseRouter
|
|
525
545
|
assert_that(subject.called_from).equals(caller1)
|
526
546
|
assert_that(subject.path).equals(url_path1)
|
527
547
|
assert_that(subject.name).equals(url_name1)
|
548
|
+
assert_that(subject.default_action_class_constant)
|
549
|
+
.equals(default_action_class1)
|
550
|
+
assert_that(subject.default_action_format)
|
551
|
+
.equals(subject.default_action_class_constant.format)
|
528
552
|
end
|
529
553
|
end
|
530
554
|
end
|
@@ -17,8 +17,8 @@ module MuchRails::Action::Controller
|
|
17
17
|
assert_that(subject).includes(MuchRails::Mixin)
|
18
18
|
end
|
19
19
|
|
20
|
-
should "know its
|
21
|
-
assert_that(subject
|
20
|
+
should "know its attributes" do
|
21
|
+
assert_that(subject.DEFAULT_ACTION_CLASS_FORMAT).equals(:any)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -29,15 +29,32 @@ module MuchRails::Action::Controller
|
|
29
29
|
let(:receiver_class) do
|
30
30
|
Class.new{ include FakeActionController }
|
31
31
|
end
|
32
|
+
|
33
|
+
should "be configured as expected" do
|
34
|
+
assert_that(subject.prepend_before_action_calls.size).equals(1)
|
35
|
+
assert_that(subject.prepend_before_action_calls.last.args)
|
36
|
+
.equals([
|
37
|
+
:require_much_rails_action_class,
|
38
|
+
only: MuchRails::Action::Router.CONTROLLER_CALL_ACTION_METHOD_NAME,
|
39
|
+
])
|
40
|
+
|
41
|
+
assert_that(subject.before_action_calls.size).equals(1)
|
42
|
+
assert_that(subject.before_action_calls.last.args)
|
43
|
+
.equals([:permit_all_much_rails_action_params])
|
44
|
+
end
|
32
45
|
end
|
33
46
|
|
34
47
|
class ReceiverInitTests < ReceiverTests
|
35
48
|
desc "when init"
|
36
49
|
subject{ receiver_class.new(params1) }
|
37
50
|
|
51
|
+
setup do
|
52
|
+
Assert.stub(::Actions::Show, :format){ nil }
|
53
|
+
end
|
54
|
+
|
38
55
|
let(:params1) do
|
39
56
|
{
|
40
|
-
MuchRails::Action::Router
|
57
|
+
MuchRails::Action::Router.ACTION_CLASS_PARAM_NAME => "Actions::Show",
|
41
58
|
controller: "actions",
|
42
59
|
action: "show",
|
43
60
|
nested: {
|
@@ -49,10 +66,10 @@ module MuchRails::Action::Controller
|
|
49
66
|
should have_readers :much_rails_action_class
|
50
67
|
|
51
68
|
should have_imeths(
|
52
|
-
MuchRails::Action::Router
|
69
|
+
MuchRails::Action::Router.CONTROLLER_CALL_ACTION_METHOD_NAME,
|
53
70
|
)
|
54
71
|
should have_imeths(
|
55
|
-
MuchRails::Action::Router
|
72
|
+
MuchRails::Action::Router.CONTROLLER_NOT_FOUND_METHOD_NAME,
|
56
73
|
)
|
57
74
|
should have_imeths :much_rails_action_class_name
|
58
75
|
should have_imeths :much_rails_action_class_format
|
@@ -65,7 +82,7 @@ module MuchRails::Action::Controller
|
|
65
82
|
.equals("::Actions::Show")
|
66
83
|
|
67
84
|
assert_that(subject.much_rails_action_class_format)
|
68
|
-
.equals(unit_module
|
85
|
+
.equals(unit_module.DEFAULT_ACTION_CLASS_FORMAT)
|
69
86
|
|
70
87
|
assert_that(subject.much_rails_action_params)
|
71
88
|
.equals(
|
@@ -75,10 +92,9 @@ module MuchRails::Action::Controller
|
|
75
92
|
|
76
93
|
assert_that(subject.much_rails_action_class).equals(Actions::Show)
|
77
94
|
|
78
|
-
Actions::Show
|
95
|
+
Assert.stub(::Actions::Show, :format){ :html }
|
79
96
|
receiver = receiver_class.new(params1)
|
80
97
|
assert_that(receiver.much_rails_action_class_format).equals(:html)
|
81
|
-
Actions::Show.format(nil)
|
82
98
|
end
|
83
99
|
end
|
84
100
|
|
@@ -88,7 +104,7 @@ module MuchRails::Action::Controller
|
|
88
104
|
|
89
105
|
let(:params1) do
|
90
106
|
{
|
91
|
-
MuchRails::Action::Router
|
107
|
+
MuchRails::Action::Router.ACTION_CLASS_PARAM_NAME =>
|
92
108
|
"Actions::Unknown",
|
93
109
|
}
|
94
110
|
end
|
@@ -16,17 +16,17 @@ class MuchRails::Action::Router
|
|
16
16
|
|
17
17
|
should have_imeths :url_class
|
18
18
|
|
19
|
-
should "be
|
19
|
+
should "be configured as expected" do
|
20
20
|
assert_that(subject < MuchRails::Action::BaseRouter).is_true
|
21
21
|
end
|
22
22
|
|
23
|
-
should "know its
|
24
|
-
assert_that(subject
|
25
|
-
assert_that(subject
|
23
|
+
should "know its attributes" do
|
24
|
+
assert_that(subject.DEFAULT_CONTROLLER_NAME).equals("application")
|
25
|
+
assert_that(subject.CONTROLLER_CALL_ACTION_METHOD_NAME)
|
26
26
|
.equals(:much_rails_call_action)
|
27
|
-
assert_that(subject
|
27
|
+
assert_that(subject.CONTROLLER_NOT_FOUND_METHOD_NAME)
|
28
28
|
.equals(:much_rails_not_found)
|
29
|
-
assert_that(subject
|
29
|
+
assert_that(subject.ACTION_CLASS_PARAM_NAME)
|
30
30
|
.equals(:much_rails_action_class_name)
|
31
31
|
assert_that(subject.url_class).equals(unit_class::URL)
|
32
32
|
end
|
@@ -64,7 +64,7 @@ class MuchRails::Action::Router
|
|
64
64
|
|
65
65
|
should "know its attributes" do
|
66
66
|
assert_that(subject.controller_name)
|
67
|
-
.equals(unit_class
|
67
|
+
.equals(unit_class.DEFAULT_CONTROLLER_NAME)
|
68
68
|
|
69
69
|
router = unit_class.new(controller_name: controller_name1)
|
70
70
|
assert_that(router.controller_name).equals(controller_name1)
|
@@ -99,12 +99,15 @@ class MuchRails::Action::Router
|
|
99
99
|
|
100
100
|
expected_draw_url_to =
|
101
101
|
"#{subject.controller_name}"\
|
102
|
-
"##{unit_class
|
102
|
+
"##{unit_class.CONTROLLER_NOT_FOUND_METHOD_NAME}"
|
103
103
|
expected_draw_route_to =
|
104
104
|
"#{subject.controller_name}"\
|
105
|
-
"##{unit_class
|
105
|
+
"##{unit_class.CONTROLLER_CALL_ACTION_METHOD_NAME}"
|
106
106
|
expected_default_defaults =
|
107
|
-
{
|
107
|
+
{
|
108
|
+
unit_class.ACTION_CLASS_PARAM_NAME => default_class_name,
|
109
|
+
"format" => :html,
|
110
|
+
}
|
108
111
|
|
109
112
|
assert_that(application_routes.get_calls.size).equals(3)
|
110
113
|
assert_that(application_routes.get_calls[0].pargs).equals([url_path])
|
@@ -113,14 +116,17 @@ class MuchRails::Action::Router
|
|
113
116
|
to: expected_draw_route_to,
|
114
117
|
as: url_name,
|
115
118
|
defaults:
|
116
|
-
{
|
119
|
+
{
|
120
|
+
unit_class.ACTION_CLASS_PARAM_NAME => request_type_class_name,
|
121
|
+
"format" => :html,
|
122
|
+
},
|
117
123
|
constraints: request_type_proc,
|
118
124
|
)
|
119
125
|
assert_that(application_routes.get_calls[1].pargs).equals([url_path])
|
120
126
|
assert_that(application_routes.get_calls[1].kargs)
|
121
127
|
.equals(
|
122
128
|
to: expected_draw_route_to,
|
123
|
-
as:
|
129
|
+
as: nil,
|
124
130
|
defaults: expected_default_defaults,
|
125
131
|
)
|
126
132
|
assert_that(application_routes.get_calls[2].pargs).equals([url2_path])
|
@@ -135,7 +141,7 @@ class MuchRails::Action::Router
|
|
135
141
|
assert_that(application_routes.post_calls.last.kargs)
|
136
142
|
.equals(
|
137
143
|
to: expected_draw_route_to,
|
138
|
-
as:
|
144
|
+
as: nil,
|
139
145
|
defaults: expected_default_defaults,
|
140
146
|
)
|
141
147
|
|
@@ -153,7 +159,7 @@ class MuchRails::Action::Router
|
|
153
159
|
assert_that(application_routes.patch_calls.last.kargs)
|
154
160
|
.equals(
|
155
161
|
to: expected_draw_route_to,
|
156
|
-
as:
|
162
|
+
as: nil,
|
157
163
|
defaults: expected_default_defaults,
|
158
164
|
)
|
159
165
|
|
@@ -162,7 +168,7 @@ class MuchRails::Action::Router
|
|
162
168
|
assert_that(application_routes.delete_calls.last.kargs)
|
163
169
|
.equals(
|
164
170
|
to: expected_draw_route_to,
|
165
|
-
as:
|
171
|
+
as: nil,
|
166
172
|
defaults: expected_default_defaults,
|
167
173
|
)
|
168
174
|
end
|
@@ -206,12 +212,12 @@ class MuchRails::Action::Router
|
|
206
212
|
should have_imeths :path_for, :url_for
|
207
213
|
|
208
214
|
should "know its attributes" do
|
209
|
-
path_string = subject.path_for(test: "args")
|
215
|
+
path_string = subject.path_for(test: "args", format: "html")
|
210
216
|
assert_that(path_string).equals("TEST PATH OR URL STRING")
|
211
217
|
assert_that(@rails_routes_method_missing_call.args)
|
212
218
|
.equals(["#{url_name1}_path".to_sym, { test: "args" }])
|
213
219
|
|
214
|
-
url_string = subject.url_for(test: "args")
|
220
|
+
url_string = subject.url_for(test: "args", format: "xml")
|
215
221
|
assert_that(url_string).equals("TEST PATH OR URL STRING")
|
216
222
|
assert_that(@rails_routes_method_missing_call.args)
|
217
223
|
.equals(["#{url_name1}_url".to_sym, { test: "args" }])
|
@@ -20,7 +20,7 @@ class MuchRails::Action::UnprocessableEntityResult
|
|
20
20
|
let(:controller1){ FakeController.new(params1) }
|
21
21
|
let(:params1) do
|
22
22
|
{
|
23
|
-
MuchRails::Action::Router
|
23
|
+
MuchRails::Action::Router.ACTION_CLASS_PARAM_NAME => "Actions::Show",
|
24
24
|
}
|
25
25
|
end
|
26
26
|
let(:errors1) do
|
data/test/unit/action_tests.rb
CHANGED
@@ -167,7 +167,7 @@ module MuchRails::Action
|
|
167
167
|
assert_that(subject.default_action_template_name)
|
168
168
|
.equals(
|
169
169
|
"some/namespace/for/"\
|
170
|
-
"#{MuchRails.config.action.namespace.
|
170
|
+
"#{MuchRails.config.action.namespace.underscore}"\
|
171
171
|
"thing/show",
|
172
172
|
)
|
173
173
|
end
|
@@ -176,11 +176,7 @@ module MuchRails::Action
|
|
176
176
|
class InitTests < ReceiverTests
|
177
177
|
desc "when init"
|
178
178
|
subject do
|
179
|
-
receiver_class.new(
|
180
|
-
params: params1,
|
181
|
-
current_user: current_user1,
|
182
|
-
request: request1,
|
183
|
-
)
|
179
|
+
receiver_class.new(params: params1, request: request1)
|
184
180
|
end
|
185
181
|
|
186
182
|
let(:receiver_class) do
|
@@ -218,6 +214,10 @@ module MuchRails::Action
|
|
218
214
|
on_after_call do
|
219
215
|
@after_call_called = true
|
220
216
|
end
|
217
|
+
|
218
|
+
def action_controller_session
|
219
|
+
controller_session
|
220
|
+
end
|
221
221
|
end
|
222
222
|
end
|
223
223
|
|
@@ -234,16 +234,41 @@ module MuchRails::Action
|
|
234
234
|
active: "true",
|
235
235
|
}
|
236
236
|
end
|
237
|
-
let(:
|
238
|
-
let(:request1){ "REQUEST 1" }
|
237
|
+
let(:request1){ FakeRequest.new }
|
239
238
|
|
240
|
-
should have_readers :params, :
|
239
|
+
should have_readers :params, :request, :errors
|
240
|
+
should have_writers :controller_session
|
241
241
|
should have_imeths :on_call, :valid_action?, :successful_action?
|
242
242
|
|
243
243
|
should "know its attributes" do
|
244
244
|
assert_that(subject.params).equals(params1.with_indifferent_access)
|
245
|
-
assert_that(subject.current_user).equals(current_user1)
|
246
245
|
assert_that(subject.request).equals(request1)
|
246
|
+
assert_that(subject.action_controller_session).is_a(FakeSession)
|
247
|
+
|
248
|
+
receiver = receiver_class.new(params: params1)
|
249
|
+
assert_that(receiver.action_controller_session).is_nil
|
250
|
+
|
251
|
+
controller_session = FakeRequest.new
|
252
|
+
receiver.controller_session = controller_session
|
253
|
+
assert_that(receiver.action_controller_session).is(controller_session)
|
254
|
+
|
255
|
+
receiver =
|
256
|
+
receiver_class.new(params: params1, request: FakeRequestWithNoEnv.new)
|
257
|
+
assert_that(receiver.action_controller_session).is_nil
|
258
|
+
|
259
|
+
receiver =
|
260
|
+
receiver_class.new(
|
261
|
+
params: params1,
|
262
|
+
request: FakeRequestWithNoControllerInstance.new,
|
263
|
+
)
|
264
|
+
assert_that(receiver.action_controller_session).is_nil
|
265
|
+
|
266
|
+
receiver =
|
267
|
+
receiver_class.new(
|
268
|
+
params: params1,
|
269
|
+
request: FakeRequestWithNoControllerInstance.new,
|
270
|
+
)
|
271
|
+
assert_that(receiver.action_controller_session).is_nil
|
247
272
|
end
|
248
273
|
|
249
274
|
should "return the expected Result" do
|
@@ -318,6 +343,7 @@ module MuchRails::Action
|
|
318
343
|
layout: false,
|
319
344
|
)
|
320
345
|
|
346
|
+
view_model = Object.new
|
321
347
|
receiver_class.on_call do
|
322
348
|
render(view_model, "some/view/template", layout: false)
|
323
349
|
end
|
@@ -330,18 +356,29 @@ module MuchRails::Action
|
|
330
356
|
layout: false,
|
331
357
|
)
|
332
358
|
|
359
|
+
view_model =
|
360
|
+
Class
|
361
|
+
.new{
|
362
|
+
def much_rails_action
|
363
|
+
"NOT A MUCH RAILS ACTION"
|
364
|
+
end
|
365
|
+
}
|
366
|
+
.new
|
333
367
|
receiver_class.on_call do
|
334
368
|
render(view_model, "some/view/template", template: "other/template")
|
335
369
|
end
|
336
370
|
action = receiver_class.new(params: params1)
|
337
371
|
result = action.call
|
338
372
|
assert_that(result.render_view_model).is(view_model)
|
373
|
+
assert_that(result.render_view_model.much_rails_action).is_not(action)
|
339
374
|
assert_that(result.render_kargs).equals(template: "other/template")
|
340
375
|
|
376
|
+
view_model = Struct.new(:much_rails_action).new(nil)
|
341
377
|
receiver_class.on_call{ render(view_model, template: "other/template") }
|
342
378
|
action = receiver_class.new(params: params1)
|
343
379
|
result = action.call
|
344
380
|
assert_that(result.render_view_model).is(view_model)
|
381
|
+
assert_that(result.render_view_model.much_rails_action).is(action)
|
345
382
|
assert_that(result.render_kargs).equals(template: "other/template")
|
346
383
|
end
|
347
384
|
|
@@ -397,4 +434,31 @@ module MuchRails::Action
|
|
397
434
|
assert_that(result.errors[:custom_validation]).includes("ERROR1")
|
398
435
|
end
|
399
436
|
end
|
437
|
+
|
438
|
+
class FakeController
|
439
|
+
def session
|
440
|
+
FakeSession.new
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
class FakeSession
|
445
|
+
end
|
446
|
+
|
447
|
+
class FakeRequest
|
448
|
+
def env
|
449
|
+
{ "action_controller.instance" => FakeController.new }
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
453
|
+
class FakeRequestWithNoControllerInstance
|
454
|
+
def env
|
455
|
+
{ "action_controller.instance" => nil }
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
class FakeRequestWithNoEnv
|
460
|
+
def env
|
461
|
+
nil
|
462
|
+
end
|
463
|
+
end
|
400
464
|
end
|
@@ -57,14 +57,7 @@ module MuchRails::ChangeAction
|
|
57
57
|
|
58
58
|
class InitTests < ReceiverTests
|
59
59
|
desc "when init"
|
60
|
-
subject{ receiver_class.new(params: {}) }
|
61
|
-
subject do
|
62
|
-
receiver_class.new(
|
63
|
-
params: {},
|
64
|
-
current_user: nil,
|
65
|
-
request: nil,
|
66
|
-
)
|
67
|
-
end
|
60
|
+
subject{ receiver_class.new(params: {}, request: nil) }
|
68
61
|
|
69
62
|
setup do
|
70
63
|
Assert.stub(subject, :any_unextracted_change_result_validation_errors?) do
|
@@ -84,13 +77,7 @@ module MuchRails::ChangeAction
|
|
84
77
|
|
85
78
|
class RecordErrorsWithResultExceptionTests < InitTests
|
86
79
|
desc "with record errors and a result exception"
|
87
|
-
subject
|
88
|
-
receiver_class.new(
|
89
|
-
params: {},
|
90
|
-
current_user: nil,
|
91
|
-
request: nil,
|
92
|
-
)
|
93
|
-
end
|
80
|
+
subject{ receiver_class.new(params: {}, request: nil) }
|
94
81
|
|
95
82
|
setup do
|
96
83
|
Assert.stub(subject, :any_unextracted_change_result_validation_errors?) do
|
@@ -118,13 +105,7 @@ module MuchRails::ChangeAction
|
|
118
105
|
|
119
106
|
class RecordErrorsWithNoResultExceptionTests < InitTests
|
120
107
|
desc "with record errors and no result exception"
|
121
|
-
subject
|
122
|
-
receiver_class.new(
|
123
|
-
params: {},
|
124
|
-
current_user: nil,
|
125
|
-
request: nil,
|
126
|
-
)
|
127
|
-
end
|
108
|
+
subject{ receiver_class.new(params: {}, request: nil) }
|
128
109
|
|
129
110
|
setup do
|
130
111
|
Assert.stub(subject, :any_unextracted_change_result_validation_errors?) do
|
@@ -149,13 +130,7 @@ module MuchRails::ChangeAction
|
|
149
130
|
|
150
131
|
class ChangeResultMethodTests < InitTests
|
151
132
|
desc "#change_result method"
|
152
|
-
subject
|
153
|
-
receiver_class.new(
|
154
|
-
params: {},
|
155
|
-
current_user: nil,
|
156
|
-
request: nil,
|
157
|
-
)
|
158
|
-
end
|
133
|
+
subject{ receiver_class.new(params: {}, request: nil) }
|
159
134
|
|
160
135
|
should "memoize and return the expected Result" do
|
161
136
|
result = subject.change_result
|
@@ -178,13 +153,7 @@ module MuchRails::ChangeAction
|
|
178
153
|
|
179
154
|
class AnyUnextractedChangeResultValidationErrorsMethodTests < ReceiverTests
|
180
155
|
desc "#any_unextracted_change_result_validation_errors? method"
|
181
|
-
subject
|
182
|
-
receiver_class.new(
|
183
|
-
params: {},
|
184
|
-
current_user: nil,
|
185
|
-
request: nil,
|
186
|
-
)
|
187
|
-
end
|
156
|
+
subject{ receiver_class.new(params: {}, request: nil) }
|
188
157
|
|
189
158
|
let(:receiver_class) do
|
190
159
|
Class.new do
|
@@ -205,13 +174,7 @@ module MuchRails::ChangeAction
|
|
205
174
|
class NoValidationErrorsTests <
|
206
175
|
AnyUnextractedChangeResultValidationErrorsMethodTests
|
207
176
|
desc "with no validation errors"
|
208
|
-
subject
|
209
|
-
receiver_class.new(
|
210
|
-
params: {},
|
211
|
-
current_user: nil,
|
212
|
-
request: nil,
|
213
|
-
)
|
214
|
-
end
|
177
|
+
subject{ receiver_class.new(params: {}, request: nil) }
|
215
178
|
|
216
179
|
let(:receiver_class) do
|
217
180
|
Class.new do
|
@@ -232,13 +195,7 @@ module MuchRails::ChangeAction
|
|
232
195
|
class ValidationErrorsTests <
|
233
196
|
AnyUnextractedChangeResultValidationErrorsMethodTests
|
234
197
|
desc "with validation errors"
|
235
|
-
subject
|
236
|
-
receiver_class.new(
|
237
|
-
params: {},
|
238
|
-
current_user: nil,
|
239
|
-
request: nil,
|
240
|
-
)
|
241
|
-
end
|
198
|
+
subject{ receiver_class.new(params: {}, request: nil) }
|
242
199
|
|
243
200
|
let(:receiver_class) do
|
244
201
|
Class.new do
|
@@ -50,13 +50,7 @@ module MuchRails::DestroyAction
|
|
50
50
|
|
51
51
|
class InitTests < ReceiverTests
|
52
52
|
desc "when init"
|
53
|
-
subject
|
54
|
-
receiver_class.new(
|
55
|
-
params: {},
|
56
|
-
current_user: nil,
|
57
|
-
request: nil,
|
58
|
-
)
|
59
|
-
end
|
53
|
+
subject{ receiver_class.new(params: {}, request: nil) }
|
60
54
|
|
61
55
|
should have_imeths :destroy_result
|
62
56
|
|
@@ -9,12 +9,21 @@ module MuchRails::InputValue
|
|
9
9
|
subject{ unit_class }
|
10
10
|
|
11
11
|
let(:unit_class){ MuchRails::InputValue }
|
12
|
+
let(:non_blank_but_empty_to_s_object) do
|
13
|
+
Class
|
14
|
+
.new{
|
15
|
+
def to_s
|
16
|
+
["", " "].sample
|
17
|
+
end
|
18
|
+
}
|
19
|
+
.new
|
20
|
+
end
|
12
21
|
|
13
22
|
should have_imeths :strip, :strip_all
|
14
23
|
|
15
24
|
should "know its attributes" do
|
16
25
|
# strip
|
17
|
-
input_value = [nil, "", " "].sample
|
26
|
+
input_value = [nil, "", " ", non_blank_but_empty_to_s_object].sample
|
18
27
|
assert_that(subject.strip(input_value)).is_nil
|
19
28
|
|
20
29
|
input_value = [" VALUE ", "\r VALUE\n"].sample
|
@@ -50,13 +50,7 @@ module MuchRails::SaveAction
|
|
50
50
|
|
51
51
|
class InitTests < ReceiverTests
|
52
52
|
desc "when init"
|
53
|
-
subject
|
54
|
-
receiver_class.new(
|
55
|
-
params: {},
|
56
|
-
current_user: nil,
|
57
|
-
request: nil,
|
58
|
-
)
|
59
|
-
end
|
53
|
+
subject{ receiver_class.new(params: {}, request: nil) }
|
60
54
|
|
61
55
|
should have_imeths :save_result
|
62
56
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: much-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-05-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: much-style-guide
|
@@ -217,14 +217,14 @@ dependencies:
|
|
217
217
|
requirements:
|
218
218
|
- - "~>"
|
219
219
|
- !ruby/object:Gem::Version
|
220
|
-
version: 0.1.
|
220
|
+
version: 0.1.2
|
221
221
|
type: :runtime
|
222
222
|
prerelease: false
|
223
223
|
version_requirements: !ruby/object:Gem::Requirement
|
224
224
|
requirements:
|
225
225
|
- - "~>"
|
226
226
|
- !ruby/object:Gem::Version
|
227
|
-
version: 0.1.
|
227
|
+
version: 0.1.2
|
228
228
|
- !ruby/object:Gem::Dependency
|
229
229
|
name: oj
|
230
230
|
requirement: !ruby/object:Gem::Requirement
|