dragonfly 0.9.15 → 1.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.

Files changed (203) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -8
  3. data/.travis.yml +11 -0
  4. data/Gemfile +1 -0
  5. data/History.md +52 -2
  6. data/LICENSE +1 -1
  7. data/README.md +38 -95
  8. data/dev/grid.jpg +0 -0
  9. data/dev/irbrc.rb +27 -0
  10. data/dev/rails_template.rb +38 -0
  11. data/dev/test.ru +56 -0
  12. data/dev/test_rails +19 -0
  13. data/dragonfly.gemspec +3 -21
  14. data/lib/dragonfly.rb +45 -44
  15. data/lib/dragonfly/app.rb +175 -96
  16. data/lib/dragonfly/configurable.rb +71 -170
  17. data/lib/dragonfly/content.rb +211 -0
  18. data/lib/dragonfly/core_ext/object.rb +1 -6
  19. data/lib/dragonfly/file_data_store.rb +197 -0
  20. data/lib/dragonfly/image_magick/analysers/image_properties.rb +23 -0
  21. data/lib/dragonfly/image_magick/generators/convert.rb +19 -0
  22. data/lib/dragonfly/image_magick/generators/plain.rb +26 -0
  23. data/lib/dragonfly/image_magick/generators/plasma.rb +25 -0
  24. data/lib/dragonfly/image_magick/generators/text.rb +127 -0
  25. data/lib/dragonfly/image_magick/plugin.rb +83 -0
  26. data/lib/dragonfly/image_magick/processors/convert.rb +29 -0
  27. data/lib/dragonfly/image_magick/processors/encode.rb +18 -0
  28. data/lib/dragonfly/image_magick/processors/thumb.rb +76 -0
  29. data/lib/dragonfly/job.rb +118 -134
  30. data/lib/dragonfly/job_endpoint.rb +2 -0
  31. data/lib/dragonfly/memory_data_store.rb +34 -0
  32. data/lib/dragonfly/middleware.rb +5 -3
  33. data/lib/dragonfly/{active_model_extensions.rb → model.rb} +5 -3
  34. data/lib/dragonfly/{active_model_extensions → model}/attachment.rb +40 -35
  35. data/lib/dragonfly/{active_model_extensions → model}/attachment_class_methods.rb +36 -40
  36. data/lib/dragonfly/model/class_methods.rb +109 -0
  37. data/lib/dragonfly/{active_model_extensions → model}/instance_methods.rb +2 -2
  38. data/lib/dragonfly/{active_model_extensions → model}/validations.rb +17 -12
  39. data/lib/dragonfly/railtie.rb +8 -6
  40. data/lib/dragonfly/register.rb +27 -0
  41. data/lib/dragonfly/response.rb +47 -52
  42. data/lib/dragonfly/routed_endpoint.rb +4 -0
  43. data/lib/dragonfly/serializer.rb +15 -5
  44. data/lib/dragonfly/server.rb +56 -29
  45. data/lib/dragonfly/shell.rb +12 -23
  46. data/lib/dragonfly/spec/data_store_examples.rb +64 -0
  47. data/lib/dragonfly/temp_object.rb +32 -47
  48. data/lib/dragonfly/url_attributes.rb +19 -22
  49. data/lib/dragonfly/url_mapper.rb +3 -0
  50. data/lib/dragonfly/utils.rb +12 -0
  51. data/lib/dragonfly/version.rb +1 -1
  52. data/lib/dragonfly/whitelist.rb +19 -0
  53. data/lib/rails/generators/dragonfly/USAGE +8 -0
  54. data/lib/rails/generators/dragonfly/dragonfly_generator.rb +24 -0
  55. data/lib/rails/generators/dragonfly/templates/initializer.rb.erb +27 -0
  56. data/samples/gif.gif +0 -0
  57. data/spec/dragonfly/app_spec.rb +270 -64
  58. data/spec/dragonfly/configurable_spec.rb +142 -418
  59. data/spec/dragonfly/content_spec.rb +353 -0
  60. data/spec/dragonfly/cookie_monster_spec.rb +2 -1
  61. data/spec/dragonfly/file_data_store_spec.rb +301 -0
  62. data/spec/dragonfly/image_magick/analysers/image_properties_spec.rb +20 -0
  63. data/spec/dragonfly/image_magick/generators/convert_spec.rb +19 -0
  64. data/spec/dragonfly/image_magick/generators/plain_spec.rb +50 -0
  65. data/spec/dragonfly/image_magick/generators/plasma_spec.rb +32 -0
  66. data/spec/dragonfly/image_magick/generators/text_spec.rb +77 -0
  67. data/spec/dragonfly/image_magick/plugin_spec.rb +131 -0
  68. data/spec/dragonfly/image_magick/processors/convert_spec.rb +56 -0
  69. data/spec/dragonfly/image_magick/processors/thumb_spec.rb +173 -0
  70. data/spec/dragonfly/job_endpoint_spec.rb +30 -73
  71. data/spec/dragonfly/job_spec.rb +280 -608
  72. data/spec/dragonfly/memory_data_store_spec.rb +20 -0
  73. data/spec/dragonfly/middleware_spec.rb +47 -27
  74. data/spec/dragonfly/{active_model_extensions → model}/model_spec.rb +331 -555
  75. data/spec/dragonfly/model/validations_spec.rb +196 -0
  76. data/spec/dragonfly/register_spec.rb +35 -0
  77. data/spec/dragonfly/routed_endpoint_spec.rb +6 -6
  78. data/spec/dragonfly/serializer_spec.rb +13 -15
  79. data/spec/dragonfly/server_spec.rb +122 -46
  80. data/spec/dragonfly/shell_spec.rb +43 -24
  81. data/spec/dragonfly/temp_object_spec.rb +69 -94
  82. data/spec/dragonfly/url_attributes_spec.rb +49 -0
  83. data/spec/dragonfly/utils_spec.rb +32 -0
  84. data/spec/dragonfly/whitelist_spec.rb +30 -0
  85. data/spec/dragonfly_spec.rb +43 -0
  86. data/spec/fixtures/deprecated_stored_content/eggs.bonus +1 -0
  87. data/spec/fixtures/deprecated_stored_content/eggs.bonus.meta +1 -0
  88. data/spec/functional/configuration_spec.rb +19 -0
  89. data/spec/functional/model_urls_spec.rb +43 -41
  90. data/spec/functional/remote_on_the_fly_spec.rb +14 -16
  91. data/spec/functional/shell_commands_spec.rb +24 -14
  92. data/spec/functional/to_response_spec.rb +10 -10
  93. data/spec/functional/urls_spec.rb +5 -3
  94. data/spec/spec_helper.rb +23 -28
  95. data/spec/support/argument_matchers.rb +7 -8
  96. data/spec/support/image_matchers.rb +14 -36
  97. data/spec/support/model_helpers.rb +97 -0
  98. data/spec/support/simple_matchers.rb +12 -0
  99. metadata +92 -393
  100. data/.yardopts +0 -29
  101. data/Rakefile +0 -36
  102. data/config.ru +0 -14
  103. data/docs.watchr +0 -1
  104. data/extra_docs/Analysers.md +0 -68
  105. data/extra_docs/Caching.md +0 -23
  106. data/extra_docs/Configuration.md +0 -149
  107. data/extra_docs/Couch.md +0 -49
  108. data/extra_docs/DataStorage.md +0 -226
  109. data/extra_docs/Encoding.md +0 -67
  110. data/extra_docs/ExampleUseCases.md +0 -116
  111. data/extra_docs/GeneralUsage.md +0 -105
  112. data/extra_docs/Generators.md +0 -68
  113. data/extra_docs/Heroku.md +0 -50
  114. data/extra_docs/ImageMagick.md +0 -136
  115. data/extra_docs/Index.md +0 -33
  116. data/extra_docs/MimeTypes.md +0 -40
  117. data/extra_docs/Models.md +0 -441
  118. data/extra_docs/Mongo.md +0 -42
  119. data/extra_docs/Processing.md +0 -77
  120. data/extra_docs/Rack.md +0 -52
  121. data/extra_docs/Rails2.md +0 -57
  122. data/extra_docs/Rails3.md +0 -56
  123. data/extra_docs/ServingRemotely.md +0 -104
  124. data/extra_docs/Sinatra.md +0 -25
  125. data/extra_docs/URLs.md +0 -203
  126. data/features/images.feature +0 -47
  127. data/features/no_processing.feature +0 -14
  128. data/features/rails.feature +0 -8
  129. data/features/steps/common_steps.rb +0 -8
  130. data/features/steps/dragonfly_steps.rb +0 -66
  131. data/features/steps/rails_steps.rb +0 -40
  132. data/features/support/env.rb +0 -13
  133. data/features/support/setup.rb +0 -41
  134. data/fixtures/rails/files/app/models/album.rb +0 -6
  135. data/fixtures/rails/files/app/views/albums/new.html.erb +0 -7
  136. data/fixtures/rails/files/app/views/albums/show.html.erb +0 -6
  137. data/fixtures/rails/files/config/initializers/dragonfly.rb +0 -4
  138. data/fixtures/rails/files/features/manage_album_images.feature +0 -38
  139. data/fixtures/rails/files/features/step_definitions/helper_steps.rb +0 -7
  140. data/fixtures/rails/files/features/step_definitions/image_steps.rb +0 -25
  141. data/fixtures/rails/files/features/step_definitions/web_steps.rb +0 -189
  142. data/fixtures/rails/files/features/support/paths.rb +0 -17
  143. data/fixtures/rails/files/features/text_images.feature +0 -7
  144. data/fixtures/rails/template.rb +0 -20
  145. data/irbrc.rb +0 -19
  146. data/lib/dragonfly/active_model_extensions/class_methods.rb +0 -98
  147. data/lib/dragonfly/analyser.rb +0 -58
  148. data/lib/dragonfly/analysis/file_command_analyser.rb +0 -33
  149. data/lib/dragonfly/analysis/image_magick_analyser.rb +0 -6
  150. data/lib/dragonfly/config/heroku.rb +0 -26
  151. data/lib/dragonfly/config/image_magick.rb +0 -6
  152. data/lib/dragonfly/config/rails.rb +0 -20
  153. data/lib/dragonfly/data_storage.rb +0 -11
  154. data/lib/dragonfly/data_storage/couch_data_store.rb +0 -83
  155. data/lib/dragonfly/data_storage/file_data_store.rb +0 -144
  156. data/lib/dragonfly/data_storage/mongo_data_store.rb +0 -96
  157. data/lib/dragonfly/data_storage/s3data_store.rb +0 -168
  158. data/lib/dragonfly/encoder.rb +0 -13
  159. data/lib/dragonfly/encoding/image_magick_encoder.rb +0 -6
  160. data/lib/dragonfly/function_manager.rb +0 -67
  161. data/lib/dragonfly/generation/image_magick_generator.rb +0 -6
  162. data/lib/dragonfly/generator.rb +0 -9
  163. data/lib/dragonfly/image_magick/analyser.rb +0 -53
  164. data/lib/dragonfly/image_magick/config.rb +0 -44
  165. data/lib/dragonfly/image_magick/encoder.rb +0 -57
  166. data/lib/dragonfly/image_magick/generator.rb +0 -147
  167. data/lib/dragonfly/image_magick/processor.rb +0 -114
  168. data/lib/dragonfly/image_magick/utils.rb +0 -46
  169. data/lib/dragonfly/image_magick_utils.rb +0 -4
  170. data/lib/dragonfly/job_builder.rb +0 -39
  171. data/lib/dragonfly/job_definitions.rb +0 -30
  172. data/lib/dragonfly/loggable.rb +0 -28
  173. data/lib/dragonfly/processing/image_magick_processor.rb +0 -6
  174. data/lib/dragonfly/processor.rb +0 -9
  175. data/lib/dragonfly/rails/images.rb +0 -32
  176. data/lib/dragonfly/simple_cache.rb +0 -23
  177. data/spec/dragonfly/active_model_extensions/spec_helper.rb +0 -95
  178. data/spec/dragonfly/analyser_spec.rb +0 -123
  179. data/spec/dragonfly/analysis/file_command_analyser_spec.rb +0 -49
  180. data/spec/dragonfly/data_storage/couch_data_store_spec.rb +0 -84
  181. data/spec/dragonfly/data_storage/file_data_store_spec.rb +0 -308
  182. data/spec/dragonfly/data_storage/mongo_data_store_spec.rb +0 -81
  183. data/spec/dragonfly/data_storage/s3_data_store_spec.rb +0 -277
  184. data/spec/dragonfly/data_storage/shared_data_store_examples.rb +0 -77
  185. data/spec/dragonfly/function_manager_spec.rb +0 -154
  186. data/spec/dragonfly/image_magick/analyser_spec.rb +0 -73
  187. data/spec/dragonfly/image_magick/encoder_spec.rb +0 -46
  188. data/spec/dragonfly/image_magick/generator_spec.rb +0 -178
  189. data/spec/dragonfly/image_magick/processor_spec.rb +0 -293
  190. data/spec/dragonfly/job_builder_spec.rb +0 -37
  191. data/spec/dragonfly/job_definitions_spec.rb +0 -57
  192. data/spec/dragonfly/loggable_spec.rb +0 -80
  193. data/spec/dragonfly/simple_cache_spec.rb +0 -27
  194. data/spec/dragonfly/url_attributes.rb +0 -47
  195. data/spec/functional/deprecations_spec.rb +0 -51
  196. data/spec/functional/image_magick_app_spec.rb +0 -27
  197. data/spec/test_imagemagick.ru +0 -49
  198. data/yard/handlers/configurable_attr_handler.rb +0 -38
  199. data/yard/setup.rb +0 -15
  200. data/yard/templates/default/fulldoc/html/css/common.css +0 -109
  201. data/yard/templates/default/layout/html/layout.erb +0 -93
  202. data/yard/templates/default/module/html/configuration_summary.erb +0 -31
  203. data/yard/templates/default/module/setup.rb +0 -17
