appmap 0.38.1 → 0.39.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0255347aa61c6f39bfec0f43a78b3cc3060bd20e4f80f1e39e0ff3714a52dff3
4
- data.tar.gz: 822bc2fe118426d6d9c9437c85ead8e603a446cabd6bd49d0053c2b1cfaf3789
3
+ metadata.gz: 7f48fa55666d8310e8a24c268a7b72c1748c22fe0aa9b884000b1e83a703dbac
4
+ data.tar.gz: 5d82f1809e549bc71659048a9dce037eafe6e261c63c09d127bbd6b1f43d5b3c
5
5
  SHA512:
6
- metadata.gz: 031534a5eb015fa99d6ad161665b131677cadbe41ed1bce20357cb1ded7ba19e5f0bcbe37cfef0c8ad35cc2904fe83e4cc9d2b12d04260b970d24cc9aea64ba3
7
- data.tar.gz: e7996262f4da21936567c1238df624220987ed04bf5aebd9a525da4d3f181ca752c1060056a5bb41b52c9cdb29e958cf7335973ac7076113278c7e8583755477
6
+ metadata.gz: 5077fd340fac2478af5361e518c777b8ef76ffeb358aee18f6f507a6314b687ea02a40721b32fe0d2886d279e76ed3d249f9ebfd7b850fb05a1d5d2168b62c6c
7
+ data.tar.gz: 97b2c5306bd7b07d9f853b883d1ece37f6160683ae0eec5c5d6afe9e6909311468fb2def4e2f70c439ad18a56f9262e77569c7385b2d34dca28e02119302b57d
@@ -4,6 +4,9 @@ AllCops:
4
4
  Layout/CaseIndentation:
5
5
  EnforcedStyle: end
6
6
 
7
+ Layout/FirstArgumentIndentation:
8
+ EnforcedStyle: consistent
9
+
7
10
  Layout/SpaceInsideArrayLiteralBrackets:
8
11
  Enabled: false
9
12
 
@@ -17,13 +20,14 @@ Layout/LineLength:
17
20
  Metrics/BlockLength:
18
21
  ExcludedMethods:
19
22
  - it
23
+ - context
20
24
 
21
25
  Style/MultilineBlockChain:
22
26
  Enabled: false
23
27
 
24
28
  Style/NumericPredicate:
25
29
  Enabled: false
26
-
30
+
27
31
  Style/AndOr:
28
32
  Enabled: false
29
33
 
@@ -28,13 +28,6 @@ jobs:
28
28
  script:
29
29
  - bundle exec rake build:base:2.6
30
30
 
31
- - stage: fixtures
32
- script:
33
- - bundle exec rake build:fixtures:2.5:all
34
- - stage: fixtures
35
- script:
36
- - bundle exec rake build:fixtures:2.6:all
37
-
38
31
  - stage: spec
39
32
  script:
40
33
  - bundle exec rake spec:2.5
@@ -1,3 +1,7 @@
1
+ # v0.39.0
2
+
3
+ * Recognize and record `normalized_path_info` in Rails applications, per 1.4 AppMap format version.
4
+
1
5
  # v0.38.1
2
6
 
3
7
  * Package configuration can be `shallow`, in case which only the initial entry into the package is recorded.
data/README.md CHANGED
@@ -171,16 +171,22 @@ Note that `test_helper.rb` in a Rails project typically loads the application's
171
171
  require_relative '../config/environment'
172
172
  ```
173
173
 
174
- and `appmap/rspec` must be required before this:
174
+ and `appmap/minitest` must be required before this:
175
175
 
176
176
  ```ruby
177
- require 'appmap/rspec'
177
+ require 'appmap/minitest'
178
178
  require_relative '../config/environment'
179
179
  ```
180
180
 
181
- 2) Run the tests with the environment variable `APPMAP=true`:
181
+ 2) Run your tests as you normally would with the environment variable `APPMAP=true`. For example:
182
182
 
183
- ```sh-session
183
+ ```
184
+ $ APPMAP=true bundle exec rake
185
+ ```
186
+
187
+ or
188
+
189
+ ```
184
190
  $ APPMAP=true bundle exec -Ilib -Itest test/*
185
191
  ```
186
192
 
@@ -7,12 +7,13 @@ module AppMap
7
7
  module Rails
8
8
  module RequestHandler
9
9
  class HTTPServerRequest < AppMap::Event::MethodEvent
10
- attr_accessor :request_method, :path_info, :params
10
+ attr_accessor :normalized_path_info, :request_method, :path_info, :params
11
11
 
12
12
  def initialize(request)
13
13
  super AppMap::Event.next_id_counter, :call, Thread.current.object_id
14
14
 
15
15
  @request_method = request.request_method
