Skip to content

Commit

Permalink
fixes #12730 - removing the fakeFS gem
Browse files Browse the repository at this point in the history
  • Loading branch information
unorthodoxgeek committed Dec 8, 2015
1 parent 0dbd3e7 commit 2a30346
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
5 changes: 4 additions & 1 deletion app/models/auth_sources/auth_source_ldap.rb
Expand Up @@ -189,9 +189,12 @@ def attributes_values(entry)
end.compact]
end

def avatar_path
"#{Rails.public_path}/assets/avatars"
end

def store_avatar(avatar)
avatar = avatar.to_utf8
avatar_path = "#{Rails.public_path}/assets/avatars"
avatar_hash = Digest::SHA1.hexdigest(avatar)
avatar_file = "#{avatar_path}/#{avatar_hash}.jpg"
unless FileTest.exist? avatar_file
Expand Down
1 change: 0 additions & 1 deletion bundler.d/test.rb
Expand Up @@ -15,5 +15,4 @@
gem "poltergeist"
gem 'test-unit' if RUBY_VERSION >= '2.2'
gem 'test_after_commit', '~> 0.4'
gem 'fakefs', :require => 'fakefs/safe'
end
32 changes: 16 additions & 16 deletions test/unit/auth_sources/auth_source_ldap_test.rb
Expand Up @@ -283,27 +283,27 @@ def setup
end

context 'save external avatar' do
def setup
require 'fakefs/safe'
FakeFS.activate!
end
let(:temp_dir){Dir.mktmpdir}

def teardown
FakeFS.deactivate!
setup do
AuthSourceLdap.any_instance.stubs(:avatar_path).returns(temp_dir)
end

test 'store_avatar can save 8bit ascii files' do
auth = AuthSourceLdap.new
FileUtils.mkdir_p(File.join(Rails.root, 'tmp'))
file = File.open("#{Rails.root}/tmp/out.txt", 'wb+')
file_string = File.open(file, 'rb') {|f| f.read} # set the file_string to binary
file_string += 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVQYV2P4DwABAQEAWk1v8QAAAABJRU5ErkJggg=='
avatar_hash = Digest::SHA1.hexdigest(file_string)
assert_equal(Encoding::ASCII_8BIT, file_string.encoding)
assert_nothing_raised do
auth.send(:store_avatar, file_string)
begin
auth = AuthSourceLdap.new
file = File.open("#{temp_dir}/out.txt", 'wb+')
file_string = File.open(file, 'rb') {|f| f.read} # set the file_string to binary
file_string += 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVQYV2P4DwABAQEAWk1v8QAAAABJRU5ErkJggg=='
avatar_hash = Digest::SHA1.hexdigest(file_string)
assert_equal(Encoding::ASCII_8BIT, file_string.encoding)
assert_nothing_raised do
auth.send(:store_avatar, file_string)
end
assert(File.exist?("#{temp_dir}/#{avatar_hash}.jpg"))
ensure
FileUtils.remove_entry temp_dir
end
assert(File.exist?("#{Rails.public_path}/assets/avatars/#{avatar_hash}.jpg"))
end
end

Expand Down

0 comments on commit 2a30346

Please sign in to comment.