lurker 0.6.8 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +5 -5
  2. data/.hound.yml +4 -78
  3. data/.jshintrc +33 -0
  4. data/.rspec +1 -2
  5. data/.rubocop.yml +0 -1
  6. data/.travis.yml +30 -19
  7. data/Gemfile +0 -33
  8. data/README.md +32 -53
  9. data/Rakefile +3 -3
  10. data/cucumber.yml +1 -2
  11. data/features/atom_persistent_within_the_same_type.feature +4 -4
  12. data/features/controller_nested_schema_scaffolding.feature +7 -10
  13. data/features/controller_schema_scaffolding.feature +1 -3
  14. data/features/dereferencing_through_inlining.feature +1 -3
  15. data/features/html_generation.feature +26 -4
  16. data/features/minitest.feature +3 -8
  17. data/features/multidomain_support.feature +6 -10
  18. data/features/multitype_request_support.feature +1 -3
  19. data/features/partials.feature +3 -8
  20. data/features/request_nested_schema_scaffolding.feature +0 -2
  21. data/features/request_schema_scaffolding.feature +0 -2
  22. data/features/schema_suffixes.feature +2 -18
  23. data/features/schema_updating_within_test_suite.feature +2 -6
  24. data/features/step_definitions/additional_cli_steps.rb +16 -12
  25. data/features/support/env.rb +50 -10
  26. data/features/test_endpoint.feature +2 -9
  27. data/gemfiles/rails_4.gemfile +14 -0
  28. data/gemfiles/rails_5.gemfile +10 -0
  29. data/gemfiles/rails_6.gemfile +10 -0
  30. data/lib/lurker.rb +9 -2
  31. data/lib/lurker/cli.rb +148 -128
  32. data/lib/lurker/endpoint.rb +11 -7
  33. data/lib/lurker/form_builder.rb +22 -31
  34. data/lib/lurker/json/concerns/validatable.rb +5 -1
  35. data/lib/lurker/json/parser.rb +1 -1
  36. data/lib/lurker/json/schema.rb +19 -6
  37. data/lib/lurker/json/{writter.rb → writer.rb} +2 -2
  38. data/lib/lurker/presenters/base_presenter.rb +10 -34
  39. data/lib/lurker/presenters/endpoint_presenter.rb +19 -8
  40. data/lib/lurker/presenters/schema_presenter.rb +6 -5
  41. data/lib/lurker/presenters/service_presenter.rb +41 -7
  42. data/lib/lurker/rendering_controller.rb +14 -7
  43. data/lib/lurker/service.rb +27 -11
  44. data/lib/lurker/spec_helper/rspec.rb +0 -4
  45. data/lib/lurker/spy.rb +3 -1
  46. data/lib/lurker/templates/documentation.md.tt +1 -0
  47. data/lib/lurker/templates/javascripts/lurker.js +133 -91
  48. data/lib/lurker/templates/layouts/_sidemenu.html.erb +2 -2
  49. data/lib/lurker/templates/layouts/application.html.erb +54 -57
  50. data/lib/lurker/templates/layouts/print.html.erb +31 -0
  51. data/lib/lurker/templates/lurker/rendering/_endpoint.html.erb +37 -0
  52. data/lib/lurker/templates/lurker/rendering/_param_form_element.html.erb +1 -1
  53. data/lib/lurker/templates/lurker/rendering/_service.html.erb +7 -0
  54. data/lib/lurker/templates/lurker/rendering/_submit_form.html.erb +77 -73
  55. data/lib/lurker/templates/lurker/rendering/all.html.erb +5 -0
  56. data/lib/lurker/templates/lurker/rendering/index.html.erb +1 -10
  57. data/lib/lurker/templates/lurker/rendering/show.html.erb +1 -37
  58. data/lib/lurker/templates/public/application.css +6 -2
  59. data/lib/lurker/templates/public/application.js +13 -13
  60. data/lib/lurker/templates/stylesheets/application.scss +3 -0
  61. data/lib/lurker/version.rb +1 -1
  62. data/lurker.gemspec +31 -33
  63. data/spec/spec_helper.rb +0 -1
  64. data/tasks/build.rake +12 -8
  65. data/tasks/generate.rake +44 -17
  66. data/templates/Dockerfile +26 -0
  67. data/templates/generate_stuff.rb +59 -26
  68. data/templates/lurker_app.rb +27 -48
  69. data/templates/rails4_ruby26_thread_error_fix.rb +20 -0
  70. metadata +149 -106
  71. checksums.yaml.gz.sig +0 -2
  72. data.tar.gz.sig +0 -3
  73. data/Appraisals +0 -20
  74. data/gemfiles/rails_32.gemfile +0 -27
  75. data/gemfiles/rails_40.gemfile +0 -27
  76. data/gemfiles/rails_41.gemfile +0 -27
  77. data/gemfiles/rails_42.gemfile +0 -27
  78. data/lib/lurker/templates/lurker/rendering/_param_form_legend.html.erb +0 -1
  79. data/lib/lurker/templates/meta_service.md.erb +0 -20
  80. data/lib/lurker/validation_error.rb +0 -4
  81. data/templates/rails32_http_patch_support.rb +0 -125
  82. metadata.gz.sig +0 -0
