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

Commit

Permalink
refs #17 画像のバリデーションに関するテストを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
YOSHIDA Hiroki committed Nov 7, 2013
1 parent 5471635 commit 0a05954
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Binary file added spec/files/invalid_aspect_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions spec/models/image_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'spec_helper'

describe Image do
describe "Validation" do
let (:valid_image_url) { 'http://example.com/image.png' }
let (:invalid_image_path) { 'spec/files/invalid_aspect_image.png' }
let (:invalid_image_size) { ImageSize.new(open(invalid_image_path)) }
let (:invalid_image) { described_class.new(url: valid_image_url, width: invalid_image_size.width, height: invalid_image_size.height) }

it "高さが足りない場合" do
image = invalid_image
image.width = 17
image.height = 16
image.should be_invalid
image.errors[:height].should be_present
end

it "幅が足りない場合" do
image = invalid_image
image.width = 16
image.height = 17
image.should be_invalid
image.errors[:width].should be_present
end

it "アスペクト比が不正な場合" do
image = invalid_image
image.width *= 100
image.height *= 100
image.should be_invalid
image.errors[:base].should be_present
end
end
end

0 comments on commit 0a05954

Please sign in to comment.