appmap 0.35.0 → 0.37.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) 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 +11 -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 +53 -23
  13. data/lib/appmap/event.rb +21 -6
  14. data/lib/appmap/hook.rb +1 -1
  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/version.rb +2 -2
  19. data/spec/abstract_controller4_base_spec.rb +27 -28
  20. data/spec/abstract_controller_base_spec.rb +43 -39
  21. data/spec/class_map_spec.rb +36 -0
  22. data/spec/fixtures/hook/exception_method.rb +44 -0
  23. data/spec/fixtures/hook/instance_method.rb +4 -0
  24. data/spec/fixtures/{rails_users_app → rails5_users_app}/.dockerignore +0 -0
  25. data/spec/fixtures/{rails_users_app → rails5_users_app}/.gitignore +0 -0
  26. data/spec/fixtures/{rails_users_app → rails5_users_app}/.rspec +0 -0
  27. data/{.ruby-version → spec/fixtures/rails5_users_app/.ruby-version} +0 -0
  28. data/spec/fixtures/{rails_users_app → rails5_users_app}/Dockerfile +0 -0
  29. data/spec/fixtures/{rails_users_app → rails5_users_app}/Dockerfile.pg +0 -0
  30. data/spec/fixtures/rails5_users_app/Gemfile +51 -0
  31. data/spec/fixtures/{rails_users_app → rails5_users_app}/Rakefile +0 -0
  32. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/api/users_controller.rb +0 -0
  33. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/application_controller.rb +0 -0
  34. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/concerns/.keep +0 -0
  35. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/health_controller.rb +0 -0
  36. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/users_controller.rb +0 -0
  37. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/models/activerecord/user.rb +0 -0
  38. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/models/concerns/.keep +0 -0
  39. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/models/sequel/user.rb +0 -0
  40. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/views/layouts/application.html.haml +0 -0
  41. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/views/users/index.html.haml +0 -0
  42. data/spec/fixtures/{rails_users_app → rails5_users_app}/appmap.yml +1 -1
  43. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/appmap +0 -0
  44. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/byebug +0 -0
  45. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/gli +0 -0
  46. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/htmldiff +0 -0
  47. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/ldiff +0 -0
  48. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/nokogiri +0 -0
  49. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rackup +0 -0
  50. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rails +0 -0
  51. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rake +0 -0
  52. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rspec +0 -0
  53. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/ruby-parse +0 -0
  54. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/ruby-rewrite +0 -0
  55. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/sequel +0 -0
  56. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/setup +0 -0
  57. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/sprockets +0 -0
  58. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/thor +0 -0
  59. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/update +0 -0
  60. data/spec/fixtures/{rails_users_app → rails5_users_app}/config.ru +0 -0
  61. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/application.rb +0 -0
  62. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/boot.rb +0 -0
  63. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/credentials.yml.enc +0 -0
  64. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/database.yml +0 -0
  65. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environment.rb +0 -0
  66. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environments/development.rb +0 -0
  67. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environments/production.rb +0 -0
  68. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environments/test.rb +0 -0
  69. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/application_controller_renderer.rb +0 -0
  70. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/backtrace_silencers.rb +0 -0
  71. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/cors.rb +0 -0
  72. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/filter_parameter_logging.rb +0 -0
  73. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/inflections.rb +0 -0
  74. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/mime_types.rb +0 -0
  75. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/record_button.rb +0 -0
  76. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/wrap_parameters.rb +0 -0
  77. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/locales/en.yml +0 -0
  78. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/routes.rb +0 -0
  79. data/spec/fixtures/{rails_users_app → rails5_users_app}/create_app +0 -0
  80. data/spec/fixtures/{rails_users_app → rails5_users_app}/db/migrate/20190728211408_create_users.rb +0 -0
  81. data/spec/fixtures/{rails_users_app → rails5_users_app}/db/schema.rb +0 -0
  82. data/spec/fixtures/{rails_users_app → rails5_users_app}/docker-compose.yml +0 -0
  83. data/spec/fixtures/{rails_users_app → rails5_users_app}/features/api_users.feature +0 -0
  84. data/spec/fixtures/{rails_users_app → rails5_users_app}/features/support/env.rb +0 -0
  85. data/spec/fixtures/{rails_users_app → rails5_users_app}/features/support/hooks.rb +0 -0
  86. data/spec/fixtures/{rails_users_app → rails5_users_app}/features/support/steps.rb +0 -0
  87. data/spec/fixtures/{rails_users_app → rails5_users_app}/lib/tasks/.keep +0 -0
  88. data/spec/fixtures/{rails_users_app → rails5_users_app}/log/.keep +0 -0
  89. data/spec/fixtures/{rails_users_app → rails5_users_app}/public/robots.txt +0 -0
  90. data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/controllers/users_controller_api_spec.rb +0 -0
  91. data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/models/user_spec.rb +0 -0
  92. data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/rails_helper.rb +0 -0
  93. data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/spec_helper.rb +0 -0
  94. data/spec/fixtures/{rails_users_app → rails5_users_app}/users_app/.gitignore +0 -0
  95. data/spec/fixtures/rails6_users_app/.dockerignore +1 -0
  96. data/spec/fixtures/rails6_users_app/.gitignore +39 -0
  97. data/spec/fixtures/rails6_users_app/.rspec +1 -0
  98. data/spec/fixtures/{rails_users_app → rails6_users_app}/.ruby-version +0 -0
  99. data/spec/fixtures/rails6_users_app/Dockerfile +29 -0
  100. data/spec/fixtures/rails6_users_app/Dockerfile.pg +3 -0
  101. data/spec/fixtures/{rails_users_app → rails6_users_app}/Gemfile +0 -0
  102. data/spec/fixtures/rails6_users_app/Rakefile +6 -0
  103. data/spec/fixtures/rails6_users_app/app/controllers/api/users_controller.rb +27 -0
  104. data/spec/fixtures/rails6_users_app/app/controllers/application_controller.rb +2 -0
  105. data/spec/fixtures/rails6_users_app/app/controllers/concerns/.keep +0 -0
  106. data/spec/fixtures/rails6_users_app/app/controllers/health_controller.rb +5 -0
  107. data/spec/fixtures/rails6_users_app/app/controllers/users_controller.rb +5 -0
  108. data/spec/fixtures/rails6_users_app/app/models/activerecord/user.rb +18 -0
  109. data/spec/fixtures/rails6_users_app/app/models/concerns/.keep +0 -0
  110. data/spec/fixtures/rails6_users_app/app/models/sequel/user.rb +25 -0
  111. data/spec/fixtures/rails6_users_app/app/views/layouts/application.html.haml +7 -0
  112. data/spec/fixtures/rails6_users_app/app/views/users/index.html.haml +7 -0
  113. data/spec/fixtures/rails6_users_app/appmap.yml +3 -0
  114. data/spec/fixtures/rails6_users_app/bin/appmap +29 -0
  115. data/spec/fixtures/rails6_users_app/bin/byebug +29 -0
  116. data/spec/fixtures/rails6_users_app/bin/gli +29 -0
  117. data/spec/fixtures/rails6_users_app/bin/htmldiff +29 -0
  118. data/spec/fixtures/rails6_users_app/bin/ldiff +29 -0
  119. data/spec/fixtures/rails6_users_app/bin/nokogiri +29 -0
  120. data/spec/fixtures/rails6_users_app/bin/rackup +29 -0
  121. data/spec/fixtures/rails6_users_app/bin/rails +4 -0
  122. data/spec/fixtures/rails6_users_app/bin/rake +29 -0
  123. data/spec/fixtures/rails6_users_app/bin/rspec +29 -0
  124. data/spec/fixtures/rails6_users_app/bin/ruby-parse +29 -0
  125. data/spec/fixtures/rails6_users_app/bin/ruby-rewrite +29 -0
  126. data/spec/fixtures/rails6_users_app/bin/sequel +29 -0
  127. data/spec/fixtures/rails6_users_app/bin/setup +25 -0
  128. data/spec/fixtures/rails6_users_app/bin/sprockets +29 -0
  129. data/spec/fixtures/rails6_users_app/bin/thor +29 -0
  130. data/spec/fixtures/rails6_users_app/bin/update +25 -0
  131. data/spec/fixtures/rails6_users_app/config.ru +5 -0
  132. data/spec/fixtures/rails6_users_app/config/application.rb +51 -0
  133. data/spec/fixtures/rails6_users_app/config/boot.rb +3 -0
  134. data/spec/fixtures/rails6_users_app/config/credentials.yml.enc +1 -0
  135. data/spec/fixtures/rails6_users_app/config/database.yml +18 -0
  136. data/spec/fixtures/rails6_users_app/config/environment.rb +5 -0
  137. data/spec/fixtures/rails6_users_app/config/environments/development.rb +40 -0
  138. data/spec/fixtures/rails6_users_app/config/environments/production.rb +68 -0
  139. data/spec/fixtures/rails6_users_app/config/environments/test.rb +36 -0
  140. data/spec/fixtures/rails6_users_app/config/initializers/application_controller_renderer.rb +8 -0
  141. data/spec/fixtures/rails6_users_app/config/initializers/backtrace_silencers.rb +7 -0
  142. data/spec/fixtures/rails6_users_app/config/initializers/cors.rb +16 -0
  143. data/spec/fixtures/rails6_users_app/config/initializers/filter_parameter_logging.rb +4 -0
  144. data/spec/fixtures/rails6_users_app/config/initializers/inflections.rb +16 -0
  145. data/spec/fixtures/rails6_users_app/config/initializers/mime_types.rb +4 -0
  146. data/spec/fixtures/rails6_users_app/config/initializers/record_button.rb +3 -0
  147. data/spec/fixtures/rails6_users_app/config/initializers/wrap_parameters.rb +9 -0
  148. data/spec/fixtures/rails6_users_app/config/locales/en.yml +33 -0
  149. data/spec/fixtures/rails6_users_app/config/routes.rb +11 -0
  150. data/spec/fixtures/rails6_users_app/create_app +27 -0
  151. data/spec/fixtures/rails6_users_app/db/migrate/20190728211408_create_users.rb +9 -0
  152. data/spec/fixtures/rails6_users_app/db/schema.rb +23 -0
  153. data/spec/fixtures/rails6_users_app/docker-compose.yml +28 -0
  154. data/spec/fixtures/rails6_users_app/features/api_users.feature +13 -0
  155. data/spec/fixtures/rails6_users_app/features/support/env.rb +4 -0
  156. data/spec/fixtures/rails6_users_app/features/support/hooks.rb +11 -0
  157. data/spec/fixtures/rails6_users_app/features/support/steps.rb +18 -0
  158. data/spec/fixtures/rails6_users_app/lib/tasks/.keep +0 -0
  159. data/spec/fixtures/rails6_users_app/log/.keep +0 -0
  160. data/spec/fixtures/rails6_users_app/public/robots.txt +1 -0
  161. data/spec/fixtures/rails6_users_app/spec/controllers/users_controller_api_spec.rb +29 -0
  162. data/spec/fixtures/rails6_users_app/spec/models/user_spec.rb +39 -0
  163. data/spec/fixtures/rails6_users_app/spec/rails_helper.rb +66 -0
  164. data/spec/fixtures/rails6_users_app/spec/spec_helper.rb +96 -0
  165. data/spec/fixtures/rails6_users_app/users_app/.gitignore +20 -0
  166. data/spec/hook_spec.rb +196 -11
  167. data/spec/rails_spec_helper.rb +5 -5
  168. data/spec/railtie_spec.rb +31 -32
  169. data/spec/record_sql_rails4_pg_spec.rb +47 -48
  170. data/spec/record_sql_rails_pg_spec.rb +62 -63
  171. data/spec/remote_recording_spec.rb +90 -89
  172. data/spec/rspec_feature_metadata_spec.rb +17 -18
  173. data/test/cli_test.rb +0 -10
  174. data/test/expectations/openssl_test_key_sign1.json +55 -0
  175. data/test/expectations/openssl_test_key_sign2.json +58 -0
  176. data/test/fixtures/gem_test/Gemfile +6 -0
  177. data/test/fixtures/gem_test/appmap.yml +3 -0
  178. data/test/fixtures/gem_test/test/to_param_test.rb +14 -0
  179. data/test/gem_test.rb +34 -0
  180. data/test/minitest_test.rb +2 -2
  181. data/test/openssl_test.rb +10 -165
  182. metadata +171 -80
