Skip to content

Commit

Permalink
fix: deprecate ALIASES and corresponding define_method(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericdeansanchez committed Jul 16, 2020
1 parent e4dbf5a commit 48b7232
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 9 deletions.
4 changes: 4 additions & 0 deletions lib/imgix/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,14 @@ def method_missing(method, *args, &block)

ALIASES.each do |from, to|
define_method from do |*args|
warn "Warning `Path.#{from}' has been deprecated and " \
"will be removed in the next major version.\n"
self.send(to, *args)
end

define_method "#{from}=" do |*args|
warn "Warning `Path.#{from}=' has been deprecated and " \
"will be removed in the next major version.\n"
self.send("#{to}=", *args)
return self
end
Expand Down
31 changes: 27 additions & 4 deletions test/units/path_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,34 @@ def test_creating_a_path
def test_signing_path_with_param
url = 'https://demo.imgix.net/images/demo.png?w=200&s=da421114ca238d1f4a927b889f67c34e'
path = client.path('/images/demo.png')
path.width = 200

assert_output(nil, "Warning `Path.width=' has been deprecated and " \
"will be removed in the next major version.\n") {
path.width = 200
}

assert_equal url, path.to_url

path = client.path('/images/demo.png')
assert_equal url, path.to_url(w: 200)

path = client.path('/images/demo.png')
assert_equal url, path.width(200).to_url

assert_output(nil, "Warning `Path.width' has been deprecated and " \
"will be removed in the next major version.\n") {
assert_equal url, path.width(200).to_url
}
end

def test_resetting_defaults
url = 'https://demo.imgix.net/images/demo.png?w=200&s=da421114ca238d1f4a927b889f67c34e'
path = client.path('/images/demo.png')
path.height = 300

assert_output(nil, "Warning `Path.height=' has been deprecated and " \
"will be removed in the next major version.\n") {
path.height = 300
}


assert_equal url, path.defaults.to_url(w: 200)
end
Expand All @@ -40,7 +53,17 @@ def test_path_with_multiple_params
assert_equal url, path.to_url(h: 200, w: 200)

path = client.path('/images/demo.png')
assert_equal url, path.height(200).width(200).to_url
assert_output(nil, "Warning `Path.height' has been deprecated and " \
"will be removed in the next major version.\n") {
path.height(200)
}

assert_output(nil, "Warning `Path.width' has been deprecated and " \
"will be removed in the next major version.\n") {
path.width(200)
}

assert_equal url, path.to_url
end

def test_path_with_multi_value_param_safely_encoded
Expand Down
31 changes: 26 additions & 5 deletions test/units/url_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,41 @@ def test_signing_with_no_params

def test_signing_with_one
path = client.path(DEMO_IMAGE_PATH)
path.width = 200

assert_output(nil, "Warning `Path.width=' has been deprecated and " \
"will be removed in the next major version.\n") {
path.width = 200
}

assert_equal 'https://demo.imgix.net/images/demo.png?w=200&s=da421114ca238d1f4a927b889f67c34e', path.to_url
end

def test_signing_with_multiple_params
path = client.path(DEMO_IMAGE_PATH)
path.height = 200
path.width = 200

assert_output(nil, "Warning `Path.height=' has been deprecated and " \
"will be removed in the next major version.\n") {
path.height = 200
}

assert_output(nil, "Warning `Path.width=' has been deprecated and " \
"will be removed in the next major version.\n") {
path.width = 200
}
assert_equal 'https://demo.imgix.net/images/demo.png?h=200&w=200&s=d570a1ecd765470f7b34a69b56718a7a', path.to_url

path = client.path(DEMO_IMAGE_PATH)
path.width = 200
path.height = 200

assert_output(nil, "Warning `Path.width=' has been deprecated and " \
"will be removed in the next major version.\n") {
path.width = 200
}

assert_output(nil, "Warning `Path.height=' has been deprecated and " \
"will be removed in the next major version.\n") {
path.height = 200
}

assert_equal 'https://demo.imgix.net/images/demo.png?w=200&h=200&s=00b5cde5c7b8bca8618cb911da4ac379', path.to_url
end

Expand Down

0 comments on commit 48b7232

Please sign in to comment.