Class: S3Test

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
BaseAttachmentTests
Defined in:
lib/test/backends/remote/s3_test.rb

Instance Method Summary collapse

Methods included from BaseAttachmentTests

#test_no_reassign_attribute_data_on_nil, #test_reassign_attribute_data, #test_should_create_file_from_uploaded_file, #test_should_overwrite_old_contents_when_updating, #test_should_save_without_updating_file

Instance Method Details

#test_flunk_s3Object



99
100
101
# File 'lib/test/backends/remote/s3_test.rb', line 99

def test_flunk_s3
  puts "s3 config file not loaded, tests not running"
end

#test_should_create_authenticated_url(klass = S3Attachment) ⇒ Object



41
42
43
44
45
# File 'lib/test/backends/remote/s3_test.rb', line 41

def test_should_create_authenticated_url(klass = S3Attachment)
  attachment_model klass
  attachment = upload_file :filename => '/files/rails.png'
  assert_match /^http.+AWSAccessKeyId.+Expires.+Signature.+/, attachment.authenticated_s3_url(:use_ssl => true)
end

#test_should_create_correct_bucket_name(klass = S3Attachment) ⇒ Object



9
10
11
12
13
# File 'lib/test/backends/remote/s3_test.rb', line 9

def test_should_create_correct_bucket_name(klass = S3Attachment)
  attachment_model klass
  attachment = upload_file :filename => '/files/rails.png'
  assert_equal attachment.s3_config[:bucket_name], attachment.bucket_name
end

#test_should_create_custom_path_prefix(klass = S3WithPathPrefixAttachment) ⇒ Object



25
26
27
28
29
# File 'lib/test/backends/remote/s3_test.rb', line 25

def test_should_create_custom_path_prefix(klass = S3WithPathPrefixAttachment)
  attachment_model klass
  attachment = upload_file :filename => '/files/rails.png'
  assert_equal File.join('some/custom/path/prefix', attachment.attachment_path_id), attachment.base_path
end

#test_should_create_default_path_prefix(klass = S3Attachment) ⇒ Object



17
18
19
20
21
# File 'lib/test/backends/remote/s3_test.rb', line 17

def test_should_create_default_path_prefix(klass = S3Attachment)
  attachment_model klass
  attachment = upload_file :filename => '/files/rails.png'
  assert_equal File.join(attachment_model.table_name, attachment.attachment_path_id), attachment.base_path
end

#test_should_create_valid_url(klass = S3Attachment) ⇒ Object



33
34
35
36
37
# File 'lib/test/backends/remote/s3_test.rb', line 33

def test_should_create_valid_url(klass = S3Attachment)
  attachment_model klass
  attachment = upload_file :filename => '/files/rails.png'
  assert_equal "#{s3_protocol}#{s3_hostname}#{s3_port_string}/#{attachment.bucket_name}/#{attachment.full_filename}", attachment.s3_url
end

#test_should_delete_attachment_from_s3_when_attachment_record_destroyed(klass = S3Attachment) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/test/backends/remote/s3_test.rb', line 62

def test_should_delete_attachment_from_s3_when_attachment_record_destroyed(klass = S3Attachment)
  attachment_model klass
  attachment = upload_file :filename => '/files/rails.png'

  urls = [attachment.s3_url] + attachment.thumbnails.collect(&:s3_url)

  urls.each {|url| assert_kind_of Net::HTTPOK, http_response_for(url) }
  attachment.destroy
  urls.each do |url|
    begin
      http_response_for(url)
    rescue Net::HTTPForbidden, Net::HTTPNotFound
      nil
    end
  end
end

#test_should_save_attachment(klass = S3Attachment) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/test/backends/remote/s3_test.rb', line 49

def test_should_save_attachment(klass = S3Attachment)
  attachment_model klass
  assert_created do
    attachment = upload_file :filename => '/files/rails.png'
    assert_valid attachment
    assert attachment.image?
    assert !attachment.size.zero?
    assert_kind_of Net::HTTPOK, http_response_for(attachment.s3_url)
  end
end