Skip to content

Commit

Permalink
fixes #14076 - remove unused Puppetclass hostgroups counter
Browse files Browse the repository at this point in the history
  • Loading branch information
domcleal committed Mar 7, 2016
1 parent d0732ec commit c3c5f4c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/models/hostgroup_class.rb
Expand Up @@ -5,7 +5,7 @@ class HostgroupClass < ActiveRecord::Base

audited :associated_with => :hostgroup, :allow_mass_assignment => true
belongs_to :hostgroup
belongs_to :puppetclass, :counter_cache => :hostgroups_count
belongs_to :puppetclass

attr_accessible :hostgroup_id, :hostgroup, :puppetclass_id, :puppetclass
validates :hostgroup, :presence => true
Expand Down
@@ -0,0 +1,10 @@
class RemoveHostgroupsCountFromPuppetclasses < ActiveRecord::Migration
def up
remove_column :puppetclasses, :hostgroups_count
end

def down
add_column :puppetclasses, :hostgroups_count, :integer, :default => 0
execute 'UPDATE puppetclasses SET hostgroups_count = (SELECT COUNT(*) FROM hostgroup_classes WHERE hostgroup_classes.puppetclass_id = puppetclasses.id)'
end
end
8 changes: 0 additions & 8 deletions test/unit/hostgroup_class_test.rb
Expand Up @@ -15,12 +15,4 @@ class HostgroupClassTest < ActiveSupport::TestCase
end
end
end

test "should update hostgroups_count" do
pc = puppetclasses(:two)
assert_difference "pc.hostgroups_count" do
HostgroupClass.create(:puppetclass_id => pc.id, :hostgroup_id => hostgroups(:common).id)
pc.reload
end
end
end

0 comments on commit c3c5f4c

Please sign in to comment.