add gem api-pie

Error : stack level too deep
This commit is contained in:
Xavier J 2016-02-22 19:42:47 +01:00
parent b4007c2735
commit 2a6da54320
9 changed files with 113 additions and 34 deletions

View file

@ -79,6 +79,9 @@ gem 'bootstrap-wysihtml5-rails', '~> 0.3.3.8'
gem 'as_csv'
gem 'apipie-rails', '=0.3.1'
gem "maruku" # for Markdown support in apipie
group :test do
gem 'capybara'
gem 'factory_girl'

View file

@ -47,6 +47,8 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.3.8)
apipie-rails (0.3.1)
json
arel (6.0.2)
as_csv (2.0.2)
actionpack (>= 3.0)
@ -211,6 +213,7 @@ GEM
activesupport (>= 3.1.0)
rack (>= 1.4.0)
rest-client
maruku (0.7.2)
method_source (0.8.2)
mime-types (2.6.1)
mini_portile (0.6.2)
@ -453,6 +456,7 @@ PLATFORMS
DEPENDENCIES
active_model_serializers
apipie-rails (= 0.3.1)
as_csv
bootstrap-datepicker-rails
bootstrap-sass (~> 3.3.5)
@ -480,6 +484,7 @@ DEPENDENCIES
leaflet-rails
logstasher
mailjet
maruku
mina!
nyan-cat-formatter
openid_connect

View file

@ -1,5 +1,18 @@
class API::V1::DossiersController < APIController
api :GET, '/procedures/:procedure_id/dossiers/', 'Liste de tous les dossiers d\'une procédure'
param :procedure_id, Integer, desc: "L'identifiant de la procédure", required: true
error code: 401, desc: "Non authorisé"
error code: 404, desc: "Procédure inconnue"
description <<-EOS
Plop
EOS
meta champs: {
}
def index
procedure = current_administrateur.procedures.find(params[:procedure_id])
dossiers = procedure.dossiers.where.not(state: :draft).paginate(page: params[:page])
@ -8,6 +21,20 @@ class API::V1::DossiersController < APIController
render json: {}, status: 404
end
api :GET, '/procedures/:procedure_id/dossiers/:id', 'Informations du dossier d\'une procédure'
param :procedure_id, Integer, desc: "L'identifiant de la procédure", required: true
param :dossier_id, Integer, desc: "L'identifiant de la procédure", required: true
error code: 401, desc: "Non authorisé"
error code: 404, desc: "Procédure ou dossier inconnu"
description <<-EOS
Plop
EOS
meta champs: {
}
def show
procedure = current_administrateur.procedures.find(params[:procedure_id])
dossier = procedure.dossiers.find(params[:id])

View file

@ -1,4 +1,17 @@
class API::V1::ProceduresController < APIController
api :GET, '/procedures/:id', 'Informations concernant une procédure'
param :id, Integer, desc: "L'identifiant de la procédure", required: true
error code: 401, desc: "Non authorisé"
error code: 404, desc: "Procédure inconnue"
description <<-EOS
Plop
EOS
meta champs: {
}
def show
@procedure = current_administrateur.procedures.find(params[:id]).decorate

View file

@ -0,0 +1,18 @@
Apipie.configure do |config|
config.app_name = "API TPS"
config.api_base_url = "/api/v1"
config.doc_base_url = "/docs"
config.api_controllers_matcher = File.join(Rails.root, "app", "controllers","api","v1", "**","*.rb")
config.markup = Apipie::Markup::Markdown.new
config.default_version = '1.0'
config.validate = false
config.copyright = "© SGMAP"
config.namespaced_resources = true
config.show_all_examples = true
config.app_info = <<-EOS
Description
EOS
end

View file

@ -113,4 +113,6 @@ Rails.application.routes.draw do
end
end
end
apipie
end

View file

