Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rubocop #5199

Merged
merged 3 commits into from Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 5 additions & 11 deletions .rubocop.yml
Expand Up @@ -468,7 +468,7 @@ Naming/FileName:
# files with a shebang in the first line).
IgnoreExecutableScripts: true

Layout/FirstParameterIndentation:
Layout/IndentFirstArgument:
EnforcedStyle: special_for_inner_method_call_in_parentheses
SupportedStyles:
# The first parameter should always be indented one step more than the
Expand Down Expand Up @@ -505,11 +505,9 @@ Style/FormatStringToken:
EnforcedStyle: template

Style/FrozenStringLiteralComment:
EnforcedStyle: when_needed
EnforcedStyle: always
SupportedStyles:
# `when_needed` will add the frozen string literal comment to files
# only when the `TargetRubyVersion` is set to 2.3+.
- when_needed
- never
# `always` will always add the frozen string literal comment to a file
# regardless of the Ruby version or if `freeze` or `<<` are called on a
# string literal. If you run code against multiple versions of Ruby, it is
Expand Down Expand Up @@ -558,7 +556,7 @@ Layout/IndentationWidth:
Width: 2

# Checks the indentation of the first element in an array literal.
Layout/IndentArray:
Layout/IndentFirstArrayElement:
# The value `special_inside_parentheses` means that array literals with
# brackets that have their opening bracket on the same line as a surrounding
# opening round parenthesis, shall have their first element indented relative
Expand Down Expand Up @@ -586,7 +584,7 @@ Layout/IndentAssignment:
IndentationWidth: ~

# Checks the indentation of the first key in a hash literal.
Layout/IndentHash:
Layout/IndentFirstHashElement:
# The value `special_inside_parentheses` means that hash literals with braces
# that have their opening brace on the same line as a surrounding opening
# round parenthesis, shall have their first key indented relative to the
Expand Down Expand Up @@ -1190,10 +1188,6 @@ Lint/UnusedMethodArgument:

##################### Performance ############################

Performance/RedundantMerge:
# Max number of key-value pairs to consider an offense
MaxKeyValuePairs: 2

Metrics/BlockLength:
Enabled: false

Expand Down
2 changes: 2 additions & 0 deletions .rubocop_rails.yml
@@ -1,3 +1,5 @@
require: rubocop-rails

Rails:
Enabled: true