@@ -15,7 +15,6 @@ end
15
15
  Dir[File.expand_path '../support/**/*.rb', __FILE__].each { |file| require file }
16
16
 
17
17
  RSpec.configure do |config|
18
- config.treat_symbols_as_metadata_keys_with_true_values = true
19
18
  config.run_all_when_everything_filtered = true
20
19
  config.filter_run :focus
21
20
  config.order = 'random'
@@ -8,13 +8,13 @@ namespace :assets do
8
8
  require 'lurker/cli'
9
9
 
10
10
  require 'sprockets'
11
- require 'sass'
11
+ require 'sass-rails'
12
12
 
13
13
  ROOT = Pathname(File.dirname(__FILE__))
14
14
  LOGGER = Logger.new(STDOUT)
15
15
  BUNDLES = %w( application.css application.js )
16
- BUILD_DIR = Pathname.new Lurker::Cli.precompiled_static_root
17
- SOURCE_DIR = Pathname.new Lurker::Cli.source_root
16
+ BUILD_DIR = Lurker::Cli.assets_root
17
+ SOURCE_DIR = Lurker::Cli.templates_root
18
18
 
19
19
  FileUtils.rm_rf(BUILD_DIR)
20
20
  FileUtils.mkdir_p(BUILD_DIR)
@@ -38,8 +38,10 @@ namespace :assets do
38
38
  sprockets.append_path(SOURCE_DIR.join('stylesheets').to_s)
39
39
 
40
40
  %w[jquery-rails bootstrap-sass remotipart lurker].each do |gem|
41
- gem_path = Pathname.new(Bundler.rubygems.find_name(gem).first.full_gem_path)
42
- %w[javascripts stylesheets].each do |prefix|
41
+ bundler_gem = Bundler.rubygems.find_name(gem).first
42
+ raise "Gem #{gem.inspect} is required in #{ENV.fetch('BUNDLE_GEMFILE', 'Gemfile')}" unless bundler_gem
43
+ gem_path = Pathname.new(bundler_gem.full_gem_path)
44
+ %w[javascripts stylesheets fonts].each do |prefix|
43
45
  %w[assets vendor/assets lib/lurker/templates].each do |interfix|
44
46
  path = gem_path.join(interfix, prefix).to_s
45
47
  sprockets.append_path(path) if File.exists? path
@@ -47,12 +49,14 @@ namespace :assets do
47
49
  end
48
50
  end
49
51
 
50
- sprockets.js_compressor = :uglify
51
- sprockets.css_compressor = :scss
52
+ unless ENV['CI']
53
+ sprockets.js_compressor = :uglify
54
+ sprockets.css_compressor = :scss
55
+ end
52
56
 
53
57
  BUNDLES.each do |bundle|
54
58
  assets = sprockets.find_asset(bundle)
55
- realname = (assets.pathname.basename.to_s.split(".").take_while { |s| !s.match /^(js|css|scss)$/ } + [$~.to_s]).join(".").gsub(/\.scss$/, '.css')
59
+ realname = (Pathname.new(assets.filename).basename.to_s.split(".").take_while { |s| !s.match /^(js|css|scss)$/ } + [$~.to_s]).join(".").gsub(/\.scss$/, '.css')
56
60
  assets.write_to(BUILD_DIR.join(realname))
57
61
  end
58
62
  end
@@ -1,7 +1,15 @@
1
- if rails_version = ENV['BUNDLE_GEMFILE'].to_s.match(/rails_\d\d/)
2
- EXAMPLE_APP = "tmp/lurker_app_#{rails_version}"
1
+ def rails_version
2
+ if (version = ENV['BUNDLE_GEMFILE'].to_s.match(/rails_([\d\.]+).gemfile/)&.to_a&.last)
3
+ Gem::Version.new(version)
4
+ end
5
+ end
6
+
7
+ if rails_version
8
+ EXAMPLE_APP = "tmp/lurker_app_rails_#{rails_version}"
9
+ TEMPLATE_TASK = rails_version >= Gem::Version.new('5.0') ? 'app:template' : 'rails:template'
10
+ TASK_RUNNER = rails_version >= Gem::Version.new('5.0') ? 'bin/rails' : 'bin/rake'
3
11
  else
4
- raise "Use `appraisal rails-XY rake ...` or export BUNDLE_GEMFILE=gemfiles/... explicitly"
12
+ raise "Export BUNDLE_GEMFILE=gemfiles/rails_... explicitly"
5
13
  end
6
14
 
7
15
  EXAMPLE_PATH = File.expand_path("../../#{EXAMPLE_APP}", __FILE__)
@@ -30,30 +38,33 @@ namespace :generate do
30
38
  task :app do |t|
31
39
  if needs_generation?
32
40
  sh "bundle exec rails new #{EXAMPLE_APP} -d postgresql -m #{File.expand_path '../../templates/lurker_app.rb', __FILE__} --skip-javascript --skip-git --skip-test-unit --skip-keeps --skip-bundle --quiet"
33
- in_lurker_app "bundle config --local local.lurker $PWD/../.." unless ENV['TRAVIS']
34
- in_lurker_app "bundle install --without development --quiet"
35
- %w[rake rspec-core spring].each do |gem|
36
- in_lurker_app "bundle binstubs #{gem}"
41
+ in_lurker_app "bundle config --local local.lurker $PWD/../.." unless ENV['CI']
42
+ in_lurker_app "bundle config --local set without 'development'"
43
+ in_lurker_app "bundle install"
44
+ %w[rake rspec-core spring bundler].each do |gem|
45
+ in_lurker_app "bundle binstubs #{gem} --force"
37
46
  end
38
47
  end
39
48
  end
40
49
 
41
50
  desc "generate a bunch of stuff with generators"
42
51
  task :stuff do
43
- in_lurker_app "LOCATION='../../templates/generate_stuff.rb' bin/rake rails:template --quiet --silent"
52
+ in_lurker_app "LOCATION='../../templates/generate_stuff.rb' #{TASK_RUNNER} #{TEMPLATE_TASK}"
44
53
 
45
- unless ENV['TRAVIS']
46
- in_lurker_app 'bin/rake db:setup'
47
- in_lurker_app 'bin/rake db:import'
54
+ if ENV['CI']
55
+ in_lurker_app "#{TASK_RUNNER} RAILS_ENV=test db:setup "
56
+ else
57
+ in_lurker_app "#{TASK_RUNNER} db:setup"
58
+ in_lurker_app "#{TASK_RUNNER} db:import"
48
59
  end
49
- in_lurker_app 'bin/rake RAILS_ENV=test db:setup'
50
60
  end
51
61
  end
52
62
 
53
63
  def in_lurker_app(command)
54
64
  FileUtils.mkdir_p(EXAMPLE_PATH)
55
65
  Dir.chdir(EXAMPLE_PATH) do
56
- Bundler.with_clean_env do
66
+ bundler_method = Bundler.respond_to?(:with_unbundled_env) ? :with_unbundled_env : :with_clean_env
67
+ Bundler.send(bundler_method) do
57
68
  sh command
58
69
  end
59
70
  end
@@ -63,23 +74,39 @@ def needs_generation?
63
74
  !File.exists?("#{EXAMPLE_PATH}/Gemfile")
64
75
  end
65
76
 
77
+ def place_github_badge(fname)
78
+ full_fname = "#{EXAMPLE_PATH}/#{fname}"
79
+ content = File.read(full_fname).gsub("</header>", <<-EOF
80
+ </header>
81
+ <a href='https://github.com/razum2um/lurker'>
82
+ <img style='position: absolute; top: 0; right: 0; border: 0; z-index: 1000'
83
+ src="https://camo.githubusercontent.com/365986a132ccd6a44c23a9169022c0b5c890c387/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f7265645f6161303030302e706e67"
84
+ data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png"
85
+ alt='Fork me on GitHub'>
86
+ </a>
87
+ EOF
88
+ )
89
+ File.open(full_fname, 'w') { |f| f.write content }
90
+ end
91
+
66
92
  desc 'destroys & recreates new test app'
67
- task :regenerate => ["clobber:coverage", "clobber:app", "generate:app", "generate:stuff"]
93
+ task :regenerate => ["clobber:coverage", "clobber:app", "assets:precompile", "generate:app", "generate:stuff"]
68
94
 
69
95
  desc 'run cucumber in a fresh env'
70
96
  task :features => [:regenerate, :cucumber]
71
97
 
72
98
  desc 'convert docs for example app, prepages gh-pages, having schemas in /lurker'
73
99
  task :convert_example_docs do
100
+ in_lurker_app "bin/lurker init_docs"
101
+
74
102
  if File.exists?(readme = File.expand_path('../../README.md', __FILE__))
75
103
  in_lurker_app "bin/lurker convert -c #{readme}"
76
104
  else
77
105
  in_lurker_app "bin/lurker convert"
78
106
  end
79
107
 
80
- in_lurker_app %Q{sed -i "" "s|</header>|</header><a href='https://github.com/razum2um/lurker'><img style='position: absolute; top: 0; right: 0; border: 0; z-index: 1000' src='https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png' alt='Fork me on GitHub'></a>|" public/lurker/index.html}
81
- in_lurker_app "bin/lurker convert -f pdf"
108
+ place_github_badge 'public/lurker/index.html'
109
+ # in_lurker_app "bin/lurker convert -f pdf"
82
110
  end
83
111
 
84
112
  task :build_example_docs => [:features, :convert_example_docs]
85
-
@@ -0,0 +1,26 @@
1
+ # cd tmp/lurker_app_*, run with
2
+ # docker run -e DATABASE_URL=postgres://user@host.docker.internal/lurker_app_rails_6 -p 3000:3000 lurker"
3
+ FROM ruby:2.7-alpine as build
4
+
5
+ WORKDIR /app
6
+
7
+ RUN apk add git postgresql-dev libpq
8
+
9
+ COPY Gemfile* ./
10
+
11
+ RUN apk add --no-cache --update alpine-sdk make && \
12
+ bundler config set without 'development test' && \
13
+ bundler config set path 'vendor/bundle' && \
14
+ bundler install
15
+
16
+ COPY . ./
17
+
18
+ EXPOSE 3000
19
+
20
+ ENV PATH "$PATH:/app/vendor/bundle/ruby/2.7.0/bin"
21
+ ENV GEM_HOME "/app/vendor/bundle/ruby/2.7.0"
22
+ ENV RAILS_ENV "production"
23
+ ENV RAILS_SERVE_STATIC_FILES "1"
24
+ ENV RAILS_LOG_TO_STDOUT "1"
25
+
26
+ CMD ["bin/rails", "s", "-b", "0.0.0.0"]
@@ -1,13 +1,12 @@
1
1
  # This is secondary testing/demo rails app template (passed to `rake rails:template`)
2
-
3
- if rails_version = ENV['BUNDLE_GEMFILE'].to_s.match(/rails_\d\d/)
2
+ if rails_version = ENV['BUNDLE_GEMFILE'].to_s.match(/rails_\d+/)
4
3
  base_db_name = "lurker_app_#{rails_version}"
5
4
  else
6
5
  base_db_name = 'lurker_app'
7
6
  end
8
7
 
9
8
  file 'config/database.yml', force: true do
10
- <<-CODE
9
+ <<~CODE
11
10
  default: &default
12
11
  adapter: postgresql
13
12
  encoding: unicode
@@ -25,7 +24,7 @@ end
25
24
 
26
25
  copy_file "#{File.expand_path '../../bin/lurker', __FILE__}", "bin/lurker"
27
26
  inject_into_file "bin/lurker", before: /require .lurker.$/ do
28
- <<-CODE
27
+ <<~CODE
29
28
  if (simplecov_root = ENV['SIMPLECOV_ROOT']) && (simplecov_cmdname = ENV['SIMPLECOV_CMDNAME'])
30
29
  require 'simplecov'
31
30
  SimpleCov.start
@@ -50,7 +49,7 @@ remove_file 'app/models/user.rb'
50
49
 
51
50
  generate 'rspec:install'
52
51
 
53
- route <<-ROUTE
52
+ route <<~ROUTE
54
53
  namespace :api do
55
54
  namespace :v1 do
56
55
  resources :users do
@@ -86,7 +85,7 @@ generate 'model User name:string surname:string --no-timestamps --no-test-framew
86
85
  generate 'model Repo user:references name:string --no-timestamps --no-test-framework --no-migration'
87
86
 
88
87
  file 'config/initializers/serializer.rb', force: true do
89
- <<-CODE
88
+ <<~CODE
90
89
  module ExactOrderAsJson
91
90
  # we need EXACT order for json attributes generation (e.g. rails32 sorts it)
92
91
  # see: https://github.com/rails/rails/pull/5678/files
@@ -109,10 +108,8 @@ file 'config/initializers/serializer.rb', force: true do
109
108
  CODE
110
109
  end
111
110
 
112
- copy_file "#{File.expand_path '../../templates/rails32_http_patch_support.rb', __FILE__}", "config/initializers/rails32_http_patch_support.rb"
113
-
114
111
  inject_into_class 'app/models/user.rb', 'User' do
115
- <<-CODE
112
+ <<~CODE
116
113
  include ExactOrderAsJson
117
114
  has_many :repos
118
115
  validates :name, presence: true
@@ -124,17 +121,17 @@ inject_into_class 'app/models/user.rb', 'User' do
124
121
  end
125
122
 
126
123
  inject_into_class 'app/models/repo.rb', 'Repo' do
127
- <<-CODE
124
+ <<~CODE
128
125
  include ExactOrderAsJson
129
126
  validates :name, presence: true
130
127
  CODE
131
128
  end
132
129
 
133
130
  file 'app/controllers/application_controller.rb', 'ApplicationController', force: true do
134
- <<-CODE
131
+ <<~CODE
135
132
  class ApplicationController < ActionController::Base
136
133
  protect_from_forgery with: :null_session
137
- before_filter :set_format
134
+ before_action :set_format
138
135
 
139
136
  private
140
137
 
@@ -154,7 +151,7 @@ file 'app/controllers/application_controller.rb', 'ApplicationController', force
154
151
  end
155
152
 
156
153
  file 'app/controllers/api/v1/users_controller.rb', 'Api::V1::UsersController', force: true do
157
- <<-CODE
154
+ <<~CODE
158
155
  class Api::V1::UsersController < ApplicationController
159
156
  def index
160
157
  @users = scoped(User)
@@ -174,7 +171,7 @@ file 'app/controllers/api/v1/users_controller.rb', 'Api::V1::UsersController', f
174
171
  end
175
172
 
176
173
  def update
177
- if user.update_attributes(user_params)
174
+ if user.update(user_params)
178
175
  render json: user
179
176
  else
180
177
  render json: { errors: user.errors }, status: :bad_request
@@ -209,7 +206,7 @@ file 'app/controllers/api/v1/users_controller.rb', 'Api::V1::UsersController', f
209
206
  end
210
207
 
211
208
  file 'app/controllers/api/v1/repos_controller.rb', 'Api::V1::ReposController', force: true do
212
- <<-CODE
209
+ <<~CODE
213
210
  class Api::V1::ReposController < ApplicationController
214
211
 
215
212
  def index
@@ -235,7 +232,7 @@ file 'app/controllers/api/v1/repos_controller.rb', 'Api::V1::ReposController', f
235
232
 
236
233
  def update
237
234
  @repo = repo
238
- if @repo.update_attributes(repo_params)
235
+ if @repo.update(repo_params)
239
236
  render json: @repo
240
237
  else
241
238
  render json: { errors: @repo.errors }, status: :bad_request
@@ -272,13 +269,13 @@ end
272
269
 
273
270
  [2, 3].each do |version|
274
271
  file "app/controllers/api/v#{version}/users_controller.rb", "Api::V#{version}::UsersController", force: true do
275
- <<-CODE
272
+ <<~CODE
276
273
  class Api::V#{version}::UsersController < Api::V1::UsersController; end
277
274
  CODE
278
275
  end
279
276
 
280
277
  file "app/controllers/api/v#{version}/repos_controller.rb", "Api::V#{version}::ReposController", force: true do
281
- <<-CODE
278
+ <<~CODE
282
279
  class Api::V#{version}::ReposController < Api::V1::ReposController; end
283
280
  CODE
284
281
  end
@@ -286,19 +283,19 @@ end
286
283
 
287
284
  # FIXME: uninitialized constant User (NameError) in last creation line
288
285
  append_to_file 'config/environment.rb' do
289
- <<-CODE
286
+ <<~CODE
290
287
  $:.unshift File.expand_path('../../app/models', __FILE__)
291
288
  CODE
292
289
  end
293
290
 
294
291
  inject_into_class 'config/application.rb', 'Application' do
295
- <<-CODE
292
+ <<~CODE
296
293
  if ENV['DATABASE_URL'].present? # heroku
297
294
  config.middleware.use Lurker::Sandbox
298
295
  end
299
296
 
300
297
  require 'rack/cors' # FIXME
301
- config.middleware.insert 0, "Rack::Cors" do
298
+ config.middleware.insert 0, Rack::Cors do
302
299
  allow do
303
300
  origins %w[localhost:3000 127.0.0.1:3000 razum2um.github.io lurker-app.herokuapp.com lurker.razum2um.me]
304
301
  resource '*',
@@ -314,7 +311,7 @@ inject_into_class 'config/application.rb', 'Application' do
314
311
  end
315
312
 
316
313
  file 'test/test_helper.rb', force: true do
317
- <<-CODE
314
+ <<~CODE
318
315
  ENV['RAILS_ENV'] ||= 'test'
319
316
  require File.expand_path('../../config/environment', __FILE__)
