Merge branch 'stable' into develop
This commit is contained in:
commit
f4454f4488
5 changed files with 78 additions and 10 deletions
|
|
@ -200,8 +200,7 @@
|
|||
= link_to t(".request_export_photos_update"), export_photos_user_path,
|
||||
class: "btn btn-default btn-block"
|
||||
.small-horizontal-spacer
|
||||
= link_to t(".download_export_photos"), download_photos_user_path, method: :post,
|
||||
class: "btn btn-success btn-block"
|
||||
= link_to t(".download_export_photos"), download_photos_user_path, class: "btn btn-success btn-block"
|
||||
.small-horizontal-spacer
|
||||
%h6
|
||||
= t(".last_exported_at", timestamp: current_user.exported_photos_at)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,20 @@
|
|||
@wip
|
||||
@javascript
|
||||
Feature: Download Photos
|
||||
|
||||
Scenario: Download my photos
|
||||
Given I am signed in
|
||||
And I click on my name in the header
|
||||
And I follow "settings"
|
||||
Scenario: Request my photos
|
||||
Given I am signed in
|
||||
When I click on my name in the header
|
||||
When I follow "Settings"
|
||||
Then I should be on my account settings page
|
||||
And I follow "download my photos"
|
||||
Then I confirm the alert
|
||||
When I follow "Request my photos"
|
||||
Then I should see a flash message indicating success
|
||||
And I should see a flash message containing "We are currently processing your photos"
|
||||
|
||||
Scenario: Download my photos
|
||||
Given I am signed in
|
||||
When I did request my photos
|
||||
And I click on my name in the header
|
||||
When I follow "Settings"
|
||||
Then I should be on my account settings page
|
||||
When I follow "Download my photos"
|
||||
Then I should get a zipped file
|
||||
|
|
|
|||
|
|
@ -219,3 +219,11 @@ end
|
|||
When /^I click the sign in button$/ do
|
||||
click_link "Sign in"
|
||||
end
|
||||
|
||||
Given /^I did request my photos$/ do
|
||||
@me.perform_export_photos!
|
||||
end
|
||||
|
||||
Then /^I should get a zipped file$/ do
|
||||
expect(DownloadHelpers.download).to end_with("zip")
|
||||
end
|
||||
|
|
|
|||
40
features/support/download_helpers.rb
Normal file
40
features/support/download_helpers.rb
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# Credits goes to Steve Richert
|
||||
# http://collectiveidea.com/blog/archives/2012/01/27/testing-file-downloads-with-capybara-and-chromedriver/
|
||||
module DownloadHelpers
|
||||
TIMEOUT ||= 5
|
||||
PATH ||= Rails.root.join("tmp/downloads")
|
||||
|
||||
module_function
|
||||
|
||||
def downloads
|
||||
Dir[PATH.join("*")]
|
||||
end
|
||||
|
||||
def download
|
||||
wait_for_download
|
||||
downloads.first
|
||||
end
|
||||
|
||||
def download_content
|
||||
wait_for_download
|
||||
File.read(download)
|
||||
end
|
||||
|
||||
def wait_for_download
|
||||
Timeout.timeout(TIMEOUT) do
|
||||
sleep 0.1 until downloaded?
|
||||
end
|
||||
end
|
||||
|
||||
def downloaded?
|
||||
!downloading? && downloads.any?
|
||||
end
|
||||
|
||||
def downloading?
|
||||
downloads.grep(/\.part$/).any?
|
||||
end
|
||||
|
||||
def clear_downloads
|
||||
FileUtils.rm_f(downloads)
|
||||
end
|
||||
end
|
||||
|
|
@ -24,7 +24,17 @@ Rails.application.routes.default_url_options[:port] = AppConfig.pod_uri.port
|
|||
Selenium::WebDriver::Firefox::Binary.path = ENV["FIREFOX_BINARY_PATH"] || Selenium::WebDriver::Firefox::Binary.path
|
||||
|
||||
Capybara.register_driver :selenium do |app|
|
||||
Capybara::Selenium::Driver.new(app, browser: :firefox)
|
||||
profile = Selenium::WebDriver::Firefox::Profile.new
|
||||
# Set the download directory to "tmp/downloads"
|
||||
profile["browser.download.dir"] = DownloadHelpers::PATH.to_s
|
||||
# Save the file instead of opening it
|
||||
profile["browser.download.folderList"] = 2
|
||||
# Hide the download Manager
|
||||
profile["browser.download.manager.showWhenStarting"] = false
|
||||
# Suppress "open with" dialog for zipped files only
|
||||
profile["browser.helperApps.neverAsk.saveToDisk"] = "application/zip"
|
||||
# Start Firefox using our profile
|
||||
Capybara::Selenium::Driver.new(app, browser: :firefox, profile: profile)
|
||||
end
|
||||
|
||||
Capybara.register_driver :mobile do |app|
|
||||
|
|
@ -74,4 +84,6 @@ include HelperMethods
|
|||
Before do
|
||||
Devise.mailer.deliveries = []
|
||||
page.driver.browser.manage.window.resize_to(1024, 500)
|
||||
# Delete all files in "tmp/downloads"
|
||||
DownloadHelpers.clear_downloads
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue