Commit 1ea8b4a3
Changed files (10)
app
controllers
views
my
settings
shared
config
spec
controllers
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" %>
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/")