@@ -29,10 +29,10 @@ def run_cmd(*cmd, &failed)
29
29
  raise 'Command failed'
30
30
  end
31
31
 
32
- shared_context 'Rails app pg database' do
33
- before(:all) do
34
- raise 'you must set @fixure_dir' unless @fixture_dir
32
+ shared_context 'Rails app pg database' do |fixture_dir|
33
+ let(:fixture_dir) { fixture_dir }
35
34
 
35
+ before(:all) do
36
36
  print_pg_logs = lambda do
37
37
  logs, = run_cmd 'docker-compose logs pg'
38
38
  puts "docker-compose logs for pg:"
@@ -40,7 +40,7 @@ shared_context 'Rails app pg database' do
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
@@ -54,7 +54,7 @@ shared_context 'Rails app pg database' do
54
54
  after(:all) do
55
55
  if ENV['NOKILL'] != 'true'
56
56
  cmd = 'docker-compose down -v'
57
- run_cmd cmd, chdir: @fixture_dir
57
+ run_cmd cmd, chdir: fixture_dir
58
58
  end
59
59
  end
60
60
  end
@@ -1,43 +1,42 @@
1
1
  require 'rails_spec_helper'
2
2
 
3
3
  describe 'AppMap tracer via Railtie' do
4
- before(:all) { @fixture_dir = 'spec/fixtures/rails_users_app' }
5
- include_context 'Rails app pg database'
6
-
7
- let(:env) { {} }
4
+ include_context 'Rails app pg database', 'spec/fixtures/rails5_users_app' do
5
+ let(:env) { {} }
8
6
 
9
- let(:cmd) { %(docker-compose run --rm -e RAILS_ENV -e APPMAP app ./bin/rails r "puts Rails.configuration.appmap.enabled.inspect") }
10
- let(:command_capture2) do
11
- require 'open3'
12
- Open3.capture3(env, cmd, chdir: @fixture_dir).tap do |result|
13
- unless result[2] == 0
14
- $stderr.puts <<~END
15
- Failed to run rails_users_app container
16
- <<< Output:
17
- #{result[0]}
18
- #{result[1]}
19
- >>> End of output
20
- END
21
- raise 'Failed to run rails_users_app container'
7
+ let(:cmd) { %(docker-compose run --rm -e RAILS_ENV -e APPMAP app ./bin/rails r "puts Rails.configuration.appmap.enabled.inspect") }
8
+ let(:command_capture2) do
9
+ require 'open3'
10
+ Open3.capture3(env, cmd, chdir: fixture_dir).tap do |result|
11
+ unless result[2] == 0
12
+ warn <<~STDERR
13
+ Failed to run rails5_users_app container
14
+ <<< Output:
15
+ #{result[0]}
16
+ #{result[1]}
17
+ >>> End of output
18
+ STDERR
19
+ raise 'Failed to run rails5_users_app container'
20
+ end
22
21
  end
23
22
  end
24
- end
25
- let(:command_output) { command_capture2[0].strip }
26
- let(:command_result) { command_capture2[2] }
27
-
28
- it 'is disabled by default' do
29
- expect(command_output).to eq('nil')
30
- end
23
+ let(:command_output) { command_capture2[0].strip }
24
+ let(:command_result) { command_capture2[2] }
31
25
 
32
- describe 'with APPMAP=true' do
33
- let(:env) { { 'APPMAP' => 'true' } }
34
- it 'is enabled' do
35
- expect(command_output.split("\n")).to include('true')
26
+ it 'is disabled by default' do
27
+ expect(command_output).to eq('nil')
36
28
  end
37
- context 'and RAILS_ENV=test' do
38
- let(:env) { { 'APPMAP' => 'true', 'RAILS_ENV' => 'test' } }
39
- it 'is disabled' do
40
- expect(command_output).to eq('nil')
29
+
30
+ describe 'with APPMAP=true' do
31
+ let(:env) { { 'APPMAP' => 'true' } }
32
+ it 'is enabled' do
33
+ expect(command_output.split("\n")).to include('true')
34
+ end
35
+ context 'and RAILS_ENV=test' do
36
+ let(:env) { { 'APPMAP' => 'true', 'RAILS_ENV' => 'test' } }
37
+ it 'is disabled' do
38
+ expect(command_output).to eq('nil')
39
+ end
41
40
  end
42
41
  end
43
42
  end
@@ -1,75 +1,74 @@
1
1
  require 'rails_spec_helper'
2
2
 
3
3
  describe 'Record SQL queries in a Rails4 app' do
4
- before(:all) { @fixture_dir = 'spec/fixtures/rails4_users_app' }
5
- include_context 'Rails app pg database'
6
-
7
- around(:each) do |example|
8
- FileUtils.rm_rf tmpdir
9
- FileUtils.mkdir_p tmpdir
10
- cmd = "docker-compose run --rm -e ORM_MODULE=#{orm_module} -e APPMAP=true -v #{File.absolute_path tmpdir}:/app/tmp app ./bin/rspec spec/controllers/users_controller_api_spec.rb:#{test_line_number}"
11
- run_cmd cmd, chdir: @fixture_dir
4
+ include_context 'Rails app pg database', 'spec/fixtures/rails4_users_app' do
5
+ around(:each) do |example|
6
+ FileUtils.rm_rf tmpdir
7
+ FileUtils.mkdir_p tmpdir
8
+ cmd = "docker-compose run --rm -e ORM_MODULE=#{orm_module} -e APPMAP=true -v #{File.absolute_path tmpdir}:/app/tmp app ./bin/rspec spec/controllers/users_controller_api_spec.rb:#{test_line_number}"
9
+ run_cmd cmd, chdir: fixture_dir
12
10
 
13
- example.run
14
- end
11
+ example.run
12
+ end
13
+
14
+ let(:tmpdir) { "tmp/spec/record_sql_rails_pg_spec" }
15
+ let(:appmap) { JSON.parse(File.read(appmap_json)).to_yaml }
15
16
 
16
- let(:tmpdir) { "tmp/spec/record_sql_rails_pg_spec" }
17
- let(:appmap) { JSON.parse(File.read(appmap_json)).to_yaml }
17
+ context 'when running specs' do
18
+ let(:test_line_number) { 31 }
19
+ let(:orm_module) { 'activerecord' }
18
20
 
19
- context 'when running specs' do
20
- let(:test_line_number) { 31 }
21
- let(:orm_module) { 'activerecord' }
21
+ it { is_expected.to be }
22
+ end
22
23
 
23
- it { is_expected.to be }
24
- end
25
-
26
- context 'while creating a new record' do
27
- let(:test_line_number) { 8 }
28
- let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_POST_api_users_with_required_parameters_creates_a_user.appmap.json') }
24
+ context 'while creating a new record' do
25
+ let(:test_line_number) { 8 }
26
+ let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_POST_api_users_with_required_parameters_creates_a_user.appmap.json') }
29
27
 
30
- xcontext 'using Sequel ORM' do
31
- let(:orm_module) { 'sequel' }
32
- it 'detects the sql INSERT' do
33
- expect(appmap).to include(<<-SQL_QUERY.strip)
28
+ xcontext 'using Sequel ORM' do
29
+ let(:orm_module) { 'sequel' }
30
+ it 'detects the sql INSERT' do
31
+ expect(appmap).to include(<<-SQL_QUERY.strip)
34
32
  sql_query:
35
33
  sql: INSERT INTO "users" ("login") VALUES ('alice') RETURNING *
36
- SQL_QUERY
34
+ SQL_QUERY
35
+ end
37
36
  end
38
- end
39
- context 'using ActiveRecord ORM' do
40
- let(:orm_module) { 'activerecord' }
41
- it 'detects the sql INSERT' do
42
- expect(appmap).to include(<<-SQL_QUERY.strip)
37
+ context 'using ActiveRecord ORM' do
38
+ let(:orm_module) { 'activerecord' }
39
+ it 'detects the sql INSERT' do
40
+ expect(appmap).to include(<<-SQL_QUERY.strip)
43
41
  sql_query:
44
42
  sql: INSERT INTO "users" ("login", "created_at", "updated_at") VALUES ($1, $2,
45
43
  $3) RETURNING "id"
46
- SQL_QUERY
44
+ SQL_QUERY
45
+ end
47
46
  end
48
47
  end
49
- end
50
48
 
51
- context 'while listing records' do
52
- let(:test_line_number) { 23 }
53
- let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_GET_api_users_lists_the_users.appmap.json') }
49
+ context 'while listing records' do
50
+ let(:test_line_number) { 23 }
51
+ let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_GET_api_users_lists_the_users.appmap.json') }
54
52
 
55
- xcontext 'using Sequel ORM' do
56
- let(:orm_module) { 'sequel' }
57
- it 'detects the sql SELECT' do
58
- expect(appmap).to include(<<-SQL_QUERY.strip)
53
+ xcontext 'using Sequel ORM' do
54
+ let(:orm_module) { 'sequel' }
55
+ it 'detects the sql SELECT' do
56
+ expect(appmap).to include(<<-SQL_QUERY.strip)
59
57
  sql_query:
60
58
  sql: SELECT * FROM "users"
61
- SQL_QUERY
59
+ SQL_QUERY
62
60
 
63
- expect(appmap).to include('sql:')
61
+ expect(appmap).to include('sql:')
62
+ end
64
63
  end
65
- end
66
- context 'using ActiveRecord ORM' do
67
- let(:orm_module) { 'activerecord' }
68
- it 'detects the sql SELECT' do
69
- expect(appmap).to include(<<-SQL_QUERY.strip)
64
+ context 'using ActiveRecord ORM' do
65
+ let(:orm_module) { 'activerecord' }
66
+ it 'detects the sql SELECT' do
67
+ expect(appmap).to include(<<-SQL_QUERY.strip)
70
68
  sql_query:
71
69
  sql: SELECT "users".* FROM "users"
72
- SQL_QUERY
70
+ SQL_QUERY
71
+ end
73
72
  end
74
73
  end
75
74
  end
@@ -1,89 +1,88 @@
1
1
  require 'rails_spec_helper'
2
2
 
3
3
  describe 'SQL events' do
4
- before(:all) { @fixture_dir = 'spec/fixtures/rails_users_app' }
5
- include_context 'Rails app pg database'
4
+ include_context 'Rails app pg database', 'spec/fixtures/rails5_users_app' do
5
+ around(:each) do |example|
6
+ FileUtils.rm_rf tmpdir
7
+ FileUtils.mkdir_p tmpdir
8
+ cmd = "docker-compose run --rm -e ORM_MODULE=#{orm_module} -e APPMAP=true -v #{File.absolute_path tmpdir}:/app/tmp app ./bin/rspec spec/controllers/users_controller_api_spec.rb:#{test_line_number}"
9
+ run_cmd cmd, chdir: fixture_dir
6
10
 
7
- around(:each) do |example|
8
- FileUtils.rm_rf tmpdir
9
- FileUtils.mkdir_p tmpdir
10
- cmd = "docker-compose run --rm -e ORM_MODULE=#{orm_module} -e APPMAP=true -v #{File.absolute_path tmpdir}:/app/tmp app ./bin/rspec spec/controllers/users_controller_api_spec.rb:#{test_line_number}"
11
- run_cmd cmd, chdir: @fixture_dir
12
-
13
- example.run
14
- end
11
+ example.run
12
+ end
15
13
 
16
- let(:tmpdir) { "tmp/spec/record_sql_rails_pg_spec" }
14
+ let(:tmpdir) { "tmp/spec/record_sql_rails_pg_spec" }
17
15
 
18
- describe 'fields' do
19
- let(:test_line_number) { 8 }
20
- let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_POST_api_users_with_required_parameters_creates_a_user.appmap.json') }
21
- let(:orm_module) { 'sequel' }
22
- let(:appmap) { JSON.parse(File.read(appmap_json)) }
23
- describe 'on a call event' do
24
- let(:event) do
25
- appmap['events'].find do |event|
26
- event['event'] == 'call' &&
27
- event.keys.include?('sql_query')
16
+ describe 'fields' do
17
+ let(:test_line_number) { 8 }
18
+ let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_POST_api_users_with_required_parameters_creates_a_user.appmap.json') }
19
+ let(:orm_module) { 'sequel' }
20
+ let(:appmap) { JSON.parse(File.read(appmap_json)) }
21
+ describe 'on a call event' do
22
+ let(:event) do
23
+ appmap['events'].find do |event|
24
+ event['event'] == 'call' &&
25
+ event.keys.include?('sql_query')
26
+ end
27
+ end
28
+ it 'do not include function-only fields' do
29
+ expect(event.keys).to_not include('defined_class')
30
+ expect(event.keys).to_not include('method_id')
31
+ expect(event.keys).to_not include('path')
32
+ expect(event.keys).to_not include('lineno')
28
33
  end
29
- end
30
- it 'do not include function-only fields' do
31
- expect(event.keys).to_not include('defined_class')
32
- expect(event.keys).to_not include('method_id')
33
- expect(event.keys).to_not include('path')
34
- expect(event.keys).to_not include('lineno')
35
34
  end
36
35
  end
37
- end
38
36
 
39
- describe 'in a Rails app' do
40
- let(:appmap) { JSON.parse(File.read(appmap_json)).to_yaml }
41
- context 'while creating a new record' do
42
- let(:test_line_number) { 8 }
43
- let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_POST_api_users_with_required_parameters_creates_a_user.appmap.json') }
37
+ describe 'in a Rails app' do
38
+ let(:appmap) { JSON.parse(File.read(appmap_json)).to_yaml }
39
+ context 'while creating a new record' do
40
+ let(:test_line_number) { 8 }
41
+ let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_POST_api_users_with_required_parameters_creates_a_user.appmap.json') }
44
42
 
45
- context 'using Sequel ORM' do
46
- let(:orm_module) { 'sequel' }
47
- it 'detects the sql INSERT' do
48
- expect(appmap).to include(<<-SQL_QUERY.strip)
43
+ context 'using Sequel ORM' do
44
+ let(:orm_module) { 'sequel' }
45
+ it 'detects the sql INSERT' do
46
+ expect(appmap).to include(<<-SQL_QUERY.strip)
49
47
  sql_query:
50
48
  sql: INSERT INTO "users" ("login") VALUES ('alice') RETURNING *
51
- SQL_QUERY
49
+ SQL_QUERY
50
+ end
52
51
  end
53
- end
54
- context 'using ActiveRecord ORM' do
55
- let(:orm_module) { 'activerecord' }
56
- it 'detects the sql INSERT' do
57
- expect(appmap).to include(<<-SQL_QUERY.strip)
52
+ context 'using ActiveRecord ORM' do
53
+ let(:orm_module) { 'activerecord' }
54
+ it 'detects the sql INSERT' do
55
+ expect(appmap).to include(<<-SQL_QUERY.strip)
58
56
  sql_query:
59
57
  sql: INSERT INTO "users" ("login") VALUES ($1) RETURNING "id"
60
- SQL_QUERY
58
+ SQL_QUERY
59
+ end
61
60
  end
62
61
  end
63
- end
64
-
65
- context 'while listing records' do
66
- let(:test_line_number) { 23 }
67
- let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_GET_api_users_lists_the_users.appmap.json') }
68
-
69
- context 'using Sequel ORM' do
70
- let(:orm_module) { 'sequel' }
71
- it 'detects the sql SELECT' do
72
- expect(appmap).to include(<<-SQL_QUERY.strip)
62
+
63
+ context 'while listing records' do
64
+ let(:test_line_number) { 23 }
65
+ let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_GET_api_users_lists_the_users.appmap.json') }
66
+
67
+ context 'using Sequel ORM' do
68
+ let(:orm_module) { 'sequel' }
69
+ it 'detects the sql SELECT' do
70
+ expect(appmap).to include(<<-SQL_QUERY.strip)
73
71
  sql_query:
74
72
  sql: SELECT * FROM "users"
75
- SQL_QUERY
76
-
77
- expect(appmap).to include('sql:')
73
+ SQL_QUERY
74
+
75
+ expect(appmap).to include('sql:')
76
+ end
78
77
  end
