require 'spec_helper' describe Images::Tags::Core do dataset :pages, :images before(:all) do @images = [ images(:first), images(:second), images(:third), images(:fourth), images(:fifth), images(:sixth) ] end before(:each) do stub(AWS::S3::Base).establish_connection! end describe '' do it 'should render its contents' do input = 'success' expected = 'success' pages(:home).should render(input).as(expected) end it 'should add the images namespace to nested radius tags' do input = 'success' pages(:home).should render(input) end end describe '' do it 'should render its contents when there are images' do input = 'success' expected = 'success' pages(:home).should render(input).as(expected) end it 'should not render its contents when there are no images' do mock(Image).all { [] } input = 'failure' expected = '' pages(:home).should render(input).as(expected) end end describe '' do it 'should render its contents when there are no images' do mock(Image).all { [] } input = 'success' expected = 'success' pages(:home).should render(input).as(expected) end it 'should not render its contents when there are images' do input = 'failure' expected = '' pages(:home).should render(input).as(expected) end end describe '' do it 'should expand its contents once for each of the available images' do input = 'test ' expected = 'test test test test test test ' pages(:home).should render(input).as(expected) end it 'should not expand its contents if there are no images available' do mock(Image).all() { [] } mock(Image).all(anything) { [] } input = 'test ' expected = '' pages(:home).should render(input).as(expected) end it 'should limit the number of images based on the limit parameter passed' do input = ' ' expected = 'first second third ' pages(:home).should render(input).as(expected) end it 'should use the offset parameter to ignore results before the offset' do input = ' ' expected = 'third fourth fifth ' pages(:home).should render(input).as(expected) end it 'should order the results based by the key passed' do input = ' ' expected = 'fifth first fourth second sixth third ' pages(:home).should render(input).as(expected) end it 'should order the results by ascending order when asc is passed for the order' do input = ' ' expected = 'first second third fourth fifth sixth ' pages(:home).should render(input).as(expected) end it 'should order the results by descending order when desc is passed for the order' do input = ' ' expected = 'sixth fifth fourth third second first ' pages(:home).should render(input).as(expected) end end describe '' do it 'should add the image namespace to nested radius tags' do input = '' expected = 'first' pages(:home).should render(input).as(expected) end it 'should render its contents if there is a current image' do input = ' ' expected = 'first second third fourth fifth sixth ' pages(:home).should render(input).as(expected) end it 'should not render its contents if there is no current image' do input = '' expected = '' pages(:home).should render(input).as(expected) end it 'should allow images to be looked up by their id attribute' do mock(Image).find('5') { @images[4] } input = '' expected = 'fifth' pages(:home).should render(input).as(expected) end it 'should allow images to be looked up by their position attribute' do input = '' expected = 'third' pages(:home).should render(input).as(expected) end it 'should allow images to be looked up by their title attribute' do input = '' expected = 'sixth' pages(:home).should render(input).as(expected) end end describe '' do before :each do asset = Paperclip::Attachment.new('asset', @images[0], { :url => Radiant::Config['images.url'] }) stub(Image).find_by_title('first') { @images[0] } stub.proxy(Image).find_by_title('invalid') stub(@images[0]).asset { asset } end it 'should not render a valid url if there is no current image' do input = '' expected = '' pages(:home).should render(input).as(expected) end it 'should render the url with the default style if not specified' do input = '' expected = '/images/first-original.png' pages(:home).should render(input).as(expected) end it 'should render the url with the style specified by the user' do input = '' expected = '/images/first-icon.png' pages(:home).should render(input).as(expected) end end describe '' do before :each do asset = Paperclip::Attachment.new('asset', @images[0], { :url => Radiant::Config['images.url'] }) stub(Image).find_by_title('first') { @images[0] } stub.proxy(Image).find_by_title('invalid') stub(@images[0]).asset { asset } end it 'should not render a valid img tag if there is no current image' do input = '' expected = '' pages(:home).should render(input).as(expected) end it 'should render the img tag with the default style if not specified' do input = '' expected = '' pages(:home).should render(input).as(expected) end it 'should render the img tag with the style specified by the user' do input = '' expected = '' pages(:home).should render(input).as(expected) end end describe '' do it 'should render the id of the current image context' do input = '' expected = @images[5].id.to_s pages(:home).should render(input).as(expected) end it 'should not render anything if there is no current image context' do input = '' expected = '' pages(:home).should render(input).as(expected) end end describe '' do it 'should render the title of the current image context' do input = '' expected = 'fourth' pages(:home).should render(input).as(expected) end it 'should not render anything if there is no current image context' do input = '' expected = '' pages(:home).should render(input).as(expected) end end describe '' do it 'should render the position of the current image context' do input = '' expected = '1' pages(:home).should render(input).as(expected) end it 'should not render anything if there is no current image context' do input = '' expected = '' pages(:home).should render(input).as(expected) end end end