From 8d4656cf89e753fec6a39d01d7cb1d4e1b93672d Mon Sep 17 00:00:00 2001 From: Xavier J Date: Tue, 3 Jan 2017 12:53:27 +0100 Subject: [PATCH] Fix features dossiers edition spec --- .../users/description_controller.rb | 2 +- spec/factories/dossier.rb | 7 ++++ spec/factories/individual.rb | 7 ++++ spec/features/users/dossier_edition_spec.rb | 39 ++++++++++--------- 4 files changed, 35 insertions(+), 20 deletions(-) create mode 100644 spec/factories/individual.rb diff --git a/app/controllers/users/description_controller.rb b/app/controllers/users/description_controller.rb index 215973c72..4dcd7f287 100644 --- a/app/controllers/users/description_controller.rb +++ b/app/controllers/users/description_controller.rb @@ -122,7 +122,7 @@ class Users::DescriptionController < UsersController private def check_autorisation_donnees - @dossier ||= current_user_dossier + @dossier = current_user_dossier redirect_to url_for(users_dossier_path(@dossier.id)) if @dossier.autorisation_donnees.nil? || !@dossier.autorisation_donnees end diff --git a/spec/factories/dossier.rb b/spec/factories/dossier.rb index 2a98f2a0b..aa619d795 100644 --- a/spec/factories/dossier.rb +++ b/spec/factories/dossier.rb @@ -19,6 +19,13 @@ FactoryGirl.define do end end + trait :for_individual do + after(:build) do |dossier, _evaluator| + dossier.individual = create :individual + dossier.save + end + end + trait :with_two_quartier_prioritaires do after(:build) do |dossier, _evaluator| dossier.quartier_prioritaires << create(:quartier_prioritaire) diff --git a/spec/factories/individual.rb b/spec/factories/individual.rb new file mode 100644 index 000000000..c5924d57c --- /dev/null +++ b/spec/factories/individual.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :individual do + nom 'Julien' + prenom 'Xavier' + birthdate '20/01/1991' + end +end diff --git a/spec/features/users/dossier_edition_spec.rb b/spec/features/users/dossier_edition_spec.rb index aa7d3f1f3..327f35767 100644 --- a/spec/features/users/dossier_edition_spec.rb +++ b/spec/features/users/dossier_edition_spec.rb @@ -1,10 +1,10 @@ require 'spec_helper' -feature 'As a User I want to edit a dossier I own', js: true do +feature 'As a User I want to edit a dossier I own' do let(:user) { create(:user) } - let(:procedure_for_individual) { create(:procedure, :published, :for_individual, :with_api_carto, :with_type_de_champ, :with_two_type_de_piece_justificative) } - let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure_for_individual, user: user, state: 'initiated') } + let(:procedure_for_individual) { create(:procedure, :published, :for_individual, :with_type_de_champ, :with_two_type_de_piece_justificative) } + let!(:dossier) { create(:dossier, :with_entreprise, :for_individual, procedure: procedure_for_individual, user: user, autorisation_donnees: true, state: 'initiated') } before "Create dossier and visit root path" do login_as user, scope: :user @@ -15,30 +15,31 @@ feature 'As a User I want to edit a dossier I own', js: true do scenario 'After sign_in, I can see dossiers "à traiter" (default), and other indexes' do expect(page.find('#a_traiter')['class'] ).to eq('active procedure_list_element') - page.find_by_id('brouillon').trigger('click') - page.find_by_id('a_traiter').trigger('click') - page.find_by_id('valides').trigger('click') - page.find_by_id('en_instruction').trigger('click') - page.find_by_id('termine').trigger('click') - page.find_by_id('invite').trigger('click') + page.find_by_id('brouillon').click + page.find_by_id('a_traiter').click + page.find_by_id('valides').click + page.find_by_id('en_instruction').click + page.find_by_id('termine').click + page.find_by_id('invite').click end - scenario 'Getting a dossier, I want to create a new message on' do - page.find_by_id('tr_dossier_' + Dossier.last.id.to_s).trigger('click') + scenario 'Getting a dossier, I want to create a new message on', js: true do + page.find_by_id('tr_dossier_' + Dossier.last.id.to_s).click expect(page).to have_current_path(users_dossier_recapitulatif_path(Dossier.first.id.to_s), only_path: true) - page.find_by_id('open-message').trigger('click') + page.find_by_id('open-message').click page.execute_script("$('#texte_commentaire').data('wysihtml5').editor.setValue('Contenu du nouveau message')") - page.find_by_id('save-message').trigger('click') + page.find_by_id('save-message').click expect(page.find('.last-commentaire .content').text).to eq('Contenu du nouveau message') end - scenario 'On the same dossier, I want to edit informations' do - page.find_by_id('tr_dossier_' + Dossier.last.id.to_s).trigger('click') - page.find_by_id('edit-dossier').trigger('click') - expect(page).to have_current_path(users_dossier_description_path(Dossier.first.id.to_s), only_path: true) + scenario 'On the same dossier, I want to edit informations', js: true do + page.find_by_id('tr_dossier_' + dossier.id.to_s).click + expect(page).to have_current_path(users_dossier_recapitulatif_path(dossier.id.to_s), only_path: true) + page.find_by_id('maj_infos').trigger('click') + expect(page).to have_current_path(users_dossier_description_path(dossier.id.to_s), only_path: true) fill_in 'champs_1', with: 'Contenu du champ 1' - page.find_by_id('modification_terminee').trigger('click') - expect(page).to have_current_path(users_dossier_recapitulatif_path(Dossier.first.id.to_s), only_path: true) + page.find_by_id('modification_terminee').click + expect(page).to have_current_path(users_dossier_recapitulatif_path(dossier.id.to_s), only_path: true) expect(page.find('#champ-1-value').text).to eq('Contenu du champ 1') end end