79
- end
80
- context 'using ActiveRecord ORM' do
81
- let(:orm_module) { 'activerecord' }
82
- it 'detects the sql SELECT' do
83
- expect(appmap).to include(<<-SQL_QUERY.strip)
78
+ context 'using ActiveRecord ORM' do
79
+ let(:orm_module) { 'activerecord' }
80
+ it 'detects the sql SELECT' do
81
+ expect(appmap).to include(<<-SQL_QUERY.strip)
84
82
  sql_query:
85
83
  sql: SELECT "users".* FROM "users"
86
- SQL_QUERY
84
+ SQL_QUERY
85
+ end
87
86
  end
88
87
  end
89
88
  end
@@ -3,115 +3,116 @@ require 'net/http'
3
3
  require 'socket'
4
4
 
5
5
  describe 'remote recording', :order => :defined do
6
- before(:all) { @fixture_dir = 'spec/fixtures/rails_users_app' }
7
- include_context 'Rails app pg database'
8
-
9
- before(:all) do
10
- start_cmd = 'docker-compose up -d app'
11
- run_cmd({ 'ORM_MODULE' => 'sequel', 'APPMAP' => 'true' }, start_cmd, chdir: @fixture_dir)
12
- Dir.chdir @fixture_dir do
13
- wait_for_container 'app'
14
- end
15
-
16
- port_cmd = 'docker-compose port app 3000'
17
- port_out, = run_cmd port_cmd, chdir: @fixture_dir
18
- @service_port = port_out.strip.split(':')[1]
19
-
20
- service_running = false
21
- retry_count = 0
22
- uri = URI("http://localhost:#{@service_port}/health")
6
+ include_context 'Rails app pg database', 'spec/fixtures/rails5_users_app' do
7
+ before(:all) do
8
+ fixture_dir = 'spec/fixtures/rails5_users_app'
9
+ start_cmd = 'docker-compose up -d app'
10
+ run_cmd({ 'ORM_MODULE' => 'sequel', 'APPMAP' => 'true' }, start_cmd, chdir: fixture_dir)
11
+ Dir.chdir fixture_dir do
12
+ wait_for_container 'app'
13
+ end
23
14
 
24
- until service_running
25
- sleep(0.25)
26
- begin
27
- res = Net::HTTP.start(uri.hostname, uri.port) do |http|
28
- http.request(Net::HTTP::Get.new(uri))
15
+ port_cmd = 'docker-compose port app 3000'
16
+ port_out, = run_cmd port_cmd, chdir: fixture_dir
17
+ @service_port = port_out.strip.split(':')[1]
18
+
19
+ service_running = false
20
+ retry_count = 0
21
+ uri = URI("http://localhost:#{@service_port}/health")
22
+
23
+ until service_running
24
+ sleep(0.25)
25
+ begin
26
+ res = Net::HTTP.start(uri.hostname, uri.port) do |http|
27
+ http.request(Net::HTTP::Get.new(uri))
28
+ end
29
+
30
+ status = res.response.code.to_i
31
+ service_running = true if status >= 200 && status < 300
32
+
33
+ # give up after a certain error threshold is met
34
+ # we don't want to wait forever if there's an unrecoverable issue
35
+ raise 'gave up waiting on fixture service' if (retry_count += 1) == 10
36
+ rescue Errno::ETIMEDOUT, Errno::ECONNRESET, EOFError
37
+ $stderr.print('.')
29
38
  end
30
-
31
- status = res.response.code.to_i
32
- service_running = true if status >= 200 && status < 300
33
-
34
- # give up after a certain error threshold is met
35
- # we don't want to wait forever if there's an unrecoverable issue
36
- raise 'gave up waiting on fixture service' if (retry_count += 1) == 10
37
- rescue Errno::ETIMEDOUT, Errno::ECONNRESET, EOFError
38
- $stderr.print('.')
39
39
  end
40
40
  end
41
- end
42
41
 
43
- def json_body(res)
44
- JSON.parse(res.body).deep_symbolize_keys
45
- end
42
+ def json_body(res)
43
+ JSON.parse(res.body).deep_symbolize_keys
44
+ end
46
45
 
47
- after(:all) do
48
- run_cmd 'docker-compose rm -fs app', chdir: @fixture_dir
49
- end
46
+ after(:all) do
47
+ fixture_dir = 'spec/fixtures/rails5_users_app'
48
+ run_cmd 'docker-compose rm -fs app', chdir: fixture_dir
49
+ end
50
50
 
51
- let(:service_address) { URI("http://localhost:#{@service_port}") }
52
- let(:users_path) { '/users' }
53
- let(:record_path) { '/_appmap/record' }
51
+ let(:service_address) { URI("http://localhost:#{@service_port}") }
52
+ let(:users_path) { '/users' }
53
+ let(:record_path) { '/_appmap/record' }
54
54
 
55
- it 'returns the recording status' do
56
- res = Net::HTTP.start(service_address.hostname, service_address.port) { |http|
57
- http.request(Net::HTTP::Get.new(record_path))
58
- }
55
+ it 'returns the recording status' do
56
+ res = Net::HTTP.start(service_address.hostname, service_address.port) { |http|
57
+ http.request(Net::HTTP::Get.new(record_path))
58
+ }
59
59
 
60
- expect(res).to be_a(Net::HTTPOK)
61
- expect(res['Content-Type']).to eq('application/json')
62
- expect(json_body(res)).to eq(enabled: false)
63
- end
60
+ expect(res).to be_a(Net::HTTPOK)
61
+ expect(res['Content-Type']).to eq('application/json')
62
+ expect(json_body(res)).to eq(enabled: false)
63
+ end
64
64
 
65
- it 'starts a new recording session' do
66
- res = Net::HTTP.start(service_address.hostname, service_address.port) { |http|
67
- http.request(Net::HTTP::Post.new(record_path))
68
- }
65
+ it 'starts a new recording session' do
66
+ res = Net::HTTP.start(service_address.hostname, service_address.port) { |http|
67
+ http.request(Net::HTTP::Post.new(record_path))
68
+ }
69
69
 
70
- expect(res).to be_a(Net::HTTPOK)
71
- end
70
+ expect(res).to be_a(Net::HTTPOK)
71
+ end
72
72
 
73
- it 'reflects the recording status' do
74
- res = Net::HTTP.start(service_address.hostname, service_address.port) { |http|
75
- http.request(Net::HTTP::Get.new(record_path))
76
- }
73
+ it 'reflects the recording status' do
74
+ res = Net::HTTP.start(service_address.hostname, service_address.port) { |http|
75
+ http.request(Net::HTTP::Get.new(record_path))
76
+ }
77
77
 
78
- expect(res).to be_a(Net::HTTPOK)
79
- expect(res['Content-Type']).to eq('application/json')
80
- expect(json_body(res)).to eq(enabled: true)
81
- end
78
+ expect(res).to be_a(Net::HTTPOK)
79
+ expect(res['Content-Type']).to eq('application/json')
80
+ expect(json_body(res)).to eq(enabled: true)
81
+ end
82
82
 
83
- it 'fails to start a new recording session while recording is already active' do
84
- res = Net::HTTP.start(service_address.hostname, service_address.port) { |http|
85
- http.request(Net::HTTP::Post.new(record_path))
86
- }
83
+ it 'fails to start a new recording session while recording is already active' do
84
+ res = Net::HTTP.start(service_address.hostname, service_address.port) { |http|
85
+ http.request(Net::HTTP::Post.new(record_path))
86
+ }
87
87
 
88
- expect(res).to be_a(Net::HTTPConflict)
89
- end
88
+ expect(res).to be_a(Net::HTTPConflict)
89
+ end
90
90
 
91
- it 'stops recording' do
92
- # Generate some events
93
- Net::HTTP.start(service_address.hostname, service_address.port) { |http|
94
- http.request(Net::HTTP::Get.new(users_path) )
95
- }
91
+ it 'stops recording' do
92
+ # Generate some events
93
+ Net::HTTP.start(service_address.hostname, service_address.port) { |http|
94
+ http.request(Net::HTTP::Get.new(users_path) )
95
+ }
96
96
 
97
- res = Net::HTTP.start(service_address.hostname, service_address.port) { |http|
98
- http.request(Net::HTTP::Delete.new(record_path))
99
- }
97
+ res = Net::HTTP.start(service_address.hostname, service_address.port) { |http|
98
+ http.request(Net::HTTP::Delete.new(record_path))
99
+ }
100
100
 
101
- expect(res).to be_a(Net::HTTPOK)
102
- expect(res['Content-Type']).to eq('application/json')
101
+ expect(res).to be_a(Net::HTTPOK)
102
+ expect(res['Content-Type']).to eq('application/json')
103
103
 
104
- data = json_body(res)
105
- expect(data[:metadata]).to be_truthy
106
- expect(data[:classMap].length).to be > 0
107
- expect(data[:events].length).to be > 0
108
- end
104
+ data = json_body(res)
105
+ expect(data[:metadata]).to be_truthy
106
+ expect(data[:classMap].length).to be > 0
107
+ expect(data[:events].length).to be > 0
108
+ end
109
109
 
110
- it 'fails to stop recording if there is no active recording session' do
111
- res = Net::HTTP.start(service_address.hostname, service_address.port) { |http|
112
- http.request(Net::HTTP::Delete.new(record_path))
113
- }
110
+ it 'fails to stop recording if there is no active recording session' do
111
+ res = Net::HTTP.start(service_address.hostname, service_address.port) { |http|
112
+ http.request(Net::HTTP::Delete.new(record_path))
113
+ }
114
114
 
115
- expect(res).to be_a(Net::HTTPNotFound)
115
+ expect(res).to be_a(Net::HTTPNotFound)
116
+ end
116
117
  end
117
118
  end