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.
- data/.gitignore +22 -0
- data/.travis.yml +13 -0
- data/Appraisals +14 -0
- data/CONTRIBUTING.md +38 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +137 -0
- data/LICENSE +26 -0
- data/README.md +444 -0
- data/Rakefile +41 -0
- data/cucumber/paperclip_steps.rb +6 -0
- data/features/basic_integration.feature +46 -0
- data/features/rake_tasks.feature +63 -0
- data/features/step_definitions/attachment_steps.rb +65 -0
- data/features/step_definitions/html_steps.rb +15 -0
- data/features/step_definitions/rails_steps.rb +182 -0
- data/features/step_definitions/s3_steps.rb +14 -0
- data/features/step_definitions/web_steps.rb +209 -0
- data/features/support/env.rb +8 -0
- data/features/support/fakeweb.rb +3 -0
- data/features/support/fixtures/.boot_config.rb.swo +0 -0
- data/features/support/fixtures/boot_config.txt +15 -0
- data/features/support/fixtures/gemfile.txt +5 -0
- data/features/support/fixtures/preinitializer.txt +20 -0
- data/features/support/paths.rb +28 -0
- data/features/support/rails.rb +46 -0
- data/features/support/selectors.rb +19 -0
- data/gemfiles/rails2.gemfile +9 -0
- data/gemfiles/rails3.gemfile +9 -0
- data/gemfiles/rails3_1.gemfile +9 -0
- data/generators/paperclip/USAGE +5 -0
- data/generators/paperclip/paperclip_generator.rb +27 -0
- data/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
- data/init.rb +4 -0
- data/lib/generators/paperclip/USAGE +8 -0
- data/lib/generators/paperclip/paperclip_generator.rb +33 -0
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
- data/lib/paperclip/attachment.rb +468 -0
- data/lib/paperclip/callback_compatibility.rb +61 -0
- data/lib/paperclip/geometry.rb +120 -0
- data/lib/paperclip/interpolations.rb +174 -0
- data/lib/paperclip/iostream.rb +45 -0
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +57 -0
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +81 -0
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +54 -0
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +95 -0
- data/lib/paperclip/matchers.rb +64 -0
- data/lib/paperclip/missing_attachment_styles.rb +87 -0
- data/lib/paperclip/processor.rb +58 -0
- data/lib/paperclip/railtie.rb +31 -0
- data/lib/paperclip/schema.rb +39 -0
- data/lib/paperclip/storage/filesystem.rb +81 -0
- data/lib/paperclip/storage/fog.rb +174 -0
- data/lib/paperclip/storage/s3.rb +333 -0
- data/lib/paperclip/storage.rb +3 -0
- data/lib/paperclip/style.rb +103 -0
- data/lib/paperclip/thumbnail.rb +105 -0
- data/lib/paperclip/upfile.rb +62 -0
- data/lib/paperclip/url_generator.rb +64 -0
- data/lib/paperclip/version.rb +3 -0
- data/lib/paperclip.rb +487 -0
- data/lib/tasks/paperclip.rake +101 -0
- data/paperclip.gemspec +41 -0
- data/rails/init.rb +2 -0
- data/shoulda_macros/paperclip.rb +124 -0
- data/test/.gitignore +1 -0
- data/test/attachment_test.rb +1116 -0
- data/test/database.yml +4 -0
- data/test/fixtures/12k.png +0 -0
- data/test/fixtures/50x50.png +0 -0
- data/test/fixtures/5k.png +0 -0
- data/test/fixtures/animated.gif +0 -0
- data/test/fixtures/bad.png +1 -0
- data/test/fixtures/fog.yml +8 -0
- data/test/fixtures/question?mark.png +0 -0
- data/test/fixtures/s3.yml +8 -0
- data/test/fixtures/spaced file.png +0 -0
- data/test/fixtures/text.txt +1 -0
- data/test/fixtures/twopage.pdf +0 -0
- data/test/fixtures/uppercase.PNG +0 -0
- data/test/geometry_test.rb +206 -0
- data/test/helper.rb +177 -0
- data/test/integration_test.rb +654 -0
- data/test/interpolations_test.rb +216 -0
- data/test/iostream_test.rb +71 -0
- data/test/matchers/have_attached_file_matcher_test.rb +24 -0
- data/test/matchers/validate_attachment_content_type_matcher_test.rb +87 -0
- data/test/matchers/validate_attachment_presence_matcher_test.rb +26 -0
- data/test/matchers/validate_attachment_size_matcher_test.rb +51 -0
- data/test/paperclip_missing_attachment_styles_test.rb +80 -0
- data/test/paperclip_test.rb +390 -0
- data/test/processor_test.rb +10 -0
- data/test/schema_test.rb +98 -0
- data/test/storage/filesystem_test.rb +56 -0
- data/test/storage/fog_test.rb +219 -0
- data/test/storage/s3_live_test.rb +138 -0
- data/test/storage/s3_test.rb +943 -0
- data/test/style_test.rb +209 -0
- data/test/support/mock_attachment.rb +22 -0
- data/test/support/mock_interpolator.rb +24 -0
- data/test/support/mock_model.rb +2 -0
- data/test/support/mock_url_generator_builder.rb +27 -0
- data/test/thumbnail_test.rb +383 -0
- data/test/upfile_test.rb +53 -0
- data/test/url_generator_test.rb +187 -0
- 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
|
|
Binary file
|
|
@@ -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,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