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.

Files changed (157) hide show
  1. data/.gitignore +2 -0
  2. data/.specopts +2 -0
  3. data/.yardopts +11 -5
  4. data/Gemfile +22 -0
  5. data/Gemfile.rails.2.3.5 +13 -0
  6. data/History.md +49 -0
  7. data/README.md +18 -28
  8. data/Rakefile +24 -36
  9. data/VERSION +1 -1
  10. data/config.ru +4 -1
  11. data/dragonfly.gemspec +85 -99
  12. data/extra_docs/Analysers.md +66 -30
  13. data/extra_docs/Caching.md +22 -0
  14. data/extra_docs/Configuration.md +116 -0
  15. data/extra_docs/DataStorage.md +114 -14
  16. data/extra_docs/Encoding.md +62 -37
  17. data/extra_docs/GeneralUsage.md +118 -0
  18. data/extra_docs/Generators.md +92 -0
  19. data/extra_docs/Heroku.md +51 -0
  20. data/extra_docs/Index.md +8 -9
  21. data/extra_docs/MimeTypes.md +18 -17
  22. data/extra_docs/Models.md +251 -0
  23. data/extra_docs/Processing.md +94 -70
  24. data/extra_docs/Rack.md +53 -0
  25. data/extra_docs/Rails2.md +44 -0
  26. data/extra_docs/Rails3.md +51 -0
  27. data/extra_docs/Sinatra.md +21 -0
  28. data/extra_docs/URLs.md +114 -0
  29. data/features/images.feature +6 -7
  30. data/features/no_processing.feature +0 -6
  31. data/features/rails_2.3.5.feature +1 -1
  32. data/features/rails_3.0.0.rc.feature +8 -0
  33. data/features/steps/dragonfly_steps.rb +14 -12
  34. data/features/steps/rails_steps.rb +20 -9
  35. data/features/support/env.rb +10 -11
  36. data/fixtures/files/app/views/albums/new.html.erb +4 -4
  37. data/fixtures/files/app/views/albums/show.html.erb +1 -1
  38. data/fixtures/files/features/manage_album_images.feature +1 -1
  39. data/fixtures/files/features/step_definitions/{album_steps.rb → image_steps.rb} +4 -3
  40. data/fixtures/files/features/support/paths.rb +2 -0
  41. data/fixtures/files/features/text_images.feature +7 -0
  42. data/fixtures/rails_3.0.0.rc/template.rb +21 -0
  43. data/irbrc.rb +2 -1
  44. data/lib/dragonfly.rb +4 -16
  45. data/lib/dragonfly/{active_record_extensions.rb → active_model_extensions.rb} +1 -1
  46. data/lib/dragonfly/active_model_extensions/attachment.rb +146 -0
  47. data/lib/dragonfly/{active_record_extensions → active_model_extensions}/class_methods.rb +5 -6
  48. data/lib/dragonfly/{active_record_extensions → active_model_extensions}/instance_methods.rb +1 -1
  49. data/lib/dragonfly/{active_record_extensions → active_model_extensions}/validations.rb +5 -9
  50. data/lib/dragonfly/analyser.rb +59 -0
  51. data/lib/dragonfly/analysis/file_command_analyser.rb +1 -1
  52. data/lib/dragonfly/analysis/r_magick_analyser.rb +46 -31
  53. data/lib/dragonfly/app.rb +138 -173
  54. data/lib/dragonfly/config/heroku.rb +19 -0
  55. data/lib/dragonfly/config/r_magick.rb +37 -0
  56. data/lib/dragonfly/config/{rails_defaults.rb → rails.rb} +6 -7
  57. data/lib/dragonfly/configurable.rb +30 -27
  58. data/lib/dragonfly/core_ext/object.rb +1 -1
  59. data/lib/dragonfly/data_storage/file_data_store.rb +59 -26
  60. data/lib/dragonfly/data_storage/mongo_data_store.rb +65 -0
  61. data/lib/dragonfly/data_storage/s3data_store.rb +31 -12
  62. data/lib/dragonfly/encoder.rb +13 -0
  63. data/lib/dragonfly/encoding/r_magick_encoder.rb +10 -19
  64. data/lib/dragonfly/endpoint.rb +43 -0
  65. data/lib/dragonfly/function_manager.rb +65 -0
  66. data/lib/dragonfly/{processing/r_magick_text_processor.rb → generation/r_magick_generator.rb} +25 -11
  67. data/lib/dragonfly/generator.rb +9 -0
  68. data/lib/dragonfly/job.rb +290 -0
  69. data/lib/dragonfly/job_builder.rb +39 -0
  70. data/lib/dragonfly/job_definitions.rb +26 -0
  71. data/lib/dragonfly/job_endpoint.rb +17 -0
  72. data/lib/dragonfly/loggable.rb +28 -0
  73. data/lib/dragonfly/middleware.rb +21 -14
  74. data/lib/dragonfly/processing/r_magick_processor.rb +71 -48
  75. data/lib/dragonfly/processor.rb +9 -0
  76. data/lib/dragonfly/r_magick_utils.rb +24 -0
  77. data/lib/dragonfly/rails/images.rb +10 -7
  78. data/lib/dragonfly/routed_endpoint.rb +42 -0
  79. data/lib/dragonfly/serializer.rb +32 -0
  80. data/lib/dragonfly/simple_cache.rb +23 -0
  81. data/lib/dragonfly/simple_endpoint.rb +64 -0
  82. data/lib/dragonfly/temp_object.rb +77 -45
  83. data/spec/argument_matchers.rb +7 -17
  84. data/spec/dragonfly/active_model_extensions/active_model_setup.rb +97 -0
  85. data/spec/dragonfly/active_model_extensions/active_record_setup.rb +85 -0
  86. data/spec/dragonfly/{active_record_extensions → active_model_extensions}/model_spec.rb +282 -244
  87. data/spec/dragonfly/active_model_extensions/spec_helper.rb +11 -0
  88. data/spec/dragonfly/analyser_spec.rb +123 -0
  89. data/spec/dragonfly/analysis/file_command_analyser_spec.rb +2 -2
  90. data/spec/dragonfly/analysis/r_magick_analyser_spec.rb +10 -1
  91. data/spec/dragonfly/app_spec.rb +175 -69
  92. data/spec/dragonfly/configurable_spec.rb +14 -0
  93. data/spec/dragonfly/data_storage/data_store_spec.rb +36 -9
  94. data/spec/dragonfly/data_storage/file_data_store_spec.rb +61 -38
  95. data/spec/dragonfly/data_storage/mongo_data_store_spec.rb +18 -0
  96. data/spec/dragonfly/data_storage/s3_data_store_spec.rb +34 -39
  97. data/spec/dragonfly/deprecation_spec.rb +20 -0
  98. data/spec/dragonfly/function_manager_spec.rb +154 -0
  99. data/spec/dragonfly/generation/r_magick_generator_spec.rb +119 -0
  100. data/spec/dragonfly/job_builder_spec.rb +37 -0
  101. data/spec/dragonfly/job_definitions_spec.rb +35 -0
  102. data/spec/dragonfly/job_endpoint_spec.rb +66 -0
  103. data/spec/dragonfly/job_spec.rb +605 -0
  104. data/spec/dragonfly/loggable_spec.rb +80 -0
  105. data/spec/dragonfly/middleware_spec.rb +37 -17
  106. data/spec/dragonfly/processing/r_magick_processor_spec.rb +182 -166
  107. data/spec/dragonfly/routed_endpoint_spec.rb +48 -0
  108. data/spec/dragonfly/serializer_spec.rb +61 -0
  109. data/spec/dragonfly/simple_cache_spec.rb +27 -0
  110. data/spec/dragonfly/simple_endpoint_spec.rb +78 -0
  111. data/spec/dragonfly/temp_object_spec.rb +154 -119
  112. data/spec/simple_matchers.rb +22 -0
  113. data/spec/spec_helper.rb +28 -4
  114. data/yard/templates/default/layout/html/layout.erb +18 -11
  115. metadata +89 -190
  116. data/config.rb +0 -5
  117. data/extra_docs/ActiveRecord.md +0 -196
  118. data/extra_docs/ExampleUseCases.md +0 -189
  119. data/extra_docs/GettingStarted.md +0 -114
  120. data/extra_docs/Shortcuts.md +0 -118
  121. data/extra_docs/UsingWithRails.md +0 -81
  122. data/features/rails_3.0.0.beta3.feature +0 -7
  123. data/fixtures/rails_3.0.0.beta3/template.rb +0 -16
  124. data/lib/dragonfly/active_record_extensions/attachment.rb +0 -170
  125. data/lib/dragonfly/analyser_list.rb +0 -9
  126. data/lib/dragonfly/analysis/base.rb +0 -10
  127. data/lib/dragonfly/belongs_to_app.rb +0 -24
  128. data/lib/dragonfly/config/heroku_rails_images.rb +0 -23
  129. data/lib/dragonfly/config/r_magick_images.rb +0 -69
  130. data/lib/dragonfly/config/r_magick_text.rb +0 -25
  131. data/lib/dragonfly/config/rails_images.rb +0 -13
  132. data/lib/dragonfly/data_storage/base.rb +0 -21
  133. data/lib/dragonfly/data_storage/base64_data_store.rb +0 -23
  134. data/lib/dragonfly/data_storage/transparent_data_store.rb +0 -21
  135. data/lib/dragonfly/delegatable.rb +0 -14
  136. data/lib/dragonfly/delegator.rb +0 -62
  137. data/lib/dragonfly/encoder_list.rb +0 -9
  138. data/lib/dragonfly/encoding/base.rb +0 -14
  139. data/lib/dragonfly/encoding/transparent_encoder.rb +0 -14
  140. data/lib/dragonfly/extended_temp_object.rb +0 -120
  141. data/lib/dragonfly/parameters.rb +0 -163
  142. data/lib/dragonfly/processing/base.rb +0 -10
  143. data/lib/dragonfly/processor_list.rb +0 -9
  144. data/lib/dragonfly/url_handler.rb +0 -147
  145. data/spec/dragonfly/active_record_extensions/attachment_spec.rb +0 -8
  146. data/spec/dragonfly/active_record_extensions/migration.rb +0 -42
  147. data/spec/dragonfly/active_record_extensions/models.rb +0 -6
  148. data/spec/dragonfly/active_record_extensions/spec_helper.rb +0 -24
  149. data/spec/dragonfly/belongs_to_app_spec.rb +0 -55
  150. data/spec/dragonfly/delegatable_spec.rb +0 -32
  151. data/spec/dragonfly/delegator_spec.rb +0 -145
  152. data/spec/dragonfly/extended_temp_object_spec.rb +0 -71
  153. data/spec/dragonfly/parameters_spec.rb +0 -298
  154. data/spec/dragonfly/processing/r_magick_text_processor_spec.rb +0 -84
  155. data/spec/dragonfly/url_handler_spec.rb +0 -247
  156. data/spec/dragonfly_spec.rb +0 -16
  157. data/spec/ginger_scenarios.rb +0 -13
