diff --git a/spec/requests/active_personal_space_lists_controller_spec.rb b/spec/requests/active_personal_space_lists_controller_spec.rb new file mode 100644 index 00000000..44eb1424 --- /dev/null +++ b/spec/requests/active_personal_space_lists_controller_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe ActivePersonalSpaceList, type: :request do + let(:user) { Fabricate(:user) } + let(:users_space_list) { Fabricate(:personal_space_list, user:) } + let(:someone_elses_space_list) { Fabricate(:personal_space_list) } + + before do + sign_in user + end + + it "can activate and deactivate a list" do + expect(user.active_personal_space_list).to be_nil + + post activate_personal_space_list_personal_space_list_path(id: users_space_list.id) + expect(user.reload.active_personal_space_list.personal_space_list_id).to be(users_space_list.id) + + post deactivate_personal_space_list_personal_space_list_path(id: users_space_list.id) + expect(user.reload.active_personal_space_list).to be_nil + end +end diff --git a/spec/requests/personal_space_lists/shared_with_publics_controller_spec.rb b/spec/requests/personal_space_lists/shared_with_publics_controller_spec.rb index ebc3dc28..3e7d9ad8 100644 --- a/spec/requests/personal_space_lists/shared_with_publics_controller_spec.rb +++ b/spec/requests/personal_space_lists/shared_with_publics_controller_spec.rb @@ -143,4 +143,25 @@ expect(response).to redirect_to(personal_space_lists_path) expect(someone_elses_data_on_space.reload.contact_status).to eq("said_no") end + + it "can activate and deactivate a list shared by someone, and have it removed if the list is no longer shared" do + expect(user.active_personal_space_list).to be_nil + + post activate_personal_space_list_personal_space_list_path(id: someone_elses_space_list.id) + expect(user.reload.active_personal_space_list).to be_nil + + someone_elses_space_list.start_sharing + + post activate_personal_space_list_personal_space_list_path(id: someone_elses_space_list.id) + expect(user.reload.active_personal_space_list.personal_space_list_id).to be(someone_elses_space_list.id) + + post deactivate_personal_space_list_personal_space_list_path(id: someone_elses_space_list.id) + expect(user.reload.active_personal_space_list).to be_nil + + post activate_personal_space_list_personal_space_list_path(id: someone_elses_space_list.id) + expect(user.reload.active_personal_space_list.personal_space_list_id).to be(someone_elses_space_list.id) + + someone_elses_space_list.stop_sharing + expect(user.reload.active_personal_space_list).to be_nil + end end