Просмотр исходного кода

Updated dependencies and applied new rubocop rules.

Thorsten Eckel 9 лет назад
Родитель
Сommit
d7995bc6d3

+ 10 - 9
.rubocop.yml

@@ -2,13 +2,15 @@
 # https://github.com/bbatsov/rubocop/blob/master/config/enabled.yml
 
 AllCops:
-  RunRailsCops: true
   Exclude:
     - 'bin/rails'
     - 'bin/rake'
     - 'bin/spring'
     - 'db/schema.rb'
 
+Rails:
+  Enabled: true
+
 # Zammad StyleGuide
 
 Metrics/LineLength:
@@ -30,8 +32,13 @@ Style/IfUnlessModifier:
   StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier'
   Enabled: false
 
-Style/TrailingComma:
-  Description: 'Checks for trailing comma in parameter lists and literals.'
+Style/TrailingCommaInLiteral:
+  Description: 'Checks for trailing comma in array and hash literals.'
+  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
+  Enabled: false
+
+Style/TrailingCommaInArguments:
+  Description: 'Checks for trailing comma in argument lists.'
   StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
   Enabled: false
 
@@ -47,12 +54,6 @@ Style/SpaceAfterMethodName:
   StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-no-spaces'
   Enabled: false
 
-Style/SingleSpaceBeforeFirstArg:
-  Description: >-
-                 Checks that exactly one space is used between a method name
-                 and the first argument for method calls without parentheses.
-  Enabled: false
-
 Style/LeadingCommentSpace:
   Description: 'Comments should start with a space.'
   StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-space'

+ 17 - 22
Gemfile.lock

@@ -44,9 +44,7 @@ GEM
     addressable (2.4.0)
     arel (6.0.3)
     ast (2.2.0)
-    astrolabe (1.3.1)
-      parser (~> 2.2)
-    autoprefixer-rails (6.2.3)
+    autoprefixer-rails (6.3.1)
       execjs
       json
     biz (1.3.3)
@@ -58,7 +56,7 @@ GEM
     browser (1.1.0)
     buftok (0.2.0)
     builder (3.2.2)
-    childprocess (0.5.8)
+    childprocess (0.5.9)
       ffi (~> 1.0, >= 1.0.11)
     clavius (1.0.1)
       memoizable (~> 0.4.0)
@@ -95,7 +93,7 @@ GEM
       http_parser.rb (~> 0.6.0)
     equalizer (0.0.10)
     erubis (2.7.0)
-    eventmachine (1.0.8)
+    eventmachine (1.0.9.1)
     execjs (2.6.0)
     faraday (0.9.2)
       multipart-post (>= 1.2, < 3)
@@ -159,7 +157,7 @@ GEM
     mysql2 (0.3.20)
     naught (1.1.0)
     nenv (0.2.0)
-    net-ldap (0.12.1)
+    net-ldap (0.13.0)
     nokogiri (1.6.7.1)
       mini_portile2 (~> 2.0.0.rc2)
     notiffany (0.0.8)
@@ -177,28 +175,28 @@ GEM
       rack (>= 1.0, < 3)
     omniauth-facebook (3.0.0)
       omniauth-oauth2 (~> 1.2)
-    omniauth-google-oauth2 (0.2.10)
+    omniauth-google-oauth2 (0.3.0)
       addressable (~> 2.3)
       jwt (~> 1.0)
       multi_json (~> 1.3)
       omniauth (>= 1.1.1)
-      omniauth-oauth2 (~> 1.3.1)
+      omniauth-oauth2 (>= 1.3.1)
     omniauth-linkedin (0.2.0)
       omniauth-oauth (~> 1.0)
     omniauth-oauth (1.1.0)
       oauth
       omniauth (~> 1.0)
-    omniauth-oauth2 (1.3.1)
+    omniauth-oauth2 (1.4.0)
       oauth2 (~> 1.0)
       omniauth (~> 1.2)
     omniauth-twitter (1.2.1)
       json (~> 1.3)
       omniauth-oauth (~> 1.1)
-    parser (2.2.3.0)
-      ast (>= 1.1, < 3.0)
+    parser (2.3.0.1)
+      ast (~> 2.2)
     pluginator (1.3.0)
     polyglot (0.3.5)
-    power_assert (0.2.6)
+    power_assert (0.2.7)
     powerpack (0.1.1)
     pre-commit (0.26.0)
       pluginator (~> 1.1)
