-
Notifications
You must be signed in to change notification settings - Fork 398
/
sql_patches_spec.rb
49 lines (42 loc) · 1.35 KB
/
sql_patches_spec.rb
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
# frozen_string_literal: true
# this enables activerecord, and allows us to test the auto detection logic
require 'active_record'
describe SqlPatches do
# and patched= to some extent
describe ".all_patch_files" do
it "uses env variable" do
with_patch_env("custom1") do
expect(SqlPatches.all_patch_files).to eq(["custom1"])
end
end
it "uses supports multiple env variable" do
with_patch_env("custom1,custom2") do
expect(SqlPatches.all_patch_files).to eq(["custom1", "custom2"])
end
end
it "strips whitespace from env variable" do
with_patch_env("custom1, custom2") do
expect(SqlPatches.all_patch_files).to eq(["custom1", "custom2"])
end
end
it "allows env var to turn off" do
with_patch_env("false") do
expect(SqlPatches.all_patch_files).to eq([])
end
end
it "uses detection of env variable is not defined" do
with_patch_env(nil) do
expect(SqlPatches.all_patch_files).to eq([])
expect(Rack::MiniProfiler).to receive(:patch_rails?).and_return(true)
expect(SqlPatches.all_patch_files).to eq(["activerecord"])
end
end
end
def with_patch_env(value)
old_value = ENV["RACK_MINI_PROFILER_PATCH"]
ENV["RACK_MINI_PROFILER_PATCH"] = value
yield
ensure
ENV["RACK_MINI_PROFILER_PATCH"] = old_value
end
end