Add type champs "Address" plug at the BAN

This commit is contained in:
Xavier J 2016-06-09 12:08:18 +02:00
parent 35a07aec87
commit 23ab25396f
18 changed files with 2804 additions and 13 deletions

View file

@ -0,0 +1,16 @@
require 'spec_helper'
describe Ban::SearchController, type: :controller do
describe '#GET' do
let (: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, request: request
end
it { expect(response.status).to eq 200 }
end
end

4
spec/factories/champ.rb Normal file
View file

@ -0,0 +1,4 @@
FactoryGirl.define do
factory :champ do
end
end

View file

@ -0,0 +1,44 @@
require 'spec_helper'
describe Carto::Bano::AddressRetriever do
describe '#list' do
let(:request) { 'Paris' }
let(:response) { File.open('spec/support/files/ban_address_search.json') }
let(:status) { 200 }
subject { described_class.new(request).list }
before do
stub_request(:get, "http://api-adresse.data.gouv.fr/search?&q=#{request}&limit=5")
.to_return(status: status, body: response, headers: {})
end
context 'when address return a list of address' do
it { expect(subject.size).to eq 5 }
it { is_expected.to be_an_instance_of Array }
end
context 'when address return an empty list' do
let(:response) { File.open('spec/support/files/ban_address_search_no_result.json') }
it { expect(subject.size).to eq 0 }
it { is_expected.to be_an_instance_of Array }
end
context 'when BAN is unavailable' do
let(:status) { 503 }
let(:response) { '' }
it { expect(subject.size).to eq 0 }
it { is_expected.to be_an_instance_of Array }
end
context 'when request is empty' do
let(:response) { 'Missing query' }
let(:request) { '' }
it { expect(subject.size).to eq 0 }
it { is_expected.to be_an_instance_of Array }
end
end
end

View file

@ -15,4 +15,26 @@ describe Champ do
it { is_expected.to delegate_method(:type_champ).to(:type_de_champ) }
it { is_expected.to delegate_method(:order_place).to(:type_de_champ) }
end
describe 'data_provide' do
let(:champ) { create :champ }
subject { champ.data_provide }
context 'when type_champ is datetime' do
before do
champ.type_de_champ = create :type_de_champ, type_champ: 'datetime'
end
it { is_expected.to eq 'datepicker' }
end
context 'when type_champ is address' do
before do
champ.type_de_champ = create :type_de_champ, type_champ: 'address'
end
it { is_expected.to eq 'typeahead' }
end
end
end

View file

@ -0,0 +1,117 @@
{
"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": [
4.366801,
44.425528
]
},
"properties": {
"citycode": "07330",
"postcode": "07150",
"name": "Paris",
"id": "07330_B095_bd3524",
"context": "07, Ard\u00e8che, Rh\u00f4ne-Alpes",
"score": 0.8291454545454544,
"label": "Paris 07150 Vallon-Pont-d'Arc",
"city": "Vallon-Pont-d'Arc",
"type": "locality"
},
"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"
}
]
}

View file

@ -0,0 +1,9 @@
{
"limit": 5,
"attribution": "BAN",
"version": "draft",
"licence": "ODbL 1.0",
"query": "Paris",
"type": "FeatureCollection",
"features": []
}