railsapp_factory 0.0.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.
- data/.gitignore +43 -0
- data/.travis.yml +36 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +168 -0
- data/Rakefile +8 -0
- data/lib/railsapp_factory/build_error.rb +7 -0
- data/lib/railsapp_factory/build_methods.rb +141 -0
- data/lib/railsapp_factory/class_methods.rb +155 -0
- data/lib/railsapp_factory/helper_methods.rb +118 -0
- data/lib/railsapp_factory/run_in_app_methods.rb +157 -0
- data/lib/railsapp_factory/server_methods.rb +82 -0
- data/lib/railsapp_factory/string_inquirer.rb +26 -0
- data/lib/railsapp_factory/template_methods.rb +54 -0
- data/lib/railsapp_factory/version.rb +3 -0
- data/lib/railsapp_factory.rb +50 -0
- data/railsapp_factory.gemspec +25 -0
- data/spec/railsapp_factory/class_methods_spec.rb +121 -0
- data/spec/railsapp_factory/helper_methods_spec.rb +124 -0
- data/spec/railsapp_factory/string_inquirer_spec.rb +24 -0
- data/spec/railsapp_factory/template_methods_spec.rb +98 -0
- data/spec/railsapp_factory_spec.rb +387 -0
- data/spec/spec_helper.rb +41 -0
- data/spec/templates/add-file.rb +6 -0
- data/spec/templates/add-ruby_version-controller.rb +9 -0
- data/spec/templates/add-yet-another-file.rb +6 -0
- data/templates/add_json_pure.rb +5 -0
- data/templates/add_necessary_gems.rb +55 -0
- data/templates/use_bundler_with_rails23.rb +187 -0
- metadata +157 -0
@@ -0,0 +1,55 @@
|
|
1
|
+
# Template to
|
2
|
+
# add javascript runtime
|
3
|
+
|
4
|
+
# Add both gems so that the application is suitable for jruby as well as MRI
|
5
|
+
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
gemfile = open('Gemfile').collect {|line| line.chomp}
|
9
|
+
gemfile0 = gemfile.dup
|
10
|
+
|
11
|
+
gemfile.each do |line|
|
12
|
+
# change to single quotes
|
13
|
+
line.sub!(/"([^"']+)"/, '\'\1\'')
|
14
|
+
line.sub!(/platform:/, ':platform =>')
|
15
|
+
line.sub!(/require:/, ':require =>')
|
16
|
+
# see http://docs.travis-ci.com/user/database-setup/
|
17
|
+
if line.sub!(/^\s*(gem\s*['"]sqlite3['"])\s*$/, '\1, :platform => [:ruby, :mswin, :mingw]')
|
18
|
+
puts "Changing gem sqlite to handle multiple platforms"
|
19
|
+
gemfile <<= "gem 'jdbc-sqlite3', platform: :jruby"
|
20
|
+
end
|
21
|
+
|
22
|
+
if line.sub!(/^\s*gem\s*['"]mysql2?['"]\s*$/, '\0, :platform => :ruby')
|
23
|
+
puts "Changing gem mysql to handle multiple platforms"
|
24
|
+
gemfile <<= "gem 'activerecord-jdbcmysql-adapter', platform: :jruby"
|
25
|
+
end
|
26
|
+
|
27
|
+
if line.sub!(/^[#\s]*(gem\s*['"]therubyracer['"])\s*$/, '\1, :platform => :ruby')
|
28
|
+
puts "Changing gem therubyracer to enable and handle multiple platforms"
|
29
|
+
gemfile <<= "gem 'therubyrhino', :platform => :jruby"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
gemfile <<= "gem 'therubyrhino', :platform => :jruby"
|
34
|
+
gemfile <<= "gem 'therubyracer', :platform => :ruby"
|
35
|
+
|
36
|
+
cleaned_up_gemfile = [ ]
|
37
|
+
gemfile.each do |line|
|
38
|
+
unless line =~ /^gem / && cleaned_up_gemfile.include?(line)
|
39
|
+
#puts "Keeping: [#{line}]"
|
40
|
+
cleaned_up_gemfile << line
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
if cleaned_up_gemfile != gemfile0
|
45
|
+
puts 'Updating Gemfile'
|
46
|
+
FileUtils.rm_f 'Gemfile.bak'
|
47
|
+
FileUtils.move 'Gemfile', 'Gemfile.bak'
|
48
|
+
File.open('Gemfile', 'w') do |f|
|
49
|
+
cleaned_up_gemfile.each do |line|
|
50
|
+
f.puts line
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
@@ -0,0 +1,187 @@
|
|
1
|
+
# Template to
|
2
|
+
# 1. update rails 2.3 to using bundler as per http://bundler.io/v1.5/rails23.html
|
3
|
+
# - copies gem details from config/environment.rb to Gemfile and comments them out in environment.rb file
|
4
|
+
# 2. fix broken require in Rakefile
|
5
|
+
# 3. update to rails-lts (unless RAILS_LTS env var is set to false)
|
6
|
+
#
|
7
|
+
# Template is safe to apply multiple times
|
8
|
+
|
9
|
+
|
10
|
+
file 'config/preinitializer.rb', <<-EOF
|
11
|
+
|
12
|
+
begin
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler'
|
15
|
+
rescue LoadError
|
16
|
+
raise "Could not load the bundler gem. Install it with `gem install bundler`."
|
17
|
+
end
|
18
|
+
|
19
|
+
if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24")
|
20
|
+
raise RuntimeError, "Your bundler version is too old for Rails 2.3.\n" +
|
21
|
+
"Run `gem install bundler` to upgrade."
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
# Set up load paths for all bundled gems
|
26
|
+
ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
|
27
|
+
Bundler.setup
|
28
|
+
rescue Bundler::GemNotFound
|
29
|
+
raise RuntimeError, "Bundler couldn't find some gems.\n" +
|
30
|
+
"Did you run `bundle install`?"
|
31
|
+
end
|
32
|
+
|
33
|
+
EOF
|
34
|
+
|
35
|
+
INSERT_INTO_BOOT = <<-EOF
|
36
|
+
|
37
|
+
class Rails::Boot
|
38
|
+
def run
|
39
|
+
load_initializer
|
40
|
+
|
41
|
+
Rails::Initializer.class_eval do
|
42
|
+
def load_gems
|
43
|
+
@bundler_loaded ||= Bundler.require :default, Rails.env
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
Rails::Initializer.run(:set_load_path)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
EOF
|
52
|
+
|
53
|
+
file_name = 'config/boot.rb'
|
54
|
+
mentions_bundler = false
|
55
|
+
File.open(file_name).each do |line|
|
56
|
+
mentions_bundler ||= line =~ /Bundler\./
|
57
|
+
end
|
58
|
+
|
59
|
+
unless mentions_bundler
|
60
|
+
puts " updating #{file_name} - inserting bundler code"
|
61
|
+
bak_name = file_name + '.without_bundler'
|
62
|
+
unless File.exists? bak_name
|
63
|
+
FileUtils.move file_name, bak_name
|
64
|
+
File.open(file_name, 'w') do |f|
|
65
|
+
File.open(bak_name).each do |line|
|
66
|
+
if line =~ /Rails.boot!/
|
67
|
+
f.puts INSERT_INTO_BOOT
|
68
|
+
end
|
69
|
+
f.puts line
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Check what has already been done
|
76
|
+
has_source = false
|
77
|
+
has_gem = {}
|
78
|
+
if File.exists? 'Gemfile'
|
79
|
+
File.open('Gemfile', 'r').each do |line|
|
80
|
+
has_source ||= line =~ /^\s*source\s/
|
81
|
+
if line =~ /^\s*gem\s+['"]([^'"]+)['"]/
|
82
|
+
has_gem[$1] = line
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
#update Gemfile based on what is in config/environment.rb
|
88
|
+
File.open('Gemfile', 'a+') do |gemfile|
|
89
|
+
unless has_source
|
90
|
+
gemfile.puts "source '#{ENV['GEM_SOURCE'] || 'https://rubygems.org'}'"
|
91
|
+
end
|
92
|
+
|
93
|
+
# make sure rails is in the gem list
|
94
|
+
unless has_gem['rails']
|
95
|
+
rails_gem_version = nil
|
96
|
+
open('config/environment.rb').each do |line|
|
97
|
+
if line =~ /^RAILS_GEM_VERSION\s*=\s*\D(2\.3\.\d+)\D/
|
98
|
+
rails_gem_version = $1
|
99
|
+
end
|
100
|
+
end
|
101
|
+
rails_gem_version ||= '2.3.18'
|
102
|
+
|
103
|
+
if ENV['RAILS_LTS'] == 'false'
|
104
|
+
# a different version has been deliberately picked
|
105
|
+
has_gem['rails'] = "gem 'rails', '#{rails_gem_version}'"
|
106
|
+
gemfile.puts has_gem['rails']
|
107
|
+
puts " updating Gemfile - adding rails gem #{rails_gem_version}"
|
108
|
+
else
|
109
|
+
has_gem['rails'] = "gem 'rails', :git => 'git://github.com/makandra/rails.git', :branch => '2-3-lts'"
|
110
|
+
gemfile.puts has_gem['rails']
|
111
|
+
if rails_gem_version != '2.3.18'
|
112
|
+
puts 'WARNING - RAILS_GEM_VERSION needs to be updated to 2.3.18 in config/environment.rb!'
|
113
|
+
end
|
114
|
+
puts " updating Gemfile - adding rails gem #{rails_gem_version}-lts"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# make sure database adapters are in the list
|
119
|
+
open('config/database.yml').each do |line|
|
120
|
+
if line =~ /^\s*adapter:\s*['"]?([^'"\s]+)/
|
121
|
+
adapter = $1
|
122
|
+
unless has_gem[adapter]
|
123
|
+
gemfile.puts "gem '#{adapter}' # used in database.yml"
|
124
|
+
puts " updating Gemfile - adding #{adapter} gem # used in database.yml"
|
125
|
+
has_gem[adapter] = true
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# copy over other gem definitions
|
131
|
+
file_name = 'config/environment.rb'
|
132
|
+
bak_name = file_name + '.bak'
|
133
|
+
FileUtils.rm_f bak_name
|
134
|
+
FileUtils.move file_name, bak_name
|
135
|
+
File.open(file_name, 'w') do |f|
|
136
|
+
File.open(bak_name, 'r').each do |line|
|
137
|
+
if line =~ /^([\s#]*)config\.(gem.*)/
|
138
|
+
prefix = $1
|
139
|
+
command = $2
|
140
|
+
prefix.sub!(/^\s+/, '')
|
141
|
+
command.sub!(/:version *=>/, ' ')
|
142
|
+
command.sub!(/:lib/, ':require')
|
143
|
+
command.sub!(/require:/, ':require => ')
|
144
|
+
command.sub!(/lib:/, ':lib => ')
|
145
|
+
if line =~ /^\s*config.gem\s+['"]([^'"]+)['"]/
|
146
|
+
prefix = '# ' if has_gem[$1]
|
147
|
+
has_gem[$1] = line
|
148
|
+
puts " updating Gemfile - adding #{$1} gem" if prefix !~ /#/
|
149
|
+
end
|
150
|
+
gemfile.puts "#{prefix}#{command} # converted from: #{line}"
|
151
|
+
f.print '# Moved to Gemfile: '
|
152
|
+
end
|
153
|
+
f.puts line
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
unless has_gem['json_pure']
|
158
|
+
gemfile.puts "gem 'json_pure' # used by RailsapFactory *_eval methods"
|
159
|
+
puts ' updating Gemfile - adding json_pure gem # used by RailsapFactory *_eval methods'
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
# Fix ERROR: 'rake/rdoctask' is obsolete and no longer supported. Use 'rdoc/task' (available in RDoc 2.4.2+) instead.
|
165
|
+
# .../railsapp/Rakefile:8
|
166
|
+
|
167
|
+
file_name = 'Rakefile'
|
168
|
+
bak_name = file_name + '.bak'
|
169
|
+
unless File.exists? bak_name
|
170
|
+
FileUtils.move file_name, bak_name
|
171
|
+
File.open(file_name, 'w') do |f|
|
172
|
+
File.open(bak_name, 'r').each do |line|
|
173
|
+
if line =~ /rake.rdoctask/
|
174
|
+
line = "# require 'rdoc/task' # replaces outs of date: #{line}"
|
175
|
+
puts ' updating Rakefile - fixing rake/rdoctask line'
|
176
|
+
end
|
177
|
+
f.puts line
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
%w{Gemfile config/environment.rb Rakefile}.each do |file|
|
183
|
+
puts '=' * 50, file, '=' * 50
|
184
|
+
puts File.read(file)
|
185
|
+
end
|
186
|
+
puts '=' * 50, 'END OF TEMPLATE'
|
187
|
+
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: railsapp_factory
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ian Heggie
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-03-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json_pure
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.12'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '2.12'
|
78
|
+
description: Rails application factory to make testing gems against multiple versions
|
79
|
+
easier
|
80
|
+
email:
|
81
|
+
- ian@heggie.biz
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- .travis.yml
|
88
|
+
- Gemfile
|
89
|
+
- LICENSE.txt
|
90
|
+
- README.md
|
91
|
+
- Rakefile
|
92
|
+
- lib/railsapp_factory.rb
|
93
|
+
- lib/railsapp_factory/build_error.rb
|
94
|
+
- lib/railsapp_factory/build_methods.rb
|
95
|
+
- lib/railsapp_factory/class_methods.rb
|
96
|
+
- lib/railsapp_factory/helper_methods.rb
|
97
|
+
- lib/railsapp_factory/run_in_app_methods.rb
|
98
|
+
- lib/railsapp_factory/server_methods.rb
|
99
|
+
- lib/railsapp_factory/string_inquirer.rb
|
100
|
+
- lib/railsapp_factory/template_methods.rb
|
101
|
+
- lib/railsapp_factory/version.rb
|
102
|
+
- railsapp_factory.gemspec
|
103
|
+
- spec/railsapp_factory/class_methods_spec.rb
|
104
|
+
- spec/railsapp_factory/helper_methods_spec.rb
|
105
|
+
- spec/railsapp_factory/string_inquirer_spec.rb
|
106
|
+
- spec/railsapp_factory/template_methods_spec.rb
|
107
|
+
- spec/railsapp_factory_spec.rb
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
- spec/templates/add-file.rb
|
110
|
+
- spec/templates/add-ruby_version-controller.rb
|
111
|
+
- spec/templates/add-yet-another-file.rb
|
112
|
+
- templates/add_json_pure.rb
|
113
|
+
- templates/add_necessary_gems.rb
|
114
|
+
- templates/use_bundler_with_rails23.rb
|
115
|
+
homepage: ''
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ! '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
segments:
|
129
|
+
- 0
|
130
|
+
hash: 1127916945110373028
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ! '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
segments:
|
138
|
+
- 0
|
139
|
+
hash: 1127916945110373028
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 1.8.23.2
|
143
|
+
signing_key:
|
144
|
+
specification_version: 3
|
145
|
+
summary: The prupose of this gem is to make integration testing of gems and libraries
|
146
|
+
against multiple versions of rails easy and avoid having to keep copies of the framework
|
147
|
+
in the gem being tested
|
148
|
+
test_files:
|
149
|
+
- spec/railsapp_factory/class_methods_spec.rb
|
150
|
+
- spec/railsapp_factory/helper_methods_spec.rb
|
151
|
+
- spec/railsapp_factory/string_inquirer_spec.rb
|
152
|
+
- spec/railsapp_factory/template_methods_spec.rb
|
153
|
+
- spec/railsapp_factory_spec.rb
|
154
|
+
- spec/spec_helper.rb
|
155
|
+
- spec/templates/add-file.rb
|
156
|
+
- spec/templates/add-ruby_version-controller.rb
|
157
|
+
- spec/templates/add-yet-another-file.rb
|