fog-dragonfly 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. data/.specopts +2 -0
  2. data/.yardopts +23 -0
  3. data/Gemfile +23 -0
  4. data/Gemfile.rails.2.3.5 +14 -0
  5. data/History.md +266 -0
  6. data/LICENSE +20 -0
  7. data/README.md +88 -0
  8. data/Rakefile +92 -0
  9. data/VERSION +1 -0
  10. data/config.ru +13 -0
  11. data/docs.watchr +1 -0
  12. data/dragonfly.gemspec +293 -0
  13. data/extra_docs/Analysers.md +108 -0
  14. data/extra_docs/Caching.md +23 -0
  15. data/extra_docs/Configuration.md +138 -0
  16. data/extra_docs/DataStorage.md +136 -0
  17. data/extra_docs/Encoding.md +96 -0
  18. data/extra_docs/GeneralUsage.md +121 -0
  19. data/extra_docs/Generators.md +102 -0
  20. data/extra_docs/Heroku.md +50 -0
  21. data/extra_docs/Index.md +36 -0
  22. data/extra_docs/MimeTypes.md +40 -0
  23. data/extra_docs/Models.md +266 -0
  24. data/extra_docs/Mongo.md +45 -0
  25. data/extra_docs/Processing.md +130 -0
  26. data/extra_docs/Rack.md +52 -0
  27. data/extra_docs/Rails2.md +55 -0
  28. data/extra_docs/Rails3.md +62 -0
  29. data/extra_docs/Sinatra.md +25 -0
  30. data/extra_docs/URLs.md +169 -0
  31. data/features/3.0.3.feature +8 -0
  32. data/features/images.feature +47 -0
  33. data/features/no_processing.feature +14 -0
  34. data/features/rails_2.3.5.feature +7 -0
  35. data/features/steps/common_steps.rb +8 -0
  36. data/features/steps/dragonfly_steps.rb +66 -0
  37. data/features/steps/rails_steps.rb +39 -0
  38. data/features/support/env.rb +40 -0
  39. data/fixtures/files/app/models/album.rb +3 -0
  40. data/fixtures/files/app/views/albums/new.html.erb +4 -0
  41. data/fixtures/files/app/views/albums/show.html.erb +4 -0
  42. data/fixtures/files/config/initializers/dragonfly.rb +4 -0
  43. data/fixtures/files/features/manage_album_images.feature +12 -0
  44. data/fixtures/files/features/step_definitions/image_steps.rb +15 -0
  45. data/fixtures/files/features/support/paths.rb +15 -0
  46. data/fixtures/files/features/text_images.feature +7 -0
  47. data/fixtures/rails_2.3.5/template.rb +10 -0
  48. data/fixtures/rails_3.0.3/template.rb +20 -0
  49. data/irbrc.rb +17 -0
  50. data/lib/dragonfly.rb +45 -0
  51. data/lib/dragonfly/active_model_extensions.rb +13 -0
  52. data/lib/dragonfly/active_model_extensions/attachment.rb +169 -0
  53. data/lib/dragonfly/active_model_extensions/class_methods.rb +45 -0
  54. data/lib/dragonfly/active_model_extensions/instance_methods.rb +28 -0
  55. data/lib/dragonfly/active_model_extensions/validations.rb +37 -0
  56. data/lib/dragonfly/analyser.rb +59 -0
  57. data/lib/dragonfly/analysis/file_command_analyser.rb +32 -0
  58. data/lib/dragonfly/analysis/image_magick_analyser.rb +47 -0
  59. data/lib/dragonfly/analysis/r_magick_analyser.rb +63 -0
  60. data/lib/dragonfly/app.rb +182 -0
  61. data/lib/dragonfly/config/heroku.rb +19 -0
  62. data/lib/dragonfly/config/image_magick.rb +41 -0
  63. data/lib/dragonfly/config/r_magick.rb +46 -0
  64. data/lib/dragonfly/config/rails.rb +17 -0
  65. data/lib/dragonfly/configurable.rb +119 -0
  66. data/lib/dragonfly/core_ext/object.rb +8 -0
  67. data/lib/dragonfly/core_ext/string.rb +9 -0
  68. data/lib/dragonfly/core_ext/symbol.rb +9 -0
  69. data/lib/dragonfly/data_storage.rb +9 -0
  70. data/lib/dragonfly/data_storage/file_data_store.rb +114 -0
  71. data/lib/dragonfly/data_storage/mongo_data_store.rb +82 -0
  72. data/lib/dragonfly/data_storage/s3data_store.rb +115 -0
  73. data/lib/dragonfly/encoder.rb +13 -0
  74. data/lib/dragonfly/encoding/image_magick_encoder.rb +57 -0
  75. data/lib/dragonfly/encoding/r_magick_encoder.rb +61 -0
  76. data/lib/dragonfly/function_manager.rb +69 -0
  77. data/lib/dragonfly/generation/hash_with_css_style_keys.rb +23 -0
  78. data/lib/dragonfly/generation/image_magick_generator.rb +140 -0
  79. data/lib/dragonfly/generation/r_magick_generator.rb +155 -0
  80. data/lib/dragonfly/generator.rb +9 -0
  81. data/lib/dragonfly/image_magick_utils.rb +81 -0
  82. data/lib/dragonfly/job.rb +371 -0
  83. data/lib/dragonfly/job_builder.rb +39 -0
  84. data/lib/dragonfly/job_definitions.rb +26 -0
  85. data/lib/dragonfly/job_endpoint.rb +15 -0
  86. data/lib/dragonfly/loggable.rb +28 -0
  87. data/lib/dragonfly/middleware.rb +34 -0
  88. data/lib/dragonfly/processing/image_magick_processor.rb +99 -0
  89. data/lib/dragonfly/processing/r_magick_processor.rb +126 -0
  90. data/lib/dragonfly/processor.rb +9 -0
  91. data/lib/dragonfly/r_magick_utils.rb +48 -0
  92. data/lib/dragonfly/rails/images.rb +22 -0
  93. data/lib/dragonfly/response.rb +82 -0
  94. data/lib/dragonfly/routed_endpoint.rb +40 -0
  95. data/lib/dragonfly/serializer.rb +32 -0
  96. data/lib/dragonfly/simple_cache.rb +23 -0
  97. data/lib/dragonfly/simple_endpoint.rb +63 -0
  98. data/lib/dragonfly/temp_object.rb +220 -0
  99. data/samples/beach.png +0 -0
  100. data/samples/egg.png +0 -0
  101. data/samples/round.gif +0 -0
  102. data/samples/sample.docx +0 -0
  103. data/samples/taj.jpg +0 -0
  104. data/spec/argument_matchers.rb +19 -0
  105. data/spec/dragonfly/active_model_extensions/active_model_setup.rb +97 -0
  106. data/spec/dragonfly/active_model_extensions/active_record_setup.rb +85 -0
  107. data/spec/dragonfly/active_model_extensions/model_spec.rb +723 -0
  108. data/spec/dragonfly/active_model_extensions/spec_helper.rb +11 -0
  109. data/spec/dragonfly/analyser_spec.rb +123 -0
  110. data/spec/dragonfly/analysis/file_command_analyser_spec.rb +57 -0
  111. data/spec/dragonfly/analysis/image_magick_analyser_spec.rb +15 -0
  112. data/spec/dragonfly/analysis/r_magick_analyser_spec.rb +27 -0
  113. data/spec/dragonfly/analysis/shared_analyser_spec.rb +51 -0
  114. data/spec/dragonfly/app_spec.rb +280 -0
  115. data/spec/dragonfly/config/r_magick_spec.rb +25 -0
  116. data/spec/dragonfly/configurable_spec.rb +220 -0
  117. data/spec/dragonfly/core_ext/string_spec.rb +17 -0
  118. data/spec/dragonfly/core_ext/symbol_spec.rb +17 -0
  119. data/spec/dragonfly/data_storage/data_store_spec.rb +76 -0
  120. data/spec/dragonfly/data_storage/file_data_store_spec.rb +169 -0
  121. data/spec/dragonfly/data_storage/mongo_data_store_spec.rb +38 -0
  122. data/spec/dragonfly/data_storage/s3_data_store_spec.rb +94 -0
  123. data/spec/dragonfly/deprecation_spec.rb +20 -0
  124. data/spec/dragonfly/encoding/image_magick_encoder_spec.rb +41 -0
  125. data/spec/dragonfly/encoding/r_magick_encoder_spec.rb +37 -0
  126. data/spec/dragonfly/function_manager_spec.rb +154 -0
  127. data/spec/dragonfly/generation/hash_with_css_style_keys_spec.rb +24 -0
  128. data/spec/dragonfly/generation/image_magick_generator_spec.rb +12 -0
  129. data/spec/dragonfly/generation/r_magick_generator_spec.rb +24 -0
  130. data/spec/dragonfly/generation/shared_generator_spec.rb +91 -0
  131. data/spec/dragonfly/image_magick_utils_spec.rb +16 -0
  132. data/spec/dragonfly/job_builder_spec.rb +37 -0
  133. data/spec/dragonfly/job_definitions_spec.rb +35 -0
  134. data/spec/dragonfly/job_endpoint_spec.rb +120 -0
  135. data/spec/dragonfly/job_spec.rb +773 -0
  136. data/spec/dragonfly/loggable_spec.rb +80 -0
  137. data/spec/dragonfly/middleware_spec.rb +68 -0
  138. data/spec/dragonfly/processing/image_magick_processor_spec.rb +29 -0
  139. data/spec/dragonfly/processing/r_magick_processor_spec.rb +26 -0
  140. data/spec/dragonfly/processing/shared_processing_spec.rb +215 -0
  141. data/spec/dragonfly/routed_endpoint_spec.rb +48 -0
  142. data/spec/dragonfly/serializer_spec.rb +61 -0
  143. data/spec/dragonfly/simple_cache_spec.rb +27 -0
  144. data/spec/dragonfly/simple_endpoint_spec.rb +89 -0
  145. data/spec/dragonfly/temp_object_spec.rb +352 -0
  146. data/spec/image_matchers.rb +47 -0
  147. data/spec/simple_matchers.rb +44 -0
  148. data/spec/spec_helper.rb +58 -0
  149. data/yard/handlers/configurable_attr_handler.rb +38 -0
  150. data/yard/setup.rb +15 -0
  151. data/yard/templates/default/fulldoc/html/css/common.css +107 -0
  152. data/yard/templates/default/layout/html/layout.erb +87 -0
  153. data/yard/templates/default/module/html/configuration_summary.erb +31 -0
  154. data/yard/templates/default/module/setup.rb +17 -0
  155. metadata +550 -0
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ describe Dragonfly::Serializer do
5
+
6
+ include Dragonfly::Serializer
7
+
8
+ [
9
+ 'a',
10
+ 'sdhflasd',
11
+ '/2010/03/01/hello.png',
12
+ '//..',
13
+ 'whats/up.egg.frog',
14
+ '£ñçùí;'
15
+ ].each do |string|
16
+ it "should encode #{string.inspect} properly with no padding/line break" do
17
+ b64_encode(string).should_not =~ /\n|=/
18
+ end
19
+ it "should correctly encode and decode #{string.inspect} to the same string" do
20
+ str = b64_decode(b64_encode(string))
21
+ str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
22
+ str.should == string
23
+ end
24
+ end
25
+
26
+ [
27
+ :hello,
28
+ nil,
29
+ true,
30
+ 4,
31
+ 2.3,
32
+ 'wassup man',
33
+ [3,4,5],
34
+ {:wo => 'there'},
35
+ [{:this => 'should', :work => [3, 5.3, nil, {false => 'egg'}]}, [], true]
36
+ ].each do |object|
37
+ it "should correctly marshal encode #{object.inspect} properly with no padding/line break" do
38
+ encoded = marshal_encode(object)
39
+ # raise encoded.index("\n").inspect
40
+ encoded.should be_a(String)
41
+ encoded.should_not =~ /\n|=/
42
+ end
43
+ it "should correctly marshal encode and decode #{object.inspect} to the same object" do
44
+ marshal_decode(marshal_encode(object)).should == object
45
+ end
46
+ end
47
+
48
+ describe "marshal_decode" do
49
+ it "should raise an error if the string passed in is empty" do
50
+ lambda{
51
+ marshal_decode('')
52
+ }.should raise_error(Dragonfly::Serializer::BadString)
53
+ end
54
+ it "should raise an error if the string passed in is gobbledeegook" do
55
+ lambda{
56
+ marshal_decode('ahasdkjfhasdkfjh')
57
+ }.should raise_error(Dragonfly::Serializer::BadString)
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Dragonfly::SimpleCache do
4
+
5
+ before(:each) do
6
+ @cache = Dragonfly::SimpleCache.new(2)
7
+ end
8
+
9
+ it "should act as a normal hash" do
10
+ @cache[:egg] = 'four'
11
+ @cache[:egg].should == 'four'
12
+ end
13
+
14
+ it "should allow filling up to the limit" do
15
+ @cache[:a] = 1
16
+ @cache[:b] = 2
17
+ @cache.should == {:a => 1, :b => 2}
18
+ end
19
+
20
+ it "should get rid of the first added when full" do
21
+ @cache[:a] = 1
22
+ @cache[:b] = 2
23
+ @cache[:c] = 3
24
+ @cache.should == {:b => 2, :c => 3}
25
+ end
26
+
27
+ end
@@ -0,0 +1,89 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'rack/mock'
3
+ require 'rack/cache'
4
+
5
+ def request(app, path)
6
+ Rack::MockRequest.new(app).get(path)
7
+ end
8
+
9
+ describe Dragonfly::SimpleEndpoint do
10
+
11
+ before(:each) do
12
+ @app = test_app
13
+ @app.protect_from_dos_attacks = false
14
+ @uid = @app.store('HELLO THERE')
15
+ @endpoint = Dragonfly::SimpleEndpoint.new(@app)
16
+ end
17
+
18
+ after(:each) do
19
+ @app.destroy(@uid)
20
+ end
21
+
22
+ it "should return the thing when given the url" do
23
+ url = "/#{@app.fetch(@uid).serialize}"
24
+ response = request(@endpoint, url)
25
+ response.status.should == 200
26
+ response.body.should == 'HELLO THERE'
27
+ response.content_type.should == 'application/octet-stream'
28
+ end
29
+
30
+ it "should return a 400 if no sha given but protection on" do
31
+ @app.protect_from_dos_attacks = true
32
+ url = "/#{@app.fetch(@uid).serialize}"
33
+ response = request(@endpoint, url)
34
+ response.status.should == 400
35
+ end
36
+
37
+ it "should return a 400 if wrong sha given and protection on" do
38
+ @app.protect_from_dos_attacks = true
39
+ url = "/#{@app.fetch(@uid).serialize}?s=asdfs"
40
+ response = request(@endpoint, url)
41
+ response.status.should == 400
42
+ end
43
+
44
+ it "should return a 404 when the url isn't known" do
45
+ response = request(@endpoint, '/sadhfasdfdsfsdf')
46
+ response.status.should == 404
47
+ response.body.should == 'Not found'
48
+ response.content_type.should == 'text/plain'
49
+ end
50
+
51
+ it "should return a 404 when the url is a well-encoded but bad array" do
52
+ url = "/#{Dragonfly::Serializer.marshal_encode([[:egg, {:some => 'args'}]])}"
53
+ response = request(@endpoint, url)
54
+ response.status.should == 404
55
+ response.body.should == 'Not found'
56
+ response.content_type.should == 'text/plain'
57
+ end
58
+
59
+ it "should still work when mapped to a prefix" do
60
+ endpoint = @endpoint
61
+ rack_app = Rack::Builder.new do
62
+ map '/some_prefix' do
63
+ run endpoint
64
+ end
65
+ end.to_app
66
+ url = "/some_prefix/#{@app.fetch(@uid).serialize}"
67
+ response = request(rack_app, url)
68
+ response.status.should == 200
69
+ response.body.should == 'HELLO THERE'
70
+ end
71
+
72
+ it "should return a simple text response at the root" do
73
+ response = request(@endpoint, '/')
74
+ response.status.should == 200
75
+ response.body.length.should > 0
76
+ response.content_type.should == 'text/plain'
77
+ end
78
+
79
+ it "should return a cacheable response" do
80
+ url = "/#{@app.fetch(@uid).serialize}"
81
+ cache = Rack::Cache.new(@endpoint, :entitystore => 'heap:/')
82
+ response = request(cache, url)
83
+ response.status.should == 200
84
+ response.headers['X-Rack-Cache'].should == "miss, store"
85
+ response = request(cache, url)
86
+ response.status.should == 200
87
+ response.headers['X-Rack-Cache'].should == "fresh"
88
+ end
89
+ end
@@ -0,0 +1,352 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Dragonfly::TempObject do
4
+
5
+ ####### Helper Methods #######
6
+
7
+ def sample_path(filename)
8
+ File.dirname(__FILE__) + '/../../samples/' + filename
9
+ end
10
+
11
+ def new_tempfile(data='HELLO')
12
+ tempfile = Tempfile.new('test')
13
+ tempfile.write(data)
14
+ tempfile.rewind
15
+ tempfile
16
+ end
17
+
18
+ def new_file(data='HELLO')
19
+ File.open('/tmp/test_file', 'w') do |f|
20
+ f.write(data)
21
+ end
22
+ File.new('/tmp/test_file')
23
+ end
24
+
25
+ def new_temp_object(data, opts={})
26
+ klass = opts.delete(:class) || Dragonfly::TempObject
27
+ klass.new(initialization_object(data), opts)
28
+ end
29
+
30
+ def initialization_object(data)
31
+ raise NotImplementedError, "This should be implemented in the describe block!"
32
+ end
33
+
34
+ def get_parts(temp_object)
35
+ parts = []
36
+ temp_object.each do |bytes|
37
+ parts << bytes
38
+ end
39
+ parts.length.should >= 2 # Sanity check to check that the sample file is adequate for this test
40
+ parts
41
+ end
42
+
43
+ ###############################
44
+
45
+ it "should raise an error if initialized with a non-string/file/tempfile" do
46
+ lambda{
47
+ Dragonfly::TempObject.new(3)
48
+ }.should raise_error(ArgumentError)
49
+ end
50
+
51
+ describe "common behaviour", :shared => true do
52
+
53
+ describe "simple initialization" do
54
+
55
+ before(:each) do
56
+ @temp_object = new_temp_object('HELLO')
57
+ end
58
+
59
+ describe "data" do
60
+ it "should return the data correctly" do
61
+ @temp_object.data.should == 'HELLO'
62
+ end
63
+ end
64
+
65
+ describe "file" do
66
+ it "should return a readable file" do
67
+ @temp_object.file.should be_a(File)
68
+ end
69
+ it "should contain the correct data" do
70
+ @temp_object.file.read.should == 'HELLO'
71
+ end
72
+ it "should yield a file then close it if a block is given" do
73
+ @temp_object.file do |f|
74
+ f.read.should == 'HELLO'
75
+ f.should_receive :close
76
+ end
77
+ end
78
+ it "should return whatever is returned from the block if a block is given" do
79
+ @temp_object.file do |f|
80
+ 'doogie'
81
+ end.should == 'doogie'
82
+ end
83
+ it "should enable reading the file twice" do
84
+ @temp_object.file{|f| f.read }.should == "HELLO"
85
+ @temp_object.file{|f| f.read }.should == "HELLO"
86
+ end
87
+ end
88
+
89
+ describe "tempfile" do
90
+ it "should create a closed tempfile" do
91
+ @temp_object.tempfile.should be_a(Tempfile)
92
+ @temp_object.tempfile.should be_closed
93
+ end
94
+ it "should contain the correct data" do
95
+ @temp_object.tempfile.open.read.should == 'HELLO'
96
+ end
97
+ end
98
+
99
+ describe "path" do
100
+ it "should return the absolute file path" do
101
+ @temp_object.path.should == @temp_object.tempfile.path
102
+ end
103
+ end
104
+
105
+ describe "size" do
106
+ it "should return the size in bytes" do
107
+ @temp_object.size.should == 5
108
+ end
109
+ end
110
+
111
+ describe "to_file" do
112
+ before(:each) do
113
+ @filename = 'eggnog.txt'
114
+ FileUtils.rm(@filename) if File.exists?(@filename)
115
+ end
116
+ after(:each) do
117
+ FileUtils.rm(@filename) if File.exists?(@filename)
118
+ end
119
+ it "should write to a file" do
120
+ @temp_object.to_file(@filename)
121
+ File.exists?(@filename).should be_true
122
+ end
123
+ it "should write the correct data to the file" do
124
+ @temp_object.to_file(@filename)
125
+ File.read(@filename).should == 'HELLO'
126
+ end
127
+ it "should return a readable file" do
128
+ file = @temp_object.to_file(@filename)
129
+ file.should be_a(File)
130
+ file.read.should == 'HELLO'
131
+ end
132
+ end
133
+
134
+ end
135
+
136
+ describe "initializing attributes too" do
137
+ it "should set the name" do
138
+ temp_object = Dragonfly::TempObject.new(initialization_object('HELLO'), :name => 'monkey.egg')
139
+ temp_object.name.should == 'monkey.egg'
140
+ end
141
+ it "should set the meta" do
142
+ temp_object = Dragonfly::TempObject.new(initialization_object('HELLO'), :meta => {:dr => 'doolittle'})
143
+ temp_object.meta.should == {:dr => 'doolittle'}
144
+ end
145
+ it "should set the format" do
146
+ temp_object = Dragonfly::TempObject.new(initialization_object('HELLO'), :format => :jpg)
147
+ temp_object.format.should == :jpg
148
+ end
149
+ it "should raise an error if an invalid option is given" do
150
+ lambda {
151
+ Dragonfly::TempObject.new(initialization_object('HELLO'), :doobie => 'doo')
152
+ }.should raise_error(ArgumentError)
153
+ end
154
+ end
155
+
156
+ describe "each" do
157
+ it "should yield 8192 bytes each time" do
158
+ temp_object = new_temp_object(File.read(sample_path('round.gif')))
159
+ parts = get_parts(temp_object)
160
+ parts[0...-1].each do |part|
161
+ part.bytesize.should == 8192
162
+ end
163
+ parts.last.bytesize.should <= 8192
164
+ end
165
+ it "should yield the number of bytes specified in the class configuration" do
166
+ klass = Class.new(Dragonfly::TempObject)
167
+ temp_object = new_temp_object(File.read(sample_path('round.gif')), :class => klass)
168
+ klass.block_size = 3001
169
+ parts = get_parts(temp_object)
170
+ parts[0...-1].each do |part|
171
+ part.length.should == 3001
172
+ end
173
+ parts.last.length.should <= 3001
174
+ end
175
+ end
176
+
177
+ end
178
+
179
+ describe "initializing from a string" do
180
+
181
+ def initialization_object(data)
182
+ data
183
+ end
184
+
185
+ it_should_behave_like "common behaviour"
186
+
187
+ it "should not create a file when calling each" do
188
+ temp_object = new_temp_object('HELLO')
189
+ temp_object.should_not_receive(:tempfile)
190
+ temp_object.each{}
191
+ end
192
+ end
193
+
194
+ describe "initializing from a tempfile" do
195
+
196
+ def initialization_object(data)
197
+ new_tempfile(data)
198
+ end
199
+
200
+ it_should_behave_like "common behaviour"
201
+
202
+ it "should not create a data string when calling each" do
203
+ temp_object = new_temp_object('HELLO')
204
+ temp_object.should_not_receive(:data)
205
+ temp_object.each{}
206
+ end
207
+ end
208
+
209
+ describe "initializing from a file" do
210
+
211
+ def initialization_object(data)
212
+ new_file(data)
213
+ end
214
+
215
+ it_should_behave_like "common behaviour"
216
+
217
+ it "should not create a data string when calling each" do
218
+ temp_object = new_temp_object('HELLO')
219
+ temp_object.should_not_receive(:data)
220
+ temp_object.each{}
221
+ end
222
+ end
223
+
224
+ describe "initializing from another temp object" do
225
+ before(:each) do
226
+ @temp_object1 = Dragonfly::TempObject.new(new_tempfile('hello'))
227
+ @temp_object2 = Dragonfly::TempObject.new(@temp_object1)
228
+ end
229
+ it "should not be the same object" do
230
+ @temp_object1.should_not == @temp_object2
231
+ end
232
+ it "should have the same data" do
233
+ @temp_object1.data.should == @temp_object2.data
234
+ end
235
+ it "should have a different file path" do
236
+ @temp_object1.path.should_not == @temp_object2.path
237
+ end
238
+ end
239
+
240
+ describe "name" do
241
+ before(:each) do
242
+ @obj = new_tempfile
243
+ end
244
+ it "should set the name if the initial object responds to 'original filename'" do
245
+ def @obj.original_filename
246
+ 'jimmy.page'
247
+ end
248
+ Dragonfly::TempObject.new(@obj).name.should == 'jimmy.page'
249
+ end
250
+ it "should not set the name if the initial object doesn't respond to 'original filename'" do
251
+ Dragonfly::TempObject.new(@obj).name.should be_nil
252
+ end
253
+ it "should set the name if the initial object is a file object" do
254
+ file = File.new(SAMPLES_DIR + '/round.gif')
255
+ temp_object = Dragonfly::TempObject.new(file)
256
+ temp_object.name.should == 'round.gif'
257
+ end
258
+ it "should still be nil if set to empty string on initialize" do
259
+ temp_object = Dragonfly::TempObject.new('sdf', :name => '')
260
+ temp_object.name.should be_nil
261
+ end
262
+ it "should allow setting" do
263
+ temp_object = Dragonfly::TempObject.new('sdf')
264
+ temp_object.name = "jonny.briggs"
265
+ temp_object.name.should == 'jonny.briggs'
266
+ end
267
+ end
268
+
269
+ describe "ext" do
270
+ it "should use the correct extension from name" do
271
+ temp_object = Dragonfly::TempObject.new('asfsadf', :name => 'hello.there.mate')
272
+ temp_object.ext.should == 'mate'
273
+ end
274
+ it "should be nil if name has none" do
275
+ temp_object = Dragonfly::TempObject.new('asfsadf', :name => 'hello')
276
+ temp_object.ext.should be_nil
277
+ end
278
+ it "should be nil if name is nil" do
279
+ temp_object = Dragonfly::TempObject.new('asfsadf')
280
+ temp_object.ext.should be_nil
281
+ end
282
+ end
283
+
284
+ describe "basename" do
285
+ it "should use the correct basename from name" do
286
+ temp_object = Dragonfly::TempObject.new('A', :name => 'hello.there.mate')
287
+ temp_object.basename.should == 'hello.there'
288
+ end
289
+ it "should be the name if it has no ext" do
290
+ temp_object = Dragonfly::TempObject.new('A', :name => 'hello')
291
+ temp_object.basename.should == 'hello'
292
+ end
293
+ it "should be nil if name is nil" do
294
+ temp_object = Dragonfly::TempObject.new('A', :name => nil)
295
+ temp_object.basename.should be_nil
296
+ end
297
+ end
298
+
299
+ describe "meta" do
300
+ before(:each) do
301
+ @temp_object = Dragonfly::TempObject.new('get outta here!')
302
+ end
303
+ it "should return an empty hash if not set" do
304
+ @temp_object.meta.should == {}
305
+ end
306
+ it "should allow setting" do
307
+ @temp_object.meta = {:teeth => 'many'}
308
+ @temp_object.meta.should == {:teeth => 'many'}
309
+ end
310
+ end
311
+
312
+ describe "format" do
313
+ it "should return nil if not set" do
314
+ temp_object = Dragonfly::TempObject.new('wassin my belly??!')
315
+ temp_object.format.should be_nil
316
+ end
317
+ it "should allow setting on initialize" do
318
+ temp_object = Dragonfly::TempObject.new('wassin my belly??!', :format => :jpg)
319
+ temp_object.format.should == :jpg
320
+ end
321
+ it "should allow setting" do
322
+ temp_object = Dragonfly::TempObject.new('jo*ida pero contenta')
323
+ temp_object.format = :tiff
324
+ temp_object.format.should == :tiff
325
+ end
326
+ end
327
+
328
+ describe "extract_attributes_from" do
329
+ before(:each) do
330
+ @temp_object = Dragonfly::TempObject.new("ne'er gonna give you up",
331
+ :meta => {:a => 4},
332
+ :name => 'fred.txt',
333
+ :format => :txt
334
+ )
335
+ @attributes = {:meta => {:b => 5}, :ogle => 'bogle', :format => :dungbats}
336
+ @temp_object.extract_attributes_from(@attributes)
337
+ end
338
+ it "should overwrite its own attributes if specified" do
339
+ @temp_object.format.should == :dungbats
340
+ end
341
+ it "should merge its own meta if specified" do
342
+ @temp_object.meta.should == {:a => 4, :b => 5}
343
+ end
344
+ it "should leave non-specified attributes untouched" do
345
+ @temp_object.name.should == 'fred.txt'
346
+ end
347
+ it "should remove attributes from the hash" do
348
+ @attributes.should == {:ogle => 'bogle'}
349
+ end
350
+ end
351
+
352
+ end