Merge pull request #3 from opf/feature/houndci-config-ruby-style

Add Hound/Rubocop config; Make Ruby style consistent
pull/6827/head
linki 10 years ago
commit fc4ba6f627
  1. 3
      .hound.yml
  2. 265
      .rubocop.yml
  3. 8
      lib/open_project/auth_plugins.rb
  4. 4
      lib/open_project/auth_plugins/engine.rb
  5. 2
      lib/open_project/auth_plugins/hooks.rb
  6. 2
      lib/open_project/auth_plugins/version.rb
  7. 8
      lib/open_project/plugins/auth_plugin.rb
  8. 22
      openproject-auth_plugins.gemspec
  9. 8
      spec/requests/auth_plugins.rb
  10. 18
      spec/requests/flexible_strategy_spec.rb
  11. 8
      spec/views/hooks/login/_providers.html.erb_spec.rb

@ -0,0 +1,3 @@
ruby:
enabled: true
config_file: .rubocop.yml

@ -0,0 +1,265 @@
AllCops:
Exclude:
- *.gemspec
AccessorMethodName:
Enabled: false
ActionFilter:
Enabled: false
Alias:
Enabled: false
AndOr:
Enabled: false
ArrayJoin:
Enabled: false
AsciiComments:
Enabled: false
AsciiIdentifiers:
Enabled: false
Attr:
Enabled: false
BlockNesting:
Enabled: false
Blocks:
Enabled: false
CaseEquality:
Enabled: false
CharacterLiteral:
Enabled: false
ClassAndModuleChildren:
Enabled: false
ClassLength:
Enabled: false
ClassVars:
Enabled: false
CollectionMethods:
PreferredMethods:
find: detect
reduce: inject
collect: map
find_all: select
ColonMethodCall:
Enabled: false
CommentAnnotation:
Enabled: false
CyclomaticComplexity:
Enabled: false
Delegate:
Enabled: false
DeprecatedHashMethods:
Enabled: false
Documentation:
Enabled: false
DotPosition:
EnforcedStyle: leading
DoubleNegation:
Enabled: false
EachWithObject:
Enabled: false
EmptyLiteral:
Enabled: false
Encoding:
Enabled: false
EvenOdd:
Enabled: false
FileName:
Enabled: false
FlipFlop:
Enabled: false
FormatString:
Enabled: false
GlobalVars:
Enabled: false
GuardClause:
Enabled: false
IfUnlessModifier:
Enabled: false
IfWithSemicolon:
Enabled: false
InlineComment:
Enabled: false
Lambda:
Enabled: false
LambdaCall:
Enabled: false
LineEndConcatenation:
Enabled: false
LineLength:
Max: 100
MethodLength:
Enabled: false
ModuleFunction:
Enabled: false
NegatedIf:
Enabled: false
NegatedWhile:
Enabled: false
Next:
Enabled: false
NilComparison:
Enabled: false
Not:
Enabled: false
NumericLiterals:
Enabled: false
OneLineConditional:
Enabled: false
OpMethod:
Enabled: false
ParameterLists:
Enabled: false
PercentLiteralDelimiters:
Enabled: false
PerlBackrefs:
Enabled: false
PredicateName:
NamePrefixBlacklist:
- is_
Proc:
Enabled: false
RaiseArgs:
Enabled: false
RegexpLiteral:
Enabled: false
SelfAssignment:
Enabled: false
SingleLineBlockParams:
Enabled: false
SingleLineMethods:
Enabled: false
SignalException:
Enabled: false
SpecialGlobalVars:
Enabled: false
StringLiterals:
EnforcedStyle: single_quotes
VariableInterpolation:
Enabled: false
TrailingComma:
Enabled: false
TrivialAccessors:
Enabled: false
VariableInterpolation:
Enabled: false
WhenThen:
Enabled: false
WhileUntilModifier:
Enabled: false
WordArray:
Enabled: false
# Lint
AmbiguousOperator:
Enabled: false
AmbiguousRegexpLiteral:
Enabled: false
AssignmentInCondition:
Enabled: false
ConditionPosition:
Enabled: false
DeprecatedClassMethods:
Enabled: false
ElseLayout:
Enabled: false
HandleExceptions:
Enabled: false
InvalidCharacterLiteral:
Enabled: false
LiteralInCondition:
Enabled: false
LiteralInInterpolation:
Enabled: false
Loop:
Enabled: false
ParenthesesAsGroupedExpression:
Enabled: false
RequireParentheses:
Enabled: false
UnderscorePrefixedVariableName:
Enabled: false
Void:
Enabled: false

