-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathspec_helper.rb
More file actions
126 lines (103 loc) · 3.9 KB
/
spec_helper.rb
File metadata and controls
126 lines (103 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
require 'simplecov'
require 'coveralls'
Coveralls::Output.no_color = true
formatters = [
Coveralls::SimpleCov::Formatter,
SimpleCov::Formatter::HTMLFormatter
]
SimpleCov.formatters = formatters
SimpleCov.start 'rails' do
add_group 'Services', 'app/services'
add_group 'Serializers', 'app/serializers'
end
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
require 'sidekiq/testing'
require 'capybara/rspec'
require 'capybara/rails'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
Dir[Rails.root.join('spec/shared/*.rb')].each { |f| require f }
Dir[Rails.root.join('spec/models/nomenclature_change/shared/*.rb')].each { |f| require f }
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = false
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = true
config.infer_spec_type_from_file_location!
config.include ActiveSupport::Testing::TimeHelpers
config.include Devise::Test::ControllerHelpers, type: :controller
config.extend ControllerMacros, type: :controller
config.include FactoryBot::Syntax::Methods
config.include JsonSpec::Helpers
config.include SapiSpec::Helpers
config.before(:all) do
# https://github.com/thoughtbot/factory_bot/issues/1255
# https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#build-strategies-1
FactoryBot.use_parent_strategy = false
DatabaseCleaner.clean_with(:deletion, { cache_tables: false })
@user = create(:user)
RequestStore.store[:track_who_does_it_current_user] = @user
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, drops_tables: true) do
DatabaseCleaner.strategy = :deletion, { cache_tables: false }
ApplicationRecord.connection.execute('SELECT * FROM drop_trade_sandboxes()')
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
# this is duplicated here because of the :drops_tables specs
@user = create(:user)
RequestStore.store[:track_who_does_it_current_user] = @user
end
config.before(:each) do |example|
# Clears out the jobs for tests using the fake testing
Sidekiq::Worker.clear_all
# Get the current example from the example_method object
if example.metadata[:sidekiq] == :fake
Sidekiq::Testing.fake!
elsif example.metadata[:sidekiq] == :inline
Sidekiq::Testing.inline!
elsif example.metadata[:type] == :feature
Sidekiq::Testing.inline!
else
Sidekiq::Testing.fake!
end
end
config.before(:each) do |example|
if example.metadata[:cache]
memory_store = ActiveSupport::Cache.lookup_store(:memory_store)
allow(
Rails.application.config.action_controller
).to receive(:perform_caching).and_return(true)
allow(Rails).to receive(:cache).and_return(memory_store)
Rails.cache.clear
end
end
end
def build_attributes(*args)
FactoryBot.build(*args).attributes.delete_if do |k, v|
[ 'id', 'created_at', 'updated_at', 'touched_at' ].member?(k)
end
end