Skip to content

Commit

Permalink
Remove stubbed OpenID specs. They are far too brittle. Add a note to
Browse files Browse the repository at this point in the history
write an integration test instead.
  • Loading branch information
xaviershay committed Dec 3, 2010
1 parent ec4a1b9 commit 8f9e5c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 127 deletions.
19 changes: 10 additions & 9 deletions app/controllers/comments_controller.rb
Expand Up @@ -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
Expand All @@ -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

Expand Down
118 changes: 0 additions & 118 deletions spec/controllers/comments_controller_spec.rb
Expand Up @@ -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!
Expand Down

0 comments on commit 8f9e5c4

Please sign in to comment.