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