Skip to content

Commit

Permalink
Let Room name be unique within each event
Browse files Browse the repository at this point in the history
  • Loading branch information
amatsuda committed Nov 14, 2024
1 parent b961164 commit 4baf5f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/models/room.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Room < ApplicationRecord
belongs_to :event
has_many :time_slots

validates :name, uniqueness: true, presence: true
validates :name, uniqueness: {scope: :event_id}, presence: true
scope :by_grid_position, -> {where.not(grid_position: nil).order(:grid_position)}
scope :grid_order, -> { order(:grid_position) }
end
Expand Down
12 changes: 8 additions & 4 deletions spec/models/room_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

describe Room do
describe "validations" do
it "requires that names are unique" do
room = create(:room, name: 'name')
room2 = build(:room, name: room.name)

it "requires that names are unique within an event" do
event1 = create(:event)
room = create(:room, event: event1, name: 'name')
room2 = build(:room, event: event1, name: room.name)
expect(room2).to be_invalid

event2 = create(:event)
room3 = build(:room, event: event2, name: room.name)
expect(room3).to be_valid
end
end
end

0 comments on commit 4baf5f8

Please sign in to comment.