aboutsummaryrefslogtreecommitdiffstats
path: root/spec/services/file_service_spec.rb
diff options
context:
space:
mode:
authorRobert2017-07-23 22:56:12 +0200
committerRobert2017-07-25 21:31:51 +0200
commitfe46c7832fa1e0c6af450f0937aea3534c0f6b01 (patch)
tree60670a6ac730a081c3627f25a44c0bd78ea90d3a /spec/services/file_service_spec.rb
parent384a06676b8e0985f39fbc894a2d7dd458823529 (diff)
downloadchouette-core-fe46c7832fa1e0c6af450f0937aea3534c0f6b01.tar.bz2
Refs: #3507;20h Specing and Implementing the ZipService
Diffstat (limited to 'spec/services/file_service_spec.rb')
-rw-r--r--spec/services/file_service_spec.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/spec/services/file_service_spec.rb b/spec/services/file_service_spec.rb
new file mode 100644
index 000000000..90e164408
--- /dev/null
+++ b/spec/services/file_service_spec.rb
@@ -0,0 +1,16 @@
+RSpec.describe FileService do
+
+ it 'computes a unique filename' do
+ expect( File ).to receive(:exists?).with('xxx/yyy_0').and_return( false )
+
+ expect(described_class.unique_filename('xxx/yyy')).to eq('xxx/yyy_0')
+ end
+
+ it 'handles duplicate names by means of a counter' do
+ expect( File ).to receive(:exists?).with('xxx/yyy_0').and_return( true )
+ expect( File ).to receive(:exists?).with('xxx/yyy_1').and_return( true )
+ expect( File ).to receive(:exists?).with('xxx/yyy_2').and_return( false )
+
+ expect(described_class.unique_filename('xxx/yyy')).to eq('xxx/yyy_2')
+ end
+end