appmap 0.35.1 → 0.38.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +1 -1
  3. data/.gitignore +2 -1
  4. data/.rubocop.yml +10 -0
  5. data/CHANGELOG.md +22 -0
  6. data/README.md +14 -8
  7. data/Rakefile +3 -2
  8. data/appmap.gemspec +2 -1
  9. data/appmap.yml +1 -7
  10. data/lib/appmap.rb +2 -2
  11. data/lib/appmap/class_map.rb +20 -6
  12. data/lib/appmap/config.rb +66 -22
  13. data/lib/appmap/event.rb +21 -6
  14. data/lib/appmap/hook/method.rb +18 -12
  15. data/lib/appmap/rails/request_handler.rb +8 -1
  16. data/lib/appmap/railtie.rb +1 -1
  17. data/lib/appmap/rspec.rb +1 -1
  18. data/lib/appmap/trace.rb +18 -7
  19. data/lib/appmap/version.rb +2 -2
  20. data/spec/abstract_controller4_base_spec.rb +27 -28
  21. data/spec/abstract_controller_base_spec.rb +73 -38
  22. data/spec/class_map_spec.rb +36 -0
  23. data/spec/fixtures/hook/exception_method.rb +44 -0
  24. data/spec/fixtures/hook/instance_method.rb +4 -0
  25. data/spec/fixtures/{rails_users_app → rails5_users_app}/.dockerignore +0 -0
  26. data/spec/fixtures/{rails_users_app → rails5_users_app}/.gitignore +0 -0
  27. data/spec/fixtures/{rails_users_app → rails5_users_app}/.rspec +0 -0
  28. data/{.ruby-version → spec/fixtures/rails5_users_app/.ruby-version} +0 -0
  29. data/spec/fixtures/{rails_users_app → rails5_users_app}/Dockerfile +0 -0
  30. data/spec/fixtures/{rails_users_app → rails5_users_app}/Dockerfile.pg +0 -0
  31. data/spec/fixtures/rails5_users_app/Gemfile +51 -0
  32. data/spec/fixtures/{rails_users_app → rails5_users_app}/Rakefile +0 -0
  33. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/api/users_controller.rb +0 -0
  34. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/application_controller.rb +0 -0
  35. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/concerns/.keep +0 -0
  36. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/health_controller.rb +0 -0
  37. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/users_controller.rb +0 -0
  38. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/models/activerecord/user.rb +0 -0
  39. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/models/concerns/.keep +0 -0
  40. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/models/sequel/user.rb +0 -0
  41. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/views/layouts/application.html.haml +0 -0
  42. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/views/users/index.html.haml +0 -0
  43. data/spec/fixtures/rails5_users_app/appmap.yml +4 -0
  44. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/appmap +0 -0
  45. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/byebug +0 -0
  46. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/gli +0 -0
  47. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/htmldiff +0 -0
  48. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/ldiff +0 -0
  49. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/nokogiri +0 -0
  50. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rackup +0 -0
  51. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rails +0 -0
  52. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rake +0 -0
  53. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rspec +0 -0
  54. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/ruby-parse +0 -0
  55. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/ruby-rewrite +0 -0
  56. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/sequel +0 -0
  57. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/setup +0 -0
  58. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/sprockets +0 -0
  59. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/thor +0 -0
  60. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/update +0 -0
  61. data/spec/fixtures/{rails_users_app → rails5_users_app}/config.ru +0 -0
  62. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/application.rb +0 -0
  63. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/boot.rb +0 -0
  64. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/credentials.yml.enc +0 -0
  65. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/database.yml +0 -0
  66. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environment.rb +0 -0
  67. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environments/development.rb +0 -0
  68. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environments/production.rb +0 -0
  69. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environments/test.rb +0 -0
  70. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/application_controller_renderer.rb +0 -0
  71. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/backtrace_silencers.rb +0 -0
  72. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/cors.rb +0 -0
  73. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/filter_parameter_logging.rb +0 -0
  74. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/inflections.rb +0 -0
  75. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/mime_types.rb +0 -0
  76. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/record_button.rb +0 -0
  77. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/wrap_parameters.rb +0 -0
  78. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/locales/en.yml +0 -0
  79. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/routes.rb +0 -0
  80. data/spec/fixtures/{rails_users_app → rails5_users_app}/create_app +0 -0
  81. data/spec/fixtures/{rails_users_app → rails5_users_app}/db/migrate/20190728211408_create_users.rb +0 -0
  82. data/spec/fixtures/{rails_users_app → rails5_users_app}/db/schema.rb +0 -0
  83. data/spec/fixtures/{rails_users_app → rails5_users_app}/docker-compose.yml +0 -0
  84. data/spec/fixtures/{rails_users_app → rails5_users_app}/features/api_users.feature +0 -0
  85. data/spec/fixtures/{rails_users_app → rails5_users_app}/features/support/env.rb +0 -0
  86. data/spec/fixtures/{rails_users_app → rails5_users_app}/features/support/hooks.rb +0 -0
  87. data/spec/fixtures/{rails_users_app → rails5_users_app}/features/support/steps.rb +0 -0
  88. data/spec/fixtures/{rails_users_app → rails5_users_app}/lib/tasks/.keep +0 -0
  89. data/spec/fixtures/{rails_users_app → rails5_users_app}/log/.keep +0 -0
  90. data/spec/fixtures/{rails_users_app → rails5_users_app}/public/robots.txt +0 -0
  91. data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/controllers/users_controller_api_spec.rb +1 -1
  92. data/spec/fixtures/rails5_users_app/spec/controllers/users_controller_spec.rb +16 -0
  93. data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/models/user_spec.rb +0 -0
  94. data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/rails_helper.rb +0 -0
  95. data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/spec_helper.rb +0 -0
  96. data/spec/fixtures/{rails_users_app → rails5_users_app}/users_app/.gitignore +0 -0
  97. data/spec/fixtures/rails6_users_app/.dockerignore +1 -0
  98. data/spec/fixtures/rails6_users_app/.gitignore +39 -0
  99. data/spec/fixtures/rails6_users_app/.rspec +1 -0
  100. data/spec/fixtures/{rails_users_app → rails6_users_app}/.ruby-version +0 -0
  101. data/spec/fixtures/rails6_users_app/Dockerfile +29 -0
  102. data/spec/fixtures/rails6_users_app/Dockerfile.pg +3 -0
  103. data/spec/fixtures/{rails_users_app → rails6_users_app}/Gemfile +1 -1
  104. data/spec/fixtures/rails6_users_app/Rakefile +6 -0
  105. data/spec/fixtures/rails6_users_app/app/controllers/api/users_controller.rb +27 -0
  106. data/spec/fixtures/rails6_users_app/app/controllers/application_controller.rb +2 -0
  107. data/spec/fixtures/rails6_users_app/app/controllers/concerns/.keep +0 -0
  108. data/spec/fixtures/rails6_users_app/app/controllers/health_controller.rb +5 -0
  109. data/spec/fixtures/rails6_users_app/app/controllers/users_controller.rb +5 -0
  110. data/spec/fixtures/rails6_users_app/app/models/activerecord/user.rb +18 -0
  111. data/spec/fixtures/rails6_users_app/app/models/concerns/.keep +0 -0
  112. data/spec/fixtures/rails6_users_app/app/models/sequel/user.rb +25 -0
  113. data/spec/fixtures/rails6_users_app/app/views/layouts/application.html.haml +7 -0
  114. data/spec/fixtures/rails6_users_app/app/views/users/index.html.haml +7 -0
  115. data/spec/fixtures/rails6_users_app/appmap.yml +5 -0
  116. data/spec/fixtures/rails6_users_app/bin/appmap +29 -0
  117. data/spec/fixtures/rails6_users_app/bin/byebug +29 -0
  118. data/spec/fixtures/rails6_users_app/bin/gli +29 -0
  119. data/spec/fixtures/rails6_users_app/bin/htmldiff +29 -0
  120. data/spec/fixtures/rails6_users_app/bin/ldiff +29 -0
  121. data/spec/fixtures/rails6_users_app/bin/nokogiri +29 -0
  122. data/spec/fixtures/rails6_users_app/bin/rackup +29 -0
  123. data/spec/fixtures/rails6_users_app/bin/rails +4 -0
  124. data/spec/fixtures/rails6_users_app/bin/rake +29 -0
  125. data/spec/fixtures/rails6_users_app/bin/rspec +29 -0
  126. data/spec/fixtures/rails6_users_app/bin/ruby-parse +29 -0
  127. data/spec/fixtures/rails6_users_app/bin/ruby-rewrite +29 -0
  128. data/spec/fixtures/rails6_users_app/bin/sequel +29 -0
  129. data/spec/fixtures/rails6_users_app/bin/setup +25 -0
  130. data/spec/fixtures/rails6_users_app/bin/sprockets +29 -0
  131. data/spec/fixtures/rails6_users_app/bin/thor +29 -0
  132. data/spec/fixtures/rails6_users_app/bin/update +25 -0
  133. data/spec/fixtures/rails6_users_app/config.ru +5 -0
  134. data/spec/fixtures/rails6_users_app/config/application.rb +51 -0
  135. data/spec/fixtures/rails6_users_app/config/boot.rb +3 -0
  136. data/spec/fixtures/rails6_users_app/config/credentials.yml.enc +1 -0
  137. data/spec/fixtures/rails6_users_app/config/database.yml +18 -0
  138. data/spec/fixtures/rails6_users_app/config/environment.rb +5 -0
  139. data/spec/fixtures/rails6_users_app/config/environments/development.rb +40 -0
  140. data/spec/fixtures/rails6_users_app/config/environments/production.rb +68 -0
  141. data/spec/fixtures/rails6_users_app/config/environments/test.rb +36 -0
  142. data/spec/fixtures/rails6_users_app/config/initializers/application_controller_renderer.rb +8 -0
  143. data/spec/fixtures/rails6_users_app/config/initializers/backtrace_silencers.rb +7 -0
  144. data/spec/fixtures/rails6_users_app/config/initializers/cors.rb +16 -0
  145. data/spec/fixtures/rails6_users_app/config/initializers/filter_parameter_logging.rb +4 -0
  146. data/spec/fixtures/rails6_users_app/config/initializers/inflections.rb +16 -0
  147. data/spec/fixtures/rails6_users_app/config/initializers/mime_types.rb +4 -0
  148. data/spec/fixtures/rails6_users_app/config/initializers/record_button.rb +3 -0
  149. data/spec/fixtures/rails6_users_app/config/initializers/wrap_parameters.rb +9 -0
  150. data/spec/fixtures/rails6_users_app/config/locales/en.yml +33 -0
  151. data/spec/fixtures/rails6_users_app/config/routes.rb +11 -0
  152. data/spec/fixtures/rails6_users_app/create_app +27 -0
  153. data/spec/fixtures/rails6_users_app/db/migrate/20190728211408_create_users.rb +9 -0
  154. data/spec/fixtures/rails6_users_app/db/schema.rb +23 -0
  155. data/spec/fixtures/rails6_users_app/docker-compose.yml +28 -0
  156. data/spec/fixtures/rails6_users_app/features/api_users.feature +13 -0
  157. data/spec/fixtures/rails6_users_app/features/support/env.rb +4 -0
  158. data/spec/fixtures/rails6_users_app/features/support/hooks.rb +11 -0
  159. data/spec/fixtures/rails6_users_app/features/support/steps.rb +18 -0
  160. data/spec/fixtures/rails6_users_app/lib/tasks/.keep +0 -0
  161. data/spec/fixtures/rails6_users_app/log/.keep +0 -0
  162. data/spec/fixtures/rails6_users_app/public/robots.txt +1 -0
  163. data/spec/fixtures/rails6_users_app/spec/controllers/users_controller_api_spec.rb +29 -0
  164. data/spec/fixtures/rails6_users_app/spec/controllers/users_controller_spec.rb +16 -0
  165. data/spec/fixtures/rails6_users_app/spec/models/user_spec.rb +39 -0
  166. data/spec/fixtures/rails6_users_app/spec/rails_helper.rb +66 -0
  167. data/spec/fixtures/rails6_users_app/spec/spec_helper.rb +96 -0
  168. data/spec/fixtures/rails6_users_app/users_app/.gitignore +20 -0
  169. data/spec/hook_spec.rb +225 -18
  170. data/spec/rails_spec_helper.rb +5 -5
  171. data/spec/railtie_spec.rb +31 -32
  172. data/spec/record_sql_rails4_pg_spec.rb +47 -48
  173. data/spec/record_sql_rails_pg_spec.rb +62 -63
  174. data/spec/remote_recording_spec.rb +90 -89
  175. data/spec/rspec_feature_metadata_spec.rb +17 -18
  176. data/test/expectations/openssl_test_key_sign1.json +55 -0
  177. data/test/expectations/openssl_test_key_sign2.json +58 -0
  178. data/test/fixtures/gem_test/Gemfile +6 -0
  179. data/test/fixtures/gem_test/appmap.yml +3 -0
  180. data/test/fixtures/gem_test/test/to_param_test.rb +14 -0
  181. data/test/gem_test.rb +34 -0
  182. data/test/minitest_test.rb +2 -2
  183. data/test/openssl_test.rb +10 -117
  184. metadata +173 -80
  185. data/spec/fixtures/rails_users_app/appmap.yml +0 -3
