Commit 1bdde521

mo khan <mo@mokhan.ca>
2013-07-29 23:56:21
add features spec for uploading an avatar
1 parent 88298c9
Changed files (4)
app/controllers/avatars_controller.rb
@@ -7,7 +7,7 @@ class AvatarsController < ApplicationController
 
   def update
     @avatar.attach(params[:avatar][:avatar])
-    redirect_to edit_avatar_path(current_user), :notice => 'Your avatar has been updated.'
+    redirect_to edit_avatar_path(current_user), :notice => t(:avatar_uploaded)
   end
 
   protected 
app/controllers/settings_controller.rb
@@ -9,7 +9,7 @@ class SettingsController < ApplicationController
     @user = current_user
     @user.interest_ids = params[:user][:interest_ids] ||= []
     if @user.update_without_password(user_params)
-      redirect_to settings_path, :notice => 'Your settings have been updated successfully!'
+      redirect_to settings_path, :notice => t(:profile_saved)
     else
       render :index
     end
config/locales/en.yml
@@ -27,3 +27,4 @@ en:
   passwords:
     updated: 'Your password was updated.'
   profile_saved: 'Your settings have been updated successfully!'
+  avatar_uploaded: 'Your avatar has been updated.'
spec/features/upload_avatar_spec.rb
@@ -0,0 +1,24 @@
+require "spec_helper"
+
+describe "uploading an avatar" do
+  let(:user) { create(:user, :password => "password") }
+
+  before :each do
+    visit user_session_path
+    within('.form-inline') do
+      fill_in('user_email', :with => user.email)
+      fill_in('user_password', :with => "password")
+    end
+    click_button("Sign In")
+    visit edit_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)
+    end
+    click_button "Upload picture"
+  end
+
+  it "should display a success message" do
+    page.should have_content(I18n.t(:avatar_uploaded))
+  end
+end