<commit_before># This file is part of Mconf-Web, a web application that provides access
# to the Mconf webconferencing system. Copyright (C) 2010-2015 Mconf.
#
# This file is licensed under the Affero General Public License version
# 3 or later. See the LICENSE file.

require "spec_helper"

describe BigbluebuttonRails do

  describe "#invitation_url" do
    let(:target) { BigbluebuttonRails.configuration }
    let(:room) { FactoryGirl.create(:bigbluebutton_room) }
    before {
      Site.current.update_attributes(domain: "localhost:4000")
    }
    set_conf_scope_rooms('webconf')

    it { target.should respond_to(:get_invitation_url) }
    it { target.get_invitation_url.should be_a(Proc) }
    it { target.get_invitation_url.call(room).should eql("http://#{Site.current.domain}/webconf/#{room.slug}") }

    context "works with HTTPS" do
      before {
        Site.current.update_attributes(ssl: true)
      }

      it { target.get_invitation_url.call(room).should eql("https://#{Site.current.domain}/webconf/#{room.slug}") }
    end
  end

  describe "#get_create_options" do
    let(:target) { BigbluebuttonRails.configuration }
    let(:room) { FactoryGirl.create(:bigbluebutton_room) }
    before {
      Site.current.update_attributes(domain: "localhost:4000")
    }

    it { target.should respond_to(:get_create_options) }
    it { target.get_create_options.should be_a(Proc) }

    context "for a user room" do
      before {
        room.update_attributes(owner: FactoryGirl.create(:user))
      }

      it {
        target.get_create_options.call(room).should have_key("meta_mconfweb-url")
        target.get_create_options.call(room).should have_key("meta_mconfweb-room-type")
        target.get_create_options.call(room)["meta_mconfweb-url"].should eql("http://#{Site.current.domain}/")
        target.get_create_options.call(room)["meta_mconfweb-room-type"].should eql("User")
      }
    end

    context "for a space room" do
      before {
        room.update_attributes(owner: FactoryGirl.create(:space))
      }

      it {
        target.get_create_options.call(room).should have_key("meta_mconfweb-url")
        target.get_create_options.call(room).should have_key("meta_mconfweb-room-type")
        target.get_create_options.call(room)["meta_mconfweb-url"].should eql("http://#{Site.current.domain}/")
        target.get_create_options.call(room)["meta_mconfweb-room-type"].should eql("Space")
      }
    end

    context "works with HTTPS" do
      before {
        Site.current.update_attributes(ssl: true)
        room.update_attributes(owner: FactoryGirl.create(:space))
      }

      it {
        target.get_create_options.call(room).should have_key("meta_mconfweb-url")
        target.get_create_options.call(room).should have_key("meta_mconfweb-room-type")
        target.get_create_options.call(room)["meta_mconfweb-url"].should eql("https://#{Site.current.domain}/")
        target.get_create_options.call(room)["meta_mconfweb-room-type"].should eql("Space")
      }
    end
  end
end<commit_msg>Add a few more tests for BigbluebuttonRails' .get_create_options<commit_after># This file is part of Mconf-Web, a web application that provides access
# to the Mconf webconferencing system. Copyright (C) 2010-2015 Mconf.
#
# This file is licensed under the Affero General Public License version
# 3 or later. See the LICENSE file.

require "spec_helper"