@@ -239,21 +237,19 @@ GEM
       rake (>= 0.8.7)
       thor (>= 0.18.1, < 2.0)
     rainbow (2.0.0)
-    rake (10.4.2)
+    rake (10.5.0)
     rb-fsevent (0.9.7)
     rb-inotify (0.9.5)
       ffi (>= 0.5.0)
     ref (2.0.0)
-    rubocop (0.35.1)
-      astrolabe (~> 1.3)
-      parser (>= 2.2.3.0, < 3.0)
+    rubocop (0.36.0)
+      parser (>= 2.3.0.0, < 3.0)
       powerpack (~> 0.1)
       rainbow (>= 1.99.1, < 3.0)
       ruby-progressbar (~> 1.7)
-      tins (<= 1.6.0)
     ruby-progressbar (1.7.5)
     rubyzip (1.1.7)
-    sass (3.4.20)
+    sass (3.4.21)
     sass-rails (5.0.4)
       railties (>= 4.0.0, < 5.0)
       sass (~> 3.1)
@@ -261,7 +257,7 @@ GEM
       sprockets-rails (>= 2.0, < 4.0)
       tilt (>= 1.1, < 3)
     scrub_rb (1.0.1)
-    selenium-webdriver (2.48.1)
+    selenium-webdriver (2.49.0)
       childprocess (~> 0.5)
       multi_json (~> 1.0)
       rubyzip (~> 1.0)
@@ -277,7 +273,7 @@ GEM
     simplecov-rcov (0.2.3)
       simplecov (>= 0.4.1)
     slop (3.6.0)
-    spring (1.6.1)
+    spring (1.6.2)
     sprockets (3.5.2)
       concurrent-ruby (~> 1.0)
       rack (> 1, < 3)
@@ -293,8 +289,7 @@ GEM
       ref
     thor (0.19.1)
     thread_safe (0.3.5)
-    tilt (2.0.1)
-    tins (1.6.0)
+    tilt (2.0.2)
     treetop (1.4.15)
       polyglot
       polyglot (>= 0.3.1)

+ 5 - 5
app/controllers/search_controller.rb

@@ -20,11 +20,11 @@ class SearchController < ApplicationController
 
     # convert objects string into array of class names
     # e.g. user-ticket-another_object = %w( User Ticket AnotherObject )
-    if !params[:objects]
-      objects = Setting.get('models_searchable')
-    else
-      objects = params[:objects].split('-').map(&:camelize)
-    end
+    objects = if !params[:objects]
+                Setting.get('models_searchable')
+              else
+                params[:objects].split('-').map(&:camelize)
+              end
 
     # get priorities of result
     objects_in_order = []

+ 3 - 5
app/controllers/sessions_controller.rb

@@ -18,11 +18,9 @@ class SessionsController < ApplicationController
     end
 
     # remember me - set session cookie to expire later
-    if params[:remember_me]
-      request.env['rack.session.options'][:expire_after] = 1.year
-    else
-      request.env['rack.session.options'][:expire_after] = nil
-    end
+    request.env['rack.session.options'][:expire_after] = if params[:remember_me]
+                                                           1.year
+                                                         end
     # both not needed to set :expire_after works fine
     #  request.env['rack.session.options'][:renew] = true
     #  reset_session

+ 6 - 6
app/controllers/ticket_articles_controller.rb

@@ -19,7 +19,7 @@ class TicketArticlesController < ApplicationController
 
   # POST /articles
   def create
-    form_id  = params[:ticket_article][:form_id]
+    form_id = params[:ticket_article][:form_id]
     params[:ticket_article].delete(:form_id)
     @article = Ticket::Article.new( Ticket::Article.param_validation( params[:ticket_article] ) )
 
@@ -93,11 +93,11 @@ class TicketArticlesController < ApplicationController
     file = params[:File]
     content_type = file.content_type
     if !content_type || content_type == 'application/octet-stream'
