Skip to content

Commit

Permalink
Merge pull request #1703 from AlchemyCMS/read-essence-picture-size-fr…
Browse files Browse the repository at this point in the history
…om-content-settings

Use contents settings for size in EssencePicture#picture_url
  • Loading branch information
tvdeyen authored Jan 4, 2020
2 parents de2cfbc + 05e1c16 commit 7fe465a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/models/alchemy/essence_picture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def picture_url_options
{
format: picture.default_render_format,
crop_from: crop_from.presence,
crop_size: crop_size.presence
crop_size: crop_size.presence,
size: content.settings[:size]
}.with_indifferent_access
end

Expand Down
5 changes: 5 additions & 0 deletions lib/alchemy/test_support/factories/essence_picture_factory.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# frozen_string_literal: true

require 'factory_bot'
require 'alchemy/test_support/factories/content_factory'
require 'alchemy/test_support/factories/picture_factory'

FactoryBot.define do
factory :alchemy_essence_picture, class: 'Alchemy::EssencePicture' do
picture factory: :alchemy_picture

trait :with_content do
association :content, factory: :alchemy_content
end
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%- cache(gallery_picture) do -%>
<%= element_view_for(gallery_picture) do |el| -%>
<%= el.render :picture, size: '160x120' %>
<%= el.render :picture %>
<%- end -%>
<%- end -%>
2 changes: 2 additions & 0 deletions spec/dummy/config/alchemy/elements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@
contents:
- name: picture
type: EssencePicture
settings:
size: 160x120

- name: right_column
fixed: true
Expand Down
14 changes: 12 additions & 2 deletions spec/models/alchemy/essence_picture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module Alchemy

let(:options) { {} }
let(:picture) { create(:alchemy_picture) }
let(:essence) { create(:alchemy_essence_picture, picture: picture) }
let(:essence) { create(:alchemy_essence_picture, :with_content, picture: picture) }

context 'with no format in the options' do
it "includes the image's default render format." do
Expand Down Expand Up @@ -116,7 +116,7 @@ module Alchemy
subject(:picture_url_options) { essence.picture_url_options }

let(:picture) { build_stubbed(:alchemy_picture) }
let(:essence) { build_stubbed(:alchemy_essence_picture, picture: picture) }
let(:essence) { build_stubbed(:alchemy_essence_picture, :with_content, picture: picture) }

it { is_expected.to be_a(HashWithIndifferentAccess) }

Expand Down Expand Up @@ -150,6 +150,16 @@ module Alchemy
end
end

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

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

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

Expand Down

0 comments on commit 7fe465a

Please sign in to comment.