Skip to content

Commit

Permalink
Fix CI (#5432)
Browse files Browse the repository at this point in the history
* Fix Greenlight CI

* Rubocop fixes
  • Loading branch information
farhatahmad authored Oct 3, 2023
1 parent e7ba4e0 commit 16bf14f
Show file tree
Hide file tree
Showing 28 changed files with 143 additions and 140 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.build.push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
- v2
- v3
- translations*
- snyk*
- dependabot*

jobs:
main:
Expand Down
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@ Rails/Output:
Rails/RootPathnameMethods:
Enabled: false

Rails/ThreeStateBooleanColumn:
Enabled: false

2 changes: 1 addition & 1 deletion app/controllers/api/v1/admin/server_rooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def index

pagy, paged_rooms = pagy(rooms)

RunningMeetingChecker.new(rooms: paged_rooms.select(&:online)).call if paged_rooms.select(&:online).any?
RunningMeetingChecker.new(rooms: paged_rooms.select(&:online)).call if paged_rooms.any?(&:online)

render_data data: paged_rooms, meta: pagy_metadata(pagy), serializer: ServerRoomSerializer, status: :ok
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/rooms_configurations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def show

render_data data: config_value, status: :ok
rescue StandardError
return render_error status: :not_found unless config_value
render_error status: :not_found unless config_value
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/rooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def index
room.shared = true if room.user_id != current_user.id
end

RunningMeetingChecker.new(rooms: rooms.select(&:online)).call if rooms.select(&:online).any?
RunningMeetingChecker.new(rooms: rooms.select(&:online)).call if rooms.any?(&:online)

render_data data: rooms, status: :ok
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/verify_account_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def find_user_and_authorize
return render_error status: :bad_request unless params[:user]

@user = User.find_by id: params[:user][:id]
return render_data status: :ok unless @user && !@user.verified?
render_data status: :ok unless @user && !@user.verified?
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/concerns/authorizable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ module Authorizable

# Unless the request format is explicitly json Rails will mitigate the responsibility to CSR to handle it.
def ensure_valid_request
return render 'components/index' if !Rails.env.development? && !valid_api_request?
render 'components/index' if !Rails.env.development? && !valid_api_request?
end

# Ensures that the user is logged in
def ensure_authenticated
return render_error status: :unauthorized unless current_user
render_error status: :unauthorized unless current_user
end

# PermissionsChecker service will return a true or false depending on whether the current_user's role has the provided permission_name
def ensure_authorized(permission_names, user_id: nil, friendly_id: nil, record_id: nil)
return render_error status: :forbidden unless PermissionsChecker.new(
render_error status: :forbidden unless PermissionsChecker.new(
current_user:,
permission_names:,
user_id:,
Expand All @@ -42,7 +42,7 @@ def ensure_authorized(permission_names, user_id: nil, friendly_id: nil, record_i
end

def ensure_super_admin
return render_error status: :forbidden unless current_user.super_admin?
render_error status: :forbidden unless current_user.super_admin?
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/presentable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Presentable
extend ActiveSupport::Concern

def presentation_file_name(room)
return room.presentation.filename if room.presentation.attached?
room.presentation.filename if room.presentation.attached?
end

def presentation_thumbnail(room)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def change

# Use Active Record's configured type for primary key

create_table :active_storage_variant_records, id: primary_key_type, if_not_exists: true do |t| # rubocop:disable Rails/CreateTableWithTimestamps
create_table :active_storage_variant_records, id: primary_key_type, if_not_exists: true do |t|
t.belongs_to :blob, null: false, index: false, type: blobs_primary_key_type
t.string :variation_digest, null: false

Expand Down
2 changes: 0 additions & 2 deletions lib/tasks/poller.rake
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ namespace :poller do
online_meetings = Room.includes(:user).where(online: true)

RunningMeetingChecker.new(rooms: online_meetings).call

rescue StandardError => e
err "Unable to poll meetings. Error: #{e}"
end
Expand All @@ -72,7 +71,6 @@ namespace :poller do
end

RecordingCreator.new(recording:).call

rescue StandardError => e
err "Unable to poll Recording:\nRecordID: #{recording[:recordID]}\nError: #{e}"
next
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/admin/invitations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
get :index

expect(response).to have_http_status(:ok)
expect(JSON.parse(response.body)['data'].pluck('email')).to match_array(invitations.pluck(:email))
expect(response.parsed_body['data'].pluck('email')).to match_array(invitations.pluck(:email))
end

it 'returns the invitations according to the query' do
Expand All @@ -52,7 +52,7 @@

get :index, params: { search: 'test.com' }

expect(JSON.parse(response.body)['data'].pluck('email')).to match_array(invitations.pluck(:email))
expect(response.parsed_body['data'].pluck('email')).to match_array(invitations.pluck(:email))
end

context 'user without ManageUsers permission' do
Expand All @@ -74,7 +74,7 @@
expect { post :create, params: { invitations: valid_params } }.to change(Invitation, :count).by(3)

expect(response).to have_http_status(:ok)
expect(JSON.parse(response.body)['errors']).to be_nil
expect(response.parsed_body['errors']).to be_nil
end

it 'emails the invitations to the invited user' do
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/admin/role_permissions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
get :index, params: { role_id: user_with_manage_roles_permission.role_id }

expect(response).to have_http_status(:ok)
expect(JSON.parse(response.body)['data']['CreateRoom']).to eq('true')
expect(JSON.parse(response.body)['data']['RoomLimit']).to eq('100')
expect(JSON.parse(response.body)['data']['SharedList']).to eq('true')
expect(JSON.parse(response.body)['data']['ManageRoles']).to eq('true')
expect(response.parsed_body['data']['CreateRoom']).to eq('true')
expect(response.parsed_body['data']['RoomLimit']).to eq('100')
expect(response.parsed_body['data']['SharedList']).to eq('true')
expect(response.parsed_body['data']['ManageRoles']).to eq('true')
end

context 'user without ManageRoles permission' do
Expand Down
24 changes: 12 additions & 12 deletions spec/controllers/admin/roles_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

get :index
expect(response).to have_http_status(:ok)
expect(JSON.parse(response.body)['data'].pluck('id')).to match_array(roles.pluck(:id))
expect(response.parsed_body['data'].pluck('id')).to match_array(roles.pluck(:id))
end

it 'returns the roles according to the query' do
Expand All @@ -44,14 +44,14 @@
create_list(:role, 3)

get :index, params: { search: 'role' }
expect(JSON.parse(response.body)['data'].pluck('id')).to match_array(search_roles.pluck(:id))
expect(response.parsed_body['data'].pluck('id')).to match_array(search_roles.pluck(:id))
end

it 'returns all roles if the search bar is empty' do
create_list(:role, 5)

get :index, params: { search: '' }
expect(JSON.parse(response.body)['data'].pluck('id')).to match_array(Role.pluck(:id))
expect(response.parsed_body['data'].pluck('id')).to match_array(Role.pluck(:id))
end

it 'excludes roles with a different provider' do
Expand All @@ -62,7 +62,7 @@

get :index

expect(JSON.parse(response.body)['data'].pluck('id')).to match_array(greenlight_roles.pluck(:id))
expect(response.parsed_body['data'].pluck('id')).to match_array(greenlight_roles.pluck(:id))
end

context 'user with ManageUser permission' do
Expand All @@ -79,7 +79,7 @@

get :index
expect(response).to have_http_status(:ok)
expect(JSON.parse(response.body)['data'].pluck('id')).to match_array(roles.pluck(:id))
expect(response.parsed_body['data'].pluck('id')).to match_array(roles.pluck(:id))
end
end

Expand Down Expand Up @@ -108,14 +108,14 @@
expect(response).to have_http_status(:ok)
# Order is important match_array isn't adequate for this test.

expect(JSON.parse(response.body)['data'].pluck('name')).to eq(roles.sort.reverse)
expect(response.parsed_body['data'].pluck('name')).to eq(roles.sort.reverse)
end

it 'orders the roles list by column and direction ASC' do
get :index, params: { sort: { column: 'name', direction: 'ASC' } }
expect(response).to have_http_status(:ok)
# Order is important match_array isn't adequate for this test.
expect(JSON.parse(response.body)['data'].pluck('name')).to eq(roles.sort)
expect(response.parsed_body['data'].pluck('name')).to eq(roles.sort)
end
end
end
Expand All @@ -125,14 +125,14 @@
valid_params = { name: 'CrazyRole' }
expect { post :create, params: { role: valid_params } }.to change(Role, :count).by(1)
expect(response).to have_http_status(:created)
expect(JSON.parse(response.body)['errors']).to be_nil
expect(response.parsed_body['errors']).to be_nil
end

it 'returns :bad_request for invalid params' do
invalid_params = { name: '' }
post :create, params: { not_role: invalid_params }
expect(response).to have_http_status(:bad_request)
expect(JSON.parse(response.body)['errors']).not_to be_empty
expect(response.parsed_body['errors']).not_to be_empty
end

it 'calls create_role_permissions on role' do
Expand Down Expand Up @@ -161,7 +161,7 @@
post :update, params: { id: role.id, role: valid_params }
expect(role.reload.name).to eq(valid_params[:name])
expect(response).to have_http_status(:ok)
expect(JSON.parse(response.body)['errors']).to be_nil
expect(response.parsed_body['errors']).to be_nil
end

it 'returns :not_found for unfound roles' do
Expand All @@ -174,7 +174,7 @@
invalid_params = { name: '' }
post :update, params: { id: role.id, not_role: invalid_params }
expect(response).to have_http_status(:bad_request)
expect(JSON.parse(response.body)['errors']).not_to be_empty
expect(response.parsed_body['errors']).not_to be_empty
end

context 'user without ManageRoles permission' do
Expand All @@ -196,7 +196,7 @@
role = create(:role)
get :show, params: { id: role.id }
expect(response).to have_http_status(:ok)
expect(JSON.parse(response.body)['data']['id']).to eq(role.id)
expect(response.parsed_body['data']['id']).to eq(role.id)
end

it 'returns :not_found for unfound roles' do
Expand Down
14 changes: 7 additions & 7 deletions spec/controllers/admin/server_recordings_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@

get :index
expect(response).to have_http_status(:ok)
expect(JSON.parse(response.body)['data'].pluck('id')).to match_array(recordings.pluck(:id))
expect(response.parsed_body['data'].pluck('id')).to match_array(recordings.pluck(:id))
end

it 'returns the recordings according to the query' do
search_recordings = [create(:recording, name: 'Recording 1'), create(:recording, name: 'Recording 2'), create(:recording, name: 'Recording 3')]

get :index, params: { search: 'recording' }
expect(response).to have_http_status(:ok)
expect(JSON.parse(response.body)['data'].pluck('id')).to match_array(search_recordings.pluck(:id))
expect(response.parsed_body['data'].pluck('id')).to match_array(search_recordings.pluck(:id))
end

it 'returns all recordings if the search query is empty' do
recordings = create_list(:recording, 5)

get :index, params: { search: '' }
expect(response).to have_http_status(:ok)
expect(JSON.parse(response.body)['data'].pluck('id')).to match_array(recordings.pluck(:id))
expect(response.parsed_body['data'].pluck('id')).to match_array(recordings.pluck(:id))
end

it 'excludes rooms whose owners have a different provider' do
Expand All @@ -64,7 +64,7 @@

get :index

expect(JSON.parse(response.body)['data'].pluck('id')).to match_array(recs.pluck(:id))
expect(response.parsed_body['data'].pluck('id')).to match_array(recs.pluck(:id))
end

context 'SuperAdmin accessing recordings for provider other than current provider' do
Expand All @@ -79,7 +79,7 @@

get :index
expect(response).to have_http_status(:ok)
expect(JSON.parse(response.body)['data'].pluck('id')).to match_array(recordings.pluck(:id))
expect(response.parsed_body['data'].pluck('id')).to match_array(recordings.pluck(:id))
end
end

Expand All @@ -105,14 +105,14 @@
get :index, params: { sort: { column: 'name', direction: 'DESC' } }
expect(response).to have_http_status(:ok)
# Order is important match_array isn't adequate for this test.
expect(JSON.parse(response.body)['data'].pluck('name')).to eq(%w[P O O])
expect(response.parsed_body['data'].pluck('name')).to eq(%w[P O O])
end

it 'orders the recordings list by column and direction ASC' do
get :index, params: { sort: { column: 'name', direction: 'ASC' } }
expect(response).to have_http_status(:ok)
# Order is important match_array isn't adequate for this test.
expect(JSON.parse(response.body)['data'].pluck('name')).to eq(%w[O O P])
expect(response.parsed_body['data'].pluck('name')).to eq(%w[O O P])
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/admin/server_rooms_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
create_list(:room, 2, user_id: user_two.id)

get :index
expect(JSON.parse(response.body)['data'].pluck('friendly_id'))
expect(response.parsed_body['data'].pluck('friendly_id'))
.to match_array(Room.all.pluck(:friendly_id))
end

Expand All @@ -56,7 +56,7 @@
create_list(:room, 2, user_id: user_two.id)

get :index
expect(JSON.parse(response.body)['data'].pluck('friendly_id'))
expect(response.parsed_body['data'].pluck('friendly_id'))
.to match_array(Room.all.pluck(:friendly_id))
end
end
Expand All @@ -69,7 +69,7 @@
create_list(:room, 2, user: user2)

get :index
expect(JSON.parse(response.body)['data'].pluck('id')).to match_array(rooms.pluck(:id))
expect(response.parsed_body['data'].pluck('id')).to match_array(rooms.pluck(:id))
end

context 'user without ManageRooms permission' do
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/admin/site_settings_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
get :index, params: { names: %w[settingA settingB] }

expect(response).to have_http_status(:ok)
expect(JSON.parse(response.body)['data']).to eq({
'settingA' => 'valueA',
'settingB' => 'valueB'
})
expect(response.parsed_body['data']).to eq({
'settingA' => 'valueA',
'settingB' => 'valueB'
})
end

context 'user without ManageSiteSettings permission' do
Expand Down
Loading

0 comments on commit 16bf14f

Please sign in to comment.