adhere to rubocop guidelines

This commit is contained in:
Josh 2018-06-26 10:29:46 -04:00
parent d2a677d15f
commit ad5f218f23
64 changed files with 305 additions and 212 deletions

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
source 'https://rubygems.org' source 'https://rubygems.org'
git_source(:github) do |repo_name| git_source(:github) do |repo_name|
@ -67,12 +69,16 @@ group :development, :test do
# Environment configuration. # Environment configuration.
gem 'dotenv-rails' gem 'dotenv-rails'
# Ruby linting.
gem 'rubocop'
end end
group :test do group :test do
# Include Rspec and other testing utilities. # Include Rspec and other testing utilities.
gem 'rspec-rails', '~> 3.7' gem 'rspec-rails', '~> 3.7'
gem 'action-cable-testing' gem 'action-cable-testing'
gem 'rails-controller-testing'
gem 'shoulda-matchers', '~> 3.1' gem 'shoulda-matchers', '~> 3.1'
gem 'faker' gem 'faker'
gem "factory_bot_rails" gem "factory_bot_rails"

View File

@ -41,6 +41,7 @@ GEM
minitest (~> 5.1) minitest (~> 5.1)
tzinfo (~> 1.1) tzinfo (~> 1.1)
arel (7.1.4) arel (7.1.4)
ast (2.4.0)
autoprefixer-rails (8.6.2) autoprefixer-rails (8.6.2)
execjs execjs
bcrypt (3.1.12) bcrypt (3.1.12)
@ -84,6 +85,7 @@ GEM
hashie (3.5.7) hashie (3.5.7)
i18n (1.0.1) i18n (1.0.1)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
jaro_winkler (1.5.1)
jbuilder (2.7.0) jbuilder (2.7.0)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
multi_json (>= 1.2) multi_json (>= 1.2)
@ -133,8 +135,12 @@ GEM
omniauth-twitter (1.4.0) omniauth-twitter (1.4.0)
omniauth-oauth (~> 1.1) omniauth-oauth (~> 1.1)
rack rack
parallel (1.12.1)
parser (2.5.1.0)
ast (~> 2.4.0)
pg (0.21.0) pg (0.21.0)
popper_js (1.12.9) popper_js (1.12.9)
powerpack (0.1.2)
puma (3.11.4) puma (3.11.4)
rack (2.0.5) rack (2.0.5)
rack-test (0.6.3) rack-test (0.6.3)
@ -151,6 +157,10 @@ GEM
bundler (>= 1.3.0) bundler (>= 1.3.0)
railties (= 5.0.7) railties (= 5.0.7)
sprockets-rails (>= 2.0.0) sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.2)
actionpack (~> 5.x, >= 5.0.1)
actionview (~> 5.x, >= 5.0.1)
activesupport (~> 5.x)
rails-dom-testing (2.0.3) rails-dom-testing (2.0.3)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
nokogiri (>= 1.6) nokogiri (>= 1.6)
@ -162,6 +172,7 @@ GEM
method_source method_source
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
rainbow (3.0.0)
rake (12.3.1) rake (12.3.1)
rb-fsevent (0.10.3) rb-fsevent (0.10.3)
rb-inotify (0.9.10) rb-inotify (0.9.10)
@ -184,6 +195,15 @@ GEM
rspec-mocks (~> 3.7.0) rspec-mocks (~> 3.7.0)
rspec-support (~> 3.7.0) rspec-support (~> 3.7.0)
rspec-support (3.7.1) rspec-support (3.7.1)
rubocop (0.57.2)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
sass (3.5.6) sass (3.5.6)
sass-listen (~> 4.0.0) sass-listen (~> 4.0.0)
sass-listen (4.0.0) sass-listen (4.0.0)
@ -222,6 +242,7 @@ GEM
thread_safe (~> 0.1) thread_safe (~> 0.1)
uglifier (4.1.11) uglifier (4.1.11)
execjs (>= 0.3.0, < 3) execjs (>= 0.3.0, < 3)
unicode-display_width (1.4.0)
web-console (3.6.2) web-console (3.6.2)
actionview (>= 5.0) actionview (>= 5.0)
activemodel (>= 5.0) activemodel (>= 5.0)
@ -254,8 +275,10 @@ DEPENDENCIES
pg (~> 0.18) pg (~> 0.18)
puma (~> 3.0) puma (~> 3.0)
rails (~> 5.0.7) rails (~> 5.0.7)
rails-controller-testing
redis (~> 3.0) redis (~> 3.0)
rspec-rails (~> 3.7) rspec-rails (~> 3.7)
rubocop
sass-rails (~> 5.0) sass-rails (~> 5.0)
shoulda-matchers (~> 3.1) shoulda-matchers (~> 3.1)
spring spring

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Add your own tasks in files placed in lib/tasks ending in .rake, # Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module ApplicationCable module ApplicationCable
class Channel < ActionCable::Channel::Base class Channel < ActionCable::Channel::Base
end end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module ApplicationCable module ApplicationCable
class Connection < ActionCable::Connection::Base class Connection < ActionCable::Connection::Base
end end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class WaitingChannel < ApplicationCable::Channel class WaitingChannel < ApplicationCable::Channel
def subscribed def subscribed
stream_from "#{params[:uid]}_waiting_channel" stream_from "#{params[:uid]}_waiting_channel"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'bigbluebutton_api' require 'bigbluebutton_api'
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
@ -43,18 +45,18 @@ class ApplicationController < ActionController::Base
# Determines if a form field needs the is-invalid class. # Determines if a form field needs the is-invalid class.
def form_is_invalid?(obj, key) def form_is_invalid?(obj, key)
'is-invalid' if !obj.errors.messages[key].empty? 'is-invalid' unless obj.errors.messages[key].empty?
end end
helper_method :form_is_invalid? helper_method :form_is_invalid?
# Default, unconfigured meeting options. # Default, unconfigured meeting options.
def default_meeting_options def default_meeting_options
invite_msg = "To invite someone to the meeting, send them this link:"
{ {
user_is_moderator: false, user_is_moderator: false,
meeting_logout_url: request.base_url + logout_room_path(@room), meeting_logout_url: request.base_url + logout_room_path(@room),
meeting_recorded: true, meeting_recorded: true,
moderator_message: "To invite someone to the meeting, send them this link:\n\n moderator_message: "#{invite_msg}\n\n #{request.base_url + relative_root + room_path(@room)}",
#{request.base_url + relative_root + room_path(@room)}"
} }
end end
end end

