Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Commit

Permalink
create a private url generator when the private visibility option is set
Browse files Browse the repository at this point in the history
  • Loading branch information
dougbradbury committed Dec 14, 2013
1 parent a0f77a3 commit ea9421b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/paperclip/storage/dropbox/generator_factory.rb
Expand Up @@ -5,7 +5,7 @@ module Storage
module Dropbox
module GeneratorFactory
def self.build_url_generator(storage, options)
if options[:dropbox_credentials][:access_type] == "app_folder"
if options[:dropbox_credentials][:access_type] == "app_folder" || options[:dropbox_visibility] == "private"
PrivateUrlGenerator.new(storage, options)
elsif options[:dropbox_credentials][:access_type] == "dropbox"
PublicUrlGenerator.new(storage, options)
Expand Down
2 changes: 1 addition & 1 deletion lib/paperclip/storage/dropbox/public_url_generator.rb
Expand Up @@ -6,7 +6,7 @@ class PublicUrlGenerator < UrlGenerator
def file_url(style)
url = URI.parse("https://dl.dropboxusercontent.com/u/#{user_id}/")
path = @attachment.path(style)
path = path.match(/^Public\//).post_match
path = path.match(/^Public\//).try(:post_match)
url.merge!(path)
url.to_s
end
Expand Down
22 changes: 22 additions & 0 deletions spec/lib/paperclip/storage/dropbox/generator_factor_spec.rb
@@ -0,0 +1,22 @@
require "spec_helper"
require "paperclip/storage/dropbox/generator_factory"

describe Paperclip::Storage::Dropbox::GeneratorFactory do
it "should build a private url generator" do
described_class.build_url_generator(double(:storage), {
dropbox_credentials: {access_type: "app_folder"}}).should be_a(Paperclip::Storage::Dropbox::PrivateUrlGenerator)
end

it "should build a private url generator" do
described_class.build_url_generator(double(:storage), {
dropbox_credentials: { access_type: "dropbox" },
dropbox_visibility: 'private'}).should be_a(Paperclip::Storage::Dropbox::PrivateUrlGenerator)
end

it "should build a public url generator" do
described_class.build_url_generator(double(:storage), {
dropbox_credentials: { access_type: "dropbox" },
dropbox_visibility: 'public'}).should be_a(Paperclip::Storage::Dropbox::PublicUrlGenerator)
end
end

0 comments on commit ea9421b

Please sign in to comment.