---
src/config/initializers/session_store.rb | 2 +-
src/public/javascripts/application.js | 7 +++++-
src/spec/requests/sessions_spec.rb | 37 ++++++++++++++++++++++++++++++
3 files changed, 44 insertions(+), 2 deletions(-)
create mode 100644 src/spec/requests/sessions_spec.rb
diff --git a/src/config/initializers/session_store.rb
b/src/config/initializers/session_store.rb
index 8ff62fa..5fd69a1 100644
--- a/src/config/initializers/session_store.rb
+++ b/src/config/initializers/session_store.rb
@@ -28,4 +28,4 @@ Conductor::Application.config.session = {
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rake db:sessions:create")
-Conductor::Application.config.session_store :active_record_store
+Conductor::Application.config.session_store :active_record_store, :expire_after =>
15.minutes
diff --git a/src/public/javascripts/application.js
b/src/public/javascripts/application.js
index 2162880..fa842b2 100644
--- a/src/public/javascripts/application.js
+++ b/src/public/javascripts/application.js
@@ -25,7 +25,12 @@ $.extend(Conductor, {
$('#tab').html(data).show();
})
.error(function(data) {
- $('#tab').html(data.responseText).show();
+ // If our session has timed out, redirect to the login page:
+ if(data.status == 401) {
+ window.location = Conductor.PATH_PREFIX + "login";
+ } else {
+ $('#tab').html(data.responseText).show();
+ }
});
Conductor.tabRemoveActiveClass();
diff --git a/src/spec/requests/sessions_spec.rb b/src/spec/requests/sessions_spec.rb
new file mode 100644
index 0000000..4bd4611
--- /dev/null
+++ b/src/spec/requests/sessions_spec.rb
@@ -0,0 +1,37 @@
+require 'spec_helper'
+
+describe "Sessions" do
+ describe "User not logged in" do
+
+ it "should not be authenticated" do
+ get pools_path
+ response.status.should be(302)
+ end
+ end
+
+ describe "User logged in" do
+ before do
+ @user = FactoryGirl.create :tuser
+ end
+
+ it "should be authenticated" do
+
+ visit root_path
+ fill_in "Username", :with => @user.login
+ fill_in "password-input", :with => "secret"
+ click_button "Login"
+ page.status_code.should be(200)
+ end
+
+ it "should have expired session" do
+ visit root_path
+ fill_in "Username", :with => @user.login
+ fill_in "password-input", :with => "secret"
+ click_button "Login"
+ visit pools_path
+ Timecop.travel(Time.now+16.minutes)
+ visit pools_path
+ page.body.should include "#login"
+ end
+ end
+end
--
1.7.10.4
Show replies by date