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

View File

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

View File

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

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'faker'
require 'factory_bot_rails'
@ -50,53 +52,42 @@ RSpec.configure do |config|
# Include FactoryGirl.
config.include FactoryBot::Syntax::Methods
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
=begin
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
# This allows you to limit a spec run to individual examples or groups
# you care about by tagging them with `:focus` metadata. When nothing
# is tagged with `:focus`, all examples get run. RSpec also provides
# aliases for `it`, `describe`, and `context` that include `:focus`
# 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
# the `--only-failures` and `--next-failure` CLI options. We recommend
# 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
# recommended. For more details, see:
# - http://rspec.info/blog/2012/06/rspecs-new-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
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
# config.disable_monkey_patching!
# Print the 10 slowest examples and example groups at the
# end of the spec run, to help surface which specs are running
# particularly slow.
config.profile_examples = 10
# config.profile_examples = 10
# 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
# the seed, which is printed after each run.
# --seed 1234
config.order = :random
# config.order = :random
# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed
=end
end
# Kernel.srand config.seed
end

View File

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