1

我想对此方法进行单元测试,代码如下:

 def self.find_for_facebook_oauth(access_token, sign_in_resource=nil)
    data = access_token.extra.raw_info
    if !Authentication.where(:uid => access_token['uid']).empty?
      authentication = Authentication.find_by_uid(access_token['uid'])
      if !authentication.user.nil?
        user = authentication.user
        return user
      else
        # in case for some reason the authentication has no user
        raise "Something went wrong"
      end
    else
      user = User.new
      user.authentications.build(:provider => access_token['provider'], :uid => access_token['uid'], :token => access_token['credentials']['token'])
      user.save(:validate=>false)
      return user
    end
    return false
  end

怎么做?谢谢 :)

4

2 回答 2

4

答案在这个网站上

http://ashleshawrites.wordpress.com/2012/07/02/testing-omniauth-creating-mock-data/

干杯:) Tq

于 2012-07-26T03:02:22.480 回答
1

您可以使用 Omniauth-Facebook github 页面上的示例哈希来隔离测试: https ://github.com/mkdynamic/omniauth-facebook

向下滚动到“Auth Hash”以查找示例。那么这只是一个像平常一样测试的问题

于 2012-07-20T13:43:33.710 回答