diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-04 16:44:50 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-04 16:44:50 +0200 |
commit | efd950ae706cfbb55dffebd5d0c85e30acfd7a45 (patch) | |
tree | 49830af75a1fc0a0ec2c634f060fb984908a7e38 /test/site/shared_site_tests.rb | |
parent | ccaba581c0cf8653f61ce212667eaa1cc6f0a28e (diff) | |
download | rails-efd950ae706cfbb55dffebd5d0c85e30acfd7a45.tar.gz rails-efd950ae706cfbb55dffebd5d0c85e30acfd7a45.tar.bz2 rails-efd950ae706cfbb55dffebd5d0c85e30acfd7a45.zip |
Use lazy-loaded factory method for site configuration
Diffstat (limited to 'test/site/shared_site_tests.rb')
-rw-r--r-- | test/site/shared_site_tests.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/site/shared_site_tests.rb b/test/site/shared_site_tests.rb new file mode 100644 index 0000000000..de1a54b874 --- /dev/null +++ b/test/site/shared_site_tests.rb @@ -0,0 +1,63 @@ +require "test_helper" +require "active_support/core_ext/securerandom" +require "yaml" + +SITE_CONFIGURATIONS = begin + YAML.load_file(File.expand_path("../configurations.yml", __FILE__)).deep_symbolize_keys +rescue Errno::ENOENT + puts "Missing site configuration file in test/sites/configurations.yml" +end + +module ActiveFile::Site::SharedSiteTests + extend ActiveSupport::Concern + + FIXTURE_KEY = SecureRandom.base58(24) + FIXTURE_FILE = StringIO.new("Hello world!") + + included do + setup do + @site = self.class.const_get(:SITE) + @site.upload FIXTURE_KEY, FIXTURE_FILE + FIXTURE_FILE.rewind + end + + teardown do + @site.delete FIXTURE_KEY + FIXTURE_FILE.rewind + end + + test "uploading" do + begin + key = SecureRandom.base58(24) + data = "Something else entirely!" + @site.upload(key, StringIO.new(data)) + + assert_equal data, @site.download(key) + ensure + @site.delete key + end + end + + test "downloading" do + assert_equal FIXTURE_FILE.read, @site.download(FIXTURE_KEY) + end + + test "existing" do + assert @site.exist?(FIXTURE_KEY) + assert_not @site.exist?(FIXTURE_KEY + "nonsense") + end + + test "deleting" do + @site.delete FIXTURE_KEY + assert_not @site.exist?(FIXTURE_KEY) + end + + test "sizing" do + assert_equal FIXTURE_FILE.size, @site.byte_size(FIXTURE_KEY) + end + + test "checksumming" do + assert_equal Digest::MD5.hexdigest(FIXTURE_FILE.read), @site.checksum(FIXTURE_KEY) + end + end +end |