Skip to content

Commit

Permalink
Update rubocop and enable for Travis build
Browse files Browse the repository at this point in the history
Pins version to 0.42.x which aligns with the current Sufia versions for rubocop and rubocop-rspec.

rubocop_todo was updated using --auto-gen-config and can serve as a starting point for future refactorings.
  • Loading branch information
awead committed Feb 28, 2017
1 parent 1db9aee commit ffbbf7c
Show file tree
Hide file tree
Showing 17 changed files with 326 additions and 317 deletions.
18 changes: 15 additions & 3 deletions .rubocop.yml
@@ -1,16 +1,28 @@
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 2.1
DisplayCopNames: true
Include:
- '**/Rakefile'
Exclude:
- db/migrate/**
- db/schema.rb
- 'vendor/**/*'

Rails:
Enabled: true

# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 180
Max: 400

RSpec/NestedGroups:
Enabled: false

RSpec/FilePath:
Enabled: false

RSpec/LeadingSubject:
Enabled: false

Style/NumericLiterals:
MinDigits: 7
45 changes: 28 additions & 17 deletions .rubocop_todo.yml
@@ -1,6 +1,8 @@
require: rubocop-rspec

# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-09-28 11:47:17 -0700 using RuboCop version 0.42.0.
# on 2017-02-28 11:01:25 -0500 using RuboCop version 0.42.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -11,14 +13,9 @@ Lint/Loop:
Exclude:
- 'lib/browse_everything/driver/google_drive.rb'

# Offense count: 10
# Offense count: 11
Metrics/AbcSize:
Max: 32

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 101
Max: 43

# Offense count: 3
Metrics/CyclomaticComplexity:
Expand All @@ -38,6 +35,28 @@ Metrics/ParameterLists:
Metrics/PerceivedComplexity:
Max: 9

# Offense count: 1
RSpec/DescribeClass:
Exclude:
- 'spec/javascripts/jasmine_spec.rb'

# Offense count: 2
# Configuration parameters: Max.
RSpec/ExampleLength:
Exclude:
- 'spec/features/select_files_spec.rb'
- 'spec/javascripts/jasmine_spec.rb'

# Offense count: 2
RSpec/MultipleExpectations:
Max: 2

# Offense count: 1
# Configuration parameters: IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Exclude:
- 'spec/views/browse_everything/_file.html.erb_spec.rb'

# Offense count: 1
Rails/OutputSafety:
Exclude:
Expand Down Expand Up @@ -68,7 +87,7 @@ Style/ClassAndModuleChildren:
- 'lib/generators/browse_everything/config_generator.rb'
- 'lib/generators/browse_everything/install_generator.rb'

# Offense count: 18
# Offense count: 19
Style/Documentation:
Enabled: false

Expand Down Expand Up @@ -139,11 +158,3 @@ Style/RegexpLiteral:
Style/RescueModifier:
Exclude:
- 'lib/browse_everything/driver/file_system.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: use_perl_names, use_english_names
Style/SpecialGlobalVars:
Exclude:
- 'browse-everything.gemspec'
3 changes: 2 additions & 1 deletion browse-everything.gemspec
Expand Up @@ -34,7 +34,8 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rspec-rails'
spec.add_development_dependency 'rspec-its'
spec.add_development_dependency 'rubocop'
spec.add_development_dependency 'rubocop', '~> 0.42.0'
spec.add_development_dependency 'rubocop-rspec', '~> 1.8.0'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'bundler', '~> 1.3'
spec.add_development_dependency 'pry'
Expand Down
39 changes: 19 additions & 20 deletions lib/browse_everything/driver/s3.rb
Expand Up @@ -3,35 +3,35 @@
module BrowseEverything
module Driver
class S3 < Base
DEFAULTS = { signed_url: true, region: 'us-east-1' }

def initialize config, *args
DEFAULTS = { signed_url: true, region: 'us-east-1' }.freeze
CONFIG_KEYS = [:app_key, :app_secret, :bucket].freeze

def initialize(config, *args)
config = DEFAULTS.merge(config)
super
end

def icon
'amazon'
end

def validate_config
unless [:app_key, :app_secret, :bucket].all? { |key| config[key].present? }
raise BrowseEverything::InitializationError, 'Amazon S3 driver requires :bucket, :app_key and :app_secret'
end
return if CONFIG_KEYS.all? { |key| config[key].present? }
raise BrowseEverything::InitializationError, "Amazon S3 driver requires #{CONFIG_KEYS.join(',')}"
end

def contents(path = '')
path = File.join(path,'') unless path.empty?
path = File.join(path, '') unless path.empty?
result = []
listing = client.list_objects(bucket: config[:bucket], delimiter: '/', prefix: path)
unless path.empty?
result << BrowseEverything::FileEntry.new(
Pathname(path).join('..'),
'', '..', 0, Time.now, true
'', '..', 0, Time.current, true
)
end
listing.common_prefixes.each do |prefix|
result << entry_for(prefix.prefix, 0, Time.now, true)
result << entry_for(prefix.prefix, 0, Time.current, true)
end
listing.contents.reject { |entry| entry.key == path }.each do |entry|
result << entry_for(entry.key, entry.size, entry.last_modified, false)
Expand All @@ -46,21 +46,21 @@ def contents(path = '')
end

