From 3bb318c7bfbd2c858cf22f668c0f2b379f30b3c9 Mon Sep 17 00:00:00 2001 From: Yorick Holkamp Date: Wed, 18 Dec 2019 13:42:12 +0100 Subject: [PATCH] Patch image model; include image_data as allowed property and prefer to use the data over the configured URL, added test to assert the image_data is set --- lib/caracal/core/models/image_model.rb | 4 ++-- spec/lib/caracal/core/images_spec.rb | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/caracal/core/models/image_model.rb b/lib/caracal/core/models/image_model.rb index 45ba2232..21e95efe 100644 --- a/lib/caracal/core/models/image_model.rb +++ b/lib/caracal/core/models/image_model.rb @@ -72,7 +72,7 @@ def initialize(options={}, &block) end def relationship_target - image_url || image_data + image_data || image_url end @@ -115,7 +115,7 @@ def valid? private def option_keys - [:url, :width, :height, :align, :top, :bottom, :left, :right] + [:url, :width, :height, :align, :top, :bottom, :left, :right, :data] end def pixels_to_emus(value, ppi) diff --git a/spec/lib/caracal/core/images_spec.rb b/spec/lib/caracal/core/images_spec.rb index 45b173bc..1c255e84 100644 --- a/spec/lib/caracal/core/images_spec.rb +++ b/spec/lib/caracal/core/images_spec.rb @@ -14,10 +14,11 @@ describe '.img' do let!(:size) { subject.contents.size } - before { subject.img 'https://www.google.com/images/srpr/logo11w.png', width: 538, height: 190 } + before { subject.img 'https://www.google.com/images/srpr/logo11w.png', width: 538, height: 190, data: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/D/PwAHAwL/qGeMxAAAAABJRU5ErkJggg==" } it { expect(subject.contents.size).to eq size + 1 } it { expect(subject.contents.last).to be_a(Caracal::Core::Models::ImageModel) } + it { expect(subject.contents.last.image_data).to be_truthy} end end