dev/mom0tomo

技術メモ

Active Decoratorメモ

読んだもの

qiita.com GitHub - amatsuda/active_decorator: ORM agnostic truly Object-Oriented view helper for Rails 3, 4 and 5

学んだこと

  • テストのとき、ちょっと変わった書き方をする。
    • →ActiveDecorator::Decorator.instance.decorate(model_instance)を呼び出す

モデルの例

module OrganizationDecorator
  def full_name
    "#{first_name} #{last_name}"
  end
end

テストの例

describe '#full_name' do
  it 'returns the full organization name' do
    organization = Organization.new(first_name: 'John', last_name: 'Doe')
    decorated_organization = ActiveDecorator::Decorator.instance.decorate(organization)

    expect(decorated_organization.full_name).to eq('John Doe')
  end
end

ADの機能は、Rails組み込みのものだと勘違いしていた。