rspeckled 1.4.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +2 -1
  3. data/LICENSE.txt +1 -1
  4. data/lib/rspeckled/helpers/factories.rb +8 -2
  5. data/lib/rspeckled/helpers/filepaths.rb +30 -22
  6. data/lib/rspeckled/helpers/null_objects.rb +8 -2
  7. data/lib/rspeckled/helpers/patterns.rb +75 -41
  8. data/lib/rspeckled/helpers/responses.rb +8 -2
  9. data/lib/rspeckled/patches.rb +8 -6
  10. data/lib/rspeckled/plugins/configuration/capybara_screenshot.rb +5 -4
  11. data/lib/rspeckled/plugins/configuration/carrier_wave.rb +1 -1
  12. data/lib/rspeckled/plugins/configuration/devise.rb +4 -4
  13. data/lib/rspeckled/plugins/configuration/dox.rb +4 -6
  14. data/lib/rspeckled/plugins/configuration/email_spec.rb +3 -3
  15. data/lib/rspeckled/plugins/configuration/factory_bot.rb +2 -2
  16. data/lib/rspeckled/plugins/configuration/shoulda.rb +2 -2
  17. data/lib/rspeckled/plugins/configuration/vcr.rb +6 -4
  18. data/lib/rspeckled/plugins/configuration/warden.rb +3 -2
  19. data/lib/rspeckled/plugins/extensions/awesome_print.rb +20 -7
  20. data/lib/rspeckled/plugins/extensions/capybara.rb +16 -6
  21. data/lib/rspeckled/plugins/extensions/faraday/middleware/curl_logger.rb +10 -3
  22. data/lib/rspeckled/plugins/extensions/faraday.rb +2 -1
  23. data/lib/rspeckled/plugins/extensions/omniauth/mock_authentications/ebay.rb +1 -1
  24. data/lib/rspeckled/plugins/extensions/omniauth/mock_authentications/facebook.rb +1 -1
  25. data/lib/rspeckled/plugins/extensions/omniauth/mock_authentications/twitter.rb +1 -1
  26. data/lib/rspeckled/plugins/extensions/omniauth.rb +6 -3
  27. data/lib/rspeckled/plugins/extensions/ruby/deferred_garbage_collection.rb +3 -1
  28. data/lib/rspeckled/plugins/extensions/selenium/drivers/chrome.rb +6 -6
  29. data/lib/rspeckled/plugins/extensions/selenium/drivers/firefox.rb +14 -3
  30. data/lib/rspeckled/plugins/extensions/strong_parameters.rb +2 -1
  31. data/lib/rspeckled/plugins/extensions/vcr/matchers/uri_without_trailing_id.rb +3 -1
  32. data/lib/rspeckled/plugins/extensions/vcr.rb +8 -4
  33. data/lib/rspeckled/plugins/hooks/action_mailer.rb +2 -2
  34. data/lib/rspeckled/plugins/hooks/authentication.rb +87 -64
  35. data/lib/rspeckled/plugins/hooks/bullet.rb +3 -1
  36. data/lib/rspeckled/plugins/hooks/capybara.rb +2 -2
  37. data/lib/rspeckled/plugins/hooks/carrier_wave.rb +2 -2
  38. data/lib/rspeckled/plugins/hooks/database_cleaner.rb +3 -11
  39. data/lib/rspeckled/plugins/hooks/devise.rb +1 -1
  40. data/lib/rspeckled/plugins/hooks/dox.rb +1 -1
  41. data/lib/rspeckled/plugins/hooks/elasticsearch.rb +13 -9
  42. data/lib/rspeckled/plugins/hooks/factory_bot.rb +1 -1
  43. data/lib/rspeckled/plugins/hooks/foreign_keys.rb +39 -33
  44. data/lib/rspeckled/plugins/hooks/garbage_collection.rb +1 -1
  45. data/lib/rspeckled/plugins/hooks/rails.rb +52 -0
  46. data/lib/rspeckled/plugins/hooks/redis.rb +3 -3
  47. data/lib/rspeckled/plugins/hooks/referehencible.rb +2 -2
  48. data/lib/rspeckled/plugins/hooks/request.rb +1 -1
  49. data/lib/rspeckled/plugins/hooks/rspec_mocks.rb +8 -4
  50. data/lib/rspeckled/plugins/hooks/selenium_webdriver.rb +2 -2
  51. data/lib/rspeckled/plugins/hooks/sidekiq.rb +14 -12
  52. data/lib/rspeckled/plugins/hooks/singletons.rb +2 -2
  53. data/lib/rspeckled/plugins/hooks/stripe.rb +5 -3
  54. data/lib/rspeckled/plugins/hooks/timecop.rb +3 -3
  55. data/lib/rspeckled/plugins/hooks/vcr.rb +2 -2
  56. data/lib/rspeckled/plugins/hooks/warden.rb +3 -3
  57. data/lib/rspeckled/plugins/hooks/webmock.rb +3 -3
  58. data/lib/rspeckled/plugins.rb +22 -18
  59. data/lib/rspeckled/reporting/example.rb +10 -8
  60. data/lib/rspeckled/reporting/outputs/csv.rb +2 -0
  61. data/lib/rspeckled/reporting/outputs/text.rb +17 -15
  62. data/lib/rspeckled/reporting/runner.rb +26 -24
  63. data/lib/rspeckled/spec_helpers/active_record_connection_setup.rb +13 -12
  64. data/lib/rspeckled/spec_helpers/rails_engine.rb +2 -2
  65. data/lib/rspeckled/spec_helpers/rspeckled.rb +17 -1
  66. data/lib/rspeckled/support.rb +26 -22
  67. data/lib/rspeckled/tasks/documentation.rake +28 -8
  68. data/lib/rspeckled/version.rb +3 -1
  69. data.tar.gz.sig +0 -0
  70. metadata +30 -28
  71. metadata.gz.sig +0 -0
