Module: Microform::Test::IntegrationMethods

Defined in:
lib/microform/test_methods.rb

Instance Method Summary collapse

Instance Method Details

#assert_submits(form_kind, stub: nil, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/microform/test_methods.rb', line 7

def assert_submits form_kind, stub: nil, &block
  controller = self.class.name.gsub(/Test\z/, "").constantize
  form = form_kind.new OpenStruct.new(foo: :bar)

  # Mangle the variable names to circumvent any issues with method
  # collisions when the `submit` lambda is instance eval'ed within
  # the controller.
  __microform_form_kind = form_kind
  __microform_test = self
  __microform_stub = stub

  submit = -> f, *args {
    __microform_test.assert_equal __microform_form_kind, f

    if __microform_stub
      __microform_stub
    else
      __minitest_any_instance_stub__submit f, *args
    end
  }

  controller.stub_any_instance :submit, submit do
    yield form
  end
end