spec/helpers_spec.rb in retina_rails-1.0.4 vs spec/helpers_spec.rb in retina_rails-2.0.0
- old
+ new
@@ -1,36 +1,110 @@
require 'spec_helper'
-describe ActionView::Helpers::AssetTagHelper, :type => :helper do
+class Image
- class SomeWrapperClassForUrl
- def to_s
- 'image.png'
- end
+ def url(version)
+ '/some_image.png'
end
+end
+
+class Upload
+
+ attr_accessor :avatar
+
+ def initialize
+ self.avatar = Image.new
+ end
+
+ def retina_dimensions
+ {
+ :avatar => {
+ :small => {
+ :width => 40,
+ :height => 30
+ }
+ }
+ }
+ end
+
+end
+
+describe ActionView::Helpers::AssetTagHelper, :type => :helper do
+
subject { helper }
- describe :image_tag do
+ describe '#retina_image_tag' do
- context 'with retina option' do
+ context 'with dimensions present' do
- it { subject.image_tag('image.png', :retina => true).should == '<img alt="Image" data-at2x="/assets/image@2x-0842b16379ded9ddcc299912621f76bc.png" src="/assets/image-e8de7f87c2b9d08490575267a4c9eddc.png" />' }
+ it 'should set correct width and height' do
+ image = helper.retina_image_tag(Upload.new, :avatar, :small)
- it { subject.image_tag('image.some.png', :retina => true).should == '<img alt="Image.some" data-at2x="/assets/image.some@2x-0842b16379ded9ddcc299912621f76bc.png" src="/assets/image.some-e8de7f87c2b9d08490575267a4c9eddc.png" />' }
+ image.should include('width="40"')
+ image.should include('height="30"')
+ end
- context 'with class' do
+ it 'should be able to add a class' do
+ image = helper.retina_image_tag(Upload.new, :avatar, :small, :class => 'foo')
+ image.should include('class="foo"')
+ end
- it { subject.image_tag(SomeWrapperClassForUrl.new, :retina => true).should == '<img alt="Image" data-at2x="/assets/image@2x-0842b16379ded9ddcc299912621f76bc.png" src="/assets/image-e8de7f87c2b9d08490575267a4c9eddc.png" />' }
+ end
+ context 'without dimensions present' do
+
+ before(:each) { Upload.any_instance.stub(:retina_dimensions).and_return(nil) }
+
+ it 'should set correct width and height' do
+ image = helper.retina_image_tag(Upload.new, :avatar, :small, :default => { :width => 25, :height => 40 })
+
+ image.should include('width="25"')
+ image.should include('height="40"')
+
+ image = helper.retina_image_tag(Upload.new, :avatar, :small, :default => [25, 40])
+
+ image.should include('width="25"')
+ image.should include('height="40"')
end
+ it 'should set no height and width if no defaults present' do
+ image = helper.retina_image_tag(Upload.new, :avatar, :small)
+
+ image.should_not include('width')
+ image.should_not include('height')
+ end
+
+ it 'should be able to add a class' do
+ image = helper.retina_image_tag(Upload.new, :avatar, :small, :default => { :width => 25, :height => 40 }, :class => 'foo')
+
+ image.should include('class="foo"')
+ end
+
+ it 'should strip default attributes' do
+ image = helper.retina_image_tag(Upload.new, :avatar, :small, :default => { :width => 25, :height => 40 })
+
+ image.should_not include('default')
+ end
+
end
- context 'without retina' do
+ end
- it { subject.image_tag('image.png').should == '<img alt="Image" src="/assets/image-e8de7f87c2b9d08490575267a4c9eddc.png" />' }
+ describe '#image_tag' do
+ it 'should show a deprecation warning when used with retina option' do
+ ActiveSupport::Deprecation.should_receive(:warn)
+ .with("`image_tag('image.png', :retina => true)` is deprecated use `retina_image_tag` instead")
+
+ image_tag('image.png', :retina => true)
+ end
+
+ it 'should not show a deprecation warning when used without retina option' do
+ ActiveSupport::Deprecation.should_not_receive(:warn)
+ .with("`image_tag('image.png', :retina => true)` is deprecated use `retina_image_tag` instead")
+
+ image_tag('image.png')
end
end
end
\ No newline at end of file