@@ -54,6 +54,10 @@ describe Dragonfly::Configurable do
54
54
  end
55
55
  }.should raise_error(Dragonfly::Configurable::BadConfigAttribute)
56
56
  end
57
+
58
+ it "should return itself" do
59
+ @car.configure{|c|}.should == @car
60
+ end
57
61
  end
58
62
 
59
63
  describe "getting configuration" do
@@ -203,6 +207,16 @@ describe Dragonfly::Configurable do
203
207
  end
204
208
  @car.colour.should == 'branco'
205
209
  end
210
+
211
+ it "should return itself" do
212
+ @car.configure_with(@cool_configuration).should == @car
213
+ end
214
+
215
+ it "should ask the object which object to configure with if a symbol is given" do
216
+ @car.should_receive(:configurer_for).with(:cool).and_return(@cool_configuration)
217
+ @car.configure_with(:cool)
218
+ @car.colour.should == 'vermelho'
219
+ end
206
220
  end
207
221
 
208
222
  end
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
3
3
  describe "data_store", :shared => true do
4
4
 
5
5
  # Using these shared spec requires you to set the inst var @data_store
6
-
6
+
7
7
  before(:each) do
8
8
  @temp_object = Dragonfly::TempObject.new('gollum')
9
9
  end
@@ -13,12 +13,39 @@ describe "data_store", :shared => true do
13
13
  temp_object2 = Dragonfly::TempObject.new('gollum')
