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

Fix deprecation warnings about using URI.escape method #35

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
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ env:
- RAILS_VERSION=3
- RAILS_VERSION=4
- RAILS_VERSION=5
- RAILS_VERSION=6
- RAILS_VERSION=master

rvm:
Expand All @@ -13,19 +14,40 @@ rvm:
- 2.2
- 2.3
- 2.4
- 2.5
- 2.6
- 2.7
- ruby-head

matrix:
exclude:
- rvm: 1.9
env: RAILS_VERSION=5
- rvm: 1.9
env: RAILS_VERSION=6
- rvm: 1.9
env: RAILS_VERSION=master
- rvm: 2.0
env: RAILS_VERSION=5
- rvm: 2.0
env: RAILS_VERSION=6
- rvm: 2.0
env: RAILS_VERSION=master
- rvm: 2.1
env: RAILS_VERSION=5
- rvm: 2.1
env: RAILS_VERSION=6
- rvm: 2.1
env: RAILS_VERSION=master
- rvm: 2.2
env: RAILS_VERSION=6
- rvm: 2.2
env: RAILS_VERSION=master
- rvm: 2.3
env: RAILS_VERSION=6
- rvm: 2.3
env: RAILS_VERSION=master
- rvm: 2.4
env: RAILS_VERSION=6
- rvm: 2.4
env: RAILS_VERSION=master
7 changes: 1 addition & 6 deletions lib/gravatar_image_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,10 @@ def self.gravatar_id(email, filetype = nil)

def self.url_params(gravatar_params)
return nil if gravatar_params.keys.size == 0
array = gravatar_params.map { |k, v| "#{k}=#{value_cleaner(v)}" }
array = gravatar_params.map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }
"?#{array.join('&')}"
end

def self.value_cleaner(value)
value = value.to_s
URI.escape(value, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
end

end

ActionView::Base.send(:include, GravatarImageTag) if defined?(ActionView::Base)
8 changes: 5 additions & 3 deletions spec/gravatar_image_tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
other_image_escaped = 'http%3A%2F%2Fmdeering.com%2Fimages%2Fother_gravatar.png'
secure = false

view = ActionView::Base.new
let(:view) { ActionView::Base.new(ActionView::LookupContext.new([])) }

context '#gravatar_image_tag' do

Expand All @@ -29,7 +29,6 @@
{ gravatar_id: md5, default: other_image_escaped, size: 30 } => { gravatar: { default: other_image, size: 30 } }
}.each do |params, options|
it "#gravatar_image_tag should create the provided url with the provided options #{options}" do
view = ActionView::Base.new
image_tag = view.gravatar_image_tag(email, options)
expect(image_tag.include?("#{params.delete(:gravatar_id)}")).to be_truthy
expect(params.all? {|key, value| image_tag.include?("#{key}=#{value}")}).to be_truthy
Expand Down Expand Up @@ -62,7 +61,6 @@
{ gravatar_id: md5, size: 30, default: other_image_escaped } => { gravatar: { default: other_image, size: 30 } },
}.each do |params, options|
it "#gravatar_image_tag #{params} should create the provided url when defaults have been set with the provided options #{options}" do
view = ActionView::Base.new
image_tag = view.gravatar_image_tag(email, options)
expect(image_tag.include?("#{params.delete(:gravatar_id)}.#{default_filetype}")).to be_truthy
expect(params.all? {|key, value| image_tag.include?("#{key}=#{value}")}).to be_truthy
Expand Down Expand Up @@ -145,6 +143,10 @@
expect(!!view.gravatar_image_url(email, secure: true).match("^https:\/\/secure.gravatar.com\/avatar\/")).to be_truthy
end

it 'expect not to issue any deprecation warnings ' do
expect { view.gravatar_image_url(email, secure: true, rating: 'pg') }.not_to output.to_stderr
end

end

end