|
149 | 149 | versioned_get '/api_version_with_version_param?version=1', 'v1', macro_options
|
150 | 150 | expect(last_response.body).to eql '1'
|
151 | 151 | end
|
| 152 | + |
| 153 | + context 'with catch-all' do |
| 154 | + let(:options) { macro_options } |
| 155 | + let(:v1) do |
| 156 | + klass = Class.new(Grape::API) |
| 157 | + klass.version 'v1', options |
| 158 | + klass.get 'version' do |
| 159 | + 'v1' |
| 160 | + end |
| 161 | + klass |
| 162 | + end |
| 163 | + let(:v2) do |
| 164 | + klass = Class.new(Grape::API) |
| 165 | + klass.version 'v2', options |
| 166 | + klass.get 'version' do |
| 167 | + 'v2' |
| 168 | + end |
| 169 | + klass |
| 170 | + end |
| 171 | + before do |
| 172 | + subject.format :txt |
| 173 | + |
| 174 | + subject.mount v1 |
| 175 | + subject.mount v2 |
| 176 | + |
| 177 | + subject.route :any, '*path' do |
| 178 | + params[:path] |
| 179 | + end |
| 180 | + end |
| 181 | + |
| 182 | + context 'v1' do |
| 183 | + it 'finds endpoint' do |
| 184 | + versioned_get '/version', 'v1', macro_options |
| 185 | + expect(last_response.status).to eq(200) |
| 186 | + expect(last_response.body).to eq('v1') |
| 187 | + end |
| 188 | + |
| 189 | + it 'finds catch all' do |
| 190 | + versioned_get '/whatever', 'v1', macro_options |
| 191 | + expect(last_response.status).to eq(200) |
| 192 | + expect(last_response.body).to end_with 'whatever' |
| 193 | + end |
| 194 | + end |
| 195 | + |
| 196 | + context 'v2' do |
| 197 | + it 'finds endpoint' do |
| 198 | + versioned_get '/version', 'v2', macro_options |
| 199 | + expect(last_response.status).to eq(200) |
| 200 | + expect(last_response.body).to eq('v2') |
| 201 | + end |
| 202 | + |
| 203 | + it 'finds catch all' do |
| 204 | + versioned_get '/whatever', 'v2', macro_options |
| 205 | + expect(last_response.status).to eq(200) |
| 206 | + expect(last_response.body).to end_with 'whatever' |
| 207 | + end |
| 208 | + end |
| 209 | + end |
152 | 210 | end
|
0 commit comments