Module: DownloadHelper
- Defined in:
- lib/decidim/dev/test/rspec_support/download_helper.rb
Constant Summary collapse
- TIMEOUT =
10
- PATH =
Rails.root.join("tmp", "downloads").freeze
Instance Method Summary collapse
- #clear_downloads ⇒ Object
- #download_content ⇒ Object
- #download_path ⇒ Object
- #downloaded? ⇒ Boolean
- #downloading? ⇒ Boolean
- #downloads ⇒ Object
- #wait_for_download ⇒ Object
Instance Method Details
#clear_downloads ⇒ Object
35 36 37 |
# File 'lib/decidim/dev/test/rspec_support/download_helper.rb', line 35 def clear_downloads FileUtils.rm_f(downloads) end |
#download_content ⇒ Object
16 17 18 19 |
# File 'lib/decidim/dev/test/rspec_support/download_helper.rb', line 16 def download_content wait_for_download File.read(download_path) end |
#download_path ⇒ Object
11 12 13 14 |
# File 'lib/decidim/dev/test/rspec_support/download_helper.rb', line 11 def download_path wait_for_download downloads.first end |
#downloaded? ⇒ Boolean
27 28 29 |
# File 'lib/decidim/dev/test/rspec_support/download_helper.rb', line 27 def downloaded? downloads.any? && !downloading? end |
#downloading? ⇒ Boolean
31 32 33 |
# File 'lib/decidim/dev/test/rspec_support/download_helper.rb', line 31 def downloading? downloads.grep(/\.crdownload$/).any? end |
#downloads ⇒ Object
7 8 9 |
# File 'lib/decidim/dev/test/rspec_support/download_helper.rb', line 7 def downloads Dir[PATH.join("*")] end |
#wait_for_download ⇒ Object
21 22 23 24 25 |
# File 'lib/decidim/dev/test/rspec_support/download_helper.rb', line 21 def wait_for_download Timeout.timeout(TIMEOUT) do sleep 0.1 until downloaded? end end |