spec/paperclip_spec.rb in retina_rails-0.0.6 vs spec/paperclip_spec.rb in retina_rails-0.1.0
- old
+ new
@@ -1,17 +1,28 @@
require 'spec_helper'
+ROOT = File.dirname(__FILE__)
+
class PaperclipUpload < ActiveRecord::Base
has_attached_file :avatar,
:styles => {
:original => ["800x800", :jpg],
:big => ["125x125#", :jpg]
},
- :path => "#{File.dirname(__FILE__)}/:class/:id/:basename_:style.:extension",
- :url => "#{File.dirname(__FILE__)}/:class/:id/:basename_:style.:extension"
+ :retina_quality => 60,
+ :path => "#{ROOT}/:class/:id/:basename_:style.:extension",
+ :url => "#{ROOT}/:class/:id/:basename_:style.:extension"
+ has_attached_file :avatar_without_quality,
+ :styles => {
+ :original => ["800x800", :jpg],
+ :big => ["125x125#", :jpg]
+ },
+ :path => "#{ROOT}/:class/:id/:basename_:style.:extension",
+ :url => "#{ROOT}/:class/:id/:basename_:style.:extension"
+
include RetinaRails::Paperclip
end
describe RetinaRails::Paperclip do
@@ -21,23 +32,41 @@
context 'overriding options' do
it { subject.attachment_definitions[:avatar][:styles][:original_retina].should == ['1600x1600', :jpg] }
it { subject.attachment_definitions[:avatar][:styles][:big_retina].should == ['250x250#', :jpg] }
- it { subject.attachment_definitions[:avatar][:path].should == "#{File.dirname(__FILE__)}/:class/:id/:basename_:style:retina.:extension" }
- it { subject.attachment_definitions[:avatar][:url].should == "#{File.dirname(__FILE__)}/:class/:id/:basename_:style:retina.:extension" }
+ it { subject.attachment_definitions[:avatar][:path].should == "#{ROOT}/:class/:id/:basename_:style:retina.:extension" }
+ it { subject.attachment_definitions[:avatar][:url].should == "#{ROOT}/:class/:id/:basename_:style:retina.:extension" }
end
context 'uploads' do
- subject { PaperclipUpload.create(:avatar => File.open("#{File.dirname(__FILE__)}/fixtures/images/avatar.jpeg")) }
+ subject { PaperclipUpload.create(:avatar => File.open("#{ROOT}/fixtures/images/avatar.jpeg")) }
- it { subject.avatar.url(:big).should == "#{File.dirname(__FILE__)}/paperclip_uploads/1/avatar_big.jpg" }
- it { subject.avatar.url(:big_retina).should == "#{File.dirname(__FILE__)}/paperclip_uploads/2/avatar_big@2x.jpg" }
+ it { subject.avatar.url(:big).should == "#{ROOT}/paperclip_uploads/1/avatar_big.jpg" }
+ it { subject.avatar.url(:big_retina).should == "#{ROOT}/paperclip_uploads/2/avatar_big@2x.jpg" }
it { Paperclip::Geometry.from_file(subject.avatar.url(:big)).to_s.should == '125x125' }
it { Paperclip::Geometry.from_file(subject.avatar.url(:big_retina)).to_s.should == '250x250' }
+
+ end
+
+ context 'with retina quality' do
+
+ subject { PaperclipUpload.create(:avatar => File.open("#{ROOT}/fixtures/images/avatar.jpeg")) }
+
+ it { Magick::Image.read(subject.avatar.url(:big)).first.quality.should == 84 }
+ it { Magick::Image.read(subject.avatar.url(:big_retina)).first.quality.should == 60 }
+
+ end
+
+ context 'without retina quality' do
+
+ subject { PaperclipUpload.create(:avatar_without_quality => File.open("#{ROOT}/fixtures/images/avatar.jpeg")) }
+
+ it { Magick::Image.read(subject.avatar_without_quality.url(:big)).first.quality.should == 84 }
+ it { Magick::Image.read(subject.avatar_without_quality.url(:big_retina)).first.quality.should == 40 }
end
end
\ No newline at end of file