Commit 62a26c3e
Changed files (3)
app
controllers
spec
controllers
features
app/controllers/profiles_controller.rb
@@ -2,7 +2,7 @@ class ProfilesController < ApplicationController
before_action :authenticate!, :except => [:index, :show]
def index
- @profiles = User.includes(:avatar).where('creations_count > 0').order(:creations_count => :desc).page(params[:page]).per(12)
+ @profiles = User.includes(:avatar).where('creations_count > 0').order(creations_count: :desc).page(params[:page]).per(12)
end
def show
spec/controllers/my/avatars_controller_spec.rb
@@ -6,19 +6,20 @@ describe My::AvatarsController do
context "when logged in " do
before { http_login(user) }
- describe "#update" do
+ describe "#create" do
context "when uploading a new avatar" do
let(:image) { Rack::Test::UploadedFile.new('spec/fixtures/images/gorilla.jpg', 'image/jpeg') }
- before { put :update, :id => user.id, :avatar => { :avatar => image } }
+ before { post :create, photo: { image: image } }
it "should save the new avatar" do
- Avatar.last.should_not be_nil
- Avatar.last.avatar.should_not be_blank
+ user.reload
+ expect(user.avatar).to_not be_nil
+ expect(user.avatar.image).to_not be_blank
end
it "should redirect to the avatar page" do
- response.should redirect_to edit_my_avatar_path(user)
+ expect(response).to redirect_to(new_my_avatar_path)
end
it "should display a flash notice" do
@@ -27,13 +28,11 @@ describe My::AvatarsController do
end
end
- describe "#edit" do
- before :each do
- get :edit, :id => user.id
- end
+ describe "#new" do
+ before { get :new, id: user.id }
it "should display the current avatar" do
- assigns(:avatar).should_not be_nil
+ expect(assigns(:avatar)).to_not be_nil
end
end
end
spec/features/upload_avatar_spec.rb
@@ -10,15 +10,15 @@ describe "uploading an avatar", js: true do
fill_in('session_password', :with => "password")
end
click_button("Sign In")
- visit edit_my_avatar_path(user)
+ visit new_my_avatar_path
file = File.expand_path(File.join(Rails.root, '/spec/fixtures/images/gorilla.jpg'))
- within(".edit_avatar") do
- attach_file('avatar_avatar', file)
+ within(".edit_photo") do
+ attach_file('photo_image', file)
end
click_button "Upload picture"
end
it "should display a success message" do
- page.should have_content(I18n.t(:avatar_uploaded))
+ expect(page).to have_content(I18n.t(:avatar_uploaded))
end
end