1 require File.dirname(__FILE__) + '/spec_helper'
4 Model.slideshow_album :from => :pictures, :slides => { :src => :absolute_path }
8 # this form should result in minimal slideshow album attributes
9 Model.slideshow_album :pictures, :public_filename
12 def customized_slideshow1
13 Model.slideshow_album :from => :pictures, :title => :display_name, :description => :notes,
14 :slides => { :src => :public_filename, :title => :name, :description => :caption }
17 # describe "Calling the class method slideshow_album(:from => :images)" do
19 # it "should define #slideshow_album_xml as an instance method" do
20 # Model.slideshow_album :from => :images
21 # Model.new.should respond_to :slideshow_album_xml
26 describe "Calling slideshow_album without arguments" do
27 it "should raise an error" do
28 lambda {Model.slideshow_album}.should raise_error ArgumentError
32 describe "Calling slideshow_album with simple arg form" do
34 Model.slideshow_album :pictures, :public_filename
38 it "should define Model#slideshow_album_xml" do
39 @album.should respond_to :slideshow_album_xml
42 it "should define hash and accessor for the slideshow config" do
43 @album.mono_album_options[:from].should == :pictures
46 it "should create a method for accessing the slide collection" do
47 @album.should_receive(:pictures)
48 @album.mono_album_slides
51 it "should create a method for accessing slide src" do
52 @slide = mock('slide')
53 @slide.should_receive(:public_filename)
54 @album.mono_slide_src(@slide)
57 it "should create an album thumbnail src accessor, using the first slide by default" do
58 @slide1 = mock('slide')
59 @slide2 = mock('slide')
60 @slides = [@slide1, @slide2]
61 @slide1.should_receive(:public_filename).and_return('file.jpg')
62 @album.should_receive(:mono_album_slides).and_return(@slides)
63 @album.mono_album_thumbnail.should == 'file.jpg'
68 describe "Calling slideshow_album, full form, minimal args" do
70 Model.slideshow_album :from => :pictures, :slides => { :src => :public_filename }
74 it "should define Model#slideshow_album_xml" do
75 @album.should respond_to :slideshow_album_xml
78 it "should define hash and accessor for the slideshow config" do
79 @album.mono_album_options[:from].should == :pictures
82 it "should create a method for accessing the slide collection" do
83 @album.should_receive(:pictures)
84 @album.mono_album_slides
87 it "should create a method for accessing slide src" do
88 @slide = mock('slide')
89 @slide.should_receive(:public_filename)
90 @album.mono_slide_src(@slide)
93 it "should create an album thumbnail src accessor, using the first slide by default" do
94 @slide1 = mock('slide')
95 @slide2 = mock('slide')
96 @slides = [@slide1, @slide2]
97 @slide1.should_receive(:public_filename).and_return('file.jpg')
98 @album.should_receive(:mono_album_slides).and_return(@slides)
99 @album.mono_album_thumbnail.should == 'file.jpg'
104 describe "The slideshow_album_xml method, when created with minimal args" do
106 Model.slideshow_album :pictures, :public_filename
108 @picture = mock 'picture'
109 @pictures = [@picture, @picture]
110 @album.should_receive(:pictures).twice.and_return(@pictures)
111 @picture.should_receive(:public_filename).exactly(@pictures.size + 1).times.and_return('file.jpg')
112 @album_xml = @album.slideshow_album_xml
114 it "should return a properly constructed xml doc" do
115 @album_xml.should be_an_instance_of String
116 Hash.from_xml(@album_xml).should == { "album" => {
117 "thumbnail" => "file.jpg",
118 "img"=> [{"src" => "file.jpg"}, {"src" => "file.jpg"}] } }
122 describe "Calling slideshow_album with title and description args" do
124 Model.slideshow_album :from => :pictures, :title => :display_name, :description => :notes,
125 :slides => { :src => :public_filename, :title => :name, :description => :caption }
129 it "should define Model#slideshow_album_xml" do
130 @album.should respond_to :slideshow_album_xml
133 it "should define hash and accessor for the slideshow config" do
134 @album.mono_album_options[:from].should == :pictures
135 @album.mono_album_options[:title].should == :display_name
136 @album.mono_album_options[:description].should == :notes
139 it "should set the album collection method" do
140 @album.should_receive(:pictures)
141 @album.mono_album_slides
144 it "should set the album title method" do
145 @album.should_receive(:display_name)
146 @album.mono_album_title
149 it "should set the album description method" do
150 @album.should_receive(:notes)
151 @album.mono_album_description
154 it "should set the slide options" do
155 @album.mono_slide_options[:src].should == :public_filename
156 @album.mono_slide_options[:title].should == :name
157 @album.mono_slide_options[:description].should == :caption
160 it "should create a method for accessing slide src" do
161 @slide = mock('slide')
162 @slide.should_receive(:public_filename)
163 @album.mono_slide_src(@slide)
166 it "should create a method for accessing slide titles" do
167 @slide = mock('slide')
168 @slide.should_receive(:name)
169 @album.mono_slide_title(@slide)
172 it "should create a method for accessing slide descriptions" do
173 @slide = mock('slide')
174 @slide.should_receive(:caption)
175 @album.mono_slide_description(@slide)
178 it "should create an album thumbnail src accessor, using the first slide by default" do
179 @slide1 = mock('slide')
180 @slide2 = mock('slide')
181 @slides = [@slide1, @slide2]
182 @slide1.should_receive(:public_filename).and_return('file.jpg')
183 @album.should_receive(:mono_album_slides).and_return(@slides)
184 @album.mono_album_thumbnail.should == 'file.jpg'
189 describe "The slideshow_album_xml method, when created with title and description" do
191 Model.slideshow_album :from => :pictures, :title => :display_name, :description => :notes,
192 :slides => { :src => :public_filename, :title => :name, :description => :caption }
194 @picture = mock 'picture'
195 @pictures = [@picture, @picture]
196 @album.should_receive(:pictures).twice.and_return(@pictures)
197 @album.should_receive(:display_name).and_return('Some Photos I took')
198 @album.should_receive(:notes).and_return('All of these are photos that I took.')
199 @picture.should_receive(:public_filename).exactly(@pictures.size + 1).times.and_return('file.jpg')
200 @picture.should_receive(:name).exactly(@pictures.size).times.and_return('A Photo')
201 @picture.should_receive(:caption).exactly(@pictures.size).times.and_return('I took it')
202 @album_xml = @album.slideshow_album_xml
205 it "should return an xml doc with titles and descriptions for albums and slides" do
206 Hash.from_xml(@album_xml).should == {"album" => {
207 "title" => "Some Photos I took",
208 "description" => "All of these are photos that I took.",
209 "thumbnail" => "file.jpg",
211 {"title" => "A Photo", "src" => "file.jpg", "description" => "I took it"},
212 {"title" => "A Photo", "src" => "file.jpg", "description" => "I took it"}]}}