Merge branch 'develop' into staging

This commit is contained in:
Mathieu Magnin 2017-04-13 09:07:01 +02:00
commit 364a97b127
10 changed files with 206 additions and 173 deletions

63
.circleci/config.yml Normal file
View file

@ -0,0 +1,63 @@
version: 2
jobs:
build:
docker:
- image: ruby:2.3.1
- image: postgres:9.4.1
environment:
POSTGRES_USER: tps_test
POSTGRES_PASSWORD: tps_test
POSTGRES_DB: tps_test
working_directory: /tps
steps:
- checkout
- run:
name: Install System Dependencies
command: apt-get update -qq && apt-get install -y build-essential nodejs
- restore_cache:
key: bundle-install-v3-{{ checksum "Gemfile.lock" }}
- run:
name: Install Ruby Dependencies
command: bundle install
- save_cache:
key: bundle-install-v3-{{ checksum "Gemfile.lock" }}
paths:
- /usr/local/bundle
- restore_cache:
key: phantomjs-2-1-1
- run:
name: Install PhantomJS Dependencies
command: |
[ -f /usr/local/bin/phantomjs ] || apt-get update
[ -f /usr/local/bin/phantomjs ] || apt-get install -y fontconfig wget
- run:
name: Install PhantomJS
command: |
[ -f /usr/local/bin/phantomjs ] || wget -O /tmp/phantomjs.tar.bz2 https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
[ -f /usr/local/bin/phantomjs ] || tar -xjf /tmp/phantomjs.tar.bz2 -C /tmp
[ -f /usr/local/bin/phantomjs ] || mv /tmp/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs
- save_cache:
key: phantomjs-2-1-1
paths:
- /usr/local/bin/phantomjs
- run:
environment:
DATABASE_URL: "postgres://tps_test@localhost:5432/tps_test"
name: Create DB
command: bundle exec rake db:create db:schema:load db:migrate RAILS_ENV=test
- run:
environment:
DATABASE_URL: "postgres://tps_test@localhost:5432/tps_test"
name: Run Tests, Splitted by Timings
command: |
TESTFILES=$(circleci tests glob "spec/**/*.rb"| xargs -n 1 echo | grep -v "spec/factories/" | tr " " "\n" | circleci tests split --split-by=timings)
bundle exec rspec --color --require spec_helper -- ${TESTFILES}
- run:
name: Run haml-lint
command: bundle exec haml-lint app/views/
- deploy:
command: |
if [ "${CIRCLE_BRANCH}" == "staging" ]; then
bundle exec rake deploy_ha
fi

View file

@ -134,9 +134,7 @@ class Procedure < ActiveRecord::Base
exportable_dossiers = dossiers.downloadable
headers = exportable_dossiers.any? ? exportable_dossiers.first.export_headers : []
data = exportable_dossiers.map do |dossier|
dossier.full_data_strings_array
end
data = exportable_dossiers.any? ? exportable_dossiers.map { |d| d.full_data_strings_array } : [[]]
{
headers: headers,

View file

@ -1,15 +0,0 @@
database:
override:
- cp config/database.yml.ci config/database.yml
- bundle exec rake db:create db:schema:load db:migrate RAILS_ENV=test
test:
override:
- bundle exec rspec
- bundle exec haml-lint app/views/
deployment:
staging:
branch: staging
commands:
- bundle exec rake deploy_ha

View file

@ -1,6 +0,0 @@
test:
adapter: postgresql
database: app_test
pool: 5
username:
password:

View file

@ -24,7 +24,7 @@ describe API::V1::DossiersController do
context 'when procedure is found and belongs to admin' do
let(:procedure_id) { procedure.id }
let(:date_creation) { Time.local(2008, 9, 1, 10, 5, 0) }
let(:date_creation) { Time.utc(2008, 9, 1, 10, 5, 0) }
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure, state: 'initiated') } }
let(:body) { JSON.parse(retour.body, symbolize_names: true) }
@ -52,9 +52,7 @@ describe API::V1::DossiersController do
describe 'dossier' do
subject { super().first }
it { expect(subject[:id]).to eq(dossier.id) }
if ENV['PG'] == 'true'
it { expect(subject[:updated_at]).to eq("2008-09-01T08:05:00.000Z") }
end
it { expect(subject[:updated_at]).to eq("2008-09-01T10:05:00.000Z") }
it { expect(subject.keys.size).to eq(2) }
end
end
@ -113,7 +111,7 @@ describe API::V1::DossiersController do
context 'when dossier exists and belongs to procedure' do
let(:procedure_id) { procedure.id }
let(:date_creation) { Time.local(2008, 9, 1, 10, 5, 0) }
let(:date_creation) { Time.utc(2008, 9, 1, 10, 5, 0) }
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure) } }
let(:dossier_id) { dossier.id }
let(:body) { JSON.parse(retour.body, symbolize_names: true) }
@ -126,10 +124,8 @@ describe API::V1::DossiersController do
it { expect(subject[:id]).to eq(dossier.id) }
it { expect(subject[:state]).to eq(dossier.state) }
if ENV['PG'] == 'true'
it { expect(subject[:created_at]).to eq('2008-09-01T08:05:00.000Z') }
it { expect(subject[:updated_at]).to eq('2008-09-01T08:05:00.000Z') }
end
it { expect(subject[:created_at]).to eq('2008-09-01T10:05:00.000Z') }
it { expect(subject[:updated_at]).to eq('2008-09-01T10:05:00.000Z') }
it { expect(subject[:archived]).to eq(dossier.archived) }
it { expect(subject[:mandataire_social]).to eq(dossier.mandataire_social) }