View File

@ -1,9 +1,10 @@
# frozen_string_literal: true
class ErrorsController < ApplicationController class ErrorsController < ApplicationController
def not_found def not_found
render status: 404 render status: 404
end end
def unprocessable def unprocessable
render status: 422 render status: 422
end end

View File

@ -1,6 +1,7 @@
class MainController < ApplicationController # frozen_string_literal: true
#before_action :redirect_to_room class MainController < ApplicationController
# before_action :redirect_to_room
# GET / # GET /
def index def index

View File

@ -1,5 +1,6 @@
class RoomsController < ApplicationController # frozen_string_literal: true
class RoomsController < ApplicationController
before_action :validate_accepted_terms, unless: -> { !Rails.configuration.terms } before_action :validate_accepted_terms, unless: -> { !Rails.configuration.terms }
before_action :find_room, except: :create before_action :find_room, except: :create
before_action :verify_room_ownership, except: [:create, :show, :join, :logout] before_action :verify_room_ownership, except: [:create, :show, :join, :logout]
@ -9,7 +10,7 @@ class RoomsController < ApplicationController
# POST / # POST /
def create def create
redirect_to root_path unless current_user redirect_to root_path unless current_user
@room = Room.new(name: room_params[:name]) @room = Room.new(name: room_params[:name])
@room.owner = current_user @room.owner = current_user
@ -19,9 +20,6 @@ class RoomsController < ApplicationController
else else
redirect_to @room redirect_to @room
end end
else
# Handle room didn't save.
end end
end end
@ -29,7 +27,7 @@ class RoomsController < ApplicationController
def show def show
if current_user && @room.owned_by?(current_user) if current_user && @room.owned_by?(current_user)
@recordings = @room.recordings @recordings = @room.recordings
@is_running = @room.is_running? @is_running = @room.running?
else else
render :join render :join
end end
@ -47,7 +45,7 @@ class RoomsController < ApplicationController
return return
end end
if @room.is_running? if @room.running?
if current_user if current_user
redirect_to @room.join_path(current_user.name, opts, current_user.uid) redirect_to @room.join_path(current_user.name, opts, current_user.uid)
else else
@ -92,13 +90,13 @@ class RoomsController < ApplicationController
current_user.main_room = @room current_user.main_room = @room
current_user.save current_user.save
redirect_to @room redirect_to @room
end end
# POST /:room_uid/:record_id # POST /:room_uid/:record_id
def update_recording def update_recording
meta = { meta = {
"meta_#{META_LISTED}" => (params[:state] == "public") "meta_#{META_LISTED}" => (params[:state] == "public"),
} }
res = @room.update_recording(params[:record_id], meta) res = @room.update_recording(params[:record_id], meta)
@ -124,12 +122,10 @@ class RoomsController < ApplicationController
if len > 60 if len > 60
"#{len / 60} hrs" "#{len / 60} hrs"
elsif len == 0
"< 1 min"
else else
if len == 0 "#{len} min"
"< 1 min"
else
"#{len} min"
end
end end
end end
helper_method :recording_length helper_method :recording_length
@ -147,7 +143,7 @@ class RoomsController < ApplicationController
# Ensure the user is logged into the room they are accessing. # Ensure the user is logged into the room they are accessing.
def verify_room_ownership def verify_room_ownership
bring_to_room if !@room.owned_by?(current_user) bring_to_room unless @room.owned_by?(current_user)
end end
# Redirects a user to their room. # Redirects a user to their room.

View File

@ -1,5 +1,6 @@
class SessionsController < ApplicationController # frozen_string_literal: true
class SessionsController < ApplicationController
# GET /users/login # GET /users/login
def new def new
end end
@ -13,11 +14,8 @@ class SessionsController < ApplicationController
# POST /users/login # POST /users/login
def create def create
user = User.find_by(email: session_params[:email]) user = User.find_by(email: session_params[:email])
if user && user.authenticate(session_params[:password]) if user.&authenticate(session_params[:password])
login(user) login(user)
else
# Login unsuccessful, display error message.
end end
end end

View File

@ -1,5 +1,6 @@
class UsersController < ApplicationController # frozen_string_literal: true
class UsersController < ApplicationController
before_action :find_user, only: [:edit, :update] before_action :find_user, only: [:edit, :update]
before_action :ensure_unauthenticated, only: [:new, :create] before_action :ensure_unauthenticated, only: [:new, :create]
@ -12,7 +13,7 @@ class UsersController < ApplicationController
@user.provider = "greenlight" @user.provider = "greenlight"
if @user.save if @user.save
login(@user) login(@user)
else else
# Handle error on user creation. # Handle error on user creation.
render :new render :new
@ -61,16 +62,13 @@ class UsersController < ApplicationController
redirect_to edit_user_path(@user), notice: "Information successfully updated." redirect_to edit_user_path(@user), notice: "Information successfully updated."
else else
# Append custom errors. # Append custom errors.
errors.each do |k, v| @user.errors.add(k, v) end errors.each { |k, v| @user.errors.add(k, v) }
render :edit render :edit
end end
elsif @user.update_attributes(user_params)
redirect_to edit_user_path(@user), notice: "Information successfully updated."
else else
# Update the core user attributes. render :edit
if @user.update_attributes(user_params)
redirect_to edit_user_path(@user), notice: "Information successfully updated."
else
render :edit
end
end end
end end
@ -83,7 +81,7 @@ class UsersController < ApplicationController
redirect_to current_user.main_room redirect_to current_user.main_room
end end
end end
private private
def find_user def find_user

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module ApplicationHelper module ApplicationHelper
include MeetingsHelper include MeetingsHelper
@ -12,7 +14,7 @@ module ApplicationHelper
def omniauth_login_url(provider) def omniauth_login_url(provider)
"#{Rails.configuration.relative_url_root}/auth/#{provider}" "#{Rails.configuration.relative_url_root}/auth/#{provider}"
end end
# Determine if Greenlight is configured to allow user signups. # Determine if Greenlight is configured to allow user signups.
def allow_user_signup? def allow_user_signup?
Rails.configuration.allow_user_signup Rails.configuration.allow_user_signup

