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

Pass crop parameter in default EssencePicture#picture_url_options #2098

Merged
merged 1 commit into from
May 13, 2021
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: 3 additions & 0 deletions app/models/alchemy/essence_picture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ def picture_url(options = {})
def picture_url_options
return {} if picture.nil?

crop = crop_values_present? || content.settings[:crop]

{
format: picture.default_render_format,
crop: !!crop,
crop_from: crop_from.presence,
crop_size: crop_size.presence,
size: content.settings[:size],
Expand Down
35 changes: 25 additions & 10 deletions spec/models/alchemy/essence_picture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ module Alchemy
end

context "when crop sizes are present" do
before do
expect(essence).to receive(:crop_size).and_return("200x200")
expect(essence).to receive(:crop_from).and_return("10x10")
let(:essence) do
create(:alchemy_essence_picture, :with_content, picture: picture, crop_size: "200x200", crop_from: "10x10")
end

it "passes these crop sizes to the picture's url method." do
Expand Down Expand Up @@ -150,40 +149,56 @@ module Alchemy
end

context "with crop sizes present" do
before do
expect(essence).to receive(:crop_size) { "200x200" }
expect(essence).to receive(:crop_from) { "10x10" }
let(:essence) do
create(:alchemy_essence_picture, :with_content, picture: picture, crop_size: "200x200", crop_from: "10x10")
end

it "includes these crop sizes.", :aggregate_failures do
expect(picture_url_options[:crop_from]).to eq "10x10"
expect(picture_url_options[:crop_size]).to eq "200x200"
end

it "includes {crop: true}" do
expect(picture_url_options[:crop]).to be true
end
end

# Regression spec for issue #1279
context "with crop sizes being empty strings" do
before do
expect(essence).to receive(:crop_size) { "" }
expect(essence).to receive(:crop_from) { "" }
let(:essence) do
create(:alchemy_essence_picture, :with_content, picture: picture, crop_size: "", crop_from: "")
end

it "does not include these crop sizes.", :aggregate_failures do
expect(picture_url_options[:crop_from]).to be_nil
expect(picture_url_options[:crop_size]).to be_nil
end

it "includes {crop: false}" do
expect(picture_url_options[:crop]).to be false
end
end

context "with content having size setting" do
before do
expect(essence.content).to receive(:settings) { {size: "30x70"} }
expect(essence.content).to receive(:settings).twice { {size: "30x70"} }
end

it "includes this size." do
expect(picture_url_options[:size]).to eq "30x70"
end
end

context "with content having crop setting" do
before do
expect(essence.content).to receive(:settings).twice { {crop: true} }
end

it "includes this setting" do
expect(picture_url_options[:crop]).to be true
end
end

context "without picture assigned" do
let(:picture) { nil }

Expand Down