Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File input fix #20

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/matestack/ui/bootstrap/form/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/support/file.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Matestack is powerful, but more importantly, fun.
19 changes: 19 additions & 0 deletions spec/test/form/input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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