diff --git a/.rubocop.yml b/.rubocop.yml index d582fb63fd..5f9595b191 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -22,10 +22,6 @@ Style/EmptyMethod: Style/MutableConstant: Enabled: false -# See #647 -Style/SafeNavigation: - Enabled: false - Style/WordArray: Exclude: - 'db/schema.rb' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b044f91ad6..0c80804874 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-12-17 21:03:01 +0900 using RuboCop version 0.52.0. +# on 2018-01-05 15:35:35 +1030 using RuboCop version 0.52.1. # 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 @@ -14,13 +14,6 @@ Gemspec/OrderedDependencies: Exclude: - 'fat_free_crm.gemspec' -# Offense count: 1 -# Configuration parameters: Include. -# Include: **/*.gemspec -Gemspec/RequiredRubyVersion: - Exclude: - - 'fat_free_crm.gemspec' - # Offense count: 27 # Cop supports --auto-correct. Layout/ClosingParenthesisIndentation: @@ -35,12 +28,12 @@ Layout/ClosingParenthesisIndentation: - 'spec/models/polymorphic/version_spec.rb' - 'spec/views/comments/edit.js.haml_spec.rb' -# Offense count: 21 +# Offense count: 16 # Cop supports --auto-correct. Layout/EmptyLinesAroundArguments: Exclude: - - 'config/initializers/views.rb' - - 'db/seeds/fields.rb' + - 'app/helpers/accounts_helper.rb' + - 'lib/fat_free_crm/permissions.rb' - 'spec/features/accounts_spec.rb' - 'spec/features/admin/groups_spec.rb' - 'spec/features/admin/users_spec.rb' @@ -131,15 +124,6 @@ Layout/SpaceAroundOperators: - 'app/views/application/show.rss.builder' - 'app/views/campaigns/index.xls.builder' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: . -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceBeforeBlockBraces: - EnforcedStyle: space - EnforcedStyleForEmptyBraces: space - # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: AllowForAlignment. @@ -222,12 +206,11 @@ Lint/UselessAccessModifier: - 'db/migrate/20100928030620_remove_uuid.rb' - 'lib/gravatar_image_tag.rb' -# Offense count: 4 +# Offense count: 3 Lint/UselessAssignment: Exclude: - 'app/helpers/application_helper.rb' - 'app/views/home/index.atom.builder' - - 'lib/fat_free_crm/mail_processor/base.rb' # Offense count: 130 Metrics/AbcSize: @@ -248,7 +231,7 @@ Metrics/BlockNesting: Metrics/ClassLength: Max: 195 -# Offense count: 30 +# Offense count: 29 Metrics/CyclomaticComplexity: Max: 13 @@ -260,9 +243,9 @@ Metrics/MethodLength: # Offense count: 2 # Configuration parameters: CountComments. Metrics/ModuleLength: - Max: 391 + Max: 392 -# Offense count: 28 +# Offense count: 27 Metrics/PerceivedComplexity: Max: 15 @@ -311,14 +294,13 @@ Naming/VariableNumber: Exclude: - 'spec/controllers/home_controller_spec.rb' -# Offense count: 4 +# Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect. Performance/HashEachMethods: Exclude: - 'app/controllers/entities/opportunities_controller.rb' - 'lib/fat_free_crm/errors.rb' - - 'spec/controllers/tasks_controller_spec.rb' # Offense count: 1 # Cop supports --auto-correct. @@ -346,13 +328,12 @@ Security/YAMLLoad: - 'db/migrate/20120405080742_change_further_subscribed_users_to_set.rb' - 'lib/tasks/ffcrm/config.rake' -# Offense count: 4 +# Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: always, conditionals Style/AndOr: Exclude: - - 'config/unicorn.rb' - 'lib/fat_free_crm/mail_processor/base.rb' # Offense count: 8 @@ -373,7 +354,8 @@ Style/CaseEquality: - 'app/models/fields/field.rb' # Offense count: 18 -# Configuration parameters: EnforcedStyle. +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, EnforcedStyle. # SupportedStyles: nested, compact Style/ClassAndModuleChildren: Enabled: false @@ -393,14 +375,12 @@ Style/ClassVars: - 'lib/fat_free_crm/tabs.rb' - 'lib/fat_free_crm/view_factory.rb' -# Offense count: 7 +# Offense count: 3 Style/CommentedKeyword: Exclude: - 'app/controllers/entities/leads_controller.rb' - - 'app/helpers/application_helper.rb' - 'app/models/users/authentication.rb' - 'db/migrate/20100928030617_drop_openid_tables.rb' - - 'lib/fat_free_crm/mail_processor/dropbox.rb' # Offense count: 13 # Cop supports --auto-correct. @@ -463,19 +443,7 @@ Style/FormatString: Exclude: - 'spec/factories/shared_factories.rb' -# Offense count: 52 -# Configuration parameters: EnforcedStyle. -# SupportedStyles: annotated, template, unannotated -Style/FormatStringToken: - Exclude: - - 'app/inputs/date_pair_input.rb' - - 'app/inputs/date_time_input.rb' - - 'app/inputs/datetime_pair_input.rb' - - 'config/locales/th.rb' - - 'spec/models/list_spec.rb' - - 'spec/models/polymorphic/task_spec.rb' - -# Offense count: 486 +# Offense count: 485 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: when_needed, always, never @@ -499,7 +467,7 @@ Style/IdenticalConditionalBranches: Exclude: - 'app/helpers/application_helper.rb' -# Offense count: 50 +# Offense count: 51 # Cop supports --auto-correct. Style/IfUnlessModifier: Enabled: false @@ -535,13 +503,9 @@ Style/MethodMissing: - 'app/models/setting.rb' - 'lib/fat_free_crm/fields.rb' -# Offense count: 8 +# Offense count: 1 Style/MixinUsage: Exclude: - - 'lib/fat_free_crm/comment_extensions.rb' - - 'lib/fat_free_crm/exportable.rb' - - 'lib/fat_free_crm/fields.rb' - - 'lib/fat_free_crm/permissions.rb' - 'spec/helpers/fields_helper_spec.rb' # Offense count: 2 @@ -601,13 +565,12 @@ Style/ParallelAssignment: Exclude: - 'lib/fat_free_crm/core_ext/alias_method_chain.rb' -# Offense count: 100 +# Offense count: 98 # Cop supports --auto-correct. # Configuration parameters: PreferredDelimiters. Style/PercentLiteralDelimiters: Exclude: - 'app/views/tasks/index.xls.builder' - - 'config/locales/th.rb' - 'lib/tasks/ffcrm/update_data.rake' - 'spec/models/fields/field_spec.rb' @@ -687,7 +650,7 @@ Style/UnneededInterpolation: - 'app/views/opportunities/index.xls.builder' - 'app/views/tasks/index.xls.builder' -# Offense count: 2164 +# Offense count: 2157 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: diff --git a/CHANGELOG.md b/CHANGELOG.md index 66ee68813f..3771765b4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,12 @@ It does not matter how slowly you go as long as you do not stop. First they ignore you, then they laugh at you, then they fight you, then you win. –- Mahatma Gandhi -Unreleased +Fri Jan 5, 2018 (0.16.0) --------------------------------------------------------------------- - #633 Upgrade to rails 5.1.0 - #641 Swap default server from thin/unicorn to puma +- #631 Clean up locale files +- #612 DEPRECATION WARNING: #table_exists? currently checks both tables and views Thu Dec 14, 2017 (0.15.0) --------------------------------------------------------------------- diff --git a/Gemfile b/Gemfile index 296980bdea..94b4335a9b 100644 --- a/Gemfile +++ b/Gemfile @@ -62,7 +62,7 @@ group :development, :test do gem 'byebug' gem 'pry-rails' unless ENV["CI"] gem 'factory_girl_rails', '~> 4.7.0' # 4.8.0+ stubbed models are not allowed to access the database - User#destroyed?() - gem 'rubocop', '~> 0.50.0' # Pinned because upgrades require regenerating rubocop_todo.yml + gem 'rubocop', '~> 0.52.0' # Pinned because upgrades require regenerating rubocop_todo.yml gem 'rainbow' end diff --git a/Gemfile.lock b/Gemfile.lock index 9fab41224a..2ff4d5c4d0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -275,8 +275,7 @@ GEM method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rainbow (2.2.2) - rake + rainbow (3.0.0) rake (12.3.0) ransack (1.8.4) actionpack (>= 3.0) @@ -325,11 +324,11 @@ GEM rspec-mocks (~> 3.7.0) rspec-support (~> 3.7.0) rspec-support (3.7.0) - rubocop (0.50.0) + rubocop (0.52.1) parallel (~> 1.10) - parser (>= 2.3.3.1, < 3.0) + parser (>= 2.4.0.2, < 3.0) powerpack (~> 0.1) - rainbow (>= 2.2.2, < 3.0) + rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) ruby-progressbar (1.9.0) @@ -381,8 +380,6 @@ GEM timecop (0.9.1) tzinfo (1.2.4) thread_safe (~> 0.1) - tzinfo-data (1.2017.3) - tzinfo (>= 1.0.0) uglifier (4.0.2) execjs (>= 0.3.0, < 3) unicode-display_width (1.3.0) @@ -443,6 +440,7 @@ DEPENDENCIES puma rails (~> 5.1.0) rails-controller-testing + rails-i18n rails-observers rails3-jquery-autocomplete rails_12factor @@ -457,7 +455,7 @@ DEPENDENCIES responds_to_parent rspec-activemodel-mocks rspec-rails - rubocop (~> 0.50.0) + rubocop (~> 0.52.0) sass sass-rails select2-rails diff --git a/README.md b/README.md index 6798a33bac..34b703647e 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ This is the best way to deploy Fat Free CRM if you need to add plugins or make a ## Upgrading from previous versions of Fat Free CRM -Please read the [Release Notes](https://github.com/fatfreecrm/fat_free_crm/blob/master/CHANGELOG) document for more detailed information on upgrading from previous versions. +Please read the [Release Notes](https://github.com/fatfreecrm/fat_free_crm/blob/master/CHANGELOG.md) document for more detailed information on upgrading from previous versions. ## Resources diff --git a/app/controllers/admin/application_controller.rb b/app/controllers/admin/application_controller.rb index 1360ebfed3..e43d21d33a 100644 --- a/app/controllers/admin/application_controller.rb +++ b/app/controllers/admin/application_controller.rb @@ -24,7 +24,7 @@ def auto_complete #---------------------------------------------------------------------------- def require_admin_user require_user - if current_user && !current_user.admin? + unless current_user&.admin? flash[:notice] = t(:msg_require_admin) redirect_to root_path end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3921e01756..5322b42bfc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -111,7 +111,7 @@ def set_current_tab(tab = controller_name) #---------------------------------------------------------------------------- def current_user_session @current_user_session ||= Authentication.find - if @current_user_session && @current_user_session.record.suspended? + if @current_user_session&.record&.suspended? @current_user_session = nil end @current_user_session @@ -120,7 +120,7 @@ def current_user_session #---------------------------------------------------------------------------- def current_user unless @current_user - @current_user = (current_user_session && current_user_session.record) + @current_user = (current_user_session&.record) if @current_user @current_user.set_individual_locale @current_user.set_single_access_token diff --git a/app/controllers/authentications_controller.rb b/app/controllers/authentications_controller.rb index fad2928af0..f601d9dc4f 100644 --- a/app/controllers/authentications_controller.rb +++ b/app/controllers/authentications_controller.rb @@ -30,7 +30,7 @@ def create end redirect_back_or_default root_url else - if @authentication.user && @authentication.user.awaits_approval? + if @authentication.user&.awaits_approval? flash[:notice] = t(:msg_account_not_approved) else flash[:warning] = t(:msg_invalig_login) diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb index 855ec85a7a..2555ea25fd 100644 --- a/app/controllers/tasks_controller.rb +++ b/app/controllers/tasks_controller.rb @@ -125,7 +125,7 @@ def destroy #---------------------------------------------------------------------------- def complete @task = Task.tracked_by(current_user).find(params[:id]) - @task.update_attributes(completed_at: Time.now, completed_by: current_user.id) if @task + @task&.update_attributes(completed_at: Time.now, completed_by: current_user.id) # Make sure bucket's div gets hidden if it's the last completed task in the bucket. if Task.bucket_empty?(params[:bucket], current_user) @@ -140,7 +140,7 @@ def complete #---------------------------------------------------------------------------- def uncomplete @task = Task.tracked_by(current_user).find(params[:id]) - @task.update_attributes(completed_at: nil, completed_by: nil) if @task + @task&.update_attributes(completed_at: nil, completed_by: nil) # Make sure bucket's div gets hidden if we're deleting last task in the bucket. if Task.bucket_empty?(params[:bucket], current_user, @view) diff --git a/app/helpers/accounts_helper.rb b/app/helpers/accounts_helper.rb index 089ea0d62f..c6ecd83dbd 100755 --- a/app/helpers/accounts_helper.rb +++ b/app/helpers/accounts_helper.rb @@ -27,7 +27,7 @@ def account_summary(account) # and prepends the currently selected account, if any. #---------------------------------------------------------------------------- def account_select(options = {}) - options[:selected] = (@account && @account.id) || 0 + options[:selected] = (@account&.id) || 0 accounts = ([@account] + Account.my.order(:name).limit(25)).compact.uniq collection_select :account, :id, accounts, :id, :name, options, "data-placeholder": t(:select_an_account), diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a0667f909e..7b3be86110 100755 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -161,8 +161,9 @@ def link_to_close(url) #---------------------------------------------------------------------------- def link_to_email(email, length = nil, &_block) name = (length ? truncate(email, length: length) : email) - if Setting.email_dropbox && Setting.email_dropbox[:address].present? - mailto = "#{email}?bcc=#{Setting.email_dropbox[:address]}" + bcc = Setting&.email_dropbox + if bcc && bcc[:address].present? + mailto = "#{email}?bcc=#{bcc[:address]}" else mailto = email end diff --git a/app/helpers/contacts_helper.rb b/app/helpers/contacts_helper.rb index 580c622209..22273ce4d0 100644 --- a/app/helpers/contacts_helper.rb +++ b/app/helpers/contacts_helper.rb @@ -12,7 +12,7 @@ def contact_summary(contact) summary = [''] summary << contact.title.titleize if contact.title? summary << contact.department if contact.department? - if contact.account && contact.account.name? + if contact.account&.name? summary.last += " #{t(:at)} #{contact.account.name}" end summary << contact.email if contact.email.present? diff --git a/app/models/entities/account.rb b/app/models/entities/account.rb index 5becc246a9..72fcda40e3 100644 --- a/app/models/entities/account.rb +++ b/app/models/entities/account.rb @@ -91,7 +91,7 @@ def self.per_page def location return "" unless self[:billing_address] location = self[:billing_address].strip.split("\n").last - location.gsub(/(^|\s+)\d+(:?\s+|$)/, " ").strip if location + location&.gsub(/(^|\s+)\d+(:?\s+|$)/, " ")&.strip end # Attach given attachment to the account if it hasn't been attached already. diff --git a/app/models/fields/custom_field_date_pair.rb b/app/models/fields/custom_field_date_pair.rb index 8baeeaae23..01e00f382f 100644 --- a/app/models/fields/custom_field_date_pair.rb +++ b/app/models/fields/custom_field_date_pair.rb @@ -25,7 +25,7 @@ def render_value(object) end def render(value) - value && value.strftime(I18n.t("date.formats.mmddyy")) + value&.strftime(I18n.t("date.formats.mmddyy")) end def custom_validator(obj) diff --git a/app/models/fields/custom_field_datetime_pair.rb b/app/models/fields/custom_field_datetime_pair.rb index 053b2aa1f3..99e0655236 100644 --- a/app/models/fields/custom_field_datetime_pair.rb +++ b/app/models/fields/custom_field_datetime_pair.rb @@ -7,7 +7,7 @@ #------------------------------------------------------------------------------ class CustomFieldDatetimePair < CustomFieldDatePair def render(value) - value && value.strftime(I18n.t("time.formats.mmddhhss")) + value&.strftime(I18n.t("time.formats.mmddhhss")) end ActiveSupport.run_load_hooks(:fat_free_crm_datetime_pair, self) diff --git a/app/models/fields/field.rb b/app/models/fields/field.rb index 9151cc7510..35fbcb02fd 100644 --- a/app/models/fields/field.rb +++ b/app/models/fields/field.rb @@ -92,9 +92,9 @@ def render(value) when 'checkbox' value.to_s == '0' ? "no" : "yes" when 'date' - value && value.strftime(I18n.t("date.formats.mmddyy")) + value&.strftime(I18n.t("date.formats.mmddyy")) when 'datetime' - value && value.in_time_zone.strftime(I18n.t("time.formats.mmddyyyy_hhmm")) + value&.in_time_zone&.strftime(I18n.t("time.formats.mmddyyyy_hhmm")) when 'check_boxes' value.select(&:present?).in_groups_of(2, false).map { |g| g.join(', ') }.join("
".html_safe) if Array === value else diff --git a/app/models/fields/field_group.rb b/app/models/fields/field_group.rb index 643b1b97bb..59f1a2f695 100644 --- a/app/models/fields/field_group.rb +++ b/app/models/fields/field_group.rb @@ -57,7 +57,9 @@ def not_default_field_group # When deleted, transfer fields to default field group def move_fields_to_default_field_group default_group = FieldGroup.find_by_name_and_klass_name("custom_fields", klass_name) - default_group.fields << fields if default_group + if default_group.fields + default_group.fields << fields + end reload end diff --git a/app/models/observers/lead_observer.rb b/app/models/observers/lead_observer.rb index 97d59da21c..91823028fe 100644 --- a/app/models/observers/lead_observer.rb +++ b/app/models/observers/lead_observer.rb @@ -16,7 +16,7 @@ def before_update(item) def after_update(item) original = @@leads.delete(item.id) - if original && original.status != "rejected" && item.status == "rejected" + if original&.status != "rejected" && item.status == "rejected" return log_activity(item, :reject) end end diff --git a/app/models/observers/opportunity_observer.rb b/app/models/observers/opportunity_observer.rb index baf5b0c2b0..4c3eb2092f 100644 --- a/app/models/observers/opportunity_observer.rb +++ b/app/models/observers/opportunity_observer.rb @@ -42,7 +42,7 @@ def log_activity(item, event) end def update_campaign_revenue(campaign, revenue) - campaign.update_attribute(:revenue, (campaign.revenue || 0) + revenue) if campaign + campaign&.update_attribute(:revenue, (campaign.revenue || 0) + revenue) end ActiveSupport.run_load_hooks(:fat_free_crm_opportunity_observer, self) diff --git a/db/migrate/20100928030618_add_admin_to_users.rb b/db/migrate/20100928030618_add_admin_to_users.rb index b1fac5c924..731203e6c6 100644 --- a/db/migrate/20100928030618_add_admin_to_users.rb +++ b/db/migrate/20100928030618_add_admin_to_users.rb @@ -4,7 +4,7 @@ class AddAdminToUsers < ActiveRecord::Migration[4.2] def self.up add_column :users, :admin, :boolean, null: false, default: false superuser = User.first - superuser.update_attribute(:admin, true) if superuser + superuser&.update_attribute(:admin, true) end def self.down diff --git a/fat_free_crm.gemspec b/fat_free_crm.gemspec index fd79eefc4e..4ad8bdb83f 100755 --- a/fat_free_crm.gemspec +++ b/fat_free_crm.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |gem| gem.email = ['mike@fatfreecrm.com', 'nathan@fatfreecrm.com', 'warp@fatfreecrm.com', 'steveyken@gmail.com', 'daniel.oconnor@gmail.com'] gem.files = files gem.version = FatFreeCRM::VERSION::STRING - gem.required_ruby_version = '>= 2.0.0' + gem.required_ruby_version = '>= 2.3.0' gem.license = 'MIT' gem.add_dependency 'rails', '~> 5.1.0' diff --git a/lib/fat_free_crm/version.rb b/lib/fat_free_crm/version.rb index 9de1e48388..758fae0387 100644 --- a/lib/fat_free_crm/version.rb +++ b/lib/fat_free_crm/version.rb @@ -8,7 +8,7 @@ module FatFreeCRM module VERSION #:nodoc: MAJOR = 0 - MINOR = 15 + MINOR = 16 TINY = 0 PRE = nil diff --git a/lib/fat_free_crm/view_factory.rb b/lib/fat_free_crm/view_factory.rb index 2cc9dc8be5..a476e320f0 100644 --- a/lib/fat_free_crm/view_factory.rb +++ b/lib/fat_free_crm/view_factory.rb @@ -47,7 +47,7 @@ def views_for(options = {}) #---------------------------------------------------------------------------- def template_for_current_view(options = {}) view = views_for(options).first - view && view.template + view&.template end end