paperclip_database_myplaceonline 3.1.1

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 (44) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gitignore +57 -0
  4. data/.rspec +1 -0
  5. data/.travis.yml +15 -0
  6. data/Appraisals +71 -0
  7. data/Gemfile +5 -0
  8. data/LICENSE.txt +26 -0
  9. data/README.md +126 -0
  10. data/Rakefile +42 -0
  11. data/features/basic_integration.feature +45 -0
  12. data/features/step_definitions/html_steps.rb +15 -0
  13. data/features/step_definitions/paperclip_database_steps.rb +0 -0
  14. data/features/step_definitions/rails_steps.rb +209 -0
  15. data/features/step_definitions/web_steps.rb +115 -0
  16. data/features/support/env.rb +15 -0
  17. data/features/support/fakeweb.rb +3 -0
  18. data/features/support/paths.rb +28 -0
  19. data/features/support/rails.rb +62 -0
  20. data/features/support/selectors.rb +19 -0
  21. data/gemfiles/rails42_paperclip4x.gemfile +11 -0
  22. data/gemfiles/rails42_paperclip5x.gemfile +11 -0
  23. data/gemfiles/rails42_paperclip6x.gemfile +11 -0
  24. data/gemfiles/rails50_paperclip4x.gemfile +11 -0
  25. data/gemfiles/rails50_paperclip5x.gemfile +11 -0
  26. data/gemfiles/rails50_paperclip6x.gemfile +12 -0
  27. data/gemfiles/rails51_paperclip6x.gemfile +12 -0
  28. data/gemfiles/rails52_paperclip6x.gemfile +12 -0
  29. data/lib/generators/paperclip_database/migration/USAGE +8 -0
  30. data/lib/generators/paperclip_database/migration/migration_generator.rb +44 -0
  31. data/lib/generators/paperclip_database/migration/templates/migration.rb.erb +20 -0
  32. data/lib/paperclip/storage/database.rb +243 -0
  33. data/lib/paperclip_database/version.rb +3 -0
  34. data/lib/paperclip_database.rb +3 -0
  35. data/paperclip_database.gemspec +37 -0
  36. data/rails/init.rb +3 -0
  37. data/spec/database.yml +3 -0
  38. data/spec/default_options_spec.rb +74 -0
  39. data/spec/fixtures/5k.png +0 -0
  40. data/spec/major_version_API_spec.rb +89 -0
  41. data/spec/namespaced_models_spec.rb +39 -0
  42. data/spec/single_table_inheritance_spec.rb +39 -0
  43. data/spec/spec_helper.rb +92 -0
  44. metadata +260 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f1b2690aab3302814cb3011f92568c72e020733e06b2cf751bf42c5ac8ddb024