View File

@ -1,2 +1,4 @@
# frozen_string_literal: true
module ErrorsHelper module ErrorsHelper
end end

View File

@ -1,2 +1,4 @@
# frozen_string_literal: true
module MainHelper module MainHelper
end end

View File

@ -1,2 +1,4 @@
# frozen_string_literal: true
module MeetingsHelper module MeetingsHelper
end end

View File

@ -1,2 +1,4 @@
# frozen_string_literal: true
module RoomsHelper module RoomsHelper
end end

View File

@ -1,11 +1,12 @@
# frozen_string_literal: true
module SessionsHelper module SessionsHelper
# Logs a user into GreenLight. # Logs a user into GreenLight.
def login(user) def login(user)
session[:user_id] = user.id session[:user_id] = user.id
# If there are not terms, or the user has accepted them, go to their room. # If there are not terms, or the user has accepted them, go to their room.
if !Rails.configuration.terms || user.accepted_terms then if !Rails.configuration.terms || user.accepted_terms
redirect_to user.main_room redirect_to user.main_room
else else
redirect_to terms_path redirect_to terms_path

View File

@ -1,2 +1,4 @@
# frozen_string_literal: true
module UsersHelper module UsersHelper
end end

View File

@ -1,2 +1,4 @@
# frozen_string_literal: true
class ApplicationJob < ActiveJob::Base class ApplicationJob < ActiveJob::Base
end end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class NotifyUserWaitingJob < ApplicationJob class NotifyUserWaitingJob < ApplicationJob
queue_as :default queue_as :default

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ApplicationMailer < ActionMailer::Base class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com' default from: 'from@example.com'
layout 'mailer' layout 'mailer'

View File

@ -1,7 +1,9 @@
# frozen_string_literal: true
class ApplicationRecord < ActiveRecord::Base class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true self.abstract_class = true
def to_param def to_param
uid uid
end end
end end

View File

