2011-09-01 12 views
11

ट्विटर के लिए प्रमाणीकरण बनाने के लिए मैंने omniauth की रेल कलाकारों का पालन किया (http://railscasts.com/episodes/235-omniauth-part-1?view=comments)। यह विकास में ठीक काम करता है लेकिन मुझे पता लगाने के लिए rspec नहीं मिल सकता है कि मैंने प्रमाणीकरण बनाया है।Omniauth Rspec परीक्षण समस्या

def create 
    begin 

    auth_hash = request.env["omniauth.auth"] 
    @auth = current_user.authentications.build(:provider  => auth_hash['provider'], 
               :uid   => auth_hash['uid'], 
               :name   => auth_hash['user_info']['name'], 
               :nickname  => auth_hash['user_info']['nickname'], 
               :image  => auth_hash['user_info']['image'] 
              ) 

    if @auth.provider.downcase == "twitter" 
     @auth.auth_token  = auth_hash['credentials']['token'] 
     @auth.secret_token = auth_hash['credentials']['secret'] 
     @auth.site   = auth_hash['user_info']['urls']['Twitter'] 
    elsif @auth.provider == "Facebook" 

    end 

    rescue 
    redirect_to current_user, :flash => { :error => "Missing oauth data!! Check with administrator!"} 
    else 
    if @auth.save 
     msg = "Authentication success" 
    else 
     msg = "Already have authentication" 
    end 
    redirect_to current_user, :notice => msg 
    end 
end 

मेरी मार्गों में शामिल:

match '/auth/:provider/callback' => 'authentications#create' 

मैं है मेरी rspec_helper में निम्नलिखित स्थापना: यहाँ मेरी टुकड़ा मेरी प्रमाणीकरण नियंत्रक में समारोह बनाने के लिए है

OmniAuth.config.test_mode = true 
OmniAuth.config.add_mock(:twitter, { :provider => "twitter", 
            :uid   => "1234", 
            :user_info => { :name  => "Bob hope", 
                 :nickname => "bobby", 
                 :urls  => {:Twitter => "www.twitter.com/bobster"}}, 
            :credentials => { :auth_token => "lk2j3lkjasldkjflk3ljsdf"} }) 

यहाँ है मेरी आरएसपीईसी कोड जो काम नहीं कर रहा है:

describe "Post 'create'" do 
    before(:each) do 
     @user = Factory(:user) 
     sign_in @user 
    end 

    describe "success" do 
     before(:each) do 
     request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:twitter] 
     end 


     it "should create authentication" do 
     lambda do 
      post :create, :provider => "twitter" 
      response.should redirect_to(@user) 
     end.should change(Authentication, :count).by(1) 
     end 
    end 
    end 

त्रुटि मैं मिलता है:

1) AuthenticationsController पोस्ट 'बनाने' सफलता बनाना चाहिए प्रमाणीकरण विफलता/त्रुटि: लैम्ब्डा गिनती 1 से बदला है चाहिए है, लेकिन 0 # ./spec/controllers द्वारा बदल दिया गया था /authentications_controller_spec.rb:57

मैंने सब कुछ जांच लिया है और यह नहीं समझ सकता कि मैं क्या गलत कर रहा हूं। क्या कोई मदद कर सकता है?

उत्तर

3

मुझे अंत में पता चला कि क्या गलत था। मेरे नकली में: auth_token होने का अनुमान है: टोकन। यह असफल सत्यापन का कारण बन रहा था।

0

क्या यह अनुरोध प्राप्त नहीं होना चाहिए?

describe "success" do 
    before(:each) do 
    request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:twitter] 
    end 


    it "should create authentication" do 
    lambda do 
     get :create, :provider => "twitter" 
     response.should redirect_to(@user) 
    end.should change(Authentication, :count).by(1) 
    end 
end 
+1

यकीन है कि यह एक पोस्ट अनुरोध है। इसके अलावा मैंने कोशिश की और यह भी काम नहीं करता है। – Whereisccguys

संबंधित मुद्दे