@ -29,9 +29,9 @@
module OpenProject
module AuthPlugins
require "open_project/plugins/auth_plugin"
require "omniauth/flexible_builder"
require "omniauth/flexible_strategy"
require "open_project/auth_plugins/engine"
require 'open_project/plugins/auth_plugin'
require 'omniauth/flexible_builder'
require 'omniauth/flexible_strategy'
require 'open_project/auth_plugins/engine'
end
end

@ -36,8 +36,8 @@ module OpenProject::AuthPlugins
include OpenProject::Plugins::ActsAsOpEngine
register 'openproject-auth_plugins',
:author_url => 'http://finn.de',
:requires_openproject => '>= 3.1.0pre1'
author_url: 'http://finn.de',
requires_openproject: '>= 3.1.0pre1'
initializer 'auth_plugins.register_hooks' do
require 'open_project/auth_plugins/hooks'

@ -29,6 +29,6 @@
module OpenProject::AuthPlugins
class Hooks < Redmine::Hook::ViewListener
render_on :view_account_login_auth_provider, :partial => 'hooks/login/providers'
render_on :view_account_login_auth_provider, partial: 'hooks/login/providers'
end
end

@ -29,6 +29,6 @@
module OpenProject
module AuthPlugins
VERSION = "4.1.0"
VERSION = '4.1.0'
end
end

@ -47,20 +47,20 @@ module OpenProject::Plugins
end
def self.providers_for(strategy)
strategies[strategy_key(strategy)].map(&:call).flatten.map { |p| p.to_hash }
strategies[strategy_key(strategy)].map(&:call).flatten.map(&:to_hash)
end
def self.providers
strategies.values.flatten.map(&:call).flatten.map { |p| p.to_hash }
strategies.values.flatten.map(&:call).flatten.map(&:to_hash)
end
def self.strategy_key(strategy)
return strategy if strategy.is_a? Symbol
name = strategy.name.demodulize
camelization = OmniAuth.config.camelizations.select do |k, v|
camelization = OmniAuth.config.camelizations.select do |_k, v|
v == name
end.take(1).map do |k, v|
end.take(1).map do |k, _v|
k
end.first

@ -1,22 +1,22 @@
# encoding: UTF-8
$:.push File.expand_path("../lib", __FILE__)
$:.push File.expand_path('../lib', __FILE__)
require 'open_project/auth_plugins/version'
Gem::Specification.new do |s|
s.name = "openproject-auth_plugins"
s.name = 'openproject-auth_plugins'
s.version = OpenProject::AuthPlugins::VERSION
s.authors = "Finn GmbH"
s.email = "info@finn.de"
s.homepage = "https://www.openproject.org/projects/auth-plugins"
s.authors = 'Finn GmbH'
s.email = 'info@finn.de'
s.homepage = 'https://www.openproject.org/projects/auth-plugins'
s.summary = 'OpenProject Auth Plugins'
s.description = "Integration of OmniAuth strategy providers for authentication in Openproject."
s.license = "GPLv3"
s.description = 'Integration of OmniAuth strategy providers for authentication in Openproject.'
s.license = 'GPLv3'
s.files = Dir["{app,config,db,lib}/**/*"] + %w(doc/CHANGELOG.md README.md)
s.files = Dir['{app,config,db,lib}/**/*'] + %w(doc/CHANGELOG.md README.md)
s.add_dependency "rails", "~> 3.2.14"
s.add_dependency "omniauth", "~> 1.0"
s.add_dependency 'rails', '~> 3.2.14'
s.add_dependency 'omniauth', '~> 1.0'
s.add_development_dependency "rspec", "~> 2.14"
s.add_development_dependency 'rspec', '~> 2.14'
end

