From 472851695ee3bc196684b6e8480a3842f5b24e91 Mon Sep 17 00:00:00 2001 From: Margarita Barvinok Date: Fri, 5 Jul 2024 17:50:55 -0400 Subject: [PATCH 01/11] fix tests --- spec/system/room_controller_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/system/room_controller_spec.rb b/spec/system/room_controller_spec.rb index b7adb08b..e7e63617 100644 --- a/spec/system/room_controller_spec.rb +++ b/spec/system/room_controller_spec.rb @@ -48,7 +48,7 @@ context 'archive a room' do let!(:room) { FactoryBot.create(:room) } - + let!(:room_state) { FactoryBot.create(:room_state, room: room) } it 'shows a message that room was archived' do VCR.use_cassette "room" do room_id = room.id @@ -64,7 +64,7 @@ context 'cancel archiving a room' do let!(:room) { FactoryBot.create(:room) } - + let!(:room_state) { FactoryBot.create(:room_state, room: room) } it 'do not shows a message that room was archived' do VCR.use_cassette "room" do visit "rooms/#{room.id}" From 47ee27b3c99cac7718404808ae18b0a14fd8b5ec Mon Sep 17 00:00:00 2001 From: Margarita Barvinok Date: Sat, 6 Jul 2024 18:25:42 -0400 Subject: [PATCH 02/11] improve building controller tests --- spec/system/building_controller_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/system/building_controller_spec.rb b/spec/system/building_controller_spec.rb index 382cc198..c5c6b9a6 100644 --- a/spec/system/building_controller_spec.rb +++ b/spec/system/building_controller_spec.rb @@ -16,9 +16,10 @@ result = {"success"=>false, "errorcode"=>"", "error"=>"Building record number 123456 is not valid. ", "data"=>{}} allow_any_instance_of(BuildingApi).to receive(:get_building_info_by_bldrecnbr).with(bldrecnbr).and_return(result) visit new_building_path - fill_in "Building Record Number", with: "1234567" + fill_in "Building Record Number", with: bldrecnbr click_on "Create Building" expect(page).to have_content("is not valid.") + expect(Building.find_by(bldrecnbr: bldrecnbr).present?).to be_falsy end end end @@ -36,9 +37,10 @@ allow_any_instance_of(BuildingApi).to receive(:get_building_info_by_bldrecnbr).with(bldrecnbr).and_return(result) allow_any_instance_of(BuildingApi).to receive(:get_classrooms_for_building).with(bldrecnbr).and_return({}) visit new_building_path - fill_in "Building Record Number", with: "1234567" + fill_in "Building Record Number", with: bldrecnbr click_on "Create Building" expect(page).to have_content("New Building was added") + expect(Building.find_by(bldrecnbr: bldrecnbr).present?).to be_truthy end end end From caa9f2f4e25925f3ed956d91b0fefd19d66c5bad Mon Sep 17 00:00:00 2001 From: Margarita Barvinok Date: Sat, 6 Jul 2024 18:32:10 -0400 Subject: [PATCH 03/11] improve CommonAttribute controller spec --- spec/system/common_attributes_controller_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/system/common_attributes_controller_spec.rb b/spec/system/common_attributes_controller_spec.rb index 85ed5f59..a50d5f3b 100644 --- a/spec/system/common_attributes_controller_spec.rb +++ b/spec/system/common_attributes_controller_spec.rb @@ -17,6 +17,7 @@ check "Needs Checkbox?" click_on "Create" expect(page).to have_content("Common attribute was successfully created.") + expect(CommonAttribute.find_by(description: "common attribute one").present?).to be_truthy end end end @@ -66,21 +67,25 @@ it 'click on delete icon and cancel the alert messege' do VCR.use_cassette "common_attribute" do + common_attribute_id = common_attribute.id visit common_attributes_path dismiss_confirm 'Are you sure you want to delete this common attribute?' do find(:css, 'i.bi.bi-trash-fill.text-danger').click end expect(page).to_not have_content("Common attribute was successfully deleted.") + expect(CommonAttribute.find(common_attribute_id).present?).to be_truthy end end it 'click on delete icon and accept the alert message' do VCR.use_cassette "common_attribute" do + common_attribute_id = common_attribute.id visit common_attributes_path accept_confirm 'Are you sure you want to delete this common attribute?' do find(:css, 'i.bi.bi-trash-fill.text-danger').click end expect(page).to have_content("Common attribute was successfully deleted.") + expect { CommonAttribute.find(common_attribute_id) }.to raise_error(ActiveRecord::RecordNotFound) end end end From 2de6dc1b7a44e3c99f57dccaea79938dcfe68965 Mon Sep 17 00:00:00 2001 From: Margarita Barvinok Date: Sat, 6 Jul 2024 19:06:13 -0400 Subject: [PATCH 04/11] edit notes spec --- spec/system/notes_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/system/notes_spec.rb b/spec/system/notes_spec.rb index 71dfd3dc..a450d552 100644 --- a/spec/system/notes_spec.rb +++ b/spec/system/notes_spec.rb @@ -16,8 +16,8 @@ visit "rooms/#{room.id}" fill_in_trix_editor("note_content", with: "Hello world!") click_on "Add Note" - expect(page).to have_content("Hello world!") expect(page).to have_content("Updated on") + expect(Note.find_by(room_id: room.id).content.body.to_s.include?("Hello world!")).to be_truthy end end end From ef4e6095b159b58f905404166c42521316d6f805 Mon Sep 17 00:00:00 2001 From: Margarita Barvinok Date: Sat, 6 Jul 2024 19:06:23 -0400 Subject: [PATCH 05/11] edit rovers tests --- spec/system/rover_controller_spec.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/system/rover_controller_spec.rb b/spec/system/rover_controller_spec.rb index 91818347..38dad14d 100644 --- a/spec/system/rover_controller_spec.rb +++ b/spec/system/rover_controller_spec.rb @@ -19,6 +19,7 @@ fill_in "Create Rover by Uniqname", with: uniqname click_on "Create" expect(page).to have_content("is not valid.") + expect(Rover.find_by(uniqname: uniqname).present?).to be_falsy end end end @@ -33,6 +34,7 @@ fill_in "Create Rover by Uniqname", with: uniqname click_on "Create" expect(page).to have_content("Rover was successfully created.") + expect(Rover.find_by(uniqname: uniqname).present?).to be_truthy end end end @@ -52,21 +54,25 @@ let!(:rover) { FactoryBot.create(:rover) } it 'click on delete icon and cancel deleting' do VCR.use_cassette "rover" do + rover_id = rover.id visit rovers_path dismiss_confirm 'Are you sure you want to delete this rover?' do find(:css, 'i.bi.bi-trash-fill.text-danger').click end expect(page).to_not have_content("Rover was successfully deleted.") + expect(Rover.find(rover_id).present?).to be_truthy end end - it 'click on delete icon and update first name' do + it 'click on delete icon and delete rover' do VCR.use_cassette "rover" do + rover_id = rover.id visit rovers_path accept_confirm 'Are you sure you want to delete this rover?' do find(:css, 'i.bi.bi-trash-fill.text-danger').click end expect(page).to have_content("Rover was successfully deleted.") + expect { Rover.find(rover_id) }.to raise_error(ActiveRecord::RecordNotFound) end end end From 88899d8a3cc9ba204200ec79be21c8738f3fe25b Mon Sep 17 00:00:00 2001 From: Margarita Barvinok Date: Sat, 6 Jul 2024 19:10:10 -0400 Subject: [PATCH 06/11] edit specific_attribute controller tests --- spec/system/specific_attributes_controller_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/system/specific_attributes_controller_spec.rb b/spec/system/specific_attributes_controller_spec.rb index d7cbf3d9..1a6ea89e 100644 --- a/spec/system/specific_attributes_controller_spec.rb +++ b/spec/system/specific_attributes_controller_spec.rb @@ -18,6 +18,7 @@ check "Needs Checkbox?" click_on "Create" expect(page).to have_content("Specific attribute was successfully created.") + expect(SpecificAttribute.find_by(description: "specific attribute one").present?).to be_truthy end end end @@ -68,21 +69,25 @@ it 'click on delete icon and cancel the alert messege' do VCR.use_cassette "specific_attribute" do + specific_attribute_id = specific_attribute.id visit "rooms/#{room_id}/specific_attributes" dismiss_confirm 'Are you sure you want to delete this specific attribute?' do find(:css, 'i.bi.bi-trash-fill.text-danger').click end expect(page).to_not have_content("Specific attribute was successfully deleted.") + expect(SpecificAttribute.find(specific_attribute_id).present?).to be_truthy end end it 'click on delete icon and accept the alert message' do VCR.use_cassette "specific_attribute" do + specific_attribute_id = specific_attribute.id visit "rooms/#{room_id}/specific_attributes" accept_confirm 'Are you sure you want to delete this specific attribute?' do find(:css, 'i.bi.bi-trash-fill.text-danger').click end expect(page).to have_content("Specific attribute was successfully deleted.") + expect { SpecificAttribute.find(specific_attribute_id) }.to raise_error(ActiveRecord::RecordNotFound) end end end From 472363ecf93bff1b04633f338ec08e6285498e9c Mon Sep 17 00:00:00 2001 From: Margarita Barvinok Date: Sat, 6 Jul 2024 19:21:01 -0400 Subject: [PATCH 07/11] edit zones controller --- spec/system/zones_controller_spec.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/system/zones_controller_spec.rb b/spec/system/zones_controller_spec.rb index 1e220532..1c990591 100644 --- a/spec/system/zones_controller_spec.rb +++ b/spec/system/zones_controller_spec.rb @@ -17,6 +17,7 @@ fill_in "Name", with: "Zone A" click_on "Create Zone" expect(page).to have_content("Zone was successfully created.") + expect(Zone.find_by(name: "Zone A").present?).to be_truthy end end end @@ -55,23 +56,26 @@ it 'click on delete icon and cancel the alert message' do VCR.use_cassette "zone" do + zone_id = zone.id visit zones_path # dismiss_browser_dialog dismiss_confirm 'Are you sure you want to delete this zone?' do find(:css, 'i.bi.bi-trash-fill.text-danger').click end - expect(page).to_not have_content("Zone was successfully deleted.") + expect(Zone.find(zone_id).present?).to be_truthy end end it 'click on cancel icon and accept the alert message' do VCR.use_cassette "zone" do + zone_id = zone.id visit zones_path # accept_browser_dialog accept_confirm 'Are you sure you want to delete this zone?' do find(:css, 'i.bi.bi-trash-fill.text-danger').click end expect(page).to have_content("Zone was successfully deleted.") + expect { Zone.find(zone_id) }.to raise_error(ActiveRecord::RecordNotFound) end end end From 763634a425ba1d270b5ce51ad25bdabce229a38d Mon Sep 17 00:00:00 2001 From: Margarita Barvinok Date: Sat, 6 Jul 2024 19:24:24 -0400 Subject: [PATCH 08/11] add policies tests to workflow --- .github/workflows/run-rspec-tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/run-rspec-tests.yml b/.github/workflows/run-rspec-tests.yml index cc628838..897c25ab 100644 --- a/.github/workflows/run-rspec-tests.yml +++ b/.github/workflows/run-rspec-tests.yml @@ -59,6 +59,9 @@ jobs: - name: Run Model tests run: bundle exec rspec spec/models/* + - name: Run Policy tests + run: bundle exec rspec spec/policies/* + - name: Run System tests run: bundle exec rspec spec/system/* From 1ab6f38cbfa419ea6d94534c0850eb16c86ab6ee Mon Sep 17 00:00:00 2001 From: Margarita Barvinok Date: Sat, 6 Jul 2024 23:25:02 -0400 Subject: [PATCH 09/11] add error message --- app/controllers/buildings_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/buildings_controller.rb b/app/controllers/buildings_controller.rb index 9db67e84..f8b2782e 100644 --- a/app/controllers/buildings_controller.rb +++ b/app/controllers/buildings_controller.rb @@ -84,6 +84,7 @@ def destroy redirect_to buildings_path, notice: "The building was deleted." else @buildings = Building.active.order(:name) + flash.now["alert"] = "Error deleting building." end end end From c82047c9b78d740dd5d1b250e1f69ca9a96f41ec Mon Sep 17 00:00:00 2001 From: Margarita Barvinok Date: Sat, 6 Jul 2024 23:25:13 -0400 Subject: [PATCH 10/11] add more tests --- spec/system/building_controller_spec.rb | 50 +++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/spec/system/building_controller_spec.rb b/spec/system/building_controller_spec.rb index c5c6b9a6..cef48718 100644 --- a/spec/system/building_controller_spec.rb +++ b/spec/system/building_controller_spec.rb @@ -79,4 +79,54 @@ end end + context 'delete a building' do + let!(:building) { FactoryBot.create(:building) } + let!(:floor) { FactoryBot.create(:floor, building: building) } + let!(:room1) { FactoryBot.create(:room, floor: floor) } + let!(:room2) { FactoryBot.create(:room, floor: floor) } + let!(:resource1) { FactoryBot.create(:resource, room: room1) } + let!(:resource2) { FactoryBot.create(:resource, room: room1) } + let!(:specific_attribute1) { FactoryBot.create(:specific_attribute, room: room1) } + let!(:specific_attribute2) { FactoryBot.create(:specific_attribute, room: room2) } + + it 'and delete all rooms etc' do + VCR.use_cassette "building" do + building_id = building.id + visit "buildings/#{building_id}" + accept_confirm 'Are you sure you want to delete this building?' do + find(:css, 'i.bi.bi-trash-fill.text-danger').click + end + expect(page).to have_content("The building was deleted") + expect { Building.find(building_id) }.to raise_error(ActiveRecord::RecordNotFound) + end + end + + it 'fail deleting a building' do + allow(building).to receive(:delete).and_return(false) + allow(Building).to receive(:find).and_return(building) + VCR.use_cassette "building" do + building_id = building.id + visit "buildings/#{building_id}" + accept_confirm 'Are you sure you want to delete this building?' do + find(:css, 'i.bi.bi-trash-fill.text-danger').click + end + expect(page).to have_content("Error deleting building.") + end + end + + it 'fail deleting a building' do + allow_any_instance_of(BuildingsController).to receive(:delete_building).with(building).and_return(false) + allow(Building).to receive(:find).and_return(building) + VCR.use_cassette "building" do + building_id = building.id + visit "buildings/#{building_id}" + accept_confirm 'Are you sure you want to delete this building?' do + find(:css, 'i.bi.bi-trash-fill.text-danger').click + end + expect(page).to have_content("Error deleting building.") + expect(Building.find(building_id).present?).to be_truthy + end + end + + end end From 5dcfb75fd334dd60fc49482675b413b44152ed6a Mon Sep 17 00:00:00 2001 From: Margarita Barvinok Date: Sun, 7 Jul 2024 23:26:49 -0400 Subject: [PATCH 11/11] fix tests according to chanded validation --- spec/system/common_attributes_controller_spec.rb | 2 +- spec/system/specific_attributes_controller_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/system/common_attributes_controller_spec.rb b/spec/system/common_attributes_controller_spec.rb index a50d5f3b..8743ba5b 100644 --- a/spec/system/common_attributes_controller_spec.rb +++ b/spec/system/common_attributes_controller_spec.rb @@ -28,7 +28,7 @@ visit common_attributes_path fill_in "Description", with: "common attribute one" click_on "Create" - expect(page).to have_content("Needs to have either a checkbox or a quantity box, or both.") + expect(page).to have_content("Needs to have either a checkbox or a quantity box, but not both.") end end end diff --git a/spec/system/specific_attributes_controller_spec.rb b/spec/system/specific_attributes_controller_spec.rb index 1a6ea89e..dcd12119 100644 --- a/spec/system/specific_attributes_controller_spec.rb +++ b/spec/system/specific_attributes_controller_spec.rb @@ -30,7 +30,7 @@ visit "rooms/#{room.id}/specific_attributes" fill_in "Description", with: "specific attribute one" click_on "Create" - expect(page).to have_content("Needs to have either a checkbox or a quantity box, or both.") + expect(page).to have_content("Needs to have either a checkbox or a quantity box, but not both.") end end end