paperclip_database 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +54 -0
- data/.rspec +1 -0
- data/Appraisals +14 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +102 -0
- data/LICENSE.txt +26 -0
- data/README.rdoc +19 -0
- data/Rakefile +41 -0
- data/features/basic_integration.feature +29 -0
- data/features/step_definitions/html_steps.rb +15 -0
- data/features/step_definitions/paperclip_database_steps.rb +0 -0
- data/features/step_definitions/rails_steps.rb +193 -0
- data/features/step_definitions/web_steps.rb +209 -0
- data/features/support/env.rb +15 -0
- data/features/support/fakeweb.rb +3 -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 +8 -0
- data/gemfiles/rails3.gemfile +8 -0
- data/gemfiles/rails3_1.gemfile +8 -0
- data/generators/paperclip_database/USAGE +5 -0
- data/generators/paperclip_database/paperclip_database_generator.rb +28 -0
- data/generators/paperclip_database/templates/paperclip_database_migration.rb.erb +17 -0
- data/generators/templates/paperclip_database_migration.rb.erb +17 -0
- data/lib/generators/paperclip_database/USAGE +8 -0
- data/lib/generators/paperclip_database/paperclip_database_generator.rb +33 -0
- data/lib/generators/paperclip_database/templates/paperclip_database_migration.rb.erb +17 -0
- data/lib/paperclip/storage/database.rb +198 -0
- data/lib/paperclip_database/version.rb +3 -0
- data/lib/paperclip_database.rb +4 -0
- data/paperclip_database.gemspec +37 -0
- data/rails/init.rb +3 -0
- data/spec/paperclip_database_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- data/test/fixtures/5k.png +0 -0
- metadata +199 -0
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
tmp
|
2
|
+
|
3
|
+
# rcov generated
|
4
|
+
coverage
|
5
|
+
coverage.data
|
6
|
+
|
7
|
+
# rdoc generated
|
8
|
+
rdoc
|
9
|
+
|
10
|
+
# yard generated
|
11
|
+
doc
|
12
|
+
.yardoc
|
13
|
+
|
14
|
+
# bundler
|
15
|
+
.bundle
|
16
|
+
|
17
|
+
# jeweler generated
|
18
|
+
pkg
|
19
|
+
|
20
|
+
# Bundler generated
|
21
|
+
*emfile.lock
|
22
|
+
|
23
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
24
|
+
#
|
25
|
+
# * Create a file at ~/.gitignore
|
26
|
+
# * Include files you want ignored
|
27
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
28
|
+
#
|
29
|
+
# After doing this, these files will be ignored in all your git projects,
|
30
|
+
# saving you from having to 'pollute' every project you touch with them
|
31
|
+
#
|
32
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
33
|
+
#
|
34
|
+
# For MacOS:
|
35
|
+
#
|
36
|
+
#.DS_Store
|
37
|
+
|
38
|
+
# For TextMate
|
39
|
+
#*.tmproj
|
40
|
+
#tmtags
|
41
|
+
|
42
|
+
# For emacs:
|
43
|
+
*~
|
44
|
+
#\#*
|
45
|
+
#.\#*
|
46
|
+
|
47
|
+
# For vim:
|
48
|
+
#*.swp
|
49
|
+
|
50
|
+
# For redcar:
|
51
|
+
#.redcar
|
52
|
+
|
53
|
+
# For rubinius:
|
54
|
+
#*.rbc
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Appraisals
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
appraise "rails2" do
|
2
|
+
gem "rails", "~> 2.3.14"
|
3
|
+
gem "paperclip_database", :path => "../"
|
4
|
+
end
|
5
|
+
|
6
|
+
appraise "rails3" do
|
7
|
+
gem "rails", "~> 3.0.10"
|
8
|
+
gem "paperclip_database", :path => "../"
|
9
|
+
end
|
10
|
+
|
11
|
+
appraise "rails3_1" do
|
12
|
+
gem "rails", "~> 3.1.0"
|
13
|
+
gem "paperclip_database", :path => "../"
|
14
|
+
end
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
paperclip_database (0.0.1)
|
5
|
+
paperclip (>= 2.5.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (3.2.1)
|
11
|
+
activesupport (= 3.2.1)
|
12
|
+
builder (~> 3.0.0)
|
13
|
+
activerecord (3.2.1)
|
14
|
+
activemodel (= 3.2.1)
|
15
|
+
activesupport (= 3.2.1)
|
16
|
+
arel (~> 3.0.0)
|
17
|
+
tzinfo (~> 0.3.29)
|
18
|
+
activesupport (3.2.1)
|
19
|
+
i18n (~> 0.6)
|
20
|
+
multi_json (~> 1.0)
|
21
|
+
appraisal (0.4.0)
|
22
|
+
bundler
|
23
|
+
rake
|
24
|
+
arel (3.0.0)
|
25
|
+
aruba (0.4.11)
|
26
|
+
childprocess (>= 0.2.3)
|
27
|
+
cucumber (>= 1.1.1)
|
28
|
+
ffi (>= 1.0.11)
|
29
|
+
rspec (>= 2.7.0)
|
30
|
+
builder (3.0.0)
|
31
|
+
capybara (1.1.2)
|
32
|
+
mime-types (>= 1.16)
|
33
|
+
nokogiri (>= 1.3.3)
|
34
|
+
rack (>= 1.0.0)
|
35
|
+
rack-test (>= 0.5.4)
|
36
|
+
selenium-webdriver (~> 2.0)
|
37
|
+
xpath (~> 0.1.4)
|
38
|
+
childprocess (0.3.0)
|
39
|
+
ffi (~> 1.0.6)
|
40
|
+
cocaine (0.2.1)
|
41
|
+
cucumber (1.1.4)
|
42
|
+
builder (>= 2.1.2)
|
43
|
+
diff-lcs (>= 1.1.2)
|
44
|
+
gherkin (~> 2.7.1)
|
45
|
+
json (>= 1.4.6)
|
46
|
+
term-ansicolor (>= 1.0.6)
|
47
|
+
diff-lcs (1.1.3)
|
48
|
+
fakeweb (1.3.0)
|
49
|
+
ffi (1.0.11)
|
50
|
+
gherkin (2.7.4)
|
51
|
+
json (>= 1.4.6)
|
52
|
+
i18n (0.6.0)
|
53
|
+
json (1.6.5)
|
54
|
+
metaclass (0.0.1)
|
55
|
+
mime-types (1.17.2)
|
56
|
+
mocha (0.10.3)
|
57
|
+
metaclass (~> 0.0.1)
|
58
|
+
multi_json (1.0.4)
|
59
|
+
nokogiri (1.5.0)
|
60
|
+
paperclip (2.5.1)
|
61
|
+
activerecord (>= 2.3.0)
|
62
|
+
activesupport (>= 2.3.2)
|
63
|
+
cocaine (>= 0.0.2)
|
64
|
+
mime-types
|
65
|
+
rack (1.4.1)
|
66
|
+
rack-test (0.6.1)
|
67
|
+
rack (>= 1.0)
|
68
|
+
rake (0.9.2.2)
|
69
|
+
rspec (2.8.0)
|
70
|
+
rspec-core (~> 2.8.0)
|
71
|
+
rspec-expectations (~> 2.8.0)
|
72
|
+
rspec-mocks (~> 2.8.0)
|
73
|
+
rspec-core (2.8.0)
|
74
|
+
rspec-expectations (2.8.0)
|
75
|
+
diff-lcs (~> 1.1.2)
|
76
|
+
rspec-mocks (2.8.0)
|
77
|
+
rubyzip (0.9.5)
|
78
|
+
selenium-webdriver (2.18.0)
|
79
|
+
childprocess (>= 0.2.5)
|
80
|
+
ffi (~> 1.0.9)
|
81
|
+
multi_json (~> 1.0.4)
|
82
|
+
rubyzip
|
83
|
+
sqlite3 (1.3.5)
|
84
|
+
term-ansicolor (1.0.7)
|
85
|
+
tzinfo (0.3.31)
|
86
|
+
xpath (0.1.4)
|
87
|
+
nokogiri (~> 1.3)
|
88
|
+
|
89
|
+
PLATFORMS
|
90
|
+
ruby
|
91
|
+
|
92
|
+
DEPENDENCIES
|
93
|
+
appraisal (~> 0.4.0)
|
94
|
+
aruba
|
95
|
+
bundler
|
96
|
+
capybara
|
97
|
+
cucumber (~> 1.1.0)
|
98
|
+
fakeweb
|
99
|
+
mocha
|
100
|
+
paperclip_database!
|
101
|
+
rake
|
102
|
+
sqlite3 (~> 1.3.4)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
LICENSE
|
3
|
+
|
4
|
+
The MIT License
|
5
|
+
|
6
|
+
Copyright (c) 2008 Jarl Friis.
|
7
|
+
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
10
|
+
in the Software without restriction, including without limitation the rights
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
13
|
+
furnished to do so, subject to the following conditions:
|
14
|
+
|
15
|
+
The above copyright notice and this permission notice shall be included in
|
16
|
+
all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
THE SOFTWARE.
|
25
|
+
|
26
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= paperclip_database
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to paperclip_database
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 Jarl Friis. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -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_database 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_database -r rubygems -r active_record -r paperclip -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_database.db" rescue nil
|
40
|
+
Dir.glob("paperclip_database-*.gem").each{|f| FileUtils.rm f }
|
41
|
+
end
|
@@ -0,0 +1,29 @@
|
|
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: Database integration test
|
12
|
+
Given I add this snippet to the User model:
|
13
|
+
"""
|
14
|
+
has_attached_file :attachment,
|
15
|
+
:storage => :database,
|
16
|
+
:database_table => :user_attachments,
|
17
|
+
"""
|
18
|
+
And I run a paperclip_database generator to create storage for paperclip "attachment" to the "User" model
|
19
|
+
And I run a migration
|
20
|
+
And I start the rails application
|
21
|
+
When I go to the new user page
|
22
|
+
And I fill in "Name" with "something"
|
23
|
+
And I attach the file "test/fixtures/5k.png" to "Attachment"
|
24
|
+
And I press "Submit"
|
25
|
+
Then I should see "Name: something"
|
26
|
+
And I should see an image with a path of "/system/attachments/1/original/5k.png"
|
27
|
+
# And the table "attachments" should contain 3 rows.
|
28
|
+
And the result of "User.first.attachment.file_for(:original).file_contents" should be the same as "test/fixtures/5k.png"
|
29
|
+
|
@@ -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
|
File without changes
|
@@ -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 "paperclip"
|
15
|
+
"""
|
16
|
+
And I configure the application to use "paperclip_database" 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 paperclip_database generator to create storage for paperclip "(.*?)" to the "(.*?)" model$/ do |attachment_name, model_name|
|
31
|
+
step %[I successfully run `bundle exec #{generator_command} paperclip_database #{model_name} #{attachment_name}`]
|
32
|
+
end
|
33
|
+
|
34
|
+
Given /^I run a migration$/ do
|
35
|
+
step %[I successfully run `bundle exec rake db:migrate`]
|
36
|
+
end
|
37
|
+
|
38
|
+
Given /^I update my new user view to include the file upload field$/ do
|
39
|
+
if framework_version?("3")
|
40
|
+
steps %{
|
41
|
+
Given I overwrite "app/views/users/new.html.erb" with:
|
42
|
+
"""
|
43
|
+
<%= form_for @user, :html => { :multipart => true } do |f| %>
|
44
|
+
<%= f.label :name %>
|
45
|
+
<%= f.text_field :name %>
|
46
|
+
<%= f.label :attachment %>
|
47
|
+
<%= f.file_field :attachment %>
|
48
|
+
<%= submit_tag "Submit" %>
|
49
|
+
<% end %>
|
50
|
+
"""
|
51
|
+
}
|
52
|
+
else
|
53
|
+
steps %{
|
54
|
+
Given I overwrite "app/views/users/new.html.erb" with:
|
55
|
+
"""
|
56
|
+
<% form_for @user, :html => { :multipart => true } do |f| %>
|
57
|
+
<%= f.label :name %>
|
58
|
+
<%= f.text_field :name %>
|
59
|
+
<%= f.label :attachment %>
|
60
|
+
<%= f.file_field :attachment %>
|
61
|
+
<%= submit_tag "Submit" %>
|
62
|
+
<% end %>
|
63
|
+
"""
|
64
|
+
}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
Given /^I update my user view to include the attachment$/ do
|
69
|
+
steps %{
|
70
|
+
Given I overwrite "app/views/users/show.html.erb" with:
|
71
|
+
"""
|
72
|
+
<p>Name: <%= @user.name %></p>
|
73
|
+
<p>Attachment: <%= image_tag @user.attachment.url %></p>
|
74
|
+
"""
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
Given /^I add this snippet to the User model:$/ do |snippet|
|
79
|
+
file_name = "app/models/user.rb"
|
80
|
+
in_current_dir do
|
81
|
+
content = File.read(file_name)
|
82
|
+
File.open(file_name, 'w') { |f| f << content.sub(/end\Z/, "#{snippet}\nend") }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
Given /^I start the rails application$/ do
|
87
|
+
in_current_dir do
|
88
|
+
require "./config/environment"
|
89
|
+
require "capybara/rails"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
Given /^I reload my application$/ do
|
94
|
+
Rails::Application.reload!
|
95
|
+
end
|
96
|
+
|
97
|
+
When %r{I turn off class caching} do
|
98
|
+
in_current_dir do
|
99
|
+
file = "config/environments/test.rb"
|
100
|
+
config = IO.read(file)
|
101
|
+
config.gsub!(%r{^\s*config.cache_classes.*$},
|
102
|
+
"config.cache_classes = false")
|
103
|
+
File.open(file, "w"){|f| f.write(config) }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
Given /^I update my application to use Bundler$/ do
|
108
|
+
if framework_version?("2")
|
109
|
+
boot_config_template = File.read('features/support/fixtures/boot_config.txt')
|
110
|
+
preinitializer_template = File.read('features/support/fixtures/preinitializer.txt')
|
111
|
+
gemfile_template = File.read('features/support/fixtures/gemfile.txt')
|
112
|
+
in_current_dir do
|
113
|
+
content = File.read("config/boot.rb").sub(/Rails\.boot!/, boot_config_template)
|
114
|
+
File.open("config/boot.rb", "w") { |file| file.write(content) }
|
115
|
+
File.open("config/preinitializer.rb", "w") { |file| file.write(preinitializer_template) }
|
116
|
+
File.open("Gemfile", "w") { |file| file.write(gemfile_template.sub(/RAILS_VERSION/, framework_version)) }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
Given /^I add the paperclip rake task to a Rails 2.3 application$/ do
|
122
|
+
if framework_version?("2.3")
|
123
|
+
require 'fileutils'
|
124
|
+
source = File.expand_path('lib/tasks/paperclip.rake')
|
125
|
+
destination = in_current_dir { File.expand_path("lib/tasks") }
|
126
|
+
FileUtils.cp source, destination
|
127
|
+
append_to "Rakefile", "require 'paperclip'"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path|
|
132
|
+
expected = IO.binread(path)
|
133
|
+
actual = if web_file.match %r{^https?://}
|
134
|
+
Net::HTTP.get(URI.parse(web_file))
|
135
|
+
else
|
136
|
+
visit(web_file)
|
137
|
+
page.source
|
138
|
+
end
|
139
|
+
actual.should == expected
|
140
|
+
end
|
141
|
+
|
142
|
+
When /^I configure the application to use "([^\"]+)" from this project$/ do |name|
|
143
|
+
append_to_gemfile "gem '#{name}', :path => '#{PROJECT_ROOT}'"
|
144
|
+
steps %{And I run `bundle install --local`}
|
145
|
+
end
|
146
|
+
|
147
|
+
When /^I configure the application to use "([^\"]+)"$/ do |gem_name|
|
148
|
+
append_to_gemfile "gem '#{gem_name}'"
|
149
|
+
end
|
150
|
+
|
151
|
+
When /^I append gems from Appraisal Gemfile$/ do
|
152
|
+
File.read(ENV['BUNDLE_GEMFILE']).split(/\n/).each do |line|
|
153
|
+
if line =~ /^gem "(?!rails|appraisal)/
|
154
|
+
append_to_gemfile line.strip
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
When /^I comment out the gem "(.*?)" from the Gemfile$/ do |gemname|
|
160
|
+
comment_out_gem_in_gemfile gemname
|
161
|
+
end
|
162
|
+
|
163
|
+
Then /^the result of "(.*?)" should be the same as "(.*?)"$/ do |rails_expr, path|
|
164
|
+
expected = IO.binread(path)
|
165
|
+
actual = eval "#{rails_expr}"
|
166
|
+
actual.should == expected
|
167
|
+
end
|
168
|
+
|
169
|
+
|
170
|
+
module FileHelpers
|
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)
|