fix rubocop offenses for rubocop 0.44.1
This commit is contained in:
parent
27b9c8365b
commit
7248aaec67
10 changed files with 42 additions and 33 deletions
11
.rubocop.yml
11
.rubocop.yml
|
|
@ -159,6 +159,14 @@ Metrics/CyclomaticComplexity:
|
|||
Metrics/PerceivedComplexity:
|
||||
Max: 10
|
||||
|
||||
Metric/BlockLength:
|
||||
Exclude:
|
||||
- "Rakefile"
|
||||
- "**/*.rake"
|
||||
- "spec/**/*.rb"
|
||||
- "test/dummy/config/**/*.rb"
|
||||
- "lib/diaspora_federation/test/factories.rb"
|
||||
|
||||
Rails/TimeZone:
|
||||
Exclude:
|
||||
- "spec/lib/**/*"
|
||||
|
|
@ -175,3 +183,6 @@ Style/NumericPredicate:
|
|||
|
||||
Style/FrozenStringLiteralComment:
|
||||
Enabled: false
|
||||
|
||||
Rails/HttpPositionalArguments:
|
||||
Enabled: false
|
||||
|
|
|
|||
|
|
@ -232,8 +232,8 @@ module DiasporaFederation
|
|||
private
|
||||
|
||||
def validate_http_config
|
||||
configuration_error "http_concurrency: please configure a number" unless @http_concurrency.is_a?(Fixnum)
|
||||
configuration_error "http_timeout: please configure a number" unless @http_timeout.is_a?(Fixnum)
|
||||
configuration_error "http_concurrency: please configure a number" unless @http_concurrency.is_a?(Integer)
|
||||
configuration_error "http_timeout: please configure a number" unless @http_timeout.is_a?(Integer)
|
||||
|
||||
return unless !@http_verbose.is_a?(TrueClass) && !@http_verbose.is_a?(FalseClass)
|
||||
configuration_error "http_verbose: please configure a boolean"
|
||||
|
|
|
|||
|
|
@ -44,13 +44,13 @@ module DiasporaFederation
|
|||
raise "Failed to fetch #{url}: #{response.status}" unless response.success?
|
||||
response.body
|
||||
rescue => e
|
||||
if http_fallback && url.start_with?("https://")
|
||||
logger.warn "Retry with http: #{url} for #{diaspora_id}: #{e.class}: #{e.message}"
|
||||
url.sub!("https://", "http://")
|
||||
retry
|
||||
else
|
||||
unless http_fallback && url.start_with?("https://")
|
||||
raise DiscoveryError, "Failed to fetch #{url} for #{diaspora_id}: #{e.class}: #{e.message}"
|
||||
end
|
||||
|
||||
logger.warn "Retry with http: #{url} for #{diaspora_id}: #{e.class}: #{e.message}"
|
||||
url.sub!("https://", "http://")
|
||||
retry
|
||||
end
|
||||
|
||||
def host_meta_url
|
||||
|
|
|
|||
|
|
@ -131,10 +131,10 @@ module DiasporaFederation
|
|||
# @return [String] A Base64 encoded signature of #signature_data with key
|
||||
def sign_with_parent_author_if_available
|
||||
privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, parent.author)
|
||||
if privkey
|
||||
sign_with_key(privkey).tap do
|
||||
logger.info "event=sign status=complete signature=parent_author_signature obj=#{self}"
|
||||
end
|
||||
return unless privkey
|
||||
|
||||
sign_with_key(privkey).tap do
|
||||
logger.info "event=sign status=complete signature=parent_author_signature obj=#{self}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -209,11 +209,9 @@ module DiasporaFederation
|
|||
|
||||
def fetch_parent(data)
|
||||
type = data.fetch(:parent_type) {
|
||||
if const_defined?(:PARENT_TYPE)
|
||||
self::PARENT_TYPE
|
||||
else
|
||||
raise DiasporaFederation::Entity::ValidationError, "invalid #{self}! missing 'parent_type'."
|
||||
end
|
||||
break self::PARENT_TYPE if const_defined?(:PARENT_TYPE)
|
||||
|
||||
raise DiasporaFederation::Entity::ValidationError, "invalid #{self}! missing 'parent_type'."
|
||||
}
|
||||
guid = data.fetch(:parent_guid) {
|
||||
raise DiasporaFederation::Entity::ValidationError, "invalid #{self}! missing 'parent_guid'."
|
||||
|
|
@ -221,11 +219,11 @@ module DiasporaFederation
|
|||
|
||||
data[:parent] = DiasporaFederation.callbacks.trigger(:fetch_related_entity, type, guid)
|
||||
|
||||
unless data[:parent]
|
||||
# Fetch and receive parent from remote, if not available locally
|
||||
Federation::Fetcher.fetch_public(data[:author], type, guid)
|
||||
data[:parent] = DiasporaFederation.callbacks.trigger(:fetch_related_entity, type, guid)
|
||||
end
|
||||
return if data[:parent]
|
||||
|
||||
# Fetch and receive parent from remote, if not available locally
|
||||
Federation::Fetcher.fetch_public(data[:author], type, guid)
|
||||
data[:parent] = DiasporaFederation.callbacks.trigger(:fetch_related_entity, type, guid)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -194,13 +194,13 @@ module DiasporaFederation
|
|||
end
|
||||
|
||||
factory :poll_participation_entity,
|
||||
class: DiasporaFederation::Entities::PollParticipation, parent: :relayable_entity do
|
||||
class: DiasporaFederation::Entities::PollParticipation, parent: :relayable_entity do
|
||||
author { generate(:diaspora_id) }
|
||||
guid
|
||||
poll_answer_guid { generate(:guid) }
|
||||
end
|
||||
|
||||
factory :related_entity, class: DiasporaFederation::Entities::RelatedEntity do
|
||||
factory :related_entity, class: DiasporaFederation::Entities::RelatedEntity do
|
||||
author { generate(:diaspora_id) }
|
||||
local true
|
||||
public false
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ module Validation
|
|||
#
|
||||
# Valid is:
|
||||
# * a +String+: "true", "false", "t", "f", "yes", "no", "y", "n", "1", "0"
|
||||
# * a +Fixnum+: 1 or 0
|
||||
# * a +Integer+: 1 or 0
|
||||
# * a +Boolean+: true or false
|
||||
class Boolean
|
||||
# The error key for this rule
|
||||
|
|
@ -19,7 +19,7 @@ module Validation
|
|||
|
||||
if value.is_a?(String)
|
||||
true if value =~ /\A(true|false|t|f|yes|no|y|n|1|0)\z/i
|
||||
elsif value.is_a?(Fixnum)
|
||||
elsif value.is_a?(Integer)
|
||||
true if value == 1 || value == 0
|
||||
elsif [true, false].include? value
|
||||
true
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ module Validation
|
|||
|
||||
# Creates a new rule for a maximum diaspora* ID count validation
|
||||
# @param [Hash] params
|
||||
# @option params [Fixnum] :maximum maximum allowed id count
|
||||
# @option params [Integer] :maximum maximum allowed id count
|
||||
def initialize(params)
|
||||
unless params.include?(:maximum) && params[:maximum].is_a?(Fixnum)
|
||||
unless params.include?(:maximum) && params[:maximum].is_a?(Integer)
|
||||
raise ArgumentError, "A number has to be specified for :maximum"
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ module Validation
|
|||
|
||||
# Creates a new rule for a maximum tag count validation
|
||||
# @param [Hash] params
|
||||
# @option params [Fixnum] :maximum maximum allowed tag count
|
||||
# @option params [Integer] :maximum maximum allowed tag count
|
||||
def initialize(params)
|
||||
unless params.include?(:maximum) && params[:maximum].is_a?(Fixnum)
|
||||
unless params.include?(:maximum) && params[:maximum].is_a?(Integer)
|
||||
raise ArgumentError, "A number has to be specified for :maximum"
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -12,10 +12,10 @@ module DiasporaFederation
|
|||
|
||||
it "generates a different key and iv every time" do
|
||||
key_and_iv = Salmon::AES.generate_key_and_iv
|
||||
key_and_iv_2 = Salmon::AES.generate_key_and_iv
|
||||
key_and_iv2 = Salmon::AES.generate_key_and_iv
|
||||
|
||||
expect(key_and_iv[:key]).not_to eq(key_and_iv_2[:key])
|
||||
expect(key_and_iv[:iv]).not_to eq(key_and_iv_2[:iv])
|
||||
expect(key_and_iv[:key]).not_to eq(key_and_iv2[:key])
|
||||
expect(key_and_iv[:iv]).not_to eq(key_and_iv2[:iv])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ shared_examples "an Entity subclass" do
|
|||
describe "#to_h" do
|
||||
it "should return a hash with nested data" do
|
||||
expected_data = data.map {|key, value|
|
||||
if [String, TrueClass, FalseClass, Fixnum, Time, NilClass].include?(value.class)
|
||||
if [String, TrueClass, FalseClass, Integer, Time, NilClass].any? {|c| value.is_a? c }
|
||||
[key, value]
|
||||
elsif value.instance_of?(Array)
|
||||
[key, value.map(&:to_h)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue