From 074c6fe72bf6c12db4ccbd2b478b1bcec46b63c7 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 4 Apr 2017 11:42:00 +0200 Subject: [PATCH 1/8] Use scenic in all environments --- Gemfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index e6d77a9ab..60952ee60 100644 --- a/Gemfile +++ b/Gemfile @@ -93,6 +93,8 @@ gem 'simple_form' gem 'newrelic_rpm' +gem 'scenic' + # Sidekiq gem 'sidekiq' gem 'sidekiq-cron', '~> 0.4.4' @@ -145,6 +147,3 @@ group :production, :staging do gem 'sentry-raven' end -group :production, :staging, :development do - gem 'scenic' -end From 3ca914aba80741c7d4418da7529f352bb74c7a61 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 4 Apr 2017 11:42:42 +0200 Subject: [PATCH 2/8] Delete some environment-based conditions We should always try to be the closest to the production environment --- app/models/notification.rb | 1 - ...0160127170437_change_date_creation_type_to_entreprise.rb | 6 +----- db/migrate/20161025150900_create_searches.rb | 4 ++-- db/migrate/20161102154835_update_searches_to_version_2.rb | 4 ++-- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index e538f0a25..4ff810f37 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -1,6 +1,5 @@ class Notification < ActiveRecord::Base belongs_to :dossier - serialize :liste if Rails.env.test? # after_save :broadcast_notification diff --git a/db/migrate/20160127170437_change_date_creation_type_to_entreprise.rb b/db/migrate/20160127170437_change_date_creation_type_to_entreprise.rb index 5168938c7..6451dc0d1 100644 --- a/db/migrate/20160127170437_change_date_creation_type_to_entreprise.rb +++ b/db/migrate/20160127170437_change_date_creation_type_to_entreprise.rb @@ -1,10 +1,6 @@ class ChangeDateCreationTypeToEntreprise < ActiveRecord::Migration def up - if Rails.env.test? - change_column :entreprises, :date_creation, "timestamp" - else - change_column :entreprises, :date_creation, "timestamp USING to_timestamp(date_creation) at time zone 'UTC-2'" - end + change_column :entreprises, :date_creation, "timestamp USING to_timestamp(date_creation) at time zone 'UTC-2'" end def down diff --git a/db/migrate/20161025150900_create_searches.rb b/db/migrate/20161025150900_create_searches.rb index 5252c6006..3b2ee975f 100644 --- a/db/migrate/20161025150900_create_searches.rb +++ b/db/migrate/20161025150900_create_searches.rb @@ -9,7 +9,7 @@ class CreateSearches < ActiveRecord::Migration add_index :individuals, :dossier_id add_index :pieces_justificatives, :dossier_id add_index :rna_informations, :entreprise_id - create_view :searches unless Rails.env.test? #, materialized: true + create_view :searches end def down @@ -22,6 +22,6 @@ class CreateSearches < ActiveRecord::Migration remove_index :individuals, :dossier_id remove_index :pieces_justificatives, :dossier_id remove_index :rna_informations, :entreprise_id - drop_view :searches unless Rails.env.test? #, materialized: true + drop_view :searches end end diff --git a/db/migrate/20161102154835_update_searches_to_version_2.rb b/db/migrate/20161102154835_update_searches_to_version_2.rb index b749a08ea..55223b4cf 100644 --- a/db/migrate/20161102154835_update_searches_to_version_2.rb +++ b/db/migrate/20161102154835_update_searches_to_version_2.rb @@ -1,9 +1,9 @@ class UpdateSearchesToVersion2 < ActiveRecord::Migration def up - replace_view :searches, version: 2 unless Rails.env.test? + replace_view :searches, version: 2 end def down - replace_view :searches, version: 1 unless Rails.env.test? + replace_view :searches, version: 1 end end From aef804a988ee892c89498b2a776bf0a34c6ffa6d Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 4 Apr 2017 11:43:07 +0200 Subject: [PATCH 3/8] Use a postgresql database for tests Try to be the closest to the production environment --- README.md | 1 + config/database.yml | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5c17747dc..e33184bf1 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Les informations nécessaire à l'initialisation de la base doivent être pré-c su - postgres psql > create user tps with password 'lol' superuser; + > create user tps_test with password 'tps_test' superuser; > \q diff --git a/config/database.yml b/config/database.yml index 76a34a338..9f8cb0b14 100644 --- a/config/database.yml +++ b/config/database.yml @@ -9,7 +9,10 @@ development: test: - adapter: sqlite3 + adapter: postgresql + encoding: unicode + database: tps_test + host: localhost pool: 5 - timeout: 5000 - database: db/test.sqlite3 + username: tps_test + password: tps_test From 30d1d872776e496c507b122e1d5e2fe190fd2c16 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 4 Apr 2017 12:09:25 +0200 Subject: [PATCH 4/8] Fix a test due to the move to Postgresql MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit double precision’s length is 15 digits --- spec/controllers/users/carte_controller_shared_example.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/users/carte_controller_shared_example.rb b/spec/controllers/users/carte_controller_shared_example.rb index 6e5fe11a1..55d63d266 100644 --- a/spec/controllers/users/carte_controller_shared_example.rb +++ b/spec/controllers/users/carte_controller_shared_example.rb @@ -164,7 +164,7 @@ shared_examples 'carte_controller_spec' do subject { Cadastre.last } it { expect(subject.surface_intersection).to eq('0.0006') } - it { expect(subject.surface_parcelle).to eq(11252.692583090324) } + it { expect(subject.surface_parcelle).to eq(11252.6925830903) } it { expect(subject.numero).to eq('0013') } it { expect(subject.feuille).to eq(1) } it { expect(subject.section).to eq('CD') } From 0e13e4bdfd817585ada22abaae398bf6346413a8 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 4 Apr 2017 11:43:49 +0200 Subject: [PATCH 5/8] Use transaction instead of truncation DatabaseCleaner strategy It is the recommended strategy for ActiveRecod --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f3b8d6030..d28fae75d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -55,7 +55,7 @@ VCR.configure do |c| c.configure_rspec_metadata! end -DatabaseCleaner.strategy = :truncation +DatabaseCleaner.strategy = :transaction SIADETOKEN = :valid_token unless defined? SIADETOKEN BROWSER.value = Browser.new('Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)') From fa9bf2d398603b4071dc384e7e0553a17491ea1d Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 4 Apr 2017 12:09:51 +0200 Subject: [PATCH 6/8] Fix a test now that we use transaction instead of truncation --- spec/models/concern/mail_template_concern_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/concern/mail_template_concern_spec.rb b/spec/models/concern/mail_template_concern_spec.rb index f177a360a..b82d78117 100644 --- a/spec/models/concern/mail_template_concern_spec.rb +++ b/spec/models/concern/mail_template_concern_spec.rb @@ -8,8 +8,8 @@ describe MailTemplateConcern do it 'works' do initiated_mail.object = '[TPS] --numero_dossier-- --libelle_procedure-- --lien_dossier--' expected = - "[TPS] 1 Demande de subvention " + - "http://localhost:3000/users/dossiers/1/recapitulatif" + "[TPS] #{dossier.id} Demande de subvention " + + "http://localhost:3000/users/dossiers/#{dossier.id}/recapitulatif" expect(initiated_mail.object_for_dossier(dossier)).to eq(expected) end From 8015710db27fda83ff26a90dd309ddedbc019bd2 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 4 Apr 2017 11:52:52 +0200 Subject: [PATCH 7/8] Add config/database.yml.ci --- config/database.yml.ci | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 config/database.yml.ci diff --git a/config/database.yml.ci b/config/database.yml.ci new file mode 100644 index 000000000..3d17efadf --- /dev/null +++ b/config/database.yml.ci @@ -0,0 +1,6 @@ +test: + adapter: postgresql + database: app_test + pool: 5 + username: + password: From 8a424059f9889a1bffbc049f5455c6352329afa2 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 4 Apr 2017 11:53:16 +0200 Subject: [PATCH 8/8] Update circle.yml so that it works properly with postgresql --- circle.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index d16255161..8fbdcce89 100644 --- a/circle.yml +++ b/circle.yml @@ -1,6 +1,7 @@ database: override: - - bundle exec rake db:drop db:create db:migrate RAILS_ENV=test + - cp config/database.yml.ci config/database.yml + - bundle exec rake db:create db:schema:load db:migrate RAILS_ENV=test deployment: staging: