specify and implement behaviour of Depot#get_file when there is a link with no matchi...
authorLunar <lunar@anargeek.net>
Tue, 6 Mar 2012 16:03:00 +0000 (17:03 +0100)
committerLunar <lunar@anargeek.net>
Fri, 23 Mar 2012 17:11:29 +0000 (18:11 +0100)
We modify callers in Coquelicot::Application to match the new behaviour.

lib/coquelicot/app.rb
lib/coquelicot/depot.rb
spec/coquelicot/depot_spec.rb

index dfd7ddd..5170b26 100644 (file)
@@ -82,11 +82,10 @@ module Coquelicot
       not_found if link.nil?
 
       link, pass = link.split '-' if link.include? '-'
-      begin
-        file = Coquelicot.depot.get_file(link, nil)
-      rescue Errno::ENOENT => ex
-        not_found
-      end
+      file = Coquelicot.depot.get_file(link, nil)
+
+      not_found if file.nil?
+
       @expire_at = file.expire_at
       @name = "#{link}"
       unless pass.nil?
index 31f4e3c..d2068a9 100644 (file)
@@ -53,7 +53,11 @@ module Coquelicot
         name = read_link(link)
       end
       return nil if name.nil?
-      StoredFile::open(full_path(name), pass)
+      begin
+        StoredFile::open(full_path(name), pass)
+      rescue Errno::ENOENT
+        nil
+      end
     end
 
     def file_exists?(link)
index ee16231..6b67f10 100644 (file)
@@ -149,7 +149,15 @@ module Coquelicot
         end
       end
       context 'when there is a link with no matching file' do
-        it 'should return nil'
+        before(:each) do
+          depot.should_receive(:gen_random_file_name).
+            and_return('file', 'link')
+          @link = add_file
+          File.unlink File.expand_path('file', @tmpdir)
+        end
+        it 'should return nil' do
+          depot.get_file(@link).should be_nil
+        end
       end
     end