---
# System prepended metadata

title: 未整理筆記
tags: [未整理]

---

---
title: 未整理筆記
description: 有空整理一下辣
robots: noindex, nofollow
lang: zh-tw
dir: ltr
breaks: true
tags: 未整理
disqus: hackmd
---

# 未整理筆記

# Rails
## 序列化
https://buttercms.com/blog/json-serialization-in-rails-a-complete-guide

## ActiveStorage
https://5xruby.tw/posts/active-storage-review

## shoulda matcher

shoulda 測試關聯可以這樣寫
```ruby=
describe DatabaseModels::Response, type: :model do
  it { is_expected.to have_many(:question_responses) }
end
```
測試關聯原始碼像是以下使用了`reflect_on_association`以及`macro`
```ruby=
describe DatabaseModels::Response, type: :model do
  it 'has many question responses' do
    relation = described_class.reflect_on_association(:question_resp‌​onses)
    expect(relation.macro).to eq :has_many
  end
end
```

[model測試](https://xdite.gitbooks.io/rspec-101/content/contents/model/)

## Rspec - describe vs context

兩者並無太大區分基本上功能相同只是在讀的時候不一樣

[可以看看這篇](https://gist.github.com/kyuden/8889700)

>According to the rspec source code, “context” is just a alias method of “describe”, meaning that there is no functional difference between these two methods. However, there is a contextual difference that’ll help to make your tests more understandable by using both of them.
The purpose of “describe” is to wrap a set of tests against one functionality while “context” is to wrap a set of tests against one functionality under the same state. Here’s an example