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,34 +1,51 @@
1
- <% if file.container? || provider.config[:max_upload_file_size].blank? # never disable a folder or if no maximum is set
1
+ <%# Never disable folders. Files are only disabled if their size exceeds the maximum %>
2
+ <% if file.container? || provider.config[:max_upload_file_size].blank?
2
3
  disabled = false
3
4
  else
4
5
  max_size = provider.config[:max_upload_file_size].to_i
5
6
  disabled = file.size > max_size
6
7
  end
7
8
  %>
8
- <tr role="row" tabindex="-1" data-ev-location="<%= file.location %>" data-tt-id="<%=path%>" data-tt-parent-id="<%=parent%>" data-tt-branch="<%=file.container? ? 'true' : 'false'%>">
9
+ <tr role="row" tabindex="-1"
10
+ data-ev-location="<%= file.location %>"
11
+ data-tt-id="<%=path%>"
12
+ data-tt-parent-id="<%=parent%>"
13
+ data-tt-branch="<%=file.container? ? 'true' : 'false'%>">
14
+
9
15
  <td role="gridcell" class="<%=file.container? ? 'ev-container' : 'ev-file'%> ev-file-name">
10
16
  <% if disabled %>
11
- <span title="<%= t('browse_everything.size_disabled', max_size: number_to_human_size(max_size)) %>"class="<%=file.container? ? 'folder' : 'file'%>" aria-hidden="true">
12
- <%= file.name %>
17
+ <span title="<%= t('browse_everything.size_disabled', max_size: number_to_human_size(max_size)) %>"
18
+ class="<%=file.container? ? 'folder' : 'file'%>" aria-hidden="true">
19
+ <%= file.name %>
13
20
  </span>
14
21
  <span class="sr-only"><%= file.container? ? ', folder' : ', file' %> </span>
15
22
  <% else %>
16
- <%= link_to browse_everything_engine.contents_path(provider_name,file.id), :class=>'ev-link' do %>
23
+ <%= link_to browse_everything_engine.contents_path(provider_name, file.id), class: 'ev-link' do %>
17
24
  <span class="<%=file.container? ? 'folder' : 'file'%>" aria-hidden="true"/>
18
25
  <%= file.name %>
19
26
  <span class="sr-only"><%= file.container? ? ', folder' : ', file' %> </span>
20
27
  <% end %>
21
28
  <% end %>
22
29
  </td>
23
- <td role="gridcell" class="ev-directory-select">
24
- <%= check_box_tag(:select_all, "0", false, class: "ev-select-all") if file.container? %>
25
- </td>
30
+
31
+ <% if file.container? %>
32
+ <td role="gridcell" class="ev-directory-select">
33
+ <%= check_box_tag(:select_all, "0", false, class: "ev-select-all") %>
34
+ </td>
35
+ <% else %>
36
+ <td role="gridcell" class="ev-file-select">
37
+ <%= check_box_tag(file.id.to_s.parameterize, "0", false, class: "ev-select-file") %>
38
+ </td>
39
+ <% end %>
40
+
26
41
  <td role="gridcell" class="ev-file-size">
27
42
  <%= number_to_human_size(file.size).sub(/Bytes/,'bytes') %>
28
43
  </td>
44
+
29
45
  <td role="gridcell" class="ev-file-kind">
30
46
  <%= file.type %>
31
47
  </td>
48
+
32
49
  <td role="gridcell" class="ev-file-date">
33
50
  <%= file.mtime.strftime('%F %R') %>
34
51
  </td>
@@ -34,7 +34,8 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency 'rspec', '~> 3.0'
35
35
  spec.add_development_dependency 'rspec-rails'
36
36
  spec.add_development_dependency 'rspec-its'
37
- spec.add_development_dependency 'rubocop'
37
+ spec.add_development_dependency 'rubocop', '~> 0.42.0'
38
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.8.0'
38
39
  spec.add_development_dependency 'simplecov'
39
40
  spec.add_development_dependency 'bundler', '~> 1.3'
40
41
  spec.add_development_dependency 'pry'
@@ -3,35 +3,35 @@ require 'aws-sdk'
3
3
  module BrowseEverything
4
4
  module Driver
5
5
  class S3 < Base
