fake_dropbox 0.1.0 → 0.2.0
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/README.md +75 -26
- data/fake_dropbox.gemspec +12 -7
- data/lib/fake_dropbox/config.rb +23 -0
- data/lib/fake_dropbox/server.rb +50 -6
- data/lib/fake_dropbox/utils.rb +6 -0
- data/lib/fake_dropbox/version.rb +1 -1
- data/spec/server_spec.rb +115 -25
- metadata +28 -28
data/README.md
CHANGED
@@ -2,35 +2,57 @@ fake_dropbox
|
|
2
2
|
============
|
3
3
|
|
4
4
|
fake_dropbox is a simple fake implementation of the Dropbox API written in Ruby
|
5
|
-
using the Sinatra framework. It can be used
|
6
|
-
applications that use Dropbox. There are no real authentication and
|
7
|
-
are always authenticated),
|
5
|
+
using the Sinatra framework. It can be used to mock Dropbox when developing and
|
6
|
+
testing applications that use Dropbox. There are no real authentication and
|
7
|
+
users (you are always authenticated), files are stored on the local machine.
|
8
8
|
|
9
9
|
Can be used either as a standalone app listening on a port or intercept calls to
|
10
10
|
the real Dropbox in Ruby apps.
|
11
11
|
|
12
|
-
It
|
13
|
-
|
12
|
+
It implements the following API calls from [Dropbox API version 1][] (some may
|
13
|
+
be only partially implemented):
|
14
|
+
|
15
|
+
* /files (GET)
|
16
|
+
* /files_put
|
17
|
+
* /files (POST)
|
18
|
+
* /metadata
|
19
|
+
* /fileops/create_folder
|
20
|
+
* /fileops/delete
|
21
|
+
|
22
|
+
All the calls which are also present in [Dropbox API version 0][] should behave
|
23
|
+
as they behave in the official Dropbox API when version is set to 0 (e.g.
|
24
|
+
/files (POST) returns `{"result": "winner!"}` instead of file's metadata in
|
25
|
+
version 0).
|
26
|
+
|
14
27
|
If you find it useful and want to add support for more features, go ahead ;)
|
15
28
|
|
29
|
+
[Dropbox API version 0]: https://www.dropbox.com/developers/reference/oldapi
|
30
|
+
[Dropbox API version 1]: https://www.dropbox.com/developers/reference/api
|
31
|
+
|
16
32
|
|
17
33
|
Installation
|
18
34
|
------------
|
19
35
|
|
20
36
|
Using RubyGems:
|
21
37
|
|
22
|
-
|
38
|
+
```
|
39
|
+
gem install fake_dropbox
|
40
|
+
```
|
23
41
|
|
24
42
|
To get the latest development version just clone the repository:
|
25
43
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
44
|
+
```
|
45
|
+
git clone git://github.com/jgonera/fake_dropbox.git
|
46
|
+
cd fake_dropbox
|
47
|
+
gem install bundler
|
48
|
+
bundle install
|
49
|
+
```
|
30
50
|
|
31
51
|
Then, if you want to install it as a gem:
|
32
52
|
|
33
|
-
|
53
|
+
```
|
54
|
+
rake install
|
55
|
+
```
|
34
56
|
|
35
57
|
|
36
58
|
How to use
|
@@ -40,12 +62,21 @@ How to use
|
|
40
62
|
|
41
63
|
If you installed fake_dropbox as a gem, you should be able to run:
|
42
64
|
|
43
|
-
|
65
|
+
```
|
66
|
+
DROPBOX_DIR=/home/joe/somedir fake_dropbox [PORT]
|
67
|
+
```
|
44
68
|
|
45
69
|
You have to specify an environment variable `DROPBOX_DIR` which will point the
|
46
70
|
server to the directory on which the fake API should operate. Additionally, you
|
47
71
|
can specify a custom port (default is 4321).
|
48
72
|
|
73
|
+
If you cloned the repository and you don't want to install fake_dropbox as a
|
74
|
+
gem, you can run it using `rackup` while in the fake_dropbox directory:
|
75
|
+
|
76
|
+
```
|
77
|
+
DROPBOX_DIR=/home/joe/somedir rackup
|
78
|
+
```
|
79
|
+
|
49
80
|
### Intercepting requests in Ruby apps
|
50
81
|
|
51
82
|
You can also use this gem to intercept requests to Dropbox in your Ruby app,
|
@@ -55,12 +86,16 @@ is achieved by using the [WebMock](https://github.com/bblimke/webmock) library.
|
|
55
86
|
The class responsible for this is `FakeDropbox::Glue`. To intercept requests to
|
56
87
|
the real Dropbox, just instantiate this class in your code:
|
57
88
|
|
58
|
-
|
89
|
+
```ruby
|
90
|
+
fake_dropbox = FakeDropbox::Glue.new
|
91
|
+
```
|
59
92
|
|
60
93
|
You can provide an optional argument to the constructor, pointing to the
|
61
94
|
directory you want to use for your fake Dropbox:
|
62
95
|
|
63
|
-
|
96
|
+
```ruby
|
97
|
+
fake_dropbox = FakeDropbox::Glue.new('/home/joe/somedir')
|
98
|
+
```
|
64
99
|
|
65
100
|
If you don't provide it, a temporary directory will be created in the system's
|
66
101
|
temporary path.
|
@@ -69,29 +104,43 @@ Moreover:
|
|
69
104
|
|
70
105
|
* `#dropbox_dir` returns the fake Dropbox directory.
|
71
106
|
* `#empty!` deletes everything in the `dropbox_dir` *recursively*.
|
72
|
-
Even though it should work only if the `dropbox_dir` resides inside the
|
73
|
-
temporary path, you should use it with caution.
|
107
|
+
Even though it should work only if the `dropbox_dir` resides inside the
|
108
|
+
system's temporary path, you should use it with caution.
|
74
109
|
|
75
110
|
A support file for Cucumber tests could look like this:
|
76
111
|
|
77
|
-
|
112
|
+
```ruby
|
113
|
+
require 'fake_dropbox'
|
78
114
|
|
79
|
-
|
115
|
+
fake_dropbox = FakeDropbox::Glue.new
|
80
116
|
|
81
|
-
|
82
|
-
|
83
|
-
|
117
|
+
After do
|
118
|
+
fake_dropbox.empty!
|
119
|
+
end
|
120
|
+
```
|
84
121
|
|
85
|
-
###
|
122
|
+
### Configuration
|
86
123
|
|
87
|
-
|
88
|
-
|
124
|
+
fake_dropbox supports a few configuration options that can be changed after
|
125
|
+
initialization. They can be changed in two ways:
|
126
|
+
|
127
|
+
* by setting `FakeDropbox::Config.<option>` when using inside a Ruby app,
|
128
|
+
* by sending a `POST` request to `/__config__` containing options and their
|
129
|
+
values as parameters (use `true` and `false` strings as boolean equivalents).
|
130
|
+
|
131
|
+
The following options are available:
|
89
132
|
|
90
|
-
|
133
|
+
* `authorize_request_token`, default: `true`
|
134
|
+
* `authorize_access_token`, default: `true`
|
135
|
+
* `authorized`, default: `true`, when set to `false` all API requests return
|
136
|
+
`401 Unauthorized` HTTP status
|
137
|
+
* `debug`, default: `DROPBOX_DEBUG` environmental variable or `false`, if set
|
138
|
+
to `true` reports all the API requests to STDIO (URL, HTTP headers and body).
|
91
139
|
|
92
140
|
|
93
141
|
Copyright
|
94
142
|
---------
|
95
143
|
|
96
|
-
Copyright © 2011 Juliusz Gonera. fake_dropbox is released under the MIT license,
|
144
|
+
Copyright © 2011 Juliusz Gonera. fake_dropbox is released under the MIT license,
|
145
|
+
see LICENSE for details.
|
97
146
|
|
data/fake_dropbox.gemspec
CHANGED
@@ -8,8 +8,13 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["Juliusz Gonera"]
|
9
9
|
s.email = ["jgonera@gmail.com"]
|
10
10
|
s.homepage = "https://github.com/jgonera/fake_dropbox"
|
11
|
-
s.summary = %q{
|
12
|
-
s.description = %q{
|
11
|
+
s.summary = %q{Mock Dropbox when developing your Dropbox app}
|
12
|
+
s.description = %q{
|
13
|
+
Fake Dropbox server written using the Sinatra framework. For development
|
14
|
+
and testing purposes, no real authentication and users, stores files on the
|
15
|
+
local machine. Can be used either as a standalone app listening on a port
|
16
|
+
(language agnostic) or intercept calls to the real Dropbox in Ruby apps.
|
17
|
+
}
|
13
18
|
|
14
19
|
s.rubyforge_project = "fake_dropbox"
|
15
20
|
s.extra_rdoc_files = ['README.md', 'LICENSE']
|
@@ -19,11 +24,11 @@ Gem::Specification.new do |s|
|
|
19
24
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
25
|
s.require_paths = ["lib"]
|
21
26
|
|
22
|
-
s.add_dependency 'sinatra', '
|
23
|
-
s.add_dependency 'json', '
|
24
|
-
s.add_dependency 'rack', '
|
25
|
-
s.add_dependency 'rack-test', '
|
26
|
-
s.add_dependency 'webmock', '
|
27
|
+
s.add_dependency 'sinatra', '>= 1.3.1'
|
28
|
+
s.add_dependency 'json', '>= 1.6.1'
|
29
|
+
s.add_dependency 'rack', '>= 1.3.2'
|
30
|
+
s.add_dependency 'rack-test', '>= 0.6.1'
|
31
|
+
s.add_dependency 'webmock', '>= 1.7.7'
|
27
32
|
|
28
33
|
s.add_development_dependency 'rspec', '~> 2.7.0'
|
29
34
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'fake_dropbox/utils'
|
2
|
+
|
3
|
+
module FakeDropbox
|
4
|
+
module Config
|
5
|
+
class << self
|
6
|
+
include FakeDropbox::Utils
|
7
|
+
|
8
|
+
attr_accessor :authorize_request_token
|
9
|
+
attr_accessor :authorize_access_token
|
10
|
+
attr_accessor :authorized
|
11
|
+
attr_accessor :debug
|
12
|
+
|
13
|
+
def reset!
|
14
|
+
@authorize_request_token = true
|
15
|
+
@authorize_access_token = true
|
16
|
+
@authorized = true
|
17
|
+
@debug = to_bool ENV['DROPBOX_DEBUG']
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
reset!
|
22
|
+
end
|
23
|
+
end
|
data/lib/fake_dropbox/server.rb
CHANGED
@@ -2,13 +2,23 @@ require 'sinatra/base'
|
|
2
2
|
require 'json'
|
3
3
|
require 'fileutils'
|
4
4
|
require 'fake_dropbox/utils'
|
5
|
+
require 'fake_dropbox/config'
|
5
6
|
|
6
7
|
module FakeDropbox
|
7
8
|
class Server < Sinatra::Base
|
8
9
|
before do
|
9
|
-
if not request.path.start_with?('/
|
10
|
-
|
10
|
+
if not request.path.start_with?('/__') # __sinatra__ and __config__
|
11
|
+
halt 401 unless FakeDropbox::Config.authorized
|
12
|
+
@dropbox_dir = ENV['DROPBOX_DIR']
|
11
13
|
raise 'no DROPBOX_DIR in ENV' if not @dropbox_dir
|
14
|
+
if FakeDropbox::Config.debug
|
15
|
+
puts "#{request.request_method} #{request.path}"
|
16
|
+
request.env.select { |k, v| k.start_with? 'HTTP_' }.each do |k, v|
|
17
|
+
puts "#{k}: #{v}"
|
18
|
+
end
|
19
|
+
puts request.body.read
|
20
|
+
request.body.rewind
|
21
|
+
end
|
12
22
|
end
|
13
23
|
end
|
14
24
|
|
@@ -21,13 +31,22 @@ module FakeDropbox
|
|
21
31
|
"Unknown URI: #{request.request_method} #{request.path}"
|
22
32
|
end
|
23
33
|
end
|
34
|
+
|
35
|
+
post '/__config__' do
|
36
|
+
params.each do |key, value|
|
37
|
+
setter = "#{key}="
|
38
|
+
FakeDropbox::Config.send(setter, to_bool(value)) if FakeDropbox::Config.respond_to? setter
|
39
|
+
end
|
40
|
+
end
|
24
41
|
|
25
42
|
post '/:version/oauth/request_token' do
|
26
|
-
|
43
|
+
return status 401 unless FakeDropbox::Config.authorize_request_token
|
44
|
+
'oauth_token_secret=request_secret&oauth_token=request_token'
|
27
45
|
end
|
28
46
|
|
29
47
|
post '/:version/oauth/access_token' do
|
30
|
-
|
48
|
+
return status 401 unless FakeDropbox::Config.authorize_access_token
|
49
|
+
'oauth_token_secret=access_secret&oauth_token=access_token'
|
31
50
|
end
|
32
51
|
|
33
52
|
post '/:version/files/:mode*' do
|
@@ -40,8 +59,14 @@ module FakeDropbox
|
|
40
59
|
FileUtils.cp(tempfile.path, File.join(@dropbox_dir, file_path))
|
41
60
|
File.delete(tempfile.path) if File.exists? tempfile.path
|
42
61
|
|
62
|
+
result = if params[:version] == '0'
|
63
|
+
{ 'result' => 'winner!' }
|
64
|
+
else
|
65
|
+
metadata(file_path)
|
66
|
+
end
|
67
|
+
|
43
68
|
content_type :json
|
44
|
-
|
69
|
+
result.to_json
|
45
70
|
end
|
46
71
|
|
47
72
|
get '/:version/files/:mode*' do
|
@@ -50,10 +75,24 @@ module FakeDropbox
|
|
50
75
|
|
51
76
|
IO.read(file_path)
|
52
77
|
end
|
78
|
+
|
79
|
+
put '/:version/files_put/:mode*' do
|
80
|
+
file_path = File.join(params[:splat])
|
81
|
+
dir = File.join(@dropbox_dir, File.dirname(file_path))
|
82
|
+
return status 404 unless File.exists?(dir) and File.directory?(dir)
|
83
|
+
|
84
|
+
File.open(File.join(@dropbox_dir, file_path), 'w+') do |file|
|
85
|
+
file.write(request.body.read)
|
86
|
+
end
|
87
|
+
|
88
|
+
content_type :json
|
89
|
+
metadata(file_path).to_json
|
90
|
+
end
|
53
91
|
|
54
92
|
get '/:version/metadata/:mode*' do
|
93
|
+
list = params['list'] == 'false' ? false : true
|
55
94
|
content_type :json
|
56
|
-
metadata(params[:splat][0],
|
95
|
+
metadata(params[:splat][0], list).to_json
|
57
96
|
end
|
58
97
|
|
59
98
|
post '/:version/fileops/create_folder' do
|
@@ -77,7 +116,12 @@ module FakeDropbox
|
|
77
116
|
|
78
117
|
return status 404 unless File.exists?(entry_path)
|
79
118
|
|
119
|
+
metadata = metadata(entry)
|
80
120
|
FileUtils.remove_entry_secure entry_path
|
121
|
+
if params[:version] == '1'
|
122
|
+
content_type :json
|
123
|
+
metadata.to_json
|
124
|
+
end
|
81
125
|
end
|
82
126
|
end
|
83
127
|
end
|
data/lib/fake_dropbox/utils.rb
CHANGED
@@ -36,5 +36,11 @@ module FakeDropbox
|
|
36
36
|
def safe_path(path)
|
37
37
|
path.gsub(/(\.\.\/|\/\.\.)/, '')
|
38
38
|
end
|
39
|
+
|
40
|
+
def to_bool(value)
|
41
|
+
return true if value == true || value =~ /(true|t|yes|y|1)$/i
|
42
|
+
return false if value == false || value.nil? || value =~ /(false|f|no|n|0)$/i
|
43
|
+
raise ArgumentError.new("Invalid value for Boolean: \"#{value}\"")
|
44
|
+
end
|
39
45
|
end
|
40
46
|
end
|
data/lib/fake_dropbox/version.rb
CHANGED
data/spec/server_spec.rb
CHANGED
@@ -1,39 +1,66 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'FakeDropbox::Server' do
|
4
|
-
before do
|
4
|
+
before :each do
|
5
5
|
@tmpdir = Dir.mktmpdir 'fake_dropbox-test'
|
6
|
-
|
6
|
+
ENV['DROPBOX_DIR'] = @tmpdir
|
7
|
+
FakeDropbox::Config.reset!
|
7
8
|
end
|
8
9
|
|
9
|
-
after do
|
10
|
+
after :each do
|
10
11
|
FileUtils.remove_entry_secure @tmpdir
|
11
12
|
end
|
13
|
+
|
14
|
+
it "returns error 401 for any API request if not authorized" do
|
15
|
+
post "/__config__", { authorized: false }
|
16
|
+
get "/0/files/dropbox/file.ext"
|
17
|
+
last_response.status.should == 401
|
18
|
+
end
|
19
|
+
|
20
|
+
it "outputs debug to STDIO when debug set to true" do
|
21
|
+
post "/__config__", { debug: true }
|
22
|
+
original_stdout = $stdout
|
23
|
+
$stdout = StringIO.new
|
24
|
+
put "/1/files_put/dropbox/file", "test body"
|
25
|
+
$stdout.string.should =~ /^PUT \/1\/files_put\/dropbox\/file\nHTTP.*\ntest body\n$/m
|
26
|
+
$stdout = original_stdout
|
27
|
+
end
|
12
28
|
|
13
29
|
describe "POST /<version>/oauth/request_token" do
|
14
30
|
it "returns a fake OAuth request token" do
|
15
|
-
post "/0/oauth/request_token"
|
16
|
-
#File.open('/home/julas/Desktop/aaa.html', 'w') {|f| f.write(last_response.body) }
|
31
|
+
post "/0/oauth/request_token"
|
17
32
|
last_response.should be_ok
|
18
33
|
last_response.body.should include 'oauth_token=', 'oauth_token_secret='
|
19
34
|
end
|
35
|
+
|
36
|
+
it "returns error 401 when not authorized" do
|
37
|
+
post "/__config__", { authorize_request_token: false }
|
38
|
+
post "/0/oauth/request_token"
|
39
|
+
last_response.status.should == 401
|
40
|
+
end
|
20
41
|
end
|
21
42
|
|
22
43
|
describe "POST /<version>/oauth/access_token" do
|
23
44
|
it "returns a fake OAuth access token" do
|
24
|
-
post "/0/oauth/access_token"
|
45
|
+
post "/0/oauth/access_token"
|
25
46
|
last_response.should be_ok
|
26
47
|
last_response.body.should include 'oauth_token=', 'oauth_token_secret='
|
27
48
|
end
|
49
|
+
|
50
|
+
it "returns error 401 when not authorized" do
|
51
|
+
post "/__config__", { authorize_access_token: false }
|
52
|
+
post "/0/oauth/access_token"
|
53
|
+
last_response.status.should == 401
|
54
|
+
end
|
28
55
|
end
|
29
56
|
|
30
57
|
describe "POST /<version>/files/dropbox/<path>" do
|
31
58
|
let(:uploaded_file) { Rack::Test::UploadedFile.new(fixture_path('dummy.txt')) }
|
32
59
|
let(:params) { { file: uploaded_file } }
|
33
60
|
|
34
|
-
shared_examples_for "correct upload" do
|
61
|
+
shared_examples_for "correct POST upload" do
|
35
62
|
it "saves the file in the directory" do
|
36
|
-
post "/0/files/dropbox" + path, params
|
63
|
+
post "/0/files/dropbox" + path, params
|
37
64
|
Dir.entries(dir).should include 'dummy.txt'
|
38
65
|
original_content = File.new(fixture_path('dummy.txt')).read
|
39
66
|
uploaded_content = File.new(File.join(dir, 'dummy.txt')).read
|
@@ -41,13 +68,20 @@ describe 'FakeDropbox::Server' do
|
|
41
68
|
end
|
42
69
|
|
43
70
|
it "deletes the temporary file (RackMultipart*)" do
|
44
|
-
post "/0/files/dropbox" + path, params
|
71
|
+
post "/0/files/dropbox" + path, params
|
45
72
|
tempfile = last_request.params['file'][:tempfile]
|
46
73
|
File.exists?(tempfile.path).should == false
|
47
74
|
end
|
48
75
|
|
49
|
-
it "returns
|
50
|
-
post "/0/files/dropbox" + path, params
|
76
|
+
it "returns success message for version 0" do
|
77
|
+
post "/0/files/dropbox" + path, params
|
78
|
+
last_response.should be_ok
|
79
|
+
response = JSON.parse(last_response.body)
|
80
|
+
response.should == { 'result' => 'winner!' }
|
81
|
+
end
|
82
|
+
|
83
|
+
it "returns file metadata for version 1" do
|
84
|
+
post "/1/files/dropbox" + path, params
|
51
85
|
last_response.should be_ok
|
52
86
|
metadata = JSON.parse(last_response.body)
|
53
87
|
metadata['path'].should == path + '/dummy.txt'
|
@@ -59,7 +93,7 @@ describe 'FakeDropbox::Server' do
|
|
59
93
|
let (:path) { '' }
|
60
94
|
let (:dir) { @tmpdir }
|
61
95
|
|
62
|
-
it_behaves_like "correct upload"
|
96
|
+
it_behaves_like "correct POST upload"
|
63
97
|
end
|
64
98
|
|
65
99
|
context "when the path is not root" do
|
@@ -68,12 +102,57 @@ describe 'FakeDropbox::Server' do
|
|
68
102
|
let (:dir) { File.join(@tmpdir, path) }
|
69
103
|
before { Dir.mkdir(dir) }
|
70
104
|
|
71
|
-
it_behaves_like "correct upload"
|
105
|
+
it_behaves_like "correct POST upload"
|
106
|
+
end
|
107
|
+
|
108
|
+
context "when the path does not exist" do
|
109
|
+
it "returns error 404" do
|
110
|
+
post "/0/files/dropbox/incorrect", params
|
111
|
+
last_response.status.should == 404
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "PUT /<version>/files_put/dropbox/<path>" do
|
118
|
+
let(:body) { IO.read(fixture_path('dummy.txt')) }
|
119
|
+
|
120
|
+
shared_examples_for "correct PUT upload" do
|
121
|
+
it "saves the file in the directory" do
|
122
|
+
put "/1/files_put/dropbox" + path, body
|
123
|
+
Dir.entries(dir).should include 'dummy.txt'
|
124
|
+
uploaded_content = IO.read(File.join(dir, 'dummy.txt'))
|
125
|
+
uploaded_content.should == body
|
126
|
+
end
|
127
|
+
|
128
|
+
it "returns file metadata" do
|
129
|
+
put "/1/files_put/dropbox" + path, body
|
130
|
+
last_response.should be_ok
|
131
|
+
metadata = JSON.parse(last_response.body)
|
132
|
+
metadata['path'].should == path
|
133
|
+
metadata['modified'].should include Time.new.strftime('%a, %d %b %Y %H:%M')
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context "when the path is root" do
|
138
|
+
let (:path) { '/dummy.txt' }
|
139
|
+
let (:dir) { @tmpdir }
|
140
|
+
|
141
|
+
it_behaves_like "correct PUT upload"
|
142
|
+
end
|
143
|
+
|
144
|
+
context "when the path is not root" do
|
145
|
+
context "when the path exists" do
|
146
|
+
let (:path) { '/somedir/dummy.txt' }
|
147
|
+
let (:dir) { File.join(@tmpdir, '/somedir') }
|
148
|
+
before { Dir.mkdir(dir) }
|
149
|
+
|
150
|
+
it_behaves_like "correct PUT upload"
|
72
151
|
end
|
73
152
|
|
74
153
|
context "when the path does not exist" do
|
75
154
|
it "returns error 404" do
|
76
|
-
|
155
|
+
put "/1/files_put/dropbox/incorrect/dummy.txt", body
|
77
156
|
last_response.status.should == 404
|
78
157
|
end
|
79
158
|
end
|
@@ -89,7 +168,7 @@ describe 'FakeDropbox::Server' do
|
|
89
168
|
end
|
90
169
|
|
91
170
|
it "returns file contents" do
|
92
|
-
get "/0/files/dropbox/file.ext"
|
171
|
+
get "/0/files/dropbox/file.ext"
|
93
172
|
last_response.should be_ok
|
94
173
|
last_response.body.should == "This is a test."
|
95
174
|
end
|
@@ -97,7 +176,7 @@ describe 'FakeDropbox::Server' do
|
|
97
176
|
|
98
177
|
context "when the file does not exist" do
|
99
178
|
it "returns error 404" do
|
100
|
-
get "/0/files/dropbox/none.ext"
|
179
|
+
get "/0/files/dropbox/none.ext"
|
101
180
|
last_response.status.should == 404
|
102
181
|
end
|
103
182
|
end
|
@@ -106,7 +185,7 @@ describe 'FakeDropbox::Server' do
|
|
106
185
|
describe "GET /<version>/metadata/dropbox/<path>" do
|
107
186
|
it "returns metadata" do
|
108
187
|
File.open(File.join(@tmpdir, 'file.ext'), 'w')
|
109
|
-
get "/0/metadata/dropbox/file.ext", {}
|
188
|
+
get "/0/metadata/dropbox/file.ext", { list: 'false' }
|
110
189
|
last_response.should be_ok
|
111
190
|
metadata = JSON.parse(last_response.body)
|
112
191
|
metadata['path'].should == '/file.ext'
|
@@ -116,7 +195,7 @@ describe 'FakeDropbox::Server' do
|
|
116
195
|
context "when the path is a directory and want a list" do
|
117
196
|
it "returns its children metadata too" do
|
118
197
|
FileUtils.cp(fixture_path('dummy.txt'), @tmpdir)
|
119
|
-
get "/0/metadata/dropbox"
|
198
|
+
get "/0/metadata/dropbox"
|
120
199
|
metadata = JSON.parse(last_response.body)
|
121
200
|
metadata.should include 'contents'
|
122
201
|
end
|
@@ -128,13 +207,13 @@ describe 'FakeDropbox::Server' do
|
|
128
207
|
let(:params) { { path: path, root: 'dropbox' } }
|
129
208
|
|
130
209
|
it "creates a folder" do
|
131
|
-
post "/0/fileops/create_folder", params
|
210
|
+
post "/0/fileops/create_folder", params
|
132
211
|
File.exists?(File.join(@tmpdir, path)).should == true
|
133
212
|
File.directory?(File.join(@tmpdir, path)).should == true
|
134
213
|
end
|
135
214
|
|
136
215
|
it "returns folder's metadata" do
|
137
|
-
metadata = post "/0/fileops/create_folder", params
|
216
|
+
metadata = post "/0/fileops/create_folder", params
|
138
217
|
last_response.should be_ok
|
139
218
|
metadata = JSON.parse(last_response.body)
|
140
219
|
metadata['path'].should == path
|
@@ -157,7 +236,7 @@ describe 'FakeDropbox::Server' do
|
|
157
236
|
let(:params) { { path: '/somedir', root: 'wrong' } }
|
158
237
|
|
159
238
|
it "returns error 400" do
|
160
|
-
post "/0/fileops/create_folder", params
|
239
|
+
post "/0/fileops/create_folder", params
|
161
240
|
last_response.status.should == 400
|
162
241
|
end
|
163
242
|
end
|
@@ -167,7 +246,7 @@ describe 'FakeDropbox::Server' do
|
|
167
246
|
# let(:params) { { path: '/nonexistant/somedir', root: 'dropbox' } }
|
168
247
|
#
|
169
248
|
# it "returns error 404" do
|
170
|
-
# post "/0/fileops/create_folder", params
|
249
|
+
# post "/0/fileops/create_folder", params
|
171
250
|
# last_response.status.should == 404
|
172
251
|
# end
|
173
252
|
# end
|
@@ -177,7 +256,7 @@ describe 'FakeDropbox::Server' do
|
|
177
256
|
before { Dir.mkdir(File.join(@tmpdir, 'somedir')) }
|
178
257
|
|
179
258
|
it "returns error 403" do
|
180
|
-
post "/0/fileops/create_folder", params
|
259
|
+
post "/0/fileops/create_folder", params
|
181
260
|
last_response.status.should == 403
|
182
261
|
end
|
183
262
|
end
|
@@ -190,10 +269,21 @@ describe 'FakeDropbox::Server' do
|
|
190
269
|
|
191
270
|
shared_examples_for "deleting entry" do
|
192
271
|
it "removes the entry" do
|
193
|
-
post '/0/fileops/delete', params
|
272
|
+
post '/0/fileops/delete', params
|
194
273
|
last_response.should be_ok
|
195
274
|
File.exists?(abs_path).should == false
|
196
275
|
end
|
276
|
+
|
277
|
+
it "returns entry's metadata for version 0" do
|
278
|
+
post '/0/fileops/delete', params
|
279
|
+
last_response.body.should be_empty
|
280
|
+
end
|
281
|
+
|
282
|
+
it "returns entry's metadata for version 1" do
|
283
|
+
post '/1/fileops/delete', params
|
284
|
+
metadata = JSON.parse(last_response.body)
|
285
|
+
metadata['path'].should == params[:path]
|
286
|
+
end
|
197
287
|
end
|
198
288
|
|
199
289
|
context "when it's a non-empty directory" do
|
@@ -221,7 +311,7 @@ describe 'FakeDropbox::Server' do
|
|
221
311
|
let(:params) { { path: '/nonexistant.ext', root: 'dropbox' } }
|
222
312
|
|
223
313
|
it "returns error 404" do
|
224
|
-
post '/0/fileops/delete', params
|
314
|
+
post '/0/fileops/delete', params
|
225
315
|
last_response.status.should == 404
|
226
316
|
end
|
227
317
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fake_dropbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,67 +9,66 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
default_executable:
|
12
|
+
date: 2012-08-11 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: sinatra
|
17
|
-
requirement: &
|
16
|
+
requirement: &11405320 !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
18
|
requirements:
|
20
|
-
- -
|
19
|
+
- - ! '>='
|
21
20
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.
|
21
|
+
version: 1.3.1
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements: *
|
24
|
+
version_requirements: *11405320
|
26
25
|
- !ruby/object:Gem::Dependency
|
27
26
|
name: json
|
28
|
-
requirement: &
|
27
|
+
requirement: &11404220 !ruby/object:Gem::Requirement
|
29
28
|
none: false
|
30
29
|
requirements:
|
31
|
-
- -
|
30
|
+
- - ! '>='
|
32
31
|
- !ruby/object:Gem::Version
|
33
32
|
version: 1.6.1
|
34
33
|
type: :runtime
|
35
34
|
prerelease: false
|
36
|
-
version_requirements: *
|
35
|
+
version_requirements: *11404220
|
37
36
|
- !ruby/object:Gem::Dependency
|
38
37
|
name: rack
|
39
|
-
requirement: &
|
38
|
+
requirement: &11402740 !ruby/object:Gem::Requirement
|
40
39
|
none: false
|
41
40
|
requirements:
|
42
|
-
- -
|
41
|
+
- - ! '>='
|
43
42
|
- !ruby/object:Gem::Version
|
44
43
|
version: 1.3.2
|
45
44
|
type: :runtime
|
46
45
|
prerelease: false
|
47
|
-
version_requirements: *
|
46
|
+
version_requirements: *11402740
|
48
47
|
- !ruby/object:Gem::Dependency
|
49
48
|
name: rack-test
|
50
|
-
requirement: &
|
49
|
+
requirement: &11401960 !ruby/object:Gem::Requirement
|
51
50
|
none: false
|
52
51
|
requirements:
|
53
|
-
- -
|
52
|
+
- - ! '>='
|
54
53
|
- !ruby/object:Gem::Version
|
55
54
|
version: 0.6.1
|
56
55
|
type: :runtime
|
57
56
|
prerelease: false
|
58
|
-
version_requirements: *
|
57
|
+
version_requirements: *11401960
|
59
58
|
- !ruby/object:Gem::Dependency
|
60
59
|
name: webmock
|
61
|
-
requirement: &
|
60
|
+
requirement: &11401360 !ruby/object:Gem::Requirement
|
62
61
|
none: false
|
63
62
|
requirements:
|
64
|
-
- -
|
63
|
+
- - ! '>='
|
65
64
|
- !ruby/object:Gem::Version
|
66
65
|
version: 1.7.7
|
67
66
|
type: :runtime
|
68
67
|
prerelease: false
|
69
|
-
version_requirements: *
|
68
|
+
version_requirements: *11401360
|
70
69
|
- !ruby/object:Gem::Dependency
|
71
70
|
name: rspec
|
72
|
-
requirement: &
|
71
|
+
requirement: &11793560 !ruby/object:Gem::Requirement
|
73
72
|
none: false
|
74
73
|
requirements:
|
75
74
|
- - ~>
|
@@ -77,11 +76,12 @@ dependencies:
|
|
77
76
|
version: 2.7.0
|
78
77
|
type: :development
|
79
78
|
prerelease: false
|
80
|
-
version_requirements: *
|
81
|
-
description:
|
82
|
-
purposes, no real authentication and users, stores
|
83
|
-
be used either as a standalone app listening
|
84
|
-
real Dropbox in Ruby
|
79
|
+
version_requirements: *11793560
|
80
|
+
description: ! "\n Fake Dropbox server written using the Sinatra framework. For
|
81
|
+
development\n and testing purposes, no real authentication and users, stores
|
82
|
+
files on the\n local machine. Can be used either as a standalone app listening
|
83
|
+
on a port\n (language agnostic) or intercept calls to the real Dropbox in Ruby
|
84
|
+
apps.\n "
|
85
85
|
email:
|
86
86
|
- jgonera@gmail.com
|
87
87
|
executables:
|
@@ -101,6 +101,7 @@ files:
|
|
101
101
|
- config.ru
|
102
102
|
- fake_dropbox.gemspec
|
103
103
|
- lib/fake_dropbox.rb
|
104
|
+
- lib/fake_dropbox/config.rb
|
104
105
|
- lib/fake_dropbox/glue.rb
|
105
106
|
- lib/fake_dropbox/server.rb
|
106
107
|
- lib/fake_dropbox/utils.rb
|
@@ -110,7 +111,6 @@ files:
|
|
110
111
|
- spec/server_spec.rb
|
111
112
|
- spec/spec_helper.rb
|
112
113
|
- spec/utils_spec.rb
|
113
|
-
has_rdoc: true
|
114
114
|
homepage: https://github.com/jgonera/fake_dropbox
|
115
115
|
licenses: []
|
116
116
|
post_install_message:
|
@@ -131,8 +131,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
131
|
version: '0'
|
132
132
|
requirements: []
|
133
133
|
rubyforge_project: fake_dropbox
|
134
|
-
rubygems_version: 1.
|
134
|
+
rubygems_version: 1.8.15
|
135
135
|
signing_key:
|
136
136
|
specification_version: 3
|
137
|
-
summary:
|
137
|
+
summary: Mock Dropbox when developing your Dropbox app
|
138
138
|
test_files: []
|