320
317
  require 'rails/test_help'
@@ -338,9 +335,16 @@ file 'test/test_helper.rb', force: true do
338
335
  end
339
336
 
340
337
  file 'spec/support/fixme.rb', force: true do
341
- <<-CODE
338
+ <<~CODE
342
339
  require 'simplecov'
343
340
 
341
+ module ActionDispatchTestResponseCompat
342
+ def success?
343
+ status == 200
344
+ end
345
+ end
346
+ ActionDispatch::TestResponse.include(ActionDispatchTestResponseCompat)
347
+
344
348
  if simplecov_root = ENV['SIMPLECOV_ROOT']
345
349
  SimpleCov.root simplecov_root
346
350
  end
@@ -362,7 +366,6 @@ file 'spec/support/fixme.rb', force: true do
362
366
 
363
367
  RSpec.configure do |c|
364
368
  c.infer_spec_type_from_file_location! if c.respond_to?(:infer_spec_type_from_file_location!)
365
- c.treat_symbols_as_metadata_keys_with_true_values = true
366
369
  c.backtrace_exclusion_patterns += [
367
370
  /\\/lib\\/lurker/
368
371
  ]
@@ -385,7 +388,7 @@ file 'spec/support/fixme.rb', force: true do
385
388
  end
386
389
 
387
390
  file 'lib/tasks/db.rake', force: true do
388
- <<-CODE
391
+ <<~CODE
389
392
  namespace :db do
390
393
  desc 'fills in data'
391
394
  task :import => :environment do
@@ -398,7 +401,7 @@ file 'lib/tasks/db.rake', force: true do
398
401
  end
399
402
 
400
403
  file 'db/schema.rb', force: true do
401
- <<-CODE
404
+ <<~CODE
402
405
  ActiveRecord::Schema.define do
403
406
  create_table "repos", :force => true do |t|
404
407
  t.integer "user_id"
@@ -415,3 +418,33 @@ file 'db/schema.rb', force: true do
415
418
  CODE
416
419
  end
417
420
 
421
+ append_to_file 'spec/rails_helper.rb' do
422
+ <<~CODE
423
+ Dir[File.expand_path '../support/**/*.rb', __FILE__].each { |file| require file }
424
+
425
+ if Gem::Version.new(Rails.version) < Gem::Version.new('5.0.0')
426
+ require 'rails/forward_compatible_controller_tests'
427
+ RSpec.configure do |config|
428
+ config.include Rails::ForwardCompatibleControllerTests, type: :controller
429
+ config.include Rails::ForwardCompatibleControllerTests, type: :request
430
+ end
431
+ end
432
+ CODE
433
+ end
434
+
435
+ append_to_file '.rspec' do
436
+ <<~CODE
437
+ --require rails_helper
438
+ CODE
439
+ end
440
+
441
+ copy_file "#{File.expand_path '../../templates/Dockerfile', __FILE__}", "Dockerfile"
442
+
443
+ # rails-4 requires this
444
+ file 'app/assets/config/manifest.js', force: true do
445
+ <<~CODE
446
+ // empty
447
+ CODE
448
+ end
449
+
450
+ copy_file "#{File.expand_path '../../templates/rails4_ruby26_thread_error_fix.rb', __FILE__}", "spec/support/rails4_ruby26_thread_error_fix.rb"
@@ -1,38 +1,37 @@
1
1
  # This is initial testing/demo rails app template (passed to `rails new`)
2
2
 
3
3
  gem 'rack-cors', require: 'rack/cors'
4
- gem 'rspec-rails', '~> 2.14.0'
5
- gem 'spring-commands-rspec'
6
- gem 'database_cleaner'
4
+ gem 'rspec-rails', group: [:development, :test]
5
+ gem 'spring-commands-rspec', group: [:development, :test]
6
+ gem 'database_cleaner', group: [:development, :test]
7
7
  gem 'simplecov', '~> 0.7.1', require: false
