Skip to content

Commit

Permalink
Fixed rubocop issues and added test for ar_merge_conditions.
Browse files Browse the repository at this point in the history
  • Loading branch information
gtanzillo committed Jul 14, 2015
1 parent bba8ca8 commit f1c1136
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 19 deletions.
24 changes: 12 additions & 12 deletions lib/extensions/ar_merge_conditions.rb
Expand Up @@ -44,7 +44,7 @@ def self.apply_legacy_finder_options(options)
end

def self.reflection_is_polymorphic?(name)
reflection = self._reflect_on_association(name)
reflection = _reflect_on_association(name)
reflection ? reflection.polymorphic? : false
end

Expand All @@ -56,17 +56,17 @@ def self.included_associations(includes)

def self._included_associations(includes, arr)
case includes
when Symbol, String
arr << includes.to_sym
when Array
includes.each do |assoc|
_included_associations assoc, arr
end
when Hash
includes.each do |k,v|
cache = arr << k
_included_associations v, cache
end
when Symbol, String
arr << includes.to_sym
when Array
includes.each do |assoc|
_included_associations assoc, arr
end
when Hash
includes.each do |k, v|
cache = arr << k
_included_associations v, cache
end
end
end
end
Expand Down
48 changes: 48 additions & 0 deletions spec/lib/extensions/ar_merge_conditions_spec.rb
@@ -0,0 +1,48 @@
require "spec_helper"

describe ActiveRecord::Base do
context "calling apply_legacy_finder_options" do
before(:each) do
@vm = FactoryGirl.create(:vm_vmware)
@perf = FactoryGirl.create(
:metric_rollup_vm_daily,
:resource_id => @vm.id,
:timestamp => "2010-04-14T00:00:00Z",
:time_profile => @time_profile
)

# Typical includes for rendering daily metrics charts
@include = {
:max_derived_cpu_available => {},
:max_derived_cpu_reserved => {},
:min_cpu_usagemhz_rate_average => {},
:max_cpu_usagemhz_rate_average => {},
:min_cpu_usage_rate_average => {},
:max_cpu_usage_rate_average => {},
:v_pct_cpu_ready_delta_summation => {},
:v_pct_cpu_wait_delta_summation => {},
:v_pct_cpu_used_delta_summation => {},
:max_derived_memory_available => {},
:max_derived_memory_reserved => {},
:min_derived_memory_used => {},
:max_derived_memory_used => {},
:min_disk_usage_rate_average => {},
:max_disk_usage_rate_average => {},
:min_net_usage_rate_average => {},
:max_net_usage_rate_average => {},
:v_derived_storage_used => {},
:resource => {}

}
end
it "should not raise an error when a polymorphic reflection is included" do
result = nil
expect do
result = MetricRollup.apply_legacy_finder_options(:include => @include).to_a
end.not_to raise_error

result.length.should == 1
end
end
end

16 changes: 9 additions & 7 deletions spec/models/metric_rollup_spec.rb
Expand Up @@ -5,16 +5,18 @@
it "should not raise an error when a polymorphic reflection is included and references are specified in a query" do
pending "until ActiveRecord is fixed"
# TODO: A fix in ActiveRecord will make this test pass
expect {
MetricRollup.where(:id=>1000000544893).includes(:resource=>{}, :time_profile=>{}).references(:time_profile=>{}).last
}.not_to raise_error
expect do
MetricRollup.where(:id => 1000000544893)
.includes(:resource => {}, :time_profile => {})
.references(:time_profile => {}).last
end.not_to raise_error

# TODO: Also, there is a bug that exists in only the manageiq repo and not rails that causes the error "ActiveRecord::ConfigurationError: nil"
# TODO: Also, there is a bug that exists in only the manageiq repo and not rails
# TODO: that causes the error "ActiveRecord::ConfigurationError: nil"
# TODO: instead of the expected "ActiveRecord::EagerLoadPolymorphicError" error.
expect {
expect do
Tagging.includes(:taggable => {}).where('bogus_table.column = 1').references(:bogus_table => {}).to_a
}.to raise_error ActiveRecord::EagerLoadPolymorphicError
end.to raise_error ActiveRecord::EagerLoadPolymorphicError
end
end
end

0 comments on commit f1c1136

Please sign in to comment.