optional relation + RSpec กับ shoulda-matchers
13 ตุลาคม 2563
User 1 - 0..1 Laptop
- Model
a/m/user.rb has\_one :laptop
a/m/laptop.rb belongs_to :user, optional: true
- spec
*ruby
s/m/laptop\_spec.rb
it \{ should belong\_to(:user).optional }*
User 1 - 0..1 Laptop
a/m/user.rb
has\_one :laptop
a/m/laptop.rb belongs_to :user, optional: true
- spec
*ruby
s/m/laptop\_spec.rb
it \{ should belong\_to(:user).optional }*
ตอนนี้เราใช้ leading dot notation กันบ่อยมาก เช่น
บางครั้งคุณอาจอยากใช้ Heredoc ของ Ruby แบบไม่มี interpolation ('#{....}') ซึ่งทำได้โดยใส่ dash เดี่ยวรอบ keyword ของคุณ:
hashtable ระดับกลางทั้งหมดจะถูกสร้างขึ้นให้เองโดยอัตโนมัติ