@@ -9,3 +9,47 @@ class ExceptionMethod
9
9
  raise 'Exception occurred in raise_exception'
10
10
  end
11
11
  end
12
+
13
+ # subclass from BasicObject so we don't get #to_s. Requires some
14
+ # hackery to implement the other methods normally provided by Object.
15
+ class NoToSMethod < BasicObject
16
+ def is_a?(*args)
17
+ return false
18
+ end
19
+
20
+ def class
21
+ return ::Class
22
+ end
23
+
24
+ def respond_to?(*args)
25
+ return false
26
+ end
27
+
28
+ def inspect
29
+ "NoToSMethod"
30
+ end
31
+
32
+ def say_hello
33
+ "hello"
34
+ end
35
+ end
36
+
37
+ class InspectRaises < NoToSMethod
38
+ def inspect
39
+ ::Kernel.raise "#to_s missing, #inspect raises"
40
+ end
41
+
42
+ def say_hello
43
+ "hello"
44
+ end
45
+ end
46
+
47
+ class ToSRaises
48
+ def to_s
49
+ raise "#to_s raises"
50
+ end
51
+
52
+ def say_hello
53
+ "hello"
54
+ end
55
+ end
@@ -17,6 +17,10 @@ class InstanceMethod
17
17
  kw.to_s
