Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attachment default_url should allow nil #55

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/paperclip/interpolations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def self.all
# You can pass a method name on your record as a symbol, which should turn
# an interpolation pattern for Paperclip to use.
def self.interpolate(pattern, *args)
return if pattern.nil?
pattern = args.first.instance.send(pattern) if pattern.is_a? Symbol
result = pattern.dup
interpolators_cache.each do |method, token|
Expand Down
1 change: 1 addition & 0 deletions lib/paperclip/url_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def for(style_name, options)
interpolated = attachment_options[:interpolator].interpolate(
most_appropriate_url, @attachment, style_name
)
return unless interpolated

escaped = escape_url_as_needed(interpolated, options)
timestamp_as_needed(escaped, options)
Expand Down
15 changes: 15 additions & 0 deletions spec/paperclip/attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,21 @@
end
end

context 'without an Attachment and default_url nil' do
before do
rebuild_model default_url: nil
@dummy = Dummy.new
end

it 'returns false when asked exists?' do
assert [email protected]?
end

it '#url returns the default_url' do
expect(@dummy.avatar.url).to eq nil
end
end

context "on an Attachment" do
before do
@dummy = Dummy.new
Expand Down