Skip to content

Commit

Permalink
more specs
Browse files Browse the repository at this point in the history
  • Loading branch information
andersoncardoso committed Sep 18, 2014
1 parent cf8f573 commit d30d554
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
25 changes: 25 additions & 0 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,31 @@
end
end

describe "upload_avatar" do
let(:user) { FactoryGirl.create :user }
let(:file) { File.join(Rails.root, 'app', 'assets', 'images', 'imgs', 'avatar-placeholder.png') }
let(:invalid_file) { File.join(Rails.root, 'app', 'assets', 'images', 'gifs', 'spinner.gif') }

before { login_user user }

context 'valid' do
it "saves avatar" do
expect(user.avatar?).to be false
patch :upload_avatar, {user: {avatar: Rack::Test::UploadedFile.new(file)}, id: user.id}
user.reload
expect(response.status).to eq 200
expect(user.avatar?).to be true
end
end
context 'invalid' do
it "raise validation errors" do
expect(user.avatar?).to be false
patch :upload_avatar, {user: {avatar: Rack::Test::UploadedFile.new(invalid_file)}, id: user.id}
expect(response.status).to eq 422
end
end
end

describe "PasswordResets" do
let!(:user) { FactoryGirl.create(:user, :reset_password_token => 'abcdef', :reset_password_token_expires_at => Time.now + 2.days) }
let(:params) { {:token => 'abcdef'} }
Expand Down
30 changes: 30 additions & 0 deletions spec/uploaders/picture_uploader_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'spec_helper'
require 'carrierwave/test/matchers'

describe PictureUploader do
include CarrierWave::Test::Matchers

let(:picture) { FactoryGirl.create(:picture) }

before do
PictureUploader.enable_processing = true
picture.process_image_upload = true
@uploader = PictureUploader.new(picture, :image)
@uploader.thumb.enable_processing = true
path = Rails.root.join('app', 'assets', 'images', 'imgs', 'avatar-placeholder.png')
@uploader.store!(File.open path)
end

after do
PictureUploader.enable_processing = false
@uploader.remove!
end

it { expect(subject.extension_white_list).to eq ['jpg', 'jpeg', 'png'] }

context 'the thumb version' do
it "should scale down a landscape image to be exactly 240 by 200 pixels" do
expect(@uploader.thumb).to be_no_larger_than(240, 200)
end
end
end

0 comments on commit d30d554

Please sign in to comment.