@ -28,7 +28,9 @@ describe API::V1::DossiersController do
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure, state: 'initiated') } }
let(:body) { JSON.parse(response.body, symbolize_names: true) }
it { expect(response.code).to eq('200') }
it 'return REST code 200', :show_in_doc do
expect(response.code).to eq('200')
end
it { expect(body).to have_key :pagination }
@ -117,7 +119,9 @@ describe API::V1::DossiersController do
let(:field_list) { [:id, :nom_projet, :created_at, :updated_at, :description, :archived, :entreprise, :etablissement] }
subject { body[:dossier] }
it { expect(response.code).to eq('200') }
it 'return REST code 200', :show_in_doc do
expect(response.code).to eq('200')
end
it { expect(subject[:id]).to eq(dossier.id) }
it { expect(subject[:nom_projet]).to eq(dossier.nom_projet) }
it { expect(subject[:created_at]).to eq('2008-09-01T08:05:00.000Z') }
@ -128,24 +132,24 @@ describe API::V1::DossiersController do
describe 'entreprise' do
let(:field_list) { [
:siren,
:capital_social,
:numero_tva_intracommunautaire,
:forme_juridique,
:forme_juridique_code,
:nom_commercial,
:raison_sociale,
:siret_siege_social,
:code_effectif_entreprise,
:date_creation,
:nom,
:prenom] }
subject { super()[:entreprise]}
:siren,
:capital_social,
:numero_tva_intracommunautaire,
:forme_juridique,
:forme_juridique_code,
:nom_commercial,
:raison_sociale,
:siret_siege_social,
:code_effectif_entreprise,
:date_creation,
:nom,
:prenom] }
subject { super()[:entreprise] }
it { expect(subject[:siren]).to eq('440117620')}
it { expect(subject[:capital_social]).to eq(537_100_000)}
it { expect(subject[:numero_tva_intracommunautaire]).to eq('FR27440117620')}
it { expect(subject[:forme_juridique]).to eq('SA à conseil d\'administration (s.a.i.)')}
it { expect(subject[:siren]).to eq('440117620') }
it { expect(subject[:capital_social]).to eq(537_100_000) }
it { expect(subject[:numero_tva_intracommunautaire]).to eq('FR27440117620') }
it { expect(subject[:forme_juridique]).to eq('SA à conseil d\'administration (s.a.i.)') }
it { expect(subject[:forme_juridique_code]).to eq('5599') }
it { expect(subject[:nom_commercial]).to eq('GRTGAZ') }
it { expect(subject[:raison_sociale]).to eq('GRTGAZ') }
@ -157,20 +161,20 @@ describe API::V1::DossiersController do
describe 'etablissement' do
let(:field_list) { [
:siret,
:siege_social,
:naf,
:libelle_naf,
:adresse,
:numero_voie,
:type_voie,
:nom_voie,
:complement_adresse,
:code_postal,
:localite,
:code_insee_localite
:siret,
:siege_social,
:naf,
:libelle_naf,
:adresse,
:numero_voie,
:type_voie,
:nom_voie,
:complement_adresse,
:code_postal,
:localite,
:code_insee_localite
] }
subject { super()[:etablissement]}
subject { super()[:etablissement] }
it { expect(subject[:siret]).to eq('44011762001530') }
it { expect(subject[:siege_social]).to eq(true) }

View file

@ -3,6 +3,7 @@ require 'spec_helper'
describe API::V1::ProceduresController do
let(:admin) { create(:administrateur) }
it { expect(described_class).to be < APIController }
describe 'GET show' do
context 'when procedure does not exist' do
subject { get :show, id: 999_999_999, token: admin.api_token }
@ -16,9 +17,13 @@ describe API::V1::ProceduresController do
context 'when procedure exist' do
let(:procedure) { create(:procedure, administrateur: admin) }
subject { get :show, id: procedure, token: admin.api_token }
it { expect(subject.status).to eq(200) }
it 'return REST code 200', :show_in_doc do
expect(subject.status).to eq(200)
end
describe 'body' do
let(:module_api_carto) { create(:module_api_carto, use_api_carto: true, quartiers_prioritaires: true, cadastre: true)}
let(:module_api_carto) { create(:module_api_carto, use_api_carto: true, quartiers_prioritaires: true, cadastre: true) }
let(:procedure) { create(:procedure, :with_type_de_champ, :with_two_type_de_piece_justificative, module_api_carto: module_api_carto, administrateur: admin) }
let(:response) { get :show, id: procedure.id, token: admin.api_token }
subject { JSON.parse(response.body, symbolize_names: true)[:procedure] }

View file

@ -80,6 +80,8 @@ RSpec.configure do |config|
config.infer_base_class_for_anonymous_controllers = false
config.filter_run :show_in_doc => true if ENV['APIPIE_RECORD']
config.order = 'random'
config.include Devise::TestHelpers, type: :view