Skip to content

Commit 61428fb

Browse files
committed
refactor testing code, workflow
1 parent 4fdcfb4 commit 61428fb

File tree

5 files changed

+81
-32
lines changed

5 files changed

+81
-32
lines changed

spec/features/download_zipfile_spec.rb

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,46 @@
66
let(:download_dir) { '/opt/app/tmp/selenium_downloads' }
77
let(:zip_file_name) { 'data.zip' }
88
let(:zip_file_path) { File.join(download_dir, zip_file_name) }
9-
let(:crdownload_file) { "#{zip_file_path}.crdownload" }
9+
let(:zip_crdownload_file) { "#{zip_file_path}.crdownload" }
1010
let(:crdownload_files) { Dir.glob(File.join(download_dir, '*.crdownload')) }
11+
let(:all_files) { crdownload_files + [zip_file_path] }
1112

1213
before do
13-
clear_download_files
14-
visit 'catalog/berkeley-s7038h'
14+
rm_files(all_files)
15+
# visit 'catalog/berkeley-s7038h'
16+
visit_public_record
1517
end
1618

1719
after(:each) do
18-
clear_download_files
19-
Capybara.reset_sessions!
20-
puts 'After callback executed -- dff'
20+
# clear_download_files
21+
# Capybara.reset_sessions!
22+
rm_files(all_files)
23+
# puts 'After callback executed -- dff'
2124
end
2225

23-
def clear_download_files
24-
crdownload_files.append(zip_file_path).compact.each { |f| FileUtils.rm_f(f) }
25-
end
26+
# def clear_download_files
27+
# crdownload_files.append(zip_file_path).compact.each { |f| FileUtils.rm_f(f) }
28+
# end
2629

27-
def wait_for_download(zip_file_path, timeout: 5)
28-
start_time = Time.current
30+
# def wait_for_download(zip_file_path, timeout: 5)
31+
# start_time = Time.current
2932

30-
loop do
31-
elapsed_time = Time.current - start_time
32-
raise "Error: Timeout waiting for downloading #{zip_file_path}" if elapsed_time > timeout
33-
return true if File.exist?(zip_file_path)
33+
# loop do
34+
# elapsed_time = Time.current - start_time
35+
# raise "Error: Timeout waiting for downloading #{zip_file_path}" if elapsed_time > timeout
36+
# return true if File.exist?(zip_file_path)
3437

35-
sleep 1
36-
end
37-
rescue StandardError => e
38-
Rails.logger.error e.message
39-
false
40-
end
38+
# sleep 1
39+
# end
40+
# rescue StandardError => e
41+
# Rails.logger.error e.message
42+
# false
43+
# end
4144

4245
context 'verify original data.zip file' do
4346
before do
44-
find('#downloads-button').click
47+
click_download_button
48+
# find('#downloads-button').click
4549
end
4650
it 'click link to download original source data zip file' do
4751
find_link('Original Shapefile').click
@@ -53,8 +57,8 @@ def wait_for_download(zip_file_path, timeout: 5)
5357
expect(file_names).to include('SanBenito_Intersections_2016.shp'), 'Error: SanBenito_Intersections_2016.shp not found in data.zip'
5458
end
5559
else
56-
expect(File.exist?(crdownload_file)).to be_truthy, "Error: Download not completed and incompleted data.zip.crdownload file found: #{crdownload_file}"
57-
expect(File.size(crdownload_file)).to be > 130_000, 'Error: Incompleted data.zip.crdownload file size <= 130000'
60+
expect(File.exist?(zip_crdownload_file)).to be_truthy, "Error: Download not completed and incompleted data.zip.crdownload file found: #{zip_crdownload_file}"
61+
expect(File.size(zip_crdownload_file)).to be > 130_000, 'Error: Incompleted data.zip.crdownload file size <= 130000'
5862
end
5963
end
6064
end

spec/features/export_geofile_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88

99
before do
1010
FileUtils.mkdir_p(download_dir)
11-
visit 'catalog/berkeley-s7038h'
12-
find('#downloads-button').click
11+
visit_public_record
12+
click_download_button
13+
# visit 'catalog/berkeley-s7038h'
14+
# find('#downloads-button').click
1315
end
1416

1517
# after(:each) do

spec/rails_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
require 'capybara/rspec'
1010
require 'selenium-webdriver'
1111
require 'socket'
12+
require_relative 'support/common_helpers'
1213

1314
Capybara.register_driver(:remote_chrome) do |app|
1415
# chrome_args = %w[
@@ -102,6 +103,7 @@
102103
Capybara.run_server = false
103104

104105
RSpec.configure do |config|
106+
config.include CommonHelpers
105107
config.before(:each, type: :system) do
106108
driven_by :remote_chrome
107109
end

spec/support/common_helpers.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module CommonHelpers
2+
def visit_public_record
3+
visit 'catalog/berkeley-s7038h'
4+
end
5+
6+
def visit_restricted_record
7+
visit '/catalog/berkeley-s7b12n'
8+
end
9+
10+
def click_download_button
11+
find('#downloads-button').click
12+
end
13+
14+
def rm_files(file_paths)
15+
file_paths.compact.each { |f| FileUtils.rm_f(f) }
16+
Capybara.reset_sessions!
17+
end
18+
19+
def wait_for_download(zip_file_path, timeout: 5)
20+
start_time = Time.current
21+
22+
loop do
23+
elapsed_time = Time.current - start_time
24+
raise "Error: Timeout waiting for downloading #{zip_file_path}" if elapsed_time > timeout
25+
return true if File.exist?(zip_file_path)
26+
27+
sleep 1
28+
end
29+
rescue StandardError => e
30+
Rails.logger.error e.message
31+
false
32+
end
33+
34+
def decoded_url(url)
35+
uri = URI.parse(url)
36+
decoded_query = URI.decode_www_form_component(uri.query)
37+
URI.decode_www_form_component("#{uri.path}?#{decoded_query}")
38+
end
39+
40+
end

spec/system/restricted_access_spec.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
let(:app_hostname) { IPSocket.getaddress(Socket.gethostname) }
55
let(:cas_url) { "/cas/login?service=http://#{app_hostname}:3000/users/auth/calnet/callback?url=http://#{app_hostname}:3000/catalog/berkeley-s7b12n" }
66
before do
7-
visit '/catalog/berkeley-s7b12n'
7+
visit_restricted_record
8+
# visit '/catalog/berkeley-s7b12n'
89
end
910

10-
def decoded_url(url)
11-
uri = URI.parse(url)
12-
decoded_query = URI.decode_www_form_component(uri.query)
13-
URI.decode_www_form_component("#{uri.path}?#{decoded_query}")
14-
end
11+
# def decoded_url(url)
12+
# uri = URI.parse(url)
13+
# decoded_query = URI.decode_www_form_component(uri.query)
14+
# URI.decode_www_form_component("#{uri.path}?#{decoded_query}")
15+
# end
1516

1617
it 'display login to view and download link' do
1718
expect(page).to have_link('Login to View and Download')

0 commit comments

Comments
 (0)