dragonfly 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of dragonfly might be problematic. Click here for more details.
- data/.gitignore +2 -0
- data/.specopts +2 -0
- data/.yardopts +11 -5
- data/Gemfile +22 -0
- data/Gemfile.rails.2.3.5 +13 -0
- data/History.md +49 -0
- data/README.md +18 -28
- data/Rakefile +24 -36
- data/VERSION +1 -1
- data/config.ru +4 -1
- data/dragonfly.gemspec +85 -99
- data/extra_docs/Analysers.md +66 -30
- data/extra_docs/Caching.md +22 -0
- data/extra_docs/Configuration.md +116 -0
- data/extra_docs/DataStorage.md +114 -14
- data/extra_docs/Encoding.md +62 -37
- data/extra_docs/GeneralUsage.md +118 -0
- data/extra_docs/Generators.md +92 -0
- data/extra_docs/Heroku.md +51 -0
- data/extra_docs/Index.md +8 -9
- data/extra_docs/MimeTypes.md +18 -17
- data/extra_docs/Models.md +251 -0
- data/extra_docs/Processing.md +94 -70
- data/extra_docs/Rack.md +53 -0
- data/extra_docs/Rails2.md +44 -0
- data/extra_docs/Rails3.md +51 -0
- data/extra_docs/Sinatra.md +21 -0
- data/extra_docs/URLs.md +114 -0
- data/features/images.feature +6 -7
- data/features/no_processing.feature +0 -6
- data/features/rails_2.3.5.feature +1 -1
- data/features/rails_3.0.0.rc.feature +8 -0
- data/features/steps/dragonfly_steps.rb +14 -12
- data/features/steps/rails_steps.rb +20 -9
- data/features/support/env.rb +10 -11
- data/fixtures/files/app/views/albums/new.html.erb +4 -4
- data/fixtures/files/app/views/albums/show.html.erb +1 -1
- data/fixtures/files/features/manage_album_images.feature +1 -1
- data/fixtures/files/features/step_definitions/{album_steps.rb → image_steps.rb} +4 -3
- data/fixtures/files/features/support/paths.rb +2 -0
- data/fixtures/files/features/text_images.feature +7 -0
- data/fixtures/rails_3.0.0.rc/template.rb +21 -0
- data/irbrc.rb +2 -1
- data/lib/dragonfly.rb +4 -16
- data/lib/dragonfly/{active_record_extensions.rb → active_model_extensions.rb} +1 -1
- data/lib/dragonfly/active_model_extensions/attachment.rb +146 -0
- data/lib/dragonfly/{active_record_extensions → active_model_extensions}/class_methods.rb +5 -6
- data/lib/dragonfly/{active_record_extensions → active_model_extensions}/instance_methods.rb +1 -1
- data/lib/dragonfly/{active_record_extensions → active_model_extensions}/validations.rb +5 -9
- data/lib/dragonfly/analyser.rb +59 -0
- data/lib/dragonfly/analysis/file_command_analyser.rb +1 -1
- data/lib/dragonfly/analysis/r_magick_analyser.rb +46 -31
- data/lib/dragonfly/app.rb +138 -173
- data/lib/dragonfly/config/heroku.rb +19 -0
- data/lib/dragonfly/config/r_magick.rb +37 -0
- data/lib/dragonfly/config/{rails_defaults.rb → rails.rb} +6 -7
- data/lib/dragonfly/configurable.rb +30 -27
- data/lib/dragonfly/core_ext/object.rb +1 -1
- data/lib/dragonfly/data_storage/file_data_store.rb +59 -26
- data/lib/dragonfly/data_storage/mongo_data_store.rb +65 -0
- data/lib/dragonfly/data_storage/s3data_store.rb +31 -12
- data/lib/dragonfly/encoder.rb +13 -0
- data/lib/dragonfly/encoding/r_magick_encoder.rb +10 -19
- data/lib/dragonfly/endpoint.rb +43 -0
- data/lib/dragonfly/function_manager.rb +65 -0
- data/lib/dragonfly/{processing/r_magick_text_processor.rb → generation/r_magick_generator.rb} +25 -11
- data/lib/dragonfly/generator.rb +9 -0
- data/lib/dragonfly/job.rb +290 -0
- data/lib/dragonfly/job_builder.rb +39 -0
- data/lib/dragonfly/job_definitions.rb +26 -0
- data/lib/dragonfly/job_endpoint.rb +17 -0
- data/lib/dragonfly/loggable.rb +28 -0
- data/lib/dragonfly/middleware.rb +21 -14
- data/lib/dragonfly/processing/r_magick_processor.rb +71 -48
- data/lib/dragonfly/processor.rb +9 -0
- data/lib/dragonfly/r_magick_utils.rb +24 -0
- data/lib/dragonfly/rails/images.rb +10 -7
- data/lib/dragonfly/routed_endpoint.rb +42 -0
- data/lib/dragonfly/serializer.rb +32 -0
- data/lib/dragonfly/simple_cache.rb +23 -0
- data/lib/dragonfly/simple_endpoint.rb +64 -0
- data/lib/dragonfly/temp_object.rb +77 -45
- data/spec/argument_matchers.rb +7 -17
- data/spec/dragonfly/active_model_extensions/active_model_setup.rb +97 -0
- data/spec/dragonfly/active_model_extensions/active_record_setup.rb +85 -0
- data/spec/dragonfly/{active_record_extensions → active_model_extensions}/model_spec.rb +282 -244
- data/spec/dragonfly/active_model_extensions/spec_helper.rb +11 -0
- data/spec/dragonfly/analyser_spec.rb +123 -0
- data/spec/dragonfly/analysis/file_command_analyser_spec.rb +2 -2
- data/spec/dragonfly/analysis/r_magick_analyser_spec.rb +10 -1
- data/spec/dragonfly/app_spec.rb +175 -69
- data/spec/dragonfly/configurable_spec.rb +14 -0
- data/spec/dragonfly/data_storage/data_store_spec.rb +36 -9
- data/spec/dragonfly/data_storage/file_data_store_spec.rb +61 -38
- data/spec/dragonfly/data_storage/mongo_data_store_spec.rb +18 -0
- data/spec/dragonfly/data_storage/s3_data_store_spec.rb +34 -39
- data/spec/dragonfly/deprecation_spec.rb +20 -0
- data/spec/dragonfly/function_manager_spec.rb +154 -0
- data/spec/dragonfly/generation/r_magick_generator_spec.rb +119 -0
- data/spec/dragonfly/job_builder_spec.rb +37 -0
- data/spec/dragonfly/job_definitions_spec.rb +35 -0
- data/spec/dragonfly/job_endpoint_spec.rb +66 -0
- data/spec/dragonfly/job_spec.rb +605 -0
- data/spec/dragonfly/loggable_spec.rb +80 -0
- data/spec/dragonfly/middleware_spec.rb +37 -17
- data/spec/dragonfly/processing/r_magick_processor_spec.rb +182 -166
- data/spec/dragonfly/routed_endpoint_spec.rb +48 -0
- data/spec/dragonfly/serializer_spec.rb +61 -0
- data/spec/dragonfly/simple_cache_spec.rb +27 -0
- data/spec/dragonfly/simple_endpoint_spec.rb +78 -0
- data/spec/dragonfly/temp_object_spec.rb +154 -119
- data/spec/simple_matchers.rb +22 -0
- data/spec/spec_helper.rb +28 -4
- data/yard/templates/default/layout/html/layout.erb +18 -11
- metadata +89 -190
- data/config.rb +0 -5
- data/extra_docs/ActiveRecord.md +0 -196
- data/extra_docs/ExampleUseCases.md +0 -189
- data/extra_docs/GettingStarted.md +0 -114
- data/extra_docs/Shortcuts.md +0 -118
- data/extra_docs/UsingWithRails.md +0 -81
- data/features/rails_3.0.0.beta3.feature +0 -7
- data/fixtures/rails_3.0.0.beta3/template.rb +0 -16
- data/lib/dragonfly/active_record_extensions/attachment.rb +0 -170
- data/lib/dragonfly/analyser_list.rb +0 -9
- data/lib/dragonfly/analysis/base.rb +0 -10
- data/lib/dragonfly/belongs_to_app.rb +0 -24
- data/lib/dragonfly/config/heroku_rails_images.rb +0 -23
- data/lib/dragonfly/config/r_magick_images.rb +0 -69
- data/lib/dragonfly/config/r_magick_text.rb +0 -25
- data/lib/dragonfly/config/rails_images.rb +0 -13
- data/lib/dragonfly/data_storage/base.rb +0 -21
- data/lib/dragonfly/data_storage/base64_data_store.rb +0 -23
- data/lib/dragonfly/data_storage/transparent_data_store.rb +0 -21
- data/lib/dragonfly/delegatable.rb +0 -14
- data/lib/dragonfly/delegator.rb +0 -62
- data/lib/dragonfly/encoder_list.rb +0 -9
- data/lib/dragonfly/encoding/base.rb +0 -14
- data/lib/dragonfly/encoding/transparent_encoder.rb +0 -14
- data/lib/dragonfly/extended_temp_object.rb +0 -120
- data/lib/dragonfly/parameters.rb +0 -163
- data/lib/dragonfly/processing/base.rb +0 -10
- data/lib/dragonfly/processor_list.rb +0 -9
- data/lib/dragonfly/url_handler.rb +0 -147
- data/spec/dragonfly/active_record_extensions/attachment_spec.rb +0 -8
- data/spec/dragonfly/active_record_extensions/migration.rb +0 -42
- data/spec/dragonfly/active_record_extensions/models.rb +0 -6
- data/spec/dragonfly/active_record_extensions/spec_helper.rb +0 -24
- data/spec/dragonfly/belongs_to_app_spec.rb +0 -55
- data/spec/dragonfly/delegatable_spec.rb +0 -32
- data/spec/dragonfly/delegator_spec.rb +0 -145
- data/spec/dragonfly/extended_temp_object_spec.rb +0 -71
- data/spec/dragonfly/parameters_spec.rb +0 -298
- data/spec/dragonfly/processing/r_magick_text_processor_spec.rb +0 -84
- data/spec/dragonfly/url_handler_spec.rb +0 -247
- data/spec/dragonfly_spec.rb +0 -16
- data/spec/ginger_scenarios.rb +0 -13
@@ -1,17 +1,18 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
require 'active_support/core_ext/hash/except' # Needed for Rails 3.0.0.rc but subsequently fixed - TODO: remove when gem is updated
|
2
3
|
|
3
4
|
describe Item do
|
4
5
|
|
5
6
|
# See extra setup in models / initializer files
|
6
7
|
|
7
|
-
describe "
|
8
|
+
describe "defining accessors" do
|
9
|
+
|
10
|
+
let(:app1){ Dragonfly[:images] }
|
11
|
+
let(:app2){ Dragonfly[:videos] }
|
8
12
|
|
9
|
-
let(:app1){ Dragonfly::App[:images] }
|
10
|
-
let(:app2){ Dragonfly::App[:videos] }
|
11
|
-
|
12
13
|
it "should return the mapping of apps to attributes" do
|
13
|
-
|
14
|
-
|
14
|
+
app1.define_macro(model_class, :image_accessor)
|
15
|
+
app2.define_macro(model_class, :video_accessor)
|
15
16
|
Item.class_eval do
|
16
17
|
image_accessor :preview_image
|
17
18
|
video_accessor :trailer_video
|
@@ -19,58 +20,99 @@ describe Item do
|
|
19
20
|
Item.dragonfly_apps_for_attributes.should == {:preview_image => app1, :trailer_video => app2}
|
20
21
|
end
|
21
22
|
|
23
|
+
it "should work for included modules (e.g. Mongoid::Document)" do
|
24
|
+
mongoid_document = Module.new
|
25
|
+
app1.define_macro_on_include(mongoid_document, :dog_accessor)
|
26
|
+
model_class = Class.new do
|
27
|
+
def self.before_save(*args); end
|
28
|
+
def self.before_destroy(*args); end
|
29
|
+
include mongoid_document
|
30
|
+
dog_accessor :doogie
|
31
|
+
end
|
32
|
+
model_class.dragonfly_apps_for_attributes.should == {:doogie => app1}
|
33
|
+
end
|
34
|
+
|
22
35
|
end
|
23
|
-
|
24
|
-
describe "defining accessors" do
|
25
36
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
37
|
+
describe "correctly defined" do
|
38
|
+
|
39
|
+
before(:each) do
|
40
|
+
@app = Dragonfly[:images]
|
41
|
+
@app.define_macro(model_class, :image_accessor)
|
42
|
+
Item.class_eval do
|
43
|
+
image_accessor :preview_image
|
44
|
+
end
|
45
|
+
@item = Item.new
|
32
46
|
end
|
33
47
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
@item = Item.new
|
43
|
-
end
|
48
|
+
it "should provide a reader" do
|
49
|
+
@item.should respond_to(:preview_image)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should provide a writer" do
|
53
|
+
@item.should respond_to(:preview_image=)
|
54
|
+
end
|
44
55
|
|
45
|
-
|
46
|
-
|
56
|
+
describe "when there has been nothing assigned" do
|
57
|
+
it "the reader should return nil" do
|
58
|
+
@item.preview_image.should be_nil
|
59
|
+
end
|
60
|
+
it "the uid should be nil" do
|
61
|
+
@item.preview_image_uid.should be_nil
|
62
|
+
end
|
63
|
+
it "should not try to store anything on save" do
|
64
|
+
@app.datastore.should_not_receive(:store)
|
65
|
+
@item.save!
|
47
66
|
end
|
67
|
+
it "should not try to destroy anything on save" do
|
68
|
+
@app.datastore.should_not_receive(:destroy)
|
69
|
+
@item.save!
|
70
|
+
end
|
71
|
+
it "should not try to destroy anything on destroy" do
|
72
|
+
@app.datastore.should_not_receive(:destroy)
|
73
|
+
@item.destroy
|
74
|
+
end
|
75
|
+
end
|
48
76
|
|
49
|
-
|
50
|
-
|
77
|
+
describe "when the uid is set manually" do
|
78
|
+
before(:each) do
|
79
|
+
@item.preview_image_uid = 'some_known_uid'
|
80
|
+
end
|
81
|
+
it "should not try to retrieve any data" do
|
82
|
+
@app.datastore.should_not_receive(:retrieve)
|
83
|
+
@item.save!
|
84
|
+
end
|
85
|
+
it "should not try to destroy any data" do
|
86
|
+
@app.datastore.should_not_receive(:destroy)
|
87
|
+
@item.save!
|
51
88
|
end
|
89
|
+
it "should not try to store any data" do
|
90
|
+
@app.datastore.should_not_receive(:store)
|
91
|
+
@item.save!
|
92
|
+
end
|
93
|
+
end
|
52
94
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
95
|
+
describe "when there has been some thing assigned but not saved" do
|
96
|
+
before(:each) do
|
97
|
+
@item.preview_image = "DATASTRING"
|
98
|
+
end
|
99
|
+
it "the reader should return an attachment" do
|
100
|
+
@item.preview_image.should be_a(Dragonfly::ActiveModelExtensions::Attachment)
|
101
|
+
end
|
102
|
+
it "the uid should be nil" do
|
103
|
+
@item.preview_image_uid.should be_nil
|
104
|
+
end
|
105
|
+
it "should store the image when saved" do
|
106
|
+
@app.datastore.should_receive(:store).with(a_temp_object_with_data("DATASTRING"), {})
|
107
|
+
@item.save!
|
108
|
+
end
|
109
|
+
it "should not try to destroy anything on destroy" do
|
110
|
+
@app.datastore.should_not_receive(:destroy)
|
111
|
+
@item.destroy
|
112
|
+
end
|
113
|
+
it "should return nil for the url" do
|
114
|
+
@item.preview_image.url.should be_nil
|
72
115
|
end
|
73
|
-
|
74
116
|
describe "when the uid is set manually" do
|
75
117
|
before(:each) do
|
76
118
|
@item.preview_image_uid = 'some_known_uid'
|
@@ -88,179 +130,186 @@ describe Item do
|
|
88
130
|
@item.save!
|
89
131
|
end
|
90
132
|
end
|
91
|
-
|
92
|
-
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "when something has been assigned and saved" do
|
137
|
+
|
138
|
+
before(:each) do
|
139
|
+
@item.preview_image = "DATASTRING"
|
140
|
+
@app.datastore.should_receive(:store).with(a_temp_object_with_data("DATASTRING"), {}).once.and_return('some_uid')
|
141
|
+
@item.save!
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should have the correct uid" do
|
145
|
+
@item.preview_image_uid.should == 'some_uid'
|
146
|
+
end
|
147
|
+
it "should not try to store anything if saved again" do
|
148
|
+
@app.datastore.should_not_receive(:store)
|
149
|
+
@item.save!
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should not try to destroy anything if saved again" do
|
153
|
+
@app.datastore.should_not_receive(:destroy)
|
154
|
+
@item.save!
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should destroy the data on destroy" do
|
158
|
+
@app.datastore.should_receive(:destroy).with('some_uid')
|
159
|
+
@item.destroy
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should return the url for the data" do
|
163
|
+
@app.should_receive(:url_for).with(an_instance_of(Dragonfly::Job)).and_return('some.url')
|
164
|
+
@item.preview_image.url.should == 'some.url'
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should destroy the old data when the uid is set manually" do
|
168
|
+
@app.datastore.should_receive(:destroy).with('some_uid')
|
169
|
+
@item.preview_image_uid = 'some_known_uid'
|
170
|
+
@item.save!
|
171
|
+
end
|
172
|
+
|
173
|
+
describe "when accessed by a new model object" do
|
174
|
+
before(:each) do
|
175
|
+
@item = Item.find(@item.id)
|
176
|
+
end
|
177
|
+
it "should destroy the data on destroy" do
|
178
|
+
@app.datastore.should_receive(:destroy).with(@item.preview_image_uid)
|
179
|
+
@item.destroy
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "when something new is assigned" do
|
93
184
|
before(:each) do
|
94
|
-
@item.preview_image = "
|
185
|
+
@item.preview_image = "ANEWDATASTRING"
|
186
|
+
@app.datastore.stub!(:store).and_return('some_uid')
|
95
187
|
end
|
96
|
-
it "
|
97
|
-
@item.
|
188
|
+
it "should set the uid to nil" do
|
189
|
+
@item.preview_image_uid.should be_nil
|
98
190
|
end
|
99
|
-
it "
|
100
|
-
@
|
191
|
+
it "should destroy the old data when saved" do
|
192
|
+
@app.datastore.should_receive(:destroy).with('some_uid')
|
193
|
+
@item.save!
|
101
194
|
end
|
102
|
-
it "should
|
103
|
-
@app.datastore.should_receive(:
|
195
|
+
it "should not try to destroy the old data if saved again" do
|
196
|
+
@app.datastore.should_receive(:destroy).with('some_uid')
|
197
|
+
@item.save!
|
198
|
+
@app.datastore.should_not_receive(:destroy).with('some_uid')
|
104
199
|
@item.save!
|
105
200
|
end
|
106
|
-
it "should
|
107
|
-
@
|
201
|
+
it "should destroy the old data when saved, even if yet another thing is assigned" do
|
202
|
+
@item.preview_image = "YET ANOTHER DATA STRING"
|
203
|
+
@app.datastore.should_receive(:destroy).with('some_uid')
|
204
|
+
@item.save!
|
205
|
+
end
|
206
|
+
it "should store the new data when saved" do
|
207
|
+
@app.datastore.should_receive(:store).with(a_temp_object_with_data("ANEWDATASTRING"), {})
|
208
|
+
@item.save!
|
209
|
+
end
|
210
|
+
it "should destroy the old data on destroy" do
|
211
|
+
@app.datastore.should_receive(:destroy).with('some_uid')
|
108
212
|
@item.destroy
|
109
213
|
end
|
110
|
-
it "should
|
111
|
-
@item.preview_image
|
214
|
+
it "should destroy the old data on destroy, even if yet another thing is assigned" do
|
215
|
+
@item.preview_image = "YET ANOTHER DATA STRING"
|
216
|
+
@app.datastore.should_receive(:destroy).with('some_uid')
|
217
|
+
@item.destroy
|
112
218
|
end
|
113
|
-
it "should
|
114
|
-
|
115
|
-
|
116
|
-
|
219
|
+
it "should destroy the old data when the uid has been set manually" do
|
220
|
+
@app.datastore.should_receive(:destroy).with('some_uid')
|
221
|
+
@item.preview_image_uid = 'some_known_uid'
|
222
|
+
@item.save!
|
117
223
|
end
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
@app.datastore.should_not_receive(:retrieve)
|
124
|
-
@item.save!
|
125
|
-
end
|
126
|
-
it "should not try to destroy any data" do
|
127
|
-
@app.datastore.should_not_receive(:destroy)
|
128
|
-
@item.save!
|
129
|
-
end
|
130
|
-
it "should not try to store any data" do
|
131
|
-
@app.datastore.should_not_receive(:store)
|
132
|
-
@item.save!
|
133
|
-
end
|
224
|
+
it "should return the new size" do
|
225
|
+
@item.preview_image.size.should == 14
|
226
|
+
end
|
227
|
+
it "should return the new data" do
|
228
|
+
@item.preview_image.data.should == 'ANEWDATASTRING'
|
134
229
|
end
|
135
|
-
|
136
230
|
end
|
137
|
-
|
138
|
-
describe "when something has been assigned and saved" do
|
139
231
|
|
232
|
+
describe "when it is set to nil" do
|
140
233
|
before(:each) do
|
141
|
-
@item.preview_image =
|
142
|
-
@app.datastore.should_receive(:store).with(a_temp_object_with_data("DATASTRING")).once.and_return('some_uid')
|
143
|
-
@app.datastore.stub!(:store).and_return('some_uid')
|
144
|
-
@app.datastore.stub!(:destroy)
|
145
|
-
@item.save!
|
234
|
+
@item.preview_image = nil
|
146
235
|
end
|
147
|
-
it "should
|
148
|
-
@item.preview_image_uid.should
|
236
|
+
it "should set the uid to nil" do
|
237
|
+
@item.preview_image_uid.should be_nil
|
149
238
|
end
|
150
|
-
it "should
|
151
|
-
@
|
152
|
-
@item.save!
|
239
|
+
it "should return the attribute as nil" do
|
240
|
+
@item.preview_image.should be_nil
|
153
241
|
end
|
154
|
-
|
155
|
-
|
156
|
-
@app.datastore.should_not_receive(:destroy)
|
242
|
+
it "should destroy the data on save" do
|
243
|
+
@app.datastore.should_receive(:destroy).with('some_uid')
|
157
244
|
@item.save!
|
245
|
+
@item.preview_image.should be_nil
|
158
246
|
end
|
159
|
-
|
160
|
-
it "should destroy the data on destroy" do
|
247
|
+
it "should destroy the old data on destroy" do
|
161
248
|
@app.datastore.should_receive(:destroy).with('some_uid')
|
162
249
|
@item.destroy
|
163
250
|
end
|
251
|
+
end
|
164
252
|
|
165
|
-
|
166
|
-
|
167
|
-
@
|
253
|
+
describe "when the data can't be found" do
|
254
|
+
it "should log a warning if the data wasn't found on destroy" do
|
255
|
+
@app.datastore.should_receive(:destroy).with('some_uid').and_raise(Dragonfly::DataStorage::DataNotFound)
|
256
|
+
@app.log.should_receive(:warn)
|
257
|
+
@item.destroy
|
168
258
|
end
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
259
|
+
end
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
describe "other types of assignment" do
|
264
|
+
before(:each) do
|
265
|
+
@app.generator.add :egg do
|
266
|
+
"Gungedin"
|
174
267
|
end
|
175
|
-
|
176
|
-
|
177
|
-
before(:each) do
|
178
|
-
@item = Item.find(@item.id)
|
179
|
-
end
|
180
|
-
it "should destroy the data on destroy" do
|
181
|
-
@app.datastore.should_receive(:destroy).with(@item.preview_image_uid)
|
182
|
-
@item.destroy
|
183
|
-
end
|
184
|
-
it "should return the temp_object" do
|
185
|
-
@app.should_receive(:fetch).with('some_uid').and_return(temp_object = mock('extended temp_object'))
|
186
|
-
@item.preview_image.temp_object.should == temp_object
|
187
|
-
end
|
268
|
+
@app.processor.add :doogie do |temp_object|
|
269
|
+
temp_object.data.upcase
|
188
270
|
end
|
271
|
+
end
|
189
272
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
it "should set the uid to pending" do
|
195
|
-
@item.preview_image_uid.should be_a(Dragonfly::ActiveRecordExtensions::PendingUID)
|
196
|
-
end
|
197
|
-
it "should destroy the old data when saved" do
|
198
|
-
@app.datastore.should_receive(:store).with(a_temp_object_with_data("ANEWDATASTRING")).once.and_return('some_uid')
|
199
|
-
|
200
|
-
@app.datastore.should_receive(:destroy).with('some_uid')
|
201
|
-
@item.save!
|
202
|
-
end
|
203
|
-
it "should store the new data when saved" do
|
204
|
-
@app.datastore.should_receive(:store).with(a_temp_object_with_data("ANEWDATASTRING"))
|
205
|
-
@item.save!
|
206
|
-
end
|
207
|
-
it "should destroy the old data on destroy" do
|
208
|
-
@app.datastore.should_receive(:destroy).with('some_uid')
|
209
|
-
@item.destroy
|
210
|
-
end
|
211
|
-
it "should return the new size" do
|
212
|
-
@item.preview_image.size.should == 14
|
213
|
-
end
|
214
|
-
it "should return the new temp_object" do
|
215
|
-
temp_object = @item.preview_image.temp_object
|
216
|
-
temp_object.should be_a(Dragonfly::ExtendedTempObject)
|
217
|
-
temp_object.data.should == 'ANEWDATASTRING'
|
218
|
-
end
|
273
|
+
describe "assigning with a job" do
|
274
|
+
before(:each) do
|
275
|
+
@job = @app.generate(:egg)
|
276
|
+
@item.preview_image = @job
|
219
277
|
end
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
@item.preview_image = nil
|
224
|
-
end
|
225
|
-
it "should set the uid to nil" do
|
226
|
-
@item.preview_image_uid.should be_nil
|
227
|
-
end
|
228
|
-
it "should return the attribute as nil" do
|
229
|
-
@item.preview_image.should be_nil
|
230
|
-
end
|
231
|
-
it "should destroy the data on save" do
|
232
|
-
@app.datastore.should_receive(:destroy).with('some_uid')
|
233
|
-
@item.save!
|
234
|
-
@item.preview_image.should be_nil
|
235
|
-
end
|
236
|
-
it "should destroy the old data on destroy" do
|
237
|
-
@app.datastore.should_receive(:destroy).with('some_uid')
|
238
|
-
@item.destroy
|
239
|
-
end
|
278
|
+
|
279
|
+
it "should work" do
|
280
|
+
@item.preview_image.data.should == 'Gungedin'
|
240
281
|
end
|
241
282
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
@app.datastore.stub!(:retrieve).with('some_uid').and_raise(Dragonfly::DataStorage::DataNotFound)
|
246
|
-
end
|
247
|
-
it "should log a warning if the data wasn't found on destroy" do
|
248
|
-
@app.log.should_receive(:warn)
|
249
|
-
@item.destroy
|
250
|
-
end
|
283
|
+
it "should not be affected by subsequent changes to the job" do
|
284
|
+
@job.process!(:doogie)
|
285
|
+
@item.preview_image.data.should == 'Gungedin'
|
251
286
|
end
|
287
|
+
end
|
252
288
|
|
289
|
+
describe "assigning with another attachment" do
|
290
|
+
before(:each) do
|
291
|
+
Item.class_eval do
|
292
|
+
image_accessor :other_image
|
293
|
+
end
|
294
|
+
end
|
295
|
+
it "should work like assigning the job" do
|
296
|
+
@item.preview_image = 'eggheads'
|
297
|
+
@item.other_image = @item.preview_image
|
298
|
+
@item.preview_image = 'dogchin'
|
299
|
+
@item.other_image.data.should == 'eggheads'
|
300
|
+
end
|
253
301
|
end
|
254
302
|
end
|
303
|
+
|
255
304
|
end
|
256
305
|
|
257
306
|
describe "validations" do
|
258
307
|
|
259
308
|
before(:all) do
|
260
|
-
@app = Dragonfly
|
261
|
-
|
309
|
+
@app = Dragonfly[:images]
|
310
|
+
@app.define_macro(model_class, :image_accessor)
|
262
311
|
end
|
263
|
-
|
312
|
+
|
264
313
|
describe "validates_presence_of" do
|
265
314
|
|
266
315
|
before(:all) do
|
@@ -279,9 +328,9 @@ describe Item do
|
|
279
328
|
end
|
280
329
|
|
281
330
|
end
|
282
|
-
|
331
|
+
|
283
332
|
describe "validates_size_of" do
|
284
|
-
|
333
|
+
|
285
334
|
before(:all) do
|
286
335
|
Item.class_eval do
|
287
336
|
image_accessor :preview_image
|
@@ -296,9 +345,9 @@ describe Item do
|
|
296
345
|
it "should be invalid if too small" do
|
297
346
|
Item.new(:preview_image => "12345").should_not be_valid
|
298
347
|
end
|
299
|
-
|
348
|
+
|
300
349
|
end
|
301
|
-
|
350
|
+
|
302
351
|
describe "validates_property" do
|
303
352
|
|
304
353
|
before(:each) do
|
@@ -306,8 +355,7 @@ describe Item do
|
|
306
355
|
end
|
307
356
|
|
308
357
|
before(:all) do
|
309
|
-
custom_analyser = Class.new
|
310
|
-
custom_analyser.class_eval do
|
358
|
+
custom_analyser = Class.new do
|
311
359
|
def mime_type(temp_object)
|
312
360
|
case temp_object.data
|
313
361
|
when "WRONG TYPE" then 'wrong/type'
|
@@ -320,8 +368,8 @@ describe Item do
|
|
320
368
|
temp_object.data.count('G')
|
321
369
|
end
|
322
370
|
end
|
323
|
-
@app.
|
324
|
-
|
371
|
+
@app.analyser.register(custom_analyser)
|
372
|
+
|
325
373
|
Item.class_eval do
|
326
374
|
validates_property :mime_type, :of => :preview_image, :in => ['how/special', 'how/crazy'], :if => :its_friday
|
327
375
|
validates_property :mime_type, :of => [:other_image, :yet_another_image], :as => 'how/special'
|
@@ -339,12 +387,12 @@ describe Item do
|
|
339
387
|
|
340
388
|
end
|
341
389
|
end
|
342
|
-
|
390
|
+
|
343
391
|
it "should be valid if nil, if not validated on presence (even with validates_property)" do
|
344
392
|
@item.other_image = nil
|
345
393
|
@item.should be_valid
|
346
394
|
end
|
347
|
-
|
395
|
+
|
348
396
|
it "should be invalid if the property is nil" do
|
349
397
|
@item.preview_image = "OTHER TYPE"
|
350
398
|
@item.should_not be_valid
|
@@ -356,7 +404,7 @@ describe Item do
|
|
356
404
|
@item.should_not be_valid
|
357
405
|
@item.errors[:preview_image].should match_ar_error("mime type is incorrect. It needs to be one of 'how/special', 'how/crazy', but was 'wrong/type'")
|
358
406
|
end
|
359
|
-
|
407
|
+
|
360
408
|
it "should work for a range" do
|
361
409
|
@item.preview_image = "GOOGLE GUM"
|
362
410
|
@item.should_not be_valid
|
@@ -376,7 +424,7 @@ describe Item do
|
|
376
424
|
@item.preview_image = "WRONG TYPE"
|
377
425
|
@item.should be_valid
|
378
426
|
end
|
379
|
-
|
427
|
+
|
380
428
|
it "should require either :as or :in as an argument" do
|
381
429
|
lambda{
|
382
430
|
Item.class_eval do
|
@@ -401,77 +449,67 @@ describe Item do
|
|
401
449
|
|
402
450
|
end
|
403
451
|
|
404
|
-
describe "validates_mime_type_of" do
|
405
|
-
it "should provide validates_mime_type as a convenience wrapper for validates_property" do
|
406
|
-
Item.should_receive(:validates_property).with(:mime_type, :of => :preview_image, :in => ['how/special', 'how/crazy'], :if => :its_friday)
|
407
|
-
Item.class_eval do
|
408
|
-
validates_mime_type_of :preview_image, :in => ['how/special', 'how/crazy'], :if => :its_friday
|
409
|
-
end
|
410
|
-
end
|
411
|
-
end
|
412
|
-
|
413
452
|
end
|
414
453
|
|
415
454
|
describe "extra properties" do
|
416
455
|
|
417
456
|
before(:each) do
|
418
|
-
@app = Dragonfly
|
419
|
-
custom_analyser = Class.new
|
420
|
-
custom_analyser.class_eval do
|
457
|
+
@app = Dragonfly[:images]
|
458
|
+
custom_analyser = Class.new do
|
421
459
|
def some_analyser_method(temp_object)
|
422
460
|
"abc" + temp_object.data[0..0]
|
423
461
|
end
|
424
462
|
def number_of_As(temp_object); temp_object.data.count('A'); end
|
425
463
|
end
|
426
|
-
@app.
|
427
|
-
|
464
|
+
@app.analyser.register(custom_analyser)
|
465
|
+
@app.define_macro(model_class, :image_accessor)
|
428
466
|
Item.class_eval do
|
429
467
|
image_accessor :preview_image
|
430
468
|
end
|
431
469
|
@item = Item.new
|
432
470
|
end
|
433
|
-
|
471
|
+
|
434
472
|
describe "magic attributes" do
|
435
|
-
|
473
|
+
|
436
474
|
it "should default the magic attribute as nil" do
|
437
475
|
@item.preview_image_some_analyser_method.should be_nil
|
438
476
|
end
|
439
|
-
|
477
|
+
|
440
478
|
it "should set the magic attribute when assigned" do
|
441
479
|
@item.preview_image = '123'
|
442
480
|
@item.preview_image_some_analyser_method.should == 'abc1'
|
443
481
|
end
|
444
|
-
|
482
|
+
|
445
483
|
it "should not set non-magic attributes with the same prefix when assigned" do
|
446
484
|
@item.preview_image_blah_blah = 'wassup'
|
447
485
|
@item.preview_image = '123'
|
448
486
|
@item.preview_image_blah_blah.should == 'wassup'
|
449
487
|
end
|
450
|
-
|
488
|
+
|
451
489
|
it "should update the magic attribute when something else is assigned" do
|
452
490
|
@item.preview_image = '123'
|
453
491
|
@item.preview_image = '456'
|
454
492
|
@item.preview_image_some_analyser_method.should == 'abc4'
|
455
493
|
end
|
456
|
-
|
494
|
+
|
457
495
|
it "should reset the magic attribute when set to nil" do
|
458
496
|
@item.preview_image = '123'
|
459
497
|
@item.preview_image = nil
|
460
498
|
@item.preview_image_some_analyser_method.should be_nil
|
461
499
|
end
|
462
|
-
|
500
|
+
|
463
501
|
it "should not reset non-magic attributes with the same prefix when set to nil" do
|
464
502
|
@item.preview_image_blah_blah = 'wassup'
|
465
503
|
@item.preview_image = '123'
|
466
504
|
@item.preview_image = nil
|
467
505
|
@item.preview_image_blah_blah.should == 'wassup'
|
468
506
|
end
|
469
|
-
|
507
|
+
|
470
508
|
it "should work for size too" do
|
471
509
|
@item.preview_image = '123'
|
472
510
|
@item.preview_image_size.should == 3
|
473
511
|
end
|
474
|
-
|
512
|
+
|
475
513
|
it "should store the original file extension if it exists" do
|
476
514
|
data = 'jasdlkf sadjl'
|
477
515
|
data.stub!(:original_filename).and_return('hello.png')
|
@@ -486,9 +524,9 @@ describe Item do
|
|
486
524
|
@item.preview_image_name.should == 'hello.png'
|
487
525
|
end
|
488
526
|
end
|
489
|
-
|
490
|
-
|
491
|
-
describe "delegating methods to the
|
527
|
+
|
528
|
+
|
529
|
+
describe "delegating methods to the job" do
|
492
530
|
before(:each) do
|
493
531
|
@item.preview_image = "DATASTRING"
|
494
532
|
end
|
@@ -504,7 +542,7 @@ describe Item do
|
|
504
542
|
it "should include analyser methods in public_methods" do
|
505
543
|
@item.preview_image.public_methods.include?('number_of_As'.to_method_name).should be_true
|
506
544
|
end
|
507
|
-
|
545
|
+
|
508
546
|
it "should update when something new is assigned" do
|
509
547
|
@item.preview_image = 'ANEWDATASTRING'
|
510
548
|
@item.preview_image.number_of_As.should == 3
|
@@ -515,35 +553,33 @@ describe Item do
|
|
515
553
|
@app.datastore.stub!(:store).and_return('my_uid')
|
516
554
|
item = Item.create!(:preview_image => 'DATASTRING')
|
517
555
|
@item = Item.find(item.id)
|
518
|
-
@temp_object = @app.create_object('DATASTRING')
|
519
|
-
@temp_object.name = 'jonny.briggs'
|
520
556
|
end
|
521
|
-
it "should load the
|
522
|
-
@app.should_receive(:
|
557
|
+
it "should load the content then delegate the method" do
|
558
|
+
@app.datastore.should_receive(:retrieve).with('my_uid').and_return(['DATASTRING', {}])
|
523
559
|
@item.preview_image.number_of_As.should == 2
|
524
560
|
end
|
525
|
-
it "should use the magic attribute if there is one, and not load the
|
526
|
-
@app.should_not_receive(:
|
561
|
+
it "should use the magic attribute if there is one, and not load the content" do
|
562
|
+
@app.datastore.should_not_receive(:retrieve)
|
527
563
|
@item.should_receive(:preview_image_some_analyser_method).and_return('result yo')
|
528
564
|
@item.preview_image.some_analyser_method.should == 'result yo'
|
529
565
|
end
|
530
|
-
|
566
|
+
|
531
567
|
%w(size name ext).each do |attr|
|
532
|
-
it "should use the magic attribute for #{attr} if there is one, and not load the
|
533
|
-
@app.should_not_receive(:
|
568
|
+
it "should use the magic attribute for #{attr} if there is one, and not load the content" do
|
569
|
+
@app.datastore.should_not_receive(:retrieve)
|
534
570
|
@item.should_receive("preview_image_#{attr}".to_sym).and_return('result yo')
|
535
571
|
@item.preview_image.send(attr).should == 'result yo'
|
536
572
|
end
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
@app.should_receive(:
|
541
|
-
@item.preview_image.send(attr).should == @
|
573
|
+
|
574
|
+
it "should load the content then delegate '#{attr}' if there is no magic attribute for it" do
|
575
|
+
@item.should_receive(:public_methods).and_return(['preview_image_uid']) # no magic attributes
|
576
|
+
@app.datastore.should_receive(:retrieve).with('my_uid').and_return(['DATASTRING', {}])
|
577
|
+
@item.preview_image.send(attr).should == @item.preview_image.send(:job).send(attr)
|
542
578
|
end
|
543
579
|
end
|
544
|
-
|
580
|
+
|
545
581
|
end
|
546
|
-
|
582
|
+
|
547
583
|
it "should not raise an error if a non-existent method is called" do
|
548
584
|
# Just checking method missing works ok
|
549
585
|
lambda{
|
@@ -552,14 +588,14 @@ describe Item do
|
|
552
588
|
end
|
553
589
|
end
|
554
590
|
end
|
555
|
-
|
591
|
+
|
556
592
|
describe "inheritance" do
|
557
|
-
|
593
|
+
|
558
594
|
before(:all) do
|
559
|
-
@app = Dragonfly
|
560
|
-
@app2 = Dragonfly
|
561
|
-
|
562
|
-
|
595
|
+
@app = Dragonfly[:images]
|
596
|
+
@app2 = Dragonfly[:egg]
|
597
|
+
@app.define_macro(model_class, :image_accessor)
|
598
|
+
@app2.define_macro(model_class, :egg_accessor)
|
563
599
|
Car.class_eval do
|
564
600
|
image_accessor :image
|
565
601
|
end
|
@@ -568,11 +604,13 @@ describe Item do
|
|
568
604
|
end
|
569
605
|
|
570
606
|
@base_class = Car
|
571
|
-
|
572
|
-
@
|
607
|
+
class ReliantRobin < Car; image_accessor :reliant_image; end
|
608
|
+
@subclass = ReliantRobin
|
609
|
+
class ReliantRobinWithModule < Car
|
573
610
|
include Module.new
|
574
611
|
image_accessor :reliant_image
|
575
612
|
end
|
613
|
+
@subclass_with_module = ReliantRobinWithModule
|
576
614
|
@unrelated_class = Photo
|
577
615
|
end
|
578
616
|
|