Skip to content
Browse files

Added some tests, but still need to work out session details. Docs su…

…ggest testing a high level with capybara vs. individual route tests.
  • Loading branch information...
1 parent 3726470 commit 40fa12bf386a0320bf6f2a9cb6f2c2c12ba3f985 @brandonhilkert committed
View
6 app/helpers/user_helpers.rb
@@ -9,7 +9,11 @@ def current_user
end
def sign_in(user)
- session[:user_id] = user.id
+ session[:user_id] = user.id.to_s
+ end
+
+ def sign_out
+ session[:user_id] = nil
end
end
View
2 app/routes/sessions.rb
@@ -22,7 +22,7 @@ class Five
get '/logout' do
- session[:user_id] = nil
+ sign_out
redirect '/'
end
end
View
11 spec/routes/errors_spec.rb
@@ -0,0 +1,11 @@
+require_relative File.join('..', 'spec_helper')
+
+describe Five do
+ # describe "GET /asdf/asdfasdf" do
+ # it "should include error text" do
+ # get '/asdf/asdfasdf'
+ # puts last_response.body
+ # last_response.body.should include?("We can't find what you are looking for.")
+ # end
+ # end
+end
View
2 spec/routes/root_spec.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+require_relative File.join('..', 'spec_helper')
describe Five do
it "should load successfully" do
View
68 spec/routes/sessions_spec.rb
@@ -0,0 +1,68 @@
+require_relative File.join('..', 'spec_helper')
+
+describe Five do
+ include Five::UserHelpers
+
+ describe "GET /login" do
+ it "should redirect" do
+ get '/login'
+ last_response.should be_redirect
+ end
+ end
+
+ describe "GET /callback" do
+ let(:access_token) { mock('AccessToken', token: "token", secret: "secret") }
+
+ before(:each) do
+ OAuth::RequestToken.any_instance.stub(get_access_token: access_token )
+ end
+
+ # it "should set session[:access_token]" do
+ # get '/callback'
+ # puts "rack.session".inspect
+ # session[:access_token].should == "token"
+ # end
+
+ # it "should set session[:access_secret]" do
+ # get '/callback'
+ # "rack.session"[:session][:access_token].should == "secret"
+ # end
+
+ it "should redirect" do
+ get '/callback'
+ last_response.should be_redirect
+ end
+ end
+
+ describe "GET /process" do
+ let (:user) { }
+
+ before(:each) do
+ User.stub(:process_login).and_return(user)
+
+ end
+
+ # it "should sign the user in" do
+ # get '/process'
+ # signed_in?.should be_true
+ # end
+
+ # it "should redirect to user's page" do
+ # get '/process'
+ # last_response.location.should == 'http://example.org/brandonhilkert'
+ # end
+ end
+
+ describe "GET /logout" do
+ # it "should set user session to nil" do
+ # get '/logout'
+ # signed_in?.should be_false
+ # end
+
+ it "should redirect" do
+ get '/logout'
+ last_response.location.should == 'http://example.org/'
+ end
+ end
+
+end
View
2 spec/spec_helper.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), '..', 'five.rb')
+require_relative File.join('..', 'five.rb')
require 'rack/test'
require 'rspec'

0 comments on commit 40fa12b

Please sign in to comment.
Something went wrong with that request. Please try again.