From 8f9e5c4d6fa3c3b57b34b84d7d11c7f9e2fec5d2 Mon Sep 17 00:00:00 2001 From: Xavier Shay Date: Fri, 3 Dec 2010 14:54:29 +1100 Subject: [PATCH] Remove stubbed OpenID specs. They are far too brittle. Add a note to write an integration test instead. --- app/controllers/comments_controller.rb | 19 +-- spec/controllers/comments_controller_spec.rb | 118 ------------------- 2 files changed, 10 insertions(+), 127 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 579e7d61b..a63e00e2f 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -25,15 +25,14 @@ def new end end + # TODO: Spec OpenID with cucumber and rack-my-id def create @comment = Comment.new((session[:pending_comment] || params[:comment] || {}).reject {|key, value| !Comment.protected_attribute?(key) }) @comment.post = @post session[:pending_comment] = nil - unless @comment.requires_openid_authentication? - @comment.blank_openid_fields - else + if @comment.requires_openid_authentication? session[:pending_comment] = params[:comment] authenticate_with_open_id(@comment.author, :optional => [:nickname, :fullname, :email]) do |result, identity_url, registration| if result.status == :successful @@ -49,14 +48,16 @@ def create @comment.openid_error = OPEN_ID_ERRORS[ result.status ] end end - - return if response.headers[Rack::OpenID::AUTHENTICATE_HEADER] + else + @comment.blank_openid_fields end - if @comment.save - redirect_to post_path(@post) - else - render :template => 'posts/show' + unless response.headers[Rack::OpenID::AUTHENTICATE_HEADER] # OpenID gem already provided a response + if @comment.save + redirect_to post_path(@post) + else + render :template => 'posts/show' + end end end diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 553338998..e3dbfd8be 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -61,124 +61,6 @@ def mock_post! @mock_post end - def stub_open_id_authenticate(url, status_code, return_value) - status = mock("Result", :status => status_code, :server_url => 'http://example.com') - registration = { - "fullname" => "Don Alias", - "email" => "donalias@enkiblog.com" - } - @controller.stub!(:authenticate_with_open_id).and_yield(status,url, registration).and_return(return_value) - end - - describe 'with a POST to #index requiring OpenID authentication' do - before do - mock_post! - - @comment = { - 'author' => 'http://enkiblog.com', - 'body' => 'This is a comment' - } - - @controller.stub!(:authenticate_with_open_id).and_return(nil) - end - - def do_post - post :index, :year => '2007', :month => '01', :day => '01', :slug => 'a-post', :comment => @comment - end - - it 'stores a pending comment' do - do_post - session[:pending_comment].should == @comment - end - - it 'redirects to OpenID authority' do - @controller.should_receive(:authenticate_with_open_id).and_return(nil) - do_post - end - end - - describe 'with a POST to #index requiring OpenID authentication but unavailable server' do - before do - mock_post! - - stub_open_id_authenticate('http://enkiblog.com', :missing, false) - post :index, :year => '2007', :month => '01', :day => '01', :slug => 'a-post', :comment => { - 'author' => 'http://enkiblog.com', - 'body' => 'This is a comment' - } - end - - it_should_behave_like("invalid comment") - - it 'sets an appropriate error message on the comment' do - assigns(:comment).openid_error.should == "Sorry, the OpenID server couldn't be found" - end - end - - describe CommentsController, 'with a canceled OpenID completion GET to #index' do - before do - mock_post! - - stub_open_id_authenticate('http://enkiblog.com', :canceled, false) - post :index, :year => '2007', :month => '01', :day => '01', :slug => 'a-post', :comment => { - 'author' => 'http://enkiblog.com', - 'body' => 'This is a comment' - } - end - - it_should_behave_like("invalid comment") - - it 'sets an appropriate error message on the comment' do - assigns(:comment).openid_error.should == "OpenID verification was canceled" - end - end - - describe CommentsController, 'with a failed OpenID completion GET to #index' do - before do - mock_post! - - stub_open_id_authenticate('http://enkiblog.com', :failed, false) - post :index, :year => '2007', :month => '01', :day => '01', :slug => 'a-post', :comment => { - 'author' => 'http://enkiblog.com', - 'body' => 'This is a comment' - } - end - - it_should_behave_like("invalid comment") - - it 'sets an appropriate error message on the comment' do - assigns(:comment).openid_error.should == "Sorry, the OpenID verification failed" - end - end - - describe 'with a successful OpenID completion GET to #index' do - before do - mock_post! - - session[:pending_comment] = { - :author => 'http://enkiblog.com', - :body => 'This is a comment' - } - - stub_open_id_authenticate('http://enkiblog.com', :successful, false) - post :index, :year => '2007', :month => '01', :day => '01', :slug => 'a-post' - end - - it_should_behave_like("creating new comment") - - it 'records OpenID identity url' do - assigns(:comment).author_url.should == 'http://enkiblog.com' - end - - it 'uses full name as author' do - assigns(:comment).author.should == 'Don Alias' - end - - it 'records email' do - assigns(:comment).author_email.should == 'donalias@enkiblog.com' - end - end - describe "with a POST to #index (non-OpenID comment)" do before(:each) do mock_post!