Skip to content

Commit

Permalink
Get the key from the model instead of the url. This makes sure we don…
Browse files Browse the repository at this point in the history
…t get the key from the temp_cache when recreating versions
  • Loading branch information
p8 committed Feb 7, 2016
1 parent 0af6c9e commit 6c022cb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
3 changes: 2 additions & 1 deletion lib/carrierwave_direct/uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def persisted?
def key
return @key if @key.present?
if present?
self.key = decoded_key # explicitly set key
identifier = model.send("#{mounted_as}_identifier")
self.key = "#{store_dir}/#{identifier}"
else
@key = "#{store_dir}/#{guid}/#{FILENAME_WILDCARD}"
end
Expand Down
16 changes: 2 additions & 14 deletions spec/uploader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
include ModelHelpers

let(:subject) { DirectUploader.new }
let(:mounted_model) { double(sample(:mounted_model_name)) }
let(:mounted_model) { double(sample(:mounted_model_name), video_identifier: sample(:stored_filename)) }
let(:mounted_subject) { DirectUploader.new(mounted_model, sample(:mounted_as)) }
let(:direct_subject) { DirectUploader.new }

Expand Down Expand Up @@ -73,6 +73,7 @@

context "but the uploaders url is '#{sample(:s3_file_url)}'" do
before do
allow(mounted_subject).to receive(:store_dir).and_return(sample(:store_dir))
allow(mounted_subject).to receive(:url).and_return(sample(:s3_file_url))
allow(mounted_subject).to receive(:present?).and_return(true)
end
Expand Down Expand Up @@ -253,19 +254,6 @@
end
end

context "and the model's remote url contains already escaped characters" do
before do
subject.key = nil
allow(subject).to receive(:present?).and_return(:true)
allow(subject).to receive(:url).and_return("http://anyurl.com/any_path/video_dir/filename%20%28%29%2B%5B%5D2.avi")
end

it "should not double escape already escaped characters" do
expect(subject.key).to match /filename \(\)\+\[\]2.avi/
end

end

context "and the model's remote #{sample(:mounted_as)} url is blank" do
before do
allow(mounted_model).to receive(
Expand Down

0 comments on commit 6c022cb

Please sign in to comment.