14
14
  @data_store.store(@temp_object).should_not == @data_store.store(temp_object2)
15
15
  end
16
+ it "should allow for passing in options as a second argument" do
17
+ @data_store.store(@temp_object, :some => :option)
18
+ end
16
19
  end
17
-
20
+
18
21
  describe "retrieve" do
19
- it "should retrieve the stored data" do
20
- uid = @data_store.store(@temp_object)
21
- Dragonfly::TempObject.new(@data_store.retrieve(uid)).data.should == @temp_object.data
22
+
23
+ describe "without extra info" do
24
+ before(:each) do
25
+ uid = @data_store.store(@temp_object)
26
+ @obj, @extra_info = @data_store.retrieve(uid)
27
+ end
28
+
29
+ it "should retrieve the stored data" do
30
+ Dragonfly::TempObject.new(@obj).data.should == @temp_object.data
31
+ end
32
+
33
+ it { @extra_info[:name].should be_nil }
34
+ it { @extra_info[:meta].should be_a(Hash) }
35
+ end
36
+
37
+ describe "when extra info is given" do
38
+ before(:each) do
39
+ temp_object = Dragonfly::TempObject.new('gollum',
40
+ :name => 'danny.boy',
41
+ :meta => {:bitrate => '35'}
42
+ )
43
+ @uid = @data_store.store(temp_object)
44
+ @obj, @extra_info = @data_store.retrieve(@uid)
45
+ end
46
+
47
+ it { @extra_info[:name].should == 'danny.boy' }
48
+ it { @extra_info[:meta].should include_hash(:bitrate => '35') }
22
49
  end