@ -1,5 +1,6 @@
class Room < ApplicationRecord # frozen_string_literal: true
class Room < ApplicationRecord
before_create :setup before_create :setup
validates :name, presence: true validates :name, presence: true
@ -8,7 +9,6 @@ class Room < ApplicationRecord
RETURNCODE_SUCCESS = "SUCCESS" RETURNCODE_SUCCESS = "SUCCESS"
META_LISTED = "gl-listed" META_LISTED = "gl-listed"
UID_LENGTH = 6
# Determines if a user owns a room. # Determines if a user owns a room.
def owned_by?(user) def owned_by?(user)
@ -17,7 +17,7 @@ class Room < ApplicationRecord
end end
# Checks if a room is running on the BigBlueButton server. # Checks if a room is running on the BigBlueButton server.
def is_running? def running?
bbb.is_meeting_running?(bbb_id) bbb.is_meeting_running?(bbb_id)
end end
@ -34,16 +34,11 @@ class Room < ApplicationRecord
moderatorPW: random_password(12), moderatorPW: random_password(12),
attendeePW: random_password(12), attendeePW: random_password(12),
moderatorOnlyMessage: options[:moderator_message], moderatorOnlyMessage: options[:moderator_message],
"meta_#{META_LISTED}": false "meta_#{META_LISTED}": false,
} }
# Update session info. # Update session info.
self.update_attributes(sessions: sessions + 1, last_session: DateTime.now) update_attributes(sessions: sessions + 1, last_session: DateTime.now)
#meeting_options.merge!(
#{ "meta_room-id": options[:room_owner],
# "meta_meeting-name": options[:meeting_name]}
#) if options[:room_owner]
# Send the create request. # Send the create request.
begin begin
@ -56,7 +51,7 @@ class Room < ApplicationRecord
# Returns a URL to join a user into a meeting. # Returns a URL to join a user into a meeting.
def join_path(name, options = {}, uid = nil) def join_path(name, options = {}, uid = nil)
# Create the meeting if it isn't running. # Create the meeting if it isn't running.
start_session(options) unless is_running? start_session(options) unless running?
# Set meeting options. # Set meeting options.
options[:meeting_logout_url] ||= nil options[:meeting_logout_url] ||= nil
@ -64,7 +59,7 @@ class Room < ApplicationRecord
options[:user_is_moderator] ||= false options[:user_is_moderator] ||= false
options[:meeting_recorded] ||= false options[:meeting_recorded] ||= false
return call_invalid_res if !bbb return call_invalid_res unless bbb
# Get the meeting info. # Get the meeting info.
meeting_info = bbb.get_meeting_info(bbb_id, nil) meeting_info = bbb.get_meeting_info(bbb_id, nil)
@ -78,30 +73,26 @@ class Room < ApplicationRecord
# Generate the join URL. # Generate the join URL.
join_opts = {} join_opts = {}
join_opts.merge!({userID: uid}) if uid join_opts[:userID] = uid if uid
join_opts.merge!({joinViaHtml5: true}) if Rails.configuration.html5_enabled join_opts[:joinViaHtml5] = true if Rails.configuration.html5_enabled
bbb.join_meeting_url(bbb_id, name, password, join_opts) bbb.join_meeting_url(bbb_id, name, password, join_opts)
end end
# Notify waiting users that a meeting has started. # Notify waiting users that a meeting has started.
def notify_waiting def notify_waiting
ActionCable.server.broadcast("#{uid}_waiting_channel", { ActionCable.server.broadcast("#{uid}_waiting_channel", action: "started")
action: "started"
})
end end
# Retrieves all the users in a room. # Retrieves all the users in a room.
def participants def participants
begin res = bbb.get_meeting_info(bbb_id, nil)
res = bbb.get_meeting_info(bbb_id, nil) res[:attendees].map do |att|
res[:attendees].map do |att| User.find_by(uid: att[:userID], name: att[:fullName])
User.find_by(uid: att[:userID], name: att[:fullName])
end
rescue BigBlueButton::BigBlueButtonException => exc
# The meeting is most likely not running.
[]
end end
rescue BigBlueButton::BigBlueButtonException
# The meeting is most likely not running.
[]
end end
# Fetches all recordings for a room. # Fetches all recordings for a room.
@ -120,18 +111,18 @@ class Room < ApplicationRecord
end end
r.delete(:playback) r.delete(:playback)
end end
res[:recordings] res[:recordings]
end end
# Fetches a rooms public recordings. # Fetches a rooms public recordings.
def public_recordings def public_recordings
recordings.select do |r| r[:metadata][:"gl-listed"] == "true" end recordings.select { |r| r[:metadata][:"gl-listed"] == "true" }
end end
def update_recording(record_id, meta) def update_recording(record_id, meta)
meta.merge!({recordID: record_id}) meta[:recordID] = record_id
bbb.send_api_request("updateRecordings", meta) bbb.send_api_request("updateRecordings", meta)
end end
@ -153,12 +144,12 @@ class Room < ApplicationRecord
# Sets a BigBlueButtonApi object for interacting with the API. # Sets a BigBlueButtonApi object for interacting with the API.
def bbb def bbb
@bbb ||= BigBlueButton::BigBlueButtonApi.new(remove_slash(bbb_endpoint), bbb_secret, "0.8") @bbb ||= BigBlueButton::BigBlueButtonApi.new(remove_slash(bbb_endpoint), bbb_secret, "0.8")
#@bbb ||= if Rails.configuration.loadbalanced_configuration # @bbb ||= if Rails.configuration.loadbalanced_configuration
# lb_user = retrieve_loadbalanced_credentials(self.room.owner.provider) # lb_user = retrieve_loadbalanced_credentials(self.room.owner.provider)
# BigBlueButton::BigBlueButtonApi.new(remove_slash(lb_user["apiURL"]), lb_user["secret"], "0.8") # BigBlueButton::BigBlueButtonApi.new(remove_slash(lb_user["apiURL"]), lb_user["secret"], "0.8")
#else # else
# BigBlueButton::BigBlueButtonApi.new(remove_slash(bbb_endpoint), bbb_secret, "0.8") # BigBlueButton::BigBlueButtonApi.new(remove_slash(bbb_endpoint), bbb_secret, "0.8")
#end # end
end end
# Generates a uid for the room and BigBlueButton. # Generates a uid for the room and BigBlueButton.
@ -167,10 +158,15 @@ class Room < ApplicationRecord
self.bbb_id = Digest::SHA1.hexdigest(Rails.application.secrets[:secret_key_base] + Time.now.to_i.to_s).to_s self.bbb_id = Digest::SHA1.hexdigest(Rails.application.secrets[:secret_key_base] + Time.now.to_i.to_s).to_s
end end
# Generates a three character uid chunk.
def uid_chunk
charset = ("a".."z").to_a - %w(b i l o s) + ("2".."9").to_a - %w(5 8)
(0...3).map { charset.to_a[rand(charset.size)] }.join
end
# Generates a random room uid that uses the users name. # Generates a random room uid that uses the users name.
def random_room_uid def random_room_uid
charset = %w{ 2 3 4 6 7 9 a c d e f g h j k m n p q r t v w x y z} [owner.firstname, uid_chunk, uid_chunk].join('-').downcase
owner.firstname.downcase + "-" + (0...UID_LENGTH).map{ charset.to_a[rand(charset.size)] }.join.insert(UID_LENGTH / 2, "-")
end end
# Rereives the loadbalanced BigBlueButton credentials for a user. # Rereives the loadbalanced BigBlueButton credentials for a user.
@ -182,7 +178,7 @@ class Room < ApplicationRecord
uri = encode_bbb_url( uri = encode_bbb_url(
Rails.configuration.loadbalancer_endpoint, Rails.configuration.loadbalancer_endpoint,
Rails.configuration.loadbalancer_secret, Rails.configuration.loadbalancer_secret,
{name: provider} name: provider
) )
# Make the request. # Make the request.
@ -190,7 +186,7 @@ class Room < ApplicationRecord
http.use_ssl = (uri.scheme == 'https') http.use_ssl = (uri.scheme == 'https')
response = http.get(uri.request_uri) response = http.get(uri.request_uri)
unless response.kind_of?(Net::HTTPSuccess) unless response.is_a?(Net::HTTPSuccess)
raise "Error retrieving provider credentials: #{response.code} #{response.message}" raise "Error retrieving provider credentials: #{response.code} #{response.message}"
end end
@ -209,7 +205,7 @@ class Room < ApplicationRecord
encoded_params = OAuth::Helper.normalize(params) encoded_params = OAuth::Helper.normalize(params)
string = "getUser" + encoded_params + secret string = "getUser" + encoded_params + secret
checksum = OpenSSL::Digest.digest('sha1', string).unpack("H*").first checksum = OpenSSL::Digest.digest('sha1', string).unpack("H*").first
URI.parse("#{base_url}?#{encoded_params}&checksum=#{checksum}") URI.parse("#{base_url}?#{encoded_params}&checksum=#{checksum}")
end end
@ -220,7 +216,7 @@ class Room < ApplicationRecord
# Generates a random password for a meeting. # Generates a random password for a meeting.
def random_password(length) def random_password(length)
o = ([('a'..'z'), ('A'..'Z')].map do |i| i.to_a end).flatten charset = ("a".."z").to_a + ("A".."Z").to_a
((0...length).map do o[rand(o.length)] end).join ((0...length).map { charset[rand(charset.length)] }).join
end end
end end

View File

