Skip to content

Commit

Permalink
Merge pull request #141 from lsa-mis/fix-failed-rspec-tests
Browse files Browse the repository at this point in the history
Fix failed rspec tests
  • Loading branch information
britaumich authored Jul 8, 2024
2 parents 1b754f2 + 5dcfb75 commit 6f59fd3
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/run-rspec-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/*

Expand Down
1 change: 1 addition & 0 deletions app/controllers/buildings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 54 additions & 2 deletions spec/system/building_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -77,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
7 changes: 6 additions & 1 deletion spec/system/common_attributes_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/system/notes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/system/room_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"
Expand Down
8 changes: 7 additions & 1 deletion spec/system/rover_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion spec/system/specific_attributes_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion spec/system/zones_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6f59fd3

Please sign in to comment.