Skip to content

Commit cc8438f

Browse files
committed
Tests and comments around rbac and ActsAsArScope
Turns out for AAAS case, we currently only need to define all Rbac has already used all, so all methods go directly to the aar_scope (which an an active record scope) So all of these other methods are moot. Well, for this implementation. We do want it to be complete in case the code changes and someone decides to do something like call eager_load before calling all
1 parent 9c9a137 commit cc8438f

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

lib/acts_as_ar_model.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ def self.search(mode, options = {})
158158
end
159159
private_class_method :search
160160

161+
# Note: ignores references
161162
def self.to_legacy_options(options)
162163
{
163164
:conditions => options[:where],

lib/rbac/filterer.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,8 @@ def select_from_order_columns(columns)
429429
end
430430
end
431431

432+
# For ActsAsArModel - scope should be a a QueryRelation
433+
# For ActsAsArScope - scope should be a standard AR scope (with where and others tacked in)
432434
def include_references(scope, klass, includes, references, exp_includes)
433435
# TODO: do we want to klass.prune_references(exp_includes)? (see same comment for inline_view? section)
434436
scope.eager_load(references || {}).eager_load(exp_includes || {}).preload(includes)

spec/lib/rbac/filterer_spec.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2659,11 +2659,32 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects)
26592659
expect(described_class.filtered(Vm.where(:location => "good"))).to match_array(matched_vms)
26602660
end
26612661

2662-
it "support aaarm object" do
2662+
# Note: VimPerformanceTrend doesn't even implement find. Just testing this follows standard aaarm protocols
2663+
it "support ActsAsArModel object" do
26632664
expect(VimPerformanceTrend).to receive(:find).with(:all, {:include => {:a => {}}}).and_return([:good])
26642665
expect(described_class.filtered(VimPerformanceTrend, :include_for_find => {:a => {}}).to_a).to match_array([:good])
26652666
end
26662667

2668+
it "supports ActsAsArScope object all target" do
2669+
all_vms
2670+
2671+
klass = ManageIQ::Providers::InfraManager::VmOrTemplate
2672+
expect(klass).to receive(:all).and_call_original
2673+
expect(described_class.filtered(klass, :include_for_find => {:host => {}}).to_a).to eq(all_vms)
2674+
end
2675+
2676+
it "supports ActsAsArScope object scoping" do
2677+
all_vms
2678+
filter = MiqExpression.new("=" => {"field" => "Vm-location", "value" => "good"})
2679+
expect(described_class.filtered(ManageIQ::Providers::InfraManager::VmOrTemplate, :filter => filter)).to match_array(matched_vms)
2680+
end
2681+
2682+
it "understands ActsAsArScope includes (invalid)" do
2683+
expect {
2684+
expect(described_class.filtered(klass, :include_for_find => {:missing_association => {}}).to_a).to eq(klass.none)
2685+
}.to_raise(ActiveRecord::ConfigurationError)
2686+
end
2687+
26672688
# it returns objects too
26682689
# TODO: cap number of queries here
26692690
it "runs rbac on array target" do

0 commit comments

Comments
 (0)