Sorry, this entry is only available in 日本語.
Tag Archives: Helper
RSpec: Test Helper Method using current_user function
I’ll introduce the way to test rails helper code that uses current_user
method provided by device gem.
Environment
- Ruby 2.2.2
- Rails 4.1.8
- RSpec 3.1.0
Test Target
The function we are going to test is below. It compare the return value of current_user
method and user_id
given as argument, and check the argument user_id
is of current login user or not.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
module ExampleHelper # check if the id is of current user # ==== Parameter # * +user_id+ # ==== Return # Boolean def is_current_user?(user_id) if current_user && current_user.id == user_id return true end return false end end |