cloudfuji_paperclip 2.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. data/.gitignore +22 -0
  2. data/.travis.yml +13 -0
  3. data/Appraisals +14 -0
  4. data/CONTRIBUTING.md +38 -0
  5. data/Gemfile +5 -0
  6. data/Gemfile.lock +137 -0
  7. data/LICENSE +26 -0
  8. data/README.md +444 -0
  9. data/Rakefile +41 -0
  10. data/cucumber/paperclip_steps.rb +6 -0
  11. data/features/basic_integration.feature +46 -0
  12. data/features/rake_tasks.feature +63 -0
  13. data/features/step_definitions/attachment_steps.rb +65 -0
  14. data/features/step_definitions/html_steps.rb +15 -0
  15. data/features/step_definitions/rails_steps.rb +182 -0
  16. data/features/step_definitions/s3_steps.rb +14 -0
  17. data/features/step_definitions/web_steps.rb +209 -0
  18. data/features/support/env.rb +8 -0
  19. data/features/support/fakeweb.rb +3 -0
  20. data/features/support/fixtures/.boot_config.rb.swo +0 -0
  21. data/features/support/fixtures/boot_config.txt +15 -0
  22. data/features/support/fixtures/gemfile.txt +5 -0
  23. data/features/support/fixtures/preinitializer.txt +20 -0
  24. data/features/support/paths.rb +28 -0
  25. data/features/support/rails.rb +46 -0
  26. data/features/support/selectors.rb +19 -0
  27. data/gemfiles/rails2.gemfile +9 -0
  28. data/gemfiles/rails3.gemfile +9 -0
  29. data/gemfiles/rails3_1.gemfile +9 -0
  30. data/generators/paperclip/USAGE +5 -0
  31. data/generators/paperclip/paperclip_generator.rb +27 -0
  32. data/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
  33. data/init.rb +4 -0
  34. data/lib/generators/paperclip/USAGE +8 -0
  35. data/lib/generators/paperclip/paperclip_generator.rb +33 -0
  36. data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
  37. data/lib/paperclip/attachment.rb +468 -0
  38. data/lib/paperclip/callback_compatibility.rb +61 -0
  39. data/lib/paperclip/geometry.rb +120 -0
  40. data/lib/paperclip/interpolations.rb +174 -0
  41. data/lib/paperclip/iostream.rb +45 -0
  42. data/lib/paperclip/matchers/have_attached_file_matcher.rb +57 -0
  43. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +81 -0
  44. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +54 -0
  45. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +95 -0
  46. data/lib/paperclip/matchers.rb +64 -0
  47. data/lib/paperclip/missing_attachment_styles.rb +87 -0
  48. data/lib/paperclip/processor.rb +58 -0
  49. data/lib/paperclip/railtie.rb +31 -0
  50. data/lib/paperclip/schema.rb +39 -0
  51. data/lib/paperclip/storage/filesystem.rb +81 -0
  52. data/lib/paperclip/storage/fog.rb +174 -0
  53. data/lib/paperclip/storage/s3.rb +333 -0
  54. data/lib/paperclip/storage.rb +3 -0
  55. data/lib/paperclip/style.rb +103 -0
  56. data/lib/paperclip/thumbnail.rb +105 -0
  57. data/lib/paperclip/upfile.rb +62 -0
  58. data/lib/paperclip/url_generator.rb +64 -0
  59. data/lib/paperclip/version.rb +3 -0
  60. data/lib/paperclip.rb +487 -0
  61. data/lib/tasks/paperclip.rake +101 -0
  62. data/paperclip.gemspec +41 -0
  63. data/rails/init.rb +2 -0
  64. data/shoulda_macros/paperclip.rb +124 -0
  65. data/test/.gitignore +1 -0
  66. data/test/attachment_test.rb +1116 -0
  67. data/test/database.yml +4 -0
  68. data/test/fixtures/12k.png +0 -0
  69. data/test/fixtures/50x50.png +0 -0
  70. data/test/fixtures/5k.png +0 -0
  71. data/test/fixtures/animated.gif +0 -0
  72. data/test/fixtures/bad.png +1 -0
  73. data/test/fixtures/fog.yml +8 -0
  74. data/test/fixtures/question?mark.png +0 -0
  75. data/test/fixtures/s3.yml +8 -0
  76. data/test/fixtures/spaced file.png +0 -0
  77. data/test/fixtures/text.txt +1 -0
  78. data/test/fixtures/twopage.pdf +0 -0
  79. data/test/fixtures/uppercase.PNG +0 -0
  80. data/test/geometry_test.rb +206 -0
  81. data/test/helper.rb +177 -0
  82. data/test/integration_test.rb +654 -0
  83. data/test/interpolations_test.rb +216 -0
  84. data/test/iostream_test.rb +71 -0
  85. data/test/matchers/have_attached_file_matcher_test.rb +24 -0
  86. data/test/matchers/validate_attachment_content_type_matcher_test.rb +87 -0
  87. data/test/matchers/validate_attachment_presence_matcher_test.rb +26 -0
  88. data/test/matchers/validate_attachment_size_matcher_test.rb +51 -0
  89. data/test/paperclip_missing_attachment_styles_test.rb +80 -0
  90. data/test/paperclip_test.rb +390 -0
  91. data/test/processor_test.rb +10 -0
  92. data/test/schema_test.rb +98 -0
  93. data/test/storage/filesystem_test.rb +56 -0
  94. data/test/storage/fog_test.rb +219 -0
  95. data/test/storage/s3_live_test.rb +138 -0
  96. data/test/storage/s3_test.rb +943 -0
  97. data/test/style_test.rb +209 -0
  98. data/test/support/mock_attachment.rb +22 -0
  99. data/test/support/mock_interpolator.rb +24 -0
  100. data/test/support/mock_model.rb +2 -0
  101. data/test/support/mock_url_generator_builder.rb +27 -0
  102. data/test/thumbnail_test.rb +383 -0
  103. data/test/upfile_test.rb +53 -0
  104. data/test/url_generator_test.rb +187 -0
  105. metadata +404 -0
