Module: CarrierWaveDirect::Test::CapybaraHelpers
- Includes:
- Helpers
- Defined in:
- lib/carrierwave_direct/test/capybara_helpers.rb
Instance Method Summary collapse
- #attach_file_for_direct_upload(path) ⇒ Object
- #find_key ⇒ Object
- #find_upload_path ⇒ Object
- #upload_directly(uploader, button_locator, options = {}) ⇒ Object
Methods included from Helpers
Instance Method Details
#attach_file_for_direct_upload(path) ⇒ Object
9 10 11 |
# File 'lib/carrierwave_direct/test/capybara_helpers.rb', line 9 def attach_file_for_direct_upload(path) attach_file("file", path) end |
#find_key ⇒ Object
13 14 15 |
# File 'lib/carrierwave_direct/test/capybara_helpers.rb', line 13 def find_key key = page.find("input[@name='key']").value end |
#find_upload_path ⇒ Object
17 18 19 |
# File 'lib/carrierwave_direct/test/capybara_helpers.rb', line 17 def find_upload_path page.find("input[@name='file']").value end |
#upload_directly(uploader, button_locator, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/carrierwave_direct/test/capybara_helpers.rb', line 21 def upload_directly(uploader, , = {}) [:success] = true unless [:success] == false [:success] &&= ![:fail] if [:success] # simulate a successful upload # form's success action redirect url redirect_url = URI.parse(page.find("input[@name='success_action_redirect']").value) unless [:redirect_key] sample_key_args = [{:base => find_key, :filename => File.basename(find_upload_path)}] sample_key_args.unshift(uploader) if method(:sample_key).arity == -2 [:redirect_key] = sample_key(*sample_key_args) end redirect_url.query = Rack::Utils.build_nested_query({ :bucket => uploader.fog_directory, :key => [:redirect_key], :etag => "\"d41d8cd98f00b204e9800998ecf8427\"" }) # click the button # simulate success redirect visit redirect_url.to_s else # simulate an unsuccessful upload # click the button end end |