Add real tests for search controller

This commit is contained in:
Xavier J 2016-12-16 17:51:07 +01:00
parent 5b8f0304f9
commit 5ee455a36f
3 changed files with 121 additions and 6 deletions

View file

@ -2,16 +2,26 @@ require 'spec_helper'
describe Ban::SearchController, type: :controller do
describe '#GET get' do
let (:request) { '' }
subject { get :get, params: {request: request} }
before do
stub_request(:get, "http://api-adresse.data.gouv.fr/search?limit=5&q=").
to_return(:status => 200, :body => 'Missing query', :headers => {})
get :get, params: {request: request}
subject
end
it { expect(response.status).to eq 200 }
context 'when request return result', vcr: {cassette_name: 'bano_search_paris'} do
let (:request) { 'Paris' }
it { expect(response.status).to eq 200 }
it { expect(response.body).to eq '[{"label":"Paris"},{"label":"Paris 63120 Courpière"},{"label":"PARIS (Vaillac) 46240 Cœur de Causse"},{"label":"Paris 40500 Saint-Sever"},{"label":"Paris Buton 37140 Bourgueil"}]' }
end
context 'when request return nothing', vcr: {cassette_name: 'bano_search_nothing'} do
let (:request) { 'je recherche pas grand chose' }
it { expect(response.status).to eq 200 }
it { expect(response.body).to eq "[]" }
end
end
describe '#GET get_address_point' do

View file

@ -0,0 +1,42 @@
---
http_interactions:
- request:
method: get
uri: http://api-adresse.data.gouv.fr/search?limit=5&q=je%20recherche%20pas%20grand%20chose
body:
encoding: US-ASCII
string: ''
headers:
Accept:
- "*/*"
Accept-Encoding:
- gzip, deflate
User-Agent:
- rest-client/2.0.0 (darwin15.6.0 x86_64) ruby/2.3.1p112
response:
status:
code: 200
message: OK
headers:
Server:
- nginx/1.11.3
Date:
- Fri, 16 Dec 2016 16:45:53 GMT
Content-Type:
- application/json; charset=utf-8
Content-Length:
- '163'
Connection:
- keep-alive
Access-Control-Allow-Origin:
- "*"
Access-Control-Allow-Headers:
- X-Requested-With
body:
encoding: UTF-8
string: '{"limit": 5, "attribution": "BAN", "version": "draft", "licence": "ODbL
1.0", "query": "je recherche pas grand chose", "type": "FeatureCollection",
"features": []}'
http_version:
recorded_at: Fri, 16 Dec 2016 16:45:53 GMT
recorded_with: VCR 3.0.3

View file

@ -0,0 +1,63 @@
---
http_interactions:
- request:
method: get
uri: http://api-adresse.data.gouv.fr/search?limit=5&q=Paris
body:
encoding: US-ASCII
string: ''
headers:
Accept:
- "*/*"
Accept-Encoding:
- gzip, deflate
User-Agent:
- rest-client/2.0.0 (darwin15.6.0 x86_64) ruby/2.3.1p112
response:
status:
code: 200
message: OK
headers:
Server:
- nginx/1.11.3
Date:
- Fri, 16 Dec 2016 16:43:34 GMT
Content-Type:
- application/json; charset=utf-8
Content-Length:
- '1887'
Connection:
- keep-alive
Access-Control-Allow-Origin:
- "*"
Access-Control-Allow-Headers:
- X-Requested-With
body:
encoding: UTF-8
string: '{"limit": 5, "attribution": "BAN", "version": "draft", "licence": "ODbL
1.0", "query": "Paris", "type": "FeatureCollection", "features": [{"geometry":
{"type": "Point", "coordinates": [2.3469, 48.8589]}, "properties": {"adm_weight":
"6", "citycode": "75056", "name": "Paris", "city": "Paris", "postcode": "75000",
"context": "75, \u00cele-de-France", "score": 1.0, "label": "Paris", "id":
"75056", "type": "city", "population": "2244"}, "type": "Feature"}, {"geometry":
{"type": "Point", "coordinates": [3.564293, 45.766413]}, "properties": {"citycode":
"63125", "postcode": "63120", "name": "Paris", "city": "Courpi\u00e8re", "context":
"63, Puy-de-D\u00f4me, Auvergne", "score": 0.8255363636363636, "label": "Paris
63120 Courpi\u00e8re", "id": "63125_B221_03549b", "type": "locality"}, "type":
"Feature"}, {"geometry": {"type": "Point", "coordinates": [1.550208, 44.673592]},
"properties": {"citycode": "46138", "postcode": "46240", "name": "PARIS (Vaillac)",
"city": "C\u0153ur de Causse", "context": "46, Lot, Midi-Pyr\u00e9n\u00e9es",
"score": 0.824090909090909, "label": "PARIS (Vaillac) 46240 C\u0153ur de Causse",
"id": "46138_XXXX_6ee4ec", "type": "street"}, "type": "Feature"}, {"geometry":
{"type": "Point", "coordinates": [-0.526884, 43.762253]}, "properties": {"citycode":
"40282", "postcode": "40500", "name": "Paris", "city": "Saint-Sever", "context":
"40, Landes, Aquitaine", "score": 0.8236181818181818, "label": "Paris 40500
Saint-Sever", "id": "40282_B237_2364e3", "type": "locality"}, "type": "Feature"},
{"geometry": {"type": "Point", "coordinates": [0.157613, 47.336685]}, "properties":
{"citycode": "37031", "postcode": "37140", "name": "Paris Buton", "city":
"Bourgueil", "context": "37, Indre-et-Loire, Centre Val-de-Loire", "score":
0.8235454545454545, "label": "Paris Buton 37140 Bourgueil", "id": "37031_X027_0a5e7a",
"type": "locality"}, "type": "Feature"}]}'
http_version:
recorded_at: Fri, 16 Dec 2016 16:43:34 GMT
recorded_with: VCR 3.0.3