6
- DEFAULTS = { signed_url: true, region: 'us-east-1' }
7
-
8
- def initialize config, *args
6
+ DEFAULTS = { signed_url: true, region: 'us-east-1' }.freeze
7
+ CONFIG_KEYS = [:app_key, :app_secret, :bucket].freeze
8
+
9
+ def initialize(config, *args)
9
10
  config = DEFAULTS.merge(config)
10
11
  super
11
12
  end
12
-
13
+
13
14
  def icon
14
15
  'amazon'
15
16
  end
16
-
17
+
17
18
  def validate_config
18
- unless [:app_key, :app_secret, :bucket].all? { |key| config[key].present? }
19
- raise BrowseEverything::InitializationError, 'Amazon S3 driver requires :bucket, :app_key and :app_secret'
20
- end
19
+ return if CONFIG_KEYS.all? { |key| config[key].present? }
20
+ raise BrowseEverything::InitializationError, "Amazon S3 driver requires #{CONFIG_KEYS.join(',')}"
21
21
  end
22
-
22
+
23
23
  def contents(path = '')
24
- path = File.join(path,'') unless path.empty?
24
+ path = File.join(path, '') unless path.empty?
25
25
  result = []
26
26
  listing = client.list_objects(bucket: config[:bucket], delimiter: '/', prefix: path)
27
27
  unless path.empty?
28
28
  result << BrowseEverything::FileEntry.new(
29
29
  Pathname(path).join('..'),
30
- '', '..', 0, Time.now, true
30
+ '', '..', 0, Time.current, true
31
31
  )
32
32
  end
33
33
  listing.common_prefixes.each do |prefix|
34
- result << entry_for(prefix.prefix, 0, Time.now, true)
34
+ result << entry_for(prefix.prefix, 0, Time.current, true)
35
35
  end
36
36
  listing.contents.reject { |entry| entry.key == path }.each do |entry|
37
37
  result << entry_for(entry.key, entry.size, entry.last_modified, false)
@@ -46,21 +46,21 @@ module BrowseEverything
46
46
  end
47
47
 
48
48
  def entry_for(name, size, date, dir)
49
- BrowseEverything::FileEntry.new(name, [key,name].join(':'), File.basename(name), size, date, dir)
49
+ BrowseEverything::FileEntry.new(name, [key, name].join(':'), File.basename(name), size, date, dir)
50
50
  end
51
-
51
+
52
52
  def details(path)
53
53
  entry = client.head_object(path)
54
54
  BrowseEverything::FileEntry.new(
55
55
  entry.key,
56
- [key,entry.key].join(':'),
56
+ [key, entry.key].join(':'),
57
57
  File.basename(entry.key),
58
58
  entry.size,
59
59
  entry.last_modified,
60
60
  false
61
61
  )
62
62
  end
63
-
63
+
64
64
  def link_for(path)
65
65
  obj = bucket.object(path)
66
66
  if config[:signed_url]
@@ -69,19 +69,18 @@ module BrowseEverything
69
69
  obj.public_url
70
70
  end
71
71
  end
72
-
72
+
73
73
  def authorized?
74
74
  true
75
75
  end
76
-
76
+
77
77
  def bucket
78
78
  @bucket ||= Aws::S3::Bucket.new(config[:bucket], client: client)
79
79
  end
80
-
80
+
81
81
  def client
82
82
  @client ||= Aws::S3::Client.new(credentials: Aws::Credentials.new(config[:app_key], config[:app_secret]), region: config[:region])
83
83
  end
84
-
85
84
  end
86
85
  end
87
86
  end
@@ -1,3 +1,3 @@
1
1
  module BrowseEverything
2
- VERSION = '0.11.1'.freeze
2
+ VERSION = '0.12.0'.freeze
3
3
  end
@@ -14,12 +14,13 @@ describe 'Choosing files', type: :feature do
14
14
  click_button('Browse')
15
15
  sleep(5)
16
16
  click_link('Gemfile.lock')
17
+ check('config-ru')
17
18
  within('.modal-footer') do
18
- expect(page).to have_selector('span', text: '1 file selected')
19
+ expect(page).to have_selector('span', text: '2 files selected')
19
20
  click_button('Submit')
