Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put back region_description method that was accidentally extracted #15372

Merged
merged 1 commit into from
Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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