16
+ @normalized_path_info = normalized_path request
16
17
  @path_info = request.path_info.split('?')[0]
17
18
  # ActionDispatch::Http::ParameterFilter is deprecated
18
19
  parameter_filter_cls = \
@@ -28,8 +29,9 @@ module AppMap
28
29
  super.tap do |h|
29
30
  h[:http_server_request] = {
30
31
  request_method: request_method,
31
- path_info: path_info
32
- }
32
+ path_info: path_info,
33
+ normalized_path_info: normalized_path_info
34
+ }.compact
33
35
 
34
36
  h[:message] = params.keys.map do |key|
35
37
  val = params[key]
@@ -42,6 +44,13 @@ module AppMap
42
44
  end
43
45
  end
44
46
  end
47
+
48
+ private
49
+
50
+ def normalized_path(request)
51
+ route = ::Rails.application.routes.router.enum_for(:recognize, request).first
52
+ route.first.path.spec.to_s if route
53
+ end
45
54
  end
46
55
 
47
56
  class HTTPServerResponse < AppMap::Event::MethodReturnIgnoreValue
@@ -3,7 +3,7 @@
3
3
  module AppMap
4
4
  URL = 'https://github.com/applandinc/appmap-ruby'
5
5
 
6
- VERSION = '0.38.1'
6
+ VERSION = '0.39.0'
7
7
 
8
- APPMAP_FORMAT_VERSION = '1.3'
8
+ APPMAP_FORMAT_VERSION = '1.4'
9
9
  end
@@ -1,120 +1,150 @@
1
1
  require 'rails_spec_helper'
2
2
 
3
3
  describe 'AbstractControllerBase' do
4
- shared_examples 'rails version' do |rails_major_version|
5
- include_context 'Rails app pg database', "spec/fixtures/rails#{rails_major_version}_users_app" do
4
+ %w[5 6].each do |rails_major_version| # rubocop:disable Metrics/BlockLength
5
+ context "in Rails #{rails_major_version}" do
6
+ include_context 'Rails app pg database', "spec/fixtures/rails#{rails_major_version}_users_app"
6
7
  def run_spec(spec_name)
7
- cmd = "docker-compose run --rm -e APPMAP=true -v #{File.absolute_path tmpdir}:/app/tmp app ./bin/rspec #{spec_name}"
8
+ FileUtils.rm_rf tmpdir
9
+ FileUtils.mkdir_p tmpdir
10
+ cmd = <<~CMD.gsub "\n", ' '
11
+ docker-compose run --rm -e APPMAP=true
12
+ -v #{File.absolute_path tmpdir}:/app/tmp app ./bin/rspec #{spec_name}
13
+ CMD
8
14
  run_cmd cmd, chdir: fixture_dir
9
15
  end
10
16
 
11
- before do
12
- FileUtils.rm_rf tmpdir
13
- FileUtils.mkdir_p tmpdir
14
- run_spec spec_name
17
+ def tmpdir
18
+ 'tmp/spec/AbstractControllerBase'
15
19
  end
16
20
 
17
- let(:tmpdir) { 'tmp/spec/AbstractControllerBase' }
21
+ let(:appmap) { JSON.parse File.read File.join tmpdir, 'appmap/rspec', appmap_json_file }
22
+ let(:events) { appmap['events'] }
18
23
 
19
24
  describe 'testing with rspec' do
20
- let(:spec_name) { 'spec/controllers/users_controller_api_spec.rb:8' }
21
- let(:appmap_json_file) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_POST_api_users_with_required_parameters_creates_a_user.appmap.json') }
22
-
23
25
  describe 'creating a user' do
26
+ before(:all) { run_spec 'spec/controllers/users_controller_api_spec.rb:8' }
27
+ let(:appmap_json_file) do
28
+ 'Api_UsersController_POST_api_users_with_required_parameters_creates_a_user.appmap.json'
29
+ end
30
+
24
31
  it 'inventory file is printed' do
25
32
  expect(File).to exist(File.join(tmpdir, 'appmap/rspec/Inventory.appmap.json'))
26
33
  end
27
34
 
28
35
  it 'message fields are recorded in the appmap' do
