Skip to content

Commit 4baf5f8

Browse files
committed
Let Room name be unique within each event
1 parent b961164 commit 4baf5f8

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

app/models/room.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class Room < ApplicationRecord
22
belongs_to :event
33
has_many :time_slots
44

5-
validates :name, uniqueness: true, presence: true
5+
validates :name, uniqueness: {scope: :event_id}, presence: true
66
scope :by_grid_position, -> {where.not(grid_position: nil).order(:grid_position)}
77
scope :grid_order, -> { order(:grid_position) }
88
end

spec/models/room_spec.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
describe Room do
44
describe "validations" do
5-
it "requires that names are unique" do
6-
room = create(:room, name: 'name')
7-
room2 = build(:room, name: room.name)
8-
5+
it "requires that names are unique within an event" do
6+
event1 = create(:event)
7+
room = create(:room, event: event1, name: 'name')
8+
room2 = build(:room, event: event1, name: room.name)
99
expect(room2).to be_invalid
10+
11+
event2 = create(:event)
12+
room3 = build(:room, event: event2, name: room.name)
13+
expect(room3).to be_valid
1014
end
1115
end
1216
end

0 commit comments

Comments
 (0)