Skip to content

Commit

Permalink
Quick fix methods width/height not correct for rmagick calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jnormington committed Aug 6, 2016
1 parent 32a7416 commit e124a15
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
10 changes: 6 additions & 4 deletions lib/dotdiff/image/cropper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,21 @@ def load_image(file)

def height(element, image)
element_height = element.rectangle.height + element.rectangle.y
image_height = image.rows

if element_height > image.height
image.height - element.rectangle.y
if element_height > image_height
image_height - element.rectangle.y
else
element.rectangle.height
end
end

def width(element, image)
element_width = element.rectangle.width + element.rectangle.x
image_width = image.columns

if element_width > image.width
image.width - element.rectangle.x
if element_width > image_width
image_width - element.rectangle.x
else
element.rectangle.width
end
Expand Down
14 changes: 7 additions & 7 deletions spec/unit/image/cropper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def cropped_file
class MockRMagick
def crop!(x,y,w,h); end
def write(file); end
def width; end
def height; end
def columns; end
def rows; end
end

RSpec.describe DotDiff::Image::Cropper do
Expand All @@ -26,7 +26,7 @@ def height; end
let(:mock_png) { MockRMagick.new }

describe '#load_image' do
it 'calls chunky_png image from file' do
it 'calls rgmagick image read' do
expect(Magick::Image).to receive(:read).with('/home/se/full.png').once.and_return([])
subject.send(:load_image, '/home/se/full.png')
end
Expand Down Expand Up @@ -61,7 +61,7 @@ def height; end
let(:rect) {{ 'top' => -180, 'left' => 0, 'width' => 800, 'height' => 1400 }}

it 'returns the image height minus the top point' do
allow(mock_png).to receive(:height).and_return(1200)
allow(mock_png).to receive(:rows).and_return(1200)
expect(subject.height(element, mock_png)).to eq 1380
end
end
Expand All @@ -70,7 +70,7 @@ def height; end
let(:rect) {{ 'top' => -180, 'left' => 0, 'width' => 500, 'height' => 800 }}

it 'returns the element height' do
allow(mock_png).to receive(:height).and_return(1200)
allow(mock_png).to receive(:rows).and_return(1200)
expect(subject.height(element, mock_png)).to eq 800
end
end
Expand All @@ -83,7 +83,7 @@ def height; end
let(:rect) {{ 'top' => -180, 'left' => -30, 'width' => 731, 'height' => 1200 }}

it 'returns the image width minus the left point' do
allow(mock_png).to receive(:width).and_return(700)
allow(mock_png).to receive(:columns).and_return(700)
expect(subject.width(element, mock_png)).to eq 730
end
end
Expand All @@ -92,7 +92,7 @@ def height; end
let(:rect) {{ 'top' => -180, 'left' => -20, 'width' => 800, 'height' => 800 }}

it 'returns the element width' do
allow(mock_png).to receive(:width).and_return(850)
allow(mock_png).to receive(:columns).and_return(850)
expect(subject.width(element, mock_png)).to eq 800
end
end
Expand Down

0 comments on commit e124a15

Please sign in to comment.