diff --git a/lib/matestack/ui/bootstrap/form/input.rb b/lib/matestack/ui/bootstrap/form/input.rb index d303222..2bac17a 100644 --- a/lib/matestack/ui/bootstrap/form/input.rb +++ b/lib/matestack/ui/bootstrap/form/input.rb @@ -22,11 +22,9 @@ def response input options.merge(input_attributes).merge(bootstrap_range_attributes) if context.show_value div class: "form-text form-text-for-#{attribute_key}" do - plain "{{ data['#{attribute_key}'] }}" + plain "{{ #{input_key} }}" end end - when :file - file_input else input options.merge(input_attributes).merge(bootstrap_input_attributes) render_errors diff --git a/spec/support/file.md b/spec/support/file.md new file mode 100644 index 0000000..5d6c0e6 --- /dev/null +++ b/spec/support/file.md @@ -0,0 +1 @@ +Matestack is powerful, but more importantly, fun. diff --git a/spec/test/form/input_spec.rb b/spec/test/form/input_spec.rb index 303711d..5eb661e 100644 --- a/spec/test/form/input_spec.rb +++ b/spec/test/form/input_spec.rb @@ -159,4 +159,23 @@ expect(page).to have_xpath('//form//div[contains(@class, "form-text-for-foo") and contains(@class, "form-text") and contains(text(), "some notes")]') end + it 'renders bootstrap file input field and uploads file' do + form_config = get_form_config(path: input_success_form_test_path).merge(multipart: true) + matestack_render do + matestack_form form_config do + bs_form_input key: :file_upload, type: :file + bs_form_submit text: "Submit" + end + end + visit example_path + expect(page).to have_selector('form > div.matestack-ui-bootstrap-input > input.form-control#file_upload[type="file"]') + + page.attach_file('file_upload', Rails.root + '../support/file.md', make_visible: true) + + expect_any_instance_of(FormTestController).to receive(:expect_params) + .with(hash_including(wrapper: {file_upload: ActionDispatch::Http::UploadedFile})) + + click_button "Submit" + end + end