View file

@ -169,41 +169,39 @@ describe Backoffice::DossiersController, type: :controller do
end
if ENV['PG'] == 'true'
describe 'POST #search' do
describe 'by id' do
context 'when I am logged as a gestionnaire' do
before do
sign_in gestionnaire
describe 'POST #search' do
describe 'by id' do
context 'when I am logged as a gestionnaire' do
before do
sign_in gestionnaire
end
context 'when I own the dossier' do
before :each do
post :search, params: { q: dossier_id }
end
context 'when I own the dossier' do
before :each do
post :search, params: { q: dossier_id }
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'returns the expected dossier' do
expect(assigns(:dossiers).count).to eq(1)
expect(assigns(:dossiers).first.id).to eq(dossier_id)
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
context 'when I do not own the dossier' do
before :each do
post :search, params: { q: dossier2_id }
end
it 'returns the expected dossier' do
expect(assigns(:dossiers).count).to eq(1)
expect(assigns(:dossiers).first.id).to eq(dossier_id)
end
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
context 'when I do not own the dossier' do
before :each do
post :search, params: { q: dossier2_id }
end
it 'returns nothing' do
expect(assigns(:dossiers).count).to eq(0)
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'returns nothing' do
expect(assigns(:dossiers).count).to eq(0)
end
end
end

View file

@ -1,7 +1,7 @@
require 'spec_helper'
describe CommentaireDecorator do
let(:commentaire) { Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 0)) {create :commentaire} }
let(:commentaire) { Timecop.freeze(Time.utc(2008, 9, 1, 10, 5, 0)) {create :commentaire} }
let(:decorator) { commentaire.decorate }
describe 'created_at_fr' do

View file

