I did most of the initial work without any SCM. I am so bad.
[monoslider.git] / spec / album_spec.rb
blobbfa9a23a7314c4d4abe4debfd048efe7ed016df1
1 require File.dirname(__FILE__) + '/spec_helper'
3 def minimal_slideshow1
4   Model.slideshow_album :from => :pictures, :slides => { :src => :absolute_path }
5 end
7 def minimal_slideshow2
8   # this form should result in minimal slideshow album attributes
9   Model.slideshow_album :pictures, :public_filename
10 end
12 def customized_slideshow1
13   Model.slideshow_album :from => :pictures, :title => :display_name, :description => :notes,
14     :slides => { :src => :public_filename, :title => :name, :description => :caption }
15 end
17 # describe "Calling the class method slideshow_album(:from => :images)" do
18 #    
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
22 #   end
23 #   
24 # end
26 describe "Calling slideshow_album without arguments" do
27   it "should raise an error" do
28     lambda {Model.slideshow_album}.should raise_error ArgumentError
29   end
30 end
32 describe "Calling slideshow_album with simple arg form" do
33   before(:each) do
34     Model.slideshow_album :pictures, :public_filename
35     @album = Model.new
36   end
37   
38   it "should define Model#slideshow_album_xml" do
39     @album.should respond_to :slideshow_album_xml
40   end
41   
42   it "should define hash and accessor for the slideshow config" do
43     @album.mono_album_options[:from].should == :pictures
44   end
45   
46   it "should create a method for accessing the slide collection" do
47     @album.should_receive(:pictures)
48     @album.mono_album_slides
49   end
50   
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)
55   end
56   
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'
64   end
65     
66 end
68 describe "Calling slideshow_album, full form, minimal args" do
69   before(:each) do
70     Model.slideshow_album :from => :pictures, :slides => { :src => :public_filename }
71     @album = Model.new
72   end
73   
74   it "should define Model#slideshow_album_xml" do
75     @album.should respond_to :slideshow_album_xml
76   end
77   
78   it "should define hash and accessor for the slideshow config" do
79     @album.mono_album_options[:from].should == :pictures
80   end
81   
82   it "should create a method for accessing the slide collection" do
83     @album.should_receive(:pictures)
84     @album.mono_album_slides
85   end
86   
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)
91   end
92   
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'
100   end
101     
104 describe "The slideshow_album_xml method, when created with minimal args" do
105   before(:each) do
106     Model.slideshow_album :pictures, :public_filename
107     @album = Model.new
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
113   end
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"}] } }
119   end
122 describe "Calling slideshow_album with title and description args" do
123   before(:each) do
124     Model.slideshow_album :from => :pictures, :title => :display_name, :description => :notes,
125       :slides => { :src => :public_filename, :title => :name, :description => :caption }
126     @album = Model.new
127   end
128   
129   it "should define Model#slideshow_album_xml" do
130     @album.should respond_to :slideshow_album_xml
131   end
132   
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
137   end
138   
139   it "should set the album collection method" do
140     @album.should_receive(:pictures)
141     @album.mono_album_slides
142   end
143   
144   it "should set the album title method" do
145     @album.should_receive(:display_name)
146     @album.mono_album_title
147   end
148   
149   it "should set the album description method" do
150     @album.should_receive(:notes)
151     @album.mono_album_description
152   end
153   
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
158   end
159   
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)
164   end
165   
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)
170   end
171   
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)
176   end
177   
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'
185   end
186   
189 describe "The slideshow_album_xml method, when created with title and description" do
190   before(:each) do
191     Model.slideshow_album :from => :pictures, :title => :display_name, :description => :notes,
192       :slides => { :src => :public_filename, :title => :name, :description => :caption }
193     @album = Model.new
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
203   end
204   
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",
210         "img"=>[
211           {"title" => "A Photo", "src" => "file.jpg", "description" => "I took it"}, 
212           {"title" => "A Photo", "src" => "file.jpg", "description" => "I took it"}]}}
213   end