@ -1,17 +1,18 @@
class User < ApplicationRecord # frozen_string_literal: true
class User < ApplicationRecord
after_create :initialize_main_room after_create :initialize_main_room
before_save { email.downcase! unless email.nil? } before_save { email.try(:downcase!) }
has_many :rooms has_many :rooms
belongs_to :main_room, class_name: 'Room', foreign_key: :room_id, required: false belongs_to :main_room, class_name: 'Room', foreign_key: :room_id, required: false
validates :name, length: { maximum: 24 }, presence: true validates :name, length: { maximum: 24 }, presence: true
validates :provider, presence: true validates :provider, presence: true
validates :image, format: {with: /\.(png|jpg)\Z/i}, allow_blank: true validates :image, format: { with: /\.(png|jpg)\Z/i }, allow_blank: true
validates :email, length: { maximum: 60 }, allow_blank: true, validates :email, length: { maximum: 60 }, allow_blank: true,
uniqueness: { case_sensitive: false }, uniqueness: { case_sensitive: false },
format: {with: /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i } format: { with: /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i }
validates :password, length: { minimum: 6 }, confirmation: true, if: :greenlight_account? validates :password, length: { minimum: 6 }, confirmation: true, if: :greenlight_account?
@ -19,26 +20,15 @@ class User < ApplicationRecord
has_secure_password(validations: false) has_secure_password(validations: false)
class << self class << self
# Generates a user from omniauth. # Generates a user from omniauth.
def from_omniauth(auth) def from_omniauth(auth)
user = find_or_initialize_by( find_or_initialize_by(social_uid: auth['uid'], provider: auth['provider']).tap do |u|
social_uid: auth['uid'], u.name = send("#{auth['provider']}_name", auth)
provider: auth['provider'] u.username = send("#{auth['provider']}_username", auth)
) u.email = send("#{auth['provider']}_email", auth)
u.image = send("#{auth['provider']}_image", auth)
user.name = send("#{auth['provider']}_name", auth) u.save!
user.username = send("#{auth['provider']}_username", auth) end
user.email = send("#{auth['provider']}_email", auth)
user.image = send("#{auth['provider']}_image", auth)
user.save!
user
end
# Generates a user from a trusted launcher.
def from_launch(auth)
end end
private private
@ -80,9 +70,9 @@ class User < ApplicationRecord
# Retrives a list of all a users rooms that are not the main room, sorted by last session date. # Retrives a list of all a users rooms that are not the main room, sorted by last session date.
def secondary_rooms def secondary_rooms
secondary = (rooms - [main_room]) secondary = (rooms - [main_room])
no_session, session = secondary.partition do |r| r.last_session.nil? end no_session, session = secondary.partition { |r| r.last_session.nil? }
sorted = session.sort_by do |r| r.last_session end sorted = session.sort_by(&:last_session)
session + no_session sorted + no_session
end end
def firstname def firstname
@ -99,6 +89,6 @@ class User < ApplicationRecord
def initialize_main_room def initialize_main_room
self.uid = "gl-#{(0...12).map { (65 + rand(26)).chr }.join.downcase}" self.uid = "gl-#{(0...12).map { (65 + rand(26)).chr }.join.downcase}"
self.main_room = Room.create!(owner: self, name: firstname + "'s Room") self.main_room = Room.create!(owner: self, name: firstname + "'s Room")
self.save save
end end
end end

View File

@ -1,3 +1,5 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
# frozen_string_literal: true
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle') load Gem.bin_path('bundler', 'bundle')

View File

@ -1,4 +1,6 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
# frozen_string_literal: true
begin begin
load File.expand_path('../spring', __FILE__) load File.expand_path('../spring', __FILE__)
rescue LoadError => e rescue LoadError => e

View File

@ -1,4 +1,6 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
# frozen_string_literal: true
begin begin
load File.expand_path('../spring', __FILE__) load File.expand_path('../spring', __FILE__)
rescue LoadError => e rescue LoadError => e

View File

@ -1,4 +1,6 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
# frozen_string_literal: true
require 'pathname' require 'pathname'
require 'fileutils' require 'fileutils'
include FileUtils include FileUtils

View File

@ -1,4 +1,5 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
# frozen_string_literal: true
# This file loads spring without using Bundler, in order to be fast. # This file loads spring without using Bundler, in order to be fast.
# It gets overwritten when you run the `spring binstub` command. # It gets overwritten when you run the `spring binstub` command.

View File

