Skip to content

Commit

Permalink
style: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-brousse committed Oct 18, 2023
1 parent f1aacca commit 58f9cae
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class User < ApplicationRecord
include PublicActivity::Model
tracked owner: ->(controller, model) { controller && controller.current_user }

validates_presence_of :email
validates_format_of :email, with: URI::MailTo::EMAIL_REGEXP
validates :email, presence: true
validates :email, format: { with: URI::MailTo::EMAIL_REGEXP }

enum role: [:user, :vip, :admin]
after_initialize :set_default_role, :if => :new_record?
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
host: Rails.application.credentials.dig(:oidc, :server_host),
identifier: Rails.application.credentials.dig(:oidc, :client_id),
secret: Rails.application.credentials.dig(:oidc, :secret_key),
redirect_uri: "https://#{Rails.application.secrets.domain_name}/users/auth/openid_connect/callback",
redirect_uri: "https://#{Rails.application.secrets.domain_name}/users/auth/openid_connect/callback"
}
}

Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20170727132107_create_enclosures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ def change
t.timestamps
end
add_column :composants, :enclosure_id, :integer
Modele.all.each do |modele|
Modele.all.find_each do |modele|
enclosure = Enclosure.new(position:1)
modele.enclosures = [enclosure]
modele.save
Composant.where(:modele_id => modele.id).all.each do |composant|
Composant.where(:modele_id => modele.id).all.find_each do |composant|
composant.enclosure_id = enclosure.id
composant.save
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class InitCablesFromCurrentPorts < ActiveRecord::Migration[5.0]
def up
Port.all.each do |port|
Port.all.find_each do |port|
cable = Cable.create(name: port.cablename, color: port.color)
Connection.create(port: port, cable: cable)
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20180110152701_add_attributes_to_servers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def init_pdus_for_every_frames
port_type: port_type)
puts "ERROR: #{card_type}" unless card_type.valid?

Frame.all.each do |frame|
Frame.all.find_each do |frame|
['A','B'].each do |line_name|
pdu_name = "PDU_#{frame}_#{line_name}"
pdu = Server.create(frame: frame,
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/fix_duplicated_slots.rake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace :duplicated_slots do
task :fix => :environment do

Modele.includes(:enclosures => :composants)
.each do |modele|
.find_each do |modele|

servers = []
modele.enclosures.each do |enclosure|
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/init_pdus.rake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace :init_pdus do

# TODO: Refactor if we want to use it
#
Port.where("cablename ~ 'L....'").each do |port|
Port.where("cablename ~ 'L....'").find_each do |port|
puts "Cable #{port.cablename}"
line = port.cablename[2]
group = port.cablename[1]
Expand Down
11 changes: 6 additions & 5 deletions spec/controllers/users/omniauth_callbacks_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Users::OmniauthCallbacksController, type: :controller do
describe '#openid_connect' do

before {
before do
@user = User.find_or_create_by(email: '[email protected]')
puts @user.inspect
}
end

it 'creates a new user with valid authentication' do
request.env['devise.mapping'] = Devise.mappings[:user]
Expand All @@ -24,9 +25,9 @@
request.env['devise.mapping'] = Devise.mappings[:user]
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect_unknown_user]

expect {
expect do
get :openid_connect
}.not_to change(User, :count)
end.not_to change(User, :count)

expect(controller.current_user).to be_nil
end
Expand Down
10 changes: 6 additions & 4 deletions spec/support/omniauth.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# frozen_string_literal: true

OmniAuth.config.test_mode = true

OmniAuth.config.mock_auth[:openid_connect] = OmniAuth::AuthHash.new(
provider: :openid_connect,
uid: 'user_unique_id',
info: {
email: '[email protected]',
name: 'John Doe',
name: 'John Doe'
# Add other user information as needed for your tests
},
credentials: {
token: 'valid_access_token',
expires_at: Time.now + 1.hour
expires_at: Time.zone.now + 1.hour
}
)

Expand All @@ -21,10 +23,10 @@
uid: 'user_unique_id',
info: {
email: '[email protected]',
name: 'Unknown User',
name: 'Unknown User'
},
credentials: {
token: 'valid_access_token',
expires_at: Time.now + 1.hour
expires_at: Time.zone.now + 1.hour
}
)
2 changes: 1 addition & 1 deletion test/services/omniauth_dynamic_full_host_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def setup

def test_full_host_without_specific_origin
@strategy.call!(make_env('/whatever', 'rack.url_scheme' => 'http', 'SERVER_NAME' => 'facebook.lame',
'QUERY_STRING' => 'code=asofibasf|asoidnasd', 'SCRIPT_NAME' => '', 'SERVER_PORT' => 80))
'QUERY_STRING' => 'code=asofibasf|asoidnasd', 'SCRIPT_NAME' => '', 'SERVER_PORT' => 80))
assert @strategy.full_host, 'http://example.com'
end

Expand Down

0 comments on commit 58f9cae

Please sign in to comment.