1
0

rails_helper.rb 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ENV['RAILS_ENV'] ||= 'test'
  2. require File.expand_path('../config/environment', __dir__)
  3. abort("The Rails environment is running in production mode!") if Rails.env.production?
  4. require 'spec_helper'
  5. require 'rspec/rails'
  6. require 'webmock/rspec'
  7. require 'paperclip/matchers'
  8. require 'capybara/rspec'
  9. Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
  10. ActiveRecord::Migration.maintain_test_schema!
  11. WebMock.disable_net_connect!(allow: Chewy.settings[:host])
  12. Sidekiq::Testing.inline!
  13. Sidekiq.logger = nil
  14. Devise::Test::ControllerHelpers.module_eval do
  15. alias_method :original_sign_in, :sign_in
  16. def sign_in(resource, _deprecated = nil, scope: nil)
  17. original_sign_in(resource, scope: scope)
  18. SessionActivation.deactivate warden.cookies.signed['_session_id']
  19. warden.cookies.signed['_session_id'] = {
  20. value: resource.activate_session(warden.request),
  21. expires: 1.year.from_now,
  22. httponly: true,
  23. }
  24. end
  25. end
  26. RSpec.configure do |config|
  27. config.fixture_path = "#{::Rails.root}/spec/fixtures"
  28. config.use_transactional_fixtures = true
  29. config.order = 'random'
  30. config.infer_spec_type_from_file_location!
  31. config.filter_rails_from_backtrace!
  32. config.include Devise::Test::ControllerHelpers, type: :controller
  33. config.include Devise::Test::ControllerHelpers, type: :view
  34. config.include Devise::Test::IntegrationHelpers, type: :request
  35. config.include Paperclip::Shoulda::Matchers
  36. config.include ActiveSupport::Testing::TimeHelpers
  37. config.include Redisable
  38. config.before :each, type: :feature do
  39. https = ENV['LOCAL_HTTPS'] == 'true'
  40. Capybara.app_host = "http#{https ? 's' : ''}://#{ENV.fetch('LOCAL_DOMAIN')}"
  41. end
  42. config.before :each, type: :controller do
  43. stub_jsonld_contexts!
  44. end
  45. config.before :each, type: :service do
  46. stub_jsonld_contexts!
  47. end
  48. config.after :each do
  49. Rails.cache.clear
  50. redis.del(redis.keys)
  51. end
  52. end
  53. RSpec::Sidekiq.configure do |config|
  54. config.warn_when_jobs_not_processed_by_sidekiq = false
  55. end
  56. RSpec::Matchers.define_negated_matcher :not_change, :change
  57. def request_fixture(name)
  58. File.read(Rails.root.join('spec', 'fixtures', 'requests', name))
  59. end
  60. def attachment_fixture(name)
  61. File.open(Rails.root.join('spec', 'fixtures', 'files', name))
  62. end
  63. def stub_jsonld_contexts!
  64. stub_request(:get, 'https://www.w3.org/ns/activitystreams').to_return(request_fixture('json-ld.activitystreams.txt'))
  65. stub_request(:get, 'https://w3id.org/identity/v1').to_return(request_fixture('json-ld.identity.txt'))
  66. stub_request(:get, 'https://w3id.org/security/v1').to_return(request_fixture('json-ld.security.txt'))
  67. end