4
+ data.tar.gz: db189a859080f77114562c9a843ad6560a96389323b568870d453890df504ee2
5
+ SHA512:
6
+ metadata.gz: 43f7003a57f2694b344904c9eefcb3ec3abf33a55e5e64df6a460172d8c4d6df8152a8cb363effeed0aaabba77597ef47fbe7093a6a635da7845ccd877e6ea13
7
+ data.tar.gz: b95bbeba55c601ee1050394db136fce2eee3de2c76b54d9cf0aabd6844aa8891f6a0b3abcf3ba4c03614f2abb094f78a451820d2ab8e8fd28e81384f0eccd9cf
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,57 @@
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
+ # Test suite generated
24
+ spec/debug.log
25
+
26
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
27
+ #
28
+ # * Create a file at ~/.gitignore
29
+ # * Include files you want ignored
30
+ # * Run: git config --global core.excludesfile ~/.gitignore
31
+ #
32
+ # After doing this, these files will be ignored in all your git projects,
33
+ # saving you from having to 'pollute' every project you touch with them
34
+ #
35
+ # 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)
36
+ #
37
+ # For MacOS:
38
+ #
39
+ #.DS_Store
40
+
41
+ # For TextMate
42
+ #*.tmproj
43
+ #tmtags
44
+
45
+ # For emacs:
46
+ *~
47
+ #\#*
48
+ #.\#*
49
+
50
+ # For vim:
51
+ #*.swp
52
+
53
+ # For redcar:
54
+ #.redcar
55
+
56
+ # For rubinius:
57
+ #*.rbc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --format doc
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.8
4
+ - 2.4.9
5
+ - 2.5.7
6
+ - 2.6.5
7
+ gemfile:
8
+ - gemfiles/rails42_paperclip4x.gemfile
9
+ - gemfiles/rails42_paperclip5x.gemfile
10
+ - gemfiles/rails42_paperclip6x.gemfile
11
+ - gemfiles/rails50_paperclip4x.gemfile
12
+ - gemfiles/rails50_paperclip5x.gemfile
13
+ - gemfiles/rails50_paperclip6x.gemfile
14
+ - gemfiles/rails51_paperclip6x.gemfile
15
+ - gemfiles/rails52_paperclip6x.gemfile
data/Appraisals ADDED
@@ -0,0 +1,71 @@
1
+ #-*- ruby -*-
2
+ ## Rails 4.2
3
+
4
+ appraise "rails42_paperclip4x" do
5
+ gem "rails", "~> 4.2.0"
6
+ gem "paperclip", "~> 4.0"
7
+ gem 'capybara'
8
+ gem 'rspec'
9
+ gem 'sqlite3', '~> 1.3.0'
10
+ end
11
+
12
+ appraise "rails42_paperclip5x" do
13
+ gem "rails", "~> 4.2.0"
14
+ gem "paperclip", "~> 5.0"
15
+ gem 'capybara'
16
+ gem 'rspec'
17
+ gem 'sqlite3', '~> 1.3.0'
18
+ end
19
+
20
+ appraise "rails42_paperclip6x" do
21
+ gem "rails", "~> 4.2.0"
22
+ gem "paperclip", "~> 6.0"
23
+ gem 'capybara'
24
+ gem 'rspec'
25
+ gem 'sqlite3', '~> 1.3.0'
26
+ end
27
+
28
+ #Requires ruby >= 2.2.2
29
+ appraise "rails50_paperclip4x" do
30
+ gem "rails", "~> 5.0.0"
31
+ gem "paperclip", "~> 4.0"
32
+ gem 'capybara'
33
+ gem 'rspec'
34
+ gem 'sqlite3', '~> 1.3.0'
35
+ end
36
+
37
+ appraise "rails50_paperclip5x" do
38
+ gem "rails", "~> 5.0.0"
39
+ gem "paperclip", "~> 5.0"
40
+ gem 'capybara'
41
+ gem 'rspec'
42
+ gem 'sqlite3', '~> 1.3.0'
43
+ end
44
+
45
+ appraise "rails50_paperclip6x" do
46
+ gem "rails", "~> 5.0.0"
47
+ gem "paperclip", "~> 6.0"
48
+ gem 'capybara'
49
+ gem 'rspec'
50
+ gem 'sqlite3', '~> 1.3.0'
51
+ gem 'bootsnap', '~> 1.0', require: false
52
+ end
53
+
54
+ appraise "rails51_paperclip6x" do
55
+ gem "rails", "~> 5.1.0"
56
+ gem "paperclip", "~> 6.0"
57
+ gem 'capybara'
58
+ gem 'rspec'
59
+ gem 'sqlite3', '~> 1.3.0'
60
+ gem 'bootsnap', '~> 1.0', require: false
61
+ end
62
+
63
+ appraise "rails52_paperclip6x" do
64
+ gem "rails", "~> 5.2.0"
65
+ gem "paperclip", "~> 6.0"
66
+ gem 'capybara'
67
+ gem 'rspec'
68
+ gem 'sqlite3', '~> 1.3.0'
69
+ gem 'bootsnap', '~> 1.0', require: false
70
+ end
71
+
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ #gem 'aruba', :path => '../aruba'
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.md ADDED
@@ -0,0 +1,126 @@
1
+ Paperclip Database Storage
2
+ ==========================
3
+
4
+ [![Build Status](https://travis-ci.org/softace/paperclip_database.png)](http://travis-ci.org/softace/paperclip_database)
5
+ [![Gem Version](https://badge.fury.io/rb/paperclip_database.svg)](http://badge.fury.io/rb/paperclip_database)
6
+ [![Dependency Status](https://gemnasium.com/softace/paperclip_database.png)](https://gemnasium.com/softace/paperclip_database)
7
+ [![Code Climate](https://codeclimate.com/github/softace/paperclip_database.png)](https://codeclimate.com/github/softace/paperclip_database)
8
+
9
+ Paperclip Database Storage is an additional storage option for
10
+ Paperclip. It gives you the opportunity to store your paperclip binary
11
+ file uploads in the database along with all your other data.
12
+
13
+ Requirements
14
+ ------------
15
+
16
+ `paperclip_database` depends on `paperclip`
17
+
18
+ It is recommended to use the
19
+ [trim_blobs](https://github.com/softace/trim_blobs) gem to limit the
20
+ logging of BLOB data in your logfiles.
21
+
22
+ Installation
23
+ ------------
24
+
25
+ Paperclip Database Storage is distributed as a gem, which is how it
26
+ should be used in your app.
27
+
28
+ Include the gem in your Gemfile:
29
+
30
+ gem "paperclip_database", "~> 2.0"
31
+
32
+ Or, if you want to get the latest, you can get master from the main
33
+ paperclip repository:
34
+
35
+ gem "paperclip_database", :git => "git://github.com/softace/paperclip_database.git"
36
+
37
+ If you're trying to use features that don't seem to be in the latest
38
+ released gem, but are mentioned in this README, then you probably need
39
+ to specify the master branch if you want to use them. This README is
40
+ probably ahead of the latest released version, if you're reading it on
41
+ GitHub.
42
+
43
+ Supported Versions
44
+ ------------------
45
+
46
+ As of version 2.0, Rails 2 is no longer supported.
47
+ As of version 3.0, Rails 3 is no longer supported.
48
+ Supported versions are rails from >= 4.2 to < 6.0 and paperclip version >= 2.3
49
+ As Paperclip is deprecated and final rails support for that was rails 5.x this gem will equally no longer going to be updated to more than rails 5.x
50
+
51
+
52
+
53
+
54
+ Quick Start
55
+ -----------
56
+
57
+ There is no quick start. You definitely need to understand how to use
58
+ paperclip first.
59
+
60
+ Usage
61
+ -----
62
+
63
+ You use `paperclip_database` by specifying `database` as storage for
64
+ your paperclip and create a migration for the additional database
65
+ table.
66
+
67
+ In your model:
68
+
69
+ class User < ActiveRecord::Base
70
+ has_attached_file :avatar,
71
+ :storage => :database ## This is the essence
72
+ :styles => { :medium => "300x300>", :thumb => "100x100>" }
73
+ end
74
+
75
+ There is a migration generator that will create a basic migration for
76
+ the extra table.
77
+
78
+ On the console (rails 3):
79
+
80
+ bundle exec ./script/rails generate paperclip_database:migration User avatar
81
+
82
+ The generated migration should be sufficient, but you may consider
83
+ adding additional code to the migration such as `t.timestamps` for
84
+ adding standard rails timesstamps or a referential database
85
+ constraint, or an index on the foreign key id column. If you add a
86
+ refferential constraint with the option `ON DELETE CASCADE`, then you
87
+ need to add the option `:cascade_deletion => true` to your paperclip
88
+ `has_attached_file` declaration to let PaperclipDatabase know that the
89
+ Database takes care of it. Otherwise PaperclipDatabase will do the
90
+ cascade deletion.
91
+
92
+ Development
93
+ -----------
94
+
95
+ To start develop, please download the source code
96
+
97
+ git clone git://github.com/softace/paperclip_database.git
98
+
99
+ When downloaded, you can start issuing the commands like
100
+
101
+ bundle install
102
+ bundle exec appraisal clean
103
+ bundle exec appraisal generate
104
+ bundle exec appraisal install
105
+ bundle exec appraisal rake
106
+
107
+ Or you can see what other options are there:
108
+
109
+ bundle exec rake -T
110
+
111
+
112
+ History
113
+ -------
114
+
115
+ Paperclip Database Storage is heavily inspired by [this blog by Pat
116
+ Shaughnessy](http://patshaughnessy.net/2009/2/19/database-storage-for-paperclip). The
117
+ initial source code for that blog is no longer available, but the code
118
+ in this gem is based on that initial code.
119
+
120
+
121
+
122
+ Copyright
123
+ ---------
124
+
125
+ Copyright (c) 2012 Jarl Friis. See LICENSE.txt for
126
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'appraisal'
3
+ require 'rspec/core/rake_task'
4
+ require 'cucumber/rake/task'
5
+
6
+ desc 'Default: clean, appraisal:install, all.'
7
+ task :default => [:clean, :all]
8
+
9
+ desc 'Test the paperclip_database plugin under all supported Rails versions.'
10
+ task :all do |t|
11
+ if ENV['BUNDLE_GEMFILE']
12
+ exec('rake spec cucumber')
13
+ else
14
+ exec("rm gemfiles/*.lock")
15
+ Rake::Task["appraisal:gemfiles"].execute
16
+ Rake::Task["appraisal:install"].execute
17
+ exec('rake appraisal')
18
+ end
19
+ end
20
+
21
+ desc 'Test the paperclip_database plugin.'
22
+ RSpec::Core::RakeTask.new(:spec)
23
+
24
+ desc 'Run integration test'
25
+ Cucumber::Rake::Task.new do |t|
26
+ t.cucumber_opts = %w{--format progress}
27
+ end
28
+
29
+ desc 'Start an IRB session with all necessary files required.'
30
+ task :shell do |t|
31
+ chdir File.dirname(__FILE__)
32
+ exec 'irb -I lib/ -I lib/paperclip_database -r rubygems -r active_record -r paperclip -r tempfile -r init'
33
+ end
34
+
35
+ desc 'Clean up files.'
36
+ task :clean do |t|
37
+ FileUtils.rm_rf "doc"
38
+ FileUtils.rm_rf "tmp"
39
+ FileUtils.rm_rf "pkg"
40
+ FileUtils.rm_rf "public"
41
+ Dir.glob("paperclip_database-*.gem").each{|f| FileUtils.rm f }
42
+ end
@@ -0,0 +1,45 @@
1
+ Feature: Rails integration
2
+
3
+ Background:
4
+ Given I generate a new rails application
5
+ And I run a "scaffold" generator to generate a "User" scaffold with "name:string"
6
+ And I run a "paperclip" generator to add a paperclip "avatar" 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
+ And I allow the attachment to be submitted
11
+
12
+ Scenario: Database integration test
13
+ Given I add this snippet to the User model:
14
+ """
15
+ has_attached_file :avatar,
16
+ :storage => :database,
17
+ :url => '/avatar_views/:id?style=:style'
18
+ validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
19
+ """
20
+ And I run a "scaffold" generator to generate a "AvatarView" scaffold with ""
21
+ Given I replace /^ def show$.*?^ end$/ with this snippet in the "avatar_views" controller:
22
+ """
23
+ def show
24
+ style = params[:style] ? params[:style] : 'original'
25
+ record = User.find(params[:id])
26
+ raise 'Error' unless record.avatar.exists?(style)
27
+ send_data record.avatar.file_contents(style),
28
+ :filename => record.avatar_file_name,
29
+ :type => record.avatar_content_type
30
+ end
31
+ """
32
+ Given I replace /before_action :set_avatar_view.*?$/ with this snippet in the "avatar_views" controller:
33
+ """
34
+ """
35
+
36
+ And I run a "paperclip_database:migration" generator to create storage for paperclip "avatar" to the "User" model
37
+ And I run a migration
38
+ And I start the rails application
39
+ When I go to the new user page
40
+ And I fill in "Name" with "something"
41
+ And I attach the file "spec/fixtures/5k.png" to "Avatar"
42
+ And I press "Submit"
43
+ Then I should see "Name: something"
44
+ And I should see an image with a path of "/avatar_views/1"
45
+ And the file at "/avatar_views/1" should be the same as "spec/fixtures/5k.png"
@@ -0,0 +1,15 @@
1
+ Then %r{I should see an image with a path of "([^"]*)"} do |path|
2
+ expect(page).to 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
+ expect(actual).to eq expected
15
+ end
@@ -0,0 +1,209 @@
1
+ Given /^I generate a new rails application$/ do
2
+ steps %{
3
+ When I successfully 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 fix the application.rb for 3.0.12
7
+ And I remove turbolinks
8
+ And I empty the application.js file
9
+ And I configure the application to use "paperclip_database" from this project
10
+ And I reset Bundler environment variable
11
+ And I successfully run `bundle install --local`
12
+ }
13
+ end
14
+
15
+ Given "I fix the application.rb for 3.0.12" do
16
+ ##See https://github.com/rails/rails/issues/9619
17
+ in_current_directory do
18
+ File.open("config/application.rb", "a") do |f|
19
+ f << "ActionController::Base.config.relative_url_root = ''"
20
+ end
21
+ end
22
+ end
23
+
24
+ Given "I allow the attachment to be submitted" do
25
+ in_current_directory do
26
+ if framework_major_version == 3
27
+ transform_file("app/models/user.rb") do |content|
28
+ content.gsub("attr_accessible :name",
29
+ "attr_accessible :name, :avatar")
30
+ end
31
+ else
32
+ transform_file("app/controllers/users_controller.rb") do |content|
33
+ content.gsub("params.require(:user).permit(:name)",
34
+ "params.require(:user).permit!")
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ Given "I remove turbolinks" do
41
+ in_current_directory do
42
+ transform_file("app/assets/javascripts/application.js") do |content|
43
+ content.gsub("//= require turbolinks", "")
44
+ end
45
+ transform_file("app/views/layouts/application.html.erb") do |content|
46
+ content.gsub(', "data-turbolinks-track" => true', "")
47
+ end
48
+ end
49
+ end
50
+
51
+ Given "I empty the application.js file" do
52
+ in_current_directory do
53
+ transform_file("app/assets/javascripts/application.js") do |content|
54
+ ""
55
+ end
56
+ end
57
+ end
58
+
59
+ Given /^I run a "(.*?)" generator to generate a "(.*?)" scaffold with "(.*?)"$/ do |generator_name, model_name, attributes|
60
+ step %[I successfully run `bundle exec #{generator_command} #{generator_name} #{model_name} #{attributes}`]
61
+ end
62
+
63
+ Given /^I run a "(.*?)" generator to add a paperclip "(.*?)" to the "(.*?)" model$/ do |generator_name, attachment_name, model_name|
64
+ step %[I successfully run `bundle exec #{generator_command} #{generator_name} #{model_name} #{attachment_name}`]
65
+ end
66
+
67
+ Given /^I run a "(.*?)" generator to create storage for paperclip "(.*?)" to the "(.*?)" model$/ do |generator_name, attachment_name, model_name|
68
+ step %[I successfully run `bundle exec #{generator_command} #{generator_name} #{model_name} #{attachment_name}`]
69
+ end
70
+
71
+ Given /^I run a migration$/ do
72
+ step %[I successfully run `bundle exec rake db:migrate`]
73
+ end
74
+
75
+ Given /^I update my new user view to include the file upload field$/ do
76
+ steps %{
77
+ Given I overwrite "app/views/users/new.html.erb" with:
78
+ """
79
+ <%= form_for @user, :html => { :multipart => true } do |f| %>
80
+ <%= f.label :name %>
81
+ <%= f.text_field :name %>
82
+ <%= f.label :avatar %>
83
+ <%= f.file_field :avatar %>
84
+ <%= submit_tag "Submit" %>
85
+ <% end %>
86
+ """
87
+ }
88
+ end
89
+
90
+ Given /^I update my user view to include the attachment$/ do
91
+ steps %{
92
+ Given I overwrite "app/views/users/show.html.erb" with:
93
+ """
94
+ <p>Name: <%= @user.name %></p>
95
+ <p>Avatar: <%= image_tag @user.avatar.url %></p>
96
+ """
97
+ }
98
+ end
99
+
100
+ Given /^I add this snippet to the User model:$/ do |snippet|
101
+ file_name = "app/models/user.rb"
102
+ in_current_directory do
103
+ content = File.read(file_name)
104
+ File.open(file_name, 'w') { |f| f << content.sub(/end\Z/, "#{snippet}\nend") }
105
+ end
106
+ end
107
+
108
+ Given /^I replace \/(.*?)\/ with this snippet in the "(.*?)" controller:$/ do |pattern, controller_name, snippet|
109
+ in_current_directory do
110
+ transform_file("app/controllers/#{controller_name}_controller.rb") do |content|
111
+ content.gsub(Regexp.new(pattern, Regexp::MULTILINE), snippet)
112
+ end
113
+ end
114
+ end
115
+
116
+ Given /^I start the rails application$/ do
117
+ in_current_directory do
118
+ require "./config/environment"
119
+ require "capybara/rails"
120
+ end
121
+ end
122
+
123
+ Given /^I reload my application$/ do
124
+ Rails::Application.reload!
125
+ end
126
+
127
+ When %r{I turn off class caching} do
128
+ in_current_directory do
129
+ file = "config/environments/test.rb"
130
+ config = IO.read(file)
131
+ config.gsub!(%r{^\s*config.cache_classes.*$},
132
+ "config.cache_classes = false")
133
+ File.open(file, "w"){|f| f.write(config) }
134
+ end
135
+ end
136
+
137
+ Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path|
138
+ expected = IO.binread(path)
139
+ actual = if web_file.match %r{^https?://}
140
+ Net::HTTP.get(URI.parse(web_file))
141
+ else
142
+ visit(web_file)
143
+ page.source
144
+ end
145
+ expect(actual).to eq expected
146
+ end
147
+
148
+ When /^I configure the application to use "([^\"]+)" from this project$/ do |name|
149
+ append_to_gemfile "gem '#{name}', :path => '#{PROJECT_ROOT}'"
150
+ steps %{And I run `bundle install --local`}
151
+ end
152
+
153
+ When /^I configure the application to use "([^\"]+)"$/ do |gem_name|
154
+ append_to_gemfile "gem '#{gem_name}'"
155
+ end
156
+
157
+ When /^I append gems from Appraisal Gemfile$/ do
158
+ File.read(ENV['BUNDLE_GEMFILE']).split(/\n/).each do |line|
159
+ if line =~ /^gem "(?!rails|appraisal)/
160
+ append_to_gemfile line.strip
161
+ end
162
+ end
163
+ end
164
+
165
+ When /^I comment out the gem "(.*?)" from the Gemfile$/ do |gemname|
166
+ comment_out_gem_in_gemfile gemname
167
+ end
168
+
169
+ Then /^the result of "(.*?)" should be the same as "(.*?)"$/ do |rails_expr, path|
170
+ expected = IO.binread(path)
171
+ actual = eval "#{rails_expr}"
172
+ expect(actual).to eq expected
173
+ end
174
+
175
+
176
+ module FileHelpers
177
+ def append_to(path, contents)
178
+ in_current_directory do
179
+ File.open(path, "a") do |file|
180
+ file.puts
181
+ file.puts contents
182
+ end
183
+ end
184
+ end
185
+
186
+ def append_to_gemfile(contents)
187
+ append_to('Gemfile', contents)
188
+ end
189
+
190
+ def comment_out_gem_in_gemfile(gemname)
191
+ in_current_directory do
192
+ gemfile = File.read("Gemfile")
193
+ gemfile.sub!(/^(\s*)(gem\s*['"]#{gemname})/, "\\1# \\2")
194
+ File.open("Gemfile", 'w'){ |file| file.write(gemfile) }
195
+ end
196
+ end
197
+
198
+ def transform_file(filename)
199
+ if File.exists?(filename)
200
+ content = File.read(filename)
201
+ File.open(filename, "w") do |f|
202
+ content = yield(content)
203
+ f.write(content)
204
+ end
205
+ end
206
+ end
207
+ end
208
+
209
+ World(FileHelpers)