Skip to content

Commit

Permalink
Put back region_description method that was accidentally extracted
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryguy committed Jun 14, 2017
1 parent 4e2e528 commit 2fac75c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ manageiq_plugin "manageiq-providers-vmware"
manageiq_plugin "manageiq-ui-classic"

# Unmodified gems
gem "activerecord-id_regions", "~>0.1.0"
gem "activerecord-id_regions", "~>0.2.0"
gem "activerecord-session_store", "~>1.0.0"
gem "acts_as_tree", "~>2.1.0" # acts_as_tree needs to be required so that it loads before ancestry
gem "ancestry", "~>2.2.1", :require => false
Expand Down
6 changes: 5 additions & 1 deletion lib/extensions/ar_region.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module ClassMethods
def inherited(other)
if other == other.base_class
other.class_eval do
virtual_column :region_number, :type => :integer
virtual_column :region_number, :type => :integer # This method is defined in ActiveRecord::IdRegions
virtual_column :region_description, :type => :string
end
end
Expand All @@ -20,4 +20,8 @@ def inherited(other)
def miq_region
self.class.id_to_miq_region[region_number] || (self.class.id_to_miq_region[region_number] = MiqRegion.where(:region => region_number).first)
end

def region_description
miq_region.description if miq_region
end
end
13 changes: 13 additions & 0 deletions spec/lib/extensions/ar_region_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,17 @@
end.to match_query_limit_of(2)
end
end

context "#region_description" do
it "when the region exists" do
MiqRegion.seed
vm = FactoryGirl.create(:vm)
expect(vm.region_description).to eq(MiqRegion.first.description)
end

it "when the region does not exist" do
vm = FactoryGirl.create(:vm)
expect(vm.region_description).to be_nil
end
end
end

0 comments on commit 2fac75c

Please sign in to comment.