diff --git a/.travis.yml b/.travis.yml index cd4d07c..b616c2e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: ruby rvm: - 2.5.3 +services: + - mysql branches: only: - master diff --git a/Gemfile b/Gemfile index 95a428a..d073c6f 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,7 @@ gem 'active_record-acts_as', git: 'https://github.com/camsys/active_record-acts_ # To use debugger # gem 'debugger' -gem 'transam_core', git: 'https://github.com/camsys/transam_core', branch: :quarter1 +gem 'transam_core', git: 'https://github.com/camsys/transam_core', branch: :quarter2 gem 'mysql2', "~> 0.5.1" # lock gem for dummy app gem "capybara", '2.6.2' # lock gem for old capybara behavior on hidden element xpath gem 'sass-rails' diff --git a/app/controllers/audit_results_controller.rb b/app/controllers/audit_results_controller.rb index 1eeca22..9c2c32c 100644 --- a/app/controllers/audit_results_controller.rb +++ b/app/controllers/audit_results_controller.rb @@ -17,6 +17,7 @@ def index # Get the list of audit types for this organization # @types = AuditResult.where(:organization_id => @organization_list).pluck(:class_name).uniq @filterables = AuditResult.where(:organization_id => @organization_list).distinct.pluck(:filterable_type, :filterable_id) + @filterables = [[nil,nil]] if @filterables.empty? # make sure there is an array even if no results conditions = Hash.new diff --git a/app/models/asset_auditor.rb b/app/models/asset_auditor.rb index 774eb2d..8d8ad42 100644 --- a/app/models/asset_auditor.rb +++ b/app/models/asset_auditor.rb @@ -10,26 +10,9 @@ class AssetAuditor < AbstractAuditor # Only run audit if asset has changes related to audit #----------------------------------------------------------------------------- def detect_changes? asset - has_changes = false - - asset_fields_audited = [ - :reported_condition_date, - :reported_condition_type_id, - :reported_condition_rating, - :service_status_date, - :service_status_type_id, - :reported_mileage, - :reported_mileage_date - ] - - asset_fields_audited.each do |field| - if asset.changes.include? field.to_s - has_changes = true - break - end - end - has_changes + # check if in service date is before audit period but otherwise assume changes as asset events trigger audit through TransamSubAuditable + asset.in_service_date <= context.end_date end #----------------------------------------------------------------------------- diff --git a/app/models/concerns/transam_auditable.rb b/app/models/concerns/transam_auditable.rb index 2140079..3fea710 100644 --- a/app/models/concerns/transam_auditable.rb +++ b/app/models/concerns/transam_auditable.rb @@ -62,16 +62,11 @@ def audits Audit.active.where(:id => audit_results.pluck(:audit_id).uniq) end - #----------------------------------------------------------------------------- - # Protected Methods - #----------------------------------------------------------------------------- - protected - def check_for_audit_changes Rails.logger.debug "checking for audit changes" audit_changed = false audits.each do |audit| - if self.in_service_date <= audit.end_date && audit.operational? and audit.auditor.detect_changes? self + if audit.operational? and audit.auditor.detect_changes? self audit_changed = true break end diff --git a/app/models/concerns/transam_sub_auditable.rb b/app/models/concerns/transam_sub_auditable.rb new file mode 100644 index 0000000..45ea78f --- /dev/null +++ b/app/models/concerns/transam_sub_auditable.rb @@ -0,0 +1,45 @@ +module TransamSubAuditable + #----------------------------------------------------------------------------- + # + # TransamSubAuditable + # + # If an association needs to trigger the audit, insert this mixin so parent auditable runs auditable callbacks + # + #----------------------------------------------------------------------------- + extend ActiveSupport::Concern + + included do + after_save :force_save_parent_asset + after_destroy :force_save_parent_asset + end + + #----------------------------------------------------------------------------- + # Class Methods + #----------------------------------------------------------------------------- + + module ClassMethods + + end + + #----------------------------------------------------------------------------- + # Instance Methods + #----------------------------------------------------------------------------- + + + + + #----------------------------------------------------------------------------- + # Protected Methods + #----------------------------------------------------------------------------- + protected + + def force_save_parent_asset + # find parent + parent_class_name = SystemConfigExtension.find_by(extension_name: 'TransamAuditable').class_name + + parent = self.send(parent_class_name.underscore) + parent.check_for_audit_changes + parent.update_audits + end + +end diff --git a/app/views/audit_results/_index_asset_table.html.haml b/app/views/audit_results/_index_asset_table.html.haml index 6642c1d..c71964b 100644 --- a/app/views/audit_results/_index_asset_table.html.haml +++ b/app/views/audit_results/_index_asset_table.html.haml @@ -4,8 +4,8 @@ .table-responsive %table.table.table-hover{:id => 'audit_results_table', :data => {:toggle => 'table', :pagination => 'true', - :show_pagination_switch => 'true', - :page_list => "[5, 10, 20, 50, 100, 200]", + :show_pagination_switch => 'false', + :page_list => "[5, 10, 20, 50, 100, 200, 10000]", :page_size => current_user.num_table_rows, :search => 'false', :toolbar => "#table_actions", diff --git a/app/views/audit_results/_index_table.html.haml b/app/views/audit_results/_index_table.html.haml index 2686930..680a0e3 100644 --- a/app/views/audit_results/_index_table.html.haml +++ b/app/views/audit_results/_index_table.html.haml @@ -4,8 +4,8 @@ .table-responsive %table.table.table-hover{:id => 'audit_results_table', :data => {:toggle => 'table', :pagination => 'true', - :show_pagination_switch => 'true', - :page_list => "[5, 10, 20, 50, 100, 200]", + :show_pagination_switch => 'false', + :page_list => "[5, 10, 20, 50, 100, 200, 10000]", :page_size => current_user.num_table_rows, :search => 'false', :toolbar => "#table_actions", diff --git a/app/views/audits/_index_table.html.haml b/app/views/audits/_index_table.html.haml index 6eeb40d..0108ec8 100644 --- a/app/views/audits/_index_table.html.haml +++ b/app/views/audits/_index_table.html.haml @@ -4,8 +4,8 @@ .table-responsive %table.table.table-hover{:id => table_dom_id, :data => {:toggle => 'table', :pagination => 'true', - :show_pagination_switch => 'true', - :page_list => "[5, 10, 20, 50, 100, 200]", + :show_pagination_switch => 'false', + :page_list => "[5, 10, 20, 50, 100, 200, 10000]", :page_size => current_user.num_table_rows, :search => 'false', :toolbar => "#table_actions", diff --git a/db/data_migrations/20190313123702_add_sub_auditable_extension_asset_events.rb b/db/data_migrations/20190313123702_add_sub_auditable_extension_asset_events.rb new file mode 100644 index 0000000..ab61e8f --- /dev/null +++ b/db/data_migrations/20190313123702_add_sub_auditable_extension_asset_events.rb @@ -0,0 +1,15 @@ +class AddSubAuditableExtensionAssetEvents < ActiveRecord::DataMigration + def up + system_config_extensions = [{engine_name: 'audit', class_name: 'ConditionUpdateEvent', extension_name: 'TransamSubAuditable', active: true}, + {engine_name: 'audit', class_name: 'ServiceStatusUpdateEvent', extension_name: 'TransamSubAuditable', active: true} + ] + + if SystemConfig.transam_module_loaded? :transit + system_config_extensions << {engine_name: 'audit', class_name: 'MileageUpdateEvent', extension_name: 'TransamSubAuditable', active: true} + end + + system_config_extensions.each do |ext| + SystemConfigExtension.create!(ext) + end + end +end \ No newline at end of file diff --git a/db/seeds.rb b/db/seeds.rb index 5d52ec5..dd39fc2 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -30,9 +30,15 @@ # currently add auditable mixin to old assets as well system_config_extensions = [ - {engine_name: 'audit', class_name: 'TransamAsset', extension_name: 'TransamAuditable', active: true} + {engine_name: 'audit', class_name: 'TransamAsset', extension_name: 'TransamAuditable', active: true}, + {engine_name: 'audit', class_name: 'ConditionUpdateEvent', extension_name: 'TransamSubAuditable', active: true}, + {engine_name: 'audit', class_name: 'ServiceStatusUpdateEvent', extension_name: 'TransamSubAuditable', active: true} ] +if SystemConfig.transam_module_loaded? :transit + system_config_extensions << {engine_name: 'audit', class_name: 'MileageUpdateEvent', extension_name: 'TransamSubAuditable', active: true} +end + lookup_tables = %w{ audit_result_types } lookup_tables.each do |table_name| diff --git a/lib/transam_audit/version.rb b/lib/transam_audit/version.rb index 988c3ae..da9612a 100644 --- a/lib/transam_audit/version.rb +++ b/lib/transam_audit/version.rb @@ -1,3 +1,3 @@ module TransamAudit - VERSION = "2.5.0" + VERSION = "2.6.0" end diff --git a/spec/dummy/config/database.travis.yml b/spec/dummy/config/database.travis.yml index 97652f5..4b95acb 100644 --- a/spec/dummy/config/database.travis.yml +++ b/spec/dummy/config/database.travis.yml @@ -6,6 +6,8 @@ mysql: &mysql adapter: mysql2 + variables: + sql_mode: traditional username: root password: database: transam_audit_testing diff --git a/spec/dummy/config/environments/production.rb b/spec/dummy/config/environments/production.rb index 7238677..8527a98 100644 --- a/spec/dummy/config/environments/production.rb +++ b/spec/dummy/config/environments/production.rb @@ -23,7 +23,7 @@ config.serve_static_files = false # Compress JavaScripts and CSS. - config.assets.js_compressor = :uglifier + config.assets.js_compressor = Uglifier.new(harmony: true) if defined? Uglifier # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed.