Skip to content

Make Room a model#546

Open
D0gmaDev wants to merge 5 commits intomasterfrom
feat/rooms-model
Open

Make Room a model#546
D0gmaDev wants to merge 5 commits intomasterfrom
feat/rooms-model

Conversation

@D0gmaDev
Copy link
Copy Markdown
Member

@D0gmaDev D0gmaDev commented Mar 8, 2026

Closes #544

@D0gmaDev D0gmaDev requested a review from nymous March 8, 2026 22:05
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 8, 2026

Codecov Report

❌ Patch coverage is 99.24242% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.92%. Comparing base (0fb0a46) to head (80f0eb1).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
app/models/user.rb 85.71% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##            master     #546      +/-   ##
===========================================
- Coverage   100.00%   99.92%   -0.08%     
===========================================
  Files          112      118       +6     
  Lines         2498     2716     +218     
  Branches        82       99      +17     
===========================================
+ Hits          2498     2714     +216     
- Misses           0        2       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@D0gmaDev D0gmaDev requested a review from tekvalir March 27, 2026 20:56
Comment thread app/models/room.rb

validates :number, presence: true, uniqueness: true, length: { maximum: 6 },
format: { with: /\A[A-Z0-9]+\z/, message: 'must be uppercase alphanumeric' }
validates :group, presence: true, length: { maximum: 6 },
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a comment/example to understand what a "group" is?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before I write it in the code, what do you think about:

  • A room group represents the natural grouping of rooms. It can be the room number itself or a shared identifier

Comment thread app/models/room.rb
format: { with: /\A[A-Z0-9]+\z/, message: 'must be uppercase alphanumeric' }
validates :group, presence: true, length: { maximum: 6 },
format: { with: /\A[A-Z0-9]+\z/, message: 'must be uppercase alphanumeric' }
validates :building, presence: true, inclusion: { in: ('A'..'F').to_a }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "Foyer" in the F building? Accueil or Halle projet rooms in A?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answered by the seed

Comment thread app/models/room.rb Outdated
# frozen_string_literal: true

class Room < ApplicationRecord
has_one :user, foreign_key: :room, primary_key: :number, dependent: :restrict_with_error, inverse_of: :room_record
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still unsure about using a non-fixed column as a foreign key, all to avoid one join...

If we use the standard primary key, what do you think of reversing the has_one/belong_to association? Like we do with IPs, it would make finding free rooms easier.

Comment thread app/models/user.rb Outdated
Comment on lines +32 to +33
validates :room, uniqueness: true, allow_nil: true
validate :room_must_exist, if: -> { room.present? }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the primary key would also drop all this validation code

Comment thread app/services/sso_metadata_service.rb Outdated
Comment on lines +35 to +36
ensure
Rails.logger = old_logger
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread test/models/user_test.rb Outdated
Comment on lines +105 to +107
test 'changing room enqueues room sync job' do
assert_enqueued_with(job: SyncRoomToSsoJob, args: [@user.id]) do
@user.update!(room: rooms(:room_b231).number)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️


test 'sync_room skips user without oidc_id' do
@user.oidc_id = nil
assert_nothing_raised do
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, you can remove the assert_nothing_raised (and add tests that check the actual behavior of the method if you want/can)

)
.to_return(status: 200, body: '{"setDate":"2026-01-01T00:00:00Z"}')

ProductionSsoService.new.sync_room(@user)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option to test with production? => true could be with a MiniTest stub:

require 'minitest/mock'

Rails.env.stub(:production?, true) do
  SsoMetadataService.sync_room(@user)
end

(But the mock functionality has been extracted from MiniTest 6.0 because they don't want to maintain it anymore, maybe the simple inheritance is OK)

assert_requested(stub)
end

test 'sync_room does not raise on POST HTTP failure' do
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, we really want to have silent errors?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make Room a model

2 participants