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

chore: remove deprecated domain sharding behavior #80

Merged
merged 6 commits into from
Nov 5, 2019
Merged
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
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

imgix is a real-time image processing service and CDN. It allows you to manipulate images merely by changing their URL parameters. For a full list of URL parameters, please see the [imgix URL API documentation](https://www.imgix.com/docs/reference).

We recommend using something like [Paperclip](https://github.com/thoughtbot/paperclip), [Refile](https://github.com/refile/refile), [Carrierwave](https://github.com/carrierwaveuploader/carrierwave), or [s3_direct_upload](https://github.com/waynehoover/s3_direct_upload) to handle uploads. After they've been uploaded, you can then serve them using this gem.
We recommend using something like [Paperclip](https://github.com/thoughtbot/paperclip), [Refile](https://github.com/refile/refile), [Carrierwave](https://github.com/carrierwaveuploader/carrierwave), or [Active Storage](https://github.com/rails/rails/tree/master/activestorage) to handle uploads. After they've been uploaded, you can then serve them using this gem.

* [Installation](#installation)
* [Usage](#usage)
Expand Down Expand Up @@ -61,7 +61,6 @@ The following configuration flags will be respected:
- `:source` a String or Array that specifies the imgix Source address. Should be in the form of `"assets.imgix.net"`.
- `:srcset_width_tolerance` an optional numeric value determining the maximum tolerance allowable, between the downloaded dimensions and rendered dimensions of the image (default `.08` i.e. `8%`).
- `:secure_url_token` an optional secure URL token found in your dashboard (https://dashboard.imgix.com) used for signing requests
- `:shard_strategy` Specify [domain sharding strategy](https://github.com/imgix/imgix-rb#domain-sharded-urls) with multiple sources. Acceptable values are `:cycle` and `:crc`. `:crc` is used by default.

#### Multi-source configuration

Expand Down
1 change: 0 additions & 1 deletion lib/imgix/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

module Imgix
module Rails
STRATEGIES = [:crc, :cycle]
class Config < ::ActiveSupport::OrderedOptions; end

def self.config
Expand Down
14 changes: 2 additions & 12 deletions lib/imgix/rails/url_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def validate_configuration!
end

if imgix[:source]
unless imgix[:source].is_a?(Array) || imgix[:source].is_a?(String)
raise ConfigurationError.new("imgix source must be a String or an Array.")
unless imgix[:source].is_a?(String)
raise ConfigurationError.new("imgix source must be a String.")
end
end

Expand All @@ -54,10 +54,6 @@ def validate_configuration!
raise ConfigurationError.new(":sources must be a Hash")
end
end

unless !imgix.key?(:shard_strategy) || STRATEGIES.include?(imgix[:shard_strategy])
raise ConfigurationError.new("#{imgix[:shard_strategy]} is not supported")
end
end

def imgix_client(source)
Expand All @@ -80,8 +76,6 @@ def imgix_clients

if imgix[:source].is_a?(String)
opts[:host] = imgix[:source]
else
opts[:hosts] = imgix[:source]
end

if imgix.has_key?(:include_library_param)
Expand All @@ -92,10 +86,6 @@ def imgix_clients
opts[:use_https] = imgix[:use_https]
end

if imgix.has_key?(:shard_strategy)
opts[:shard_strategy] = imgix[:shard_strategy]
end

sources = imgix[:sources] || { imgix[:source] => imgix[:secure_url_token] }
@imgix_clients = {}

Expand Down
45 changes: 2 additions & 43 deletions spec/imgix/rails/url_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
}.to raise_error(Imgix::Rails::ConfigurationError)
end

it 'expects config.imgix.source to be a String or an Array' do
it 'expects config.imgix.source to be a String' do
Imgix::Rails.configure { |config| config.imgix = { source: 1 } }

expect{
url_helper.ix_image_url("assets.png")
}.to raise_error(Imgix::Rails::ConfigurationError, "imgix source must be a String or an Array.")
}.to raise_error(Imgix::Rails::ConfigurationError, "imgix source must be a String.")
end

it 'optionally expects config.imgix.secure_url_token to be defined' do
Expand Down Expand Up @@ -82,46 +82,5 @@
expect(url_helper.ix_image_url("image.jpg")).to eq "http://assets.imgix.net/image.jpg?ixlib=rails-#{Imgix::Rails::VERSION}"
end
end

describe 'optionally expects shard_strategy' do
it 'optionally expects crc shard_strategy' do
Imgix::Rails.configure do |config|
config.imgix = {
source: 'assets.imgix.net',
shard_strategy: :crc
}
end

expect{
url_helper.ix_image_url("assets.png")
}.not_to raise_error
end

it 'optionally expects cycle shard_strategy' do
Imgix::Rails.configure do |config|
config.imgix = {
source: 'assets.imgix.net',
shard_strategy: :cycle
}
end

expect{
url_helper.ix_image_url("assets.png")
}.not_to raise_error
end
end

it 'expects shard_strategy to be :crc or :cycle' do
Imgix::Rails.configure do |config|
config.imgix = {
source: 'assets.imgix.net',
shard_strategy: :foo
}
end

expect{
url_helper.ix_image_url("assets.png")
}.to raise_error(Imgix::Rails::ConfigurationError, "foo is not supported")
end
end
end
35 changes: 31 additions & 4 deletions spec/imgix/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,40 @@
}.to raise_error(Imgix::Rails::ConfigurationError)
end

it 'expects config.imgix.source to be a String or an Array' do
it 'expects config.imgix.source to be a String' do
Imgix::Rails.configure { |config| config.imgix = { source: 1 } }

expect{
helper.ix_image_tag("assets.png")
}.to raise_error(Imgix::Rails::ConfigurationError, "imgix source must be a String or an Array.")
}.to raise_error(Imgix::Rails::ConfigurationError, "imgix source must be a String.")
end

it 'expects either a :source or :sources, but not both' do
Imgix::Rails.configure { |config| config.imgix = { source: "domain1", sources: "domain2" } }

expect{
helper.ix_image_url("assets.png")
}.to raise_error(Imgix::Rails::ConfigurationError, "Exactly one of :source, :sources is required")
end

it 'expects :sources to be a hash' do
Imgix::Rails.configure { |config|
config.imgix = {
sources: 1
}
}

expect{
helper.ix_image_url("assets.png")
}.to raise_error(Imgix::Rails::ConfigurationError, ":sources must be a Hash")
end

it 'validates an imgix domain' do
Imgix::Rails.configure { |config| config.imgix = { source: "domain1" } }

expect{
helper.ix_image_url("assets.png")
}.to raise_error(ArgumentError)
end

it 'optionally expects config.imgix.secure_url_token to be defined' do
Expand Down Expand Up @@ -105,10 +133,9 @@
it 'raises error when path not supplied' do
expect{
helper.ix_image_url()
}.to raise_error
}.to raise_error(RuntimeError)
end


it 'signs image URLs with ixlib=rails' do
image_url = URI.parse(helper.ix_image_url("image.jpg", { h: 300, w: 400 }))
url_query = CGI::parse(image_url.query)
Expand Down