tori 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d60157537bc5707d71835f133dbc0006b6151d9
4
- data.tar.gz: 51cb59357eaf4282e9bb4b8121a2eafb2a54a66c
3
+ metadata.gz: b322ca18b61fe86fd91aac2183884729ebf001dd
4
+ data.tar.gz: be953afd00ea6dc0e9987380839e4a11fc42335c
5
5
  SHA512:
6
- metadata.gz: 7b17ef8fe35a5237b4c49ddcbe20aa65e5c9d9c26e22800d4dc0b40450b87b964a394c860e52c721ee74218b46f30cdcc61e7175c6f3db01735f70e212c2dd2c
7
- data.tar.gz: 095f0fca184b6eabd8f8ded81412c436785febe9d6c26e17669190134c9783f1e9fd9e58e69ad132ed9e9bf82e48b8dfb61d18edfa9b8e902b69bfecda022176
6
+ metadata.gz: feaae7d54e87b8cabd463c08f1e1a54ceaf44a983be230cfefa3af84a0a5694256343b396da19e8cc2f9293471bc8545881297d6a5f27b28ebc49eea3d4171e2
7
+ data.tar.gz: 048ebbd96232aa853aebcbbd7178668546aaa856bb5ea5e6e54e66e90e9d57d9e14b0976a97d74137d19680eb7dc786cd4cc0c61dfd2aa702a5b8116cbe7db0e
@@ -128,7 +128,7 @@ module Tori
128
128
  def copy_to(filename, tori_file, **opts)
129
129
  copy_object(
130
130
  copy_source: "#{bucket}/#{filename}",
131
- bucket: backend.bucket,
131
+ bucket: bucket,
132
132
  key: tori_file.name,
133
133
  **opts,
134
134
  )
@@ -8,8 +8,6 @@ module Tori
8
8
 
9
9
  def filename_callback(&block)
10
10
  if block_given?
11
- warn "DEPRECATED: `#{__method__}' is deprecated method."
12
- warn "Please use `tori` method block style in model like `tori :name, { |model| model.id }`."
13
11
  @filename_callback = block
14
12
  else
15
13
  @filename_callback
@@ -1,3 +1,3 @@
1
1
  module Tori
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
@@ -0,0 +1,10 @@
1
+ Aws.config[:s3] = {
2
+ stub_responses: {
3
+ head_bucket: {},
4
+ get_object: {
5
+ content_type: "text/plain",
6
+ body: "foo",
7
+ content_length: 3,
8
+ }
9
+ }
10
+ }
@@ -1,10 +1,10 @@
1
1
  require 'test_helper'
2
2
  require 'tori/backend/s3'
3
-
4
- if ENV["TORI_TEST_BUCKET"]
3
+ require_relative 'aws_s3_stub'
5
4
 
6
5
  class TestToriBackendS3 < Test::Unit::TestCase
7
6
  BucketNotFoundError = Class.new(StandardError)
7
+ TORI_TEST_BUCKET = 'tori-testing-bucket'
8
8
  def request_head(url)
9
9
  uri = URI.parse(url)
10
10
  req = Net::HTTP::Head.new(uri.path)
@@ -14,7 +14,7 @@ class TestToriBackendS3 < Test::Unit::TestCase
14
14
  end
15
15
 
16
16
  setup do
17
- @backend = Tori::Backend::S3.new(bucket: ENV["TORI_TEST_BUCKET"])
17
+ @backend = Tori::Backend::S3.new(bucket: TORI_TEST_BUCKET, client: Aws::S3::Client.new)
18
18
  fail BucketNotFoundError, "S3 test need make s3 bucket '#{@backend.bucket}'" unless @backend.exists?
19
19
 
20
20
  @testfile_path = Pathname.new("test/tmp/testfile")
@@ -28,16 +28,7 @@ class TestToriBackendS3 < Test::Unit::TestCase
28
28
  end
29
29
 
30
30
  test "auto content_type" do
31
- Tempfile.create(["test", ".jpeg"]) do |f|
32
- file = Tori::File.new(:dummy, from: f, to: @backend){ |model| "test-key" }
33
- begin
34
- file.write
35
- content_type = file.get.content_type
36
- assert { 'image/jpeg' == content_type }
37
- ensure
38
- file.delete
39
- end
40
- end
31
+ assert { 'image/jpeg' == Tori::Backend::S3.type_for("test.jpeg") }
41
32
  end
42
33
 
43
34
  test "#initialize" do
@@ -46,7 +37,7 @@ class TestToriBackendS3 < Test::Unit::TestCase
46
37
  assert { ENV["TORI_AWS_SECRET_ACCESS_KEY"] == @backend.client.config.secret_access_key }
47
38
 
48
39
  custom_backend = Tori::Backend::S3.new(
49
- bucket: ENV["TORI_TEST_BUCKET"],
40
+ bucket: TORI_TEST_BUCKET,
50
41
  client: Aws::S3::Client.new(access_key_id: 'aaa', secret_access_key: 'bbb'),
51
42
  )
52
43
  assert_instance_of Tori::Backend::S3, custom_backend
@@ -56,7 +47,7 @@ class TestToriBackendS3 < Test::Unit::TestCase
56
47
  assert_raise(ArgumentError){ Tori::Backend::S3.new }
57
48
  assert_raise(TypeError) {
58
49
  Tori::Backend::S3.new(
59
- bucket: ENV["TORI_TEST_BUCKET"],
50
+ bucket: TORI_TEST_BUCKET,
60
51
  client: Object.new,
61
52
  )
62
53
  }
@@ -69,9 +60,9 @@ class TestToriBackendS3 < Test::Unit::TestCase
69
60
  end
70
61
 
71
62
  test "#write String" do
72
- @backend.write("testfile", "foo", content_type: "image/png")
63
+ @backend.write("testfile", "foo", content_type: "text/plain")
73
64
  testfile = @backend.get_object(key: "testfile")
74
- assert { "image/png" == testfile.content_type }
65
+ assert { "text/plain" == testfile.content_type }
75
66
  assert { "foo" == testfile[:body].read }
76
67
  end
77
68
 
@@ -79,21 +70,15 @@ class TestToriBackendS3 < Test::Unit::TestCase
79
70
  assert_nothing_raised { @backend.write("testfile", @testfile_path) }
80
71
  testfile = @backend.get_object(key: "testfile")
81
72
  assert { "text/plain" == testfile.content_type }
82
- assert { 4 == testfile.content_length }
83
- assert { "text" == testfile[:body].read }
84
-
85
- @backend.write("testfile", @testfile_path, acl: "public-read-write")
86
- res = request_head(@backend.public_url("testfile"))
87
- assert { Net::HTTPOK === res}
73
+ assert { 3 == testfile.content_length }
74
+ assert { "foo" == testfile[:body].read }
88
75
 
89
- @backend.write("testfile", @testfile_path, acl: "private")
90
- res = request_head(@backend.public_url("testfile"))
91
- assert { Net::HTTPForbidden === res}
76
+ assert_nothing_raised { @backend.write("testfile", @testfile_path, acl: "public-read-write") }
77
+ assert_nothing_raised { @backend.write("testfile", @testfile_path, acl: "private") }
92
78
  end
93
79
 
94
80
  test "#read" do
95
- assert_equal "text", @backend.read("testfile")
96
- assert_raise(Aws::S3::Errors::NoSuchKey) { @backend.read("testfile", key: "nothing") }
81
+ assert_equal "foo", @backend.read("testfile")
97
82
  end
98
83
 
99
84
  test "#exists?" do
@@ -103,11 +88,10 @@ class TestToriBackendS3 < Test::Unit::TestCase
103
88
 
104
89
  test "#delete" do
105
90
  assert_nothing_raised { @backend.delete("testfile") }
106
- assert { false == @backend.exists?("testfile") }
107
91
  end
108
92
 
109
93
  test "#public_url" do
110
- assert_match %r!https?://s3-!, @backend.public_url("testfile")
94
+ assert_match %r!https?://s3!, @backend.public_url("testfile")
111
95
  assert_match @backend.bucket, @backend.public_url("testfile")
112
96
  assert_match "testfile", @backend.public_url("testfile")
113
97
  end
@@ -116,7 +100,7 @@ class TestToriBackendS3 < Test::Unit::TestCase
116
100
  path = nil
117
101
  @backend.open("testfile") do |f|
118
102
  assert_instance_of File, f
119
- assert { "text" == f.read }
103
+ assert { "foo" == f.read }
120
104
  path = f.path
121
105
  end
122
106
  assert { false == File.exist?(path) }
@@ -128,9 +112,15 @@ class TestToriBackendS3 < Test::Unit::TestCase
128
112
  @backend.write("path/to/file", @testfile_path)
129
113
  @backend.open("path/to/file") do |f|
130
114
  assert_instance_of File, f
131
- assert { "text" == f.read }
115
+ assert { "foo" == f.read }
132
116
  end
133
117
  end
134
- end
135
118
 
119
+ test "#copy_to" do
120
+ o = Object.new
121
+ file = Tori::File.new(o) do |model|
122
+ model.object_id.to_s
123
+ end
124
+ @backend.copy_to("copy_to_file", file)
125
+ end
136
126
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tori
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksss
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-14 00:00:00.000000000 Z
11
+ date: 2016-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-core
@@ -103,6 +103,7 @@ files:
103
103
  - lib/tori/file.rb
104
104
  - lib/tori/rails.rb
105
105
  - lib/tori/version.rb
106
+ - test/aws_s3_stub.rb
106
107
  - test/test_helper.rb
107
108
  - test/test_tori.rb
108
109
  - test/test_tori_backend_chain.rb
@@ -137,6 +138,7 @@ signing_key:
137
138
  specification_version: 4
138
139
  summary: Simple file uploader
139
140
  test_files:
141
+ - test/aws_s3_stub.rb
140
142
  - test/test_helper.rb
141
143
  - test/test_tori.rb
142
144
  - test/test_tori_backend_chain.rb