bulldog 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.0.4 2009-11-16
2
+
3
+ * Fix destroying the original file when the record is destroyed.
4
+
1
5
  == 0.0.3 2009-11-16
2
6
 
3
7
  * Add a way to respond to processing errors:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bulldog}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["George Ogata"]
@@ -120,7 +120,6 @@ module Bulldog
120
120
  def interpolate_path(style_name, params={})
121
121
  template = reflection.path_template
122
122
  style = reflection.styles[style_name]
123
- params[:extension] ||= style[:format]
124
123
  Interpolation.interpolate(template, record, name, style, params)
125
124
  end
126
125
 
@@ -135,7 +134,6 @@ module Bulldog
135
134
  def interpolate_url(style_name, params={})
136
135
  template = reflection.url_template
137
136
  style = reflection.styles[style_name]
138
- params[:extension] ||= style[:format]
139
137
  Interpolation.interpolate(template, record, name, style, params)
140
138
  end
141
139
 
@@ -3,10 +3,12 @@ module Bulldog
3
3
  Error = Class.new(Bulldog::Error)
4
4
 
5
5
  def self.interpolate(template, record, name, style, overrides={})
6
- # TODO: would be nice if this wasn't such a special case.
7
- if overrides[:basename]
8
- extension = File.extname(overrides[:basename]).sub(/\A./, '')
9
- overrides[:extension] ||= extension
6
+ unless overrides[:extension]
7
+ overrides = overrides.dup
8
+ overrides[:extension] ||= style[:format]
9
+ if overrides[:basename]
10
+ overrides[:extension] ||= File.extname(overrides[:basename]).sub(/\A./, '')
11
+ end
10
12
  end
11
13
  template.gsub(/:(?:(\w+)|\{(\w+?)\})/) do
12
14
  key = ($1 || $2).to_sym
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
  describe Interpolation do
4
4
  use_model_class(:Thing, :photo_file_name => :string)
5
5
 
6
- def interpolate(template)
7
- Interpolation.interpolate(template, @thing, :photo, @style)
6
+ def interpolate(template, overrides={})
7
+ Interpolation.interpolate(template, @thing, :photo, @style, overrides)
8
8
  end
9
9
 
10
10
  describe ".to_interpolate" do
@@ -36,73 +36,108 @@ describe Interpolation do
36
36
  end
37
37
  end
38
38
 
39
- describe "when the file name is not being stored" do
40
- before do
41
- Thing.has_attachment :photo do
42
- style :small, {}
43
- store_attributes :file_name => nil
39
+ describe ".interpolate" do
40
+ describe "when the file name is not being stored" do
41
+ before do
42
+ Thing.has_attachment :photo do
43
+ style :small
44
+ store_attributes :file_name => nil
45
+ end
46
+ @thing = Thing.new(:photo => test_image_file('test.jpg'))
47
+ @style = Thing.attachment_reflections[:photo].styles[:small]
44
48
  end
45
- @thing = Thing.new(:photo => test_image_file('test.jpg'))
46
- @style = Thing.attachment_reflections[:photo].styles[:small]
47
- end
48
49
 
49
- it "should interpolate :class as the plural class name" do
50
- interpolate("a/:class/b").should == "a/things/b"
51
- end
50
+ it "should interpolate :class as the plural class name" do
51
+ interpolate("a/:class/b").should == "a/things/b"
52
+ end
52
53
 
53
- it "should interpolate :id as the record ID" do
54
- @thing.stubs(:id).returns(123)
55
- interpolate("a/:id/b").should == "a/123/b"
56
- end
54
+ it "should interpolate :id as the record ID" do
55
+ @thing.stubs(:id).returns(123)
56
+ interpolate("a/:id/b").should == "a/123/b"
57
+ end
57
58
 
58
- it "should interpolate :id_partition as the record ID split into 3 3-digit partitions, 0-padded" do
59
- @thing.stubs(:id).returns(12345)
60
- interpolate("a/:id_partition/b").should == "a/000/012/345/b"
61
- end
59
+ it "should interpolate :id_partition as the record ID split into 3 3-digit partitions, 0-padded" do
60
+ @thing.stubs(:id).returns(12345)
61
+ interpolate("a/:id_partition/b").should == "a/000/012/345/b"
62
+ end
62
63
 
63
- it "should interpolate :attachment as the attachment name" do
64
- interpolate("a/:attachment/b").should == "a/photo/b"
65
- end
64
+ it "should interpolate :attachment as the attachment name" do
65
+ interpolate("a/:attachment/b").should == "a/photo/b"
66
+ end
66
67
 
