paperclip-v2_7-patched-ruby-1_8_6 2.7.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.travis.yml +14 -0
  4. data/Appraisals +20 -0
  5. data/CONTRIBUTING.md +38 -0
  6. data/Gemfile +5 -0
  7. data/LICENSE +26 -0
  8. data/NEWS +69 -0
  9. data/README.md +444 -0
  10. data/Rakefile +41 -0
  11. data/cucumber/paperclip_steps.rb +6 -0
  12. data/features/basic_integration.feature +48 -0
  13. data/features/rake_tasks.feature +68 -0
  14. data/features/step_definitions/attachment_steps.rb +65 -0
  15. data/features/step_definitions/html_steps.rb +15 -0
  16. data/features/step_definitions/rails_steps.rb +193 -0
  17. data/features/step_definitions/s3_steps.rb +14 -0
  18. data/features/step_definitions/web_steps.rb +209 -0
  19. data/features/support/env.rb +8 -0
  20. data/features/support/fakeweb.rb +3 -0
  21. data/features/support/fixtures/.boot_config.rb.swo +0 -0
  22. data/features/support/fixtures/boot_config.txt +15 -0
  23. data/features/support/fixtures/gemfile.txt +5 -0
  24. data/features/support/fixtures/preinitializer.txt +20 -0
  25. data/features/support/paths.rb +28 -0
  26. data/features/support/rails.rb +46 -0
  27. data/features/support/selectors.rb +19 -0
  28. data/gemfiles/rails2.gemfile +9 -0
  29. data/gemfiles/rails3.gemfile +9 -0
  30. data/gemfiles/rails3_1.gemfile +9 -0
  31. data/gemfiles/rails3_2.gemfile +9 -0
  32. data/generators/paperclip/USAGE +5 -0
  33. data/generators/paperclip/paperclip_generator.rb +27 -0
  34. data/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
  35. data/init.rb +4 -0
  36. data/lib/generators/paperclip/USAGE +8 -0
  37. data/lib/generators/paperclip/paperclip_generator.rb +33 -0
  38. data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
  39. data/lib/paperclip.rb +493 -0
  40. data/lib/paperclip/attachment.rb +491 -0
  41. data/lib/paperclip/attachment_options.rb +10 -0
  42. data/lib/paperclip/callback_compatibility.rb +61 -0
  43. data/lib/paperclip/geometry.rb +120 -0
  44. data/lib/paperclip/interpolations.rb +174 -0
  45. data/lib/paperclip/iostream.rb +45 -0
  46. data/lib/paperclip/matchers.rb +64 -0
  47. data/lib/paperclip/matchers/have_attached_file_matcher.rb +57 -0
  48. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +81 -0
  49. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +54 -0
  50. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +95 -0
  51. data/lib/paperclip/missing_attachment_styles.rb +87 -0
  52. data/lib/paperclip/processor.rb +58 -0
  53. data/lib/paperclip/railtie.rb +35 -0
  54. data/lib/paperclip/schema.rb +39 -0
  55. data/lib/paperclip/storage.rb +3 -0
  56. data/lib/paperclip/storage/filesystem.rb +81 -0
  57. data/lib/paperclip/storage/fog.rb +191 -0
  58. data/lib/paperclip/storage/s3.rb +351 -0
  59. data/lib/paperclip/style.rb +103 -0
  60. data/lib/paperclip/thumbnail.rb +105 -0
  61. data/lib/paperclip/upfile.rb +64 -0
  62. data/lib/paperclip/url_generator.rb +64 -0
  63. data/lib/paperclip/version.rb +3 -0
  64. data/lib/tasks/paperclip.rake +101 -0
  65. data/paperclip.gemspec +41 -0
  66. data/rails/init.rb +2 -0
  67. data/shoulda_macros/paperclip.rb +124 -0
  68. data/test/attachment_options_test.rb +40 -0
  69. data/test/attachment_test.rb +1211 -0
  70. data/test/database.yml +4 -0
  71. data/test/fixtures/12k.png +0 -0
  72. data/test/fixtures/50x50.png +0 -0
  73. data/test/fixtures/5k.png +0 -0
  74. data/test/fixtures/animated.gif +0 -0
  75. data/test/fixtures/bad.png +1 -0
  76. data/test/fixtures/fog.yml +8 -0
  77. data/test/fixtures/s3.yml +8 -0
  78. data/test/fixtures/spaced file.png +0 -0
  79. data/test/fixtures/text.txt +1 -0
  80. data/test/fixtures/twopage.pdf +0 -0
  81. data/test/fixtures/uppercase.PNG +0 -0
  82. data/test/geometry_test.rb +206 -0
  83. data/test/helper.rb +181 -0
  84. data/test/integration_test.rb +652 -0
  85. data/test/interpolations_test.rb +219 -0
  86. data/test/iostream_test.rb +71 -0
  87. data/test/matchers/have_attached_file_matcher_test.rb +24 -0
  88. data/test/matchers/validate_attachment_content_type_matcher_test.rb +110 -0
  89. data/test/matchers/validate_attachment_presence_matcher_test.rb +47 -0
  90. data/test/matchers/validate_attachment_size_matcher_test.rb +72 -0
  91. data/test/paperclip_missing_attachment_styles_test.rb +96 -0
  92. data/test/paperclip_test.rb +409 -0
  93. data/test/processor_test.rb +10 -0
  94. data/test/schema_test.rb +98 -0
  95. data/test/storage/filesystem_test.rb +62 -0
  96. data/test/storage/fog_test.rb +280 -0
  97. data/test/storage/s3_live_test.rb +138 -0
  98. data/test/storage/s3_test.rb +1093 -0
  99. data/test/style_test.rb +215 -0
  100. data/test/support/mock_attachment.rb +22 -0
  101. data/test/support/mock_interpolator.rb +24 -0
  102. data/test/support/mock_model.rb +2 -0
  103. data/test/support/mock_url_generator_builder.rb +27 -0
  104. data/test/thumbnail_test.rb +396 -0
  105. data/test/upfile_test.rb +53 -0
  106. data/test/url_generator_test.rb +187 -0
  107. metadata +374 -0
