browse-everything 0.11.1 → 0.12.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.
@@ -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
- BrowseEverything::FileEntry.new(
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 'should be a BrowseEverything::FileEntry' do
12
- expect(subject).to be_a BrowseEverything::FileEntry
13
- end
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
- it '#relative_parent_path?' do
44
- expect(subject.relative_parent_path?).to be false
45
- end
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
- BrowseEverything::FileEntry.new(
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 '#type' do
57
- expect(subject.type).to eq('application/x-directory')
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
- it '#relative_parent_path?' do
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
- BrowseEverything::FileEntry.new(
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
- it '#type' do
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 { BrowseEverything::Driver::FileSystem.new({}) }.to raise_error(BrowseEverything::InitializationError)
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) { should == 'File System' }
17
- its(:key) { should == 'file_system' }
18
- its(:icon) { should be_a(String) }
19
- specify { should be_authorized }
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) { should == 'dir_1' }
28
- specify { should be_container }
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) { should == 'dir_2' }
33
- specify { should be_container }
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) { should == 'file 1.pdf' }
38
- its(:size) { should == 2256 }
39
- its(:location) { should == "file_system:#{File.join(home, 'file 1.pdf')}" }
40
- its(:type) { should == 'application/pdf' }
41
- specify { should_not be_container }
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) { should == 'file_1.pdf' }
46
- its(:size) { should == 2256 }
47
- its(:location) { should == "file_system:#{File.join(home, 'file_1.pdf')}" }
48
- its(:type) { should == 'application/pdf' }
49
- specify { should_not be_container }
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) { should == '..' }
58
- specify { should be_container }
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) { should == 'dir_3' }
63
- specify { should be_container }
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) { should == 'file_2.txt' }
68
- its(:location) { should == "file_system:#{File.join(home, 'dir_1/file_2.txt')}" }
69
- its(:type) { should == 'text/plain' }
70
- specify { should_not be_container }
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) { should == 'file_3.m4v' }
79
- its(:location) { should == "file_system:#{File.join(home, 'dir_1/dir_3/file_3.m4v')}" }
80
- its(:size) { should == 3879 }
81
- its(:type) { should == 'video/mp4' }
82
- specify { should_not be_container }
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 { should == ['file:///path/to/file', { file_name: 'file', file_size: 0 }] }
89
+ it { is_expected.to eq(['file:///path/to/file', { file_name: 'file', file_size: 0 }]) }
90
90
  end
91
91
  end
@@ -1,5 +1,5 @@
1
1
  describe BrowseEverything::Retriever, vcr: { cassette_name: 'retriever', record: :none } do
2
- subject { BrowseEverything::Retriever.new }
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
- subject.retrieve(spec['0']) { |chunk, _retrieved, _total| content << chunk }
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| subject.retrieve(spec['0'], &block) }.to yield_with_args(data, data.length, data.length)
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 = subject.download(spec['0'])
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| subject.download(spec['0'], &block) }.to yield_with_args(String, data.length, data.length)
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
- subject.retrieve(spec['0']) { |chunk, _retrieved, _total| content << chunk }
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
- subject.retrieve(spec['1']) { |chunk, _retrieved, _total| content << chunk }
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| subject.retrieve(spec['0'], &block) }.to yield_with_args(data, data.length, data.length)
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 = subject.download(spec['0'])
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| subject.download(spec['0'], &block) }.to yield_with_args(String, data.length, data.length)
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
@@ -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: "", next_marker: nil, contents: [], name: "s3.bucket", prefix: "", delimiter: "/", max_keys: 1000, common_prefixes: [ { prefix: 'foo/' }, { prefix: 'bar/'} ], encoding_type: "url" },
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) { should == 'bar' }
27
- specify { should be_container }
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) { should == 'foo' }
32
- specify { should be_container }
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: "", next_marker: nil, name: "s3.bucket", prefix: "foo/", delimiter: "/", max_keys: 1000, common_prefixes: [], encoding_type: "url",
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: "foo/", last_modified: Time.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.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.parse('2016-10-31 22:08:12 UTC'), etag: "\"a92bbe23736ebdbd37bdc795e7d570ad\"", size: 1511860, storage_class: "STANDARD", owner: { display_name: "mbklein" } }
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) { should == '..' }
57
- specify { should be_container }
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) { should == 'baz.jpg' }
62
- its(:location) { should == "s3:foo/baz.jpg" }
63
- its(:type) { should == 'image/jpeg' }
64
- its(:size) { should == 52645 }
65
- specify { should_not be_container }
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) { should == 'quux.png' }
70
- its(:location) { should == "s3:foo/quux.png" }
71
- its(:type) { should == 'image/png' }
72
- its(:size) { should == 1511860 }
73
- specify { should_not be_container }
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
@@ -1,51 +1,65 @@
1
1
  describe BrowseEverything::Driver::SkyDrive do
2
2
  include BrowseEverything::Engine.routes.url_helpers
3
3
 
4
- def provider_yml
5
- { client_id: 'CLIENTID', client_secret: 'CLIENTSECRET', url_options: { port: '3000', protocol: 'http://', host: 'example.com' } }
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
- def redirect_url
9
- connector_response_url(provider_yml[:url_options])
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
- it 'can connect' do
13
- stub_request(:post, 'https://login.live.com/oauth20_token.srf')
14
- .with(body: { 'client_id' => 'CLIENTID', 'client_secret' => 'CLIENTSECRET', 'code' => 'code', 'grant_type' => 'authorization_code', 'redirect_uri' => redirect_url.to_s })
15
- .to_return(status: 200,
16
- body: {
17
- 'token_type' => 'bearer',
18
- 'expires_at' => (Time.now + (60 * 60 * 24)).to_i,
19
- 'scope' => 'wl.skydrive_update,wl.offline_access',
20
- 'access_token' => 'access_token',
21
- 'refresh_token' => 'refresh_token',
22
- 'authentication_token' => 'authentication_token'
23
- }.to_json,
24
- headers: {
25
- 'content-type' => 'application/json' })
26
-
27
- driver = BrowseEverything::Driver::SkyDrive.new(provider_yml)
28
- driver.connect({ code: 'code' }, {})
29
- driver.authorized?.should == true
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
- it 'can connect but expires' do
33
- stub_request(:post, 'https://login.live.com/oauth20_token.srf')
34
- .with(body: { 'client_id' => 'CLIENTID', 'client_secret' => 'CLIENTSECRET', 'code' => 'code', 'grant_type' => 'authorization_code', 'redirect_uri' => redirect_url.to_s })
35
- .to_return(status: 200,
36
- body: {
37
- 'token_type' => 'bearer',
38
- 'expires_at' => (Time.now - (60 * 60 * 24)).to_i,
39
- 'scope' => 'wl.skydrive_update,wl.offline_access',
40
- 'access_token' => 'access_token',
41
- 'refresh_token' => 'refresh_token',
42
- 'authentication_token' => 'authentication_token'
43
- }.to_json,
44
- headers: {
45
- 'content-type' => 'application/json' })
46
-
47
- driver = BrowseEverything::Driver::SkyDrive.new(provider_yml)
48
- driver.connect({ code: 'code' }, {})
49
- driver.authorized?.should == false
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