From 896c9f965e30a0c73708566aa77873ad17a86d40 Mon Sep 17 00:00:00 2001 From: Marcin Ciunelis Date: Tue, 27 Sep 2011 15:25:24 +0200 Subject: [PATCH] Time zone options added for user --- app/controllers/application_controller.rb | 6 +++++- app/models/user.rb | 1 + app/views/users/_fields.html.haml | 4 ++++ spec/controllers/users_controller_spec.rb | 14 ++++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9e3842f..6e7532c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,6 +2,7 @@ class ApplicationController < ActionController::Base protect_from_forgery before_filter :authenticate_user! + before_filter :set_time_zone # Devise override - After login, if there is only one app, # redirect to that app's path instead of the root path (apps#index). @@ -23,7 +24,10 @@ protected def redirect_to_root redirect_to(root_path) end - + + def set_time_zone + Time.zone = current_user.time_zone if user_signed_in? + end end diff --git a/app/models/user.rb b/app/models/user.rb index 5e40fce..eb0a84e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,6 +11,7 @@ class User field :name field :admin, :type => Boolean, :default => false field :per_page, :type => Fixnum, :default => PER_PAGE + field :time_zone, :default => "UTC" after_destroy :destroy_watchers before_save :ensure_authentication_token diff --git a/app/views/users/_fields.html.haml b/app/views/users/_fields.html.haml index 6e4069c..b11525b 100644 --- a/app/views/users/_fields.html.haml +++ b/app/views/users/_fields.html.haml @@ -18,6 +18,10 @@ = f.select :per_page, [10, 20, 30, 50, 75, 100] .required + = f.label :time_zone + = f.time_zone_select :time_zone, ActiveSupport::TimeZone.us_zones + +.required = f.label :password = f.password_field :password diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 1543af9..0c42106 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -16,6 +16,10 @@ describe UsersController do before do sign_in @user = Factory(:user) end + + it "should set a time zone" do + Time.zone.should.to_s == @user.time_zone + end context "GET /users/:other_id/edit" do it "redirects to the home page" do @@ -34,6 +38,11 @@ describe UsersController do get :edit, :id => @user.id response.body.should match(/id="user_per_page"/) end + + it "should have time_zone option" do + get :edit, :id => @user.id + response.body.should match(/id="user_time_zone"/) + end end context "PUT /users/:other_id" do @@ -64,6 +73,11 @@ describe UsersController do put :update, :id => @user.to_param, :user => {:per_page => 555} @user.reload.per_page.should == 555 end + + it "should be able to set time_zone option" do + put :update, :id => @user.to_param, :user => {:time_zone => "Warsaw"} + @user.reload.time_zone.should == "Warsaw" + end end context "when the update is unsuccessful" do -- libgit2 0.21.2