29
- expect(File).to exist(appmap_json_file)
30
- appmap = JSON.parse(File.read(appmap_json_file)).to_yaml
31
-
32
- expect(appmap).to include(<<-MESSAGE.strip)
33
- message:
34
- - name: login
35
- class: String
36
- value: alice
37
- object_id:
38
- MESSAGE
39
-
40
- expect(appmap).to include(<<-MESSAGE.strip)
41
- - name: password
42
- class: String
43
- value: "[FILTERED]"
44
- object_id:
45
- MESSAGE
46
-
47
- expect(appmap).to include(<<-SERVER_REQUEST.strip)
48
- http_server_request:
49
- request_method: POST
50
- path_info: "/api/users"
51
- SERVER_REQUEST
52
-
53
- expect(appmap).to include(<<-SERVER_RESPONSE.strip)
54
- http_server_response:
55
- status: 201
56
- mime_type: application/json; charset=utf-8
57
- SERVER_RESPONSE
36
+ expect(events).to include(
37
+ hash_including(
38
+ 'http_server_request' => hash_including(
39
+ 'request_method' => 'POST',
40
+ 'path_info' => '/api/users'
41
+ ),
42
+ 'message' => include(
43
+ hash_including(
44
+ 'name' => 'login',
45
+ 'class' => 'String',
46
+ 'value' => 'alice',
47
+ 'object_id' => Integer
48
+ ),
49
+ hash_including(
50
+ 'name' => 'password',
51
+ 'class' => 'String',
52
+ 'value' => '[FILTERED]',
53
+ 'object_id' => Integer
54
+ )
55
+ )
56
+ ),
57
+ hash_including(
58
+ 'http_server_response' => {
59
+ 'status' => 201,
60
+ 'mime_type' => 'application/json; charset=utf-8'
61
+ }
62
+ )
63
+ )
58
64
  end
59
65
 
60
66
  it 'properly captures method parameters in the appmap' do
61
- expect(File).to exist(appmap_json_file)
62
- appmap = JSON.parse(File.read(appmap_json_file)).to_yaml
63
-
64
- expect(appmap).to match(<<-CREATE_CALL.strip)
65
- event: call
66
- thread_id: .*
67
- defined_class: Api::UsersController
68
- method_id: build_user
69
- path: app/controllers/api/users_controller.rb
70
- lineno: 23
71
- static: false
72
- parameters:
73
- - name: params
74
- class: ActiveSupport::HashWithIndifferentAccess
75
- object_id: .*
76
- value: '{"login"=>"alice"}'
77
- kind: req
78
- receiver:
79
- CREATE_CALL
67
+ expect(events).to include hash_including(
68
+ 'event' => 'call',
69
+ 'thread_id' => Integer,
70
+ 'defined_class' => 'Api::UsersController',
71
+ 'method_id' => 'build_user',
72
+ 'path' => 'app/controllers/api/users_controller.rb',
73
+ 'lineno' => 23,
74
+ 'static' => false,
75
+ 'parameters' => include(
76
+ 'name' => 'params',
77
+ 'class' => 'ActiveSupport::HashWithIndifferentAccess',
78
+ 'object_id' => Integer,
79
+ 'value' => '{"login"=>"alice"}',
80
+ 'kind' => 'req'
81
+ ),
82
+ 'receiver' => anything
83
+ )
80
84
  end
81
85
 
82
86
  it 'returns a minimal event' do
83
- expect(File).to exist(appmap_json_file)
84
- appmap = JSON.parse(File.read(appmap_json_file))
85
- event = appmap['events'].find { |event| event['event'] == 'return' && event['return_value'] }
86
- expect(event.keys).to eq(%w[id event thread_id parent_id elapsed return_value])
87
+ expect(events).to include hash_including(
88
+ 'event' => 'return',
89
+ 'return_value' => Hash,
90
+ 'id' => Integer,
91
+ 'thread_id' => Integer,
92
+ 'parent_id' => Integer,
93
+ 'elapsed' => Numeric
94
+ )
87
95
  end
88
96
  end
89
97
 
90
- describe 'listing users' do
91
- let(:spec_name) { 'spec/controllers/users_controller_spec.rb:11' }
92
- let(:appmap_json_file) { File.join(tmpdir, 'appmap/rspec/UsersController_GET_users_lists_the_users.appmap.json') }
93
- it 'records and labels view rendering' do
94
- expect(File).to exist(appmap_json_file)
95
- appmap = JSON.parse(File.read(appmap_json_file)).to_yaml
98
+ describe 'showing a user' do
99
+ before(:all) { run_spec 'spec/controllers/users_controller_spec.rb:22' }
100
+ let(:appmap_json_file) do
101
+ 'UsersController_GET_users_login_shows_the_user.appmap.json'
102
+ end
96
103
 
97
- expect(appmap).to match(<<-VIEW_CALL.strip)
98
- event: call
99
- thread_id: .*
100
- defined_class: ActionView::Renderer
101
- method_id: render
102
- path: .*
103
- lineno: .*
104
- static: false
105
- VIEW_CALL
104
+ it 'records the normalized path info' do
105
+ expect(events).to include(
106
+ hash_including(
107
+ 'http_server_request' => {
108
+ 'request_method' => 'GET',
109
+ 'path_info' => '/users/alice',
110
+ 'normalized_path_info' => '/users/:id(.:format)'
111
+ }
112
+ )
113
+ )
114
+ end
115
+ end
106
116
 
107
- expect(appmap).to match(<<-VIEW_LABEL.strip)
108
- labels:
109
- - view
110
- VIEW_LABEL
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
+
121
+ it 'records and labels view rendering' do
122
+ expect(events).to include hash_including(
123
+ 'event' => 'call',
124
+ 'thread_id' => Numeric,
125
+ 'defined_class' => 'ActionView::Renderer',
126
+ 'method_id' => 'render',
127
+ 'path' => String,
128
+ 'lineno' => Integer,
129
+ 'static' => false
130
+ )
131
+
132
+ expect(appmap['classMap']).to include hash_including(
133
+ 'name' => 'action_view',
134
+ 'children' => include(hash_including(
135
+ 'name' => 'ActionView',
136
+ 'children' => include(hash_including(
137
+ 'name' => 'Renderer',
138
+ 'children' => include(hash_including(
139
+ 'name' => 'render',
140
+ 'labels' => ['view']
141
+ ))
142
+ ))
143
+ ))
144
+ )
111
145
  end
112
146
  end
113
147
  end
114
148
  end
115
149
  end
116
-
117
- %w[5 6].each do |version|
118
- it_behaves_like 'rails version', version
119
- end
120
150
  end
@@ -2,4 +2,12 @@ class UsersController < ApplicationController
2
2
  def index
3
3
  @users = User.all
4
4
  end
5
+
6
+ def show
7
+ if (@user = User[login: params[:id]])
8
+ render plain: @user
9
+ else
10
+ render plain: 'Not found', status: 404
11
+ end
12
+ end
5
13
  end
@@ -3,7 +3,7 @@ Rails.application.routes.draw do
3
3
  resources :users, only: %i[index create]
4
4
  end
5
5
 
6
- resources :users, only: %i[index]
6
+ resources :users, only: %i[index show]
7
7
 
8
8
  get 'health', to: 'health#show'
9
9
 
@@ -13,4 +13,15 @@ RSpec.describe UsersController, type: :controller do
13
13
  expect(response).to be_ok
14
14
  end
15
15
  end
16
+
17
+ describe 'GET /users/:login', feature: 'Show a user' do
18
+ before do
19
+ User.create login: 'alice'
20
+ end
21
+
22
+ it 'shows the user' do
23
+ get :show, params: { id: 'alice' }
24
+ expect(response).to be_ok
25
+ end
26
+ end
16
27
  end
@@ -2,4 +2,12 @@ class UsersController < ApplicationController
2
2
  def index
3
3
  @users = User.all
4
4
  end
5
+
6
+ def show
7
+ if (@user = User[login: params[:id]])
8
+ render plain: @user
9
+ else
10
+ render plain: 'Not found', status: 404
11
+ end
12
+ end
5
13
  end
@@ -3,7 +3,7 @@ Rails.application.routes.draw do
3
3
  resources :users, only: %i[index create]
4
4
  end
5
5
 
6
- resources :users, only: %i[index]
6
+ resources :users, only: %i[index show]
7
7
 
8
8
  get 'health', to: 'health#show'
9
9
 
@@ -13,4 +13,15 @@ RSpec.describe UsersController, type: :controller do
13
13
  expect(response).to be_ok
14
14
  end
15
15
  end
16
+
17
+ describe 'GET /users/:login', feature: 'Show a user' do
18
+ before do
19
+ User.create login: 'alice'
20
+ end
21
+
22
+ it 'shows the user' do
23
+ get :show, params: { id: 'alice' }
24
+ expect(response).to be_ok
25
+ end
26
+ end
16
27
  end
@@ -30,7 +30,7 @@ def run_cmd(*cmd, &failed)
30
30
  end
31
31
 
32
32
  shared_context 'Rails app pg database' do |fixture_dir|
33
- let(:fixture_dir) { fixture_dir }
33
+ define_method(:fixture_dir) { fixture_dir }
34
34
 
35
35
  before(:all) do
36
36
  print_pg_logs = lambda do
@@ -40,7 +40,7 @@ shared_context 'Rails app pg database' do |fixture_dir|
40
40
  puts logs
41
41
  end
42
42
 
43
- Dir.chdir fixture_dir do
43
+ Dir.chdir fixture_dir do
44
44
  run_cmd 'docker-compose down -v'
45
45
  cmd = 'docker-compose up -d pg'
46
46
  run_cmd cmd
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.38.1
4
+ version: 0.39.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: 2020-12-30 00:00:00.000000000 Z
11
+ date: 2021-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport