Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Default url with interpolation #16

Closed
wants to merge 2 commits into from

3 participants

@ramkumarmk

Default url returned when there is no attachment, was using the defaut_url mentioned in the options, but was not supporting interpolation. As Paperclip supports interpolation for all urls including default_url, I have added support for interpolation in default url in this gem which wasn't working earlier.

@janko-m janko-m closed this pull request from a commit
@janko-m Interpolate :default_url.
Thanks to @sasikumar87 and @ramkumarmk. Fixes #16.
5bcbfb7
@janko-m janko-m closed this in 5bcbfb7
@janko-m
Owner

Hey guys. I wasn't able to merge this because I made too much changes. Sorry it took me. And thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
6 lib/paperclip/storage/dropbox.rb
@@ -45,9 +45,9 @@ def exists?(style)
end
def url(*args)
+ style = args.first.is_a?(Symbol) ? args.first : default_style
+ options = args.last.is_a?(Hash) ? args.last : {}
if present?
- style = args.first.is_a?(Symbol) ? args.first : default_style
- options = args.last.is_a?(Hash) ? args.last : {}
query = options[:download] ? "?dl=1" : ""
if app_folder_mode
@@ -56,7 +56,7 @@ def url(*args)
File.join("http://dl.dropbox.com/u/#{user_id}", path_for_url(style) + query)
end
else
- @options[:default_url]
+ @url_generator.for(style,options)
end
end
View
24 spec/paperclip/storage/dropbox_spec.rb
@@ -205,6 +205,30 @@ def set_access_type(access_type)
end
end
end
+ context "interpolated default url if it has no attachment " do
+ def set_access_type(access_type)
+ stub_const("User", Class.new(ActiveRecord::Base) do
+ has_attached_file :avatar,
+ storage: :dropbox,
+ dropbox_credentials: CREDENTIALS_FILE[access_type],
+ styles: { medium: "300x300" },
+ default_url: ":style/missing.gif"
+ end)
+ end
+
+ it "returns url based on style if style not mentioned" do
+ set_access_type(:dropbox)
+ @user = User.create()
+ @user.avatar.url.should == "original/missing.gif"
+ end
+
+ it "returns url based on style mentioned" do
+ set_access_type(:dropbox)
+ @user = User.create()
+ @user.avatar.url(:medium).should == "medium/missing.gif"
+ end
+
+ end
end
describe "#path" do
Something went wrong with that request. Please try again.