fixes #18662 - stop default scope being overridden by association
Ensure the Taxonomix empty default scope isn't overridden by association scopes which (effectively) calls `.where(:id => ...)` and overrides the value of :id set in this default scope. This occurs on Rails 5.0 which merges the scopes more correctly/effectively than 4.2, and so invisible resources became visible through the association getter.
Like the case where there is at least one visible resource, a string SQL fragment is used instead to prevent it being overridden by ActiveRecord.
The host test now uses an admin user as it was testing that the host's environment was nil (since hostgroup#environment now returns nil due to the default scope), rather than a present value. This failed on 5.0 when hostgroup#environment returned the invisible record.
Related issues
Bug #18662: Ensure Taxonomix empty default scope isn't overridden by association scopes
fixes #18662 - stop default scope being overridden by association
Ensure the Taxonomix empty default scope isn't overridden by association
scopes which (effectively) calls `.where(:id => ...)` and overrides the
value of :id set in this default scope. This occurs on Rails 5.0 which
merges the scopes more correctly/effectively than 4.2, and so invisible
resources became visible through the association getter.
Like the case where there is at least one visible resource, a string SQL
fragment is used instead to prevent it being overridden by ActiveRecord.
The host test now uses an admin user as it was testing that the host's
environment was nil (since hostgroup#environment now returns nil due to
the default scope), rather than a present value. This failed on 5.0 when
hostgroup#environment returned the invisible record.