browse-everything 0.12.0 → 0.13.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.
@@ -0,0 +1,168 @@
1
+ include BrowserConfigHelper
2
+
3
+ describe BrowseEverything::Driver::Box, vcr: { cassette_name: 'box', record: :none } do
4
+ before(:all) { stub_configuration }
5
+ after(:all) { unstub_configuration }
6
+
7
+ let(:browser) { BrowseEverything::Browser.new(url_options) }
8
+ let(:provider) { browser.providers['box'] }
9
+ let(:auth_params) do
10
+ {
11
+ 'code' => 'CODE',
12
+ 'state' => 'box'
13
+ }
14
+ end
15
+
16
+ # To re-record the VCR responses, you will need to substitute the 'token' and 'refresh_token' values with the
17
+ # actual tokens returned from Box.
18
+ #
19
+ # The easiest way to do this is output @token to the Rails log from the box_client method:
20
+ #
21
+ # def box_client
22
+ # Rails.logger.info(@token)
23
+ # [...]
24
+ #
25
+ # Make sure you have the internal_test_app built and have copied your client id and secret to the yaml config file.
26
+ # With the test app running, you can authenticate to your Box account to browse files, and should see the
27
+ # tokens listed in the Rails log. Once you have copied the new tokens, the spec test will run and use your tokens
28
+ # to authenticate to Box. To record the new responses replace `record: :none` with `record: :all`.
29
+ let(:token) do
30
+ {
31
+ 'token' => 'TOKEN',
32
+ 'refresh_token' => 'REFRESH_TOKEN'
33
+ }
34
+ end
35
+
36
+ subject { provider }
37
+
38
+ its(:name) { is_expected.to eq('Box') }
39
+ its(:key) { is_expected.to eq('box') }
40
+ its(:icon) { is_expected.to be_a(String) }
41
+
42
+ describe '#validate_config' do
43
+ it 'raises and error with an incomplete configuration' do
44
+ expect { BrowseEverything::Driver::Box.new({}) }.to raise_error(BrowseEverything::InitializationError)
45
+ end
46
+ end
47
+
48
+ describe '#auth_link' do
49
+ subject { provider.auth_link }
50
+
51
+ it { is_expected.to start_with('https://www.box.com/api/oauth2/authorize') }
52
+ it { is_expected.to include('browse%2Fconnect') }
53
+ it { is_expected.to include('response_type') }
54
+ end
55
+
56
+ describe '#authorized?' do
57
+ subject { provider.authorized? }
58
+ context 'when the access token is not registered' do
59
+ it { is_expected.to be(false) }
60
+ end
61
+ context 'when the access tokens are registered and not expired' do
62
+ before { provider.token = token.merge('expires_at' => Time.now.to_i + 360) }
63
+ it { is_expected.to be(true) }
64
+ end
65
+ context 'when the access tokens are registered but no expiration time' do
66
+ before { provider.token = token }
67
+ it { is_expected.to be(false) }
68
+ end
69
+ context 'when the access tokens are registered but expired' do
70
+ before { provider.token = token.merge('expires_at' => Time.now.to_i - 360) }
71
+ it { is_expected.to be(false) }
72
+ end
73
+ end
74
+
75
+ describe '#connect' do
76
+ it 'registers new tokens' do
77
+ expect(provider).to receive(:register_access_token).with(kind_of(OAuth2::AccessToken))
78
+ provider.connect(auth_params, 'data')
79
+ end
80
+ end
81
+
82
+ describe '#contents' do
83
+ before { provider.token = token }
84
+
85
+ context 'with files and folders in the root directory' do
86
+ let(:root_directory) { provider.contents('') }
87
+ let(:long_file) { root_directory[0] }
88
+ let(:sas_directory) { root_directory[6] }
89
+ let(:tar_file) { root_directory[10] }
90
+
91
+ describe 'the first item' do
92
+ subject { long_file }
93
+ its(:name) { is_expected.to start_with('A very looooooooooooong box folder') }
94
+ its(:location) { is_expected.to eq('box:20375782799') }
95
+ it { is_expected.to be_container }
96
+ end
97
+
98
+ describe 'the SaS - Development Team directory' do
99
+ subject { sas_directory }
100
+ its(:name) { is_expected.to eq('SaS - Development Team') }
101
+ its(:location) { is_expected.to eq('box:2459961273') }
102
+ its(:id) { is_expected.to eq('2459961273') }
103
+ it { is_expected.to be_container }
104
+ end
105
+
106
+ describe 'a file' do
107
+ subject { tar_file }
108
+ its(:name) { is_expected.to eq('failed.tar.gz') }
109
+ its(:size) { is_expected.to eq(28_650_839) }
110
+ its(:location) { is_expected.to eq('box:25581309763') }
111
+ its(:type) { is_expected.to eq('application/x-gzip') }
112
+ its(:id) { is_expected.to eq('25581309763') }
113
+ it { is_expected.not_to be_container }
114
+ end
115
+ end
116
+
117
+ context 'with files and folders in the SaS - Development Team directory' do
118
+ let(:sas_directory) { provider.contents('2459961273') }
119
+ let(:parent_directory) { sas_directory[0] }
120
+ let(:apps_dir) { sas_directory[1] }
121
+ let(:equipment) { sas_directory[12] }
122
+
123
+ describe 'the first item' do
124
+ subject { parent_directory }
125
+
126
+ its(:name) { is_expected.to eq('..') }
127
+ its(:location) { is_expected.to be_empty }
128
+ its(:id) { is_expected.to be_kind_of(Pathname) }
129
+ it { is_expected.to be_container }
130
+ end
131
+ describe 'the second item' do
132
+ subject { apps_dir }
133
+
134
+ its(:name) { is_expected.to eq('Apps&Int') }
135
+ its(:id) { is_expected.to eq('2459974427') }
136
+ it { is_expected.to be_container }
137
+ end
138
+ describe 'a file' do
139
+ subject { equipment }
140
+
141
+ its(:name) { is_expected.to eq('Equipment.boxnote') }
142
+ its(:size) { is_expected.to eq(10140) }
143
+ its(:location) { is_expected.to eq('box:76960974625') }
144
+ its(:type) { is_expected.to eq('application/octet-stream') }
145
+ its(:id) { is_expected.to eq('76960974625') }
146
+ it { is_expected.not_to be_container }
147
+ end
148
+ end
149
+ end
150
+
151
+ describe '#link_for' do
152
+ before { provider.token = token }
153
+
154
+ context 'with a file from the root directory' do
155
+ let(:link) { provider.link_for('25581309763') }
156
+
157
+ specify { expect(link[0]).to start_with('https://dl.boxcloud.com/d/1') }
158
+ specify { expect(link[1]).to have_key(:expires) }
159
+ end
160
+
161
+ context 'with a file from the SaS - Development Team directory' do
162
+ let(:link) { provider.link_for('76960974625') }
163
+
164
+ specify { expect(link[0]).to start_with('https://dl.boxcloud.com/d/1') }
165
+ specify { expect(link[1]).to have_key(:expires) }
166
+ end
167
+ end
168
+ end
data/spec/unit/s3_spec.rb CHANGED
@@ -1,13 +1,43 @@
1
1
  include BrowserConfigHelper
