Project

General

Profile

« Previous | Next » 

Revision 9d402d07

Added by Greg Sutcliffe almost 11 years ago

Fixes #2501 - Allow my_hosts scope to include all subclasses of Host::Base

View differences:

app/models/host/base.rb
name
end
def ==(comparison_object)
super ||
comparison_object.is_a?(Host::Base) &&
id.present? &&
comparison_object.id == id
end
end
end
app/models/host/managed.rb
current = User.current
if (operation == "edit") or operation == "destroy"
if current.allowed_to?("#{operation}_hosts".to_sym)
return true if Host.my_hosts.include? self
return true if Host::Base.my_hosts.include? self
end
else # create
if current.allowed_to?(:create_hosts)
test/unit/host_test.rb
assert_equal 'my5name.mydomain.net', Host.my_hosts.first.name
end
test "sti types altered in memory with becomes are still contained in my_hosts scope" do
class Host::Valid < Host::Base ; belongs_to :domain ; end
h = Host::Valid.new :name => "mytestvalidhost.foo.com"
setup_user_and_host
as_admin do
@one.domains = [domains(:yourdomain)] # ensure it matches the user filters
h.update_attribute :domain, domains(:yourdomain)
end
h_new = h.becomes(Host::Managed) # change the type to break normal AR `==` method
assert Host::Base.my_hosts.include?(h_new)
end
test "host can be edited when user fact filter permits" do
setup_filtered_user
as_admin do

Also available in: Unified diff