@@ -1,81 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
- require File.dirname(__FILE__) + '/shared_data_store_examples'
4
- require 'mongo'
5
-
6
- describe Dragonfly::DataStorage::MongoDataStore do
7
-
8
- before(:each) do
9
- begin
10
- Mongo::Connection.new
11
- rescue Mongo::ConnectionFailure => e
12
- pending "You need to start mongo on localhost:27017 to test the MongoDataStore"
13
- end
14
- @data_store = Dragonfly::DataStorage::MongoDataStore.new :database => 'dragonfly_test'
15
- end
16
-
17
- it_should_behave_like 'data_store'
18
-
19
- describe "connecting to a replica set" do
20
- it "should initiate a replica set connection if hosts is set" do
21
- @data_store.hosts = ['1.2.3.4:27017', '1.2.3.4:27017']
22
- @data_store.connection_opts = {:name => 'testingset'}
23
- Mongo::ReplSetConnection.should_receive(:new).with(['1.2.3.4:27017', '1.2.3.4:27017'], :name => 'testingset')
24
- @data_store.connection
25
- end
26
- end
27
-
28
- describe "authenticating" do
29
- before(:each) do
30
- @temp_object = Dragonfly::TempObject.new('Feijão verde')
31
- end
32
-
33
- it "should not attempt to authenticate if a username is not given" do
34
- @data_store.db.should_not_receive(:authenticate)
35
- @data_store.store(@temp_object)
36
- end
37
-
38
- it "should attempt to authenticate once if a username is given" do
39
- @data_store.username = 'terry'
40
- @data_store.password = 'butcher'
41
- @data_store.db.should_receive(:authenticate).exactly(:once).with('terry','butcher').and_return(true)
42
- uid = @data_store.store(@temp_object)
43
- @data_store.retrieve(uid)
44
- end
45
- end
46
-
47
- describe "sharing already configured stuff" do
48
- before(:each) do
49
- @connection = Mongo::Connection.new
50
- @temp_object = Dragonfly::TempObject.new('asdf')
51
- end
52
-
53
- it "should allow sharing the connection" do
54
- @data_store.connection = @connection
55
- @connection.should_receive(:db).with('dragonfly_test').and_return(db=mock)
56
- @data_store.db.should == db
57
- end
58
-
59
- it "should allow sharing the db" do
60
- db = @connection.db('dragonfly_test_yo')
61
- @data_store.db = db
62
- @data_store.grid.instance_eval{@db}.should == db # so wrong
63
- end
64
- end
65
-
66
- describe "extra options" do
67
-
68
- before(:each) do
69
- @temp_object = Dragonfly::TempObject.new('testingyo')
70
- end
71
-
72
- [:content_type, :mime_type].each do |key|
73
- it "should allow setting content type on store with #{key.inspect}" do
74
- uid = @data_store.store(@temp_object, key => 'text/plain')
75
- @data_store.grid.get(BSON::ObjectId(uid)).content_type.should == 'text/plain'
76
- @data_store.grid.get(BSON::ObjectId(uid)).read.should == 'testingyo'
77
- end
78
- end
79
- end
80
-
81
- end
@@ -1,277 +0,0 @@
1
- require 'spec_helper'
2
- require File.dirname(__FILE__) + '/shared_data_store_examples'
3
- require 'yaml'
4
-
5
- describe Dragonfly::DataStorage::S3DataStore do
6
-
7
- # To run these tests, put a file ".s3_spec.yml" in the dragonfly root dir, like this:
8
- # key: XXXXXXXXXX
9
- # secret: XXXXXXXXXX
10
- # enabled: true
11
- if File.exist?(file = File.expand_path('../../../../.s3_spec.yml', __FILE__))
12
- config = YAML.load_file(file)
13
- KEY = config['key']
14
- SECRET = config['secret']
15
- enabled = config['enabled']
16
- else
17
- enabled = false
18
- end
19
-
20
- if enabled
21
-
22
- # Make sure it's a new bucket name
23
- BUCKET_NAME = "dragonfly-test-#{Time.now.to_i.to_s(36)}"
24
-
25
- before(:each) do
26
- WebMock.allow_net_connect!
27
- @data_store = Dragonfly::DataStorage::S3DataStore.new
28
- @data_store.configure do |d|
29
- d.bucket_name = BUCKET_NAME
30
- d.access_key_id = KEY
31
- d.secret_access_key = SECRET
32
- d.region = 'eu-west-1'
33
- end
34
- end
35
-
36
- else
37
-
38
- BUCKET_NAME = 'test-bucket'
39
-
40
- before(:each) do
41
- Fog.mock!
42
- @data_store = Dragonfly::DataStorage::S3DataStore.new
43
- @data_store.configure do |d|
44
- d.bucket_name = BUCKET_NAME
45
- d.access_key_id = 'XXXXXXXXX'
46
- d.secret_access_key = 'XXXXXXXXX'
47
- d.region = 'eu-west-1'
48
- end
49
- end
50
-
51
- end
52
-
53
- it_should_behave_like 'data_store'
54
-
55
- describe "store" do
56
- it "should return a unique identifier for each storage" do
57
- temp_object = Dragonfly::TempObject.new('gollum')
58
- temp_object2 = Dragonfly::TempObject.new('gollum')
59
- @data_store.store(temp_object).should_not == @data_store.store(temp_object2)
60
- end
61
-
62
- it "should use the name from the temp_object if set" do
63
- temp_object = Dragonfly::TempObject.new('eggheads', :name => 'doobie')
64
- uid = @data_store.store(temp_object)
65
- uid.should =~ /doobie$/
66
- data, meta = @data_store.retrieve(uid)
67
- data.should == 'eggheads'
68
- end
69
-
70
- it "should work ok with files with funny names" do
71
- temp_object = Dragonfly::TempObject.new('eggheads', :name => 'A Picture with many spaces in its name (at 20:00 pm).png')
72
- uid = @data_store.store(temp_object)
73
- uid.should =~ /A_Picture_with_many_spaces_in_its_name_at_20_00_pm_\.png$/
74
- data, meta = @data_store.retrieve(uid)
75
- data.should == 'eggheads'
76
- end
77
-
78
- it "should allow for setting the path manually" do
79
- temp_object = Dragonfly::TempObject.new('eggheads')
80
- uid = @data_store.store(temp_object, :path => 'hello/there')
81
- uid.should == 'hello/there'
82
- data, meta = @data_store.retrieve(uid)
83
- data.should == 'eggheads'
84
- end
85
-
86
- it "should work fine when not using the filesystem" do
87
- @data_store.use_filesystem = false
88
- temp_object = Dragonfly::TempObject.new('gollum')
89
- uid = @data_store.store(temp_object)
90
- @data_store.retrieve(uid).first.should == "gollum"
91
- end
92
-
93
- if enabled # Fog.mock! doesn't act consistently here
94
- it "should reset the connection and try again if Fog throws a socket EOFError" do
95
- temp_object = Dragonfly::TempObject.new('gollum')
96
- @data_store.storage.should_receive(:put_object).exactly(:once).and_raise(Excon::Errors::SocketError.new(EOFError.new))
97
- @data_store.storage.should_receive(:put_object).with(BUCKET_NAME, anything, anything, hash_including)
98
- @data_store.store(temp_object)
99
- end
100
-
101
- it "should just let it raise if Fog throws a socket EOFError again" do
102
- temp_object = Dragonfly::TempObject.new('gollum')
103
- @data_store.storage.should_receive(:put_object).and_raise(Excon::Errors::SocketError.new(EOFError.new))
104
- @data_store.storage.should_receive(:put_object).and_raise(Excon::Errors::SocketError.new(EOFError.new))
105
- expect{
106
- @data_store.store(temp_object)
107
- }.to raise_error(Excon::Errors::SocketError)
108
- end
109
- end
110
- end
111
-
112
- # Doesn't appear to raise anything right now
113
- # describe "destroy" do
114
- # before(:each) do
115
- # @temp_object = Dragonfly::TempObject.new('gollum')
116
- # end
117
- # it "should raise an error if the data doesn't exist on destroy" do
118
- # uid = @data_store.store(@temp_object)
119
- # @data_store.destroy(uid)
120
- # lambda{
121
- # @data_store.destroy(uid)
122
- # }.should raise_error(Dragonfly::DataStorage::DataNotFound)
123
- # end
124
- # end
125
-
126
- describe "domain" do
127
- it "should default to the US" do
128
- @data_store.region = nil
129
- @data_store.domain.should == 's3.amazonaws.com'
130
- end
131
-
132
- it "should return the correct domain" do
133
- @data_store.region = 'eu-west-1'
134
- @data_store.domain.should == 's3-eu-west-1.amazonaws.com'
135
- end
136
-
137
- it "does raise an error if an unknown region is given" do
138
- @data_store.region = 'latvia-central'
139
- lambda{
140
- @data_store.domain
141
- }.should raise_error
142
- end
143
- end
144
-
145
- describe "not configuring stuff properly" do
146
- before(:each) do
147
- @temp_object = Dragonfly::TempObject.new("Hi guys")
148
- end
149
-
150
- it "should require a bucket name on store" do
151
- @data_store.bucket_name = nil
152
- proc{ @data_store.store(@temp_object) }.should raise_error(Dragonfly::Configurable::NotConfigured)
153
- end
154
-
155
- it "should require an access_key_id on store" do
156
- @data_store.access_key_id = nil
157
- proc{ @data_store.store(@temp_object) }.should raise_error(Dragonfly::Configurable::NotConfigured)
158
- end
159
-
160
- it "should require a secret access key on store" do
161
- @data_store.secret_access_key = nil
162
- proc{ @data_store.store(@temp_object) }.should raise_error(Dragonfly::Configurable::NotConfigured)
163
- end
164
-
165
- it "should require a bucket name on retrieve" do
166
- @data_store.bucket_name = nil
167
- proc{ @data_store.retrieve('asdf') }.should raise_error(Dragonfly::Configurable::NotConfigured)
168
- end
169
-
170
- it "should require an access_key_id on retrieve" do
171
- @data_store.access_key_id = nil
172
- proc{ @data_store.retrieve('asdf') }.should raise_error(Dragonfly::Configurable::NotConfigured)
173
- end
174
-
175
- it "should require a secret access key on retrieve" do
176
- @data_store.secret_access_key = nil
177
- proc{ @data_store.retrieve('asdf') }.should raise_error(Dragonfly::Configurable::NotConfigured)
178
- end
179
- end
180
-
181
- describe "autocreating the bucket" do
182
- it "should create the bucket on store if it doesn't exist" do
183
- @data_store.bucket_name = "dragonfly-test-blah-blah-#{rand(100000000)}"
184
- @data_store.store(Dragonfly::TempObject.new("asdfj"))
185
- end
186
-
187
- it "should not try to create the bucket on retrieve if it doesn't exist" do
188
- @data_store.bucket_name = "dragonfly-test-blah-blah-#{rand(100000000)}"
189
- @data_store.send(:storage).should_not_receive(:put_bucket)
190
- proc{ @data_store.retrieve("gungle") }.should raise_error(Dragonfly::DataStorage::DataNotFound)
191
- end
192
- end
193
-
194
- describe "headers" do
195
- before(:each) do
196
- @temp_object = Dragonfly::TempObject.new('fjkdlsa')
197
- @data_store.storage_headers = {'x-amz-foo' => 'biscuithead'}
198
- end
199
-
200
- it "should allow configuring globally" do
201
- @data_store.storage.should_receive(:put_object).with(BUCKET_NAME, anything, anything,
202
- hash_including('x-amz-foo' => 'biscuithead')
203
- )
204
- @data_store.store(@temp_object)
205
- end
206
-
207
- it "should allow adding per-store" do
208
- @data_store.storage.should_receive(:put_object).with(BUCKET_NAME, anything, anything,
209
- hash_including('x-amz-foo' => 'biscuithead', 'hello' => 'there')
210
- )
211
- @data_store.store(@temp_object, :headers => {'hello' => 'there'})
212
- end
213
-
214
- it "should let the per-store one take precedence" do
215
- @data_store.storage.should_receive(:put_object).with(BUCKET_NAME, anything, anything,
216
- hash_including('x-amz-foo' => 'override!')
217
- )
218
- @data_store.store(@temp_object, :headers => {'x-amz-foo' => 'override!'})
219
- end
220
-
221
- it "should not mess with the meta" do
222
- @data_store.storage.should_receive(:put_object) do |_, __, ___, headers|
223
- headers['x-amz-meta-extra'].should =~ /^\w+$/
224
- end
225
- @data_store.store(@temp_object, :headers => {'hello' => 'there'})
226
- end
227
-
228
- it "should store with the content-type if passed in" do
229
- @data_store.storage.should_receive(:put_object) do |_, __, ___, headers|
230
- headers['Content-Type'].should == 'text/plain'
231
- end
232
- @data_store.store(@temp_object, :mime_type => 'text/plain')
233
- end
234
- end
235
-
236
- describe "urls for serving directly" do
237
-
238
- before(:each) do
239
- @uid = 'some/path/on/s3'
240
- end
241
-
242
- it "should use the bucket subdomain" do
243
- @data_store.url_for(@uid).should == "http://#{BUCKET_NAME}.s3.amazonaws.com/some/path/on/s3"
244
- end
245
-
246
- it "should use the bucket subdomain for other regions too" do
247
- @data_store.region = 'eu-west-1'
248
- @data_store.url_for(@uid).should == "http://#{BUCKET_NAME}.s3.amazonaws.com/some/path/on/s3"
249
- end
250
-
251
- it "should give an expiring url" do
252
- @data_store.url_for(@uid, :expires => 1301476942).should =~
253
- %r{^https://#{BUCKET_NAME}\.#{@data_store.domain}/some/path/on/s3\?AWSAccessKeyId=#{@data_store.access_key_id}&Signature=[\w%]+&Expires=1301476942$}
254
- end
255
-
256
- it "should allow for using https" do
257
- @data_store.url_for(@uid, :scheme => 'https').should == "https://#{BUCKET_NAME}.s3.amazonaws.com/some/path/on/s3"
258
- end
259
-
260
- it "should allow for always using https" do
261
- @data_store.url_scheme = 'https'
262
- @data_store.url_for(@uid).should == "https://#{BUCKET_NAME}.s3.amazonaws.com/some/path/on/s3"
263
- end
264
-
265
- it "should allow for customizing the host" do
266
- @data_store.url_for(@uid, :host => 'customised.domain.com/and/path').should == "http://customised.domain.com/and/path/some/path/on/s3"
267
- end
268
-
269
- it "should allow the url_host to be customised permanently" do
270
- url_host = 'customised.domain.com/and/path'
271
- @data_store.url_host = url_host
272
- @data_store.url_for(@uid).should == "http://#{url_host}/some/path/on/s3"
273
- end
274
-
275
- end
276
-
277
- end
@@ -1,77 +0,0 @@
1
- require 'spec_helper'
2
-
3
- shared_examples_for "data_store" do
4
-
5
- # Using these shared spec requires you to set the inst var @data_store
6
-
7
- before(:each) do
8
- @temp_object = Dragonfly::TempObject.new('gollum')
9
- end
10
-
11
- describe "store" do
12
- it "should return a unique identifier for each storage" do
13
- temp_object2 = Dragonfly::TempObject.new('gollum')
14
- @data_store.store(@temp_object).should_not == @data_store.store(temp_object2)
15
- end
16
- it "should return a unique identifier for each storage even when the first is deleted" do
17
- uid1 = @data_store.store(@temp_object)
18
- @data_store.destroy(uid1)
19
- uid2 = @data_store.store(@temp_object)
20
- uid1.should_not == uid2
21
- end
22
- it "should allow for passing in options as a second argument" do
23
- @data_store.store(@temp_object, :some => :option)
24
- end
25
- end
26
-
27
- describe "retrieve" do
28
-
29
- describe "without meta" do
30
- before(:each) do
31
- uid = @data_store.store(@temp_object)
32
- @obj, @meta = @data_store.retrieve(uid)
33
- end
34
-
35
- it "should retrieve the stored data" do
36
- Dragonfly::TempObject.new(@obj).data.should == @temp_object.data
37
- end
38
-
39
- it "should return a meta hash (probably empty)" do
40
- @meta.should be_a(Hash)
41
- end
42
-
43
- end
44
-
45
- describe "when meta is given" do
46
- before(:each) do
47
- temp_object = Dragonfly::TempObject.new('gollum', :bitrate => '35', :name => 'danny.boy')
48
- @uid = @data_store.store(temp_object)
49
- @obj, @meta = @data_store.retrieve(@uid)
50
- end
51
-
52
- it "should return the stored meta" do
53
- @meta[:bitrate].should == '35'
54
- @meta[:name].should == 'danny.boy'
55
- end
56
- end
57
-
58
- it "should raise an exception if the data doesn't exist" do
59
- lambda{
60
- @data_store.retrieve('gooble/gubbub')
61
- }.should raise_error(Dragonfly::DataStorage::DataNotFound)
62
- end
63
- end
64
-
65
- describe "destroy" do
66
-
67
- it "should destroy the stored data" do
68
- uid = @data_store.store(@temp_object)
69
- @data_store.destroy(uid)
70
- lambda{
71
- @data_store.retrieve(uid)
72
- }.should raise_error(Dragonfly::DataStorage::DataNotFound)
73
- end
74
-
75
- end
76
-
77
- end
@@ -1,154 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec::Matchers.define :have_keys do |*keys|
4
- match do |given|
5
- given.keys.map{|sym| sym.to_s }.sort == keys.map{|sym| sym.to_s }.sort
6
- end
7
- end
8
-
9
- describe Dragonfly::FunctionManager do
10
-
11
- before(:each) do
12
- @fm = Dragonfly::FunctionManager.new
13
- end
14
-
15
- describe "registering functions" do
16
-
17
- describe "registering procs" do
18
-
19
- let(:func){ proc{ "HELLO" } }
20
-
21
- it "should allow registering procs" do
22
- @fm.add :hello, func
23
- @fm.functions.should == {:hello => [func]}
24
- end
25
-
26
- it "should allow registering using block syntax" do
27
- @fm.add(:hello, &func)
28
- @fm.functions.should == {:hello => [func]}
29
- end
30
-
31
- end
32
-
33
- describe "registering classes" do
34
-
35
- before(:each) do
36
- @class = Class.new do
37
- def doogie(buff)
38
- "eggheads #{buff}"
39
- end
40
- def bumfries(smarmey)
41
- "sharkboy"
42
- end
43
- end
44
- @fm.register(@class)
45
- end
46
-
47
- it "should add the methods" do
48
- @fm.functions.should have_keys(:doogie, :bumfries)
49
- end
50
-
51
- it "should record the registered object" do
52
- @fm.objects.length.should eql(1)
53
- @fm.objects.first.should be_a(@class)
54
- end
55
-
56
- it "should work when calling" do
57
- @fm.call_last(:doogie, 3).should == "eggheads 3"
58
- end
59
-
60
- it "should return the object when registering" do
61
- @fm.register(@class).should be_a(@class)
62
- end
63
-
64
- end
65
-
66
- end
67
-
68
- describe "configuring on registration" do
69
-
70
- before(:each) do
71
- @class = Class.new do
72
- include Dragonfly::Configurable
73
- configurable_attr :height, 183
74
- def initialize(age=6)
75
- @age = age
76
- end
77
- def height_and_age
78
- [height, @age]
79
- end
80
- end
81
- @fm.register(@class)
82
- end
83
-
84
- it "should pass the args on register to the object initializer" do
85
- @fm.register(@class, 43)
86
- @fm.call_last(:height_and_age).should == [183, 43]
87
- end
88
-
89
- it "should run configure if a block given" do
90
- @fm.register(@class){|c| c.height = 180 }
91
- @fm.call_last(:height_and_age).should == [180, 6]
92
- end
93
-
94
- it "should not include configurable methods in the functions" do
95
- @fm.functions.keys.should == [:height_and_age]
96
- end
97
- end
98
-
99
- describe "calling" do
100
-
101
- describe "errors" do
102
- it "should raise an error for call_last if the function doesn't exist" do
103
- lambda{
104
- @fm.call_last(:i_dont_exist)
105
- }.should raise_error(Dragonfly::FunctionManager::NotDefined)
106
- end
107
-
108
- it "should raise an error if the function is defined but unable to handle" do
109
- @fm.add(:chicken){ throw :unable_to_handle }
110
- lambda{
111
- @fm.call_last(:chicken)
112
- }.should raise_error(Dragonfly::FunctionManager::UnableToHandle)
113
- end
114
- end
115
-
116
- describe "simple" do
117
- it "should correctly call a registered block" do
118
- @fm.add(:egg){|num| num + 1 }
119
- @fm.call_last(:egg, 4).should == 5
120
- end
121
- it "should correctly call a registered class" do
122
- klass = Class.new do
123
- def dog(num)
124
- num * 2
125
- end
126
- end
127
- @fm.register(klass)
128
- @fm.call_last(:dog, 4).should == 8
129
- end
130
- it "should correctly call an object that responds to 'call'" do
131
- obj = Object.new
132
- def obj.call(num); num - 3; end
133
- @fm.add(:spoon, obj)
134
- @fm.call_last(:spoon, 4).should == 1
135
- end
136
- end
137
-
138
- describe "with more than one implementation of same function" do
139
- it "should use the last registered" do
140
- @fm.add(:bingo){|num| num + 1 }
141
- @fm.add(:bingo){|num| num - 1 }
142
- @fm.call_last(:bingo, 4).should == 3
143
- end
144
-
145
- it "should skip methods that throw :unable_to_handle" do
146
- @fm.add(:bingo){|num| num + 1 }
147
- @fm.add(:bingo){|num| throw :unable_to_handle }
148
- @fm.call_last(:bingo, 4).should == 5
149
- end
150
- end
151
-
152
- end
153
-
154
- end