2
2
 
3
3
  describe BrowseEverything::Driver::FileSystem do
4
- before(:all) { stub_configuration }
5
- after(:all) { unstub_configuration }
6
- let(:browser) { BrowseEverything::Browser.new(url_options) }
4
+ before(:all) { stub_configuration }
5
+ after(:all) { unstub_configuration }
6
+ let(:browser) { BrowseEverything::Browser.new(url_options) }
7
7
  let(:provider) { browser.providers['s3'] }
8
+ subject { provider }
8
9
 
9
- it '#validate_config' do
10
- expect { BrowseEverything::Driver::S3.new({}) }.to raise_error(BrowseEverything::InitializationError)
10
+ describe 'defaults' do
11
+ its(:icon) { is_expected.to eq('amazon') }
12
+ its(:itself) { is_expected.to be_authorized }
13
+ end
14
+
15
+ describe 'configuration' do
16
+ it '#validate_config' do
17
+ expect { BrowseEverything::Driver::S3.new({}) }.to raise_error(BrowseEverything::InitializationError)
18
+ end
19
+
20
+ it 'rejects app_key if app_secret is missing' do
21
+ expect { BrowseEverything::Driver::S3.new(bucket: 'bucket', app_key: 'APP_KEY') }.to raise_error(BrowseEverything::InitializationError)
22
+ end
23
+
24
+ it 'rejects app_secret if app_key is missing' do
25
+ expect { BrowseEverything::Driver::S3.new(bucket: 'bucket', app_secret: 'APP_SECRET') }.to raise_error(BrowseEverything::InitializationError)
26
+ end
27
+
28
+ it 'accepts app_key and app_secret together' do
29
+ expect { BrowseEverything::Driver::S3.new(bucket: 'bucket', app_key: 'APP_KEY', app_secret: 'APP_SECRET') }.not_to raise_error
30
+ end
31
+
32
+ it 'rejects an invalid response type' do
33
+ expect { BrowseEverything::Driver::S3.new(bucket: 'bucket', response_type: :foo) }.to raise_error(BrowseEverything::InitializationError)
34
+ end
35
+
36
+ it 'deprecates :signed_url' do
37
+ driver = BrowseEverything::Driver::S3.new(bucket: 'bucket', signed_url: false)
38
+ expect(driver.config).not_to have_key(:signed_url)
39
+ expect(driver.config[:response_type]).to eq(:public_url)
40
+ end
11
41
  end
12
42
 
13
43
  describe '#contents' do
@@ -72,6 +102,33 @@ describe BrowseEverything::Driver::FileSystem do
72
102
  its(:size) { is_expected.to eq(1_511_860) }
