From 63b6bb74074c7d376ca0bcc4221b5c2e7f5f9f6a Mon Sep 17 00:00:00 2001 From: farhatahmad Date: Mon, 6 Apr 2020 16:25:04 -0400 Subject: [PATCH] Added tests --- app/controllers/rooms_controller.rb | 3 +- spec/controllers/rooms_controller_spec.rb | 62 ++++++++++++++++++++++- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index 07c2f87c..7d2d048b 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -62,7 +62,8 @@ class RoomsController < ApplicationController # GET /:room_uid def show - @anyone_can_start = JSON.parse(@room[:room_settings])["anyoneCanStart"] + @room_settings = @room[:room_settings] + @anyone_can_start = room_setting_with_config("anyoneCanStart") @room_running = room_running?(@room.bbb_id) @shared_room = room_shared_with_user diff --git a/spec/controllers/rooms_controller_spec.rb b/spec/controllers/rooms_controller_spec.rb index f6cdafd6..2765a785 100644 --- a/spec/controllers/rooms_controller_spec.rb +++ b/spec/controllers/rooms_controller_spec.rb @@ -275,7 +275,37 @@ describe RoomsController, type: :controller do expect(response).to redirect_to(join_path(room, @user.name, { user_is_moderator: false }, @user.uid)) end - it "should join the room as moderator if room has the all_join_moderator setting" do + it "doesn't join the room if the room has the anyone_can_start setting but config is disabled" do + allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:is_meeting_running?).and_return(false) + allow_any_instance_of(Setting).to receive(:get_value).and_return("disabled") + + room = Room.new(name: "test") + room.room_settings = "{\"muteOnStart\":false,\"joinViaHtml5\":false,\"anyoneCanStart\":true}" + room.owner = @owner + room.save + + @request.session[:user_id] = @user.id + post :join, params: { room_uid: room, join_name: @user.name } + + expect(response).to render_template(:wait) + end + + it "joins the room if the room doesn't have the anyone_can_start setting but config is set to enabled" do + allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:is_meeting_running?).and_return(false) + allow_any_instance_of(Setting).to receive(:get_value).and_return("enabled") + + room = Room.new(name: "test") + room.room_settings = "{\"anyoneCanStart\":false}" + room.owner = @owner + room.save + + @request.session[:user_id] = @user.id + post :join, params: { room_uid: room, join_name: @user.name } + + expect(response).to redirect_to(join_path(room, @user.name, { user_is_moderator: true }, @user.uid)) + end + + it "joins the room as moderator if room has the all_join_moderator setting" do allow_any_instance_of(Setting).to receive(:get_value).and_return("optional") allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:is_meeting_running?).and_return(true) @@ -290,6 +320,36 @@ describe RoomsController, type: :controller do expect(response).to redirect_to(join_path(room, @user.name, { user_is_moderator: true }, @user.uid)) end + it "joins the room as moderator if room doesn't have all_join_moderator but config is set to enabled" do + allow_any_instance_of(Setting).to receive(:get_value).and_return("enabled") + allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:is_meeting_running?).and_return(true) + + room = Room.new(name: "test") + room.room_settings = "{ }" + room.owner = @owner + room.save + + @request.session[:user_id] = @user.id + post :join, params: { room_uid: room, join_name: @user.name } + + expect(response).to redirect_to(join_path(room, @user.name, { user_is_moderator: true }, @user.uid)) + end + + it "doesn't join the room as moderator if room has the all_join_moderator setting but config is set to disabled" do + allow_any_instance_of(Setting).to receive(:get_value).and_return("disabled") + allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:is_meeting_running?).and_return(true) + + room = Room.new(name: "test") + room.room_settings = "{\"joinModerator\":true}" + room.owner = @owner + room.save + + @request.session[:user_id] = @user.id + post :join, params: { room_uid: room, join_name: @user.name } + + expect(response).to redirect_to(join_path(room, @user.name, { user_is_moderator: false }, @user.uid)) + end + it "should render wait if the correct access code is supplied" do allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:is_meeting_running?).and_return(false)