Class: RailsEdgeTest::Dsl::Edge
- Inherits:
-
Struct
- Object
- Struct
- RailsEdgeTest::Dsl::Edge
show all
- Defined in:
- lib/rails_edge_test/dsl/edge.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*args) ⇒ Edge
Returns a new instance of Edge.
8
9
10
11
|
# File 'lib/rails_edge_test/dsl/edge.rb', line 8
def initialize(*args)
super
@let_cache = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
support calling methods defined in action
132
133
134
135
136
137
138
|
# File 'lib/rails_edge_test/dsl/edge.rb', line 132
def method_missing(method_name, *arguments, &block)
if action.respond_to?(method_name)
action.public_send(method_name, *arguments, &block)
else
super
end
end
|
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action
6
7
8
|
# File 'lib/rails_edge_test/dsl/edge.rb', line 6
def action
@action
end
|
#description ⇒ Object
Returns the value of attribute description
6
7
8
|
# File 'lib/rails_edge_test/dsl/edge.rb', line 6
def description
@description
end
|
Instance Method Details
#controller ⇒ Object
In the context of the edge, we want ‘controller` to be the rails controller instead of our own RailsEdgeTest::Dsl::Controller. In this way the user can directly access the rails controller within their edge.
23
24
25
|
# File 'lib/rails_edge_test/dsl/edge.rb', line 23
def controller
@controller ||= controller_class.new
end
|
41
42
43
44
45
|
# File 'lib/rails_edge_test/dsl/edge.rb', line 41
def perform_delete(parameters={})
request.instance_variable_set(:@method, "DELETE")
request.env['REQUEST_METHOD'] = "DELETE"
process(parameters)
end
|
31
32
33
|
# File 'lib/rails_edge_test/dsl/edge.rb', line 31
def perform_get(parameters={})
process(parameters)
end
|
#perform_post(parameters = {}) ⇒ Object
35
36
37
38
39
|
# File 'lib/rails_edge_test/dsl/edge.rb', line 35
def perform_post(parameters={})
request.instance_variable_set(:@method, "POST")
request.env['REQUEST_METHOD'] = "POST"
process(parameters)
end
|
#process(parameters = {}) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/rails_edge_test/dsl/edge.rb', line 53
def process(parameters={})
request.assign_parameters(
::Rails.application.routes,
controller_class.controller_path,
action.name.to_s,
parameters.stringify_keys!,
'',
''
)
response = ActionDispatch::Response.new.tap do |res|
res.request = request
end
@response = controller.dispatch(action.name, request, response)
end
|
#produce_elm_file(module_name, ivar: nil) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/rails_edge_test/dsl/edge.rb', line 70
def produce_elm_file(module_name, ivar: nil)
json = produce_json(ivar: ivar)
json = json.gsub("\\", "\\\\\\\\")
filepath = File.join(
RailsEdgeTest.configuration.elm_path,
'Edge',
controller_class.name.gsub('::','/')
)
full_module_name =
"#{controller_class.name.gsub('::','.')}.#{module_name}"
data = <<~ELM
module Edge.#{full_module_name} exposing (json)
json : String
json =
"""
#{json}
"""
ELM
write_file(filepath, module_name+'.elm', data)
end
|
#request ⇒ Object
16
17
18
|
# File 'lib/rails_edge_test/dsl/edge.rb', line 16
def request
@request ||= ActionController::TestRequest.create(controller_class)
end
|
#response ⇒ Object
27
28
29
|
# File 'lib/rails_edge_test/dsl/edge.rb', line 27
def response
@response
end
|
#set_authenticity_token ⇒ Object
47
48
49
50
51
|
# File 'lib/rails_edge_test/dsl/edge.rb', line 47
def set_authenticity_token
r = request
controller.instance_eval { @_request = r }
request.['X-CSRF-Token'] = controller.send :form_authenticity_token
end
|