Skip to content

Commit

Permalink
add tests for avatar upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Van der Jeugt committed Feb 5, 2016
1 parent 60827e1 commit 7e1d673
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 1 deletion.
22 changes: 21 additions & 1 deletion spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,37 @@
end

context 'successful' do
it 'should update attributes' do
it 'should update privacy' do
new_private = !(@user.private)
put :update, id: @user, user: { private: new_private }
expect(@user.reload.private).to be new_private
expect(flash[:success]).to be_present
end

it 'should update dagschotel' do
product = create :product
put :update, id: @user, user: { dagschotel_id: product.id }
expect(@user.reload.dagschotel).to eq(product)
end

it 'should accept real images' do
file = fixture_file_upload('files/real-image.png', 'image/png')
put :update, id: @user, user: { avatar: file }
expect(flash[:success]).to be_present
end
end

context 'danger zone' do
it 'should warn for NOPs' do
put :update, id: @user, user: {}
expect(flash[:notice]).to be_present
end

it 'should not accept unreal images' do
file = fixture_file_upload('files/unreal-image.svg', 'image/svg+xml')
put :update, id: @user, user: { avatar: file }
expect(flash[:error]).to be_present
end
end
end

Expand Down
Binary file added spec/fixtures/files/real-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
182 changes: 182 additions & 0 deletions spec/fixtures/files/unreal-image.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7e1d673

Please sign in to comment.