Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
ウォール: サムネイル画像が正しいサイズにリサイズされるように変更
Browse files Browse the repository at this point in the history
  • Loading branch information
YOSHIDA Hiroki committed Nov 28, 2013
1 parent b941083 commit 2ba53bf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def create_thumb_cache_file
FileUtils.mkdir_p Settings.image_cache_dir unless File.exist? Settings.image_cache_dir
image = MiniMagick::Image.read(self.open_image.read)
image.format Settings.thumb_format
image.resize "#{self.thumb_width}x#{self.thumb_height}"
image.resize "#{self.thumb_width}x#{self.thumb_height}!"
image.write self.thumb_path
end

Expand Down
29 changes: 26 additions & 3 deletions spec/controllers/images_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,39 @@

describe ImagesController do
let (:image) { FactoryGirl.create(:image) }
let (:minimagick_image) { MiniMagick::Image.read(response.body) }

before_stub_request
before { image }
# あらかじめサムネイルのキャッシュファイルを削除しておく
before { File.delete image.thumb_path if File.exist? image.thumb_path }

describe "GET 'show'" do
it "returns http success" do
get :show, id: image.id
response.should be_success
context "通常画像の場合" do
before { get :show, id: image.id }

its (:response) { should be_success }

it "幅が正しいこと" do
expect(minimagick_image[:width]).to eq(image.width)
end

it "高さが正しいこと" do
expect(minimagick_image[:height]).to eq(image.height)
end
end

context "サムネイル画像の場合" do
before { get :show, id: image.id, type: :thumbnail }
its (:response) { should be_success }

it "幅が正しいこと" do
expect(minimagick_image[:width]).to eq(image.thumb_width)
end

it "高さが正しいこと" do
expect(minimagick_image[:height]).to eq(image.thumb_height)
end
end
end
end

0 comments on commit 2ba53bf

Please sign in to comment.