For the following example we’re gonna use RSpec for the concise syntax for test doubles.

    The remaining code is about permissions related logic: the edit link must be rendered only if the current user is an admin. This is tested by looking at the output of the template.

    Notice that exposures includes an unused params key. While this is not strictly required, we recommend providing it since it’s expected by some standard view helpers (e.g. form helpers).

    1. module Web
    2. module Views
    3. module Books
    4. class Show
    5. include Web::View
    6. def formatted_price
    7. end
    8. def edit_link
    9. if can_edit_book?
    10. link_to "Edit", routes.edit_book_path(id: book.id)
    11. end
    12. private
    13. def can_edit_book?
    14. current_user.admin?
    15. end
    16. end
    17. end
    18. end