module DownloadHelper

Constants

PATH
TIMEOUT

Public Instance Methods

clear_downloads() click to toggle source
# File lib/decidim/dev/test/rspec_support/z_download_helper.rb, line 35
def clear_downloads
  FileUtils.rm_f(downloads)
end
download_content(name = nil) click to toggle source
# File lib/decidim/dev/test/rspec_support/z_download_helper.rb, line 16
def download_content(name = nil)
  wait_for_download(name)
  File.read(download_path(name))
end
download_path(name = nil) click to toggle source
# File lib/decidim/dev/test/rspec_support/z_download_helper.rb, line 11
def download_path(name = nil)
  wait_for_download(name)
  downloads(name).first
end
downloaded?(name = nil) click to toggle source
# File lib/decidim/dev/test/rspec_support/z_download_helper.rb, line 27
def downloaded?(name = nil)
  downloads(name).any? && !downloading?
end
downloading?() click to toggle source
# File lib/decidim/dev/test/rspec_support/z_download_helper.rb, line 31
def downloading?
  downloads.grep(/\.crdownload$/).any?
end
downloads(name = nil) click to toggle source
# File lib/decidim/dev/test/rspec_support/z_download_helper.rb, line 7
def downloads(name = nil)
  Dir[PATH.join(name || "*")]
end
wait_for_download(name = nil) click to toggle source
# File lib/decidim/dev/test/rspec_support/z_download_helper.rb, line 21
def wait_for_download(name = nil)
  Timeout.timeout(TIMEOUT) do
    sleep 0.1 until downloaded?(name)
  end
end