Expand Down
30 changes: 16 additions & 14 deletions Gemfile.lock
Expand Up @@ -137,7 +137,8 @@ PATH
rspec-html-matchers (~> 0.9.1)
rspec-rails (~> 3.7)
rspec_junit_formatter (~> 0.3.0)
rubocop (~> 0.58.0)
rubocop (~> 0.71.0)
rubocop-rails (~> 2.0)
rubocop-rspec (~> 1.21)
selenium-webdriver (~> 3.7)
simplecov (~> 0.13)
Expand Down Expand Up @@ -285,7 +286,7 @@ GEM
msgpack (~> 1.0)
builder (3.2.3)
byebug (10.0.2)
capybara (3.22.0)
capybara (3.24.0)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
Expand Down Expand Up @@ -354,7 +355,7 @@ GEM
doc2text (0.4.1)
nokogiri (~> 1.8, >= 1.8.2)
rubyzip (~> 1.2, >= 1.2.2)
docile (1.3.1)
docile (1.3.2)
domain_name (0.5.20180417)
unf (>= 0.0.5, < 1.0.0)
doorkeeper (4.4.3)
Expand Down Expand Up @@ -539,7 +540,6 @@ GEM
pg_search (2.2.0)
activerecord (>= 4.2)
activesupport (>= 4.2)
powerpack (0.1.2)
premailer (1.11.1)
addressable
css_parser (>= 1.6.0)
Expand Down Expand Up @@ -621,15 +621,15 @@ GEM
rspec-cells (0.3.4)
cells (>= 4.0.0, < 6.0.0)
rspec-rails (~> 3.2)
rspec-core (3.8.0)
rspec-core (3.8.1)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.3)
rspec-expectations (3.8.4)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-html-matchers (0.9.1)
nokogiri (~> 1)
rspec (>= 3.0.0.a, < 4)
rspec-mocks (3.8.0)
rspec-mocks (3.8.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-rails (3.8.2)
Expand All @@ -640,19 +640,21 @@ GEM
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rspec-support (3.8.2)
rspec_junit_formatter (0.3.0)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (0.58.2)
rubocop (0.71.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1)
parser (>= 2.6)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
rubocop-rspec (1.30.0)
rubocop (>= 0.58.0)
unicode-display_width (>= 1.4.0, < 1.7)
rubocop-rails (2.0.1)
rack (>= 1.1)
rubocop (>= 0.70.0)
rubocop-rspec (1.33.0)
rubocop (>= 0.60.0)
ruby-ole (1.2.12.2)
ruby-progressbar (1.10.1)
ruby_dep (1.5.0)
Expand Down
2 changes: 2 additions & 0 deletions bin/bundle
Expand Up @@ -13,11 +13,13 @@ m = Module.new do
def cli_arg_version
return unless invoked_as_script? # don't want to hijack other binstubs
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`

bundler_version = nil
update_index = nil
ARGV.each_with_index do |a, i|
bundler_version = a if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/

bundler_version = Regexp.last_match(1) || ">= 0.a"
update_index = i
end
Expand Down
Expand Up @@ -17,6 +17,7 @@ def result

def current_version
return nil if params[:id].to_i < 1

@current_version ||= result.versions[params[:id].to_i - 1]
end
end
Expand Down
Expand Up @@ -14,6 +14,7 @@ class ParentPresenter < Decidim::Log::ValueTypes::DefaultPresenter
def present
return unless value
return h.translated_attribute(result.title) if result

I18n.t("not_found", id: value, scope: "decidim.accountability.admin_log.value_types.parent_presenter")
end

Expand Down
Expand Up @@ -14,6 +14,7 @@ def save
@registry = []
cumulative.each do |key, cumulative_value|
next if cumulative_value.zero?

quantity_value = quantity[key] || 0
category_id, space_type, space_id, related_object_id = key
record = Decidim::Metric.find_or_initialize_by(day: @day.to_s,
Expand Down
Expand Up @@ -15,6 +15,7 @@ def initialize(result)

def votes_count
return 0 unless proposals

proposals.sum { |proposal| proposal.votes.size }
end

Expand Down
Expand Up @@ -17,6 +17,7 @@ def initialize(newsletter, current_user)
# Broadcasts :ok if it got destroyed
def call
return broadcast(:already_sent) if newsletter.sent?

destroy_newsletter
broadcast(:ok)
end
Expand Down
Expand Up @@ -22,6 +22,7 @@ def initialize(form)
# Returns nothing.
def call
return broadcast(:invalid) unless @form.valid?

process_csv
broadcast(:ok)
end
Expand Down
Expand Up @@ -21,6 +21,7 @@ def initialize(user_group, current_user)
# Returns nothing.
def call
return broadcast(:invalid) unless @user_group.valid?

reject_user_group
broadcast(:ok)
end
Expand Down
Expand Up @@ -24,6 +24,7 @@ def call
return broadcast(:invalid) if form.invalid?

return broadcast(:ok, @organization) if update_organization

broadcast(:invalid)
end

Expand Down
Expand Up @@ -21,6 +21,7 @@ def initialize(user_group, current_user, via_csv = false)
# Returns nothing.
def call
return broadcast(:invalid) unless @user_group.valid?

verify_user_group
broadcast(:ok)
end
Expand Down
Expand Up @@ -79,6 +79,7 @@ def organization_areas

def area
return @area if defined?(@area)

@area = organization_areas.find_by(id: params[:id])
end
end
Expand Down
Expand Up @@ -75,11 +75,13 @@ def organization_scopes

def parent_scope
return @parent_scope if defined?(@parent_scope)

@parent_scope = scope ? scope.parent : organization_scopes.find_by(id: params[:scope_id])
end

def scope
return @scope if defined?(@scope)

@scope = organization_scopes.find_by(id: params[:id])
end

Expand Down
Expand Up @@ -17,6 +17,7 @@ def unique_email
organization: context.current_organization,
email: email
).where.not(id: context.current_user.id).empty?

errors.add :email, :taken
false
end
Expand Down
Expand Up @@ -28,6 +28,7 @@ def map_model(_newsletter)

def at_least_one_participatory_space_selected
return if send_to_all_users && current_user.admin?

errors.add(:base, "Select atleast one participatory space") if spaces_selected.blank?
end

Expand Down
Expand Up @@ -25,7 +25,7 @@ def title
# Returns a String with a link wrapped in a <li> element.
def public_page_link(url)
content_tag(:li) do
link_to url, class: "button", style: "color: #fff", target: "_blank" do
link_to url, class: "button", style: "color: #fff", target: "_blank", rel: "noopener" do
I18n.t("decidim.admin.view_public_page")
end
end
Expand Down
Expand Up @@ -52,6 +52,7 @@ def display_for(record, *attrs)
# Holds the logic to render a label for a given attribute.
def display_label(record, attr, locale = nil)
return content_tag(:dt, record.class.human_attribute_name(attr)) unless locale

content_tag(:dt, record.class.human_attribute_name(attr) + " (#{locale})")
end

Expand All @@ -70,6 +71,7 @@ def display_value(record, attr, locale = nil)

def display_available_locales(record)
return record.available_locales if record.respond_to?(:available_locales)

record.organization.available_locales if record.respond_to?(:organization)
current_organization.available_locales if respond_to?(:current_organization)
end
Expand Down
6 changes: 6 additions & 0 deletions decidim-admin/app/helpers/decidim/admin/newsletters_helper.rb
Expand Up @@ -14,6 +14,7 @@ def participatory_spaces_for_select(form_object)

def participatory_space_types_form_object(form_object, space_type)
return if spaces_user_can_admin[space_type.manifest_name.to_sym].blank?

html = ""
form_object.fields_for "participatory_space_types[#{space_type.manifest_name}]", space_type do |ff|
html += ff.hidden_field :manifest_name, value: space_type.manifest_name
Expand All @@ -24,6 +25,7 @@ def participatory_space_types_form_object(form_object, space_type)

def select_tag_participatory_spaces(manifest_name, spaces, child_form)
return unless spaces

content_tag :div, class: "#{manifest_name}-block spaces-block-tag cell small-12 medium-6" do
child_form.select :ids, options_for_select(spaces),
{ prompt: t("select_recipients_to_deliver.none", scope: "decidim.admin.newsletters"),
Expand All @@ -43,6 +45,7 @@ def spaces_for_select(manifest_name)
def selective_newsletter_to(newsletter)
return content_tag(:strong, t("index.not_sent", scope: "decidim.admin.newsletters"), class: "text-warning") unless newsletter.sent?
return content_tag(:strong, t("index.all_users", scope: "decidim.admin.newsletters"), class: "text-success") if newsletter.sent? && newsletter.extended_data.blank?

content_tag :div do
concat sent_to_users newsletter
concat sent_to_spaces newsletter
Expand All @@ -64,6 +67,7 @@ def sent_to_spaces(newsletter)
html = "<p style='margin-bottom:0;'> "
newsletter.sended_to_partipatory_spaces.try(:each) do |type|
next if type["ids"].blank?

html += t("index.segmented_to", scope: "decidim.admin.newsletters", subject: t("activerecord.models.decidim/#{type["manifest_name"].singularize}.other"))
if type["ids"].include?("all")
html += "<strong> #{t("index.all", scope: "decidim.admin.newsletters")} </strong>"
Expand Down Expand Up @@ -106,6 +110,7 @@ def spaces_user_can_admin
Decidim.participatory_space_manifests.each do |manifest|
organization_participatory_space(manifest.name)&.each do |space|
next unless space.admins.exists?(id: current_user.id)

@spaces_user_can_admin[manifest.name] ||= []
space_as_option_for_select_data = space_as_option_for_select(space)
@spaces_user_can_admin[manifest.name] << space_as_option_for_select_data unless @spaces_user_can_admin[manifest.name].detect do |x|
Expand All @@ -118,6 +123,7 @@ def spaces_user_can_admin

def space_as_option_for_select(space)
return unless space

[
translated_attribute(space.title),
space.id,
Expand Down
1 change: 1 addition & 0 deletions decidim-admin/app/helpers/decidim/admin/settings_helper.rb
Expand Up @@ -34,6 +34,7 @@ def settings_attribute_input(form, attribute, name, options = {})

def form_method_for_attribute(attribute)
return :editor if attribute.type.to_sym == :text && attribute.editor?

TYPES[attribute.type.to_sym]
end

Expand Down
Expand Up @@ -8,6 +8,7 @@ class ExpireImpersonationJob < ApplicationJob
def perform(user, current_user)
impersonation_log = Decidim::ImpersonationLog.where(admin: current_user, user: user).active.first
return unless impersonation_log

impersonation_log.expired_at = Time.current
impersonation_log.save!
end
Expand Down
1 change: 1 addition & 0 deletions decidim-admin/app/jobs/decidim/admin/newsletter_job.rb
Expand Up @@ -14,6 +14,7 @@ def perform(newsletter, form, recipients_ids)

@newsletter.with_lock do
raise "Newsletter already sent" if @newsletter.sent?

@newsletter.update!(
sent_at: Time.current,
extended_data: extended_data,
Expand Down
Expand Up @@ -13,6 +13,7 @@ def perform(email, verifier, organization)

return if email.blank?
return unless user_group

Decidim::Admin::VerifyUserGroup.call(user_group, verifier, true)
end

Expand Down