-      if MIME::Types.type_for(file.original_filename).first
-        content_type = MIME::Types.type_for(file.original_filename).first.content_type
-      else
-        content_type = 'application/octet-stream'
-      end
+      content_type = if MIME::Types.type_for(file.original_filename).first
+                       MIME::Types.type_for(file.original_filename).first.content_type
+                     else
+                       'application/octet-stream'
+                     end
     end
     headers_store = {
       'Content-Type' => content_type

+ 12 - 12
app/controllers/tickets_controller.rb

@@ -117,10 +117,10 @@ class TicketsController < ApplicationController
 
     # open tickets by customer
     group_ids = Group.select( 'groups.id' )
-                .joins(:users)
-                .where( 'groups_users.user_id = ?', current_user.id )
-                .where( 'groups.active = ?', true )
-                .map( &:id )
+                     .joins(:users)
+                     .where( 'groups_users.user_id = ?', current_user.id )
+                     .where( 'groups.active = ?', true )
+                     .map( &:id )
 
     access_condition = [ 'group_id IN (?)', group_ids ]
 
@@ -142,7 +142,7 @@ class TicketsController < ApplicationController
     }
 
     ticket_ids_recent_viewed = []
-    recent_views       = RecentView.list( current_user, 8, 'Ticket' )
+    recent_views = RecentView.list( current_user, 8, 'Ticket' )
     recent_views.each {|recent_view|
       next if recent_view['object'] != 'Ticket'
       ticket_ids_recent_viewed.push recent_view['o_id']
@@ -417,15 +417,15 @@ class TicketsController < ApplicationController
 
         # created
         created = Ticket.where('created_at > ? AND created_at < ?', date_start, date_end )
-                  .where(access_condition)
-                  .where(condition)
-                  .count
+                        .where(access_condition)
+                        .where(condition)
+                        .count
 
         # closed
         closed = Ticket.where('close_time > ? AND close_time < ?', date_start, date_end  )
-                 .where(access_condition)
-                 .where(condition)
-                 .count
+                       .where(access_condition)
+                       .where(condition)
+                       .count
 
         data = {
           month: date_to_check.month,
@@ -532,7 +532,7 @@ class TicketsController < ApplicationController
   def article_create(ticket, params)
 
     # create article if given
-    form_id  = params[:form_id]
+    form_id = params[:form_id]
     params.delete(:form_id)
     article = Ticket::Article.new( Ticket::Article.param_validation( params ) )
     article.ticket_id = ticket.id

+ 10 - 10
app/controllers/users_controller.rb

@@ -15,11 +15,11 @@ class UsersController < ApplicationController
   def index
 
     # only allow customer to fetch him self
-    if role?(Z_ROLENAME_CUSTOMER) && !role?(Z_ROLENAME_ADMIN) && !role?('Agent')
-      users = User.where( id: current_user.id )
-    else
-      users = User.all
-    end
+    users = if role?(Z_ROLENAME_CUSTOMER) && !role?(Z_ROLENAME_ADMIN) && !role?('Agent')
+              User.where( id: current_user.id )
+            else
+              User.all
+            end
     users_all = []
     users.each {|user|
       users_all.push User.lookup( id: user.id ).attributes_with_associations
@@ -337,11 +337,11 @@ class UsersController < ApplicationController
     end
 
     # do query
-    if params[:role_ids] && !params[:role_ids].empty?
-      user_all = User.joins(:roles).where( 'roles.id' => params[:role_ids] ).where('users.id != 1').order('users.created_at DESC').limit( params[:limit] || 20 )
-    else
-      user_all = User.where('id != 1').order('created_at DESC').limit( params[:limit] || 20 )
-    end
+    user_all = if params[:role_ids] && !params[:role_ids].empty?
+                 User.joins(:roles).where( 'roles.id' => params[:role_ids] ).where('users.id != 1').order('users.created_at DESC').limit( params[:limit] || 20 )
+               else
+                 User.where('id != 1').order('created_at DESC').limit( params[:limit] || 20 )
+               end
 
     # build result list
     if !params[:full]

+ 9 - 9
app/models/activity_stream.rb

@@ -97,15 +97,15 @@ return all activity entries of an user
     customer_role = Role.lookup( name: 'Customer' )
 
     return [] if role_ids.include?(customer_role.id)
-    if group_ids.empty?
-      stream = ActivityStream.where('(role_id IN (?) AND group_id is NULL)', role_ids )
-               .order( 'created_at DESC, id DESC' )
-               .limit( limit )
-    else
-      stream = ActivityStream.where('(role_id IN (?) AND group_id is NULL) OR ( role_id IN (?) AND group_id IN (?) ) OR ( role_id is NULL AND group_id IN (?) )', role_ids, role_ids, group_ids, group_ids )
-               .order( 'created_at DESC, id DESC' )
-               .limit( limit )
-    end
+    stream = if group_ids.empty?
+               ActivityStream.where('(role_id IN (?) AND group_id is NULL)', role_ids )
+                             .order( 'created_at DESC, id DESC' )
+                             .limit( limit )
+             else
+               ActivityStream.where('(role_id IN (?) AND group_id is NULL) OR ( role_id IN (?) AND group_id IN (?) ) OR ( role_id is NULL AND group_id IN (?) )', role_ids, role_ids, group_ids, group_ids )
+                             .order( 'created_at DESC, id DESC' )
+                             .limit( limit )
+             end
     list = []
     stream.each do |item|
       data           = item.attributes

+ 12 - 12
app/models/application_model.rb

@@ -142,7 +142,7 @@ returns
     attributes = self.attributes
     self.class.reflect_on_all_associations.map { |assoc|
       real_key = assoc.name.to_s[0, assoc.name.to_s.length - 1] + '_ids'
-      if self.respond_to?(real_key)
+      if respond_to?(real_key)
         attributes[ real_key ] = send(real_key)
       end
     }
@@ -230,7 +230,7 @@ returns
   end
 
   def cache_update(o)
-    cache_delete if self.respond_to?('cache_delete')
+    cache_delete if respond_to?('cache_delete')
     o.cache_delete if o.respond_to?('cache_delete')
   end
 
@@ -241,7 +241,7 @@ returns
     Cache.delete(key)
 
     # delete old name / login caches
-    if self.changed?
+    if changed?
       if changes.key?('name')
         name = changes['name'][0]
         key = "#{self.class}::#{name}"
@@ -349,9 +349,9 @@ returns
         end
       }
       return
-    else
-      fail 'Need name, id or login for lookup()'
     end
+
+    fail 'Need name, id or login for lookup()'
   end
 
 =begin
@@ -442,7 +442,7 @@ returns
       # do lookup with == to handle case insensitive databases
       records = where(login: data[:login])
       records.each {|loop_record|
-        if loop_record.login.downcase == data[:login].downcase
+        if loop_record.login.casecmp data[:login] == 0
           loop_record.update_attributes(data)
           return loop_record
         end
@@ -455,7 +455,7 @@ returns
       # do lookup with == to handle case insensitive databases
       records = where(email: data[:email])
       records.each {|loop_record|
-        if loop_record.email.downcase == data[:email].downcase
+        if loop_record.email.casecmp data[:email] == 0
           loop_record.update_attributes(data)
           return loop_record
         end
@@ -468,7 +468,7 @@ returns
       # do lookup with == to handle case insensitive databases
       records = where(locale: data[:locale])
       records.each {|loop_record|
-        if loop_record.locale.downcase == data[:locale].downcase
+        if loop_record.locale.casecmp data[:locale] == 0
           loop_record.update_attributes(data)
           return loop_record
         end
@@ -783,7 +783,7 @@ log object update activity stream, if configured - will be executed automaticall
   def activity_stream_update
     return if !self.class.activity_stream_support_config
 
-    return if !self.changed?
+    return if !changed?
 
     # default ignored attributes
     ignore_attributes = {
@@ -872,10 +872,10 @@ log object update history with all updated attributes, if configured - will be e
   def history_update
     return if !self.class.history_support_config
 
-    return if !self.changed?
+    return if !changed?
 
     # return if it's no update
-    return if self.new_record?
+    return if new_record?
 
     # new record also triggers update, so ignore new records
     changes = self.changes
@@ -921,7 +921,7 @@ log object update history with all updated attributes, if configured - will be e
         value_id[0] = value[0]
         value_id[1] = value[1]
 
-        if self.respond_to?( attribute_name ) && send(attribute_name)
+        if respond_to?( attribute_name ) && send(attribute_name)
           relation_class = send(attribute_name).class
           if relation_class && value_id[0]
             relation_model = relation_class.lookup( id: value_id[0] )

+ 5 - 5
app/models/calendar.rb

@@ -344,11 +344,11 @@ returns
       if public_holidays_was && public_holidays_was[day] && public_holidays_was[day]['feed']
         meta['feed'] = public_holidays_was[day]['feed']
       end
-      if meta['active']
-        meta['active'] = true
-      else
-        meta['active'] = false
-      end
+      meta['active'] = if meta['active']
+                         true
+                       else
+                         false
+                       end
     }
 
   end

Некоторые файлы не были показаны из-за большого количества измененных файлов