dragonfly 0.4.4 → 0.5.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 CHANGED
@@ -6,3 +6,4 @@ pkg
6
6
  .yardoc
7
7
  doc
8
8
  tmp
9
+ fixtures/*/tmp_app
@@ -1,3 +1,11 @@
1
+ 0.5.0 (2010-02-20)
2
+ ==================
3
+
4
+ Added support
5
+ -------------
6
+ - support for Rails 3
7
+
8
+
1
9
  0.4.4 (2010-02-16)
2
10
  ==================
3
11
 
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Mark Evans
1
+ Copyright (c) 2009-2010 Mark Evans
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -4,28 +4,42 @@ Dragonfly
4
4
  Dragonfly is a <a href="http://rack.rubyforge.org">Rack</a> framework for on-the-fly processing and encoding.
5
5
  It includes an extension for Ruby on Rails to enable easy image handling.
6
6
 
7
- For the lazy rails user
7
+ For the lazy Rails user
8
8
  -----------------------
9
9
  To use simply for image thumbnails etc. in Rails...
10
10
 
11
- environment.rb:
11
+ **environment.rb** (Rails 2.3 only):
12
12
 
13
13
  config.gem 'rmagick', :lib => 'RMagick'
14
14
  config.gem 'rack-cache', :lib => 'rack/cache'
15
- config.gem 'dragonfly', :lib => 'dragonfly/rails/images', :source => 'http://gemcutter.org'
15
+ config.gem 'dragonfly'
16
16
 
17
- Migration:
17
+ **Gemfile** (Rails 3 only):
18
+
19
+ gem 'rmagick', :require => 'RMagick'
20
+ gem 'rack-cache', :require => 'rack/cache'
21
+ gem 'dragonfly'
22
+
23
+ The above assumes that you have http://gemcutter.org as one of your gem sources.
24
+ If not you should add it, e.g. `gem source --add http://gemcutter.org` from the command line,
25
+ or add `source http://gemcutter.org` to your Gemfile.
26
+
27
+ **Initializer** (e.g. config/initializers/dragonfly.rb):
28
+
29
+ require 'dragonfly/rails/images'
30
+
31
+ **Migration**:
18
32
 
19
33
  add_column :albums, :cover_image_uid, :string
20
34
 
21
- Model:
35
+ **Model**:
22
36
 
23
37
  class Album < ActiveRecord::Base
24
38
  image_accessor :cover_image # Defines reader/writer for cover_image
25
39
  # ...
26
40
  end
27
41
 
28
- View (for uploading via a file field):
42
+ **View** (for uploading via a file field):
29
43
 
30
44
  <% form_for @album, :html => {:multipart => true} do |f| %>
31
45
  ...
@@ -34,7 +48,7 @@ View (for uploading via a file field):
34
48
  <% end %>
35
49
 
36
50
 
37
- View (to display):
51
+ **View** (to display):
38
52
 
39
53
  <%= image_tag @album.cover_image.url(:gif) %>
40
54
  <%= image_tag @album.cover_image.url('400x200') %>
@@ -67,4 +81,4 @@ Credits
67
81
  Copyright
68
82
  ========
69
83
 
70
- Copyright (c) 2009 Mark Evans. See LICENSE for details.
84
+ Copyright (c) 2009-2010 Mark Evans. See LICENSE for details.
data/Rakefile CHANGED
@@ -16,8 +16,10 @@ begin
16
16
  s.add_development_dependency 'aws-s3'
17
17
  s.add_development_dependency 'rspec'
18
18
  s.add_development_dependency 'cucumber'
19
+ s.add_development_dependency 'cucumber-rails'
19
20
  s.add_development_dependency 'activerecord'
20
21
  s.add_development_dependency 'sqlite3-ruby'
22
+ s.add_development_dependency 'ginger'
21
23
  end
22
24
  Jeweler::GemcutterTasks.new
23
25
  rescue LoadError
@@ -70,4 +72,33 @@ rescue LoadError
70
72
  puts "Cucumber is not available. To run features, install it with: (sudo) gem install cucumber"
71
73
  end
72
74
 
73
- task :default => [:spec, :features]
75
+ begin
76
+ require 'ginger'
77
+ rescue LoadError
78
+ puts "To run 'rake', to test everything, you need the Ginger gem. Install it with: (sudo) gem install ginger"
79
+ end
80
+ task :default do
81
+ system 'ginger spec && rake features'
82
+ end
83
+
84
+ desc 'Set up a Rails app ready for testing'
85
+ namespace :rails do
86
+
87
+ task :setup do
88
+ version = ENV['RAILS_VERSION']
89
+ raise "Please give a RAILS_VERSION, e.g. RAILS_VERSION=2.3.5" unless version
90
+ path = File.expand_path("fixtures/rails_#{version}")
91
+ app_name = 'tmp_app'
92
+ system %(
93
+ cd #{path} &&
94
+ rm -rf #{app_name} &&
95
+ ../rails _#{version}_ #{app_name} -m template.rb
96
+ )
97
+ FileUtils.cp("fixtures/dragonfly_setup.rb", "#{path}/#{app_name}/config/initializers")
98
+ system %(cd #{path}/#{app_name} && rake db:migrate)
99
+ puts "*** Created a Rails #{version} app in #{path}/#{app_name} ***"
100
+ puts "Now just start the server, and go to localhost:3000/albums"
101
+ puts "***"
102
+ end
103
+
104
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.4
1
+ 0.5.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dragonfly}
8
- s.version = "0.4.4"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mark Evans"]
12
- s.date = %q{2010-02-16}
12
+ s.date = %q{2010-02-20}
13
13
  s.email = %q{mark@new-bamboo.co.uk}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -39,9 +39,23 @@ Gem::Specification.new do |s|
39
39
  "extra_docs/UsingWithRails.md",
40
40
  "features/images.feature",
41
41
  "features/no_processing.feature",
42
+ "features/rails_2.3.5.feature",
43
+ "features/rails_3.0.0.beta.feature",
42
44
  "features/steps/common_steps.rb",
43
45
  "features/steps/dragonfly_steps.rb",
46
+ "features/steps/rails_steps.rb",
44
47
  "features/support/env.rb",
48
+ "fixtures/dragonfly_setup.rb",
49
+ "fixtures/files/app/models/album.rb",
50
+ "fixtures/files/app/views/albums/new.html.erb",
51
+ "fixtures/files/app/views/albums/show.html.erb",
52
+ "fixtures/files/config/initializers/aaa_dragonfly_load_path.rb",
53
+ "fixtures/files/features/manage_album_images.feature",
54
+ "fixtures/files/features/step_definitions/album_steps.rb",
55
+ "fixtures/files/features/support/paths.rb",
56
+ "fixtures/rails",
57
+ "fixtures/rails_2.3.5/template.rb",
58
+ "fixtures/rails_3.0.0.beta/template.rb",
45
59
  "generators/dragonfly_app/USAGE",
46
60
  "generators/dragonfly_app/dragonfly_app_generator.rb",
47
61
  "generators/dragonfly_app/templates/initializer.erb",
@@ -115,6 +129,7 @@ Gem::Specification.new do |s|
115
129
  "spec/dragonfly/temp_object_spec.rb",
116
130
  "spec/dragonfly/url_handler_spec.rb",
117
131
  "spec/dragonfly_spec.rb",
132
+ "spec/ginger_scenarios.rb",
118
133
  "spec/image_matchers.rb",
119
134
  "spec/simple_matchers.rb",
120
135
  "spec/spec_helper.rb",
@@ -157,6 +172,7 @@ Gem::Specification.new do |s|
157
172
  "spec/dragonfly/temp_object_spec.rb",
158
173
  "spec/dragonfly/url_handler_spec.rb",
159
174
  "spec/dragonfly_spec.rb",
175
+ "spec/ginger_scenarios.rb",
160
176
  "spec/image_matchers.rb",
161
177
  "spec/simple_matchers.rb",
162
178
  "spec/spec_helper.rb"
@@ -174,8 +190,10 @@ Gem::Specification.new do |s|
174
190
  s.add_development_dependency(%q<aws-s3>, [">= 0"])
175
191
  s.add_development_dependency(%q<rspec>, [">= 0"])
176
192
  s.add_development_dependency(%q<cucumber>, [">= 0"])
193
+ s.add_development_dependency(%q<cucumber-rails>, [">= 0"])
177
194
  s.add_development_dependency(%q<activerecord>, [">= 0"])
178
195
  s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
196
+ s.add_development_dependency(%q<ginger>, [">= 0"])
179
197
  else
180
198
  s.add_dependency(%q<rack>, [">= 0"])
181
199
  s.add_dependency(%q<jeweler>, [">= 0"])
@@ -184,8 +202,10 @@ Gem::Specification.new do |s|
184
202
  s.add_dependency(%q<aws-s3>, [">= 0"])
185
203
  s.add_dependency(%q<rspec>, [">= 0"])
186
204
  s.add_dependency(%q<cucumber>, [">= 0"])
205
+ s.add_dependency(%q<cucumber-rails>, [">= 0"])
187
206
  s.add_dependency(%q<activerecord>, [">= 0"])
188
207
  s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
208
+ s.add_dependency(%q<ginger>, [">= 0"])
189
209
  end
190
210
  else
191
211
  s.add_dependency(%q<rack>, [">= 0"])
@@ -195,8 +215,10 @@ Gem::Specification.new do |s|
195
215
  s.add_dependency(%q<aws-s3>, [">= 0"])
196
216
  s.add_dependency(%q<rspec>, [">= 0"])
197
217
  s.add_dependency(%q<cucumber>, [">= 0"])
218
+ s.add_dependency(%q<cucumber-rails>, [">= 0"])
198
219
  s.add_dependency(%q<activerecord>, [">= 0"])
199
220
  s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
221
+ s.add_dependency(%q<ginger>, [">= 0"])
200
222
  end
201
223
  end
202
224
 
@@ -43,6 +43,8 @@ Each method takes the temp_object, and the (optional) processing options hash as
43
43
 
44
44
  end
45
45
 
46
+ app = Dragonfly::App[:images]
47
+
46
48
  app.register_processor(MyProcessor)
47
49
 
48
50
  temp_object = app.create_object(File.new('path/to/image.png'))
@@ -56,3 +58,41 @@ As with analysers and encoders, if the processor is {Dragonfly::Configurable con
56
58
  app.register_processor(MyProcessor) do |p|
57
59
  p.some_attribute = 'hello'
58
60
  end
61
+
62
+ To get the url for content processed by your custom processor, the long way is using something like:
63
+
64
+ app.url_for('some_uid',
65
+ :processing_method => :black_and_white,
66
+ :processing_options => {:size => '30x30'},
67
+ :format => :png
68
+ )
69
+
70
+ or if using an activerecord model,
71
+
72
+ my_model.preview_image.url('some_uid',
73
+ :processing_method => :black_and_white,
74
+ :processing_options => {:size => '30x30'},
75
+ :format => :png
76
+ )
77
+
78
+ However, this could soon get tedious if using more than once, so the best thing is to register a shortcut for it.
79
+ So in your configuration of the Dragonfly app (or in an initializer if using 'dragonfly/rails/images') you
80
+ could do something like:
81
+
82
+ Dragonfly::App[:images].parameters.add_shortcut(/^bw-(\d*x\d*)$/) do |string, match_data|
83
+ {
84
+ :processing_method => :black_and_white,
85
+ :processing_options => {:size => match_data[1]},
86
+ :format => :png
87
+ }
88
+ end
89
+
90
+ Now you can get urls by using the shortcut:
91
+
92
+ app.url_for('some_uid', 'bw-30x30')
93
+
94
+ or with activerecord:
95
+
96
+ my_model.preview_image.url('bw-30x30')
97
+
98
+ For more information about shortcuts, see {file:Shortcuts}.
@@ -1,64 +1,40 @@
1
1
  Using With Rails
2
2
  ================
3
3
 
4
+ Dragonfly works with both Rails 2.3 and Rails 3.
5
+
4
6
  The main way to use Dragonfly with Rails is as a {Dragonfly::Middleware middleware}.
5
7
 
8
+ 1. The initializer
9
+ ------------------
10
+
6
11
  The quick way
7
12
  -------------
8
- In environment.rb:
13
+ There is a ready-made file which sets up Dragonfly for image processing for your rails app.
14
+ If image resizing, etc. is all you want to do, then put this in an initializer, e.g config/initializers/dragonfly.rb:
9
15
 
10
- config.gem 'rmagick', :lib => 'RMagick'
11
- config.gem 'rack-cache', :lib => 'rack/cache'
12
- config.gem 'dragonfly', :lib => 'dragonfly/rails/images', :source => 'http://gemcutter.org'
16
+ require 'dragonfly/rails/images'
13
17
 
14
- The required file 'dragonfly/rails/images.rb' initializes a dragonfly app, configures it to use rmagick processing, encoding, etc.,
18
+ This file initializes a dragonfly app, configures it to use rmagick processing, encoding, etc.,
15
19
  registers the app so that you can use ActiveRecord accessors, and inserts it into the Rails middleware stack.
16
20
 
17
- Because in this case it's configured to use {http://tomayko.com/src/rack-cache/ rack-cache} and {http://rmagick.rubyforge.org/ rmagick},
18
- you should include the first two lines above.
19
-
20
- To see what you can do with the active record accessors, see {file:ActiveRecord}.
21
-
22
- The more explicit way - using an initializer
23
- --------------------------------------------
24
- If you want more control over the configuration, you can do what the file 'dragonfly/rails/images' does yourself,
25
- in an initializer.
26
-
27
- In that case in environment.rb we only need:
28
-
29
- config.gem 'rmagick', :lib => 'RMagick' # if used
30
- config.gem 'rack-cache', :lib => 'rack/cache' # if used
31
- config.gem 'dragonfly', :source => 'http://gemcutter.org'
32
-
33
- The easiest way to create the initializer is using the supplied generator
34
- (which will be visible if you have the dragonfly gem installed).
35
-
36
- ./script/generate dragonfly_app images
37
-
38
- The argument 'images' could be anything - it is an arbitrary app name.
39
-
40
- This creates an initializer 'dragonfly_images' which does the following:
41
-
42
- 1. Creates and configures a dragonfly app
43
- 2. Registers the app for use with ActiveRecord - see {file:ActiveRecord}
44
- 3. Inserts the app into the Rails middleware stack
45
-
46
- For reference, the contents of an example initializer are shown below.
47
- You could just copy and paste this yourself into an initializer if you prefer,
48
- but make sure to change the 'secret' configuration option, so as to protect your app from Denial-of-Service attacks (see {file:GettingStarted}).
21
+ The more explicit way
22
+ ---------------------
23
+ If you want to set up and configure the Dragonfly app yourself, then you can put something like the code below in an initializer and
24
+ modify accordingly:
49
25
 
50
26
  require 'dragonfly'
51
27
 
52
- # Configuration
28
+ # Set up and configure the dragonfly app
53
29
  app = Dragonfly::App[:images]
54
30
  app.configure_with(Dragonfly::RMagickConfiguration)
55
31
  app.configure do |c|
56
- c.log = RAILS_DEFAULT_LOGGER
32
+ c.log = Rails.logger
57
33
  c.datastore.configure do |d|
58
34
  d.root_path = "#{Rails.root}/public/system/dragonfly/#{Rails.env}"
59
35
  end
60
36
  c.url_handler.configure do |u|
61
- u.secret = 'fed49e269eebed54cc85b28a6c51cba6a543e7b5'
37
+ u.secret = 'insert some secret here to protect from DOS attacks!'
62
38
  u.path_prefix = '/media'
63
39
  end
64
40
  end
@@ -70,18 +46,48 @@ but make sure to change the 'secret' configuration option, so as to protect your
70
46
  ActiveRecord::Base.extend Dragonfly::ActiveRecordExtensions
71
47
  ActiveRecord::Base.register_dragonfly_app(:image, Dragonfly::App[:images])
72
48
 
73
- # Add the Dragonfly App to the middleware stack
74
- ActionController::Dispatcher.middleware.insert_after ActionController::Failsafe, Dragonfly::Middleware, :images
49
+ ### Insert the middleware ###
50
+ # Where the middleware is depends on the version of Rails
51
+ middleware = Rails.respond_to?(:application) ? Rails.application.middleware : ActionController::Dispatcher.middleware
52
+ middleware.insert_after Rack::Lock, Dragonfly::Middleware, :images
75
53
 
76
- # # UNCOMMENT THIS IF YOU WANT TO CACHE REQUESTS WITH Rack::Cache, and add the line
77
- # # config.gem 'rack-cache', :lib => 'rack/cache'
78
- # # to environment.rb
54
+ # # UNCOMMENT THIS IF YOU WANT TO CACHE REQUESTS WITH Rack::Cache
79
55
  # require 'rack/cache'
80
- # ActionController::Dispatcher.middleware.insert_before Dragonfly::Middleware, Rack::Cache, {
56
+ # middleware.insert_before Dragonfly::Middleware, Rack::Cache, {
81
57
  # :verbose => true,
82
58
  # :metastore => "file:#{Rails.root}/tmp/dragonfly/cache/meta",
83
59
  # :entitystore => "file:#{Rails.root}/tmp/dragonfly/cache/body"
84
60
  # }
85
61
 
62
+ If you can't be bothered to copy and paste, then there's actually a generator for Rails 2.3 (not Rails 3 yet) that will do something like the above for you:
63
+
64
+ ./script/generate dragonfly_app images
65
+
66
+ 2. Gem dependencies
67
+ -------------------
68
+
69
+ Tell Rails about the gem dependencies in the usual way:
70
+
71
+ For Rails 2.3 add this to config/environment.rb:
72
+
73
+ config.gem 'rmagick', :lib => 'RMagick' # only if used
74
+ config.gem 'rack-cache', :lib => 'rack/cache' # only if used
75
+ config.gem 'dragonfly'
76
+
77
+ For Rails 3 add it to the Gemfile, e.g.:
78
+
79
+ gem 'rmagick', :require => 'RMagick' # only if used
80
+ gem 'rack-cache', :require => 'rack/cache' # only if used
81
+ gem 'dragonfly'
82
+
83
+ You only need the lines above for {http://tomayko.com/src/rack-cache/ rack-cache} and
84
+ {http://rmagick.rubyforge.org/ rmagick} if you've used the file 'dragonfly/rails/images', or manually used them yourself.
85
+
86
+ 3. Use it!
87
+ ----------
88
+
89
+ Now that you have a parasitic Dragonfly app living inside your Rails app, you can upload media to your models, display/play around with them, etc.
86
90
 
87
91
  To see what you can do with the active record accessors, see {file:ActiveRecord}.
92
+
93
+ For more info about general Dragonfly setup, including avoiding denial-of-service attacks, see {file:GettingStarted}.
@@ -0,0 +1,14 @@
1
+ Feature: champion uses dragonfly in his Rails 2.3.5 application
2
+ In order to be a champion
3
+ A user uses dragonfly in his Rails 2.3.5 application
4
+
5
+ Background:
6
+ Given a Rails 2.3.5 application set up for using dragonfly
7
+
8
+ Scenario: Set up dragonfly using the generator
9
+ When I use the Rails 2.3.5 generator to set up dragonfly
10
+ Then the cucumber features in my Rails 2.3.5 app should pass
11
+
12
+ Scenario: Set up dragonfly using the provided initializer
13
+ When I use the provided 2.3.5 initializer
14
+ Then the cucumber features in my Rails 2.3.5 app should pass
@@ -0,0 +1,15 @@
1
+ Feature: champion uses dragonfly in his Rails 3.0.0.beta application
2
+ In order to be a champion
3
+ A user uses dragonfly in his Rails 3.0.0.beta application
4
+
5
+ Background:
6
+ Given PENDING: Neither cucumber generators nor Rails templates seem to be working properly yet for Rails 3
7
+ Given a Rails 3.0.0.beta application set up for using dragonfly
8
+
9
+ Scenario: Set up dragonfly using the generator
10
+ When I use the Rails 3.0.0.beta generator to set up dragonfly
11
+ Then the cucumber features in my Rails 3.0.0.beta app should pass
12
+
13
+ Scenario: Set up dragonfly using bundler require
14
+ When I use the provided 3.0.0.beta initializer
15
+ Then the cucumber features in my Rails 3.0.0.beta app should pass
@@ -0,0 +1,38 @@
1
+ RAILS_APP_NAME = 'tmp_app'
2
+ FIXTURES_PATH = File.expand_path(File.dirname(__FILE__) + "/../../fixtures")
3
+
4
+ def fixture_path(version)
5
+ "#{FIXTURES_PATH}/rails_#{version}"
6
+ end
7
+
8
+ def app_path(version)
9
+ "#{fixture_path(version)}/#{RAILS_APP_NAME}"
10
+ end
11
+
12
+ ##############################################################################
13
+
14
+ Given /^a Rails (.+) application set up for using dragonfly$/ do |version|
15
+ raise "Problem setting up Rails app" unless `
16
+ cd #{fixture_path(version)} &&
17
+ rm -rf #{RAILS_APP_NAME} &&
18
+ ../rails _#{version}_ #{RAILS_APP_NAME} -m template.rb`
19
+ end
20
+
21
+ When /^I use the Rails (.+) generator to set up dragonfly$/ do |version|
22
+ raise "Problem using the generator" unless `
23
+ cd #{fixture_path(version)}/#{RAILS_APP_NAME} &&
24
+ ./script/generate dragonfly_app images`
25
+ end
26
+
27
+ When /^I use the provided (.+) initializer$/ do |version|
28
+ FileUtils.cp("#{FIXTURES_PATH}/dragonfly_setup.rb", "#{app_path(version)}/config/initializers")
29
+ end
30
+
31
+ Then /^the cucumber features in my Rails (.+) app should pass$/ do |version|
32
+ puts "\n*** RUNNING FEATURES IN THE RAILS APP... ***\n"
33
+ path = File.join(fixture_path(version), RAILS_APP_NAME)
34
+ `cd #{path} && RAILS_ENV=cucumber rake db:migrate`
35
+ features_passed = system "cd #{path} && cucumber features"
36
+ puts "\n*** FINISHED RUNNING FEATURES IN THE RAILS APP ***\n"
37
+ raise "Features failed" unless features_passed
38
+ end
@@ -0,0 +1 @@
1
+ require 'dragonfly/rails/images'
@@ -0,0 +1,3 @@
1
+ class Album < ActiveRecord::Base
2
+ image_accessor :cover_image
3
+ end
@@ -0,0 +1,4 @@
1
+ <% form_for @album, :html => {:multipart => true} do |f| %>
2
+ <%= f.file_field :cover_image %>
3
+ <%= f.submit 'Create' %>
4
+ <% end %>
@@ -0,0 +1,3 @@
1
+ Look at this cover image!
2
+ <%= image_tag @album.cover_image.url('200x100!') %>
3
+ <%= link_to 'Index', albums_path %>
@@ -0,0 +1,3 @@
1
+ # This is a hack to get the generated rails apps to use the version of dragonfly being worked on.
2
+ $:.unshift(File.expand_path(File.dirname(__FILE__)+'/../../../../../lib'))
3
+
@@ -0,0 +1,12 @@
1
+ Feature: champion adds cover images to his albums
2
+ In order to be a champion
3
+ A user adds an image to his album
4
+
5
+ Scenario: Add and view image
6
+ When I go to the new album page
7
+ And I attach the file "../../../samples/beach.png" to "album[cover_image]"
8
+ And I press "Create"
9
+ Then I should see "successfully created"
10
+ And I should see "Look at this cover image!"
11
+ When I look at the generated beach image
12
+ And I should see a JPEG image of size 200x100
@@ -0,0 +1,14 @@
1
+ When /^I look at the generated (.+) image$/ do |image_name|
2
+ page.body =~ /src="(.+?#{image_name}.+?)"/
3
+ url = $1
4
+ visit(url)
5
+ end
6
+
7
+ Then /^I should see a (.+) image of size (.+)$/ do |format, size|
8
+ tempfile = Tempfile.new('wicked')
9
+ tempfile.write page.body
10
+ tempfile.close
11
+ output = `identify #{tempfile.path}`.split(' ')
12
+ output[1].should == 'JPEG'
13
+ output[2].should == '200x100'
14
+ end
@@ -0,0 +1,13 @@
1
+ module NavigationHelpers
2
+ def path_to(page_name)
3
+ case page_name
4
+ when "the new album page"
5
+ '/albums/new'
6
+ else
7
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
8
+ "Now, go and add a mapping in #{__FILE__}"
9
+ end
10
+ end
11
+ end
12
+
13
+ World(NavigationHelpers)
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ # I'm using this file because at the time of writing, the Rails 3 exec file
3
+ # doesn't allow for running older versions side by side
4
+
5
+ require 'rubygems'
6
+
7
+ version = ">= 0"
8
+
9
+ if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
10
+ version = $1
11
+ ARGV.shift
12
+ end
13
+
14
+ if version =~ /^3|[^.]3/
15
+ # Rails 3...
16
+ gem 'railties', version
17
+ load Gem.bin_path('railties', 'rails', version)
18
+ else
19
+ # ... pre Rails 3
20
+ gem 'rails', version
21
+ load Gem.bin_path('rails', 'rails', version)
22
+ end
@@ -0,0 +1,13 @@
1
+ generate 'scaffold albums cover_image_uid:string'
2
+ rake 'db:migrate'
3
+
4
+ # Set up webrat and cucumber
5
+ gem 'cucumber'
6
+ generate 'cucumber'
7
+
8
+ gem 'rack-cache', :lib => 'rack/cache'
9
+ gem 'rmagick', :lib => 'RMagick'
10
+
11
+ # Copy over all files from the template dir
12
+ files_dir = File.expand_path(File.dirname(__FILE__) + '/../../files')
13
+ run "cp -r #{files_dir}/** ."
@@ -0,0 +1,13 @@
1
+ run "script/rails generate scaffold albums cover_image_uid:string"
2
+ rake 'db:migrate'
3
+
4
+ # Cucumber generator doesn't seem to be working yet...
5
+ # gem 'cucumber'
6
+ # run 'script/rails generate cucumber:skeleton'
7
+ gem 'rack-cache', :require => 'rack/cache'
8
+ run 'echo "" >> Gemfile' # Annoyingly the generators don't insert line-breaks yet
9
+ gem 'rmagick', :require => 'RMagick'
10
+
11
+ # # Copy over all files from the template dir
12
+ files_dir = File.expand_path(File.dirname(__FILE__) + '/../../files')
13
+ run "cp -r #{files_dir}/** ."
@@ -4,7 +4,7 @@ require 'dragonfly'
4
4
  app = Dragonfly::App[:<%= app_name %>]
5
5
  app.configure_with(Dragonfly::RMagickConfiguration)
6
6
  app.configure do |c|
7
- c.log = RAILS_DEFAULT_LOGGER
7
+ c.log = Rails.logger
8
8
  c.datastore.configure do |d|
9
9
  d.root_path = "#{Rails.root}/public/system/dragonfly/#{Rails.env}"
10
10
  end
@@ -10,8 +10,9 @@ module Dragonfly
10
10
  # Defines e.g. 'image_accessor' for any activerecord class body
11
11
  define_method "#{accessor_prefix}_accessor" do |attribute|
12
12
 
13
- before_save :save_attached_files unless before_save_callback_chain.find(:save_attached_files)
14
- before_destroy :destroy_attached_files unless before_destroy_callback_chain.find(:destroy_attached_files)
13
+ # Prior to activerecord 3, adding before callbacks more than once does add it more than once
14
+ before_save :save_attachments unless respond_to?(:before_save_callback_chain) && before_save_callback_chain.find(:save_attachments)
15
+ before_destroy :destroy_attachments unless respond_to?(:before_destroy_callback_chain) && before_destroy_callback_chain.find(:destroy_attachments)
15
16
 
16
17
  # Register the new attribute
17
18
  dragonfly_apps_for_attributes[attribute] = app
@@ -11,13 +11,13 @@ module Dragonfly
11
11
 
12
12
  private
13
13
 
14
- def save_attached_files
14
+ def save_attachments
15
15
  attachments.each do |attribute, attachment|
16
16
  attachment.save!
17
17
  end
18
18
  end
19
19
 
20
- def destroy_attached_files
20
+ def destroy_attachments
21
21
  attachments.each do |attribute, attachment|
22
22
  attachment.destroy!
23
23
  end
@@ -6,7 +6,7 @@ require 'rack/cache'
6
6
  app = Dragonfly::App[:images]
7
7
  app.configure_with(Dragonfly::RMagickConfiguration)
8
8
  app.configure do |c|
9
- c.log = RAILS_DEFAULT_LOGGER
9
+ c.log = Rails.logger
10
10
  c.datastore.configure do |d|
11
11
  d.root_path = "#{Rails.root}/public/system/dragonfly/#{Rails.env}"
12
12
  end
@@ -21,8 +21,10 @@ ActiveRecord::Base.extend Dragonfly::ActiveRecordExtensions
21
21
  ActiveRecord::Base.register_dragonfly_app(:image, app)
22
22
 
23
23
  ### Insert the middleware ###
24
- ActionController::Dispatcher.middleware.insert_after ActionController::Failsafe, Dragonfly::Middleware, :images
25
- ActionController::Dispatcher.middleware.insert_before Dragonfly::Middleware, Rack::Cache, {
24
+ # Where the middleware is depends on the version of Rails
25
+ middleware = Rails.respond_to?(:application) ? Rails.application.middleware : ActionController::Dispatcher.middleware
26
+ middleware.insert_after Rack::Lock, Dragonfly::Middleware, :images
27
+ middleware.insert_before Dragonfly::Middleware, Rack::Cache, {
26
28
  :verbose => true,
27
29
  :metastore => "file:#{Rails.root}/tmp/dragonfly/cache/meta",
28
30
  :entitystore => "file:#{Rails.root}/tmp/dragonfly/cache/body"
@@ -1,5 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
+ require 'ginger'
3
4
  require 'active_record'
4
5
 
5
6
  DB_FILE = File.expand_path(File.dirname(__FILE__)+'/db.sqlite3')
@@ -0,0 +1,13 @@
1
+ require 'ginger'
2
+
3
+ Ginger.configure do |config|
4
+ config.aliases["active_record"] = "activerecord" # Because the gem name is 'activerecord', but the require is 'active_record'
5
+
6
+ activerecord_2_3_5 = Ginger::Scenario.new("ActiveRecord 2.3.5")
7
+ activerecord_2_3_5[/^active_?record$/] = "2.3.5"
8
+
9
+ activerecord_3_0_0 = Ginger::Scenario.new("ActiveRecord 3.0.0 beta")
10
+ activerecord_3_0_0[/^active_?record$/] = "3.0.0.beta"
11
+
12
+ config.scenarios << activerecord_2_3_5 << activerecord_3_0_0
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dragonfly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Evans
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-16 00:00:00 +00:00
12
+ date: 2010-02-20 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -82,6 +82,16 @@ dependencies:
82
82
  - !ruby/object:Gem::Version
83
83
  version: "0"
84
84
  version:
85
+ - !ruby/object:Gem::Dependency
86
+ name: cucumber-rails
87
+ type: :development
88
+ version_requirement:
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ version:
85
95
  - !ruby/object:Gem::Dependency
86
96
  name: activerecord
87
97
  type: :development
@@ -102,6 +112,16 @@ dependencies:
102
112
  - !ruby/object:Gem::Version
103
113
  version: "0"
104
114
  version:
115
+ - !ruby/object:Gem::Dependency
116
+ name: ginger
117
+ type: :development
118
+ version_requirement:
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: "0"
124
+ version:
105
125
  description:
106
126
  email: mark@new-bamboo.co.uk
107
127
  executables: []
@@ -135,9 +155,23 @@ files:
135
155
  - extra_docs/UsingWithRails.md
136
156
  - features/images.feature
137
157
  - features/no_processing.feature
158
+ - features/rails_2.3.5.feature
159
+ - features/rails_3.0.0.beta.feature
138
160
  - features/steps/common_steps.rb
139
161
  - features/steps/dragonfly_steps.rb
162
+ - features/steps/rails_steps.rb
140
163
  - features/support/env.rb
164
+ - fixtures/dragonfly_setup.rb
165
+ - fixtures/files/app/models/album.rb
166
+ - fixtures/files/app/views/albums/new.html.erb
167
+ - fixtures/files/app/views/albums/show.html.erb
168
+ - fixtures/files/config/initializers/aaa_dragonfly_load_path.rb
169
+ - fixtures/files/features/manage_album_images.feature
170
+ - fixtures/files/features/step_definitions/album_steps.rb
171
+ - fixtures/files/features/support/paths.rb
172
+ - fixtures/rails
173
+ - fixtures/rails_2.3.5/template.rb
174
+ - fixtures/rails_3.0.0.beta/template.rb
141
175
  - generators/dragonfly_app/USAGE
142
176
  - generators/dragonfly_app/dragonfly_app_generator.rb
143
177
  - generators/dragonfly_app/templates/initializer.erb
@@ -211,6 +245,7 @@ files:
211
245
  - spec/dragonfly/temp_object_spec.rb
212
246
  - spec/dragonfly/url_handler_spec.rb
213
247
  - spec/dragonfly_spec.rb
248
+ - spec/ginger_scenarios.rb
214
249
  - spec/image_matchers.rb
215
250
  - spec/simple_matchers.rb
216
251
  - spec/spec_helper.rb
@@ -275,6 +310,7 @@ test_files:
275
310
  - spec/dragonfly/temp_object_spec.rb
276
311
  - spec/dragonfly/url_handler_spec.rb
277
312
  - spec/dragonfly_spec.rb
313
+ - spec/ginger_scenarios.rb
278
314
  - spec/image_matchers.rb
279
315
  - spec/simple_matchers.rb
280
316
  - spec/spec_helper.rb