@ -1,4 +1,6 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
# frozen_string_literal: true
require 'pathname' require 'pathname'
require 'fileutils' require 'fileutils'
include FileUtils include FileUtils

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# This file is used by Rack-based servers to start the application. # This file is used by Rack-based servers to start the application.
require_relative 'config/environment' require_relative 'config/environment'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_relative 'boot' require_relative 'boot'
require 'rails/all' require 'rails/all'
@ -13,12 +15,16 @@ module Greenlight
# -- all .rb files in that directory are automatically loaded. # -- all .rb files in that directory are automatically loaded.
# Use custom error routes. # Use custom error routes.
config.exceptions_app = self.routes config.exceptions_app = routes
config.loadbalanced_configuration = (ENV["USE_LOADBALANCED_CONFIGURATION"] == "true") config.loadbalanced_configuration = (ENV["USE_LOADBALANCED_CONFIGURATION"] == "true")
# Setup BigBlueButton configuration. # Setup BigBlueButton configuration.
unless config.loadbalanced_configuration if config.loadbalanced_configuration
# Fetch credentials from a loadbalancer based on provider.
config.loadbalancer_endpoint = ENV["LOADBALANCER_ENDPOINT"]
config.loadbalancer_secret = ENV["LOADBALANCER_SECRET"]
else
# Default credentials (test-install.blindsidenetworks.com/bigbluebutton). # Default credentials (test-install.blindsidenetworks.com/bigbluebutton).
config.bigbluebutton_endpoint_default = "http://test-install.blindsidenetworks.com/bigbluebutton/api/" config.bigbluebutton_endpoint_default = "http://test-install.blindsidenetworks.com/bigbluebutton/api/"
config.bigbluebutton_secret_default = "8cd8ef52e8e101574e400365b55e11a6" config.bigbluebutton_secret_default = "8cd8ef52e8e101574e400365b55e11a6"
@ -35,10 +41,6 @@ module Greenlight
# Fix endpoint format if required. # Fix endpoint format if required.
config.bigbluebutton_endpoint += "api/" unless config.bigbluebutton_endpoint.ends_with?('api/') config.bigbluebutton_endpoint += "api/" unless config.bigbluebutton_endpoint.ends_with?('api/')
else
# Fetch credentials from a loadbalancer based on provider.
config.loadbalancer_endpoint = ENV["LOADBALANCER_ENDPOINT"]
config.loadbalancer_secret = ENV["LOADBALANCER_SECRET"]
end end
# Determine if GreenLight should allow non-omniauth signup/login. # Determine if GreenLight should allow non-omniauth signup/login.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' # Set up gems listed in the Gemfile. require 'bundler/setup' # Set up gems listed in the Gemfile.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Load the Rails application. # Load the Rails application.
require_relative 'application' require_relative 'application'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
Rails.application.configure do Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb. # Settings specified here will take precedence over those in config/application.rb.
@ -18,7 +20,7 @@ Rails.application.configure do
config.cache_store = :memory_store config.cache_store = :memory_store
config.public_file_server.headers = { config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=172800' 'Cache-Control' => 'public, max-age=172800',
} }
else else
config.action_controller.perform_caching = false config.action_controller.perform_caching = false

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
Rails.application.configure do Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb. # Settings specified here will take precedence over those in config/application.rb.
@ -47,7 +49,7 @@ Rails.application.configure do
config.log_level = :debug config.log_level = :debug
# Prepend all log lines with the following tags. # Prepend all log lines with the following tags.
config.log_tags = [ :request_id ] config.log_tags = [:request_id]
# Use a different cache store in production. # Use a different cache store in production.
# config.cache_store = :mem_cache_store # config.cache_store = :mem_cache_store
@ -85,9 +87,6 @@ Rails.application.configure do
config.active_record.dump_schema_after_migration = false config.active_record.dump_schema_after_migration = false
# Set the relative url root for deployment to a subdirectory. # Set the relative url root for deployment to a subdirectory.
if ENV['RELATIVE_URL_ROOT'].present? config.relative_url_root = "/"
config.relative_url_root = ENV['RELATIVE_URL_ROOT'] config.relative_url_root = ENV['RELATIVE_URL_ROOT'] if ENV['RELATIVE_URL_ROOT'].present?
else
config.relative_url_root = "/"
end
end end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
Rails.application.configure do Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb. # Settings specified here will take precedence over those in config/application.rb.
@ -15,7 +17,7 @@ Rails.application.configure do
# Configure public file server for tests with Cache-Control for performance. # Configure public file server for tests with Cache-Control for performance.
config.public_file_server.enabled = true config.public_file_server.enabled = true
config.public_file_server.headers = { config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=3600' 'Cache-Control' => 'public, max-age=3600',
} }
# Show full error reports and disable caching. # Show full error reports and disable caching.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# ActiveSupport::Reloader.to_prepare do # ActiveSupport::Reloader.to_prepare do

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets. # Version of your assets, change this if you want to expire all your assets.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# Specify a serializer for the signed and encrypted cookie jars. # Specify a serializer for the signed and encrypted cookie jars.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file. # Configure sensitive parameters which will be filtered from the log file.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Send a request to check if the HTML5 client is enabled on the BigBlueButton server. # Send a request to check if the HTML5 client is enabled on the BigBlueButton server.
uri = URI.parse(Rails.configuration.bigbluebutton_endpoint.gsub('bigbluebutton/api', 'html5client/check')) uri = URI.parse(Rails.configuration.bigbluebutton_endpoint.gsub('bigbluebutton/api', 'html5client/check'))
res = Net::HTTP.get_response(uri) res = Net::HTTP.get_response(uri)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format. Inflections # Add new inflection rules using the following format. Inflections

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks: # Add new mime types for use in respond_to blocks:

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# #
# This file contains migration options to ease your Rails 5.0 upgrade. # This file contains migration options to ease your Rails 5.0 upgrade.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# List of supported Omniauth providers. # List of supported Omniauth providers.
Rails.application.config.providers = [:google, :twitter] Rails.application.config.providers = [:google, :twitter]
@ -10,8 +12,8 @@ Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, ENV['TWITTER_ID'], ENV['TWITTER_SECRET'] provider :twitter, ENV['TWITTER_ID'], ENV['TWITTER_SECRET']
provider :google_oauth2, ENV['GOOGLE_OAUTH2_ID'], ENV['GOOGLE_OAUTH2_SECRET'], provider :google_oauth2, ENV['GOOGLE_OAUTH2_ID'], ENV['GOOGLE_OAUTH2_SECRET'],
scope: ['profile', 'email'], scope: %w(profile email),
access_type: 'online', access_type: 'online',
name: 'google', name: 'google',
hd: ENV['GOOGLE_OAUTH2_HD'].blank? ? nil : ENV['GOOGLE_OAUTH2_HD'] hd: ENV['GOOGLE_OAUTH2_HD'].blank? ? nil : ENV['GOOGLE_OAUTH2_HD']
end end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
Rails.application.config.session_store :cookie_store, key: '_greenlight-2_0_session' Rails.application.config.session_store :cookie_store, key: '_greenlight-2_0_session'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Load terms and conditions. # Load terms and conditions.
terms = "#{Rails.root}/config/terms.txt" terms = "#{Rails.root}/config/terms.txt"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# This file contains settings for ActionController::ParamsWrapper which # This file contains settings for ActionController::ParamsWrapper which

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Puma can serve each request in a thread from an internal thread pool. # Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers a minimum and maximum. # The `threads` method setting takes two numbers a minimum and maximum.
# Any libraries that use thread pools should be configured to match # Any libraries that use thread pools should be configured to match

View File