8
- gem 'kramdown', '~> 1.3'
9
- gem 'pdfkit', '~> 0.5'
10
- gem 'wkhtmltopdf-binary', '~> 0.9'
11
- gem 'execjs'
12
- gem 'coderay'
13
-
14
- unless ENV['TRAVIS']
15
- if RUBY_VERSION > '2.0.0'
16
- gem 'pry-byebug', group: [:development, :test]
17
- else
18
- gem 'pry-debugger', group: [:development, :test]
19
- end
20
- gem 'pry-stack_explorer', group: [:development, :test]
8
+ gem 'kramdown', '~> 1.3', group: [:development, :test]
9
+ gem 'pdfkit', '~> 0.5', group: [:development, :test]
10
+ gem 'wkhtmltopdf-binary', '~> 0.9', group: [:development, :test]
11
+ gem 'execjs', group: [:development, :test]
12
+ gem 'coderay', group: [:development, :test]
13
+
14
+ # only for rails-4
15
+ version = ENV['BUNDLE_GEMFILE'].to_s.match(/rails_([\d\.]+).gemfile/)&.to_a&.last
16
+ if version && (Gem::Version.new(version) < Gem::Version.new('5'))
17
+ gem 'rails-forward_compatible_controller_tests', group: [:development, :test], require: false
21
18
  end
22
19
 
23
- gem 'unicorn', group: :production
24
- gem 'therubyracer', group: :production
20
+ unless ENV['CI']
21
+ gem 'pry-byebug', group: [:development, :test]
22
+ end
25
23
 
26
24
  append_to_file 'Gemfile' do
27
- gem = if ENV['TRAVIS']
28
- "gem 'lurker', github: 'razum2um/lurker', branch: 'master'"
25
+ gem = if ENV['CI']
26
+ branch = ENV['TRAVIS_BRANCH'] || %x[git branch --show-current]
27
+ "gem 'lurker', github: 'razum2um/lurker', branch: '#{branch.strip}'"
29
28
  else
30
29
  origin = `cd ../.. && git config --get remote.origin.url`.scan(/github\.com.(.*).git/).flatten.first.strip rescue 'razum2um/lurker'
31
30
  branch = `cd ../.. && git rev-parse --abbrev-ref HEAD`.strip rescue 'master'
32
31
  "gem 'lurker', github: '#{origin}', branch: '#{branch}'"
33
32
  end
34
33
 
35
- <<-CODE
34
+ <<~CODE
36
35
 
37
36
  # new line above is important, branch is also important
38
37
  # please, dont commit here: "gem 'lurker', path: '../../'"
@@ -41,34 +40,14 @@ append_to_file 'Gemfile' do
41
40
  CODE
42
41
  end
43
42
 
44
- file 'config/unicorn.rb' do
45
- <<-CODE
46
- worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
47
- timeout 15
48
- preload_app true
49
-
50
- before_fork do |server, worker|
51
- Signal.trap 'TERM' do
52
- puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
53
- Process.kill 'QUIT', Process.pid
54
- end
55
-
56
- defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
57
- end
58
-
59
- after_fork do |server, worker|
60
- Signal.trap 'TERM' do
61
- puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
62
- end
63
-
64
- defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
65
- end
66
- CODE
67
- end
68
-
69
43
  file 'Procfile' do
70
- <<-CODE
71
- web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
44
+ <<~CODE
45
+ web: bundle exec puma -p $PORT
72
46
  CODE
73
47
  end
74
48
 
49
+ # docker needs with for mri too
50
+ gsub_file('Gemfile', /gem.*tzinfo-data.*/, 'gem "tzinfo-data"')
51
+
52
+ # pg 0.21 with rails-4 has too much warnings
53
+ gsub_file('Gemfile', "gem 'pg', '~> 0.15'", "gem 'pg', '<= 0.20'")