jeudi 27 avril 2017

How to access a controller helper method from a helper test in Rails 4?

I've got a method defined in ApplicationController as a helper method.

helper_method :can_access_participant_contact_data?

I'm trying to write a test for a helper method that resides in a helper file. This helper method makes a call to 'helper_method :can_access_participant_contact_data?'

def redacted_contact_data participant, attribute_name
  attribute = participant.try(:contact_data).try(attribute_name)
  return attribute if can_access_participant_contact_data?(participant)
  return nil       if attribute.blank?
  return attribute.gsub(/\S/i, '*') # Asterisked string
end

When I run my test, I'm getting this message

undefined method `can_access_participant_contact_data?' for #<ParticipantsHelperTest:0x007fd6c7c6d608>

I've been having a look around but I'm not sure how to get around this issue. Do I need to mock the application controller method somehow? or can I just include the method into the test?

Aucun commentaire:

Enregistrer un commentaire