23
50
 
24
51
  it "should raise an exception if the data doesn't exist" do
@@ -27,9 +54,9 @@ describe "data_store", :shared => true do
27
54
  }.should raise_error(Dragonfly::DataStorage::DataNotFound)
28
55
  end
29
56
  end
30
-
57
+
31
58
  describe "destroy" do
32
-
59
+
33
60
  it "should destroy the stored data" do
34
61
  uid = @data_store.store(@temp_object)
35
62
  @data_store.destroy(uid)
@@ -37,7 +64,7 @@ describe "data_store", :shared => true do
37
64
  @data_store.retrieve(uid)
38
65
  }.should raise_error(Dragonfly::DataStorage::DataNotFound)
39
66
  end
40
-
67
+
41
68
  end
42
69
 
43
- end
70
+ end
@@ -3,19 +3,19 @@ require File.dirname(__FILE__) + '/data_store_spec'
3
3
 
4
4
  describe Dragonfly::DataStorage::FileDataStore do
5
5
 
6
+ def touch_file(filename)
7
+ FileUtils.mkdir_p(File.dirname(filename))
8
+ FileUtils.touch(filename)
9
+ end
10
+
6
11
  before(:each) do
7
12
  @data_store = Dragonfly::DataStorage::FileDataStore.new
8
13
  @data_store.root_path = '/var/tmp/dragonfly_test'
9
-
10
- # Set 'now' to a date in the past
11
- Time.stub!(:now).and_return Time.mktime(1984,"may",4,14,28,1)
12
- @file_pattern_prefix_without_root = '1984/05/04/142801'
13
- @file_pattern_prefix = "#{@data_store.root_path}/#{@file_pattern_prefix_without_root}"
14
14
  end
15
15
 
16
16
  after(:each) do
17
17
  # Clean up created files
18
- FileUtils.rm_rf("#{@data_store.root_path}/1984")
18
+ FileUtils.rm_rf("#{@data_store.root_path}")
19
19
  end
20
20
 
21
21
  it_should_behave_like 'data_store'
@@ -27,54 +27,55 @@ describe Dragonfly::DataStorage::FileDataStore do
27
27
  describe "store" do
28
28
 
29
29
  def it_should_write_to_file(storage_path, temp_object)
