tupper 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +3 -9
- data/Rakefile +3 -2
- data/lib/tupper.rb +0 -1
- data/lib/tupper/errors.rb +0 -1
- data/lib/tupper/version.rb +1 -1
- data/sample/config.ru +0 -1
- data/sample/sample.rb +0 -1
- data/spec/tupper_spec.rb +39 -54
- data/tupper.gemspec +0 -1
- metadata +14 -28
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e2bfeecccf6b40f09734a46ea8b36e5f5c8f3439
|
4
|
+
data.tar.gz: 83edca5f70bea68f2efbc34a547d9c44c04f81fa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 22222124f74c5f217b60c25c2affe9d443595211434fb1a1ff11e31556041ddc09a661721bd5077cf60117ce92d55127617269639ed841bcf9ad913acf9b381d
|
7
|
+
data.tar.gz: 627c12091e9e5d2a366a46390efe50e1acf735d8cdf8c416805b1b1bb7fea1a9480042df5d71c1c97b4759d9eebe790f100dcd9dac0445d49e4bad38db737e40
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Tupper
|
2
2
|
|
3
|
+
[![Circle CI](https://circleci.com/gh/kwappa/tupper.svg?style=svg)](https://circleci.com/gh/kwappa/tupper)
|
4
|
+
|
3
5
|
Tupper is a helper for processing uploaded file via web form.
|
4
6
|
|
5
7
|
## Installation
|
@@ -53,12 +55,4 @@ end
|
|
53
55
|
|
54
56
|
### more info
|
55
57
|
|
56
|
-
see
|
57
|
-
|
58
|
-
## Contributing
|
59
|
-
|
60
|
-
1. Fork it
|
61
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
62
|
-
3. Commit your changes (`git commit -am 'Added some feature'`)
|
63
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
64
|
-
5. Create new Pull Request
|
58
|
+
see `/sample`
|
data/Rakefile
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
1
|
require "bundler/gem_tasks"
|
3
2
|
|
4
3
|
Bundler.setup
|
5
4
|
require 'rspec/core/rake_task'
|
6
5
|
|
6
|
+
task default: :spec
|
7
|
+
|
7
8
|
desc "run spec"
|
8
9
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
9
|
-
t.rspec_opts = ["-c", "-
|
10
|
+
t.rspec_opts = ["-c", "-fd"]
|
10
11
|
end
|
data/lib/tupper.rb
CHANGED
data/lib/tupper/errors.rb
CHANGED
data/lib/tupper/version.rb
CHANGED
data/sample/config.ru
CHANGED
data/sample/sample.rb
CHANGED
data/spec/tupper_spec.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
require 'bundler'
|
3
2
|
Bundler.setup(:default, :test)
|
4
3
|
require 'fakefs/spec_helpers'
|
@@ -11,152 +10,138 @@ describe Tupper do
|
|
11
10
|
let(:initialize_json) {
|
12
11
|
"{\"tupper_file_info\":\"test\"}"
|
13
12
|
}
|
14
|
-
|
15
13
|
let(:collect_json) {
|
16
14
|
"{\"uploaded_file\":\"/tmp/tupper/1341556030_54c89662.txt\",\"original_file\":\"dummy_tsv.txt\"}"
|
17
15
|
}
|
18
|
-
|
19
16
|
let(:blank_session) { Hash.new }
|
20
|
-
|
21
17
|
let(:invalid_session) { { Tupper::SESSION_STORE_KEY => 'invalid session' } }
|
22
|
-
|
23
18
|
let(:collect_session) { { Tupper::SESSION_STORE_KEY => collect_json } }
|
24
|
-
|
25
19
|
let(:initialize_session) { { Tupper::SESSION_STORE_KEY => initialize_json } }
|
26
20
|
|
27
21
|
describe '#initialize' do
|
28
22
|
context 'without session data' do
|
29
|
-
|
30
|
-
|
31
|
-
@tupper.temp_dir = Tupper::DEFAULT_TMP_DIR
|
32
|
-
end
|
23
|
+
let(:tupper) { Tupper.new(blank_session) }
|
24
|
+
before { tupper.temp_dir = Tupper::DEFAULT_TMP_DIR }
|
33
25
|
|
34
26
|
it "should create default temporary directory" do
|
35
|
-
Dir.exists?(
|
36
|
-
|
27
|
+
expect(Dir.exists?(tupper.temp_dir)).to be
|
28
|
+
expect(tupper.temp_dir).to eq '/tmp/tupper'
|
37
29
|
end
|
38
30
|
|
39
31
|
it "should initialize max_size by default" do
|
40
|
-
|
32
|
+
expect(tupper.max_size).to eq 8
|
41
33
|
end
|
42
34
|
end
|
43
35
|
|
44
36
|
context 'with invalid session data' do
|
45
|
-
specify {
|
46
|
-
expect { Tupper.new(invalid_session) }
|
47
|
-
.to raise_error Tupper::SessionError
|
48
|
-
}
|
37
|
+
specify { expect { Tupper.new(invalid_session) }.to raise_error Tupper::SessionError }
|
49
38
|
end
|
50
39
|
|
51
40
|
context 'with valid session data' do
|
52
|
-
subject { Tupper.new(collect_session).file_info }
|
53
|
-
|
41
|
+
subject(:file_info) { Tupper.new(collect_session).file_info }
|
42
|
+
specify { expect(file_info).to be_an_instance_of Hash }
|
54
43
|
end
|
55
44
|
end
|
56
45
|
|
57
46
|
describe '#configure' do
|
58
|
-
|
47
|
+
let(:tupper) do
|
59
48
|
Tupper.new({}).configure do |tupper|
|
60
49
|
tupper.max_size = 16
|
61
50
|
tupper.temp_dir = '/tmp/hoge/piyo'
|
62
51
|
end
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'configures correctly' do
|
55
|
+
expect(tupper.max_size).to eq 16
|
56
|
+
expect(tupper.temp_dir).to eq '/tmp/hoge/piyo'
|
57
|
+
expect(Dir.exists?('/tmp/hoge/piyo')).to be
|
58
|
+
end
|
67
59
|
end
|
68
60
|
|
69
61
|
describe '#temp_dir=' do
|
70
|
-
|
71
|
-
|
72
|
-
@tupper.temp_dir = 'hoge'
|
73
|
-
end
|
62
|
+
let(:tupper) { Tupper.new(blank_session) }
|
63
|
+
before { tupper.temp_dir = 'hoge' }
|
74
64
|
|
75
65
|
it 'should set property "temp_dir" and create directory' do
|
76
|
-
|
77
|
-
Dir.exists?(
|
66
|
+
expect(tupper.temp_dir).to eq 'hoge'
|
67
|
+
expect(Dir.exists?(tupper.temp_dir)).to be
|
78
68
|
end
|
79
69
|
end
|
80
70
|
|
81
71
|
describe '#temp_dir' do
|
82
72
|
context 'temp_dir is not assigned' do
|
83
|
-
subject { Tupper.new(blank_session) }
|
84
|
-
|
73
|
+
subject(:temp_dir) { Tupper.new(blank_session).temp_dir }
|
74
|
+
specify { expect(temp_dir).to eq Tupper::DEFAULT_TMP_DIR }
|
85
75
|
end
|
86
76
|
end
|
87
77
|
|
88
78
|
describe '#upload' do
|
89
79
|
let(:test_dir) { '/tmp' }
|
90
80
|
let(:test_file) { File.join(test_dir, 'test_file') }
|
91
|
-
|
92
|
-
|
93
|
-
FileUtils.mkdir_p(test_dir)
|
94
|
-
end
|
81
|
+
let(:tupper) { Tupper.new(blank_session).configure { |t| t.max_size = 1 } }
|
82
|
+
before { FileUtils.mkdir_p(test_dir) }
|
95
83
|
|
96
84
|
context 'file that smaller than or equal max size was uploaded' do
|
97
85
|
before do
|
98
86
|
File.open(test_file, 'w') { |f| f.write('*' * 1024 * 1024) }
|
99
|
-
|
87
|
+
tupper.upload(tempfile: test_file, filename: 'dummy.txt')
|
100
88
|
end
|
101
|
-
specify {
|
89
|
+
specify { expect(tupper).to have_uploaded_file }
|
102
90
|
end
|
103
91
|
|
104
92
|
context 'file that lager than max size was uploaded' do
|
105
93
|
before do
|
106
94
|
File.open(test_file, 'w') { |f| f.write('*' * 1024 * (1024 + 1)) }
|
107
95
|
end
|
108
|
-
specify {
|
109
|
-
expect { @tupper.upload(tempfile: test_file, filename: 'too_large_file.txt') }
|
110
|
-
.to raise_error Tupper::FileSizeError
|
111
|
-
}
|
96
|
+
specify { expect { tupper.upload(tempfile: test_file, filename: 'too_large_file.txt') }.to raise_error Tupper::FileSizeError }
|
112
97
|
end
|
113
98
|
end
|
114
99
|
|
115
100
|
describe '#has_uploaded_file?' do
|
116
101
|
context 'before upload' do
|
117
|
-
|
118
|
-
|
102
|
+
let(:tupper) { Tupper.new(blank_session) }
|
103
|
+
specify { expect(tupper).to_not have_uploaded_file }
|
119
104
|
end
|
120
105
|
|
121
106
|
context 'has collect session' do
|
107
|
+
let(:tupper) { Tupper.new(collect_session) }
|
122
108
|
before do
|
123
|
-
@tupper = Tupper.new(collect_session)
|
124
109
|
FileUtils.mkdir_p Tupper::DEFAULT_TMP_DIR
|
125
110
|
FileUtils.touch('/tmp/tupper/1341556030_54c89662.txt')
|
126
111
|
end
|
127
|
-
specify {
|
112
|
+
specify { expect(tupper).to have_uploaded_file }
|
128
113
|
end
|
129
114
|
end
|
130
115
|
|
131
116
|
describe '#uploaded_file' do
|
132
117
|
context 'before upload'do
|
133
118
|
subject { Tupper.new(initialize_session).uploaded_file }
|
134
|
-
|
119
|
+
specify { expect(subject).to be_nil }
|
135
120
|
end
|
136
121
|
|
137
122
|
context 'has collect session' do
|
123
|
+
let!(:tupper) { Tupper.new(collect_session) }
|
138
124
|
before do
|
139
|
-
@tupper = Tupper.new(collect_session)
|
140
125
|
FileUtils.mkdir_p Tupper::DEFAULT_TMP_DIR
|
141
126
|
FileUtils.touch('/tmp/tupper/1341556030_54c89662.txt')
|
142
127
|
end
|
143
128
|
|
144
|
-
|
145
|
-
it { should == '/tmp/tupper/1341556030_54c89662.txt' }
|
129
|
+
specify { expect(tupper.uploaded_file).to eq '/tmp/tupper/1341556030_54c89662.txt' }
|
146
130
|
end
|
147
131
|
end
|
148
132
|
|
149
133
|
describe '#cleanup' do
|
134
|
+
let!(:tupper) { Tupper.new(collect_session) }
|
135
|
+
|
150
136
|
before do
|
151
|
-
@tupper = Tupper.new(collect_session)
|
152
137
|
FileUtils.mkdir_p Tupper::DEFAULT_TMP_DIR
|
153
138
|
FileUtils.touch('/tmp/tupper/1341556030_54c89662.txt')
|
154
|
-
|
139
|
+
tupper.cleanup
|
155
140
|
end
|
156
141
|
|
157
142
|
it 'should delete uploaded_file and session' do
|
158
|
-
|
159
|
-
File.exists?('/tmp/tupper/1341556030_54c89662.txt').
|
143
|
+
expect(tupper.instance_variable_get(:@session)).to_not be_include Tupper::SESSION_STORE_KEY
|
144
|
+
expect(File.exists?('/tmp/tupper/1341556030_54c89662.txt')).to_not be
|
160
145
|
end
|
161
146
|
end
|
162
147
|
end
|
data/tupper.gemspec
CHANGED
metadata
CHANGED
@@ -1,62 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tupper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.1.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- SHIOYA, Hiromu
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-03-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: fakefs
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
description: Tupper is a helper for processing uploaded file via web form.
|
@@ -66,7 +59,7 @@ executables: []
|
|
66
59
|
extensions: []
|
67
60
|
extra_rdoc_files: []
|
68
61
|
files:
|
69
|
-
- .gitignore
|
62
|
+
- ".gitignore"
|
70
63
|
- Gemfile
|
71
64
|
- LICENSE
|
72
65
|
- README.md
|
@@ -82,33 +75,26 @@ files:
|
|
82
75
|
- tupper.gemspec
|
83
76
|
homepage: https://github.com/kwappa/tupper
|
84
77
|
licenses: []
|
78
|
+
metadata: {}
|
85
79
|
post_install_message:
|
86
80
|
rdoc_options: []
|
87
81
|
require_paths:
|
88
82
|
- lib
|
89
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
84
|
requirements:
|
92
|
-
- -
|
85
|
+
- - ">="
|
93
86
|
- !ruby/object:Gem::Version
|
94
87
|
version: '0'
|
95
|
-
segments:
|
96
|
-
- 0
|
97
|
-
hash: 2782862997147548774
|
98
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
-
none: false
|
100
89
|
requirements:
|
101
|
-
- -
|
90
|
+
- - ">="
|
102
91
|
- !ruby/object:Gem::Version
|
103
92
|
version: '0'
|
104
|
-
segments:
|
105
|
-
- 0
|
106
|
-
hash: 2782862997147548774
|
107
93
|
requirements: []
|
108
94
|
rubyforge_project:
|
109
|
-
rubygems_version:
|
95
|
+
rubygems_version: 2.4.5
|
110
96
|
signing_key:
|
111
|
-
specification_version:
|
97
|
+
specification_version: 4
|
112
98
|
summary: Tupper is a helper for processing uploaded file via web form.
|
113
99
|
test_files:
|
114
100
|
- spec/tupper_spec.rb
|