@ -1,52 +1,50 @@
require 'spec_helper'
if ENV['PG'] == 'true'
feature 'search file on gestionnaire backoffice' do
let(:administrateur) { create(:administrateur) }
let(:gestionnaire) { create(:gestionnaire, administrateurs: [administrateur]) }
feature 'search file on gestionnaire backoffice' do
let(:administrateur) { create(:administrateur) }
let(:gestionnaire) { create(:gestionnaire, administrateurs: [administrateur]) }
before do
login_as gestionnaire, scope: :gestionnaire
end
before do
login_as gestionnaire, scope: :gestionnaire
end
context 'when gestionnaire is logged in' do
context 'when he click on search button' do
let(:terms) { '' }
let!(:procedure) { create(:procedure, administrateur: administrateur) }
context 'when gestionnaire is logged in' do
context 'when he click on search button' do
let(:terms) { '' }
let!(:procedure) { create(:procedure, administrateur: administrateur) }
before do
create :assign_to, gestionnaire: gestionnaire, procedure: procedure
before do
create :assign_to, gestionnaire: gestionnaire, procedure: procedure
visit backoffice_dossiers_url
page.find_by_id(:q).set terms
page.find_by_id(:search_button).click
visit backoffice_dossiers_url
page.find_by_id(:q).set terms
page.find_by_id(:search_button).click
end
it { expect(page).to have_css('#backoffice_search') }
context 'when terms input is empty' do
it { expect(page).to have_content('Aucun dossier') }
end
context 'when terms input is informed' do
let(:terms) { 'test' }
it 'terms stay in input after search' do
expect(page.find_by_id('q').value).to eq(terms)
end
it { expect(page).to have_css('#backoffice_search') }
context 'when terms input is empty' do
context 'when terms input does not return result' do
it { expect(page).to have_content('Aucun dossier') }
end
context 'when terms input is informed' do
let(:terms) { 'test' }
context 'when terms input does return result' do
let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: 'initiated') }
let!(:dossier_2) { create(:dossier, procedure: procedure, state: 'initiated') }
it 'terms stay in input after search' do
expect(page.find_by_id('q').value).to eq(terms)
end
let(:terms) { dossier.entreprise.raison_sociale }
context 'when terms input does not return result' do
it { expect(page).to have_content('Aucun dossier') }
end
context 'when terms input does return result' do
let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: 'initiated') }
let!(:dossier_2) { create(:dossier, procedure: procedure, state: 'initiated') }
let(:terms) { dossier.entreprise.raison_sociale }
it { expect(page).to have_content(dossier.entreprise.raison_sociale) }
end
it { expect(page).to have_content(dossier.entreprise.raison_sociale) }
end
end
end

View file

@ -261,11 +261,15 @@ describe Procedure do
let(:procedure) { create :procedure }
subject { procedure.generate_export }
context 'when there are no dossiers' do
it { expect(subject[:data]).to eq([]) }
shared_examples "export is empty" do
it { expect(subject[:data]).to eq([[]]) }
it { expect(subject[:headers]).to eq([]) }
end
context 'when there are no dossiers' do
it_behaves_like "export is empty"
end
context 'when there are some dossiers' do
let!(:dossier){ create(:dossier, procedure: procedure, state: 'initiated') }
let!(:dossier2){ create(:dossier, procedure: procedure, state: 'closed') }
@ -277,8 +281,7 @@ describe Procedure do
context 'when there is a draft dossier' do
let!(:dossier_not_exportable){ create(:dossier, procedure: procedure, state: 'draft') }
it { expect(subject[:data]).to eq([]) }
it { expect(subject[:headers]).to eq([]) }
it_behaves_like "export is empty"
end
end
end

View file

@ -1,81 +1,79 @@
require 'spec_helper'
if ENV['PG'] == 'true'
describe Search do
describe '.results' do
subject { liste_dossiers }
describe Search do
describe '.results' do
subject { liste_dossiers }
let(:liste_dossiers) do
described_class.new(gestionnaire: gestionnaire_1, query: terms).results
let(:liste_dossiers) do
described_class.new(gestionnaire: gestionnaire_1, query: terms).results
end
let(:administrateur_1) { create(:administrateur) }
let(:administrateur_2) { create(:administrateur) }
let(:gestionnaire_1) { create(:gestionnaire, administrateurs: [administrateur_1]) }
let(:gestionnaire_2) { create(:gestionnaire, administrateurs: [administrateur_2]) }
before do
create :assign_to, gestionnaire: gestionnaire_1, procedure: procedure_1
create :assign_to, gestionnaire: gestionnaire_2, procedure: procedure_2
end
let(:procedure_1) { create(:procedure, administrateur: administrateur_1) }
let(:procedure_2) { create(:procedure, administrateur: administrateur_2) }
let!(:dossier_0) { create(:dossier, state: 'draft', procedure: procedure_1, user: create(:user, email: 'brouillon@clap.fr')) }
let!(:dossier_1) { create(:dossier, state: 'initiated', procedure: procedure_1, user: create(:user, email: 'contact@test.com')) }
let!(:dossier_2) { create(:dossier, state: 'initiated', procedure: procedure_1, user: create(:user, email: 'plop@gmail.com')) }
let!(:dossier_3) { create(:dossier, state: 'initiated', procedure: procedure_2, user: create(:user, email: 'peace@clap.fr')) }
let!(:dossier_archived) { create(:dossier, state: 'initiated', procedure: procedure_1, archived: true, user: create(:user, email: 'brouillonArchived@clap.fr')) }
let!(:etablissement_1) { create(:etablissement, entreprise: create(:entreprise, raison_sociale: 'OCTO Academy', dossier: dossier_1), dossier: dossier_1, siret: '41636169600051') }
let!(:etablissement_2) { create(:etablissement, entreprise: create(:entreprise, raison_sociale: 'Plop octo', dossier: dossier_2), dossier: dossier_2, siret: '41816602300012') }
let!(:etablissement_3) { create(:etablissement, entreprise: create(:entreprise, raison_sociale: 'OCTO Technology', dossier: dossier_3), dossier: dossier_3, siret: '41816609600051') }
describe 'search is empty' do
let(:terms) { '' }
it { expect(subject.size).to eq(0) }
end
describe 'search draft file' do
let(:terms) { 'brouillon' }
it { expect(subject.size).to eq(0) }
end
describe 'search on contact email' do
let(:terms) { 'clap' }
it { expect(subject.size).to eq(0) }
end
describe 'search on SIRET' do
context 'when is part of SIRET' do
let(:terms) { '4181' }
it { expect(subject.size).to eq(1) }
end
let(:administrateur_1) { create(:administrateur) }
let(:administrateur_2) { create(:administrateur) }
let(:gestionnaire_1) { create(:gestionnaire, administrateurs: [administrateur_1]) }
let(:gestionnaire_2) { create(:gestionnaire, administrateurs: [administrateur_2]) }
before do
create :assign_to, gestionnaire: gestionnaire_1, procedure: procedure_1
create :assign_to, gestionnaire: gestionnaire_2, procedure: procedure_2
end
let(:procedure_1) { create(:procedure, administrateur: administrateur_1) }
let(:procedure_2) { create(:procedure, administrateur: administrateur_2) }
let!(:dossier_0) { create(:dossier, state: 'draft', procedure: procedure_1, user: create(:user, email: 'brouillon@clap.fr')) }
let!(:dossier_1) { create(:dossier, state: 'initiated', procedure: procedure_1, user: create(:user, email: 'contact@test.com')) }
let!(:dossier_2) { create(:dossier, state: 'initiated', procedure: procedure_1, user: create(:user, email: 'plop@gmail.com')) }
let!(:dossier_3) { create(:dossier, state: 'initiated', procedure: procedure_2, user: create(:user, email: 'peace@clap.fr')) }
let!(:dossier_archived) { create(:dossier, state: 'initiated', procedure: procedure_1, archived: true, user: create(:user, email: 'brouillonArchived@clap.fr')) }
let!(:etablissement_1) { create(:etablissement, entreprise: create(:entreprise, raison_sociale: 'OCTO Academy', dossier: dossier_1), dossier: dossier_1, siret: '41636169600051') }
let!(:etablissement_2) { create(:etablissement, entreprise: create(:entreprise, raison_sociale: 'Plop octo', dossier: dossier_2), dossier: dossier_2, siret: '41816602300012') }
let!(:etablissement_3) { create(:etablissement, entreprise: create(:entreprise, raison_sociale: 'OCTO Technology', dossier: dossier_3), dossier: dossier_3, siret: '41816609600051') }
describe 'search is empty' do
let(:terms) { '' }
it { expect(subject.size).to eq(0) }
end
describe 'search draft file' do
let(:terms) { 'brouillon' }
it { expect(subject.size).to eq(0) }
end
describe 'search on contact email' do
let(:terms) { 'clap' }
it { expect(subject.size).to eq(0) }
end
describe 'search on SIRET' do
context 'when is part of SIRET' do
let(:terms) { '4181' }
it { expect(subject.size).to eq(1) }
end
context 'when is a complet SIRET' do
let(:terms) { '41816602300012' }
it { expect(subject.size).to eq(1) }
end
end
describe 'search on raison social' do
let(:terms) { 'OCTO' }
it { expect(subject.size).to eq(2) }
end
describe 'search on multiple fields' do
let(:terms) { 'octo plop' }
context 'when is a complet SIRET' do
let(:terms) { '41816602300012' }
it { expect(subject.size).to eq(1) }
end
end
describe 'search on raison social' do
let(:terms) { 'OCTO' }
it { expect(subject.size).to eq(2) }
end
describe 'search on multiple fields' do
let(:terms) { 'octo plop' }
it { expect(subject.size).to eq(1) }
end
end
end