@ -1,5 +1,6 @@
Rails.application.routes.draw do # frozen_string_literal: true
Rails.application.routes.draw do
# Error routes. # Error routes.
match '/404', to: 'errors#not_found', via: :all match '/404', to: 'errors#not_found', via: :all
match '/422', to: 'errors#unprocessable', via: :all match '/422', to: 'errors#unprocessable', via: :all
@ -15,7 +16,7 @@ Rails.application.routes.draw do
# Handles login of greenlight provider accounts. # Handles login of greenlight provider accounts.
post '/login', to: 'sessions#create', as: :create_session post '/login', to: 'sessions#create', as: :create_session
# Log the user out of the session. # Log the user out of the session.
get '/logout', to: 'sessions#destroy' get '/logout', to: 'sessions#destroy'
@ -39,7 +40,7 @@ Rails.application.routes.draw do
post '/start', to: 'rooms#start', as: :start_room post '/start', to: 'rooms#start', as: :start_room
get '/logout', to: 'rooms#logout', as: :logout_room get '/logout', to: 'rooms#logout', as: :logout_room
post '/home', to: 'rooms#home', as: :make_home post '/home', to: 'rooms#home', as: :make_home
# Mange recordings. # Mange recordings.
scope '/:record_id' do scope '/:record_id' do
post '/', to: 'rooms#update_recording', as: :update_recording post '/', to: 'rooms#update_recording', as: :update_recording

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
%w( %w(
.ruby-version .ruby-version
.rbenv-vars .rbenv-vars

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class CreateUsers < ActiveRecord::Migration[5.0] class CreateUsers < ActiveRecord::Migration[5.0]
def change def change
create_table :users do |t| create_table :users do |t|

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class CreateRooms < ActiveRecord::Migration[5.0] class CreateRooms < ActiveRecord::Migration[5.0]
def change def change
create_table :rooms do |t| create_table :rooms do |t|

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# This file should contain all the record creation needed to seed the database with its default values. # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
# #

View File

@ -1,11 +1,13 @@
# frozen_string_literal: true
require 'net/http' require 'net/http'
require 'nokogiri' require 'nokogiri'
require 'digest/sha1' require 'digest/sha1'
namespace :conf do namespace :conf do
desc "Check Configuration" desc "Check Configuration"
task :check => :environment do task check: :environment do
ENV_VARIABLES = ['SECRET_KEY_BASE', 'BIGBLUEBUTTON_ENDPOINT', 'BIGBLUEBUTTON_SECRET'] ENV_VARIABLES = %w(SECRET_KEY_BASE BIGBLUEBUTTON_ENDPOINT BIGBLUEBUTTON_SECRET)
# Initial check that variables are set # Initial check that variables are set
print "\nChecking environment" print "\nChecking environment"
@ -31,17 +33,15 @@ end
# takes the full URL including the protocol # takes the full URL including the protocol
def test_request(url) def test_request(url)
begin uri = URI(url)
uri = URI(url) res = Net::HTTP.get(uri)
res = Net::HTTP.get(uri)
doc = Nokogiri::XML(res) doc = Nokogiri::XML(res)
if doc.css("returncode").text != "SUCCESS" if doc.css("returncode").text != "SUCCESS"
failed("Could not get a valid response from BigBlueButton server - #{res}") failed("Could not get a valid response from BigBlueButton server - #{res}")
end
rescue => exc
failed("Error connecting to BigBlueButton server - #{exc}")
end end
rescue => exc
failed("Error connecting to BigBlueButton server - #{exc}")
end end
def failed(msg) def failed(msg)
@ -49,6 +49,6 @@ def failed(msg)
exit exit
end end
def passed() def passed
print(": Passed\n") print(": Passed\n")
end end

View File

@ -1,10 +1,11 @@
# frozen_string_literal: true
FactoryBot.define do FactoryBot.define do
factory :user do factory :user do
password = Faker::Internet.password(8) password = Faker::Internet.password(8)
provider { %w(greenlight google twitter).sample } provider { %w(greenlight google twitter).sample }
uid { rand(10 ** 8) } uid { rand(10**8) }
name { Faker::Name.first_name } name { Faker::Name.first_name }
username { Faker::Internet.user_name } username { Faker::Internet.user_name }
email { Faker::Internet.email } email { Faker::Internet.email }

View File

@ -1,12 +1,13 @@
# frozen_string_literal: true
require "rails_helper" require "rails_helper"
require 'bigbluebutton_api' require 'bigbluebutton_api'
describe Room, type: :model do describe Room, type: :model do
before do
before {
@user = create(:user) @user = create(:user)
@room = @user.main_room @room = @user.main_room
} end
context 'validations' do context 'validations' do
it { should validate_presence_of(:name) } it { should validate_presence_of(:name) }
@ -45,14 +46,14 @@ describe Room, type: :model do
end end
end end
context "#is_running?" do context "#running?" do
it "should return false when not running" do it "should return false when not running" do
expect(@room.is_running?).to be false expect(@room.running?).to be false
end end
it "should return true when running" do it "should return true when running" do
allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:is_meeting_running?).and_return(true) allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:is_meeting_running?).and_return(true)
expect(@room.is_running?).to be true expect(@room.running?).to be true
end end
end end
@ -60,11 +61,9 @@ describe Room, type: :model do
it "should update latest session info" do it "should update latest session info" do
allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:create_meeting).and_return(true) allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:create_meeting).and_return(true)
expect{ expect do
@room.start_session @room.start_session
}.to change { end.to change { @room.sessions }.by(1)
@room.sessions
}.by(1)
expect(@room.last_session.utc.to_i).to eq(Time.now.to_i) expect(@room.last_session.utc.to_i).to eq(Time.now.to_i)
end end
@ -72,33 +71,31 @@ describe Room, type: :model do
context "#join_path" do context "#join_path" do
it "should return correct join URL for user" do it "should return correct join URL for user" do
allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:get_meeting_info).and_return({ allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:get_meeting_info).and_return(
attendeePW: "testpass" attendeePW: "testpass"
}) )
endpoint = Rails.configuration.bigbluebutton_endpoint endpoint = Rails.configuration.bigbluebutton_endpoint
secret = Rails.configuration.bigbluebutton_secret secret = Rails.configuration.bigbluebutton_secret
fullname = "fullName=Example" fullname = "fullName=Example"
html = if Rails.configuration.html5_enabled then "&joinViaHtml5=true" else "" end html = Rails.configuration.html5_enabled ? "&joinViaHtml5=true" : ""
meetingID = "&meetingID=#{@room.bbb_id}" meeting_id = "&meetingID=#{@room.bbb_id}"
password = "&password=testpass" password = "&password=testpass"
query = fullname + html + meetingID + password query = fullname + html + meeting_id + password
checksum_string = "join#{query + secret}" checksum_string = "join#{query + secret}"
checksum = OpenSSL::Digest.digest('sha1', checksum_string).unpack("H*").first checksum = OpenSSL::Digest.digest('sha1', checksum_string).unpack("H*").first
expect(@room.join_path("Example")).to eql( expect(@room.join_path("Example")).to eql("#{endpoint}join?#{query}&checksum=#{checksum}")
"#{endpoint}join?#{query}&checksum=#{checksum}"
)
end end
end end
context "#notify_waiting" do context "#notify_waiting" do
it "should broadcast to waiting channel with started action" do it "should broadcast to waiting channel with started action" do
expect{ expect do
@room.notify_waiting @room.notify_waiting
}.to have_broadcasted_to("#{@room.uid}_waiting_channel").with(a_hash_including(action: "started")) end.to have_broadcasted_to("#{@room.uid}_waiting_channel").with(a_hash_including(action: "started"))
end end
end end
@ -107,13 +104,13 @@ describe Room, type: :model do
user1 = create(:user) user1 = create(:user)
user2 = create(:user) user2 = create(:user)
allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:get_meeting_info).and_return({ allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:get_meeting_info).and_return(
attendees: [ attendees: [
{userID: user1.uid, fullName: user1.name}, { userID: user1.uid, fullName: user1.name },
{userID: "non-matching-uid", fullName: "Guest User"}, { userID: "non-matching-uid", fullName: "Guest User" },
{userID: user2.uid, fullName: user2.name} { userID: user2.uid, fullName: user2.name },
] ],
}) )
expect(@room.participants).to contain_exactly(user1, nil, user2) expect(@room.participants).to contain_exactly(user1, nil, user2)
end end
@ -121,21 +118,21 @@ describe Room, type: :model do
context "#recordings" do context "#recordings" do
it "should properly find meeting recordings" do it "should properly find meeting recordings" do
allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:get_recordings).and_return({ allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:get_recordings).and_return(
recordings: [ recordings: [
{ {
name: "Example", name: "Example",
playback: { playback: {
format: "presentation" format: "presentation",
} },
}, },
] ],
}) )
expect(@room.recordings).to contain_exactly({ expect(@room.recordings).to contain_exactly(
name: "Example", name: "Example",
playbacks: ["presentation"] playbacks: %w(presentation),
}) )
end end
end end
end end

