browse-everything 0.15.1 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +61 -9
  3. data/.rubocop_todo.yml +2 -15
  4. data/.travis.yml +19 -19
  5. data/CONTRIBUTING.md +6 -6
  6. data/Gemfile +12 -8
  7. data/README.md +30 -0
  8. data/Rakefile +2 -1
  9. data/app/assets/javascripts/browse_everything/behavior.js.coffee +5 -0
  10. data/app/controllers/browse_everything_controller.rb +75 -23
  11. data/app/helpers/browse_everything_helper.rb +2 -8
  12. data/app/helpers/font_awesome_version_helper.rb +9 -8
  13. data/app/services/browse_everything_session.rb +10 -0
  14. data/app/services/browse_everything_session/provider_session.rb +42 -0
  15. data/app/services/browser_factory.rb +25 -0
  16. data/app/views/browse_everything/_files.html.erb +56 -6
  17. data/browse-everything.gemspec +29 -25
  18. data/config/routes.rb +7 -2
  19. data/lib/browse-everything.rb +2 -0
  20. data/lib/browse_everything.rb +45 -12
  21. data/lib/browse_everything/auth/google/credentials.rb +28 -0
  22. data/lib/browse_everything/auth/google/request_parameters.rb +61 -0
  23. data/lib/browse_everything/browser.rb +11 -4
  24. data/lib/browse_everything/driver/authentication_factory.rb +22 -0
  25. data/lib/browse_everything/driver/base.rb +72 -19
  26. data/lib/browse_everything/driver/box.rb +46 -17
  27. data/lib/browse_everything/driver/dropbox.rb +36 -10
  28. data/lib/browse_everything/driver/file_system.rb +14 -26
  29. data/lib/browse_everything/driver/google_drive.rb +187 -54
  30. data/lib/browse_everything/driver/s3.rb +81 -75
  31. data/lib/browse_everything/engine.rb +3 -2
  32. data/lib/browse_everything/file_entry.rb +3 -1
  33. data/lib/browse_everything/retriever.rb +103 -31
  34. data/lib/browse_everything/version.rb +3 -1
  35. data/lib/generators/browse_everything/assets_generator.rb +3 -2
  36. data/lib/generators/browse_everything/config_generator.rb +11 -9
  37. data/lib/generators/browse_everything/install_generator.rb +3 -2
  38. data/lib/generators/browse_everything/templates/browse_everything_providers.yml.example +12 -11
  39. data/spec/controllers/browse_everything_controller_spec.rb +80 -0
  40. data/spec/features/select_files_spec.rb +13 -13
  41. data/spec/features/test_compiling_stylesheets_spec.rb +2 -0
  42. data/spec/fixtures/vcr_cassettes/google_drive.yml +331 -0
  43. data/spec/fixtures/vcr_cassettes/retriever.yml +93 -0
  44. data/spec/helper/browse_everything_controller_helper_spec.rb +21 -7
  45. data/spec/javascripts/jasmine_spec.rb +2 -0
  46. data/spec/javascripts/support/jasmine_helper.rb +1 -0
  47. data/spec/lib/browse_everything/auth/google/credentials_spec.rb +41 -0
  48. data/spec/{unit → lib/browse_everything}/browse_everything_helper_spec.rb +2 -0
  49. data/spec/lib/browse_everything/browser_spec.rb +109 -0
  50. data/spec/{unit → lib/browse_everything/driver}/base_spec.rb +5 -4
  51. data/spec/{unit → lib/browse_everything/driver}/box_spec.rb +20 -5
  52. data/spec/{unit → lib/browse_everything/driver}/dropbox_spec.rb +15 -18
  53. data/spec/{unit → lib/browse_everything/driver}/file_system_spec.rb +32 -26
  54. data/spec/lib/browse_everything/driver/google_drive_spec.rb +171 -0
  55. data/spec/{unit → lib/browse_everything/driver}/s3_spec.rb +38 -21
  56. data/spec/lib/browse_everything/driver_spec.rb +38 -0
  57. data/spec/{unit → lib/browse_everything}/file_entry_spec.rb +4 -1
  58. data/spec/lib/browse_everything/retriever_spec.rb +200 -0
  59. data/spec/lib/browse_everything_spec.rb +67 -0
  60. data/spec/services/browse_everything_session/provider_session_spec.rb +50 -0
  61. data/spec/services/browser_factory_spec.rb +40 -0
  62. data/spec/spec_helper.rb +39 -18
  63. data/spec/support/app/controllers/file_handler_controller.rb +4 -4
  64. data/spec/support/app/views/file_handler/main.html.erb +1 -1
  65. data/spec/support/capybara.rb +17 -0
  66. data/spec/support/rake.rb +3 -1
  67. data/spec/support/wait_for_ajax.rb +14 -0
  68. data/spec/test_app_templates/Gemfile.extra +1 -0
  69. data/spec/test_app_templates/lib/generators/test_app_generator.rb +10 -4
  70. data/spec/views/browse_everything/{_file.html.erb_spec.rb → _files.html.erb_spec.rb} +24 -18
  71. data/tasks/ci.rake +2 -0
  72. metadata +159 -107
  73. data/app/views/browse_everything/_file.html.erb +0 -52
  74. data/app/views/browse_everything/resolve.html.erb +0 -1
  75. data/spec/unit/browser_spec.rb +0 -76
  76. data/spec/unit/retriever_spec.rb +0 -109