@@ -0,0 +1,41 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'appraisal'
3
+ require 'rake/testtask'
4
+ require 'cucumber/rake/task'
5
+
6
+ desc 'Default: run unit tests.'
7
+ task :default => [:clean, 'appraisal:install', :all]
8
+
9
+ desc 'Test the paperclip plugin under all supported Rails versions.'
10
+ task :all do |t|
11
+ exec('rake appraisal test cucumber')
12
+ end
13
+
14
+ desc 'Test the paperclip plugin.'
15
+ Rake::TestTask.new(:test) do |t|
16
+ t.libs << 'lib' << 'profile'
17
+ t.pattern = 'test/**/*_test.rb'
18
+ t.verbose = true
19
+ end
20
+
21
+ desc 'Run integration test'
22
+ Cucumber::Rake::Task.new do |t|
23
+ t.cucumber_opts = %w{--format progress}
24
+ end
25
+
26
+ desc 'Start an IRB session with all necessary files required.'
27
+ task :shell do |t|
28
+ chdir File.dirname(__FILE__)
29
+ exec 'irb -I lib/ -I lib/paperclip -r rubygems -r active_record -r tempfile -r init'
30
+ end
31
+
32
+ desc 'Clean up files.'
33
+ task :clean do |t|
34
+ FileUtils.rm_rf "doc"
35
+ FileUtils.rm_rf "tmp"
36
+ FileUtils.rm_rf "pkg"
37
+ FileUtils.rm_rf "public"
38
+ FileUtils.rm "test/debug.log" rescue nil
39
+ FileUtils.rm "test/paperclip.db" rescue nil
40
+ Dir.glob("paperclip-*.gem").each{|f| FileUtils.rm f }
41
+ end
@@ -0,0 +1,6 @@
1
+ When /^I attach an? "([^\"]*)" "([^\"]*)" file to an? "([^\"]*)" on S3$/ do |attachment, extension, model|
2
+ stub_paperclip_s3(model, attachment, extension)
3
+ attach_file attachment,
4
+ "features/support/paperclip/#{model.gsub(" ", "_").underscore}/#{attachment}.#{extension}"
5
+ end
6
+
@@ -0,0 +1,48 @@
1
+ Feature: Rails integration
2
+
3
+ Background:
4
+ Given I generate a new rails application
5
+ And I run a rails generator to generate a "User" scaffold with "name:string"
6
+ And I run a paperclip generator to add a paperclip "attachment" to the "User" model
7
+ And I run a migration
8
+ And I update my new user view to include the file upload field
9
+ And I update my user view to include the attachment
10
+
11
+ Scenario: Filesystem integration test
12
+ Given I add this snippet to the User model:
13
+ """
14
+ has_attached_file :attachment
15
+ """
16
+ And I add attr_accessible to a Rails 3.2 application
17
+ And I start the rails application
18
+ When I go to the new user page
19
+ And I fill in "Name" with "something"
20
+ And I attach the file "test/fixtures/5k.png" to "Attachment"
21
+ And I press "Submit"
22
+ Then I should see "Name: something"
23
+ And I should see an image with a path of "/system/attachments/1/original/5k.png"
24
+ And the file at "/system/attachments/1/original/5k.png" should be the same as "test/fixtures/5k.png"
25
+
26
+ Scenario: S3 Integration test
27
+ Given I add this snippet to the User model:
28
+ """
29
+ has_attached_file :attachment,
30
+ :storage => :s3,
31
+ :path => "/:attachment/:id/:style/:filename",
32
+ :s3_credentials => Rails.root.join("config/s3.yml")
33
+ """
34
+ And I add attr_accessible to a Rails 3.2 application
35
+ And I write to "config/s3.yml" with:
36
+ """
37
+ bucket: paperclip
38
+ access_key_id: access_key
39
+ secret_access_key: secret_key
40
+ """
41
+ And I start the rails application
42
+ When I go to the new user page
43
+ And I fill in "Name" with "something"
44
+ And I attach the file "test/fixtures/5k.png" to "Attachment" on S3
45
+ And I press "Submit"
46
+ Then I should see "Name: something"
47
+ And I should see an image with a path of "http://s3.amazonaws.com/paperclip/attachments/1/original/5k.png"
48
+ And the file at "http://s3.amazonaws.com/paperclip/attachments/1/original/5k.png" should be uploaded to S3
@@ -0,0 +1,68 @@
1
+ Feature: Rake tasks
2
+
3
+ Background:
4
+ Given I generate a new rails application
5
+ And I run a rails generator to generate a "User" scaffold with "name:string"
6
+ And I run a paperclip generator to add a paperclip "attachment" to the "User" model
7
+ And I run a migration
8
+ And I add the paperclip rake task to a Rails 2.3 application
9
+ And I add attr_accessible to a Rails 3.2 application
10
+ And I add this snippet to the User model:
11
+ """
12
+ has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename"
13
+ """
14
+
15
+ Scenario: Paperclip refresh thumbnails task
16
+ When I modify my attachment definition to:
17
+ """
18
+ has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename",
19
+ :styles => { :medium => "200x200#" }
20
+ """
21
+ And I add attr_accessible to a Rails 3.2 application
22
+ And I upload the fixture "5k.png"
23
+ Then the attachment "medium/5k.png" should have a dimension of 200x200
24
+ When I modify my attachment definition to:
25
+ """
26
+ has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename",
27
+ :styles => { :medium => "100x100#" }
28
+ """
29
+ And I add attr_accessible to a Rails 3.2 application
30
+ When I successfully run `bundle exec rake paperclip:refresh:thumbnails CLASS=User --trace`
31
+ Then the attachment "original/5k.png" should exist
32
+ And the attachment "medium/5k.png" should have a dimension of 100x100
33
+
34
+ Scenario: Paperclip refresh metadata task
35
+ When I upload the fixture "5k.png"
36
+ And I swap the attachment "original/5k.png" with the fixture "12k.png"
37
+ And I successfully run `bundle exec rake paperclip:refresh:metadata CLASS=User --trace`
38
+ Then the attachment should have the same content type as the fixture "12k.png"
39
+ And the attachment should have the same file size as the fixture "12k.png"
40
+
41
+ Scenario: Paperclip refresh missing styles task
42
+ When I upload the fixture "5k.png"
43
+ Then the attachment file "original/5k.png" should exist
44
+ And the attachment file "medium/5k.png" should not exist
45
+ When I modify my attachment definition to:
46
+ """
47
+ has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename",
48
+ :styles => { :medium => "200x200#" }
49
+ """
50
+ And I add attr_accessible to a Rails 3.2 application
51
+ When I successfully run `bundle exec rake paperclip:refresh:missing_styles --trace`
52
+ Then the attachment file "original/5k.png" should exist
53
+ And the attachment file "medium/5k.png" should exist
54
+
55
+ Scenario: Paperclip clean task
56
+ When I upload the fixture "5k.png"
57
+ And I upload the fixture "12k.png"
58
+ Then the attachment file "original/5k.png" should exist
59
+ And the attachment file "original/12k.png" should exist
60
+ When I modify my attachment definition to:
61
+ """
62
+ has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename"
63
+ validates_attachment_size :attachment, :less_than => 10.kilobytes
64
+ """
65
+ And I add attr_accessible to a Rails 3.2 application
66
+ And I successfully run `bundle exec rake paperclip:clean CLASS=User --trace`
67
+ Then the attachment file "original/5k.png" should exist
68
+ But the attachment file "original/12k.png" should not exist
@@ -0,0 +1,65 @@
1
+ module AttachmentHelpers
2
+ def fixture_path(filename)
3
+ File.expand_path("#{PROJECT_ROOT}/test/fixtures/#{filename}")
4
+ end
5
+
6
+ def attachment_path(filename)
7
+ File.expand_path("public/system/attachments/#{filename}")
8
+ end
9
+ end
10
+ World(AttachmentHelpers)
11
+
12
+ When /^I modify my attachment definition to:$/ do |definition|
13
+ write_file "app/models/user.rb", <<-FILE
14
+ class User < ActiveRecord::Base
15
+ #{definition}
16
+ end
17
+ FILE
18
+ in_current_dir { FileUtils.rm_rf ".rbx" }
19
+ end
20
+
21
+ When /^I upload the fixture "([^"]*)"$/ do |filename|
22
+ run_simple %(bundle exec #{runner_command} "User.create!(:attachment => File.open('#{fixture_path(filename)}'))")
23
+ end
24
+
25
+ Then /^the attachment "([^"]*)" should have a dimension of (\d+x\d+)$/ do |filename, dimension|
26
+ in_current_dir do
27
+ geometry = `identify -format "%wx%h" "#{attachment_path(filename)}"`.strip
28
+ geometry.should == dimension
29
+ end
30
+ end
31
+
32
+ Then /^the attachment "([^"]*)" should exist$/ do |filename|
33
+ in_current_dir do
34
+ File.exists?(attachment_path(filename)).should be
35
+ end
36
+ end
37
+
38
+ When /^I swap the attachment "([^"]*)" with the fixture "([^"]*)"$/ do |attachment_filename, fixture_filename|
39
+ in_current_dir do
40
+ require 'fileutils'
41
+ FileUtils.rm_f attachment_path(attachment_filename)
42
+ FileUtils.cp fixture_path(fixture_filename), attachment_path(attachment_filename)
43
+ end
44
+ end
45
+
46
+ Then /^the attachment should have the same content type as the fixture "([^"]*)"$/ do |filename|
47
+ in_current_dir do
48
+ require 'mime/types'
49
+ attachment_content_type = `bundle exec #{runner_command} "puts User.last.attachment_content_type"`.strip
50
+ attachment_content_type.should == MIME::Types.type_for(filename).first.content_type
51
+ end
52
+ end
53
+
54
+ Then /^the attachment should have the same file size as the fixture "([^"]*)"$/ do |filename|
55
+ in_current_dir do
56
+ attachment_file_size = `bundle exec #{runner_command} "puts User.last.attachment_file_size"`.strip
57
+ attachment_file_size.should == File.size(fixture_path(filename)).to_s
58
+ end
59
+ end
60
+
61
+ Then /^the attachment file "([^"]*)" should (not )?exist$/ do |filename, not_exist|
62
+ in_current_dir do
63
+ check_file_presence([attachment_path(filename)], !not_exist)
64
+ end
65
+ end
@@ -0,0 +1,15 @@
1
+ Then %r{I should see an image with a path of "([^"]*)"} do |path|
2
+ page.should have_css("img[src^='#{path}']")
3
+ end
4
+
5
+ Then %r{^the file at "([^"]*)" is the same as "([^"]*)"$} do |web_file, path|
6
+ expected = IO.read(path)
7
+ actual = if web_file.match %r{^https?://}
8
+ Net::HTTP.get(URI.parse(web_file))
9
+ else
10
+ visit(web_file)
11
+ page.body
12
+ end
13
+ actual.force_encoding("UTF-8") if actual.respond_to?(:force_encoding)
14
+ actual.should == expected
15
+ end
@@ -0,0 +1,193 @@
1
+ Given /^I generate a new rails application$/ do
2
+ steps %{
3
+ When I run `bundle exec #{new_application_command} #{APP_NAME}`
4
+ And I cd to "#{APP_NAME}"
5
+ And I turn off class caching
6
+ And I write to "Gemfile" with:
7
+ """
8
+ source "http://rubygems.org"
9
+ gem "rails", "#{framework_version}"
10
+ gem "sqlite3"
11
+ gem "capybara"
12
+ gem "gherkin"
13
+ gem "aws-sdk"
14
+ gem "rake", "0.9.2"
15
+ """
16
+ And I configure the application to use "paperclip" from this project
17
+ And I reset Bundler environment variable
18
+ And I successfully run `bundle install --local`
19
+ }
20
+ end
21
+
22
+ Given /^I run a rails generator to generate a "([^"]*)" scaffold with "([^"]*)"$/ do |model_name, attributes|
23
+ step %[I successfully run `bundle exec #{generator_command} scaffold #{model_name} #{attributes}`]
24
+ end
25
+
26
+ Given /^I run a paperclip generator to add a paperclip "([^"]*)" to the "([^"]*)" model$/ do |attachment_name, model_name|
27
+ step %[I successfully run `bundle exec #{generator_command} paperclip #{model_name} #{attachment_name}`]
28
+ end
29
+
30
+ Given /^I run a migration$/ do
31
+ step %[I successfully run `bundle exec rake db:migrate`]
32
+ end
33
+
34
+ Given /^I update my new user view to include the file upload field$/ do
35
+ if framework_version?("3")
36
+ steps %{
37
+ Given I overwrite "app/views/users/new.html.erb" with:
38
+ """
39
+ <%= form_for @user, :html => { :multipart => true } do |f| %>
40
+ <%= f.label :name %>
41
+ <%= f.text_field :name %>
42
+ <%= f.label :attachment %>
43
+ <%= f.file_field :attachment %>
44
+ <%= submit_tag "Submit" %>
45
+ <% end %>
46
+ """
47
+ }
48
+ else
49
+ steps %{
50
+ Given I overwrite "app/views/users/new.html.erb" with:
51
+ """
52
+ <% form_for @user, :html => { :multipart => true } do |f| %>
53
+ <%= f.label :name %>
54
+ <%= f.text_field :name %>
55
+ <%= f.label :attachment %>
56
+ <%= f.file_field :attachment %>
57
+ <%= submit_tag "Submit" %>
58
+ <% end %>
59
+ """
60
+ }
61
+ end
62
+ end
63
+
64
+ Given /^I update my user view to include the attachment$/ do
65
+ steps %{
66
+ Given I overwrite "app/views/users/show.html.erb" with:
67
+ """
68
+ <p>Name: <%= @user.name %></p>
69
+ <p>Attachment: <%= image_tag @user.attachment.url %></p>
70
+ """
71
+ }
72
+ end
73
+
74
+ Given /^I add this snippet to the User model:$/ do |snippet|
75
+ insert_snippet_into_file("app/models/user.rb", snippet)
76
+ end
77
+
78
+ Given /^I start the rails application$/ do
79
+ in_current_dir do
80
+ require "./config/environment"
81
+ require "capybara/rails"
82
+ end
83
+ end
84
+
85
+ Given /^I reload my application$/ do
86
+ Rails::Application.reload!
87
+ end
88
+
89
+ When %r{I turn off class caching} do
90
+ in_current_dir do
91
+ file = "config/environments/test.rb"
92
+ config = IO.read(file)
93
+ config.gsub!(%r{^\s*config.cache_classes.*$},
94
+ "config.cache_classes = false")
95
+ File.open(file, "w"){|f| f.write(config) }
96
+ end
97
+ end
98
+
99
+ Given /^I update my application to use Bundler$/ do
100
+ if framework_version?("2")
101
+ boot_config_template = File.read('features/support/fixtures/boot_config.txt')
102
+ preinitializer_template = File.read('features/support/fixtures/preinitializer.txt')
103
+ gemfile_template = File.read('features/support/fixtures/gemfile.txt')
104
+ in_current_dir do
105
+ content = File.read("config/boot.rb").sub(/Rails\.boot!/, boot_config_template)
106
+ File.open("config/boot.rb", "w") { |file| file.write(content) }
107
+ File.open("config/preinitializer.rb", "w") { |file| file.write(preinitializer_template) }
108
+ File.open("Gemfile", "w") { |file| file.write(gemfile_template.sub(/RAILS_VERSION/, framework_version)) }
109
+ end
110
+ end
111
+ end
112
+
113
+ Given /^I add attr_accessible to a Rails 3.2 application$/ do
114
+ if framework_version?("3.2")
115
+ insert_snippet_into_file("app/models/user.rb", "attr_accessible :attachment\n")
116
+ end
117
+ end
118
+
119
+ Given /^I add the paperclip rake task to a Rails 2.3 application$/ do
120
+ if framework_version?("2.3")
121
+ require 'fileutils'
122
+ source = File.expand_path('lib/tasks/paperclip.rake')
123
+ destination = in_current_dir { File.expand_path("lib/tasks") }
124
+ FileUtils.cp source, destination
125
+ append_to "Rakefile", "require 'paperclip'"
126
+ end
127
+ end
128
+
129
+ Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path|
130
+ expected = IO.read(path)
131
+ actual = if web_file.match %r{^https?://}
132
+ Net::HTTP.get(URI.parse(web_file))
133
+ else
134
+ visit(web_file)
135
+ page.source
136
+ end
137
+ actual.force_encoding("UTF-8") if actual.respond_to?(:force_encoding)
138
+ actual.should == expected
139
+ end
140
+
141
+ When /^I configure the application to use "([^\"]+)" from this project$/ do |name|
142
+ append_to_gemfile "gem '#{name}', :path => '#{PROJECT_ROOT}'"
143
+ steps %{And I run `bundle install --local`}
144
+ end
145
+
146
+ When /^I configure the application to use "([^\"]+)"$/ do |gem_name|
147
+ append_to_gemfile "gem '#{gem_name}'"
148
+ end
149
+
150
+ When /^I append gems from Appraisal Gemfile$/ do
151
+ File.read(ENV['BUNDLE_GEMFILE']).split(/\n/).each do |line|
152
+ if line =~ /^gem "(?!rails|appraisal)/
153
+ append_to_gemfile line.strip
154
+ end
155
+ end
156
+ end
157
+
158
+ When /^I comment out the gem "([^"]*)" from the Gemfile$/ do |gemname|
159
+ comment_out_gem_in_gemfile gemname
160
+ end
161
+
162
+ module FileHelpers
163
+ def insert_snippet_into_file(file_name, snippet)
164
+ in_current_dir do
165
+ content = File.read(file_name)
166
+ File.open(file_name, 'w') { |f| f << content.sub(/end\Z/, "#{snippet}\nend") }
167
+ content = File.read(file_name)
168
+ end
169
+ end
170
+
171
+ def append_to(path, contents)
172
+ in_current_dir do
173
+ File.open(path, "a") do |file|
174
+ file.puts
175
+ file.puts contents
176
+ end
177
+ end
178
+ end
179
+
180
+ def append_to_gemfile(contents)
181
+ append_to('Gemfile', contents)
182
+ end
183
+
184
+ def comment_out_gem_in_gemfile(gemname)
185
+ in_current_dir do
186
+ gemfile = File.read("Gemfile")
187
+ gemfile.sub!(/^(\s*)(gem\s*['"]#{gemname})/, "\\1# \\2")
188
+ File.open("Gemfile", 'w'){ |file| file.write(gemfile) }
189
+ end
190
+ end
191
+ end
192
+
193
+ World(FileHelpers)
@@ -0,0 +1,14 @@
1
+ When /^I attach the file "([^"]*)" to "([^"]*)" on S3$/ do |file_path, field|
2
+ definition = User.attachment_definitions[field.downcase.to_sym]
3
+ path = "https://paperclip.s3.amazonaws.com#{definition[:path]}"
4
+ path.gsub!(':filename', File.basename(file_path))
5
+ path.gsub!(/:([^\/\.]+)/) do |match|
6
+ "([^\/\.]+)"
7
+ end
8
+ FakeWeb.register_uri(:put, Regexp.new(path), :body => "OK")
9
+ step "I attach the file \"#{file_path}\" to \"#{field}\""
10
+ end
11
+
12
+ Then /^the file at "([^"]*)" should be uploaded to S3$/ do |url|
13
+ FakeWeb.registered_uri?(:put, url)
14
+ end