require File.dirname(__FILE__) + '/../../../spec_helper' describe Images::Tags::Image do dataset :pages dataset :images before(:all) do @images = Image.all end before(:each) do stub(AWS::S3::Base).establish_connection! end describe '' do it 'should render without errors' do content = '' pages(:home).should render(content) end it 'should allow tags in the images namespace to be used without defining their namespace' do content = '' pages(:home).should render(content) end it 'should reference an image given its title' do image = @images[2] content = '' pages(:home).should render(content).as(image.asset.url) end it 'should raise an exception if an image title is used that does not exist' do content = '' lambda { pages(:home).render(content) }.should raise_error end end describe '' do it 'should run through all of our images' do content = 'test!' expected = '' @images.length.times { expected += 'test!' } pages(:home).should render(content).as(expected) end it 'should be running through the image objects' do content = '' expected = '' @images.each { |image| expected += image.asset.url } pages(:home).should render(content).as(expected) end it 'should only run through however many images we specify with limit' do content = '' expected = '' @images[0..1].each { |image| expected += image.asset.url } pages(:home).should render(content).as(expected) end it 'should start at the image number we give it using offset' do content = '' expected = '' @images[1..2].each { |image| expected += image.asset.url } pages(:home).should render(content).as(expected) end it 'should display images in the order we give' do # asc content = '' expected = '' @images.each { |image| expected += image.asset.url } pages(:home).should render(content).as(expected) #desc content = '' expected = '' @images.reverse.each { |image| expected += image.asset.url } pages(:home).should render(content).as(expected) end it 'should allow us to order images by title' do content = '' expected = '' @images.sort! { |a,b| a.title <=> b.title } @images.each { |image| expected += image.asset.url } pages(:home).should render(content).as(expected) end end describe '' do it 'should render the first image' do content = '' expected = @images.first.asset.url pages(:home).should render(content).as(expected) end end describe '' do it 'should expand the tag if the image is the first' do content = '' expected = @images.first.asset.url pages(:home).should render(content).as(expected) end end describe '' do it 'should expand the tag if the image is not the first' do content = '' expected = '' @images.each do |image| expected += image.asset.url unless image == @images.first end pages(:home).should render(content).as(expected) end end describe '' do it 'should expand the contents if there are images' do content = 'test text' expected = 'test text' pages(:home).should render(content).as(expected) end it 'should not expand the contents if there are no images' do Image.delete_all content = 'test text' expected = '' pages(:home).should render(content).as(expected) end it 'should expand if the min count is equal to the image count' do min_count = Image.count content = 'test text' expected = 'test text' pages(:home).should render(content).as(expected) end it 'should not expand if the min count is greater than the image count' do min_count = Image.count + 1 content = 'test text' expected = '' pages(:home).should render(content).as(expected) end end describe '' do it 'should not the contents if there are images' do content = 'test text' expected = '' pages(:home).should render(content).as(expected) end it 'should expand the contents if there are no images' do Image.delete_all content = 'test text' expected = 'test text' pages(:home).should render(content).as(expected) end it 'should not expand if the min count is equal to the image count' do min_count = Image.count content = 'test text' expected = '' pages(:home).should render(content).as(expected) end it 'should expand if the min count is greater than the image count' do min_count = Image.count + 1 content = 'test text' expected = 'test text' pages(:home).should render(content).as(expected) end end describe '' do it 'should output the url for a valid image' do content = '' expected = @images.first.asset.url pages(:home).should render(content).as(expected) end end describe '' do it 'should output the title for a valid image' do content = '' expected = @images.first.title pages(:home).should render(content).as(expected) end end describe '' do it 'should output a valid image tag when given a valid image' do content = '' expected = '' + @images.first.title + '' pages(:home).should render(content).as(expected) end it 'should output a valid image tag when specifying an image by title' do content = '' expected = '' + @images.first.title + '' pages(:home).should render(content).as(expected) end it 'should output an image tag with the specified size' do content = '' expected = '' + @images.first.title + '' pages(:home).should render(content).as(expected) end it 'should use the given alt text specified' do content = '' expected = 'new alt text' pages(:home).should render(content).as(expected) end end end