From 0277ae5dbdd46b0c5b1dad02674413548187d31b Mon Sep 17 00:00:00 2001 From: Jannik Pulfer Date: Fri, 2 Aug 2024 10:55:55 +0200 Subject: [PATCH] Rewrite people_employees feature spec as request spec --- spec/features/people_employees_spec.rb | 53 -------------------------- spec/rails_helper.rb | 1 + spec/requests/people_employees_spec.rb | 53 ++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 53 deletions(-) delete mode 100644 spec/features/people_employees_spec.rb create mode 100644 spec/requests/people_employees_spec.rb diff --git a/spec/features/people_employees_spec.rb b/spec/features/people_employees_spec.rb deleted file mode 100644 index 6900e6840..000000000 --- a/spec/features/people_employees_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'rails_helper' - -describe Ptime::PeopleEmployees do - describe 'Update or create person', type: :feature, js: true do - before(:each) do - sign_in auth_users(:user), scope: :auth_user - end - - it 'should update person when visited' do - stub_ptime_request(fixture_data("wally").to_json, "employees/50", 200) - - Company.create!(name: "Ex-Mitarbeiter") - person_wally = people(:wally) - person_wally.ptime_employee_id = 50 - person_wally.save! - - expect(person_wally.name).to eq('Wally Allround') - expect(person_wally.email).to eq('wally@example.com') - visit person_path(person_wally) - person_wally.reload - expect(person_wally.name).to eq('Changed Wally Allround') - expect(person_wally.shortname).to eq('CAL') - expect(person_wally.email).to eq('changedwally@example.com') - expect(person_wally.marital_status).to eq('single') - expect(person_wally.title).to eq('Quarter-Stack Developer') - expect(person_wally.birthdate).to eq('1.1.2000') - expect(person_wally.location).to eq('Basel') - expect(person_wally.nationality).to eq('DE') - expect(person_wally.nationality2).to eq('DK') - end - - it 'should create person when visited' do - stub_ptime_request(fixture_data("wally").to_json, "employees/50", 200) - - Company.create!(name: "Ex-Mitarbeiter") - - person_wally = people(:wally) - person_wally.destroy! - expect(Person.find_by(name: "Wally Allround")).to be_nil - visit new_person_path(ptime_employee_id: 50) - new_wally = Person.find_by(name: "Changed Wally Allround") - expect(new_wally.name).to eq('Changed Wally Allround') - expect(new_wally.shortname).to eq('CAL') - expect(new_wally.email).to eq('changedwally@example.com') - expect(new_wally.marital_status).to eq('single') - expect(new_wally.title).to eq('Quarter-Stack Developer') - expect(new_wally.birthdate).to eq('1.1.2000') - expect(new_wally.location).to eq('Basel') - expect(new_wally.nationality).to eq('DE') - expect(new_wally.nationality2).to eq('DK') - end - end -end \ No newline at end of file diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index d57d07b37..43ba3a7e7 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -78,6 +78,7 @@ # Helpers from gems config.include(Devise::Test::IntegrationHelpers, type: :feature) + config.include(Devise::Test::IntegrationHelpers, type: :request) config.include(Devise::Test::ControllerHelpers, type: :controller) config.include(ActionView::RecordIdentifier, type: :feature) diff --git a/spec/requests/people_employees_spec.rb b/spec/requests/people_employees_spec.rb new file mode 100644 index 000000000..f8dde026d --- /dev/null +++ b/spec/requests/people_employees_spec.rb @@ -0,0 +1,53 @@ +require "rails_helper" + +describe 'Update or create person' do + before(:each) do + sign_in auth_users(:user), scope: :auth_user + end + it 'should update person when visited' do + stub_ptime_request(fixture_data("wally").to_json, "employees/50", 200) + + Company.create!(name: "Ex-Mitarbeiter") + person_wally = people(:wally) + person_wally.ptime_employee_id = 50 + person_wally.save! + expect(person_wally.name).to eq('Wally Allround') + expect(person_wally.email).to eq('wally@example.com') + + get "/people/#{person_wally.id}" + expect(response).to render_template(:show) + + person_wally.reload + expect(person_wally.name).to eq('Changed Wally Allround') + expect(person_wally.shortname).to eq('CAL') + expect(person_wally.email).to eq('changedwally@example.com') + expect(person_wally.marital_status).to eq('single') + expect(person_wally.title).to eq('Quarter-Stack Developer') + expect(person_wally.birthdate).to eq('1.1.2000') + expect(person_wally.location).to eq('Basel') + expect(person_wally.nationality).to eq('DE') + expect(person_wally.nationality2).to eq('DK') + end + + it 'should create person when visited' do + stub_ptime_request(fixture_data("wally").to_json, "employees/50", 200) + + Company.create!(name: "Ex-Mitarbeiter") + person_wally = people(:wally) + person_wally.destroy! + expect(Person.find_by(name: "Wally Allround")).to be_nil + + get "/people/new?ptime_employee_id=50" + + new_wally = Person.find_by(name: "Changed Wally Allround") + expect(new_wally.name).to eq('Changed Wally Allround') + expect(new_wally.shortname).to eq('CAL') + expect(new_wally.email).to eq('changedwally@example.com') + expect(new_wally.marital_status).to eq('single') + expect(new_wally.title).to eq('Quarter-Stack Developer') + expect(new_wally.birthdate).to eq('1.1.2000') + expect(new_wally.location).to eq('Basel') + expect(new_wally.nationality).to eq('DE') + expect(new_wally.nationality2).to eq('DK') + end +end \ No newline at end of file