Skip to content

Commit 1a396d3

Browse files
authored
Merge pull request #287 from basemate/fixing_issue_256
fixed form component usage on component-level
2 parents 51c3df4 + 595af44 commit 1a396d3

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

app/lib/matestack/ui/core/component_node.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ def initialize(component_instance, included_config)
1313
@hash = {}
1414
@node_start_id = 0
1515
@component_instance = component_instance
16-
@included_config = included_config
1716
component_instance.instance_variables.each do |component_instance_var_key|
1817
self.instance_variable_set(component_instance_var_key, component_instance.instance_variable_get(component_instance_var_key))
1918
end
19+
@included_config = included_config
2020
end
2121

2222
def method_missing meth, *args, &block

spec/usage/components/form_spec.rb

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,61 @@ def form_config
15541554
it "can have a label"
15551555

15561556
end
1557+
1558+
describe "Usage on Component Level" do
1559+
1560+
it "Example 1 - Async submit request with clientside payload from component-level" do
1561+
1562+
module Components end
1563+
1564+
class Components::SomeComponent < Matestack::Ui::StaticComponent
1565+
1566+
def response
1567+
components {
1568+
form form_config, :include do
1569+
form_input id: "my-test-input", key: :foo, type: :text
1570+
form_submit do
1571+
button text: "Submit me!"
1572+
end
1573+
end
1574+
}
1575+
end
1576+
1577+
def form_config
1578+
return {
1579+
for: :my_object,
1580+
method: :post,
1581+
path: :success_form_test_path,
1582+
params: {
1583+
id: 42
1584+
}
1585+
}
1586+
end
1587+
end
1588+
1589+
class ExamplePage < Matestack::Ui::Page
1590+
1591+
def response
1592+
components {
1593+
div do
1594+
custom_someComponent
1595+
end
1596+
}
1597+
end
1598+
1599+
end
1600+
1601+
visit "/example"
1602+
1603+
fill_in "my-test-input", with: "bar"
1604+
click_button "Submit me!"
1605+
1606+
expect_any_instance_of(FormTestController).to receive(:expect_params)
1607+
.with(hash_including(my_object: { foo: "bar" }))
1608+
1609+
end
1610+
end
1611+
15571612
end
15581613

15591614
end

0 commit comments

Comments
 (0)