30
- FileUtils.should_receive(:cp).with(temp_object.path, storage_path)
30
+ temp_object.should_receive(:to_file).with(storage_path).and_return(mock('file', :close => nil))
31
+ end
32
+
33
+ before(:each) do
34
+ # Set 'now' to a date in the past
35
+ Time.stub!(:now).and_return Time.mktime(1984,"may",4,14,28,1)
36
+ @file_pattern_prefix_without_root = '1984/05/04/'
37
+ @file_pattern_prefix = "#{@data_store.root_path}/#{@file_pattern_prefix_without_root}"
31
38
  end
32
39
 
33
40
  it "should store the file in a folder based on date, with default filename" do
34
- it_should_write_to_file("#{@file_pattern_prefix}_file", @temp_object)
41
+ it_should_write_to_file("#{@file_pattern_prefix}file", @temp_object)
35
42
  @data_store.store(@temp_object)
36
43
  end
37
44
 
38
45
  it "should use the temp_object name if it exists" do
39
- @temp_object.name = 'hello'
40
- it_should_write_to_file("#{@file_pattern_prefix}_hello", @temp_object)
41
- @data_store.store(@temp_object)
42
- end
43
-
44
- it "should strip the extension of the temp_object name" do
45
- @temp_object.name = 'hello.you.png'
46
- it_should_write_to_file("#{@file_pattern_prefix}_hello.you", @temp_object)
46
+ @temp_object.should_receive(:name).at_least(:once).and_return('hello.there')
47
+ it_should_write_to_file("#{@file_pattern_prefix}hello.there", @temp_object)
47
48
  @data_store.store(@temp_object)
48
49
  end
49
50
 
50
- it "should use the default file suffix if the temp_object name is blank" do
51
- @temp_object.name = ''
52
- it_should_write_to_file("#{@file_pattern_prefix}_file", @temp_object)
51
+ it "should get rid of funny characters in the temp_object name" do
52
+ @temp_object.should_receive(:name).at_least(:once).and_return('A Picture with many spaces in its name (at 20:00 pm).png')
53
+ it_should_write_to_file("#{@file_pattern_prefix}A_Picture_with_many_spaces_in_its_name_at_20_00_pm_.png", @temp_object)
53
54
  @data_store.store(@temp_object)
54
55
  end
55
56
 
56
57
  describe "when the filename already exists" do
57
58
 
58
- it "should store the file with a numbered suffix" do
59
- FileUtils.mkdir_p(@file_pattern_prefix)
60
- FileUtils.touch("#{@file_pattern_prefix}_file")
61
- it_should_write_to_file("#{@file_pattern_prefix}_file_2", @temp_object)
59
+ it "should use a different filename" do
60
+ touch_file("#{@file_pattern_prefix}file")
61
+ @data_store.should_receive(:disambiguate).with('file').and_return('file_2')
62
+ it_should_write_to_file("#{@file_pattern_prefix}file_2", @temp_object)
62
63
  @data_store.store(@temp_object)
63
64
  end
64
65
 
65
- it "should store the file with a numbered suffix taking into account the name" do
66
- @temp_object.name = 'hello.png'
67
- FileUtils.mkdir_p(@file_pattern_prefix)
68
- FileUtils.touch("#{@file_pattern_prefix}_hello")
69
- it_should_write_to_file("#{@file_pattern_prefix}_hello_2", @temp_object)
66
+ it "should use a different filename taking into account the name and ext" do
67
+ @temp_object.should_receive(:name).at_least(:once).and_return('hello.png')
68
+ touch_file("#{@file_pattern_prefix}hello.png")
69
+ @data_store.should_receive(:disambiguate).with('hello.png').and_return('blah.png')
70
70
  @data_store.store(@temp_object)
71
71
  end
