Skip to content

Commit

Permalink
Patch image model; include image_data as allowed property and prefer …
Browse files Browse the repository at this point in the history
…to use the data over the configured URL, added test to assert the image_data is set
  • Loading branch information
yholkamp committed Dec 18, 2019
1 parent 562bdc4 commit 3bb318c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/caracal/core/models/image_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def initialize(options={}, &block)
end

def relationship_target
image_url || image_data
image_data || image_url
end


Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion spec/lib/caracal/core/images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3bb318c

Please sign in to comment.