1
我應該如何去測試這個幫助器與RSpec?測試幫助器方法w/RSpec
module ApplicationHelper
def build_rpx_url(provider)
signin_url(provider) << "?token_url=" << token_url << provider_params(provider)
end
private
def signin_url(provider)
case provider.downcase
when 'facebook'; 'https://login.xyz.net/facebook/connect_start'
when 'google'; 'https://login.xyz.net/openid/start'
when 'twitter'; 'https://login.xyz.net/twitter/start'
when 'linkedin'; 'https://login.xyz.net/linkedin/start'
when 'yahoo'; 'https://login.xyz.net/openid/start'
end
end
def provider_params(provider)
params = case provider.downcase
when 'facebook'; ["ext_perm=publish_stream,email,offline_access"]
when 'google'; ["openid_identifier=https://www.google.com/accounts/o8/id"]
when 'twitter'; []
when 'linkedin'; []
when 'yahoo'; ["openid_identifier=http://me.yahoo.com/"]
end
params.empty? ? '' : "&" << params.join('&')
end
def token_url
"#{new_user_session_url}?authenticity_token=#{Rack::Utils.escape(form_authenticity_token)}"
end
end