72
-
73
- it "should store the file with an incremented number suffix" do
74
- FileUtils.mkdir_p(@file_pattern_prefix)
75
- FileUtils.touch("#{@file_pattern_prefix}_file")
76
- FileUtils.touch("#{@file_pattern_prefix}_file_2")
77
- it_should_write_to_file("#{@file_pattern_prefix}_file_3", @temp_object)
72
+
73
+ it "should keep trying until it finds a free filename" do
74
+ touch_file("#{@file_pattern_prefix}file")
75
+ touch_file("#{@file_pattern_prefix}file_2")
76
+ @data_store.should_receive(:disambiguate).with('file').and_return('file_2')
77
+ @data_store.should_receive(:disambiguate).with('file_2').and_return('file_3')
78
+ it_should_write_to_file("#{@file_pattern_prefix}file_3", @temp_object)
78
79
  @data_store.store(@temp_object)
79
80
  end
80
81
 
@@ -83,18 +84,30 @@ describe Dragonfly::DataStorage::FileDataStore do
83
84
  describe "return value" do
84
85
 
85
86
  it "should return the filepath without the root of the stored file when a file name is not provided" do
86
- @data_store.store(@temp_object).should == "#{@file_pattern_prefix_without_root}_file"
87
+ @data_store.store(@temp_object).should == "#{@file_pattern_prefix_without_root}file"
87
88
  end
88
89
 
89
90
  it "should return the filepath without the root of the stored file when a file name is provided" do
90
- @temp_object.name = 'hello.you.png'
91
- @data_store.store(@temp_object).should == "#{@file_pattern_prefix_without_root}_hello.you"
91
+ @temp_object.should_receive(:name).at_least(:once).and_return('hello.you.png')
92
+ @data_store.store(@temp_object).should == "#{@file_pattern_prefix_without_root}hello.you.png"
92
93
  end
93
94
 
94
95
  end
95
96
 
96
97
  end
97
98
 
99
+ describe "disambiguate" do
100
+ it "should add a suffix" do
101
+ @data_store.disambiguate('file').should =~ /^file_\w+$/
102
+ end
103
+ it "should add a suffix to the basename" do
104
+ @data_store.disambiguate('file.png').should =~ /^file_\w+\.png$/
105
+ end
106
+ it "should be random(-ish)" do
107
+ @data_store.disambiguate('file').should_not == @data_store.disambiguate('file')
108
+ end
109
+ end
110
+
98
111
  describe "errors" do
99
112
 
100
113
  it "should raise an error if it can't create a directory" do
@@ -103,12 +116,22 @@ describe Dragonfly::DataStorage::FileDataStore do
103
116
  end
104
117
 
105
118
  it "should raise an error if it can't create a file" do
106
- FileUtils.should_receive(:cp).and_raise(Errno::EACCES)
119
+ @temp_object.should_receive(:to_file).and_raise(Errno::EACCES)
107
120
  lambda{ @data_store.store(@temp_object) }.should raise_error(Dragonfly::DataStorage::UnableToStore)
108
121
  end
109
122
 
110
123
  end
111
124
 
125
+ describe "retrieve" do
126
+ it "should be able to retrieve any file, stored or not (and without extra data)" do
127
+ FileUtils.mkdir_p("#{@data_store.root_path}/jelly_beans/are")
128
+ File.open("#{@data_store.root_path}/jelly_beans/are/good", 'w'){|f| f.write('hey dog') }
129
+ file, meta = @data_store.retrieve("jelly_beans/are/good")
130
+ file.read.should == 'hey dog'
131
+ meta.should == {}
132
+ end
133
+ end
134
+
112
135
  describe "destroying" do
113
136
 
114
137
  it "should raise an error if the data doesn't exist" do
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require File.dirname(__FILE__) + '/data_store_spec'
3
+ require 'mongo'
4
+
5
+ describe Dragonfly::DataStorage::MongoDataStore do
6
+
7
+ before(:each) do
8
+ begin
9
+ Mongo::Connection.new
10
+ rescue Mongo::ConnectionFailure => e
11
+ pending "You need to start mongo on localhost:27017 to test the MongoDataStore"
12
+ end
13
+ @data_store = Dragonfly::DataStorage::MongoDataStore.new
14
+ end
15
+
16
+ it_should_behave_like 'data_store'
17
+
18
+ end
@@ -3,49 +3,44 @@ require File.dirname(__FILE__) + '/data_store_spec'
3
3
 
4
4
  describe Dragonfly::DataStorage::S3DataStore do