@@ -1,52 +0,0 @@
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?
3
- disabled = false
4
- else
5
- max_size = provider.config[:max_upload_file_size].to_i
6
- disabled = file.size > max_size
7
- end
8
- %>
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
-
15
- <td role="gridcell" title="<%= file.name %>" class="<%=file.container? ? 'ev-container' : 'ev-file'%> ev-file-name">
16
- <% if disabled %>
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 %>
20
- </span>
21
- <span class="sr-only"><%= file.container? ? ', folder' : ', file' %> </span>
22
- <% else %>
23
- <%= link_to browse_everything_engine.contents_path(provider_name, file.id), class: 'ev-link' do %>
24
- <span class="<%=file.container? ? 'folder' : 'file'%>" aria-hidden="true"/>
25
- <%= file.name %>
26
- <span class="sr-only"><%= file.container? ? ', folder' : ', file' %> </span>
27
- <% end %>
28
- <% end %>
29
- </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
-
41
- <td role="gridcell" class="ev-file-size">
42
- <%= number_to_human_size(file.size).sub(/Bytes/,'bytes') %>
43
- </td>
44
-
45
- <td role="gridcell" class="ev-file-kind">
46
- <%= file.type %>
47
- </td>
48
-
49
- <td role="gridcell" class="ev-file-date">
50
- <%= file.mtime.strftime('%F %R') %>
51
- </td>
52
- </tr>
@@ -1 +0,0 @@
1
- <%= array_to_hidden_fields(@links,'selected_files') %>
@@ -1,76 +0,0 @@
1
- include BrowserConfigHelper
2
-
3
- describe BrowseEverything::Browser do
4
- let(:file_config) do
5
- {
6
- file_system: { home: '/file/config/home' },
7
- dropbox: { client_id: 'DropboxId', client_secret: 'DropboxClientSecret' }
8
- }.to_yaml
9
- end
10
-
11
- let(:global_config) do
12
- {
13
- file_system: { home: '/global/config/home' },
14
- dropbox: { client_id: 'DropboxId', client_secret: 'DropboxClientSecret' }
15
- }
16
- end
17
-
18
- let(:local_config) do
19
- {
20
- file_system: { home: '/local/config/home' },
21
- dropbox: { client_id: 'DropboxId', client_secret: 'DropboxClientSecret' },
22
- url_options: url_options
23
- }
24
- end
25
-
26
- describe 'file config' do
27
- let(:browser) { described_class.new(url_options) }
28
-
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])
33
- end
34
-
35
- it 'uses the file configuration' do
36
- expect(browser.providers[:file_system].config[:home]).to eq('/file/config/home')
37
- end
38
- end
39
-
40
- describe 'global config' do
41
- let(:browser) { described_class.new(url_options) }
42
-
43
- before { BrowseEverything.configure(global_config) }
44
-
45
- it 'has 2 providers' do
46
- expect(browser.providers.keys).to eq([:file_system, :dropbox])
47
- end
48
-
49
- it 'uses the global configuration' do
50
- expect(browser.providers[:file_system].config[:home]).to eq('/global/config/home')
51
- end
52
- end
53
-
54
- describe 'local config' do
55
- let(:browser) { described_class.new(local_config) }
56
-
57
- it 'has 2 providers' do
58
- expect(browser.providers.keys).to eq([:file_system, :dropbox])
59
- end
60
-
61
- it 'uses the local configuration' do
62
- expect(browser.providers[:file_system].config[:home]).to eq('/local/config/home')
63
- end
64
- end
65
-
66
- describe 'unknown provider' do
67
- let(:browser) do
68
- described_class.new(local_config.merge(foo: { key: 'bar', secret: 'baz' }))
69
- end
70
-
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])
74
- end
75
- end
76
- end
@@ -1,109 +0,0 @@
1
- describe BrowseEverything::Retriever, vcr: { cassette_name: 'retriever', record: :none } do
2
- let(:retriever) { described_class.new }
3
- let(:datafile) { File.expand_path('../../fixtures/file_system/file_1.pdf', __FILE__) }
4
- let(:datafile_with_spaces) { File.expand_path('../../fixtures/file_system/file 1.pdf', __FILE__) }
5
- let(:data) { File.open(datafile, 'rb', &:read) }
6
- let(:data_with_spaces) { File.open(datafile_with_spaces, 'rb', &:read) }
7
- let(:size) { File.size(datafile) }
8
-
9
- context 'with a non-URI' do
10
- let(:spec) do
11
- {
12
- '0' => {
13
- 'url' => '/some/dir/file.pdf',
14
- 'file_name' => 'file.pdf',
15
- 'file_size' => size.to_s
16
- }
17
- }
18
- end
19
-
20
- describe '#retrieve' do
21
- it 'raises an error' do
22
- expect { retriever.retrieve(spec['0']) }.to raise_error(URI::BadURIError)
23
- end
24
- end
25
- end
26
-
27
- context 'http://' do
28
- let(:spec) do
29
- {
30
- '0' => {
31
- 'url' => 'https://retrieve.cloud.example.com/some/dir/file.pdf',
32
- 'auth_header' => { 'Authorization' => 'Bearer ya29.kQCEAHj1bwFXr2AuGQJmSGRWQXpacmmYZs4kzCiXns3d6H1ZpIDWmdM8' },
33
- 'expires' => (Time.now + 3600).xmlschema,
34
- 'file_name' => 'file.pdf',
35
- 'file_size' => size.to_s
36
- }
37
- }
38
- end
39
-
40
- context '#retrieve' do
41
- it 'content' do
42
- content = ''
43
- retriever.retrieve(spec['0']) { |chunk, _retrieved, _total| content << chunk }
44
- expect(content).to eq(data)
45
- end
46
-
47
- it 'callbacks' do
48
- expect { |block| retriever.retrieve(spec['0'], &block) }.to yield_with_args(data, data.length, data.length)
49
- end
50
- end
51
-
52
- context '#download' do
53
- it 'content' do
54
- file = retriever.download(spec['0'])
55
- expect(File.open(file, 'rb', &:read)).to eq(data)
56
- end
57
-
58
- it 'callbacks' do
59
- expect { |block| retriever.download(spec['0'], &block) }.to yield_with_args(String, data.length, data.length)
60
- end
61
- end
62
- end
63
-
64
- context 'file://' do
65
- let(:spec) do
66
- {
67
- '0' => {
68
- 'url' => "file://#{datafile}",
69
- 'file_name' => 'file.pdf',
70
- 'file_size' => size.to_s
71
- },
72
- '1' => {
73
- 'url' => "file://#{datafile_with_spaces}",
74
- 'file_name' => 'file.pdf',
75
- 'file_size' => size.to_s
76
- }
77
- }
78
- end
79
-
80
- context '#retrieve' do
81
- it 'content' do
82
- content = ''
83
- retriever.retrieve(spec['0']) { |chunk, _retrieved, _total| content << chunk }
84
- expect(content).to eq(data)
85
- end
86
-
87
- it 'content with spaces' do
88
- content = ''
89
- retriever.retrieve(spec['1']) { |chunk, _retrieved, _total| content << chunk }
90
- expect(content).to eq(data_with_spaces)
91
- end
92
-
93
- it 'callbacks' do
94
- expect { |block| retriever.retrieve(spec['0'], &block) }.to yield_with_args(data, data.length, data.length)
95
- end
96
- end
97
-
98
- context '#download' do
99
- it 'content' do
100
- file = retriever.download(spec['0'])
101
- expect(File.open(file, 'rb', &:read)).to eq(data)
102
- end
103
-
104
- it 'callbacks' do
105
- expect { |block| retriever.download(spec['0'], &block) }.to yield_with_args(String, data.length, data.length)
106
- end
107
- end
108
- end
109
- end