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

Display Generic Object Associations correctly (Post /report_data related GTL fixes) #2596

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 14 additions & 7 deletions app/controllers/generic_object_controller.rb
Expand Up @@ -17,14 +17,21 @@ def self.model
GenericObject
end

def self.populate_display_methods(record)
define_singleton_method("display_methods") do
associations = %w()
record.property_associations.each do |key, _value|
associations.push(key)
end
associations
def self.display_methods
[]
end

def display_methods(record)
associations = %w()
record.property_associations.each do |key, _value|
associations.push(key)
end
associations
end

def display_nested_generic(display)
return unless @record.property_associations.key?(display)
nested_list(display, @record.generic_object_definition.properties[:associations][display], :association => display)
end

private
Expand Down
12 changes: 9 additions & 3 deletions app/controllers/mixins/generic_show_mixin.rb
Expand Up @@ -5,8 +5,6 @@ def show
return unless init_show
@center_toolbar = self.class.toolbar_singular if self.class.toolbar_singular

self.class.populate_display_methods(@record) if self.class.respond_to?(:populate_display_methods)

case @display
# these methods are defined right in GenericShowMixin
when "summary_only"
Expand All @@ -28,10 +26,14 @@ def show
when "topology"
show_topology

# nested list methods as enabled by 'display_methods'
# nested list methods as enabled by 'display_methods' on the class
when *self.class.display_methods
display_nested_list(@display)

# .. or on an instance
when *display_methods(@record)
display_nested_list(@display)

else
# if the controller implements more display modes for #show, invoke those
if self.class.respond_to?(:custom_display_modes)
Expand All @@ -44,6 +46,10 @@ def show
end
end

def display_methods
[]
end

def custom_display_method(display)
methods = self.class.custom_display_modes
# Converting to hash so brakeman doesn't complain about using params directly
Expand Down
24 changes: 24 additions & 0 deletions spec/controllers/generic_object_controller_spec.rb
Expand Up @@ -14,6 +14,30 @@
get :show, :params => {:id => generic_obj.id}
end
it { expect(response.status).to eq(200) }

it 'displays Generic Object association in the nested display list' do
generic_obj_defn = FactoryGirl.create(
:generic_object_definition,
:name => "test_definition",
:properties => {
:attributes => {
:flag => "boolean",
:data_read => "float",
:max_number => "integer",
:server => "string",
:s_time => "datetime"
},
:associations => {"cp" => "ManageIQ::Providers::CloudManager", "vms" => "Vm"},
:methods => %w(some_method)
}
)
generic_obj = FactoryGirl.create(:generic_object, :generic_object_definition_id => generic_obj_defn.id)
get :show, :params => { :display => "cp", :id => generic_obj.id }
expect(response.status).to eq(200)

get :show, :params => { :display => "vms", :id => generic_obj.id }
expect(response.status).to eq(200)
end
end

describe "#show_list" do
Expand Down