From 69c121a8799cd80d48b8a18d755f4cd17ae6ac61 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Tue, 16 Jan 2018 15:16:51 +0100 Subject: [PATCH] FC ParticulierControllerSpec: simplify ... well you know --- .../particulier_controller_spec.rb | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/spec/controllers/france_connect/particulier_controller_spec.rb b/spec/controllers/france_connect/particulier_controller_spec.rb index 3823c91a0..30ea70beb 100644 --- a/spec/controllers/france_connect/particulier_controller_spec.rb +++ b/spec/controllers/france_connect/particulier_controller_spec.rb @@ -69,43 +69,29 @@ describe FranceConnect::ParticulierController, type: :controller do end context 'when france_connect_particulier_id does not exist in database' do - let(:last_france_connect_information) { FranceConnectInformation.last } - it { expect { subject }.to change { FranceConnectInformation.count }.by(1) } describe 'FranceConnectInformation attributs' do - before do - get :callback, params: {code: code} - end + let(:stored_fci) { FranceConnectInformation.last } - subject { last_france_connect_information } + before { subject } - it { expect(subject.gender).to eq gender } - it { expect(subject.given_name).to eq given_name } - it { expect(subject.family_name).to eq family_name } - it { expect(subject.email_france_connect).to eq email } - it { expect(subject.birthdate.to_time.to_i).to eq birthdate.to_time.to_i } - it { expect(subject.birthplace).to eq birthplace } - it { expect(subject.france_connect_particulier_id).to eq france_connect_particulier_id } + it { expect(stored_fci).to have_attributes(user_info.merge(birthdate: DateTime.parse(birthdate))) } end - it { expect(subject).to redirect_to(root_path) } + it { is_expected.to redirect_to(root_path) } end end context 'when code is not correct' do before do allow(FranceConnectService).to receive(:retrieve_user_informations_particulier) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') } - get :callback, params: {code: code} + subject end - it 'redirect to login page' do - expect(response).to redirect_to(new_user_session_path) - end + it { expect(response).to redirect_to(new_user_session_path) } - it 'display error message' do - expect(flash[:alert]).to be_present - end + it { expect(flash[:alert]).to be_present } end end end