-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathapi_version_constraint_middleware_spec.rb
58 lines (44 loc) · 1.36 KB
/
api_version_constraint_middleware_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
50
51
52
53
54
55
56
57
58
require 'rails_helper'
require 'securerandom'
RSpec.describe "/api/hellos", type: :request do
let(:version) { 8 }
let(:accept_header) { "application/json; version=#{version}" }
let(:headers) {
h = {}
h["Accept"] = accept_header if accept_header
h
}
before do
Stitches.configuration.reset_to_defaults!
Stitches.configuration.allowlist_regexp = /.*hello.*/
Stitches::ApiClientAccessWrapper.clear_api_cache
end
context "when correctly configured for version 1" do
let(:version) { 1 }
it "executes the correct controller" do
get "/api/hellos", headers: headers
expect(response.body).to include "Hello"
end
end
context "when correctly configured for version 2" do
let(:version) { 2 }
it "executes the correct controller" do
get "/api/hellos", headers: headers
expect(response.body).to include "Greetings"
end
end
context "when correctly configured for a version that does not exist" do
let(:version) { 6 }
it "fails to map to a controller" do
get "/api/hellos", headers: headers
expect(response).to be_not_found
end
end
context "when accept header is missing version" do
let(:accept_header) { "application/json" }
it "fails to map to a controller" do
get "/api/hellos", headers: headers
expect(response).to be_not_found
end
end
end