spec/unit/attachment/maybe_spec.rb in bulldog-0.2.0 vs spec/unit/attachment/maybe_spec.rb in bulldog-0.2.1
- old
+ new
@@ -20,110 +20,160 @@
end
@thing = Thing.new
end
describe "#interpolate_path" do
- it "should return the path that the given style name would be stored at" do
- spec = self
- configure_attachment do
- path "#{spec.temporary_directory}/:attachment.:style.jpg"
- end
- @thing.photo.interpolate_path(:original).should == "#{temporary_directory}/photo.original.jpg"
- end
+ describe "when the path template is a Symbol" do
+ before do
+ Thing.class_eval do
+ has_attachment :photo do
+ path :test_path
+ end
- it "should use the given interpolation parameters" do
- spec = self
- configure_attachment do
- path "#{spec.temporary_directory}/:attachment.:style.jpg"
+ define_method :test_path do |@name, @style|
+ "#{name}-#{style.name}"
+ end
+
+ attr_reader :name, :style
+ end
+ @thing = Thing.new
end
- @thing.photo.interpolate_path(:original, :style => 'STYLE').should == "#{temporary_directory}/photo.STYLE.jpg"
- end
- it "should use the style's format attribute for the extension by default" do
- spec = self
- configure_attachment do
- style :processed, :format => 'png'
- path "#{spec.temporary_directory}/:attachment.:style.:extension"
+ it "should call the specified method with the attachment name and style" do
+ @thing.photo.interpolate_path(:original).should == "photo-original"
+ @thing.name == :photo
+ @thing.style.name == :original
end
- @thing.photo.interpolate_path(:processed, :format => 'png').should == "#{temporary_directory}/photo.processed.png"
end
- describe "for the original style" do
- it "should support the :basename interpolation key if the basename is given" do
+ describe "when the path template is a String" do
+ it "should return the path that the given style name would be stored at" do
spec = self
configure_attachment do
- path "#{spec.temporary_directory}/:attachment.:style/:basename"
+ path "#{spec.temporary_directory}/:attachment.:style.jpg"
end
- @thing.photo.interpolate_path(:original, :basename => 'file.xyz').should == "#{temporary_directory}/photo.original/file.xyz"
+ @thing.photo.interpolate_path(:original).should == "#{temporary_directory}/photo.original.jpg"
end
- it "should support the :extension interpolation key if the basename is given" do
+ it "should use the given interpolation parameters" do
spec = self
configure_attachment do
- path "#{spec.temporary_directory}/:attachment.:style.:extension"
+ path "#{spec.temporary_directory}/:attachment.:style.jpg"
end
- @thing.photo.interpolate_path(:original, :basename => 'file.xyz').should == "#{temporary_directory}/photo.original.xyz"
+ @thing.photo.interpolate_path(:original, :style => 'STYLE').should == "#{temporary_directory}/photo.STYLE.jpg"
end
- it "should support the :extension interpolation key if the extension is given" do
+ it "should use the style's format attribute for the extension by default" do
spec = self
configure_attachment do
+ style :processed, :format => 'png'
path "#{spec.temporary_directory}/:attachment.:style.:extension"
end
- @thing.photo.interpolate_path(:original, :extension => 'xyz').should == "#{temporary_directory}/photo.original.xyz"
+ @thing.photo.interpolate_path(:processed, :format => 'png').should == "#{temporary_directory}/photo.processed.png"
end
+
+ describe "for the original style" do
+ it "should support the :basename interpolation key if the basename is given" do
+ spec = self
+ configure_attachment do
+ path "#{spec.temporary_directory}/:attachment.:style/:basename"
+ end
+ @thing.photo.interpolate_path(:original, :basename => 'file.xyz').should == "#{temporary_directory}/photo.original/file.xyz"
+ end
+
+ it "should support the :extension interpolation key if the basename is given" do
+ spec = self
+ configure_attachment do
+ path "#{spec.temporary_directory}/:attachment.:style.:extension"
+ end
+ @thing.photo.interpolate_path(:original, :basename => 'file.xyz').should == "#{temporary_directory}/photo.original.xyz"
+ end
+
+ it "should support the :extension interpolation key if the extension is given" do
+ spec = self
+ configure_attachment do
+ path "#{spec.temporary_directory}/:attachment.:style.:extension"
+ end
+ @thing.photo.interpolate_path(:original, :extension => 'xyz').should == "#{temporary_directory}/photo.original.xyz"
+ end
+ end
end
end
describe "#interpolate_url" do
- it "should return the url that the given style name would be found at" do
- spec = self
- configure_attachment do
- url "/:attachment.:style.jpg"
- end
- @thing.photo.interpolate_url(:original).should == "/photo.original.jpg"
- end
+ describe "when the url template is a Symbol" do
+ before do
+ Thing.class_eval do
+ has_attachment :photo do
+ url :test_url
+ end
- it "should use the given interpolation parameters" do
- spec = self
- configure_attachment do
- url "/:attachment.:style.jpg"
+ define_method :test_url do |@name, @style|
+ "#{name}-#{style.name}"
+ end
+
+ attr_reader :name, :style
+ end
+ @thing = Thing.new
end
- @thing.photo.interpolate_url(:original, :style => 'STYLE').should == "/photo.STYLE.jpg"
- end
- it "should use the style's format attribute for the extension by default" do
- spec = self
- configure_attachment do
- style :processed, :format => 'png'
- url "/:attachment.:style.:extension"
+ it "should call the specified method with the attachment name and style" do
+ @thing.photo.interpolate_url(:original).should == "photo-original"
+ @thing.name == :photo
+ @thing.style.name == :original
end
- @thing.photo.interpolate_url(:processed).should == "/photo.processed.png"
end
- describe "for the original style" do
- it "should support the :basename interpolation key if the basename is given" do
+ describe "when the url template is a String" do
+ it "should return the url that the given style name would be found at" do
spec = self
configure_attachment do
- url "/:attachment.:style/:basename"
+ url "/:attachment.:style.jpg"
end
- @thing.photo.interpolate_url(:original, :basename => 'file.xyz').should == "/photo.original/file.xyz"
+ @thing.photo.interpolate_url(:original).should == "/photo.original.jpg"
end
- it "should support the :extension interpolation key if the basename is given" do
+ it "should use the given interpolation parameters" do
spec = self
configure_attachment do
- url "/:attachment.:style.:extension"
+ url "/:attachment.:style.jpg"
end
- @thing.photo.interpolate_url(:original, :basename => 'file.xyz').should == "/photo.original.xyz"
+ @thing.photo.interpolate_url(:original, :style => 'STYLE').should == "/photo.STYLE.jpg"
end
- it "should support the :extension interpolation key if the extension is given" do
+ it "should use the style's format attribute for the extension by default" do
spec = self
configure_attachment do
+ style :processed, :format => 'png'
url "/:attachment.:style.:extension"
end
- @thing.photo.interpolate_url(:original, :extension => 'xyz').should == "/photo.original.xyz"
+ @thing.photo.interpolate_url(:processed).should == "/photo.processed.png"
+ end
+
+ describe "for the original style" do
+ it "should support the :basename interpolation key if the basename is given" do
+ spec = self
+ configure_attachment do
+ url "/:attachment.:style/:basename"
+ end
+ @thing.photo.interpolate_url(:original, :basename => 'file.xyz').should == "/photo.original/file.xyz"
+ end
+
+ it "should support the :extension interpolation key if the basename is given" do
+ spec = self
+ configure_attachment do
+ url "/:attachment.:style.:extension"
+ end
+ @thing.photo.interpolate_url(:original, :basename => 'file.xyz').should == "/photo.original.xyz"
+ end
+
+ it "should support the :extension interpolation key if the extension is given" do
+ spec = self
+ configure_attachment do
+ url "/:attachment.:style.:extension"
+ end
+ @thing.photo.interpolate_url(:original, :extension => 'xyz').should == "/photo.original.xyz"
+ end
end
end
end
describe "#reload" do