appmap 0.42.1 → 0.43.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +8 -5
- data/lib/appmap/event.rb +18 -0
- data/lib/appmap/rails/request_handler.rb +41 -10
- data/lib/appmap/version.rb +1 -1
- data/spec/abstract_controller_base_spec.rb +67 -22
- data/spec/fixtures/rails5_users_app/Gemfile +7 -3
- data/spec/fixtures/rails5_users_app/app/controllers/api/users_controller.rb +2 -0
- data/spec/fixtures/rails5_users_app/app/controllers/users_controller.rb +9 -1
- data/spec/fixtures/rails5_users_app/config/application.rb +2 -0
- data/spec/fixtures/rails5_users_app/create_app +8 -2
- data/spec/fixtures/rails5_users_app/spec/controllers/users_controller_api_spec.rb +13 -0
- data/spec/fixtures/rails5_users_app/spec/controllers/users_controller_spec.rb +2 -2
- data/spec/fixtures/rails5_users_app/spec/rails_helper.rb +3 -9
- data/spec/fixtures/rails6_users_app/Gemfile +5 -4
- data/spec/fixtures/rails6_users_app/app/controllers/api/users_controller.rb +1 -0
- data/spec/fixtures/rails6_users_app/app/controllers/users_controller.rb +9 -1
- data/spec/fixtures/rails6_users_app/config/application.rb +2 -0
- data/spec/fixtures/rails6_users_app/create_app +8 -2
- data/spec/fixtures/rails6_users_app/spec/controllers/users_controller_api_spec.rb +13 -0
- data/spec/fixtures/rails6_users_app/spec/controllers/users_controller_spec.rb +2 -2
- data/spec/fixtures/rails6_users_app/spec/rails_helper.rb +3 -9
- data/spec/record_sql_rails_pg_spec.rb +1 -1
- data/spec/spec_helper.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4007f0eb67a3a25088e8b3677de8d0388fd1bfec4b326c43a51c503f640325b5
|
4
|
+
data.tar.gz: 1b593251a7a072b7a1483e7af172b9157d6913208658fb324630bc52b0b4fe73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6af64a17bf69655ae8bdc9b4b67b7e2c9bd1b87d07a23e266dcabd2a927311224a4b27a77355674559828a08ae1df2e7231e2a68a2734c0f620de8efc48ec6d4
|
7
|
+
data.tar.gz: 7725cb0c79d8be13fddf7a3b688113f4fd31941c4f08f64ee44d4fbb3f5255dd3a308b08ef578413938052ee3b9eeecedc3e58bc092b12e23bfa872eac119eb7
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# v0.43.0
|
2
|
+
|
3
|
+
* Record `name` and `class` of each entry in Hash-like parameters, messages, and return values.
|
4
|
+
* Record client-sent headers in HTTP server request and response.
|
5
|
+
* Record HTTP server request `mime_type`.
|
6
|
+
* Record HTTP server request `authorization`.
|
7
|
+
|
1
8
|
# v0.42.1
|
2
9
|
|
3
10
|
* Add missing require `set`.
|
data/README.md
CHANGED
@@ -369,7 +369,7 @@ The fixture apps in `test/fixtures` are plain Ruby projects that exercise the ba
|
|
369
369
|
|
370
370
|
### `spec/fixtures`
|
371
371
|
|
372
|
-
The fixture apps in `spec/fixtures` are simple Rack,
|
372
|
+
The fixture apps in `spec/fixtures` are simple Rack, Rails5, and Rails6 apps.
|
373
373
|
You can use them to interactively develop and test the recording features of the `appmap` gem.
|
374
374
|
These fixture apps are more sophisticated than `test/fixtures`, because they include additional
|
375
375
|
resources such as a PostgreSQL database.
|
@@ -395,11 +395,15 @@ $ docker-compose run --rm app ./create_app
|
|
395
395
|
Now you can start a development container.
|
396
396
|
|
397
397
|
```sh-session
|
398
|
-
$ docker-compose run --rm -v $PWD/../../..:/src/appmap-ruby app bash
|
398
|
+
$ docker-compose run --rm -v $PWD:/app -v $PWD/../../..:/src/appmap-ruby app bash
|
399
399
|
Starting rails_users_app_pg_1 ... done
|
400
|
-
root@6fab5f89125f:/app# cd /src/
|
400
|
+
root@6fab5f89125f:/app# cd /src/appmap-ruby
|
401
|
+
root@6fab5f89125f:/src/appmap-ruby# rm ext/appmap/*.so ext/appmap/*.o
|
402
|
+
root@6fab5f89125f:/src/appmap-ruby# bundle
|
403
|
+
root@6fab5f89125f:/src/appmap-ruby# bundle exec rake compile
|
404
|
+
root@6fab5f89125f:/src/appmap-ruby# cd /src/app
|
401
405
|
root@6fab5f89125f:/src/app# bundle config local.appmap /src/appmap-ruby
|
402
|
-
root@6fab5f89125f:/src/app# bundle
|
406
|
+
root@6fab5f89125f:/src/app# bundle
|
403
407
|
```
|
404
408
|
|
405
409
|
At this point, the bundle is built with the `appmap` gem located in `/src/appmap`, which is volume-mounted from the host.
|
@@ -414,4 +418,3 @@ Configuring AppMap from path appmap.yml
|
|
414
418
|
Finished in 0.07357 seconds (files took 2.1 seconds to load)
|
415
419
|
4 examples, 0 failures
|
416
420
|
```
|
417
|
-
|
data/lib/appmap/event.rb
CHANGED
@@ -36,6 +36,18 @@ module AppMap
|
|
36
36
|
(value_string||'')[0...LIMIT].encode('utf-8', invalid: :replace, undef: :replace, replace: '_')
|
37
37
|
end
|
38
38
|
|
39
|
+
def object_properties(hash_like)
|
40
|
+
hash = hash_like.to_h
|
41
|
+
hash.keys.map do |key|
|
42
|
+
{
|
43
|
+
name: key,
|
44
|
+
class: hash[key].class.name,
|
45
|
+
}
|
46
|
+
end
|
47
|
+
rescue
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
|
39
51
|
protected
|
40
52
|
|
41
53
|
# Heuristic for dynamically defined class whose name can be nil
|
@@ -79,6 +91,12 @@ module AppMap
|
|
79
91
|
end
|
80
92
|
end
|
81
93
|
end
|
94
|
+
|
95
|
+
protected
|
96
|
+
|
97
|
+
def object_properties(hash_like)
|
98
|
+
self.class.object_properties(hash_like)
|
99
|
+
end
|
82
100
|
end
|
83
101
|
|
84
102
|
class MethodCall < MethodEvent
|
@@ -6,15 +6,38 @@ require 'appmap/hook'
|
|
6
6
|
module AppMap
|
7
7
|
module Rails
|
8
8
|
module RequestHandler
|
9
|
+
# Host and User-Agent will just introduce needless variation.
|
10
|
+
# Content-Type and Authorization get their own fields in the request.
|
11
|
+
IGNORE_HEADERS = %w[host user_agent content_type authorization].map(&:upcase).map {|h| "HTTP_#{h}"}.freeze
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def selected_headers(env)
|
15
|
+
# Rack prepends HTTP_ to all client-sent headers.
|
16
|
+
matching_headers = env
|
17
|
+
.select { |k,v| k.start_with? 'HTTP_'}
|
18
|
+
.reject { |k,v| IGNORE_HEADERS.member?(k) }
|
19
|
+
.reject { |k,v| v.blank? }
|
20
|
+
.each_with_object({}) do |kv, memo|
|
21
|
+
key = kv[0].sub(/^HTTP_/, '').split('_').map(&:capitalize).join('-')
|
22
|
+
value = kv[1]
|
23
|
+
memo[key] = value
|
24
|
+
end
|
25
|
+
matching_headers.blank? ? nil : matching_headers
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
9
29
|
class HTTPServerRequest < AppMap::Event::MethodEvent
|
10
|
-
attr_accessor :normalized_path_info, :request_method, :path_info, :params
|
30
|
+
attr_accessor :normalized_path_info, :request_method, :path_info, :params, :mime_type, :headers, :authorization
|
11
31
|
|
12
32
|
def initialize(request)
|
13
33
|
super AppMap::Event.next_id_counter, :call, Thread.current.object_id
|
14
34
|
|
15
|
-
|
16
|
-
|
17
|
-
|
35
|
+
self.request_method = request.request_method
|
36
|
+
self.normalized_path_info = normalized_path(request)
|
37
|
+
self.mime_type = request.headers['Content-Type']
|
38
|
+
self.headers = RequestHandler.selected_headers(request.env)
|
39
|
+
self.authorization = request.headers['Authorization']
|
40
|
+
self.path_info = request.path_info.split('?')[0]
|
18
41
|
# ActionDispatch::Http::ParameterFilter is deprecated
|
19
42
|
parameter_filter_cls = \
|
20
43
|
if defined?(ActiveSupport::ParameterFilter)
|
@@ -22,7 +45,7 @@ module AppMap
|
|
22
45
|
else
|
23
46
|
ActionDispatch::Http::ParameterFilter
|
24
47
|
end
|
25
|
-
|
48
|
+
self.params = parameter_filter_cls.new(::Rails.application.config.filter_parameters).filter(request.params)
|
26
49
|
end
|
27
50
|
|
28
51
|
def to_h
|
@@ -30,7 +53,10 @@ module AppMap
|
|
30
53
|
h[:http_server_request] = {
|
31
54
|
request_method: request_method,
|
32
55
|
path_info: path_info,
|
33
|
-
|
56
|
+
mime_type: mime_type,
|
57
|
+
normalized_path_info: normalized_path_info,
|
58
|
+
authorization: authorization,
|
59
|
+
headers: headers,
|
34
60
|
}.compact
|
35
61
|
|
36
62
|
h[:message] = params.keys.map do |key|
|
@@ -39,8 +65,11 @@ module AppMap
|
|
39
65
|
name: key,
|
40
66
|
class: val.class.name,
|
41
67
|
value: self.class.display_string(val),
|
42
|
-
object_id: val.__id__
|
43
|
-
}
|
68
|
+
object_id: val.__id__,
|
69
|
+
}.tap do |message|
|
70
|
+
properties = object_properties(val)
|
71
|
+
message[:properties] = properties if properties
|
72
|
+
end
|
44
73
|
end
|
45
74
|
end
|
46
75
|
end
|
@@ -59,7 +88,7 @@ module AppMap
|
|
59
88
|
end
|
60
89
|
|
61
90
|
class HTTPServerResponse < AppMap::Event::MethodReturnIgnoreValue
|
62
|
-
attr_accessor :status, :mime_type
|
91
|
+
attr_accessor :status, :mime_type, :headers
|
63
92
|
|
64
93
|
def initialize(response, parent_id, elapsed)
|
65
94
|
super AppMap::Event.next_id_counter, :return, Thread.current.object_id
|
@@ -68,13 +97,15 @@ module AppMap
|
|
68
97
|
self.mime_type = response.headers['Content-Type']
|
69
98
|
self.parent_id = parent_id
|
70
99
|
self.elapsed = elapsed
|
100
|
+
self.headers = RequestHandler.selected_headers(response.headers)
|
71
101
|
end
|
72
102
|
|
73
103
|
def to_h
|
74
104
|
super.tap do |h|
|
75
105
|
h[:http_server_response] = {
|
76
106
|
status: status,
|
77
|
-
mime_type: mime_type
|
107
|
+
mime_type: mime_type,
|
108
|
+
headers: headers
|
78
109
|
}.compact
|
79
110
|
end
|
80
111
|
end
|
data/lib/appmap/version.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
require 'rails_spec_helper'
|
2
2
|
|
3
|
-
describe '
|
3
|
+
describe 'Rails' do
|
4
4
|
%w[5 6].each do |rails_major_version| # rubocop:disable Metrics/BlockLength
|
5
|
-
context "
|
6
|
-
include_context 'Rails app pg database', "spec/fixtures/rails#{rails_major_version}_users_app"
|
5
|
+
context "#{rails_major_version}" do
|
6
|
+
include_context 'Rails app pg database', "spec/fixtures/rails#{rails_major_version}_users_app" unless use_existing_data?
|
7
|
+
|
7
8
|
def run_spec(spec_name)
|
8
|
-
FileUtils.rm_rf tmpdir
|
9
|
-
FileUtils.mkdir_p tmpdir
|
10
9
|
cmd = <<~CMD.gsub "\n", ' '
|
11
10
|
docker-compose run --rm -e RAILS_ENV=test -e APPMAP=true
|
12
11
|
-v #{File.absolute_path tmpdir}:/app/tmp app ./bin/rspec #{spec_name}
|
@@ -18,12 +17,20 @@ describe 'AbstractControllerBase' do
|
|
18
17
|
'tmp/spec/AbstractControllerBase'
|
19
18
|
end
|
20
19
|
|
20
|
+
unless use_existing_data?
|
21
|
+
before(:all) do
|
22
|
+
FileUtils.rm_rf tmpdir
|
23
|
+
FileUtils.mkdir_p tmpdir
|
24
|
+
run_spec 'spec/controllers/users_controller_spec.rb'
|
25
|
+
run_spec 'spec/controllers/users_controller_api_spec.rb'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
21
29
|
let(:appmap) { JSON.parse File.read File.join tmpdir, 'appmap/rspec', appmap_json_file }
|
22
30
|
let(:events) { appmap['events'] }
|
23
31
|
|
24
|
-
describe '
|
25
|
-
describe 'creating
|
26
|
-
before(:all) { run_spec 'spec/controllers/users_controller_api_spec.rb:8' }
|
32
|
+
describe 'an API route' do
|
33
|
+
describe 'creating an object' do
|
27
34
|
let(:appmap_json_file) do
|
28
35
|
'Api_UsersController_POST_api_users_with_required_parameters_creates_a_user.appmap.json'
|
29
36
|
end
|
@@ -32,11 +39,12 @@ describe 'AbstractControllerBase' do
|
|
32
39
|
expect(File).to exist(File.join(tmpdir, 'appmap/rspec/Inventory.appmap.json'))
|
33
40
|
end
|
34
41
|
|
35
|
-
it '
|
42
|
+
it 'http_server_request is recorded in the appmap' do
|
36
43
|
expect(events).to include(
|
37
44
|
hash_including(
|
38
45
|
'http_server_request' => hash_including(
|
39
46
|
'request_method' => 'POST',
|
47
|
+
'normalized_path_info' => '/api/users(.:format)',
|
40
48
|
'path_info' => '/api/users'
|
41
49
|
),
|
42
50
|
'message' => include(
|
@@ -53,12 +61,17 @@ describe 'AbstractControllerBase' do
|
|
53
61
|
'object_id' => Integer
|
54
62
|
)
|
55
63
|
)
|
56
|
-
)
|
64
|
+
)
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'http_server_response is recorded in the appmap' do
|
69
|
+
expect(events).to include(
|
57
70
|
hash_including(
|
58
|
-
'http_server_response' =>
|
71
|
+
'http_server_response' => hash_including(
|
59
72
|
'status' => 201,
|
60
73
|
'mime_type' => 'application/json; charset=utf-8'
|
61
|
-
|
74
|
+
)
|
62
75
|
)
|
63
76
|
)
|
64
77
|
end
|
@@ -70,7 +83,7 @@ describe 'AbstractControllerBase' do
|
|
70
83
|
'defined_class' => 'Api::UsersController',
|
71
84
|
'method_id' => 'build_user',
|
72
85
|
'path' => 'app/controllers/api/users_controller.rb',
|
73
|
-
'lineno' =>
|
86
|
+
'lineno' => Integer,
|
74
87
|
'static' => false,
|
75
88
|
'parameters' => include(
|
76
89
|
'name' => 'params',
|
@@ -93,10 +106,47 @@ describe 'AbstractControllerBase' do
|
|
93
106
|
'elapsed' => Numeric
|
94
107
|
)
|
95
108
|
end
|
109
|
+
|
110
|
+
context 'with an object-style message' do
|
111
|
+
let(:appmap_json_file) { 'Api_UsersController_POST_api_users_with_required_parameters_with_object-style_parameters_creates_a_user.appmap.json' }
|
112
|
+
|
113
|
+
it 'message properties are recorded in the appmap' do
|
114
|
+
expect(events).to include(
|
115
|
+
hash_including(
|
116
|
+
'message' => include(
|
117
|
+
hash_including(
|
118
|
+
'name' => 'user',
|
119
|
+
'properties' => [
|
120
|
+
{ 'name' => 'login', 'class' => 'String' },
|
121
|
+
{ 'name' => 'password', 'class' => 'String' }
|
122
|
+
]
|
123
|
+
)
|
124
|
+
)
|
125
|
+
)
|
126
|
+
)
|
127
|
+
end
|
128
|
+
end
|
96
129
|
end
|
97
130
|
|
98
|
-
describe '
|
99
|
-
|
131
|
+
describe 'listing objects' do
|
132
|
+
context 'with a custom header' do
|
133
|
+
let(:appmap_json_file) { 'Api_UsersController_GET_api_users_with_a_custom_header_lists_the_users.appmap.json' }
|
134
|
+
|
135
|
+
it 'custom header is recorded in the appmap' do
|
136
|
+
expect(events).to include(
|
137
|
+
hash_including(
|
138
|
+
'http_server_request' => hash_including(
|
139
|
+
'headers' => hash_including('X-Sandwich' => 'turkey')
|
140
|
+
)
|
141
|
+
)
|
142
|
+
)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe 'a UI route' do
|
149
|
+
describe 'rendering a page' do
|
100
150
|
let(:appmap_json_file) do
|
101
151
|
'UsersController_GET_users_login_shows_the_user.appmap.json'
|
102
152
|
end
|
@@ -112,11 +162,6 @@ describe 'AbstractControllerBase' do
|
|
112
162
|
)
|
113
163
|
)
|
114
164
|
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe 'listing users' do
|
118
|
-
before(:all) { run_spec 'spec/controllers/users_controller_spec.rb:11' }
|
119
|
-
let(:appmap_json_file) { 'UsersController_GET_users_lists_the_users.appmap.json' }
|
120
165
|
|
121
166
|
it 'records and labels view rendering' do
|
122
167
|
expect(events).to include hash_including(
|
@@ -128,7 +173,7 @@ describe 'AbstractControllerBase' do
|
|
128
173
|
'lineno' => Integer,
|
129
174
|
'static' => false
|
130
175
|
)
|
131
|
-
|
176
|
+
|
132
177
|
expect(appmap['classMap']).to include hash_including(
|
133
178
|
'name' => 'action_view',
|
134
179
|
'children' => include(hash_including(
|
@@ -142,7 +187,7 @@ describe 'AbstractControllerBase' do
|
|
142
187
|
))
|
143
188
|
))
|
144
189
|
)
|
145
|
-
end
|
190
|
+
end
|
146
191
|
end
|
147
192
|
end
|
148
193
|
end
|
@@ -39,12 +39,16 @@ group :development, :test do
|
|
39
39
|
gem 'appmap', appmap_options
|
40
40
|
gem 'cucumber-rails', require: false
|
41
41
|
gem 'rspec-rails'
|
42
|
-
# Required for Sequel, since without ActiveRecord, the Rails transactional fixture support
|
43
|
-
# isn't activated.
|
44
|
-
gem 'database_cleaner'
|
45
42
|
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
46
43
|
gem 'pry-byebug'
|
47
44
|
end
|
48
45
|
|
46
|
+
group :test do
|
47
|
+
# Require only one of these.
|
48
|
+
# 'database_cleaner' requries 'database_cleaner-active_record', so don't require it.
|
49
|
+
gem 'database_cleaner-active_record', require: false
|
50
|
+
gem 'database_cleaner-sequel', require: false
|
51
|
+
end
|
52
|
+
|
49
53
|
group :development do
|
50
54
|
end
|
@@ -4,7 +4,15 @@ class UsersController < ApplicationController
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def show
|
7
|
-
|
7
|
+
find_user = lambda do |id|
|
8
|
+
if User.respond_to?(:[])
|
9
|
+
User[login: id]
|
10
|
+
else
|
11
|
+
User.find_by_login!(id)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
if (@user = find_user.(params[:id]))
|
8
16
|
render plain: @user
|
9
17
|
else
|
10
18
|
render plain: 'Not found', status: 404
|
@@ -15,8 +15,10 @@ case orm_module
|
|
15
15
|
when 'sequel'
|
16
16
|
require 'sequel-rails'
|
17
17
|
require 'sequel_secure_password'
|
18
|
+
require 'database_cleaner-sequel' if Rails.env.test?
|
18
19
|
when 'activerecord'
|
19
20
|
require 'active_record/railtie'
|
21
|
+
require 'database_cleaner-active_record' if Rails.env.test?
|
20
22
|
end
|
21
23
|
|
22
24
|
require 'appmap/railtie' if defined?(AppMap)
|
@@ -16,11 +16,17 @@ if [[ $? != 0 ]]; then
|
|
16
16
|
exit 1
|
17
17
|
fi
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
# Required for migrations
|
20
|
+
export ORM_MODULE=sequel
|
21
21
|
|
22
|
+
set +e
|
23
|
+
psql -h pg -U postgres -c "drop database if exists app_development"
|
24
|
+
psql -h pg -U postgres -c "drop database if exists app_test"
|
22
25
|
set -e
|
23
26
|
|
27
|
+
psql -h pg -U postgres -c "create database app_development"
|
28
|
+
psql -h pg -U postgres -c "create database app_test"
|
29
|
+
|
24
30
|
RAILS_ENV=development ./bin/rake db:migrate
|
25
31
|
RAILS_ENV=test ./bin/rake db:migrate
|
26
32
|
|
@@ -8,6 +8,12 @@ RSpec.describe Api::UsersController, type: :controller do
|
|
8
8
|
post :create, params: { login: 'alice', password: 'foobar' }
|
9
9
|
expect(response.status).to eq(201)
|
10
10
|
end
|
11
|
+
describe 'with object-style parameters' do
|
12
|
+
it 'creates a user' do
|
13
|
+
post :create, params: { user: { login: 'alice', password: 'foobar' } }
|
14
|
+
expect(response.status).to eq(201)
|
15
|
+
end
|
16
|
+
end
|
11
17
|
end
|
12
18
|
describe 'with a missing parameter' do
|
13
19
|
it 'reports error 422' do
|
@@ -25,5 +31,12 @@ RSpec.describe Api::UsersController, type: :controller do
|
|
25
31
|
users = JSON.parse(response.body)
|
26
32
|
expect(users.map { |r| r['login'] }).to include('alice')
|
27
33
|
end
|
34
|
+
describe 'with a custom header' do
|
35
|
+
it 'lists the users' do
|
36
|
+
request.headers['X-Sandwich'] = 'turkey'
|
37
|
+
get :index, params: {}
|
38
|
+
expect(response.status).to eq(200)
|
39
|
+
end
|
40
|
+
end
|
28
41
|
end
|
29
42
|
end
|
@@ -4,7 +4,7 @@ require 'rack/test'
|
|
4
4
|
RSpec.describe UsersController, type: :controller do
|
5
5
|
render_views
|
6
6
|
|
7
|
-
describe 'GET /users'
|
7
|
+
describe 'GET /users' do
|
8
8
|
before do
|
9
9
|
User.create login: 'alice'
|
10
10
|
end
|
@@ -14,7 +14,7 @@ RSpec.describe UsersController, type: :controller do
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
describe 'GET /users/:login'
|
17
|
+
describe 'GET /users/:login' do
|
18
18
|
before do
|
19
19
|
User.create login: 'alice'
|
20
20
|
end
|
@@ -45,7 +45,6 @@ RSpec.configure do |config|
|
|
45
45
|
# arbitrary gems may also be filtered via:
|
46
46
|
# config.filter_gems_from_backtrace("gem name")
|
47
47
|
|
48
|
-
|
49
48
|
DatabaseCleaner.allow_remote_database_url = true
|
50
49
|
|
51
50
|
config.before(:suite) do
|
@@ -54,13 +53,8 @@ RSpec.configure do |config|
|
|
54
53
|
end
|
55
54
|
|
56
55
|
config.around :each do |example|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
DatabaseCleaner.cleaning do
|
62
|
-
example.run
|
63
|
-
end
|
64
|
-
}.call
|
56
|
+
DatabaseCleaner.cleaning do
|
57
|
+
example.run
|
58
|
+
end
|
65
59
|
end
|
66
60
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
3
3
|
|
4
|
-
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
5
4
|
gem 'rails', '~> 6'
|
6
5
|
|
7
6
|
gem 'haml-rails'
|
@@ -40,12 +39,14 @@ group :development, :test do
|
|
40
39
|
gem 'appmap', appmap_options
|
41
40
|
gem 'cucumber-rails', require: false
|
42
41
|
gem 'rspec-rails'
|
43
|
-
# Required for Sequel, since without ActiveRecord, the Rails transactional fixture support
|
44
|
-
# isn't activated.
|
45
|
-
gem 'database_cleaner'
|
46
42
|
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
47
43
|
gem 'pry-byebug'
|
48
44
|
end
|
49
45
|
|
46
|
+
group :test do
|
47
|
+
gem 'database_cleaner-active_record', require: false
|
48
|
+
gem 'database_cleaner-sequel', require: false
|
49
|
+
end
|
50
|
+
|
50
51
|
group :development do
|
51
52
|
end
|
@@ -4,7 +4,15 @@ class UsersController < ApplicationController
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def show
|
7
|
-
|
7
|
+
find_user = lambda do |id|
|
8
|
+
if User.respond_to?(:[])
|
9
|
+
User[login: id]
|
10
|
+
else
|
11
|
+
User.find_by_login!(id)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
if (@user = find_user.(params[:id]))
|
8
16
|
render plain: @user
|
9
17
|
else
|
10
18
|
render plain: 'Not found', status: 404
|
@@ -15,8 +15,10 @@ case orm_module
|
|
15
15
|
when 'sequel'
|
16
16
|
require 'sequel-rails'
|
17
17
|
require 'sequel_secure_password'
|
18
|
+
require 'database_cleaner-sequel' if Rails.env.test?
|
18
19
|
when 'activerecord'
|
19
20
|
require 'active_record/railtie'
|
21
|
+
require 'database_cleaner-active_record' if Rails.env.test?
|
20
22
|
end
|
21
23
|
|
22
24
|
require 'appmap/railtie' if defined?(AppMap)
|
@@ -16,11 +16,17 @@ if [[ $? != 0 ]]; then
|
|
16
16
|
exit 1
|
17
17
|
fi
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
# Required for migrations
|
20
|
+
export ORM_MODULE=sequel
|
21
21
|
|
22
|
+
set +e
|
23
|
+
psql -h pg -U postgres -c "drop database if exists app_development"
|
24
|
+
psql -h pg -U postgres -c "drop database if exists app_test"
|
22
25
|
set -e
|
23
26
|
|
27
|
+
psql -h pg -U postgres -c "create database app_development"
|
28
|
+
psql -h pg -U postgres -c "create database app_test"
|
29
|
+
|
24
30
|
RAILS_ENV=development ./bin/rake db:migrate
|
25
31
|
RAILS_ENV=test ./bin/rake db:migrate
|
26
32
|
|
@@ -8,6 +8,12 @@ RSpec.describe Api::UsersController, type: :controller do
|
|
8
8
|
post :create, params: { login: 'alice', password: 'foobar' }
|
9
9
|
expect(response.status).to eq(201)
|
10
10
|
end
|
11
|
+
describe 'with object-style parameters' do
|
12
|
+
it 'creates a user' do
|
13
|
+
post :create, params: { user: { login: 'alice', password: 'foobar' } }
|
14
|
+
expect(response.status).to eq(201)
|
15
|
+
end
|
16
|
+
end
|
11
17
|
end
|
12
18
|
describe 'with a missing parameter' do
|
13
19
|
it 'reports error 422' do
|
@@ -25,5 +31,12 @@ RSpec.describe Api::UsersController, type: :controller do
|
|
25
31
|
users = JSON.parse(response.body)
|
26
32
|
expect(users.map { |r| r['login'] }).to include('alice')
|
27
33
|
end
|
34
|
+
describe 'with a custom header' do
|
35
|
+
it 'lists the users' do
|
36
|
+
request.headers['X-Sandwich'] = 'turkey'
|
37
|
+
get :index, params: {}
|
38
|
+
expect(response.status).to eq(200)
|
39
|
+
end
|
40
|
+
end
|
28
41
|
end
|
29
42
|
end
|
@@ -4,7 +4,7 @@ require 'rack/test'
|
|
4
4
|
RSpec.describe UsersController, type: :controller do
|
5
5
|
render_views
|
6
6
|
|
7
|
-
describe 'GET /users'
|
7
|
+
describe 'GET /users' do
|
8
8
|
before do
|
9
9
|
User.create login: 'alice'
|
10
10
|
end
|
@@ -14,7 +14,7 @@ RSpec.describe UsersController, type: :controller do
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
describe 'GET /users/:login'
|
17
|
+
describe 'GET /users/:login' do
|
18
18
|
before do
|
19
19
|
User.create login: 'alice'
|
20
20
|
end
|
@@ -45,7 +45,6 @@ RSpec.configure do |config|
|
|
45
45
|
# arbitrary gems may also be filtered via:
|
46
46
|
# config.filter_gems_from_backtrace("gem name")
|
47
47
|
|
48
|
-
|
49
48
|
DatabaseCleaner.allow_remote_database_url = true
|
50
49
|
|
51
50
|
config.before(:suite) do
|
@@ -54,13 +53,8 @@ RSpec.configure do |config|
|
|
54
53
|
end
|
55
54
|
|
56
55
|
config.around :each do |example|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
DatabaseCleaner.cleaning do
|
62
|
-
example.run
|
63
|
-
end
|
64
|
-
}.call
|
56
|
+
DatabaseCleaner.cleaning do
|
57
|
+
example.run
|
58
|
+
end
|
65
59
|
end
|
66
60
|
end
|
@@ -61,7 +61,7 @@ describe 'SQL events' do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
context 'while listing records' do
|
64
|
-
let(:test_line_number) {
|
64
|
+
let(:test_line_number) { 29 }
|
65
65
|
let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_GET_api_users_lists_the_users.appmap.json') }
|
66
66
|
|
67
67
|
context 'using Sequel ORM' do
|
data/spec/spec_helper.rb
CHANGED
@@ -14,3 +14,9 @@ require 'appmap'
|
|
14
14
|
RSpec.configure do |config|
|
15
15
|
config.example_status_persistence_file_path = "tmp/rspec_failed_examples.txt"
|
16
16
|
end
|
17
|
+
|
18
|
+
# Re-run the Rails specs without re-generating the data. This is useful for efficiently enhancing and
|
19
|
+
# debugging the test itself.
|
20
|
+
def use_existing_data?
|
21
|
+
ENV['USE_EXISTING_DATA'] == 'true'
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appmap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.43.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Gilpin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|