@ -37,13 +37,13 @@ describe OpenProject::Plugins::AuthPlugin do
let(:strategies) { {} }
let(:providers_a) do
lambda { [{name: 'a1'}, {name: 'a2'}] }
lambda { [{ name: 'a1' }, { name: 'a2' }] }
end
let(:providers_b) do
lambda { [{name: 'b1'}] }
lambda { [{ name: 'b1' }] }
end
let(:providers_c) do
lambda { [{name: 'c1'}] }
lambda { [{ name: 'c1' }] }
end
let(:middlewares) { [] }
@ -56,7 +56,7 @@ describe OpenProject::Plugins::AuthPlugin do
middlewares << strategy
}
app.stub_chain(:config, :middleware, :use) { |mw, &block|
app.stub_chain(:config, :middleware, :use) { |_mw, &block|
omniauth_builder.instance_eval(&block)
}

@ -38,16 +38,16 @@ describe OmniAuth::FlexibleStrategy do
end
end
def env_for(url, opts={})
def env_for(url, opts = {})
Rack::MockRequest.env_for(url, opts).tap do |env|
env['rack.session'] = {}
end
end
let(:app) { ->(env) { [200, env, "ok"] } }
let(:app) { ->(env) { [200, env, 'ok'] } }
let(:middleware) { MockStrategy.new(app) }
let(:provider_a) { {name: 'provider_a', identifier: 'a'} }
let(:provider_b) { {name: 'provider_b', identifier: 'b'} }
let(:provider_a) { { name: 'provider_a', identifier: 'a' } }
let(:provider_b) { { name: 'provider_b', identifier: 'b' } }
before do
allow(OpenProject::Plugins::AuthPlugin).to receive(:providers_for).with(MockStrategy) {
@ -67,7 +67,7 @@ describe OmniAuth::FlexibleStrategy do
end
it 'should not match other paths' do
code, env = middleware.call env_for("http://www.example.com/auth/other_provider")
code, env = middleware.call env_for('http://www.example.com/auth/other_provider')
expect(env).not_to include 'omniauth.strategy' # no hit
end
@ -87,7 +87,7 @@ describe OmniAuth::FlexibleStrategy do
end
it 'should not match other paths' do
code, env = middleware.call env_for("http://www.example.com/auth/other_provider/callback")
code, env = middleware.call env_for('http://www.example.com/auth/other_provider/callback')
expect(code).to eq 200
expect(env).not_to include 'omniauth.strategy' # no hit
@ -116,16 +116,16 @@ describe OmniAuth::FlexibleStrategy do
context 'with a mapping set' do
it 'returns an attribute hash' do
middleware.call env_for("http://www.example.com/auth/provider_with_mapping")
middleware.call env_for('http://www.example.com/auth/provider_with_mapping')
attribute_map = middleware.omniauth_hash_to_user_attributes(auth_hash)
expect(attribute_map).to eq({ uid: 'foo', mail: 'foo@example.com' })
expect(attribute_map).to eq(uid: 'foo', mail: 'foo@example.com')
end
end
context 'without a mapping set' do
it 'returns an empty hash' do
middleware.call env_for("http://www.example.com/auth/provider_a")
middleware.call env_for('http://www.example.com/auth/provider_a')
attribute_map = middleware.omniauth_hash_to_user_attributes(auth_hash)
expect(attribute_map).to eq({})

@ -31,16 +31,16 @@ require 'spec_helper'
describe 'rendering the login buttons for all providers' do
let(:providers) do
[
{name: 'mock_auth'},
{name: 'test_auth', display_name: 'Test'},
{name: 'foob_auth', icon: 'foobar.png'}
{ name: 'mock_auth' },
{ name: 'test_auth', display_name: 'Test' },
{ name: 'foob_auth', icon: 'foobar.png' }
]
end
before do
allow(OpenProject::Plugins::AuthPlugin).to receive(:providers).and_return(providers)
render :partial => 'hooks/login/providers', :handlers => [:erb], :formats => [:html]
render partial: 'hooks/login/providers', handlers: [:erb], formats: [:html]
end
it 'should show the mock_auth button with the name as its label' do

Loading…
Cancel
Save