def entry_for(name, size, date, dir)
BrowseEverything::FileEntry.new(name, [key,name].join(':'), File.basename(name), size, date, dir)
BrowseEverything::FileEntry.new(name, [key, name].join(':'), File.basename(name), size, date, dir)
end

def details(path)
entry = client.head_object(path)
BrowseEverything::FileEntry.new(
entry.key,
[key,entry.key].join(':'),
[key, entry.key].join(':'),
File.basename(entry.key),
entry.size,
entry.last_modified,
false
)
end

def link_for(path)
obj = bucket.object(path)
if config[:signed_url]
Expand All @@ -69,19 +69,18 @@ def link_for(path)
obj.public_url
end
end

def authorized?
true
end

def bucket
@bucket ||= Aws::S3::Bucket.new(config[:bucket], client: client)
end

def client
@client ||= Aws::S3::Client.new(credentials: Aws::Credentials.new(config[:app_key], config[:app_secret]), region: config[:region])
end

end
end
end
2 changes: 1 addition & 1 deletion spec/features/test_compiling_stylesheets_spec.rb
@@ -1,5 +1,5 @@
describe 'Compiling the stylesheets', type: :feature do
it 'should not raise errors' do
it 'does not raise errors' do
visit '/'
expect(page).not_to have_content 'Sass::SyntaxError'
end
Expand Down
16 changes: 5 additions & 11 deletions spec/helper/browse_everything_controller_helper_spec.rb
Expand Up @@ -6,32 +6,26 @@
before(:all) { stub_configuration }
after(:all) { unstub_configuration }

subject { helper_context.auth_link.scan(/state/) }

let(:helper_context) { controller.view_context }
let(:browser) { BrowseEverything::Browser.new(url_options) }

before do
allow(controller).to receive(:provider).and_return(provider)
end
before { allow(controller).to receive(:provider).and_return(provider) }

context 'dropbox' do
let(:provider) { browser.providers['dropbox'] }

describe 'auth_link' do
subject { helper_context.auth_link }
it 'has a single state' do
expect(subject.scan(/state/).length).to eq 1
end
its(:length) { is_expected.to eq(1) }
end
end

context 'box' do
let(:provider) { browser.providers['box'] }

describe 'auth_link' do
subject { helper_context.auth_link }
it 'has a single state' do
expect(subject.scan(/state/).length).to eq 1
end
its(:length) { is_expected.to eq(1) }
end
end
end
34 changes: 20 additions & 14 deletions spec/unit/base_spec.rb
@@ -1,25 +1,31 @@
include BrowserConfigHelper

describe BrowseEverything::Driver::Base do
subject { BrowseEverything::Driver::Base.new({}) }
let(:driver) { described_class.new({}) }

describe 'simple properties' do
its(:name) { should == 'Base' }
its(:key) { should == 'base' }
its(:icon) { should be_a(String) }
its(:auth_link) { should be_empty }
specify { should_not be_authorized }
subject { driver }

its(:name) { is_expected.to eq('Base') }
its(:key) { is_expected.to eq('base') }
its(:icon) { is_expected.to be_a(String) }
its(:auth_link) { is_expected.to be_empty }
specify { is_expected.not_to be_authorized }
end
context '#connect' do
specify { subject.connect({}, {}).should be_blank }
describe '#connect' do
subject { driver.connect({}, {}) }
it { is_expected.to be_blank }
end
context '#contents' do
specify { subject.contents('').should be_empty }
describe '#contents' do
subject { driver.contents('') }
it { is_expected.to be_empty }
end
context '#details' do
specify { subject.details('/path/to/foo.txt').should be_nil }
describe '#details' do
subject { driver.details('/path/to/foo.txt') }
it { is_expected.to be_nil }
end
context '#link_for' do
specify { subject.link_for('/path/to/foo.txt').should == ['/path/to/foo.txt', { file_name: 'foo.txt' }] }
describe '#link_for' do
subject { driver.link_for('/path/to/foo.txt') }
it { is_expected.to contain_exactly('/path/to/foo.txt', file_name: 'foo.txt') }
end
end
12 changes: 6 additions & 6 deletions spec/unit/browse_everything_helper_spec.rb
Expand Up @@ -11,27 +11,27 @@ def initialize(params)

let(:test_file) { BrowseEverything::FileEntry.new 0, '/path/to/file.mp4', 'file.mp4', 12345, Time.now, false }

it 'should match a full type' do
it 'matches a full type' do
expect(test_class.new(accept: 'video/mp4').is_acceptable?(test_file)).to eq(true)
end

it 'should match a wildcard type' do
it 'matches a wildcard type' do
expect(test_class.new(accept: 'video/*').is_acceptable?(test_file)).to eq(true)
end

it 'should not match the wrong full type' do
it 'does not match the wrong full type' do
expect(test_class.new(accept: 'video/mpeg').is_acceptable?(test_file)).to eq(false)
end

it 'should not match the wrong wildcard type' do
it 'does not match the wrong wildcard type' do
expect(test_class.new(accept: 'audio/*').is_acceptable?(test_file)).to eq(false)
end

it 'should match a type list' do
it 'matches a type list' do
expect(test_class.new(accept: 'audio/*, video/mp4').is_acceptable?(test_file)).to eq(true)
end

it 'should not match the wrong type list' do
it 'does not match the wrong type list' do
expect(test_class.new(accept: 'audio/*, application/json').is_acceptable?(test_file)).to eq(false)
end
end

0 comments on commit ffbbf7c

Please sign in to comment.