18
18
  end
19
19
 
20
+ def say_kws(*args, kw1:, kw2: 'kw2', **kws)
21
+ [kw1, kw2, kws, args].join
22
+ end
23
+
20
24
  def say_block(&block)
21
25
  yield
22
26
  end
@@ -0,0 +1,51 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
+
4
+ gem 'rails', '~> 5'
5
+
6
+ gem 'haml-rails'
7
+
8
+ gem 'activerecord', require: false
9
+ gem 'pg'
10
+ gem 'sequel', '= 5.20.0', require: false
11
+ gem 'sequel-rails', require: false
12
+ gem 'sequel_secure_password', require: false
13
+
14
+ appmap_path = \
15
+ # Support debugging inside the container with volume-mounted source
16
+ if File.directory?('/src/appmap-ruby')
17
+ '/src/appmap-ruby'
18
+ elsif File.exist?('../../../appmap.gemspec')
19
+ '../../..'
20
+ end
21
+
22
+ if appmap_path
23
+ # Set the branch parameter, so that 'bundle config local.appmap' will work
24
+ appmap_branch = Dir.chdir appmap_path do
25
+ `git rev-parse --abbrev-ref HEAD`.strip
26
+ end
27
+ end
28
+
29
+ appmap_options = \
30
+ if appmap_path && appmap_branch
31
+ { git: appmap_path, branch: appmap_branch }
32
+ elsif appmap_path
33
+ { path: appmap_path }
34
+ else
35
+ {}
36
+ end.merge(require: %w[appmap appmap/railtie])
37
+
38
+ gem 'appmap', appmap_options
39
+
40
+ group :development, :test do
41
+ gem 'cucumber-rails', require: false
42
+ gem 'rspec-rails'
43
+ # Required for Sequel, since without ActiveRecord, the Rails transactional fixture support
44
+ # isn't activated.
45
+ gem 'database_cleaner'
46
+ # Call 'byebug' anywhere in the code to stop execution and get a debugger console
47
+ gem 'pry-byebug'
48
+ end
49
+
50
+ group :development do
51
+ end
@@ -0,0 +1,4 @@
1
+ name: rails5_users_app
2
+ packages:
3
+ - path: app
4
+ - gem: sequel
@@ -21,7 +21,7 @@ RSpec.describe Api::UsersController, feature_group: 'Users', type: :controller,
21
21
  post :create, params: { login: 'alice' }
