tupper 1.1.1 → 1.1.2
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.
- data/lib/tupper.rb +8 -2
- data/lib/tupper/version.rb +1 -1
- data/spec/tupper_spec.rb +27 -13
- metadata +5 -5
data/lib/tupper.rb
CHANGED
@@ -13,8 +13,14 @@ class Tupper
|
|
13
13
|
|
14
14
|
def initialize session
|
15
15
|
@max_size = DEFAULT_MAX_SIZE
|
16
|
-
@session
|
17
|
-
|
16
|
+
@session = session
|
17
|
+
if @session.has_key?(SESSION_STORE_KEY)
|
18
|
+
json = @session.fetch(SESSION_STORE_KEY)
|
19
|
+
else
|
20
|
+
json = ''
|
21
|
+
end
|
22
|
+
|
23
|
+
unless json.empty?
|
18
24
|
begin
|
19
25
|
@file_info = JSON.parse(json)
|
20
26
|
rescue
|
data/lib/tupper/version.rb
CHANGED
data/spec/tupper_spec.rb
CHANGED
@@ -8,20 +8,34 @@ require 'tupper/errors'
|
|
8
8
|
describe Tupper do
|
9
9
|
include FakeFS::SpecHelpers
|
10
10
|
|
11
|
+
let(:initialize_json) {
|
12
|
+
"{\"tupper_file_info\":\"test\"}"
|
13
|
+
}
|
14
|
+
|
11
15
|
let(:collect_json) {
|
12
16
|
"{\"uploaded_file\":\"/tmp/tupper/1341556030_54c89662.txt\",\"original_file\":\"dummy_tsv.txt\"}"
|
13
17
|
}
|
14
18
|
|
19
|
+
let(:blank_session) { Hash.new }
|
20
|
+
|
21
|
+
let(:invalid_session) { { Tupper::SESSION_STORE_KEY => 'invalid session' } }
|
22
|
+
|
23
|
+
let(:collect_session) { { Tupper::SESSION_STORE_KEY => collect_json } }
|
24
|
+
|
25
|
+
let(:initialize_session) { { Tupper::SESSION_STORE_KEY => initialize_json } }
|
26
|
+
|
15
27
|
describe '#initialize' do
|
16
28
|
context 'without session data' do
|
17
29
|
before do
|
18
|
-
@tupper = Tupper.new(
|
30
|
+
@tupper = Tupper.new(blank_session)
|
19
31
|
@tupper.temp_dir = Tupper::DEFAULT_TMP_DIR
|
20
32
|
end
|
33
|
+
|
21
34
|
it "should create default temporary directory" do
|
22
35
|
Dir.exists?(@tupper.temp_dir).should be_true
|
23
36
|
@tupper.temp_dir.should == '/tmp/tupper'
|
24
37
|
end
|
38
|
+
|
25
39
|
it "should initialize max_size by default" do
|
26
40
|
@tupper.max_size.should == 8
|
27
41
|
end
|
@@ -29,14 +43,14 @@ describe Tupper do
|
|
29
43
|
|
30
44
|
context 'with invalid session data' do
|
31
45
|
specify {
|
32
|
-
expect { Tupper.new(
|
46
|
+
expect { Tupper.new(invalid_session) }
|
33
47
|
.to raise_error Tupper::SessionError
|
34
48
|
}
|
35
49
|
end
|
36
50
|
|
37
51
|
context 'with valid session data' do
|
38
|
-
subject { Tupper.new(
|
39
|
-
|
52
|
+
subject { Tupper.new(collect_session).file_info }
|
53
|
+
it { should be_instance_of Hash }
|
40
54
|
end
|
41
55
|
end
|
42
56
|
|
@@ -54,7 +68,7 @@ describe Tupper do
|
|
54
68
|
|
55
69
|
describe '#temp_dir=' do
|
56
70
|
before do
|
57
|
-
@tupper = Tupper.new(
|
71
|
+
@tupper = Tupper.new(blank_session)
|
58
72
|
@tupper.temp_dir = 'hoge'
|
59
73
|
end
|
60
74
|
|
@@ -66,7 +80,7 @@ describe Tupper do
|
|
66
80
|
|
67
81
|
describe '#temp_dir' do
|
68
82
|
context 'temp_dir is not assigned' do
|
69
|
-
subject { Tupper.new(
|
83
|
+
subject { Tupper.new(blank_session) }
|
70
84
|
its(:temp_dir) { should == Tupper::DEFAULT_TMP_DIR }
|
71
85
|
end
|
72
86
|
end
|
@@ -75,7 +89,7 @@ describe Tupper do
|
|
75
89
|
let(:test_dir) { '/tmp' }
|
76
90
|
let(:test_file) { File.join(test_dir, 'test_file') }
|
77
91
|
before do
|
78
|
-
@tupper = Tupper.new(
|
92
|
+
@tupper = Tupper.new(blank_session).configure { |t| t.max_size = 1 }
|
79
93
|
FileUtils.mkdir_p(test_dir)
|
80
94
|
end
|
81
95
|
|
@@ -100,13 +114,13 @@ describe Tupper do
|
|
100
114
|
|
101
115
|
describe '#has_uploaded_file?' do
|
102
116
|
context 'before upload' do
|
103
|
-
subject { Tupper.new(
|
117
|
+
subject { Tupper.new(blank_session) }
|
104
118
|
it { should_not have_uploaded_file }
|
105
119
|
end
|
106
120
|
|
107
121
|
context 'has collect session' do
|
108
122
|
before do
|
109
|
-
@tupper = Tupper.new(
|
123
|
+
@tupper = Tupper.new(collect_session)
|
110
124
|
FileUtils.mkdir_p Tupper::DEFAULT_TMP_DIR
|
111
125
|
FileUtils.touch('/tmp/tupper/1341556030_54c89662.txt')
|
112
126
|
end
|
@@ -116,13 +130,13 @@ describe Tupper do
|
|
116
130
|
|
117
131
|
describe '#uploaded_file' do
|
118
132
|
context 'before upload'do
|
119
|
-
subject { Tupper.new(
|
120
|
-
|
133
|
+
subject { Tupper.new(initialize_session).uploaded_file }
|
134
|
+
it { should be_nil }
|
121
135
|
end
|
122
136
|
|
123
137
|
context 'has collect session' do
|
124
138
|
before do
|
125
|
-
@tupper = Tupper.new(
|
139
|
+
@tupper = Tupper.new(collect_session)
|
126
140
|
FileUtils.mkdir_p Tupper::DEFAULT_TMP_DIR
|
127
141
|
FileUtils.touch('/tmp/tupper/1341556030_54c89662.txt')
|
128
142
|
end
|
@@ -134,7 +148,7 @@ describe Tupper do
|
|
134
148
|
|
135
149
|
describe '#cleanup' do
|
136
150
|
before do
|
137
|
-
@tupper = Tupper.new(
|
151
|
+
@tupper = Tupper.new(collect_session)
|
138
152
|
FileUtils.mkdir_p Tupper::DEFAULT_TMP_DIR
|
139
153
|
FileUtils.touch('/tmp/tupper/1341556030_54c89662.txt')
|
140
154
|
@tupper.cleanup
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tupper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-06-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -94,7 +94,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
94
|
version: '0'
|
95
95
|
segments:
|
96
96
|
- 0
|
97
|
-
hash:
|
97
|
+
hash: 2782862997147548774
|
98
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
99
|
none: false
|
100
100
|
requirements:
|
@@ -103,10 +103,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
version: '0'
|
104
104
|
segments:
|
105
105
|
- 0
|
106
|
-
hash:
|
106
|
+
hash: 2782862997147548774
|
107
107
|
requirements: []
|
108
108
|
rubyforge_project:
|
109
|
-
rubygems_version: 1.8.
|
109
|
+
rubygems_version: 1.8.23
|
110
110
|
signing_key:
|
111
111
|
specification_version: 3
|
112
112
|
summary: Tupper is a helper for processing uploaded file via web form.
|