---
title: "علاقة اختيارية + RSpec مع shoulda-matchers"
description: "User 1 - 0..1 Laptop"
canonical: https://oozou.com/til/optional-relation-rspec-w-shoulda-matchers-41
locale: ar
date: 2020-10-13
topic: ruby
---

# علاقة اختيارية + RSpec مع shoulda-matchers

> User 1 - 0..1 Laptop

Published: 2020-10-13 · Topic: [ruby](https://oozou.com/ar/til-topics/ruby) ([markdown](https://oozou.com/ar/til-topics/ruby.md))

*User 1 - 0..1 Laptop*

- النموذج (Model)
  ```ruby
  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 }*

---

Contact OOZOU: hello@oozou.com · +66 2544 0000 · https://oozou.com/ar/contact

More for AI agents: https://oozou.com/llms.txt · every page has a markdown twin at its URL plus ".md"
