Module: DownloadHelper

Defined in:
decidim-dev/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

Instance Method Details

#clear_downloadsObject



35
36
37
# File 'decidim-dev/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 'decidim-dev/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 'decidim-dev/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

Returns:

  • (Boolean)


27
28
29
# File 'decidim-dev/lib/decidim/dev/test/rspec_support/z_download_helper.rb', line 27

def downloaded?(name = nil)
  downloads(name).any? && !downloading?
end

#downloading?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'decidim-dev/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 'decidim-dev/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 'decidim-dev/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