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

Fix ImageModel missing :data option key #149

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion lib/caracal/core/models/iframe_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Caracal
module Core
module Models

# This class handles block options passed to the img method.
# This class handles block options passed to the iframe method.
#
class IFrameModel < BaseModel

Expand Down
2 changes: 1 addition & 1 deletion lib/caracal/core/models/image_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def valid?
private

def option_keys
[:url, :width, :height, :align, :top, :bottom, :left, :right]
[:url, :data, :width, :height, :align, :top, :bottom, :left, :right]
end

def pixels_to_emus(value, ppi)
Expand Down
23 changes: 18 additions & 5 deletions spec/lib/caracal/core/images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,24 @@
# .img
describe '.img' do
let!(:size) { subject.contents.size }

before { subject.img 'https://www.google.com/images/srpr/logo11w.png', width: 538, height: 190 }

it { expect(subject.contents.size).to eq size + 1 }
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::ImageModel) }
let!(:url) { 'https://www.google.com/images/srpr/logo11w.png' }

describe 'when no data provided' do
before { subject.img url, width: 538, height: 190 }

it { expect(subject.contents.size).to eq size + 1 }
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::ImageModel) }
end

describe 'when data provided as binary' do
let!(:binary_data) { open(url).read }

before { subject.img url, data: binary_data, width: 538, height: 190 }

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 eq binary_data }
end
end

end
Expand Down