Skip to content

Commit

Permalink
Merge pull request #34 from camsys/quarter2
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mathmerized authored Jun 4, 2019
2 parents e7afdbf + 8c0bbde commit c7b740c
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 35 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: ruby
rvm:
- 2.5.3
services:
- mysql
branches:
only:
- master
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions app/controllers/audit_results_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 2 additions & 19 deletions app/models/asset_auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

#-----------------------------------------------------------------------------
Expand Down
7 changes: 1 addition & 6 deletions app/models/concerns/transam_auditable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions app/models/concerns/transam_sub_auditable.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions app/views/audit_results/_index_asset_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions app/views/audit_results/_index_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions app/views/audits/_index_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
2 changes: 1 addition & 1 deletion lib/transam_audit/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module TransamAudit
VERSION = "2.5.0"
VERSION = "2.6.0"
end
2 changes: 2 additions & 0 deletions spec/dummy/config/database.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

mysql: &mysql
adapter: mysql2
variables:
sql_mode: traditional
username: root
password:
database: transam_audit_testing
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c7b740c

Please sign in to comment.