@@ -13,16 +13,16 @@ class Chrome
13
13
  def driver(app)
14
14
  ::Capybara::Selenium::Driver.new(
15
15
  app,
16
- :browser => :chrome,
17
- :options => options
16
+ browser: :chrome,
17
+ options: options,
18
18
  )
19
19
  end
20
20
 
21
21
  def headless(app)
22
22
  ::Capybara::Selenium::Driver.new(
23
23
  app,
24
- :browser => :chrome,
25
- :options => headless_options
24
+ browser: :chrome,
25
+ options: headless_options,
26
26
  )
27
27
  end
28
28
 
@@ -36,8 +36,8 @@ class Chrome
36
36
 
37
37
  def options
38
38
  browser_options = ::Selenium::WebDriver::Chrome::Options.new
39
- browser_options.add_preference(:profile, :prompt_for_download => { :popups => 0 })
40
- browser_options.add_preference(:download, :default_directory => downloads_directory)
39
+ browser_options.add_preference(:profile, prompt_for_download: { popups: 0 })
40
+ browser_options.add_preference(:download, default_directory: downloads_directory)
41
41
  browser_options.add_argument('--window-size=1920,1200')
42
42
  browser_options
43
43
  end
@@ -11,11 +11,17 @@ class Firefox
11
11
  end
12
12
 
13
13
  def driver(app)
14
- ::Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile, :options => options)
14
+ ::Capybara::Selenium::Driver.new(app,
15
+ browser: :firefox,
16
+ profile: profile,
17
+ options: options)
15
18
  end
16
19
 
17
20
  def headless(app)
18
- ::Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile, :options => headless_options)
21
+ ::Capybara::Selenium::Driver.new(app,
22
+ browser: :firefox,
23
+ profile: profile,
24
+ options: headless_options)
19
25
  end
20
26
 
21
27
  private
@@ -30,7 +36,12 @@ class Firefox
30
36
  ::Selenium::WebDriver::Firefox::Profile.new.tap do |profile|
31
37
  profile['browser.download.dir'] = downloads_directory
32
38
  profile['browser.download.folderList'] = 2
33
- profile['browser.helperApps.neverAsk.saveToDisk'] = 'images/jpeg, application/pdf, application/octet-stream'
39
+ profile['browser.helperApps.neverAsk.saveToDisk'] = %w{
40
+ images/jpeg
41
+ application/pdf
42
+ application/octet-stream
43
+ }
44
+ .join(', ')
34
45
  profile['pdfjs.disabled'] = true
35
46
  end
36
47
  end
@@ -3,7 +3,8 @@
3
3
  always_permitted_parameters = %w{id}
4
4
 
5
5
  if ::ActionController::Parameters.respond_to?(:always_permitted_parameters)
