Commit 1ea8b4a3

mo khan <mo@mokhan.ca>
2014-05-22 04:27:06
move settings to my/settings.
1 parent a1d8ec3
app/controllers/my/base_controller.rb
@@ -1,11 +1,5 @@
 module My
   class BaseController < ApplicationController
-    before_filter :restrict_access!
-
-    private
-
-    def restrict_access!
-      redirect_to root_path unless signed_in?
-    end
+    before_filter :authenticate_user!
   end
 end
app/controllers/my/settings_controller.rb
@@ -0,0 +1,23 @@
+module My
+  class SettingsController < BaseController
+    def index
+      @user = current_user
+    end
+
+    def update
+      @user = current_user
+      @user.interest_ids = params[:user][:interest_ids] ||= []
+      if @user.update_without_password(user_params)
+        redirect_to my_settings_path, :notice => t(:profile_saved)
+      else
+        render :index
+      end
+    end
+
+    private
+
+    def user_params
+      params.require(:user).permit(:name, :email, :city, :website, :twitter, :facebook)
+    end
+  end
+end
app/controllers/settings_controller.rb
@@ -1,23 +0,0 @@
-class SettingsController < ApplicationController
-  before_filter :authenticate_user!
-
-  def index
-    @user = current_user
-  end
-
-  def update
-    @user = current_user
-    @user.interest_ids = params[:user][:interest_ids] ||= []
-    if @user.update_without_password(user_params)
-      redirect_to settings_path, :notice => t(:profile_saved)
-    else
-      render :index
-    end
-  end
-
-  private
-
-  def user_params
-    params.require(:user).permit(:name, :email, :city, :website, :twitter, :facebook)
-  end
-end
app/views/settings/index.html.erb → app/views/my/settings/index.html.erb
@@ -10,7 +10,7 @@
 
 <div class="row">
   <div class="span12">
-    <%= form_for(@user, :url => setting_path(@user), :html => { :method => :put, :class => "form-horizontal" }) do |f| %>
+    <%= form_for(@user, :url => my_setting_path(@user), :html => { :method => :put, :class => "form-horizontal" }) do |f| %>
       <fieldset>
         <div class="control-group">
           <%= f.label :name, :class => "control-label"  %>
app/views/shared/_account_nav.html.erb
@@ -4,7 +4,7 @@
       <li class="<%= selected == :dashboard ? "active" : "" %>"><%= link_to "Dashboard", my_dashboard_path %></li>
       <li class="<%= selected == :creations ? "active" : "" %>"><%= link_to "Creations", my_cakes_path %></li>
       <li class="<%= selected == :favorites ? "active" : "" %>"><%= link_to "Favorites", my_favorites_path %></li>
-      <li class="<%= selected == :basic_info ? "active" : "" %>"><%= link_to "Settings", settings_path %></li>
+      <li class="<%= selected == :basic_info ? "active" : "" %>"><%= link_to "Settings", my_settings_path %></li>
       <li class="<%= selected == :password ? "active" : "" %>"><%= link_to "Password", pwd_path %></li>
       <li class="<%= selected == :picture ? "active" : "" %>"><%= link_to "Picture", edit_avatar_path(current_user) %></li>
       <li class="pull-right"><%= link_to t('.logout'), destroy_user_session_path, class: "btn btn-inverse" %></li>
config/routes.rb
@@ -43,7 +43,6 @@ Cake::Application.routes.draw do
   # sitemap
   get "/sitemap.xml", :to => "sitemap#index", :defaults => {:format => :xml}
 
-  resources :settings, :only => [:index, :update]
   resources :avatars, :only => [:edit, :update]
   get 'pwd' => "passwords#index"
   patch 'pwd' => "passwords#update"
@@ -70,5 +69,6 @@ Cake::Application.routes.draw do
     get 'dashboard', to: 'dashboard#index'
     resources :cakes, only: [:index]
     resources :favorites, only: [:index]
+    resources :settings, :only => [:index, :update]
   end
 end
spec/controllers/my/cakes_controller_spec.rb
@@ -27,7 +27,7 @@ describe My::CakesController do
   context "when not logged in" do
     it "redirects you to the home page" do
       get :index
-      response.should redirect_to(root_path)
+      response.should redirect_to(new_user_session_path)
     end
   end
 end
spec/controllers/settings_controller_spec.rb → spec/controllers/my/settings_controller_spec.rb
@@ -1,6 +1,6 @@
 require "spec_helper"
 
-describe SettingsController do
+describe My::SettingsController do
   describe :index do
     it "should load the current user" do
       user = create(:user)
@@ -29,7 +29,7 @@ describe SettingsController do
     end
 
     it "should redirect to the settings page" do
-      response.should redirect_to(settings_path)
+      response.should redirect_to(my_settings_path)
     end
 
     it "should include a success message" do
spec/features/change_password_spec.rb
@@ -11,7 +11,7 @@ describe "changing my password" do
         fill_in('user_password', :with => "password")
       end
       click_button("Sign In")
-      visit settings_path
+      visit my_settings_path
       click_link("Password")
       within(".form-horizontal") do
         fill_in('user_password', :with => "mopass")
spec/features/change_profile_settings_spec.rb
@@ -10,7 +10,7 @@ describe "Change settings" do
       fill_in('user_password', :with => "password")
     end
     click_button("Sign In")
-    visit settings_path
+    visit my_settings_path
     within(".form-horizontal") do
       fill_in('user_city', :with => "Calgary, Alberta, Canada")
       fill_in('user_website', :with => "http://mokhan.ca/")