nsisam 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/nsisam/client.rb +3 -3
- data/lib/nsisam/fake_client.rb +4 -4
- data/nsisam.gemspec +2 -2
- data/spec/fake_client_spec.rb +10 -10
- data/spec/nsisam_spec.rb +19 -18
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.2
|
data/lib/nsisam/client.rb
CHANGED
@@ -110,7 +110,7 @@ module NSISam
|
|
110
110
|
# nsisam.get_file("test_key", :doc)
|
111
111
|
def get_file(key, type=:file, expected_checksum = nil)
|
112
112
|
response = get(key, expected_checksum)
|
113
|
-
Response.new(
|
113
|
+
response = Response.new(
|
114
114
|
'key' => response.key,
|
115
115
|
'checksum' => response.checksum,
|
116
116
|
'filename' => response.data['filename'],
|
@@ -149,9 +149,9 @@ module NSISam
|
|
149
149
|
# nsisam.update_file("my key", "my value")
|
150
150
|
# nsisam.update_file("my key", "my value", :video)
|
151
151
|
# nsisam.update_file("my key", "my value", :doc)
|
152
|
-
def update_file(key, type=:file, new_content)
|
152
|
+
def update_file(key, type=:file, new_content, filename)
|
153
153
|
encoded = Base64.encode64(new_content)
|
154
|
-
update(key, type => encoded)
|
154
|
+
update(key, type => encoded, filename: filename)
|
155
155
|
end
|
156
156
|
|
157
157
|
# Pre-configure the NSISam module with default params for the NSISam::Client
|
data/lib/nsisam/fake_client.rb
CHANGED
@@ -11,7 +11,7 @@ module NSISam
|
|
11
11
|
def store(data)
|
12
12
|
key = Time.now.to_i.to_s
|
13
13
|
@storage[key] = JSON.load(data.to_json)
|
14
|
-
|
14
|
+
Response.new 'key' => key, 'checksum' => 0
|
15
15
|
end
|
16
16
|
|
17
17
|
def store_file(file, type=:file)
|
@@ -22,7 +22,7 @@ module NSISam
|
|
22
22
|
|
23
23
|
def get(key, expected_checksum=nil)
|
24
24
|
if @storage.has_key?(key)
|
25
|
-
|
25
|
+
Response.new 'data' => @storage[key]
|
26
26
|
else
|
27
27
|
raise NSISam::Errors::Client::KeyNotFoundError
|
28
28
|
end
|
@@ -40,7 +40,7 @@ module NSISam
|
|
40
40
|
def delete(key)
|
41
41
|
if @storage.has_key?(key)
|
42
42
|
@storage.delete key
|
43
|
-
|
43
|
+
Response.new 'deleted' => true
|
44
44
|
else
|
45
45
|
raise NSISam::Errors::Client::KeyNotFoundError
|
46
46
|
end
|
@@ -49,7 +49,7 @@ module NSISam
|
|
49
49
|
def update(key, value)
|
50
50
|
if @storage.has_key?(key)
|
51
51
|
@storage[key] = value
|
52
|
-
|
52
|
+
Response.new 'key' => key, 'checksum' => 0
|
53
53
|
else
|
54
54
|
raise NSISam::Errors::Client::KeyNotFoundError
|
55
55
|
end
|
data/nsisam.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "nsisam"
|
8
|
-
s.version = "0.6.
|
8
|
+
s.version = "0.6.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Douglas Camata"]
|
12
|
-
s.date = "2012-08-
|
12
|
+
s.date = "2012-08-31"
|
13
13
|
s.description = "A simple gem to access a SAM node. For more info about SAM\n visit www.github.com/nsi-iff/sam_buildout."
|
14
14
|
s.email = "d.camata@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/fake_client_spec.rb
CHANGED
@@ -8,8 +8,8 @@ describe "NSISam::FakeClient" do
|
|
8
8
|
it "can store a value" do
|
9
9
|
response = @nsisam.store("something")
|
10
10
|
response.should_not be_nil
|
11
|
-
response.
|
12
|
-
response.
|
11
|
+
response.key.should_not be_nil
|
12
|
+
response.checksum.should_not be_nil
|
13
13
|
end
|
14
14
|
|
15
15
|
it "can store a file" do
|
@@ -21,8 +21,8 @@ describe "NSISam::FakeClient" do
|
|
21
21
|
|
22
22
|
it "can delete a stored value" do
|
23
23
|
resp = @nsisam.store("delete this")
|
24
|
-
response = @nsisam.delete(resp
|
25
|
-
response
|
24
|
+
response = @nsisam.delete(resp.key)
|
25
|
+
response.should be_deleted
|
26
26
|
end
|
27
27
|
|
28
28
|
it "raises error when key not found" do
|
@@ -38,8 +38,8 @@ describe "NSISam::FakeClient" do
|
|
38
38
|
|
39
39
|
it "can retrieve a stored value" do
|
40
40
|
resp = @nsisam.store("retrieve this")
|
41
|
-
response = @nsisam.get(resp
|
42
|
-
response
|
41
|
+
response = @nsisam.get(resp.key)
|
42
|
+
response.data.should == "retrieve this"
|
43
43
|
end
|
44
44
|
|
45
45
|
it "can retrieve a stored file" do
|
@@ -50,9 +50,9 @@ describe "NSISam::FakeClient" do
|
|
50
50
|
|
51
51
|
it "can update values in keys already stored" do
|
52
52
|
resp = @nsisam.store("update this")
|
53
|
-
response = @nsisam.update(resp
|
54
|
-
response
|
55
|
-
@nsisam.get(response
|
56
|
-
response.
|
53
|
+
response = @nsisam.update(resp.key, "updated")
|
54
|
+
response.key.should == resp.key
|
55
|
+
@nsisam.get(response.key).data.should == "updated"
|
56
|
+
response.checksum.should_not be_nil
|
57
57
|
end
|
58
58
|
end
|
data/spec/nsisam_spec.rb
CHANGED
@@ -16,6 +16,7 @@ describe NSISam do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
let(:file_content) { example_file_content }
|
19
|
+
let(:filename) { 'teste.txt' }
|
19
20
|
|
20
21
|
context "cannot connect to server" do
|
21
22
|
it "throws error if couldn't connect to the server" do
|
@@ -36,9 +37,9 @@ describe NSISam do
|
|
36
37
|
it "encodes content before storing" do
|
37
38
|
Base64.should_receive(:encode64).with(file_content).
|
38
39
|
and_return(:dummy_value)
|
39
|
-
@nsisam.should_receive(:store).with(file: :dummy_value).
|
40
|
+
@nsisam.should_receive(:store).with(file: :dummy_value, filename: filename).
|
40
41
|
and_return(:dummy_result)
|
41
|
-
@nsisam.store_file(file_content).should == :dummy_result
|
42
|
+
@nsisam.store_file(file_content, filename).should == :dummy_result
|
42
43
|
end
|
43
44
|
end
|
44
45
|
end
|
@@ -87,7 +88,7 @@ describe NSISam do
|
|
87
88
|
Base64.should_receive(:decode64).with(:dummy_value).
|
88
89
|
and_return(:decoded_dummy)
|
89
90
|
response = @nsisam.get_file(:key)
|
90
|
-
response.
|
91
|
+
response.file.should == :decoded_dummy
|
91
92
|
end
|
92
93
|
|
93
94
|
it "can generate a direct link to download any file" do
|
@@ -112,12 +113,12 @@ describe NSISam do
|
|
112
113
|
|
113
114
|
context 'file' do
|
114
115
|
it 'encodes content before updating' do
|
115
|
-
key = @nsisam.store_file(file_content).key
|
116
|
+
key = @nsisam.store_file(file_content, filename).key
|
116
117
|
Base64.should_receive(:encode64).with(:dummy_content).
|
117
118
|
and_return(:dummy_content)
|
118
|
-
@nsisam.should_receive(:update).with(key, file: :dummy_content).
|
119
|
+
@nsisam.should_receive(:update).with(key, file: :dummy_content, filename: filename).
|
119
120
|
and_return(:dummy_result)
|
120
|
-
@nsisam.update_file(key, :dummy_content).should == :dummy_result
|
121
|
+
@nsisam.update_file(key, :dummy_content, filename).should == :dummy_result
|
121
122
|
end
|
122
123
|
end
|
123
124
|
end
|
@@ -125,26 +126,26 @@ describe NSISam do
|
|
125
126
|
context 'file storage without mocking' do
|
126
127
|
it 'stores, retrieves and updates files' do
|
127
128
|
updated_file_content = file_content + 'anything ha!'
|
128
|
-
key = @nsisam.store_file(file_content).key
|
129
|
-
@nsisam.get_file(key).
|
130
|
-
@nsisam.update_file(key, updated_file_content)
|
131
|
-
@nsisam.get_file(key).
|
129
|
+
key = @nsisam.store_file(file_content, filename).key
|
130
|
+
@nsisam.get_file(key).file.should == file_content
|
131
|
+
@nsisam.update_file(key, updated_file_content, filename)
|
132
|
+
@nsisam.get_file(key).file.should == updated_file_content
|
132
133
|
end
|
133
134
|
|
134
135
|
it 'stores, retrieves and updates documents for other nsi-services' do
|
135
136
|
updated_file_content = file_content + 'anything ha!'
|
136
|
-
key = @nsisam.store_file(file_content, :doc).key
|
137
|
-
@nsisam.get_file(key, :doc).
|
138
|
-
@nsisam.update_file(key, :doc, updated_file_content)
|
139
|
-
@nsisam.get_file(key, :doc).
|
137
|
+
key = @nsisam.store_file(file_content, filename, :doc).key
|
138
|
+
@nsisam.get_file(key, :doc).file.should == file_content
|
139
|
+
@nsisam.update_file(key, :doc, updated_file_content, filename)
|
140
|
+
@nsisam.get_file(key, :doc).file.should == updated_file_content
|
140
141
|
end
|
141
142
|
|
142
143
|
it 'stores, retrieves and updates videos for other nsi-services' do
|
143
144
|
updated_file_content = file_content + 'anything ha!'
|
144
|
-
key = @nsisam.store_file(file_content, :video).key
|
145
|
-
@nsisam.get_file(key, :video).
|
146
|
-
@nsisam.update_file(key, :video, updated_file_content)
|
147
|
-
@nsisam.get_file(key, :video).
|
145
|
+
key = @nsisam.store_file(file_content, filename, :video).key
|
146
|
+
@nsisam.get_file(key, :video).file.should == file_content
|
147
|
+
@nsisam.update_file(key, :video, updated_file_content, filename)
|
148
|
+
@nsisam.get_file(key, :video).file.should == updated_file_content
|
148
149
|
end
|
149
150
|
end
|
150
151
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nsisam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.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: 2012-08-
|
12
|
+
date: 2012-08-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -172,7 +172,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
172
172
|
version: '0'
|
173
173
|
segments:
|
174
174
|
- 0
|
175
|
-
hash:
|
175
|
+
hash: -3250131280174348984
|
176
176
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
177
|
none: false
|
178
178
|
requirements:
|