spec/fake_client_spec.rb in nsisam-0.6.4 vs spec/fake_client_spec.rb in nsisam-0.7.0
- old
+ new
@@ -1,6 +1,7 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+require 'net/http'
describe "NSISam::FakeClient" do
before :all do
@nsisam = NSISam::FakeClient.new
end
@@ -11,11 +12,11 @@
response.key.should_not be_nil
response.checksum.should_not be_nil
end
it "can store a file" do
- response = @nsisam.store_file("some file not in base64")
+ response = @nsisam.store_file("some file not in base64", 'dumb.txt')
response.should_not be_nil
response.key.should_not be_nil
response.checksum.should_not be_nil
end
@@ -41,11 +42,11 @@
response = @nsisam.get(resp.key)
response.data.should == "retrieve this"
end
it "can retrieve a stored file" do
- resp = @nsisam.store_file("file not in base64")
+ resp = @nsisam.store_file("file not in base64", 'dumb.txt')
response = @nsisam.get_file(resp.key)
response.data.should_not be_nil
end
it "can update values in keys already stored" do
@@ -53,6 +54,45 @@
response = @nsisam.update(resp.key, "updated")
response.key.should == resp.key
@nsisam.get(response.key).data.should == "updated"
response.checksum.should_not be_nil
end
+
+ context "can host files" do
+ it "stored by #store_file" do
+ response = @nsisam.store_file("file not in base64", 'dumb.txt')
+ response.key.should_not be_nil
+ request = Net::HTTP.get_response(URI.parse("http://#{@nsisam.host}:#{@nsisam.port}/file/#{response.key}"))
+ request.body.should == "file not in base64"
+ end
+
+ it "stored by #store in a dict with file and filename" do
+ data = {file: Base64.encode64('a file'), filename: 'dumb.txt'}
+ response = @nsisam.store(data)
+ request = Net::HTTP.get_response(URI.parse("http://#{@nsisam.host}:#{@nsisam.port}/file/#{response.key}"))
+ request.body.should == "a file"
+ end
+
+ it "should update the hosted file when the file is updated through #store" do
+ data = {file: Base64.encode64('a file'), filename: 'dumb.txt'}
+ response = @nsisam.store(data)
+ request = Net::HTTP.get_response(URI.parse("http://#{@nsisam.host}:#{@nsisam.port}/file/#{response.key}"))
+ request.body.should == "a file"
+
+ data = {file: Base64.encode64('another file'), filename: 'dumb.txt'}
+ response = @nsisam.store(data)
+ request = Net::HTTP.get_response(URI.parse("http://#{@nsisam.host}:#{@nsisam.port}/file/#{response.key}"))
+ request.body.should == "another file"
+ end
+
+ it "should update the hosted file when the file is updated through #store_file" do
+ response = @nsisam.store_file('a file', 'dumb.txt')
+ request = Net::HTTP.get_response(URI.parse("http://#{@nsisam.host}:#{@nsisam.port}/file/#{response.key}"))
+ request.body.should == "a file"
+
+ response = @nsisam.update_file(response.key, 'another file', 'dumb.txt')
+ request = Net::HTTP.get_response(URI.parse("http://#{@nsisam.host}:#{@nsisam.port}/file/#{response.key}"))
+ request.body.should == "another file"
+ end
+ end
+
end