Commit d311e69

mo khan <mo@mokhan.ca>
2015-11-15 04:19:58
remove redundant code from profiles controller.
1 parent f28ddb6
Changed files (5)
app
assets
controllers
views
config
locales
spec
app/assets/javascripts/views/google_sync_button.js.coffee
@@ -14,4 +14,3 @@ Stronglifters.GoogleSyncButton = Ractive.extend
     @_drive ||= new Stronglifters.GoogleDrive
       client_id: @get('client_id')
       drive_upload_path: @get('drive_upload_path')
-
app/controllers/profiles_controller.rb
@@ -1,33 +1,25 @@
 class ProfilesController < ApplicationController
-  
   def show
     @user = User.find_by(username: params[:id])
     @profile = @user.profile
     @program = Program.stronglifts
   end
-  
+
   def edit
-    @user = @current_user
-    @profile = @user.profile
+    @profile = @current_user.profile
     @program = Program.stronglifts
   end
-  
+
   def update
-    if @current_user
-      @profile = @current_user.profile
-      @profile.update_attributes(profile_params)
-      flash[:notice] = t("profiles.edit.profile_update_success")
-      redirect_to profile_path(@profile)
-    else
-      flash[:notice] = t("profiles.edit.profile_update_error")
-      render 'edit'
-    end
+    profile = @current_user.profile
+    profile.update_attributes(profile_params)
+    flash[:notice] = t("profiles.edit.profile_update_success")
+    redirect_to profile_path(profile)
   end
-  
+
   private
 
-    def profile_params
-      params.require(:profile).permit(:gender, :social_tolerance)
-    end
-      
+  def profile_params
+    params.require(:profile).permit(:gender, :social_tolerance)
+  end
 end
app/views/profiles/edit.html.erb
@@ -1,8 +1,7 @@
 <div class="row">
-    
   <div class="small-12 columns text-center">
-    <%= gravatar_for(@user, size: 128) %>
-    <h1><%= @user.username %></h1>
+    <%= gravatar_for(@current_user, size: 128) %>
+    <h1><%= @current_user.username %></h1>
     <%= form_for(@profile, method: :patch) do |f| %>
       <fieldset>
         <legend><%= t("profiles.edit.gender.gender") %></legend>
@@ -25,5 +24,4 @@
       <%= f.submit t("profiles.edit.save"), class: "button"  %>
     <% end %>
   </div>
-  
-</div>
\ No newline at end of file
+</div>
config/locales/en.yml
@@ -50,14 +50,12 @@ en:
         high: High
         social_tolerance: Social Tolerance
       save: Save Profile
-      profile_update_error: "Your profile could not be updated."
       profile_update_success: "Profile updated. This is how your public profile appears."
     show:
       exercise_header: Exercise
       maximum_achieved: Maximum Achieved
       no_workouts_completed: 0 workouts completed
       personal_records: Personal Records
-      training_history: Training History
       workouts_completed: "%{count} workouts completed since %{first_session}."
   sessions:
     create:
@@ -70,9 +68,6 @@ en:
   training_sessions:
     drive_upload:
       success: 'Our minions have been summoned to fetch your backup.'
-    index:
-      backup_file: "File"
-      upload_backup_button: "Upload"
     upload:
       success: "Our minions have been summoned to unpack your backup."
       failure: "We don't know how to unpack this type of file."
spec/controllers/profiles_controller_spec.rb
@@ -1,24 +1,23 @@
 require "rails_helper"
 
 describe ProfilesController do
-  
   describe "authenticated" do
-    
-    describe "#show" do
-      include_context "stronglifts_program"
+    include_context "stronglifts_program"
+    let(:user) { create(:user) }
 
-      let(:user) { create(:user) }
-      let(:other_user) { create(:user) }
+    before :each do
+      http_login(user)
+    end
 
-      before :each do
-        http_login(user)
-      end
+    describe "#show" do
+      let(:other_user) { create(:user) }
 
       it "loads the user's profile" do
         get :show, id: user.to_param
         expect(assigns(:user)).to eql(user)
         expect(assigns(:program)).to eql(Program.stronglifts)
       end
+
       it "loads the other user's profile" do
         get :show, id: other_user.to_param
         expect(assigns(:user)).to eql(other_user)
@@ -27,75 +26,49 @@ describe ProfilesController do
     end
 
     describe "#edit" do
-      include_context "stronglifts_program"
-
-      let(:user) { create(:user) }
       let(:other_user) { create(:user) }
-      
-      before :each do
-        http_login(user)
-      end
 
       it "loads the user's profile into an edit view" do
         get :edit, id: user.to_param
-        expect(assigns(:user)).to eql(user)
+        expect(assigns(:current_user)).to eql(user)
         expect(assigns(:program)).to eql(Program.stronglifts)
       end
-      
+
       it "will not load the other user's profile into an edit view" do
         get :edit, id: other_user.to_param
-        expect(assigns(:user)).to eql(user)
+        expect(assigns(:current_user)).to eql(user)
         expect(assigns(:program)).to eql(Program.stronglifts)
       end
-      
     end
-    
-    describe "#update" do
-      include_context "stronglifts_program"
 
-      let(:user) { create(:user) }
-      
-      before :each do
-        http_login(user)
-      end
-      
+    describe "#update" do
       it "updates the user profile" do
-        patch :update, id: user.to_param, profile: {gender: "male"}
+        patch :update, id: user.to_param, profile: { gender: "male" }
         user.reload
         expect(user.profile.male?).to be_truthy
         expect(response).to redirect_to(profile_path(user.profile))
       end
-      
     end
-    
   end
-  
-  describe "unauthenticated" do
-    
-    describe "#show" do
-      include_context "stronglifts_program"
 
-      let(:user) { create(:user) }
+  describe "unauthenticated" do
+    include_context "stronglifts_program"
+    let(:user) { create(:user) }
 
+    describe "#show" do
       it "loads the user's profile" do
         get :show, id: user.to_param
-        expect(assigns(:user)).to eql(nil)
-        expect(assigns(:program)).to eql(nil)
+        expect(assigns(:user)).to be_nil
+        expect(assigns(:program)).to be_nil
       end
     end
 
     describe "#edit" do
-      include_context "stronglifts_program"
-
-      let(:user) { create(:user) }
-
       it "loads the user's profile into an edit view" do
         get :edit, id: user.to_param
-        expect(assigns(:user)).to eql(nil)
-        expect(assigns(:program)).to eql(nil)
+        expect(assigns(:user)).to be_nil
+        expect(assigns(:program)).to be_nil
       end
     end
-    
   end
-    
 end