20
21
  end
21
22
  sleep(5)
22
- expect(page).to have_selector('#status', text: '1 items selected')
23
+ expect(page).to have_selector('#status', text: '2 items selected')
23
24
  end
24
25
  end
25
26
 
@@ -1,5 +1,5 @@
1
1
  describe 'Compiling the stylesheets', type: :feature do
2
- it 'should not raise errors' do
2
+ it 'does not raise errors' do
3
3
  visit '/'
4
4
  expect(page).not_to have_content 'Sass::SyntaxError'
5
5
  end
@@ -6,21 +6,18 @@ describe BrowseEverythingController, type: :controller do
6
6
  before(:all) { stub_configuration }
7
7
  after(:all) { unstub_configuration }
8
8
 
9
+ subject { helper_context.auth_link.scan(/state/) }
10
+
9
11
  let(:helper_context) { controller.view_context }
10
12
  let(:browser) { BrowseEverything::Browser.new(url_options) }
11
13
 
12
- before do
13
- allow(controller).to receive(:provider).and_return(provider)
14
- end
14
+ before { allow(controller).to receive(:provider).and_return(provider) }
15
15
 
16
16
  context 'dropbox' do
17
17
  let(:provider) { browser.providers['dropbox'] }
18
18
 
19
19
  describe 'auth_link' do
20
- subject { helper_context.auth_link }
21
- it 'has a single state' do
22
- expect(subject.scan(/state/).length).to eq 1
23
- end
20
+ its(:length) { is_expected.to eq(1) }
24
21
  end
25
22
  end
26
23
 
@@ -28,10 +25,7 @@ describe BrowseEverythingController, type: :controller do
28
25
  let(:provider) { browser.providers['box'] }
29
26
 
30
27
  describe 'auth_link' do
31
- subject { helper_context.auth_link }
32
- it 'has a single state' do
33
- expect(subject.scan(/state/).length).to eq 1
34
- end
28
+ its(:length) { is_expected.to eq(1) }
35
29
  end
36
30
  end
37
31
  end
@@ -1,25 +1,31 @@
1
1
  include BrowserConfigHelper
2
2
 
3
3
  describe BrowseEverything::Driver::Base do
4
- subject { BrowseEverything::Driver::Base.new({}) }
4
+ let(:driver) { described_class.new({}) }
5
5
 
6
6
  describe 'simple properties' do
7
- its(:name) { should == 'Base' }
8
- its(:key) { should == 'base' }
9
- its(:icon) { should be_a(String) }
10
- its(:auth_link) { should be_empty }
11
- specify { should_not be_authorized }
7
+ subject { driver }
8
+
9
+ its(:name) { is_expected.to eq('Base') }
10
+ its(:key) { is_expected.to eq('base') }
11
+ its(:icon) { is_expected.to be_a(String) }
12
+ its(:auth_link) { is_expected.to be_empty }
13
+ specify { is_expected.not_to be_authorized }
12
14
  end
13
- context '#connect' do
14
- specify { subject.connect({}, {}).should be_blank }
15
+ describe '#connect' do
16
+ subject { driver.connect({}, {}) }
17
+ it { is_expected.to be_blank }
15
18
  end
16
- context '#contents' do
17
- specify { subject.contents('').should be_empty }
19
+ describe '#contents' do
20
+ subject { driver.contents('') }
21
+ it { is_expected.to be_empty }
18
22
  end
19
- context '#details' do
20
- specify { subject.details('/path/to/foo.txt').should be_nil }
23
+ describe '#details' do
24
+ subject { driver.details('/path/to/foo.txt') }
25
+ it { is_expected.to be_nil }
21
26
  end
22
- context '#link_for' do
23
- specify { subject.link_for('/path/to/foo.txt').should == ['/path/to/foo.txt', { file_name: 'foo.txt' }] }
27
+ describe '#link_for' do
28
+ subject { driver.link_for('/path/to/foo.txt') }
29
+ it { is_expected.to contain_exactly('/path/to/foo.txt', file_name: 'foo.txt') }
24
30
  end
25
31
  end
@@ -11,27 +11,27 @@ describe BrowseEverythingHelper do
11
11
 