22
22
  end
23
23
  it 'lists the users' do
24
- post :index, params: {}
24
+ get :index, params: {}
25
25
  users = JSON.parse(response.body)
26
26
  expect(users.map { |r| r['login'] }).to include('alice')
27
27
  end
@@ -0,0 +1,16 @@
1
+ require 'rails_helper'
2
+ require 'rack/test'
3
+
4
+ RSpec.describe UsersController, type: :controller do
5
+ render_views
6
+
7
+ describe 'GET /users', feature: 'Show all users' do
8
+ before do
9
+ User.create login: 'alice'
10
+ end
11
+ it 'lists the users' do
12
+ get :index
13
+ expect(response).to be_ok
14
+ end
15
+ end
16
+ end
@@ -0,0 +1 @@
1
+ Gemfile.lock
@@ -0,0 +1,39 @@
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+ vendor
10
+
11
+ # Ignore all logfiles and tempfiles.
12
+ /log/*
13
+ /tmp/*
14
+ !/log/.keep
15
+ !/tmp/.keep
16
+
17
+ # Ignore uploaded files in development
18
+ /storage/*
19
+ !/storage/.keep
20
+
21
+ /node_modules
22
+ /yarn-error.log
23
+
24
+ /public/assets
25
+ .byebug_history
26
+
27
+ # Ignore master key for decrypting credentials and more.
28
+ /config/master.key
29
+
30
+ # Other
31
+ .DS_Store
32
+ .appmap
33
+ appmap.json
34
+ appmap-recording-*.json
35
+ capybara-*.html
36
+
37
+ # appmap gem is pre-installed, don't lock to a version
38
+ Gemfile.lock
39
+
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1,29 @@
1
+ ARG GEM_VERSION
2
+ ARG RUBY_VERSION
3
+
4
+ FROM appmap:${GEM_VERSION} as appmap
5
+
6
+ FROM ruby:${RUBY_VERSION}
7
+ RUN apt-get update && apt-get install -y vim less
8
+ RUN apt-get install -y postgresql-client
9
+
10
+ RUN mkdir /app
11
+ WORKDIR /app
12
+
13
+ RUN gem install -N bundler
14
+
15
+ COPY Gemfile .
16
+
17
+ RUN bundle
18
+ RUN bundle binstubs bundler rspec-core --force
19
+
20
+ COPY . .
21
+
22
+ COPY --from=appmap /pkg/appmap.gem /tmp/
23
+ RUN gem install /tmp/appmap.gem && \
24
+ bundle update --local appmap && \
25
+ bundle binstubs appmap --force
26
+
27
+ EXPOSE 3000
28
+
29
+ HEALTHCHECK --interval=1s --retries=10 CMD curl --fail http://localhost:3000/health || exit 1
@@ -0,0 +1,3 @@
1
+ FROM postgres:10
2
+
3
+ HEALTHCHECK --interval=1s --retries=10 CMD psql -U postgres -c "select 1" || exit 1
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
2
2
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
3
 
4
4
  # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
5
- gem 'rails', '~> 5.2.3'
5
+ gem 'rails', '~> 6'
6
6
 
7
7
  gem 'haml-rails'
8
8
 
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,27 @@
1
+ module Api
2
+ class UsersController < ActionController::API
3
+ def index
4
+ @users = User.all
5
+ render json: @users
6
+ end
7
+
8
+ def create
9
+ @user = build_user(params.slice(:login).to_unsafe_h)
10
+ unless @user.valid?
11
+ error = {
12
+ code: 'invalid',
13
+ target: 'User',
14
+ message: @user.errors.full_messages.join(', '),
15
+ details: @user.errors.map { |k, v| { code: 'invalid', target: k, message: Array(v).join(', ') } }
16
+ }
17
+ return render json: error, status: :unprocessable_entity
18
+ end
19
+ @user.save
20
+ render json: @user, status: :created
21
+ end
22
+
23
+ def build_user(params)
24
+ User.new(params)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,5 @@
1
+ class HealthController < ActionController::API
2
+ def show
3
+ render nothing: true, status: 204
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class UsersController < ApplicationController
2
+ def index
3
+ @users = User.all
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ class User < ActiveRecord::Base
2
+ has_secure_password validations: false
3
+ validates_presence_of :login
4
+ validates_confirmation_of :password, if: -> { password_provided? }
5
+
6
+ def authenticate(unencrypted)
7
+ # Just be extra sure that empty passwords aren't accepted
8
+ return false if unencrypted.blank? || password.blank?
9
+
10
+ super
11
+ end
12
+
13
+ protected
14
+
15
+ def password_provided?
16
+ !(password.blank? && password_confirmation.blank?)
17
+ end
18
+ end