5
5
 
6
- # Uncomment this to test it with an actual internet connection
7
- # describe "common data_store behaviour" do
8
- #
9
- # before(:each) do
10
- # @data_store = Dragonfly::DataStorage::S3DataStore.new
11
- # @data_store.configure do |d|
12
- # d.bucket_name = 'dragonfly_test'
13
- # d.access_key_id = 'xxxxxxxxxx'
14
- # d.secret_access_key = 'xxxxxxxxxx'
15
- # end
16
- # end
17
- #
18
- # it_should_behave_like 'data_store'
19
- #
20
- # end
6
+ # Change this to test it with an actual internet connection
7
+ enabled = false
8
+
9
+ if enabled
21
10
 
22
- describe "specific s3_data_store behaviour" do
23
- before(:each) do
24
- @data_store = Dragonfly::DataStorage::S3DataStore.new
25
- @data_store.configure do |d|
26
- d.bucket_name = 'dragonfly_test'
27
- d.access_key_id = 'my_key_id'
28
- d.secret_access_key = 'my_secret_access_key'
11
+ describe "common data_store behaviour" do
12
+
13
+ before(:each) do
14
+ @data_store = Dragonfly::DataStorage::S3DataStore.new
15
+ @data_store.configure do |d|
16
+ d.bucket_name = 'dragonfly_test'
17
+ d.access_key_id = 'XXX'
18
+ d.secret_access_key = 'XXX'
19
+ end
29
20
  end
30
- @temp_object = Dragonfly::TempObject.new('gollum')
31
- AWS::S3::Base.stub!(:establish_connection!).with(
32
- :access_key_id => @data_store.access_key_id,
33
- :secret_access_key => @data_store.secret_access_key
34
- )
35
- AWS::S3::Bucket.stub!(:create).with(@data_store.bucket_name)
36
- AWS::S3::Service.stub!(:buckets).and_return([])
37
- AWS::S3::S3Object.stub!(:store).with(anything, anything, @data_store.bucket_name)
38
- AWS::S3::S3Object.stub!(:value).with(anything, @data_store.bucket_name)
39
- AWS::S3::S3Object.stub!(:delete).with(anything, @data_store.bucket_name)
40
- end
41
21
 
42
-
43
- describe "store" do
44
- it "should return a unique identifier for each storage" do
45
- temp_object2 = Dragonfly::TempObject.new('gollum')
46
- @data_store.store(@temp_object).should_not == @data_store.store(temp_object2)
22
+ it_should_behave_like 'data_store'
23
+
24
+ describe "store" do
25
+ it "should return a unique identifier for each storage" do
26
+ temp_object = Dragonfly::TempObject.new('gollum')
27
+ temp_object2 = Dragonfly::TempObject.new('gollum')
28
+ @data_store.store(temp_object).should_not == @data_store.store(temp_object2)
29
+ end
30
+
31
+ it "should work ok with files with funny names" do
32
+ temp_object = Dragonfly::TempObject.new('eggheads',
33
+ :name => 'A Picture with many spaces in its name (at 20:00 pm).png'
34
+ )
35
+ uid = @data_store.store(temp_object)
36
+ uid.should =~ /A_Picture_with_many_spaces_in_its_name_at_20_00_pm_\.png$/
37
+ data, extra = @data_store.retrieve(uid)
38
+ data.should == 'eggheads'
39
+ end
47
40
  end
41
+
48
42
  end
43
+
49
44
  end
50
45
 
51
- end
46
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Deprecated stuff" do
4
+
5
+ describe "job urls" do
6
+
7
+ before(:each) do
8
+ @app = test_app.configure_with(:rmagick) do |c|
9
+ c.log = Logger.new($stdout)
10
+ end
11
+ @job = @app.fetch('eggs')
12
+ end
13
+
14
+ it { @job.url(:gif).should == @job.gif.url }
15
+ it { @job.url('20x20').should == @job.thumb('20x20').url }
16
+ it { @job.url('20x20', :gif).should == @job.thumb('20x20', :gif).url }
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,154 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ def have_keys(*keys)
4
+ simple_matcher("have keys #{keys.join(', ')}") 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