Skip to content

Commit

Permalink
Merge pull request #34 from mscottford/filter_unauthorized_to_sym_fix
Browse files Browse the repository at this point in the history
Prevents to_sym getting called on nil from within Filter#unauthorized!
  • Loading branch information
soupmatt committed Feb 12, 2012
2 parents dd9860f + 67c9609 commit d7b83db
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/casclient/frameworks/rails/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ def logout(controller, service = nil)
end

def unauthorized!(controller, vr = nil)
format = controller.request.format.to_sym
format = nil
unless controller.request.format.nil?
format = controller.request.format.to_sym
end
format = (format == :js ? :json : format)
case format
when :xml, :json
Expand Down
17 changes: 17 additions & 0 deletions spec/casclient/frameworks/rails/filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,21 @@ def mock_post_request
end
end
end

context "controller request is missing format" do
context "#unauthorized!" do
it 'should not crash' do
request = double('mock request')
request.stub(:format).and_return(nil)

controller = controller_with_session(request)

CASClient::Frameworks::Rails::Filter.
should_receive(:redirect_to_cas_for_authentication).
with(controller)

CASClient::Frameworks::Rails::Filter.unauthorized!(controller)
end
end
end
end

0 comments on commit d7b83db

Please sign in to comment.