Skip to content
This repository was archived by the owner on Oct 22, 2020. It is now read-only.

Commit 3879832

Browse files
committed
Add #before_download method to FileDownload mixin
1 parent e79b231 commit 3879832

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/wpxf/wordpress/file_download.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,18 @@ def validate_content(content)
7676
true
7777
end
7878

79+
# A task to run before the download starts.
80+
# @return [Boolean] true if pre-download operations were successful.
81+
def before_download
82+
true
83+
end
84+
7985
# Run the module.
8086
# @return [Boolean] true if successful.
8187
def run
8288
validate_implementation
8389

84-
return false unless super
90+
return false unless super || !before_download
8591

8692
res = request_file
8793
return false unless validate_result(res) && validate_content(res.body)

spec/wordpress/file_download_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,11 @@
3838
'A value must be specified for #working_directory'
3939
)
4040
end
41+
42+
it 'when #before_download returns false, return false' do
43+
allow(subject).to receive(:before_download).and_return(false)
44+
allow(subject).to receive(:working_directory).and_return('wp-content')
45+
expect(subject.run).to be false
46+
end
4147
end
4248
end

0 commit comments

Comments
 (0)