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

Instance Method Details

#clear_downloadsObject



35
36
37
# File 'lib/decidim/dev/test/rspec_support/download_helper.rb', line 35

def clear_downloads
  FileUtils.rm_f(downloads)
end

#download_contentObject



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_pathObject



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

Returns:

  • (Boolean)


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

def downloaded?
  downloads.any? && !downloading?
end

#downloading?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/decidim/dev/test/rspec_support/download_helper.rb', line 31

def downloading?
  downloads.grep(/\.crdownload$/).any?
end

#downloadsObject



7
8
9
# File 'lib/decidim/dev/test/rspec_support/download_helper.rb', line 7

def downloads
  Dir[PATH.join("*")]
end

#wait_for_downloadObject



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