From 10eb21bd1103fc43caeb7f1c890f19853712c9da Mon Sep 17 00:00:00 2001 From: Mehdi Lahmam Date: Tue, 29 Dec 2015 22:06:39 +0100 Subject: [PATCH] Make `CarrierWave::MiniMagick#mini_magic_image` private This method doesn't need to be part of the public API. It's used by the new public `#width` and `#height` methods (introduced by #1405). This commit also fixes a typo in the method name and tweaks the comments. --- lib/carrierwave/processing/mini_magick.rb | 33 ++++++++++------------- spec/processing/mini_magick_spec.rb | 16 +++++------ 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/lib/carrierwave/processing/mini_magick.rb b/lib/carrierwave/processing/mini_magick.rb index dd90c573c..67845acfc 100644 --- a/lib/carrierwave/processing/mini_magick.rb +++ b/lib/carrierwave/processing/mini_magick.rb @@ -245,40 +245,25 @@ def resize_and_pad(width, height, background=:transparent, gravity='Center', com end ## - # Return the mini magic instance of the image - # - # === Returns - # - # # - # - def mini_magic_image - if url - ::MiniMagick::Image.open(url) - else - ::MiniMagick::Image.open(current_path) - end - end - - ## - # Gives the width of the image, useful for model validation + # Returns the width of the image in pixels. # # === Returns # # [Integer] the image's width in pixels # def width - mini_magic_image[:width] + mini_magick_image[:width] end ## - # Gives the height of the image, useful for model validation + # Returns the height of the image in pixels. # # === Returns # # [Integer] the image's height in pixels # def height - mini_magic_image[:height] + mini_magick_image[:height] end ## @@ -338,5 +323,15 @@ def append_combine_options(cmd, combine_options) end end + private + + def mini_magick_image + if url + ::MiniMagick::Image.open(url) + else + ::MiniMagick::Image.open(current_path) + end + end + end # MiniMagick end # CarrierWave diff --git a/spec/processing/mini_magick_spec.rb b/spec/processing/mini_magick_spec.rb index 14221b2bd..e10129ab4 100644 --- a/spec/processing/mini_magick_spec.rb +++ b/spec/processing/mini_magick_spec.rb @@ -156,6 +156,14 @@ end end + describe "#width and #height" do + it "should return the width and height of the image" do + @instance.resize_to_fill(200, 300) + expect(@instance.width).to eq(200) + expect(@instance.height).to eq(300) + end + end + describe "test errors" do context "invalid image file" do before do @@ -188,12 +196,4 @@ end end - describe "return_width_and_height" do - it "should return the width and height of the image" do - @instance.resize_to_fill(200, 300) - expect(@instance.width).to eq(200) - expect(@instance.height).to eq(300) - end - end - end