6
- ::ActionController::Parameters.always_permitted_parameters += always_permitted_parameters
6
+ ::ActionController::Parameters
7
+ .always_permitted_parameters += always_permitted_parameters
7
8
  else
8
9
  always_permitted_parameters.each do |always_permitted_parameter|
9
10
  ::ActionController::Parameters::NEVER_UNPERMITTED_PARAMS << always_permitted_parameter
@@ -16,7 +16,9 @@ class UriWithoutTrailingId
16
16
 
17
17
  if request_uri.match?(trailing_id_matcher)
18
18
  request_uri_without_id = request_uri.sub(trailing_id_matcher, '')
19
- vcr_cassette_request_uri_without_id = vcr_cassette_request_uri.sub(trailing_id_matcher, '')
19
+ vcr_cassette_request_uri_without_id = vcr_cassette_request_uri.sub(
20
+ trailing_id_matcher, ''
21
+ )
20
22
 
21
23
  request_uri.match(trailing_id_matcher) &&
22
24
  vcr_cassette_request_uri.match(trailing_id_matcher) &&
@@ -3,11 +3,15 @@
3
3
  require 'rspeckled/plugins/extensions/vcr/matchers/uri_without_trailing_id'
4
4
 
5
5
  ::VCR.configure do |config|
6
- config.register_request_matcher :uri_without_trailing_guid do |request, vcr_cassette_request|
7
- ::Rspeckled::Vcr::Matchers::UriWithoutTrailingId.new(%r(/[a-f0-9\-]{32,36}/?\z)).call(request, vcr_cassette_request)
6
+ config.register_request_matcher :uri_without_trailing_guid do |request, vcr_request|
7
+ ::Rspeckled::Vcr::Matchers::UriWithoutTrailingId
8
+ .new(%r(/[a-f0-9\-]{32,36}/?\z))
9
+ .call(request, vcr_request)
8
10
  end
9
11
 
10
- config.register_request_matcher :uri_without_trailing_id do |request, vcr_cassette_request|
11
- ::Rspeckled::Vcr::Matchers::UriWithoutTrailingId.new(%r{/\d+/?\z}).call(request, vcr_cassette_request)
12
+ config.register_request_matcher :uri_without_trailing_id do |request, vcr_request|
13
+ ::Rspeckled::Vcr::Matchers::UriWithoutTrailingId
14
+ .new(%r{/\d+/?\z})
15
+ .call(request, vcr_request)
12
16
  end
13
17
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.configure do |config|
4
- config.before(:each, :email => true) do
3
+ ::RSpec.configure do |config|
4
+ config.before(:each, email: true) do
5
5
  config.rspeckled_logger.debug("Before Each - Start - #{__FILE__}")
6
6
 
7
7
  if ::ActionMailer::Base.delivery_method == :cache
@@ -1,30 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.configure do |config|
4
- config.around(:each, :authentication => lambda { |v| !!v }) do |example|
3
+ # rubocop:disable Metrics/BlockNesting
4
+ ::RSpec.configure do |config| # rubocop:disable Metrics/BlockLength
5
+ config.around(:each, authentication: ->(v) { !v.nil? }) do |example| # rubocop:disable Metrics/BlockLength
5
6
  config.rspeckled_logger.debug("Around Each - Start - #{__FILE__}")
6
7
 
7
- options = if example.metadata[:authentication].is_a?(::Hash)
8
- example.metadata[:authentication]
9
- else
10
- {
11
- :token => {
12
- :roles => example.metadata[:authentication],
13
- },
14
- }
15
- end
16
-
17
- options[:class] ||= described_class
18
- .name[/\A([^:]+)::/, 1]
19
- .concat('::User')
20
- .constantize
21
-
22
- class_name_underscored = options[:class]
23
- .name[/(?:.*::)?(\w+)\z/, 1]
24
- .gsub(/([a-z])([A-Z])/, '\1_\2')
25
- .downcase
26
-
27
- defaults = {
8
+ options = if example.metadata[:authentication].is_a?(::Hash)
9
+ example.metadata[:authentication]
10
+ else
11
+ {
12
+ token: {
13
+ roles: example.metadata[:authentication],
14
+ },
15
+ }
16
+ end
17
+
18
+ options[:class] ||= described_class
19
+ .name[/\A([^:]+)::/, 1]
20
+ .concat('::User')
21
+ .constantize
22
+
23
+ class_name_underscored = options[:class]
24
+ .name[/(?:.*::)?(\w+)\z/, 1]
25
+ .gsub(/([a-z])([A-Z])/, '\1_\2')
26
+ .downcase
27
+ defaults = {
28
28
  :type => :json_web_token,
29
29
  :authentication_method => :"authenticate_#{class_name_underscored}!",
30
30
  :class_instance_overrides => {},
@@ -33,58 +33,80 @@ RSpec.configure do |config|
33
33
  :strategy => :factory,
34
34
  :successful? => true,
35
35
  :token => {
36
- :roles => 'standard',
36
+ roles: 'standard',
37
37
  },
38
38
  }
39
39
 
40
- options = defaults.deep_merge(options)
41
-
42
- instance = case options[:strategy]
43
- when :factory
44
- ::FactoryBot.create(class_name_underscored.to_sym, *options[:class_instance_traits], options[:class_instance_overrides])
45
- when :instance
46
- options[:class].new(options[:class_instance_overrides])
47
- end
48
-
49
- authentication_result = options[:successful?] ? instance : nil
40
+ options = defaults.deep_merge(options)
41
+ instance = case options[:strategy]
42
+ when :factory
43
+ ::FactoryBot.create(
44
+ class_name_underscored.to_sym,
45
+ *options[:class_instance_traits],
46
+ options[:class_instance_overrides],
47
+ )
48
+ when :instance
49
+ options[:class].new(options[:class_instance_overrides])
50
+ end
51
+ authentication_result = options[:successful?] ? instance : nil
50
52
 
51
53
  case options[:type]
52
54
  when :standard
53
- authentication_controller_class = (example.metadata[:type] == :controller) ? described_class : ApplicationController
54
- authentication_controller_instance = authentication_controller_class.new
55
- authentication_method = if authentication_controller_instance.respond_to?(options[:authentication_method], true)
56
- options[:authentication_method]
57
- elsif authentication_controller_instance.respond_to?(:authenticate, true)
58
- :authenticate
59
- end
60
-
61
- authentication_controller_class.__send__(:define_method, authentication_method) { options[:successful?] }
62
- authentication_controller_class.__send__(:define_method, options[:method]) { authentication_result }
55
+ authentication_controller_class = if example.metadata[:type] == :controller
56
+ described_class
57
+ else
58
+ ApplicationController
59
+ end
60
+ authentication_controller_instance = authentication_controller_class.new
61
+ authentication_method = if authentication_controller_instance
62
+ .respond_to?(
63
+ options[:authentication_method],
64
+ true,
65
+ )
66
+
67
+ options[:authentication_method]
68
+ elsif authentication_controller_instance
69
+ .respond_to?(:authenticate, true)
70
+
71
+ :authenticate
72
+ end
73
+
74
+ authentication_controller_class.__send__(:define_method, authentication_method) do
75
+ options[:successful?]
76
+ end
77
+
78
+ authentication_controller_class.__send__(:define_method, options[:method]) do
79
+ authentication_result
80
+ end
81
+
63
82
  authentication_controller_class.__send__(:helper_method, options[:method])
64
- example.example_group_instance.class.let(options[:method]) { authentication_result }
83
+ example.example_group_instance.class.let(options[:method]) { authentication_result }
65
84
 
66
85
  example.run
67
86
 
68
87
  authentication_controller_class.__send__(:remove_method, options[:method])
69
88
  when :json_web_token
70
- @token_data = [
71
- {
72
- 'aid' => options[:token][:audience_id] || instance['account_id'] || instance['id'],
73
- 'aud' => options[:token][:audience] || instance.class.name,
74
- 'exp' => options[:token][:expired_at] || 1.day.from_now.utc.to_i,
75
- 'iat' => options[:token][:issued_at] || ::Time.now.utc.to_i,
76
- 'iss' => options[:token][:issuer] || 'rspeckled',
77
- 'jti' => options[:token][:token_id] || ::SecureRandom.uuid,
78
- 'nbf' => options[:token][:not_before] || 1.day.ago.utc.to_i,
79
- 'rol' => options[:token][:roles] || 'standard',
80
- 'sid' => options[:token][:subject_id],
81
- 'sub' => options[:token][:subject],
82
- },
83
- {
84
- 'typ' => 'JWT',
85
- 'cty' => 'application/json-web-token',
86
- },
87
- ]
89
+ @token_data =
90
+ [
91
+ {
92
+ 'aid' => options[:token][:audience_id] ||
93
+ instance['account_id'] ||
94
+ instance['id'],
95
+ 'aud' => options[:token][:audience] || instance.class.name,
96
+ 'exp' => options[:token][:expired_at] || 1.day.from_now.utc.to_i,
97
+ 'iat' => options[:token][:issued_at] || ::Time.now.utc.to_i,
98
+ 'iss' => options[:token][:issuer] || 'rspeckled',
99
+ 'jti' => options[:token][:token_id] || ::SecureRandom.uuid,
100
+ 'nbf' => options[:token][:not_before] || 1.day.ago.utc.to_i,
101
+ 'rol' => options[:token][:roles] || 'standard',
102
+ 'sid' => options[:token][:subject_id],
103
+ 'sub' => options[:token][:subject],
104
+ },
105
+ {
106
+ 'typ' => 'JWT',
107
+ 'cty' => 'application/json-web-token',
108
+ },
109
+ ]
88
110
 
89
111
  example.example_group_instance.class.let(options[:method]) { authentication_result }
90
112
 
@@ -96,7 +118,7 @@ RSpec.configure do |config|
96
118
  config.rspeckled_logger.debug("Around Each - End - #{__FILE__}")
97
119
  end
98
120
 
99
- config.before(:each, :authentication => lambda { |v| !!v }) do |_example|
121
+ config.before(:each, authentication: ->(v) { !v.nil? }) do |_example|
100
122
  config.rspeckled_logger.debug("Before Each - Start - #{__FILE__}")
101
123
 
102
124
  request.env['X_JSON_WEB_TOKEN'] = @token_data
@@ -104,3 +126,4 @@ RSpec.configure do |config|
104
126
  config.rspeckled_logger.debug("Before Each - End - #{__FILE__}")
105
127
  end
106
128
  end
129
+ # rubocop:enable Metrics/BlockNesting
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.configure do |config|
3
+ # rubocop:disable Metrics/BlockNesting
4
+ ::RSpec.configure do |config|
4
5
  config.before(:each) do
5
6
  config.rspeckled_logger.debug("Before Each - Start - #{__FILE__}")
6
7
 
@@ -20,3 +21,4 @@ RSpec.configure do |config|
20
21
  config.rspeckled_logger.debug("After Each - End - #{__FILE__}")
21
22
  end
22
23
  end
24
+ # rubocop:enable Metrics/BlockNesting
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.configure do |config|
4
- config.before(:each, :js => true) do
4
+ config.before(:each, js: true) do
5
5
  config.rspeckled_logger.debug("Before Each - Start - #{__FILE__}")
6
6
 
7
7
  page.driver.reset!
@@ -10,7 +10,7 @@ RSpec.configure do |config|
10
10
  end
11
11
 
12
12
  # Focus The Browser on Activation
13
- config.around(:each, :js => true, :autofocus => true) do |example|
13
+ config.around(:each, js: true, autofocus: true) do |example|
14
14
  config.rspeckled_logger.debug("Around Each - Start - #{__FILE__}")
15
15
 
16
16
  browser_name = example.metadata[:driver].to_s.capitalize
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.configure do |config|
4
- config.around(:each, :file_attachment => true) do |example|
3
+ ::RSpec.configure do |config|
4
+ config.around(:each, file_attachment: true) do |example|
5
5
  config.rspeckled_logger.debug("Around Each - Start - #{__FILE__}")
6
6
 
7
7
  previous_carrierwave_processing_mode = subject.class.enable_processing
@@ -1,18 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- begin
4
- autodetected = ::DatabaseCleaner::Base.new.__send__(:autodetect)
5
- rescue ::DatabaseCleaner::NoORMDetected
6
- autodetected = false
7
- end
8
-
9
- return unless autodetected
10
-
11
3
  RSpec.configure do |config|
12
4
  config.before(:suite) do
13
5
  config.rspeckled_logger.debug("Before Suite - Start - #{__FILE__}")
14
6
 
15
- ::DatabaseCleaner.clean_with(:truncation, :except => %w{ar_internal_metadata})
7
+ ::DatabaseCleaner.clean_with(:truncation, except: %w{ar_internal_metadata})
16
8
 
17
9
  config.rspeckled_logger.debug("Before Suite - End - #{__FILE__}")
18
10
  end
@@ -20,8 +12,8 @@ RSpec.configure do |config|
20
12
  config.around(:each) do |example|
21
13
  config.rspeckled_logger.debug("Around Each - Start - #{__FILE__}")
22
14
 
23
- ::DatabaseCleaner.strategy = if example.metadata[:js] || %i{mongoid}.include?(autodetected)
24
- [:truncation, :except => %w{ar_internal_metadata}]
15
+ ::DatabaseCleaner.strategy = if example.metadata[:js]
16
+ [:truncation, { except: %w{ar_internal_metadata} }]
25
17
  else
26
18
  :transaction
27
19
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.configure do |config|
4
- config.before(:each, :type => :controller) do |_example|
4
+ config.before(:each, type: :controller) do |_example|
5
5
  config.rspeckled_logger.debug("Before Each - Start - #{__FILE__}")
6
6
 
7
7
  @request.env['devise.mapping'] = ::Devise.mappings[:user]
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.configure do |config|
3
+ ::RSpec.configure do |config|
4
4
  config.after(:each, :dox) do |example|
5
5
  example.metadata[:request] = request
6
6
  example.metadata[:response] = response
@@ -1,15 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.configure do |config|
4
- config.before(:all, :elasticsearch => lambda { |v| !!v }) do
3
+ ::RSpec.configure do |config|
4
+ config.before(:all, elasticsearch: ->(v) { !v.nil? }) do
5
5
  config.rspeckled_logger.debug("Before All - Start - #{__FILE__}")
6
6
 
7
- ::Elasticsearch::Extensions::Test::Cluster.start(:port => 9200) unless ::Elasticsearch::Extensions::Test::Cluster.running?
7
+ unless ::Elasticsearch::Extensions::Test::Cluster.running?
8
+ ::Elasticsearch::Extensions::Test::Cluster.start(port: 9200)
9
+ end
8
10
 
9
11
  config.rspeckled_logger.debug("Before All - End - #{__FILE__}")
10
12
  end
11
13
 
12
- config.around(:each, :elasticsearch => lambda { |v| !!v }) do |example|
14
+ config.around(:each, elasticsearch: ->(v) { !v.nil? }) do |example|
13
15
  config.rspeckled_logger.debug("Around Each - Start - #{__FILE__}")
14
16
 
15
17
  model = case example.metadata[:elasticsearch]
@@ -17,20 +19,22 @@ RSpec.configure do |config|
17
19
  example.metadata[:elasticsearch].constantize
18
20
  end
19
21
 
20
- model.__elasticsearch__.client.indices.delete :index => '_all'
21
- model.__elasticsearch__.create_index! :index => model.index_name
22
+ model.__elasticsearch__.client.indices.delete index: '_all'
23
+ model.__elasticsearch__.create_index! index: model.index_name
22
24
 
23
25
  example.run
24
26
 
25
- model.__elasticsearch__.client.indices.delete :index => '_all'
27
+ model.__elasticsearch__.client.indices.delete index: '_all'
26
28
 
27
29
  config.rspeckled_logger.debug("Around Each - End - #{__FILE__}")
28
30
  end
29
31
 
30
- config.after(:all, :elasticsearch => lambda { |v| !!v }) do
32
+ config.after(:all, elasticsearch: ->(v) { !v.nil? }) do
31
33
  config.rspeckled_logger.debug("After All - Start - #{__FILE__}")
32
34
 
33
- ::Elasticsearch::Extensions::Test::Cluster.stop(:port => 9200) if ::Elasticsearch::Extensions::Test::Cluster.running?
35
+ if ::Elasticsearch::Extensions::Test::Cluster.running?
36
+ ::Elasticsearch::Extensions::Test::Cluster.stop(port: 9200)
37
+ end
34
38
 
35
39
  config.rspeckled_logger.debug("After All - End - #{__FILE__}")
36
40
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.configure do |config|
3
+ ::RSpec.configure do |config|
4
4
  config.before(:suite) do
5
5
  config.rspeckled_logger.debug("Before Suite - Start - #{__FILE__}")
6
6
 
@@ -1,66 +1,72 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.configure do |config|
4
- config.around(:each, :disable_foreign_keys => lambda { |v| !!v }) do |example|
3
+ # rubocop:disable Metrics/BlockNesting
4
+ ::RSpec.configure do |config| # rubocop:disable Metrics/BlockLength
5
+ config.around(:each, disable_foreign_keys: ->(v) { !v.nil? }) do |example| # rubocop:disable Metrics/BlockLength
5
6
  config.rspeckled_logger.debug("Around Each - Start - #{__FILE__}")
6
7
 
7
8
  options = example.metadata[:disable_foreign_keys]
8
9
  options = case options
9
10
  when ::Array
10
- { :tables => options.map(&:to_s) }
11
+ { tables: options.map(&:to_s) }
11
12
  when ::String, ::Symbol
12
- { :tables => [options.to_s] }
13
+ { tables: [options.to_s] }
13
14
  when ::FalseClass
14
- { :tables => [] }
15
+ { tables: [] }
15
16
  when ::TrueClass
16
- { :tables => :all }
17
+ { tables: :all }
17
18
  end
18
19
 
19
- foreign_key_names_sql = <<~HEREDOC
20
+ foreign_key_disable_sql = <<~HEREDOC
20
21
  SELECT
21
- "constraint_column_usage"."constraint_name",
22
- "pg_class"."relname" AS "local_table_name",
23
- "constraint_column_usage"."table_name" AS "foreign_table_name",
24
- "constraint_column_usage"."column_name" AS "foreign_column_name"
22
+ 'ALTER TABLE "' || "pg_namespace"."nspname" || '"."' || "pg_class"."relname" || '" DISABLE TRIGGER "' || "pg_trigger"."tgname" || '";' AS "statement"
25
23
  FROM
26
- "information_schema"."constraint_column_usage"
27
- INNER JOIN
28
- "pg_constraint"
29
- ON
30
- "constraint_column_usage"."constraint_name" = "pg_constraint"."conname"
24
+ "pg_trigger"
31
25
  INNER JOIN
32
26
  "pg_class"
33
- ON
34
- "pg_class"."oid" = "pg_constraint"."conrelid"
27
+ ON
28
+ "pg_trigger"."tgrelid" = "pg_class"."oid"
29
+ INNER JOIN
30
+ "pg_namespace"
31
+ ON
32
+ "pg_class"."relnamespace" = "pg_namespace"."oid"
33
+ INNER JOIN
34
+ "pg_proc"
35
+ ON
36
+ "pg_trigger"."tgfoid" = "pg_proc"."oid"
35
37
  WHERE
36
- "pg_constraint"."contype" = 'f'
37
- AND
38
- "pg_constraint"."condeferrable" = 't'
38
+ regexp_match("pg_proc"."proname", '.*_FKey_.*') IS NOT NULL
39
39
  HEREDOC
40
40
 
41
41
  unless options[:tables] == :all
42
- foreign_key_names_sql += " AND\n"
42
+ foreign_key_disable_sql += " AND\n "
43
43
 
44
44
  table_constraint_sql = options[:tables]
45
45
  .map { |table_name| "'#{table_name}'" }
46
46
  .join(', ')
47
47
 
48
- foreign_key_names_sql += %Q{ "pg_class"."relname" IN (#{table_constraint_sql})}
48
+ foreign_key_disable_sql += %Q{ "pg_class"."relname" IN (#{table_constraint_sql})}
49
49
  end
50
50
 
51
- foreign_keys_to_disable = ::ActiveRecord::Base.connection.select_values(foreign_key_names_sql).join(',')
51
+ foreign_key_disable = ::ActiveRecord::Base
52
+ .connection
53
+ .select_values(foreign_key_disable_sql)
54
+ .join(' ')
52
55
 
53
- if foreign_keys_to_disable.blank?
54
- puts 'You asked to disable foreign keys but there were no foreign keys found to disable'
55
- else
56
- ::ActiveRecord::Base.connection.execute('SET CONSTRAINTS %<key_pattern>s DEFERRED' % { :key_pattern => foreign_keys_to_disable })
57
- end
58
-
59
- example.run
56
+ ::ActiveRecord::Base.transaction do
57
+ if foreign_key_disable.blank?
58
+ puts(<<~HEREDOC).tr("\n", ' ')
59
+ You asked to disable foreign keys but there were no foreign keys found
60
+ to disable
61
+ HEREDOC
62
+ else
63
+ ::ActiveRecord::Base.connection.execute(foreign_key_disable)
64
+ end
60
65
 
61
- # Remember we don't have to re-enable foreign keys because database cleaner
62
- # will do that for us when it rolls back the transaction
66
+ example.run
67
+ end
63
68
 
64
69
  config.rspeckled_logger.debug("Around Each - End - #{__FILE__}")
65
70
  end
66
71
  end
72
+ # rubocop:enable Metrics/BlockNesting
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'rspeckled/plugins/extensions/ruby/deferred_garbage_collection'
4
4
 
5
- RSpec.configure do |config|
5
+ ::RSpec.configure do |config|
6
6
  config.before(:all) do
7
7
  config.rspeckled_logger.debug("Before All - Start - #{__FILE__}")
8
8
 
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Layout/LineLength
4
+ ::RSpec.configure do |config| # rubocop:disable Metrics/BlockLength
5
+ config.around(:each, debug: true) do |example| # rubocop:disable Metrics/BlockLength
6
+ config.rspeckled_logger.debug("Around Each - Start - #{__FILE__}")
7
+
8
+ debug_rails_logger = ::ActiveSupport::TaggedLogging.new(::ActiveSupport::Logger.new($stdout))
9
+ debug_rails_logger.level = :debug
10
+
11
+ current_rails_configuration_logger = ::Rails.configuration.logger
12
+ current_rails_configuration_logger_level = ::Rails.configuration.log_level
13
+
14
+ current_action_cable_logger = ::ActionCable.server.config.logger if defined?(::ActionCable)
15
+ current_action_controller_logger = ::ActionController::Base.logger if defined?(::ActionController)
16
+ current_action_mailer_logger = ::ActionMailer::Base.logger if defined?(::ActionMailer)
17
+ current_action_view_logger = ::ActionView::Base.logger if defined?(::ActionView)
18
+ current_active_job_logger = ::ActiveJob::Base.logger if defined?(::ActiveJob)
19
+ current_active_record_logger = ::ActiveRecord::Base.logger if defined?(::ActiveRecord)
20
+ current_active_storage_logger = ::ActiveStorage.logger if defined?(::ActiveStorage)
21
+ current_rails_logger = ::Rails.logger if defined?(::Rails)
22
+
23
+ ::Rails.configuration.log_level = debug_rails_logger.level
24
+ ::Rails.configuration.logger = debug_rails_logger
25
+
26
+ ::ActionCable.server.config.logger = debug_rails_logger if defined?(::ActionCable)
27
+ ::ActionController::Base.logger = debug_rails_logger if defined?(::ActionController)
28
+ ::ActionMailer::Base.logger = debug_rails_logger if defined?(::ActionMailer)
29
+ ::ActionView::Base.logger = debug_rails_logger if defined?(::ActionView)
30
+ ::ActiveJob::Base.logger = debug_rails_logger if defined?(::ActiveJob)
31
+ ::ActiveRecord::Base.logger = debug_rails_logger if defined?(::ActiveRecord)
32
+ ::ActiveStorage.logger = debug_rails_logger if defined?(::ActiveStorage)
33
+ ::Rails.logger = debug_rails_logger if defined?(::Rails)
34
+
35
+ example.run
36
+
37
+ ::Rails.configuration.logger = current_rails_configuration_logger
38
+ ::Rails.configuration.log_level = current_rails_configuration_logger_level
39
+
40
+ ::ActionCable.server.config.logger = current_action_cable_logger if defined?(::ActionCable)
41
+ ::ActionController::Base.logger = current_action_controller_logger if defined?(::ActionController)
42
+ ::ActionMailer::Base.logger = current_action_mailer_logger if defined?(::ActionMailer)
43
+ ::ActionView::Base.logger = current_action_view_logger if defined?(::ActionView)
44
+ ::ActiveJob::Base.logger = current_active_job_logger if defined?(::ActiveJob)
45
+ ::ActiveRecord::Base.logger = current_active_record_logger if defined?(::ActiveRecord)
46
+ ::ActiveStorage.logger = current_active_storage_logger if defined?(::ActiveStorage)
47
+ ::Rails.logger = current_rails_logger if defined?(::Rails)
48
+
49
+ config.rspeckled_logger.debug("Around Each - End - #{__FILE__}") if defined?(config)
50
+ end
51
+ end
52
+ # rubocop:enable Layout/LineLength