12
12
  let(:test_file) { BrowseEverything::FileEntry.new 0, '/path/to/file.mp4', 'file.mp4', 12345, Time.now, false }
13
13
 
14
- it 'should match a full type' do
14
+ it 'matches a full type' do
15
15
  expect(test_class.new(accept: 'video/mp4').is_acceptable?(test_file)).to eq(true)
16
16
  end
17
17
 
18
- it 'should match a wildcard type' do
18
+ it 'matches a wildcard type' do
19
19
  expect(test_class.new(accept: 'video/*').is_acceptable?(test_file)).to eq(true)
20
20
  end
21
21
 
22
- it 'should not match the wrong full type' do
22
+ it 'does not match the wrong full type' do
23
23
  expect(test_class.new(accept: 'video/mpeg').is_acceptable?(test_file)).to eq(false)
24
24
  end
25
25
 
26
- it 'should not match the wrong wildcard type' do
26
+ it 'does not match the wrong wildcard type' do
27
27
  expect(test_class.new(accept: 'audio/*').is_acceptable?(test_file)).to eq(false)
28
28
  end
29
29
 
30
- it 'should match a type list' do
30
+ it 'matches a type list' do
31
31
  expect(test_class.new(accept: 'audio/*, video/mp4').is_acceptable?(test_file)).to eq(true)
32
32
  end
33
33
 
34
- it 'should not match the wrong type list' do
34
+ it 'does not match the wrong type list' do
35
35
  expect(test_class.new(accept: 'audio/*, application/json').is_acceptable?(test_file)).to eq(false)
36
36
  end
37
37
  end
@@ -24,51 +24,53 @@ describe BrowseEverything::Browser do
24
24
  end
25
25
 
26
26
  describe 'file config' do
27
- before(:each) { allow(File).to receive(:read).and_return(file_config) }
28
- subject { BrowseEverything::Browser.new(url_options) }
27
+ let(:browser) { described_class.new(url_options) }
29
28
 
30
- it 'should have 2 providers' do
31
- expect(subject.providers.keys).to eq([:file_system, :dropbox])
29
+ before { allow(File).to receive(:read).and_return(file_config) }
30
+
31
+ it 'has 2 providers' do
32
+ expect(browser.providers.keys).to eq([:file_system, :dropbox])
32
33
  end
33
34
 
34
- it 'should use the file configuration' do
35
- expect(subject.providers[:dropbox].config[:app_key]).to eq('FileConfigKey')
35
+ it 'uses the file configuration' do
36
+ expect(browser.providers[:dropbox].config[:app_key]).to eq('FileConfigKey')
36
37
  end
37
38
  end
38
39
 
39
40
  describe 'global config' do
40
- before(:each) { BrowseEverything.configure(global_config) }
41
- subject { BrowseEverything::Browser.new(url_options) }
41
+ let(:browser) { described_class.new(url_options) }
42
+
43
+ before { BrowseEverything.configure(global_config) }
42
44
 
43
- it 'should have 2 providers' do
44
- expect(subject.providers.keys).to eq([:file_system, :dropbox])
45
+ it 'has 2 providers' do
46
+ expect(browser.providers.keys).to eq([:file_system, :dropbox])
45
47
  end
46
48
 
47
- it 'should use the global configuration' do
48
- expect(subject.providers[:dropbox].config[:app_key]).to eq('GlobalConfigKey')
49
+ it 'uses the global configuration' do
50
+ expect(browser.providers[:dropbox].config[:app_key]).to eq('GlobalConfigKey')
49
51
  end
50
52
  end
51
53
 
52
54
  describe 'local config' do
53
- subject { BrowseEverything::Browser.new(local_config) }
55
+ let(:browser) { described_class.new(local_config) }
54
56
 
55
- it 'should have 2 providers' do
56
- expect(subject.providers.keys).to eq([:file_system, :dropbox])
57
+ it 'has 2 providers' do
58
+ expect(browser.providers.keys).to eq([:file_system, :dropbox])
57
59
  end
58
60
 
59
- it 'should use the local configuration' do
60
- expect(subject.providers[:dropbox].config[:app_key]).to eq('LocalConfigKey')
61
+ it 'uses the local configuration' do
62
+ expect(browser.providers[:dropbox].config[:app_key]).to eq('LocalConfigKey')
61
63
  end
62
64
  end
63
65
 
64
66
  describe 'unknown provider' do
65
- subject do
66
- BrowseEverything::Browser.new(local_config.merge(foo: { key: 'bar', secret: 'baz' }))
67
+ let(:browser) do
68
+ described_class.new(local_config.merge(foo: { key: 'bar', secret: 'baz' }))
67
69
  end
68
70
 
69
- it 'should complain but continue' do
70
- allow(Rails.logger).to receive(:warn).with('Unknown provider: foo')
71
- expect(subject.providers.keys).to eq([:file_system, :dropbox])
71
+ it 'complains but continue' do
72
+ expect(Rails.logger).to receive(:warn).with('Unknown provider: foo')
73
+ expect(browser.providers.keys).to eq([:file_system, :dropbox])
72
74
  end
73
75
  end
74
76
  end
@@ -19,50 +19,48 @@ describe BrowseEverything::Driver::Dropbox, vcr: { cassette_name: 'dropbox', rec
19
19
 
20
20
  describe 'simple properties' do
21
21
  subject { provider }
22
- its(:name) { should == 'Dropbox' }
23
- its(:key) { should == 'dropbox' }
24
- its(:icon) { should be_a(String) }
22
+ its(:name) { is_expected.to eq('Dropbox') }
23
+ its(:key) { is_expected.to eq('dropbox') }
24
+ its(:icon) { is_expected.to be_a(String) }
25
25
  end
26
26
 
27
- context 'authorization' do
28
- subject { provider }
29
-
30
- specify { should_not be_authorized }
27
+ describe '#auth_link' do
28
+ subject { provider.auth_link[0] }
31
29
 
32
- context '#auth_link' do
33
- specify { subject.auth_link[0].should start_with('https://www.dropbox.com/1/oauth2/authorize') }
34
- specify { subject.auth_link[0].should include('browse%2Fconnect') }
35
- specify { subject.auth_link[0].should include('state') }
36
- end
30
+ it { is_expected.to start_with('https://www.dropbox.com/1/oauth2/authorize') }
31
+ it { is_expected.to include('browse%2Fconnect') }
32
+ it { is_expected.to include('state') }
33
+ end
37
34
 
38
- it 'should authorize' do
39
- subject.connect(auth_params, csrf_data)
40
- expect(subject).to be_authorized
41
- end
35
+ describe 'authorization' do
36
+ subject { provider }
37
+ before { provider.connect(auth_params, csrf_data) }
38
+ it { is_expected.to be_authorized }
42
39
  end
43
40
 
44
41
  describe '#contents' do
45
- before(:each) { provider.connect(auth_params, csrf_data) }
42
+ before { provider.connect(auth_params, csrf_data) }
46
43
 
47
44
  context 'root directory' do
48
45
  let(:contents) { provider.contents('') }
46
+
49
47
  context '[0]' do
50
48
  subject { contents[0] }
51
- its(:name) { should == 'Apps' }
52
- specify { should be_container }
49
+ its(:name) { is_expected.to eq('Apps') }
50
+ specify { is_expected.to be_container }
53
51
  end
54
52
  context '[1]' do
55
53
  subject { contents[1] }
56
- its(:name) { should == 'Books' }
57
- specify { should be_container }
54
+ its(:name) { is_expected.to eq('Books') }
55
+ specify { is_expected.to be_container }
58
56
  end
59
57
  context '[4]' do
60
58
  subject { contents[4] }
61
- its(:name) { should == 'iPad intro.pdf' }
62
- its(:size) { should == 208218 }
63
- its(:location) { should == 'dropbox:/iPad intro.pdf' }
64
- its(:type) { should == 'application/pdf' }
65
- specify { should_not be_container }
59
+ its(:name) { is_expected.to eq('iPad intro.pdf') }
60
+ its(:size) { is_expected.to eq(208218) }
61
+ its(:location) { is_expected.to eq('dropbox:/iPad intro.pdf') }
62
+ its(:type) { is_expected.to eq('application/pdf') }
63
+ specify { is_expected.not_to be_container }
66
64
  end
67
65
  end
68
66
 
@@ -70,51 +68,57 @@ describe BrowseEverything::Driver::Dropbox, vcr: { cassette_name: 'dropbox', rec
70
68
  let(:contents) { provider.contents('/Writer') }
71
69
  context '[0]' do
72
70
  subject { contents[0] }
73
- its(:name) { should == '..' }
74
- specify { should be_container }
71
+
72
+ its(:name) { is_expected.to eq('..') }
73
+ specify { is_expected.to be_container }
75
74
  end
76
75
  context '[1]' do
77
76
  subject { contents[1] }
78
- its(:name) { should == 'About Writer.txt' }
79
- its(:location) { should == 'dropbox:/Writer/About Writer.txt' }
80
- its(:type) { should == 'text/plain' }
81
- specify { should_not be_container }
77
+
78
+ its(:name) { is_expected.to eq('About Writer.txt') }
79
+ its(:location) { is_expected.to eq('dropbox:/Writer/About Writer.txt') }
80
+ its(:type) { is_expected.to eq('text/plain') }
81
+ specify { is_expected.not_to be_container }
82
82
  end
83
83
  context '[2]' do
84
84
  subject { contents[2] }
85
- its(:name) { should == 'Markdown Test.txt' }
86
- its(:location) { should == 'dropbox:/Writer/Markdown Test.txt' }
87
- its(:type) { should == 'text/plain' }
88
- specify { should_not be_container }
85
+
86
+ its(:name) { is_expected.to eq('Markdown Test.txt') }
87
+ its(:location) { is_expected.to eq('dropbox:/Writer/Markdown Test.txt') }
88
+ its(:type) { is_expected.to eq('text/plain') }
89
+ specify { is_expected.not_to be_container }
89
90
  end
90
91
  context '[3]' do
91
92
  subject { contents[3] }
92
- its(:name) { should == 'Writer FAQ.txt' }
93
- its(:location) { should == 'dropbox:/Writer/Writer FAQ.txt' }
94
- its(:type) { should == 'text/plain' }
95
- specify { should_not be_container }
93
+
94
+ its(:name) { is_expected.to eq('Writer FAQ.txt') }
95
+ its(:location) { is_expected.to eq('dropbox:/Writer/Writer FAQ.txt') }
96
+ its(:type) { is_expected.to eq('text/plain') }
97
+ specify { is_expected.not_to be_container }
96
98
  end
97
99
  end
98
100
 
99
101
  context '#details' do
100
102
  subject { provider.details('') }
101
- its(:name) { should == 'Apps' }
103
+ its(:name) { is_expected.to eq('Apps') }
102
104
  end
103
105
  end
104
106
 
105
107
  describe '#link_for' do
106
- before(:each) { provider.connect(auth_params, csrf_data) }
108
+ before { provider.connect(auth_params, csrf_data) }
107
109
 
108
110
  context '[0]' do
109
- subject { provider.link_for('/Writer/Writer FAQ.txt') }
110
- specify { subject[0].should == 'https://dl.dropboxusercontent.com/1/view/FakeDropboxAccessPath/Writer/Writer%20FAQ.txt' }
111
- specify { subject[1].should have_key(:expires) }
111
+ let(:link) { provider.link_for('/Writer/Writer FAQ.txt') }
112
+
113
+ specify { expect(link[0]).to eq('https://dl.dropboxusercontent.com/1/view/FakeDropboxAccessPath/Writer/Writer%20FAQ.txt') }
114
+ specify { expect(link[1]).to have_key(:expires) }
112
115
  end
113
116
 
114
117
  context '[1]' do
115
- subject { provider.link_for('/Writer/Markdown Test.txt') }
116
- specify { subject[0].should == 'https://dl.dropboxusercontent.com/1/view/FakeDropboxAccessPath/Writer/Markdown%20Test.txt' }
117
- specify { subject[1].should have_key(:expires) }
118
+ let(:link) { provider.link_for('/Writer/Markdown Test.txt') }
119
+
120
+ specify { expect(link[0]).to eq('https://dl.dropboxusercontent.com/1/view/FakeDropboxAccessPath/Writer/Markdown%20Test.txt') }
121
+ specify { expect(link[1]).to have_key(:expires) }
118
122
  end
119
123
  end
120
124
  end