Project

General

Profile

« Previous | Next » 

Revision 8e81effc

Added by Amit Karsale over 7 years ago

Fixes #13775 - merge if data set is present

View differences:

app/controllers/api/base_controller.rb
association = resource_class.reflect_on_all_associations.find {|assoc| assoc.plural_name == parent_name.pluralize}
#if couldn't find an association by name, try to find one by class
association ||= resource_class.reflect_on_all_associations.find {|assoc| assoc.class_name == parent_name.camelize}
result_scope = resource_class.joins(association.name).merge(scope)
result_scope = resource_class_join(association, scope)
# Check that the scope resolves before return
result_scope if result_scope.to_a
rescue ActiveRecord::ConfigurationError
......
where(association.name => scope.map(&:id))
end
def resource_class_join(association, scope)
resource_class.joins(association.name).merge(scope)
end
def resource_scope_for_index(options = {})
resource_scope(options).search_for(*search_options).paginate(paginate_options)
end
app/controllers/api/v2/hosts_controller.rb
def allowed_nested_id
%w(hostgroup_id location_id organization_id environment_id)
end
def resource_class_join(association, scope)
resource_class_join = resource_class.joins(association.name)
resource_class_join.merge(scope).present? ? resource_class_join.merge(scope) : resource_class_join
end
end
end
end
test/controllers/api/v2/hosts_controller_test.rb
)
end
def basic_attrs_with_hg
hostgroup_attr = {
:hostgroup_id => Hostgroup.first.id
}
basic_attrs.merge(hostgroup_attr)
end
def nics_attrs
[{
:primary => true,
......
assert_response :success
end
test "should update hostgroup_id of host" do
@host = FactoryGirl.create(:host, basic_attrs_with_hg)
put :update, { :id => @host.to_param, :hostgroup_id => Hostgroup.last.id }
assert_response :success
end
test "should update interfaces from compute profile" do
disable_orchestration

Also available in: Unified diff