describe BigbluebuttonRails do

  describe "#invitation_url" do
    let(:target) { BigbluebuttonRails.configuration }
    let(:room) { FactoryGirl.create(:bigbluebutton_room) }
    before {
      Site.current.update_attributes(domain: "localhost:4000")
    }
    set_conf_scope_rooms('webconf')

    it { target.should respond_to(:get_invitation_url) }
    it { target.get_invitation_url.should be_a(Proc) }
    it { target.get_invitation_url.call(room).should eql("http://#{Site.current.domain}/webconf/#{room.slug}") }

    context "works with HTTPS" do
      before {
        Site.current.update_attributes(ssl: true)
      }

      it { target.get_invitation_url.call(room).should eql("https://#{Site.current.domain}/webconf/#{room.slug}") }
    end
  end

  describe "#get_create_options" do
    let(:target) { BigbluebuttonRails.configuration }
    let(:room) { FactoryGirl.create(:bigbluebutton_room) }
    before {
      Site.current.update_attributes(domain: "localhost:4000")
    }

    it { target.should respond_to(:get_create_options) }
    it { target.get_create_options.should be_a(Proc) }

    context "sets the metadata" do
      context "for a user room" do
        before {
          room.update_attributes(owner: FactoryGirl.create(:user))
        }

        it {
          target.get_create_options.call(room).should have_key("meta_mconfweb-url")
          target.get_create_options.call(room).should have_key("meta_mconfweb-room-type")
          target.get_create_options.call(room)["meta_mconfweb-url"].should eql("http://#{Site.current.domain}/")
          target.get_create_options.call(room)["meta_mconfweb-room-type"].should eql("User")
        }
      end

      context "for a space room" do
        before {
          room.update_attributes(owner: FactoryGirl.create(:space))
        }

        it {
          target.get_create_options.call(room).should have_key("meta_mconfweb-url")
          target.get_create_options.call(room).should have_key("meta_mconfweb-room-type")
          target.get_create_options.call(room)["meta_mconfweb-url"].should eql("http://#{Site.current.domain}/")
          target.get_create_options.call(room)["meta_mconfweb-room-type"].should eql("Space")
        }
      end

      context "works with HTTPS" do
        before {
          Site.current.update_attributes(ssl: true)
          room.update_attributes(owner: FactoryGirl.create(:space))
        }

        it {
          target.get_create_options.call(room).should have_key("meta_mconfweb-url")
          target.get_create_options.call(room).should have_key("meta_mconfweb-room-type")
          target.get_create_options.call(room)["meta_mconfweb-url"].should eql("https://#{Site.current.domain}/")
          target.get_create_options.call(room)["meta_mconfweb-room-type"].should eql("Space")
        }
      end
    end

    context "sets the record flag" do
      context "if there's no user logged" do
        it {
          target.get_create_options.call(room, nil).should have_key(:record)
          target.get_create_options.call(room, nil)[:record].should be(false)
        }
      end

      context "if there's a user logged" do
        let(:user) { FactoryGirl.create(:user) }
        before {
          # a custom ability to control what the user can do
          @ability = Object.new
          @ability.extend(CanCan::Ability)
          Abilities.stub(:ability_for).and_return(@ability)
        }

        context "sets the record option" do
          context "when the user can record" do
            before { @ability.can :record_meeting, room }

            context "and the room is set to record" do
              before { room.update_attributes(record_meeting: true) }
              it {
                target.get_create_options.call(room, user).should have_key(:record)
                target.get_create_options.call(room, user)[:record].should be(true)
              }
            end

            context "and the room is not set to record" do
              before { room.update_attributes(record_meeting: false) }
              it {
                target.get_create_options.call(room, user).should have_key(:record)
                target.get_create_options.call(room, user)[:record].should be(true)
              }
            end
          end

          context "when the user cannot record" do
            before { @ability.cannot :record_meeting, room }

            context "and the room is set to record" do
              before { room.update_attributes(record_meeting: true) }
              it {
                target.get_create_options.call(room, user).should have_key(:record)
                target.get_create_options.call(room, user)[:record].should be(false)
              }
            end

            context "and the room is not set to record" do
              before { room.update_attributes(record_meeting: false) }
              it {
                target.get_create_options.call(room, nil).should have_key(:record)
                target.get_create_options.call(room, nil)[:record].should be(false)
              }
            end
          end
        end

      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11385443482330915, 'fraction_numerical': 0.003978469459396209, 'mean_word_length': 2.7868852459016393, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2871289', 'n_tokens_mistral': 2626, 'n_tokens_neox': 2557, 'n_words': 481}