Commit 896c9f965e30a0c73708566aa77873ad17a86d40
1 parent
fb03e5a1
Exists in
master
and in
1 other branch
Time zone options added for user
Showing
4 changed files
with
24 additions
and
1 deletions
Show diff stats
app/controllers/application_controller.rb
| ... | ... | @@ -2,6 +2,7 @@ class ApplicationController < ActionController::Base |
| 2 | 2 | protect_from_forgery |
| 3 | 3 | |
| 4 | 4 | before_filter :authenticate_user! |
| 5 | + before_filter :set_time_zone | |
| 5 | 6 | |
| 6 | 7 | # Devise override - After login, if there is only one app, |
| 7 | 8 | # redirect to that app's path instead of the root path (apps#index). |
| ... | ... | @@ -23,7 +24,10 @@ protected |
| 23 | 24 | def redirect_to_root |
| 24 | 25 | redirect_to(root_path) |
| 25 | 26 | end |
| 26 | - | |
| 27 | + | |
| 28 | + def set_time_zone | |
| 29 | + Time.zone = current_user.time_zone if user_signed_in? | |
| 30 | + end | |
| 27 | 31 | |
| 28 | 32 | end |
| 29 | 33 | ... | ... |
app/models/user.rb
| ... | ... | @@ -11,6 +11,7 @@ class User |
| 11 | 11 | field :name |
| 12 | 12 | field :admin, :type => Boolean, :default => false |
| 13 | 13 | field :per_page, :type => Fixnum, :default => PER_PAGE |
| 14 | + field :time_zone, :default => "UTC" | |
| 14 | 15 | |
| 15 | 16 | after_destroy :destroy_watchers |
| 16 | 17 | before_save :ensure_authentication_token | ... | ... |
app/views/users/_fields.html.haml
spec/controllers/users_controller_spec.rb
| ... | ... | @@ -16,6 +16,10 @@ describe UsersController do |
| 16 | 16 | before do |
| 17 | 17 | sign_in @user = Factory(:user) |
| 18 | 18 | end |
| 19 | + | |
| 20 | + it "should set a time zone" do | |
| 21 | + Time.zone.should.to_s == @user.time_zone | |
| 22 | + end | |
| 19 | 23 | |
| 20 | 24 | context "GET /users/:other_id/edit" do |
| 21 | 25 | it "redirects to the home page" do |
| ... | ... | @@ -34,6 +38,11 @@ describe UsersController do |
| 34 | 38 | get :edit, :id => @user.id |
| 35 | 39 | response.body.should match(/id="user_per_page"/) |
| 36 | 40 | end |
| 41 | + | |
| 42 | + it "should have time_zone option" do | |
| 43 | + get :edit, :id => @user.id | |
| 44 | + response.body.should match(/id="user_time_zone"/) | |
| 45 | + end | |
| 37 | 46 | end |
| 38 | 47 | |
| 39 | 48 | context "PUT /users/:other_id" do |
| ... | ... | @@ -64,6 +73,11 @@ describe UsersController do |
| 64 | 73 | put :update, :id => @user.to_param, :user => {:per_page => 555} |
| 65 | 74 | @user.reload.per_page.should == 555 |
| 66 | 75 | end |
| 76 | + | |
| 77 | + it "should be able to set time_zone option" do | |
| 78 | + put :update, :id => @user.to_param, :user => {:time_zone => "Warsaw"} | |
| 79 | + @user.reload.time_zone.should == "Warsaw" | |
| 80 | + end | |
| 67 | 81 | end |
| 68 | 82 | |
| 69 | 83 | context "when the update is unsuccessful" do | ... | ... |