@@ -0,0 +1,182 @@
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
+ """
15
+ And I configure the application to use "paperclip" from this project
16
+ And I reset Bundler environment variable
17
+ And I successfully run `bundle install --local`
18
+ }
19
+ end
20
+
21
+ Given /^I run a rails generator to generate a "([^"]*)" scaffold with "([^"]*)"$/ do |model_name, attributes|
22
+ step %[I successfully run `bundle exec #{generator_command} scaffold #{model_name} #{attributes}`]
23
+ end
24
+
25
+ Given /^I run a paperclip generator to add a paperclip "([^"]*)" to the "([^"]*)" model$/ do |attachment_name, model_name|
26
+ step %[I successfully run `bundle exec #{generator_command} paperclip #{model_name} #{attachment_name}`]
27
+ end
28
+
29
+ Given /^I run a migration$/ do
30
+ step %[I successfully run `bundle exec rake db:migrate`]
31
+ end
32
+
33
+ Given /^I update my new user view to include the file upload field$/ do
34
+ if framework_version?("3")
35
+ steps %{
36
+ Given I overwrite "app/views/users/new.html.erb" with:
37
+ """
38
+ <%= form_for @user, :html => { :multipart => true } do |f| %>
39
+ <%= f.label :name %>
40
+ <%= f.text_field :name %>
41
+ <%= f.label :attachment %>
42
+ <%= f.file_field :attachment %>
43
+ <%= submit_tag "Submit" %>
44
+ <% end %>
45
+ """
46
+ }
47
+ else
48
+ steps %{
49
+ Given I overwrite "app/views/users/new.html.erb" with:
50
+ """
51
+ <% form_for @user, :html => { :multipart => true } do |f| %>
52
+ <%= f.label :name %>
53
+ <%= f.text_field :name %>
54
+ <%= f.label :attachment %>
55
+ <%= f.file_field :attachment %>
56
+ <%= submit_tag "Submit" %>
57
+ <% end %>
58
+ """
59
+ }
60
+ end
61
+ end
62
+
63
+ Given /^I update my user view to include the attachment$/ do
64
+ steps %{
65
+ Given I overwrite "app/views/users/show.html.erb" with:
66
+ """
67
+ <p>Name: <%= @user.name %></p>
68
+ <p>Attachment: <%= image_tag @user.attachment.url %></p>
69
+ """
70
+ }
71
+ end
72
+
73
+ Given /^I add this snippet to the User model:$/ do |snippet|
74
+ file_name = "app/models/user.rb"
75
+ in_current_dir do
76
+ content = File.read(file_name)
77
+ File.open(file_name, 'w') { |f| f << content.sub(/end\Z/, "#{snippet}\nend") }
78
+ end
79
+ end
80
+
81
+ Given /^I start the rails application$/ do
82
+ in_current_dir do
83
+ require "./config/environment"
84
+ require "capybara/rails"
85
+ end
86
+ end
87
+
88
+ Given /^I reload my application$/ do
89
+ Rails::Application.reload!
90
+ end
91
+
92
+ When %r{I turn off class caching} do
93
+ in_current_dir do
94
+ file = "config/environments/test.rb"
95
+ config = IO.read(file)
96
+ config.gsub!(%r{^\s*config.cache_classes.*$},
97
+ "config.cache_classes = false")
98
+ File.open(file, "w"){|f| f.write(config) }
99
+ end
100
+ end
101
+
102
+ Given /^I update my application to use Bundler$/ do
103
+ if framework_version?("2")
104
+ boot_config_template = File.read('features/support/fixtures/boot_config.txt')
105
+ preinitializer_template = File.read('features/support/fixtures/preinitializer.txt')
106
+ gemfile_template = File.read('features/support/fixtures/gemfile.txt')
107
+ in_current_dir do
108
+ content = File.read("config/boot.rb").sub(/Rails\.boot!/, boot_config_template)
109
+ File.open("config/boot.rb", "w") { |file| file.write(content) }
110
+ File.open("config/preinitializer.rb", "w") { |file| file.write(preinitializer_template) }
111
+ File.open("Gemfile", "w") { |file| file.write(gemfile_template.sub(/RAILS_VERSION/, framework_version)) }
112
+ end
113
+ end
114
+ end
115
+
116
+ Given /^I add the paperclip rake task to a Rails 2.3 application$/ do
117
+ if framework_version?("2.3")
118
+ require 'fileutils'
119
+ source = File.expand_path('lib/tasks/paperclip.rake')
120
+ destination = in_current_dir { File.expand_path("lib/tasks") }
121
+ FileUtils.cp source, destination
122
+ append_to "Rakefile", "require 'paperclip'"
123
+ end
124
+ end
125
+
126
+ Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path|
127
+ expected = IO.read(path)
128
+ actual = if web_file.match %r{^https?://}
129
+ Net::HTTP.get(URI.parse(web_file))
130
+ else
131
+ visit(web_file)
132
+ page.source
133
+ end
134
+ actual.force_encoding("UTF-8") if actual.respond_to?(:force_encoding)
135
+ actual.should == expected
136
+ end
137
+
138
+ When /^I configure the application to use "([^\"]+)" from this project$/ do |name|
139
+ append_to_gemfile "gem '#{name}', :path => '#{PROJECT_ROOT}'"
140
+ steps %{And I run `bundle install --local`}
141
+ end
142
+
143
+ When /^I configure the application to use "([^\"]+)"$/ do |gem_name|
144
+ append_to_gemfile "gem '#{gem_name}'"
145
+ end
146
+
147
+ When /^I append gems from Appraisal Gemfile$/ do
148
+ File.read(ENV['BUNDLE_GEMFILE']).split(/\n/).each do |line|
149
+ if line =~ /^gem "(?!rails|appraisal)/
150
+ append_to_gemfile line.strip
151
+ end
152
+ end
153
+ end
154
+
155
+ When /^I comment out the gem "([^"]*)" from the Gemfile$/ do |gemname|
156
+ comment_out_gem_in_gemfile gemname
157
+ end
158
+
159
+ module FileHelpers
160
+ def append_to(path, contents)
161
+ in_current_dir do
162
+ File.open(path, "a") do |file|
163
+ file.puts
164
+ file.puts contents
165
+ end
166
+ end
167
+ end
168
+
169
+ def append_to_gemfile(contents)
170
+ append_to('Gemfile', contents)
171
+ end
172
+
173
+ def comment_out_gem_in_gemfile(gemname)
174
+ in_current_dir do
175
+ gemfile = File.read("Gemfile")
176
+ gemfile.sub!(/^(\s*)(gem\s*['"]#{gemname})/, "\\1# \\2")
177
+ File.open("Gemfile", 'w'){ |file| file.write(gemfile) }
178
+ end
179
+ end
180
+ end
181
+
182
+ 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
@@ -0,0 +1,209 @@
1
+ # TL;DR: YOU SHOULD DELETE THIS FILE
2
+ #
3
+ # This file was generated by Cucumber-Rails and is only here to get you a head start
4
+ # These step definitions are thin wrappers around the Capybara/Webrat API that lets you
5
+ # visit pages, interact with widgets and make assertions about page content.
6
+ #
7
+ # If you use these step definitions as basis for your features you will quickly end up
8
+ # with features that are:
9
+ #
10
+ # * Hard to maintain
11
+ # * Verbose to read
12
+ #
13
+ # A much better approach is to write your own higher level step definitions, following
14
+ # the advice in the following blog posts:
15
+ #
16
+ # * http://benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories.html
17
+ # * http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/
18
+ # * http://elabs.se/blog/15-you-re-cuking-it-wrong
19
+ #
20
+
21
+
22
+ require 'uri'
23
+ require 'cgi'
24
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
25
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "selectors"))
26
+
27
+ module WithinHelpers
28
+ def with_scope(locator)
29
+ locator ? within(*selector_for(locator)) { yield } : yield
30
+ end
31
+ end
32
+ World(WithinHelpers)
33
+
34
+ # Single-line step scoper
35
+ When /^(.*) within (.*[^:])$/ do |step, parent|
36
+ with_scope(parent) { When step }
37
+ end
38
+
39
+ # Multi-line step scoper
40
+ When /^(.*) within (.*[^:]):$/ do |step, parent, table_or_string|
41
+ with_scope(parent) { When "#{step}:", table_or_string }
42
+ end
43
+
44
+ Given /^(?:|I )am on (.+)$/ do |page_name|
45
+ visit path_to(page_name)
46
+ end
47
+
48
+ When /^(?:|I )go to (.+)$/ do |page_name|
49
+ visit path_to(page_name)
50
+ end
51
+
52
+ When /^(?:|I )press "([^"]*)"$/ do |button|
53
+ click_button(button)
54
+ end
55
+
56
+ When /^(?:|I )follow "([^"]*)"$/ do |link|
57
+ click_link(link)
58
+ end
59
+
60
+ When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
61
+ fill_in(field, :with => value)
62
+ end
63
+
64
+ When /^(?:|I )fill in "([^"]*)" for "([^"]*)"$/ do |value, field|
65
+ fill_in(field, :with => value)
66
+ end
67
+
68
+ # Use this to fill in an entire form with data from a table. Example:
69
+ #
70
+ # When I fill in the following:
71
+ # | Account Number | 5002 |
72
+ # | Expiry date | 2009-11-01 |
73
+ # | Note | Nice guy |
74
+ # | Wants Email? | |
75
+ #
76
+ # TODO: Add support for checkbox, select og option
77
+ # based on naming conventions.
78
+ #
79
+ When /^(?:|I )fill in the following:$/ do |fields|
80
+ fields.rows_hash.each do |name, value|
81
+ When %{I fill in "#{name}" with "#{value}"}
82
+ end
83
+ end
84
+
85
+ When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
86
+ select(value, :from => field)
87
+ end
88
+
89
+ When /^(?:|I )check "([^"]*)"$/ do |field|
90
+ check(field)
91
+ end
92
+
93
+ When /^(?:|I )uncheck "([^"]*)"$/ do |field|
94
+ uncheck(field)
95
+ end
96
+
97
+ When /^(?:|I )choose "([^"]*)"$/ do |field|
98
+ choose(field)
99
+ end
100
+
101
+ When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
102
+ attach_file(field, File.expand_path(path))
103
+ end
104
+
105
+ Then /^(?:|I )should see "([^"]*)"$/ do |text|
106
+ if page.respond_to? :should
107
+ page.should have_content(text)
108
+ else
109
+ assert page.has_content?(text)
110
+ end
111
+ end
112
+
113
+ Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
114
+ regexp = Regexp.new(regexp)
115
+
116
+ if page.respond_to? :should
117
+ page.should have_xpath('//*', :text => regexp)
118
+ else
119
+ assert page.has_xpath?('//*', :text => regexp)
120
+ end
121
+ end
122
+
123
+ Then /^(?:|I )should not see "([^"]*)"$/ do |text|
124
+ if page.respond_to? :should
125
+ page.should have_no_content(text)
126
+ else
127
+ assert page.has_no_content?(text)
128
+ end
129
+ end
130
+
131
+ Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
132
+ regexp = Regexp.new(regexp)
133
+
134
+ if page.respond_to? :should
135
+ page.should have_no_xpath('//*', :text => regexp)
136
+ else
137
+ assert page.has_no_xpath?('//*', :text => regexp)
138
+ end
139
+ end
140
+
141
+ Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
142
+ with_scope(parent) do
143
+ field = find_field(field)
144
+ if field.value.respond_to? :should
145
+ field.value.should =~ /#{value}/
146
+ else
147
+ assert_match(/#{value}/, field.value)
148
+ end
149
+ end
150
+ end
151
+
152
+ Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
153
+ with_scope(parent) do
154
+ field = find_field(field)
155
+ if field.value.respond_to? :should_not
156
+ field.value.should_not =~ /#{value}/
157
+ else
158
+ assert_no_match(/#{value}/, field.value)
159
+ end
160
+ end
161
+ end
162
+
163
+ Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
164
+ with_scope(parent) do
165
+ field_checked = find_field(label)['checked']
166
+ if field_checked.respond_to? :should
167
+ field_checked.should be_true
168
+ else
169
+ assert field_checked
170
+ end
171
+ end
172
+ end
173
+
174
+ Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
175
+ with_scope(parent) do
176
+ field_checked = find_field(label)['checked']
177
+ if field_checked.respond_to? :should
178
+ field_checked.should be_false
179
+ else
180
+ assert !field_checked
181
+ end
182
+ end
183
+ end
184
+
185
+ Then /^(?:|I )should be on (.+)$/ do |page_name|
186
+ current_path = URI.parse(current_url).path
187
+ if current_path.respond_to? :should
188
+ current_path.should == path_to(page_name)
189
+ else
190
+ assert_equal path_to(page_name), current_path
191
+ end
192
+ end
193
+
194
+ Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
195
+ query = URI.parse(current_url).query
196
+ actual_params = query ? CGI.parse(query) : {}
197
+ expected_params = {}
198
+ expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
199
+
200
+ if actual_params.respond_to? :should
201
+ actual_params.should == expected_params
202
+ else
203
+ assert_equal expected_params, actual_params
204
+ end
205
+ end
206
+
207
+ Then /^show me the page$/ do
208
+ save_and_open_page
209
+ end
@@ -0,0 +1,8 @@
1
+ require 'aruba/cucumber'
2
+ require 'capybara/cucumber'
3
+ require 'test/unit/assertions'
4
+ World(Test::Unit::Assertions)
5
+
6
+ Before do
7
+ @aruba_timeout_seconds = 120
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'fake_web'
2
+
3
+ FakeWeb.allow_net_connect = false
@@ -0,0 +1,15 @@
1
+ class Rails::Boot
2
+ def run
3
+ load_initializer
4
+
5
+ Rails::Initializer.class_eval do
6
+ def load_gems
7
+ @bundler_loaded ||= Bundler.require :default, Rails.env
8
+ end
9
+ end
10
+
11
+ Rails::Initializer.run(:set_load_path)
12
+ end
13
+ end
14
+
15
+ Rails.boot!
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "RAILS_VERSION"
4
+ gem "rdoc"
5
+ gem "sqlite3"
@@ -0,0 +1,20 @@
1
+ begin
2
+ require "rubygems"
3
+ require "bundler"
4
+ rescue LoadError
5
+ raise "Could not load the bundler gem. Install it with `gem install bundler`."
6
+ end
7
+
8
+ if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24")
9
+ raise RuntimeError, "Your bundler version is too old for Rails 2.3." +
10
+ "Run `gem install bundler` to upgrade."
11
+ end
12
+
13
+ begin
14
+ # Set up load paths for all bundled gems
15
+ ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
16
+ Bundler.setup
17
+ rescue Bundler::GemNotFound
18
+ raise RuntimeError, "Bundler couldn't find some gems." +
19
+ "Did you run `bundle install`?"
20
+ end
@@ -0,0 +1,28 @@
1
+ module NavigationHelpers
2
+ # Maps a name to a path. Used by the
3
+ #
4
+ # When /^I go to (.+)$/ do |page_name|
5
+ #
6
+ # step definition in web_steps.rb
7
+ #
8
+ def path_to(page_name)
9
+ case page_name
10
+
11
+ when /the home\s?page/
12
+ '/'
13
+ when /the new user page/
14
+ '/users/new'
15
+ else
16
+ begin
17
+ page_name =~ /the (.*) page/
18
+ path_components = $1.split(/\s+/)
19
+ self.send(path_components.push('path').join('_').to_sym)
20
+ rescue Object => e
21
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
22
+ "Now, go and add a mapping in #{__FILE__}"
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ World(NavigationHelpers)
@@ -0,0 +1,46 @@
1
+ PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze
2
+ APP_NAME = 'testapp'.freeze
3
+ BUNDLE_ENV_VARS = %w(RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE)
4
+ ORIGINAL_BUNDLE_VARS = Hash[ENV.select{ |key,value| BUNDLE_ENV_VARS.include?(key) }]
5
+
6
+ ENV['RAILS_ENV'] = 'test'
7
+
8
+ Before do
9
+ ENV['BUNDLE_GEMFILE'] = File.join(Dir.pwd, ENV['BUNDLE_GEMFILE']) unless ENV['BUNDLE_GEMFILE'].start_with?(Dir.pwd)
10
+ @framework_version = nil
11
+ end
12
+
13
+ After do
14
+ ORIGINAL_BUNDLE_VARS.each_pair do |key, value|
15
+ ENV[key] = value
16
+ end
17
+ end
18
+
19
+ When /^I reset Bundler environment variable$/ do
20
+ BUNDLE_ENV_VARS.each do |key|
21
+ ENV[key] = nil
22
+ end
23
+ end
24
+
25
+ module RailsCommandHelpers
26
+ def framework_version?(version_string)
27
+ framework_version =~ /^#{version_string}/
28
+ end
29
+
30
+ def framework_version
31
+ @framework_version ||= `rails -v`[/^Rails (.+)$/, 1]
32
+ end
33
+
34
+ def new_application_command
35
+ framework_version?("3") ? "rails new" : "rails"
36
+ end
37
+
38
+ def generator_command
39
+ framework_version?("3") ? "script/rails generate" : "script/generate"
40
+ end
41
+
42
+ def runner_command
43
+ framework_version?("3") ? "script/rails runner" : "script/runner"
44
+ end
45
+ end
46
+ World(RailsCommandHelpers)
@@ -0,0 +1,19 @@
1
+ module HtmlSelectorsHelpers
2
+ # Maps a name to a selector. Used primarily by the
3
+ #
4
+ # When /^(.+) within (.+)$/ do |step, scope|
5
+ #
6
+ # step definitions in web_steps.rb
7
+ #
8
+ def selector_for(locator)
9
+ case locator
10
+ when "the page"
11
+ "html > body"
12
+ else
13
+ raise "Can't find mapping from \"#{locator}\" to a selector.\n" +
14
+ "Now, go and add a mapping in #{__FILE__}"
15
+ end
16
+ end
17
+ end
18
+
19
+ World(HtmlSelectorsHelpers)
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "jruby-openssl", :platform=>:jruby
6
+ gem "rails", "~> 2.3.14"
7
+ gem "paperclip", :path=>"../"
8
+
9
+ gemspec :path=>"../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "jruby-openssl", :platform=>:jruby
6
+ gem "rails", "~> 3.0.10"
7
+ gem "paperclip", :path=>"../"
8
+
9
+ gemspec :path=>"../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "jruby-openssl", :platform=>:jruby
6
+ gem "rails", "~> 3.1.0"
7
+ gem "paperclip", :path=>"../"
8
+
9
+ gemspec :path=>"../"
@@ -0,0 +1,5 @@
1
+ Usage:
2
+
3
+ script/generate paperclip Class attachment1 (attachment2 ...)
4
+
5
+ This will create a migration that will add the proper columns to your class's table.
@@ -0,0 +1,27 @@
1
+ class PaperclipGenerator < Rails::Generator::NamedBase
2
+ attr_accessor :attachments, :migration_name
3
+
4
+ def initialize(args, options = {})
5
+ super
6
+ @class_name, @attachments = args[0], args[1..-1]
7
+ end
8
+
9
+ def manifest
10
+ file_name = generate_file_name
11
+ @migration_name = file_name.camelize
12
+ record do |m|
13
+ m.migration_template "paperclip_migration.rb.erb",
14
+ File.join('db', 'migrate'),
15
+ :migration_file_name => file_name
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def generate_file_name
22
+ names = attachments.map{|a| a.underscore }
23
+ names = names[0..-2] + ["and", names[-1]] if names.length > 1
24
+ "add_attachments_#{names.join("_")}_to_#{@class_name.underscore}"
25
+ end
26
+
27
+ end
@@ -0,0 +1,19 @@
1
+ class <%= migration_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ <% attachments.each do |attachment| -%>
4
+ add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_name, :string
5
+ add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_content_type, :string
6
+ add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_size, :integer
7
+ add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_updated_at, :datetime
8
+ <% end -%>
9
+ end
10
+
11
+ def self.down
12
+ <% attachments.each do |attachment| -%>
13
+ remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_name
14
+ remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_content_type
15
+ remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_size
16
+ remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_updated_at
17
+ <% end -%>
18
+ end
19
+ end
data/init.rb ADDED
@@ -0,0 +1,4 @@
1
+ require File.join(File.dirname(__FILE__), "lib", "paperclip")
2
+ require 'paperclip/railtie'
3
+
4
+ Paperclip::Railtie.insert
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate paperclip Thing
6
+
7
+ This will create:
8
+ what/will/it/create