Module: DownloadHelper
- Defined in:
- lib/decidim/dev/test/rspec_support/z_download_helper.rb
Constant Summary collapse
- TIMEOUT =
10
- PATH =
Rails.root.join("tmp/downloads").freeze
Instance Method Summary collapse
- #clear_downloads ⇒ Object
- #download_content(name = nil) ⇒ Object
- #download_path(name = nil) ⇒ Object
- #downloaded?(name = nil) ⇒ Boolean
- #downloading? ⇒ Boolean
- #downloads(name = nil) ⇒ Object
- #wait_for_download(name = nil) ⇒ Object
Instance Method Details
#clear_downloads ⇒ Object
35 36 37 |
# 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) ⇒ Object
16 17 18 19 |
# 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) ⇒ Object
11 12 13 14 |
# 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) ⇒ Boolean
27 28 29 |
# File 'lib/decidim/dev/test/rspec_support/z_download_helper.rb', line 27 def downloaded?(name = nil) downloads(name).any? && !downloading? end |
#downloading? ⇒ Boolean
31 32 33 |
# File 'lib/decidim/dev/test/rspec_support/z_download_helper.rb', line 31 def downloading? downloads.grep(/\.crdownload$/).any? end |
#downloads(name = nil) ⇒ Object
7 8 9 |
# 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) ⇒ Object
21 22 23 24 25 |
# 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 |