73
103
  specify { is_expected.not_to be_container }
74
104
  end
105
+
106
+ context '#link_for' do
107
+ subject { contents[2] }
108
+ before do
109
+ object = instance_double(Aws::S3::Object)
110
+ allow(object).to receive(:presigned_url).and_return('https://s3.amazonaws.com/presigned_url')
111
+ allow(object).to receive(:public_url).and_return('https://s3.amazonaws.com/public_url')
112
+ allow(object).to receive(:bucket_name).and_return('s3.bucket')
113
+ allow(object).to receive(:key).and_return('foo/quux.png')
114
+ allow(provider.bucket).to receive(:object).and_return(object)
115
+ end
116
+
117
+ it ':signed_url' do
118
+ provider.config[:response_type] = :signed_url
119
+ expect(provider.link_for('foo/quux.png')).to eq('https://s3.amazonaws.com/presigned_url')
120
+ end
121
+
122
+ it ':public_url' do
123
+ provider.config[:response_type] = :public_url
124
+ expect(provider.link_for('foo/quux.png')).to eq('https://s3.amazonaws.com/public_url')
125
+ end
126
+
127
+ it ':s3_uri' do
128
+ provider.config[:response_type] = :s3_uri
129
+ expect(provider.link_for('foo/quux.png')).to eq('s3://s3.bucket/foo/quux.png')
130
+ end
131
+ end
75
132
  end
76
133
  end
77
134
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browse-everything
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carolyn Cole
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2017-03-01 00:00:00.000000000 Z
16
+ date: 2017-04-30 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: rails
@@ -385,14 +385,14 @@ dependencies:
385
385
  requirements:
386
386
  - - "~>"
387
387
  - !ruby/object:Gem::Version
388
- version: '0.10'
388
+ version: '1.0'
389
389
  type: :development
390
390
  prerelease: false
391
391
  version_requirements: !ruby/object:Gem::Requirement
392
392
  requirements:
393
393
  - - "~>"
394
394
  - !ruby/object:Gem::Version
395
- version: '0.10'
395
+ version: '1.0'
396
396
  - !ruby/object:Gem::Dependency
397
397
  name: capybara
398
398
  requirement: !ruby/object:Gem::Requirement
@@ -461,6 +461,7 @@ executables: []
461
461
  extensions: []
462
462
  extra_rdoc_files: []
463
463
  files:
464
+ - ".engine_cart.yml"
464
465
  - ".gitignore"
465
466
  - ".rspec"
466
467
  - ".rubocop.yml"
@@ -518,6 +519,7 @@ files:
518
519
  - spec/fixtures/file_system/dir_2/file_4.docx
519
520
  - spec/fixtures/file_system/file 1.pdf
520
521
  - spec/fixtures/file_system/file_1.pdf
522
+ - spec/fixtures/vcr_cassettes/box.yml
521
523
  - spec/fixtures/vcr_cassettes/dropbox.yml
522
524
  - spec/fixtures/vcr_cassettes/retriever.yml
523
525
  - spec/helper/browse_everything_controller_helper_spec.rb
@@ -533,6 +535,7 @@ files:
533
535
  - spec/support/rake.rb
534
536
  - spec/test_app_templates/lib/generators/test_app_generator.rb
535
537
  - spec/unit/base_spec.rb
538
+ - spec/unit/box_spec.rb
536
539
  - spec/unit/browse_everything_helper_spec.rb
537
540
  - spec/unit/browser_spec.rb
538
541
  - spec/unit/dropbox_spec.rb
@@ -566,7 +569,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
566
569
  version: '0'
567
570
  requirements: []
568
571
  rubyforge_project:
569
- rubygems_version: 2.6.10
572
+ rubygems_version: 2.5.1
570
573
  signing_key:
571
574
  specification_version: 4
572
575
  summary: AJAX/Rails engine file browser for cloud storage services
@@ -578,6 +581,7 @@ test_files:
578
581
  - spec/fixtures/file_system/dir_2/file_4.docx
579
582
  - spec/fixtures/file_system/file 1.pdf
580
583
  - spec/fixtures/file_system/file_1.pdf
584
+ - spec/fixtures/vcr_cassettes/box.yml
581
585
  - spec/fixtures/vcr_cassettes/dropbox.yml
582
586
  - spec/fixtures/vcr_cassettes/retriever.yml
583
587
  - spec/helper/browse_everything_controller_helper_spec.rb
@@ -593,6 +597,7 @@ test_files:
593
597
  - spec/support/rake.rb
594
598
  - spec/test_app_templates/lib/generators/test_app_generator.rb
595
599
  - spec/unit/base_spec.rb
600
+ - spec/unit/box_spec.rb
596
601
  - spec/unit/browse_everything_helper_spec.rb
597
602
  - spec/unit/browser_spec.rb
598
603
  - spec/unit/dropbox_spec.rb