View File

@ -1,7 +1,11 @@
# frozen_string_literal: true
require "rails_helper" require "rails_helper"
describe User, type: :model do describe User, type: :model do
before { @user = create(:user) } before do
@user = create(:user)
end
context 'validations' do context 'validations' do
it { should validate_presence_of(:name) } it { should validate_presence_of(:name) }
@ -21,8 +25,8 @@ describe User, type: :model do
it { should allow_value("", nil).for(:image) } it { should allow_value("", nil).for(:image) }
it "should convert email to downcase on save" do it "should convert email to downcase on save" do
user = create(:user, email: "EXAMPLE@EXAMPLE.COM") user = create(:user, email: "DOWNCASE@DOWNCASE.COM")
expect(user.email).to eq("example@example.com") expect(user.email).to eq("downcase@downcase.com")
end end
context 'is greenlight account' do context 'is greenlight account' do
@ -63,11 +67,11 @@ describe User, type: :model do
"name" => "Test Name", "name" => "Test Name",
"nickname" => "username", "nickname" => "username",
"email" => "test@example.com", "email" => "test@example.com",
"image" => "example.png" "image" => "example.png",
} },
} }
expect { expect do
user = User.from_omniauth(auth) user = User.from_omniauth(auth)
expect(user.name).to eq("Test Name") expect(user.name).to eq("Test Name")
@ -75,9 +79,7 @@ describe User, type: :model do
expect(user.image).to eq("example.png") expect(user.image).to eq("example.png")
expect(user.provider).to eq("twitter") expect(user.provider).to eq("twitter")
expect(user.social_uid).to eq("123456789") expect(user.social_uid).to eq("123456789")
}.to change { end.to change { User.count }.by(1)
User.count
}.by(1)
end end
end end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# This file is copied to spec/ when you run 'rails generate rspec:install' # This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper' require 'spec_helper'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'faker' require 'faker'
require 'factory_bot_rails' require 'factory_bot_rails'
@ -50,53 +52,42 @@ RSpec.configure do |config|
# Include FactoryGirl. # Include FactoryGirl.
config.include FactoryBot::Syntax::Methods config.include FactoryBot::Syntax::Methods
# The settings below are suggested to provide a good initial experience # The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content. # with RSpec, but feel free to customize to your heart's content.
=begin
# This allows you to limit a spec run to individual examples or groups # This allows you to limit a spec run to individual examples or groups
# you care about by tagging them with `:focus` metadata. When nothing # you care about by tagging them with `:focus` metadata. When nothing
# is tagged with `:focus`, all examples get run. RSpec also provides # is tagged with `:focus`, all examples get run. RSpec also provides
# aliases for `it`, `describe`, and `context` that include `:focus` # aliases for `it`, `describe`, and `context` that include `:focus`
# metadata: `fit`, `fdescribe` and `fcontext`, respectively. # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
config.filter_run_when_matching :focus # config.filter_run_when_matching :focus
# Allows RSpec to persist some state between runs in order to support # Allows RSpec to persist some state between runs in order to support
# the `--only-failures` and `--next-failure` CLI options. We recommend # the `--only-failures` and `--next-failure` CLI options. We recommend
# you configure your source control system to ignore this file. # you configure your source control system to ignore this file.
config.example_status_persistence_file_path = "spec/examples.txt" # config.example_status_persistence_file_path = "spec/examples.txt"
# Limits the available syntax to the non-monkey patched syntax that is # Limits the available syntax to the non-monkey patched syntax that is
# recommended. For more details, see: # recommended. For more details, see:
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
config.disable_monkey_patching! # config.disable_monkey_patching!
# Many RSpec users commonly either run the entire suite or an individual
# file, and it's useful to allow more verbose output when running an
# individual spec file.
if config.files_to_run.one?
# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
config.default_formatter = "doc"
end
# Print the 10 slowest examples and example groups at the # Print the 10 slowest examples and example groups at the
# end of the spec run, to help surface which specs are running # end of the spec run, to help surface which specs are running
# particularly slow. # particularly slow.
config.profile_examples = 10 # config.profile_examples = 10
# Run specs in random order to surface order dependencies. If you find an # Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing # order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run. # the seed, which is printed after each run.
# --seed 1234 # --seed 1234
config.order = :random # config.order = :random
# Seed global randomization in this process using the `--seed` CLI option. # Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce # Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value # test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure. # as the one that triggered the failure.
Kernel.srand config.seed # Kernel.srand config.seed
=end end
end

View File

@ -1,9 +1,10 @@
# Configure Shoulda-Matchers. # frozen_string_literal: true
# Configure Shoulda-Matchers.
Shoulda::Matchers.configure do |config| Shoulda::Matchers.configure do |config|
config.integrate do |with| config.integrate do |with|
with.test_framework :rspec with.test_framework :rspec
with.library :rails with.library :rails
end end
end end