Commit e49bef1d
Changed files (7)
app
controllers
views
my
avatars
shared
config
spec
controllers
features
app/controllers/my/avatars_controller.rb
@@ -0,0 +1,24 @@
+module My
+ class AvatarsController < BaseController
+ before_filter :find_or_build_avatar
+
+ def edit
+ end
+
+ def update
+ @avatar.attach(params[:avatar][:avatar])
+ redirect_to edit_my_avatar_path(current_user), :notice => t(:avatar_uploaded)
+ end
+
+ protected
+
+ def find_or_build_avatar
+ if current_user.avatar == nil
+ @avatar = current_user.avatar = Avatar.new
+ current_user.save
+ else
+ @avatar = current_user.avatar
+ end
+ end
+ end
+end
app/controllers/avatars_controller.rb
@@ -1,23 +0,0 @@
-class AvatarsController < ApplicationController
- before_filter :authenticate_user!
- before_filter :find_or_build_avatar
-
- def edit
- end
-
- def update
- @avatar.attach(params[:avatar][:avatar])
- redirect_to edit_avatar_path(current_user), :notice => t(:avatar_uploaded)
- end
-
- protected
-
- def find_or_build_avatar
- if current_user.avatar == nil
- @avatar = current_user.avatar = Avatar.new
- current_user.save
- else
- @avatar = current_user.avatar
- end
- end
-end
app/views/avatars/edit.html.erb → app/views/my/avatars/edit.html.erb
@@ -8,7 +8,7 @@ try { mixpanel.track_forms(".edit_avatar", "uploaded avatar"); } catch {}
<div class="row">
<div class="span12">
<%= avatar_for(current_user) %>
- <%= form_for(@avatar, :url => avatar_path(@avatar), :method => :put, :multipart => true, remote: true, authenticity_token: true) do |f| %>
+ <%= form_for(@avatar, :url => my_avatar_path(@avatar), :method => :put, :multipart => true, remote: true, authenticity_token: true) do |f| %>
<div class="control-group">
<div class="controls">
<%= f.file_field :avatar %>
config/routes.rb
@@ -1,5 +1,4 @@
Cake::Application.routes.draw do
- # /home
get "about_us" => "home#about_us"
get "why_cakeside" => "home#why_cakeside"
@@ -18,13 +17,10 @@ Cake::Application.routes.draw do
get 'page/:page', :action => :index, :on => :collection
end
- # /profiles
resources :profiles, :only => [:index, :show] do
get 'page/:page', :action => :index, :on => :collection
end
- #get 'favorites' => 'profiles#favorites', :as => 'profiles_favorites'
- # /categories
get 'categories/:slug' => "categories#show", :as => :category
get 'categories/:slug/page/:page' => "categories#show"
@@ -43,8 +39,6 @@ Cake::Application.routes.draw do
# sitemap
get "/sitemap.xml", :to => "sitemap#index", :defaults => {:format => :xml}
- resources :avatars, :only => [:edit, :update]
-
root :to => "creations#index"
namespace :api, :defaults => { :format => 'json' } do
@@ -69,7 +63,6 @@ Cake::Application.routes.draw do
resources :favorites, only: [:index]
resources :settings, only: [:index, :update]
resources :passwords, only: [:index, :update]
- #get 'pwd' => "passwords#index"
- #patch 'pwd' => "passwords#update"
+ resources :avatars, :only => [:edit, :update]
end
end
spec/controllers/avatars_controller_spec.rb → spec/controllers/my/avatars_controller_spec.rb
@@ -1,6 +1,6 @@
require "spec_helper"
-describe AvatarsController do
+describe My::AvatarsController do
let(:user) { create(:user) }
context "when logged in " do
@@ -18,7 +18,7 @@ describe AvatarsController do
end
it "should redirect to the avatar page" do
- response.should redirect_to edit_avatar_path(user)
+ response.should redirect_to edit_my_avatar_path(user)
end
it "should display a flash notice" do
spec/features/upload_avatar_spec.rb
@@ -10,7 +10,7 @@ describe "uploading an avatar" do
fill_in('user_password', :with => "password")
end
click_button("Sign In")
- visit edit_avatar_path(user)
+ visit edit_my_avatar_path(user)
file = File.expand_path(File.join(Rails.root, '/spec/fixtures/images/gorilla.jpg'))
within(".edit_avatar") do
attach_file('avatar_avatar', file)