67
- it "should interpolate :style as the style name" do
68
- interpolate("a/:style/b").should == "a/small/b"
69
- end
68
+ it "should interpolate :style as the style name" do
69
+ interpolate("a/:style/b").should == "a/small/b"
70
+ end
70
71
 
71
- it "should raise an error for :basename" do
72
- lambda{interpolate("a/:basename/b")}.should raise_error(Interpolation::Error)
73
- end
72
+ it "should raise an error for :basename by default" do
73
+ lambda{interpolate("a/:basename/b")}.should raise_error(Interpolation::Error)
74
+ end
74
75
 
75
- it "should raise an error for :extension" do
76
- lambda{interpolate("a/:extension/b")}.should raise_error(Interpolation::Error)
77
- end
76
+ it "should raise an error for :extension by default" do
77
+ lambda{interpolate("a/:extension/b")}.should raise_error(Interpolation::Error)
78
+ end
78
79
 
79
- it "should allow using braces for interpolating between symbol characters" do
80
- @thing.stubs(:id).returns(5)
81
- interpolate("a/x:{id}x/b").should == "a/x5x/b"
82
- end
80
+ it "should allow overriding the basename to use to avoid an error" do
81
+ interpolate("a/:basename/b", :basename => 'BASENAME').should == 'a/BASENAME/b'
82
+ end
83
83
 
84
- it "should raise an error for an unrecognized interpolation key" do
85
- lambda{interpolate(":invalid")}.should raise_error(Interpolation::Error)
86
- end
87
- end
84
+ it "should allow overriding the extension to use to avoid an error" do
85
+ interpolate("a/:extension/b", :extension => 'EXT').should == 'a/EXT/b'
86
+ end
88
87
 
89
- describe "when the file name is being stored" do
90
- before do
91
- Thing.has_attachment :photo do
92
- style :small, {}
93
- store_attributes :file_name => :photo_file_name
88
+ it "should take the extension from the style format, if given" do
89
+ @style[:format] = 'FMT'
90
+ Interpolation.interpolate("a/:extension/b", @thing, :photo, @style).should == 'a/FMT/b'
94
91
  end
95
92
 
96
- @thing = Thing.new(:photo => test_image_file('test.jpg'))
97
- @style = Thing.attachment_reflections[:photo].styles[:small]
98
- end
93
+ it "should take the extension from the overridden basename, if given" do
94
+ interpolate("a/:extension/b", :basename => 'BASENAME.EXT').should == 'a/EXT/b'
95
+ end
96
+
97
+ it "should use an extension override over the style format if both are present" do
98
+ @style[:format] = 'FMT'
99
+ interpolate("a/:extension/b", :extension => 'EXT').should == 'a/EXT/b'
100
+ end
99
101
 
100
- it "should interpolate :basename as the basename of the uploaded file" do
101
- interpolate("a/:basename/b").should == "a/test.jpg/b"
102
+ it "should use the style format over the basename override if both are present" do
103
+ @style[:format] = 'FMT'
104
+ interpolate("a/:extension/b", :basename => 'BASENAME.EXT').should == 'a/FMT/b'
105
+ end
106
+
107
+ it "should not modify the hash of overrides, if given" do
108
+ overrides = {:basename => 'BASENAME.EXT'}
109
+ interpolate("a/:extension/b", overrides).should == 'a/EXT/b'
110
+ overrides.should == {:basename => 'BASENAME.EXT'}
111
+ end
112
+
113
+ it "should allow using braces for interpolating between symbol characters" do
114
+ @thing.stubs(:id).returns(5)
115
+ interpolate("a/x:{id}x/b").should == "a/x5x/b"
116
+ end
117
+
118
+ it "should raise an error for an unrecognized interpolation key" do
119
+ lambda{interpolate(":invalid")}.should raise_error(Interpolation::Error)
120
+ end
102
121
  end
103
122
 
104
- it "should interpolate :extension as the extension of the uploaded file" do
105
- interpolate("a/:extension/b").should == "a/jpg/b"
123
+ describe "when the file name is being stored" do
124
+ before do
125
+ Thing.has_attachment :photo do
126
+ style :small, {}
127
+ store_attributes :file_name => :photo_file_name
128
+ end
129
+
130
+ @thing = Thing.new(:photo => test_image_file('test.jpg'))
131
+ @style = Thing.attachment_reflections[:photo].styles[:small]
132
+ end
133
+
134
+ it "should interpolate :basename as the basename of the uploaded file" do
135
+ interpolate("a/:basename/b").should == "a/test.jpg/b"
136
+ end
137
+
138
+ it "should interpolate :extension as the extension of the uploaded file" do
139
+ interpolate("a/:extension/b").should == "a/jpg/b"
140
+ end
106
141
  end
107
142
  end
108
143
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bulldog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - George Ogata