browse-everything 0.11.1 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +15 -3
- data/.rubocop_todo.yml +28 -17
- data/CONTRIBUTING.md +66 -20
- data/app/assets/javascripts/browse_everything/behavior.js.coffee +23 -13
- data/app/assets/stylesheets/browse_everything/_browse_everything.scss +8 -9
- data/app/controllers/browse_everything_controller.rb +2 -0
- data/app/views/browse_everything/_file.html.erb +25 -8
- data/browse-everything.gemspec +2 -1
- data/lib/browse_everything/driver/s3.rb +19 -20
- data/lib/browse_everything/version.rb +1 -1
- data/spec/features/select_files_spec.rb +3 -2
- data/spec/features/test_compiling_stylesheets_spec.rb +1 -1
- data/spec/helper/browse_everything_controller_helper_spec.rb +5 -11
- data/spec/unit/base_spec.rb +20 -14
- data/spec/unit/browse_everything_helper_spec.rb +6 -6
- data/spec/unit/browser_spec.rb +24 -22
- data/spec/unit/dropbox_spec.rb +52 -48
- data/spec/unit/file_entry_spec.rb +19 -58
- data/spec/unit/file_system_spec.rb +33 -33
- data/spec/unit/retriever_spec.rb +10 -12
- data/spec/unit/s3_spec.rb +25 -25
- data/spec/unit/sky_drive_spec.rb +54 -40
- data/spec/views/browse_everything/_file.html.erb_spec.rb +5 -5
- data/tasks/ci.rake +8 -1
- metadata +21 -7
@@ -1,89 +1,50 @@
|
|
1
1
|
describe BrowseEverything::FileEntry do
|
2
2
|
let(:mtime) { Time.now }
|
3
|
+
|
3
4
|
describe 'regular file' do
|
4
5
|
subject do
|
5
|
-
|
6
|
+
described_class.new(
|
6
7
|
'file_id_01234', 'my_provider:/location/pa/th/file.m4v',
|
7
8
|
'file.m4v', '1.2 GB', mtime, false
|
8
9
|
)
|
9
10
|
end
|
10
11
|
|
11
|
-
it
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
it '#id' do
|
16
|
-
expect(subject.id).to eq('file_id_01234')
|
17
|
-
end
|
18
|
-
|
19
|
-
it '#location' do
|
20
|
-
expect(subject.location).to eq('my_provider:/location/pa/th/file.m4v')
|
21
|
-
end
|
22
|
-
|
23
|
-
it '#name' do
|
24
|
-
expect(subject.name).to eq('file.m4v')
|
25
|
-
end
|
26
|
-
|
27
|
-
it '#size' do
|
28
|
-
expect(subject.size).to eq('1.2 GB')
|
29
|
-
end
|
30
|
-
|
31
|
-
it '#mtime' do
|
32
|
-
expect(subject.mtime).to eq(mtime)
|
33
|
-
end
|
34
|
-
|
35
|
-
it '#type' do
|
36
|
-
expect(subject.type).to eq('video/mp4')
|
37
|
-
end
|
38
|
-
|
39
|
-
it '#container?' do
|
40
|
-
expect(subject.container?).to be false
|
41
|
-
end
|
12
|
+
it { is_expected.to be_a(described_class) }
|
13
|
+
it { is_expected.not_to be_container }
|
14
|
+
it { is_expected.not_to be_relative_parent_path }
|
42
15
|
|
43
|
-
|
44
|
-
|
45
|
-
|
16
|
+
its(:id) { is_expected.to eq('file_id_01234') }
|
17
|
+
its(:location) { is_expected.to eq('my_provider:/location/pa/th/file.m4v') }
|
18
|
+
its(:name) { is_expected.to eq('file.m4v') }
|
19
|
+
its(:size) { is_expected.to eq('1.2 GB') }
|
20
|
+
its(:mtime) { is_expected.to eq(mtime) }
|
21
|
+
its(:type) { is_expected.to eq('video/mp4') }
|
46
22
|
end
|
47
23
|
|
48
24
|
describe 'directory' do
|
49
25
|
subject do
|
50
|
-
|
26
|
+
described_class.new(
|
51
27
|
'directory_id_1234', 'my_provider:/location/pa/th',
|
52
28
|
'th', '', mtime, true
|
53
29
|
)
|
54
30
|
end
|
55
31
|
|
56
|
-
it
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
it '#container?' do
|
61
|
-
expect(subject.container?).to be true
|
62
|
-
end
|
32
|
+
it { is_expected.to be_container }
|
33
|
+
it { is_expected.not_to be_relative_parent_path }
|
63
34
|
|
64
|
-
|
65
|
-
expect(subject.relative_parent_path?).to be false
|
66
|
-
end
|
35
|
+
its(:type) { is_expected.to eq('application/x-directory') }
|
67
36
|
end
|
68
37
|
|
69
38
|
describe 'parent path' do
|
70
39
|
subject do
|
71
|
-
|
40
|
+
described_class.new(
|
72
41
|
'directory_id_1234', 'my_provider:/location/pa/th',
|
73
42
|
'..', '', mtime, true
|
74
43
|
)
|
75
44
|
end
|
45
|
+
it { is_expected.to be_container }
|
46
|
+
it { is_expected.to be_relative_parent_path }
|
76
47
|
|
77
|
-
|
78
|
-
expect(subject.type).to eq('application/x-directory')
|
79
|
-
end
|
80
|
-
|
81
|
-
it '#container?' do
|
82
|
-
expect(subject.container?).to be true
|
83
|
-
end
|
84
|
-
|
85
|
-
it '#relative_parent_path?' do
|
86
|
-
expect(subject.relative_parent_path?).to be true
|
87
|
-
end
|
48
|
+
its(:type) { is_expected.to eq('application/x-directory') }
|
88
49
|
end
|
89
50
|
end
|
@@ -8,15 +8,15 @@ describe BrowseEverything::Driver::FileSystem do
|
|
8
8
|
let(:provider) { browser.providers['file_system'] }
|
9
9
|
|
10
10
|
it '#validate_config' do
|
11
|
-
expect {
|
11
|
+
expect { described_class.new({}) }.to raise_error(BrowseEverything::InitializationError)
|
12
12
|
end
|
13
13
|
|
14
14
|
describe 'simple properties' do
|
15
15
|
subject { provider }
|
16
|
-
its(:name) {
|
17
|
-
its(:key) {
|
18
|
-
its(:icon) {
|
19
|
-
specify {
|
16
|
+
its(:name) { is_expected.to eq('File System') }
|
17
|
+
its(:key) { is_expected.to eq('file_system') }
|
18
|
+
its(:icon) { is_expected.to be_a(String) }
|
19
|
+
specify { is_expected.to be_authorized }
|
20
20
|
end
|
21
21
|
|
22
22
|
describe '#contents' do
|
@@ -24,29 +24,29 @@ describe BrowseEverything::Driver::FileSystem do
|
|
24
24
|
let(:contents) { provider.contents('/') }
|
25
25
|
context '[0]' do
|
26
26
|
subject { contents[0] }
|
27
|
-
its(:name) {
|
28
|
-
specify {
|
27
|
+
its(:name) { is_expected.to eq('dir_1') }
|
28
|
+
specify { is_expected.to be_container }
|
29
29
|
end
|
30
30
|
context '[1]' do
|
31
31
|
subject { contents[1] }
|
32
|
-
its(:name) {
|
33
|
-
specify {
|
32
|
+
its(:name) { is_expected.to eq('dir_2') }
|
33
|
+
specify { is_expected.to be_container }
|
34
34
|
end
|
35
35
|
context '[2]' do
|
36
36
|
subject { contents[2] }
|
37
|
-
its(:name) {
|
38
|
-
its(:size) {
|
39
|
-
its(:location) {
|
40
|
-
its(:type) {
|
41
|
-
specify {
|
37
|
+
its(:name) { is_expected.to eq('file 1.pdf') }
|
38
|
+
its(:size) { is_expected.to eq(2256) }
|
39
|
+
its(:location) { is_expected.to eq("file_system:#{File.join(home, 'file 1.pdf')}") }
|
40
|
+
its(:type) { is_expected.to eq('application/pdf') }
|
41
|
+
specify { is_expected.not_to be_container }
|
42
42
|
end
|
43
43
|
context '[3]' do
|
44
44
|
subject { contents[3] }
|
45
|
-
its(:name) {
|
46
|
-
its(:size) {
|
47
|
-
its(:location) {
|
48
|
-
its(:type) {
|
49
|
-
specify {
|
45
|
+
its(:name) { is_expected.to eq('file_1.pdf') }
|
46
|
+
its(:size) { is_expected.to eq(2256) }
|
47
|
+
its(:location) { is_expected.to eq("file_system:#{File.join(home, 'file_1.pdf')}") }
|
48
|
+
its(:type) { is_expected.to eq('application/pdf') }
|
49
|
+
specify { is_expected.not_to be_container }
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -54,20 +54,20 @@ describe BrowseEverything::Driver::FileSystem do
|
|
54
54
|
let(:contents) { provider.contents('/dir_1') }
|
55
55
|
context '[0]' do
|
56
56
|
subject { contents[0] }
|
57
|
-
its(:name) {
|
58
|
-
specify {
|
57
|
+
its(:name) { is_expected.to eq('..') }
|
58
|
+
specify { is_expected.to be_container }
|
59
59
|
end
|
60
60
|
context '[1]' do
|
61
61
|
subject { contents[1] }
|
62
|
-
its(:name) {
|
63
|
-
specify {
|
62
|
+
its(:name) { is_expected.to eq('dir_3') }
|
63
|
+
specify { is_expected.to be_container }
|
64
64
|
end
|
65
65
|
context '[2]' do
|
66
66
|
subject { contents[2] }
|
67
|
-
its(:name) {
|
68
|
-
its(:location) {
|
69
|
-
its(:type) {
|
70
|
-
specify {
|
67
|
+
its(:name) { is_expected.to eq('file_2.txt') }
|
68
|
+
its(:location) { is_expected.to eq("file_system:#{File.join(home, 'dir_1/file_2.txt')}") }
|
69
|
+
its(:type) { is_expected.to eq('text/plain') }
|
70
|
+
specify { is_expected.not_to be_container }
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -75,17 +75,17 @@ describe BrowseEverything::Driver::FileSystem do
|
|
75
75
|
let(:contents) { provider.contents('/dir_1/dir_3/file_3.m4v') }
|
76
76
|
context '[0]' do
|
77
77
|
subject { contents[0] }
|
78
|
-
its(:name) {
|
79
|
-
its(:location) {
|
80
|
-
its(:size) {
|
81
|
-
its(:type) {
|
82
|
-
specify {
|
78
|
+
its(:name) { is_expected.to eq('file_3.m4v') }
|
79
|
+
its(:location) { is_expected.to eq("file_system:#{File.join(home, 'dir_1/dir_3/file_3.m4v')}") }
|
80
|
+
its(:size) { is_expected.to eq(3879) }
|
81
|
+
its(:type) { is_expected.to eq('video/mp4') }
|
82
|
+
specify { is_expected.not_to be_container }
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
87
|
describe "#link_for('/path/to/file')" do
|
88
88
|
subject { provider.link_for('/path/to/file') }
|
89
|
-
it {
|
89
|
+
it { is_expected.to eq(['file:///path/to/file', { file_name: 'file', file_size: 0 }]) }
|
90
90
|
end
|
91
91
|
end
|
data/spec/unit/retriever_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
describe BrowseEverything::Retriever, vcr: { cassette_name: 'retriever', record: :none } do
|
2
|
-
|
2
|
+
let(:retriever) { described_class.new }
|
3
3
|
let(:datafile) { File.expand_path('../../fixtures/file_system/file_1.pdf', __FILE__) }
|
4
4
|
let(:datafile_with_spaces) { File.expand_path('../../fixtures/file_system/file 1.pdf', __FILE__) }
|
5
5
|
let(:data) { File.open(datafile, 'rb', &:read) }
|
@@ -22,23 +22,23 @@ describe BrowseEverything::Retriever, vcr: { cassette_name: 'retriever', record:
|
|
22
22
|
context '#retrieve' do
|
23
23
|
it 'content' do
|
24
24
|
content = ''
|
25
|
-
|
25
|
+
retriever.retrieve(spec['0']) { |chunk, _retrieved, _total| content << chunk }
|
26
26
|
expect(content).to eq(data)
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'callbacks' do
|
30
|
-
expect { |block|
|
30
|
+
expect { |block| retriever.retrieve(spec['0'], &block) }.to yield_with_args(data, data.length, data.length)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
context '#download' do
|
35
35
|
it 'content' do
|
36
|
-
file =
|
36
|
+
file = retriever.download(spec['0'])
|
37
37
|
expect(File.open(file, 'rb', &:read)).to eq(data)
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'callbacks' do
|
41
|
-
expect { |block|
|
41
|
+
expect { |block| retriever.download(spec['0'], &block) }.to yield_with_args(String, data.length, data.length)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -62,32 +62,30 @@ describe BrowseEverything::Retriever, vcr: { cassette_name: 'retriever', record:
|
|
62
62
|
context '#retrieve' do
|
63
63
|
it 'content' do
|
64
64
|
content = ''
|
65
|
-
|
65
|
+
retriever.retrieve(spec['0']) { |chunk, _retrieved, _total| content << chunk }
|
66
66
|
expect(content).to eq(data)
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'content with spaces' do
|
70
70
|
content = ''
|
71
|
-
|
71
|
+
retriever.retrieve(spec['1']) { |chunk, _retrieved, _total| content << chunk }
|
72
72
|
expect(content).to eq(data_with_spaces)
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'callbacks' do
|
76
|
-
expect { |block|
|
76
|
+
expect { |block| retriever.retrieve(spec['0'], &block) }.to yield_with_args(data, data.length, data.length)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
80
|
context '#download' do
|
81
81
|
it 'content' do
|
82
|
-
file =
|
82
|
+
file = retriever.download(spec['0'])
|
83
83
|
expect(File.open(file, 'rb', &:read)).to eq(data)
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'callbacks' do
|
87
|
-
expect { |block|
|
87
|
+
expect { |block| retriever.download(spec['0'], &block) }.to yield_with_args(String, data.length, data.length)
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
91
|
-
|
92
|
-
context ''
|
93
91
|
end
|
data/spec/unit/s3_spec.rb
CHANGED
@@ -15,62 +15,62 @@ describe BrowseEverything::Driver::FileSystem do
|
|
15
15
|
before do
|
16
16
|
Aws.config[:s3] = {
|
17
17
|
stub_responses: {
|
18
|
-
list_objects: { is_truncated: false, marker:
|
18
|
+
list_objects: { is_truncated: false, marker: '', next_marker: nil, contents: [], name: 's3.bucket', prefix: '', delimiter: '/', max_keys: 1000, common_prefixes: [{ prefix: 'foo/' }, { prefix: 'bar/' }], encoding_type: 'url' }
|
19
19
|
}
|
20
20
|
}
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
let(:contents) { provider.contents('') }
|
24
24
|
context '[0]' do
|
25
25
|
subject { contents[0] }
|
26
|
-
its(:name) {
|
27
|
-
specify {
|
26
|
+
its(:name) { is_expected.to eq('bar') }
|
27
|
+
specify { is_expected.to be_container }
|
28
28
|
end
|
29
29
|
context '[1]' do
|
30
30
|
subject { contents[1] }
|
31
|
-
its(:name) {
|
32
|
-
specify {
|
31
|
+
its(:name) { is_expected.to eq('foo') }
|
32
|
+
specify { is_expected.to be_container }
|
33
33
|
end
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
context 'subdirectory' do
|
37
37
|
before do
|
38
38
|
Aws.config[:s3] = {
|
39
39
|
stub_responses: {
|
40
|
-
list_objects:
|
40
|
+
list_objects:
|
41
41
|
{
|
42
|
-
is_truncated: false, marker:
|
42
|
+
is_truncated: false, marker: '', next_marker: nil, name: 's3.bucket', prefix: 'foo/', delimiter: '/', max_keys: 1000, common_prefixes: [], encoding_type: 'url',
|
43
43
|
contents: [
|
44
|
-
{ key:
|
45
|
-
{ key:
|
46
|
-
{ key:
|
44
|
+
{ key: 'foo/', last_modified: Time.zone.parse('2014-02-03 16:27:01 UTC'), etag: '"d41d8cd98f00b204e9800998ecf8427e"', size: 0, storage_class: 'STANDARD', owner: { display_name: 'mbklein' } },
|
45
|
+
{ key: 'foo/baz.jpg', last_modified: Time.zone.parse('2016-10-31 20:12:32 UTC'), etag: '"4e2ad532e659a65e8f106b350255a7ba"', size: 52645, storage_class: 'STANDARD', owner: { display_name: 'mbklein' } },
|
46
|
+
{ key: 'foo/quux.png', last_modified: Time.zone.parse('2016-10-31 22:08:12 UTC'), etag: '"a92bbe23736ebdbd37bdc795e7d570ad"', size: 1_511_860, storage_class: 'STANDARD', owner: { display_name: 'mbklein' } }
|
47
47
|
]
|
48
48
|
}
|
49
49
|
}
|
50
50
|
}
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
let(:contents) { provider.contents('foo/') }
|
54
54
|
context '[0]' do
|
55
55
|
subject { contents[0] }
|
56
|
-
its(:name) {
|
57
|
-
specify {
|
56
|
+
its(:name) { is_expected.to eq('..') }
|
57
|
+
specify { is_expected.to be_container }
|
58
58
|
end
|
59
59
|
context '[1]' do
|
60
60
|
subject { contents[1] }
|
61
|
-
its(:name) {
|
62
|
-
its(:location) {
|
63
|
-
its(:type) {
|
64
|
-
its(:size) {
|
65
|
-
specify {
|
61
|
+
its(:name) { is_expected.to eq('baz.jpg') }
|
62
|
+
its(:location) { is_expected.to eq('s3:foo/baz.jpg') }
|
63
|
+
its(:type) { is_expected.to eq('image/jpeg') }
|
64
|
+
its(:size) { is_expected.to eq(52645) }
|
65
|
+
specify { is_expected.not_to be_container }
|
66
66
|
end
|
67
67
|
context '[2]' do
|
68
68
|
subject { contents[2] }
|
69
|
-
its(:name) {
|
70
|
-
its(:location) {
|
71
|
-
its(:type) {
|
72
|
-
its(:size) {
|
73
|
-
specify {
|
69
|
+
its(:name) { is_expected.to eq('quux.png') }
|
70
|
+
its(:location) { is_expected.to eq('s3:foo/quux.png') }
|
71
|
+
its(:type) { is_expected.to eq('image/png') }
|
72
|
+
its(:size) { is_expected.to eq(1_511_860) }
|
73
|
+
specify { is_expected.not_to be_container }
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
data/spec/unit/sky_drive_spec.rb
CHANGED
@@ -1,51 +1,65 @@
|
|
1
1
|
describe BrowseEverything::Driver::SkyDrive do
|
2
2
|
include BrowseEverything::Engine.routes.url_helpers
|
3
3
|
|
4
|
-
|
5
|
-
{
|
4
|
+
let(:provider_yml) do
|
5
|
+
{
|
6
|
+
client_id: 'CLIENTID', client_secret: 'CLIENTSECRET',
|
7
|
+
url_options: { port: '3000', protocol: 'http://', host: 'example.com' }
|
8
|
+
}
|
6
9
|
end
|
7
10
|
|
8
|
-
|
9
|
-
|
11
|
+
let(:redirect_url) { connector_response_url(provider_yml[:url_options]) }
|
12
|
+
|
13
|
+
let(:response_body) do
|
14
|
+
{
|
15
|
+
'client_id' => 'CLIENTID', 'client_secret' => 'CLIENTSECRET', 'code' => 'code',
|
16
|
+
'grant_type' => 'authorization_code', 'redirect_uri' => redirect_url.to_s
|
17
|
+
}
|
10
18
|
end
|
11
19
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
20
|
+
let(:driver) { described_class.new(provider_yml) }
|
21
|
+
|
22
|
+
subject { driver }
|
23
|
+
|
24
|
+
context 'when expiration is in the future' do
|
25
|
+
before do
|
26
|
+
stub_request(:post, 'https://login.live.com/oauth20_token.srf')
|
27
|
+
.with(body: response_body)
|
28
|
+
.to_return(status: 200,
|
29
|
+
body: {
|
30
|
+
'token_type' => 'bearer',
|
31
|
+
'expires_at' => (Time.now + (60 * 60 * 24)).to_i,
|
32
|
+
'scope' => 'wl.skydrive_update,wl.offline_access',
|
33
|
+
'access_token' => 'access_token',
|
34
|
+
'refresh_token' => 'refresh_token',
|
35
|
+
'authentication_token' => 'authentication_token'
|
36
|
+
}.to_json,
|
37
|
+
headers: {
|
38
|
+
'content-type' => 'application/json' })
|
39
|
+
driver.connect({ code: 'code' }, {})
|
40
|
+
end
|
41
|
+
|
42
|
+
it { is_expected.to be_authorized }
|
30
43
|
end
|
31
44
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
context 'when the session has expired' do
|
46
|
+
before do
|
47
|
+
stub_request(:post, 'https://login.live.com/oauth20_token.srf')
|
48
|
+
.with(body: response_body)
|
49
|
+
.to_return(status: 200,
|
50
|
+
body: {
|
51
|
+
'token_type' => 'bearer',
|
52
|
+
'expires_at' => (Time.now - (60 * 60 * 24)).to_i,
|
53
|
+
'scope' => 'wl.skydrive_update,wl.offline_access',
|
54
|
+
'access_token' => 'access_token',
|
55
|
+
'refresh_token' => 'refresh_token',
|
56
|
+
'authentication_token' => 'authentication_token'
|
57
|
+
}.to_json,
|
58
|
+
headers: {
|
59
|
+
'content-type' => 'application/json' })
|
60
|
+
driver.connect({ code: 'code' }, {})
|
61
|
+
end
|
62
|
+
|
63
|
+
it { is_expected.not_to be_authorized }
|
50
64
|
end
|
51
65
|
end
|