diff --git a/app/decorators/field_service_instance_broker_decorator.rb b/app/decorators/field_service_instance_broker_decorator.rb index 8ef848ac1e9..a5bc773296e 100644 --- a/app/decorators/field_service_instance_broker_decorator.rb +++ b/app/decorators/field_service_instance_broker_decorator.rb @@ -22,7 +22,7 @@ def decorate(hash, service_instances) join(:service_instances, service_plan_id: :service_plans__id). where(service_instances__id: managed_service_instances.map(&:id)). distinct. - order_by(:service_brokers__created_at). + order_by(:service_brokers__created_at, :service_brokers__guid). select(:service_brokers__name, :service_brokers__guid, :service_brokers__created_at). all diff --git a/app/decorators/field_service_instance_offering_decorator.rb b/app/decorators/field_service_instance_offering_decorator.rb index 5bb54b03881..2e1c8b3007f 100644 --- a/app/decorators/field_service_instance_offering_decorator.rb +++ b/app/decorators/field_service_instance_offering_decorator.rb @@ -21,7 +21,7 @@ def decorate(hash, service_instances) join(:service_instances, service_plan_id: :service_plans__id). where(service_instances__id: managed_service_instances.map(&:id)). distinct. - order_by(:services__created_at). + order_by(:services__created_at, :services__guid). select(:services__label, :services__guid, :services__description, :services__tags, :services__extra, :services__service_broker_id, :services__created_at). all diff --git a/app/decorators/field_service_instance_organization_decorator.rb b/app/decorators/field_service_instance_organization_decorator.rb index a3de525732d..db1cde83847 100644 --- a/app/decorators/field_service_instance_organization_decorator.rb +++ b/app/decorators/field_service_instance_organization_decorator.rb @@ -17,7 +17,7 @@ def decorate(hash, resources) spaces = resources.map { |r| r.try(:space) || r }.uniq orgs = spaces.map(&:organization).uniq - hash[:included][:organizations] = orgs.sort_by(&:created_at).map do |org| + hash[:included][:organizations] = orgs.sort_by { |o| [o.created_at, o.guid] }.map do |org| org_view = {} org_view[:name] = org.name if @fields.include?('name') org_view[:guid] = org.guid if @fields.include?('guid') diff --git a/app/decorators/field_service_instance_plan_decorator.rb b/app/decorators/field_service_instance_plan_decorator.rb index ef47e9a44ab..dd1af646a4e 100644 --- a/app/decorators/field_service_instance_plan_decorator.rb +++ b/app/decorators/field_service_instance_plan_decorator.rb @@ -19,7 +19,7 @@ def decorate(hash, service_instances) hash[:included] ||= {} plans = managed_service_instances.map(&:service_plan).uniq - hash[:included][:service_plans] = plans.sort_by(&:created_at).map do |plan| + hash[:included][:service_plans] = plans.sort_by { |p| [p.created_at, p.guid] }.map do |plan| plan_view = {} plan_view[:guid] = plan.guid if @fields.include?('guid') plan_view[:name] = plan.name if @fields.include?('name') diff --git a/app/decorators/field_service_instance_space_decorator.rb b/app/decorators/field_service_instance_space_decorator.rb index 305597e6044..1eb2f8709c4 100644 --- a/app/decorators/field_service_instance_space_decorator.rb +++ b/app/decorators/field_service_instance_space_decorator.rb @@ -17,7 +17,7 @@ def decorate(hash, resources) spaces = resources.map { |r| r.try(:space) || r }.uniq - hash[:included][:spaces] = spaces.sort_by(&:created_at).map do |space| + hash[:included][:spaces] = spaces.sort_by { |s| [s.created_at, s.guid] }.map do |space| temp = {} temp[:guid] = space.guid if @fields.include?('guid') temp[:name] = space.name if @fields.include?('name') diff --git a/app/decorators/field_service_offering_service_broker_decorator.rb b/app/decorators/field_service_offering_service_broker_decorator.rb index ea513f0f12c..7ee3d49e0b2 100644 --- a/app/decorators/field_service_offering_service_broker_decorator.rb +++ b/app/decorators/field_service_offering_service_broker_decorator.rb @@ -15,7 +15,7 @@ def initialize(fields) def decorate(hash, service_offerings) hash[:included] ||= {} service_brokers = service_offerings.map(&:service_broker).uniq - hash[:included][:service_brokers] = service_brokers.sort_by(&:created_at).map do |broker| + hash[:included][:service_brokers] = service_brokers.sort_by { |sb| [sb.created_at, sb.guid] }.map do |broker| broker_view = {} broker_view[:name] = broker.name if @fields.include?('name') broker_view[:guid] = broker.guid if @fields.include?('guid') diff --git a/app/decorators/field_service_plan_service_broker_decorator.rb b/app/decorators/field_service_plan_service_broker_decorator.rb index 08c69e1b142..cdba6244048 100644 --- a/app/decorators/field_service_plan_service_broker_decorator.rb +++ b/app/decorators/field_service_plan_service_broker_decorator.rb @@ -16,7 +16,7 @@ def decorate(hash, service_plans) hash[:included] ||= {} service_offerings = service_plans.map(&:service).uniq service_brokers = service_offerings.map(&:service_broker).uniq - hash[:included][:service_brokers] = service_brokers.sort_by(&:created_at).map do |broker| + hash[:included][:service_brokers] = service_brokers.sort_by { |sb| [sb.created_at, sb.guid] }.map do |broker| broker_view = {} broker_view[:name] = broker.name if @fields.include?('name') broker_view[:guid] = broker.guid if @fields.include?('guid') diff --git a/app/decorators/include_binding_app_decorator.rb b/app/decorators/include_binding_app_decorator.rb index ccdc3378068..ff9390a0d55 100644 --- a/app/decorators/include_binding_app_decorator.rb +++ b/app/decorators/include_binding_app_decorator.rb @@ -19,7 +19,7 @@ def apps(bindings) app_guids = bindings.pluck(:app_guid).compact.uniq return if app_guids.empty? - AppModel.where(guid: app_guids).order(:created_at). + AppModel.where(guid: app_guids).order(:created_at, :guid). eager(Presenters::V3::AppPresenter.associated_resources).all end end diff --git a/app/decorators/include_binding_route_decorator.rb b/app/decorators/include_binding_route_decorator.rb index 8bd53eef8d7..5eb5448a454 100644 --- a/app/decorators/include_binding_route_decorator.rb +++ b/app/decorators/include_binding_route_decorator.rb @@ -20,7 +20,7 @@ def match?(include_params) def routes(route_bindings) route_ids = route_bindings.map(&:route_id) - routes = Route.where(id: route_ids).order_by(:created_at). + routes = Route.where(id: route_ids).order_by(:created_at, :guid). eager(Presenters::V3::RoutePresenter.associated_resources).all routes.map { |route| Presenters::V3::RoutePresenter.new(route).to_hash } end diff --git a/app/decorators/include_binding_service_instance_decorator.rb b/app/decorators/include_binding_service_instance_decorator.rb index c695e7b5658..9860a3e2365 100644 --- a/app/decorators/include_binding_service_instance_decorator.rb +++ b/app/decorators/include_binding_service_instance_decorator.rb @@ -18,7 +18,7 @@ def decorate(hash, bindings) private def service_instances(bindings) - ServiceInstance.where(guid: bindings.map(&:service_instance_guid).uniq).order(:created_at). + ServiceInstance.where(guid: bindings.map(&:service_instance_guid).uniq).order(:created_at, :guid). eager(Presenters::V3::ServiceInstancePresenter.associated_resources).all end end diff --git a/app/decorators/include_organization_decorator.rb b/app/decorators/include_organization_decorator.rb index 0940db20c89..49ff0685d0f 100644 --- a/app/decorators/include_organization_decorator.rb +++ b/app/decorators/include_organization_decorator.rb @@ -8,7 +8,7 @@ def match?(include) def decorate(hash, resources) hash[:included] ||= {} organization_ids = resources.map { |r| r.space.organization_id }.uniq - organizations = Organization.where(id: organization_ids).order(:created_at). + organizations = Organization.where(id: organization_ids).order(:created_at, :guid). eager(Presenters::V3::OrganizationPresenter.associated_resources).all hash[:included][:organizations] = organizations.map { |organization| Presenters::V3::OrganizationPresenter.new(organization).to_hash } diff --git a/app/decorators/include_role_organization_decorator.rb b/app/decorators/include_role_organization_decorator.rb index 6299499acfc..817d6c2ecc9 100644 --- a/app/decorators/include_role_organization_decorator.rb +++ b/app/decorators/include_role_organization_decorator.rb @@ -11,7 +11,7 @@ def decorate(hash, roles) hash[:included] ||= {} organization_ids = roles.reject(&:for_space?).map(&:organization_id).uniq unless organization_ids.empty? - organizations = Organization.where(id: organization_ids).order(:created_at). + organizations = Organization.where(id: organization_ids).order(:created_at, :guid). eager(Presenters::V3::OrganizationPresenter.associated_resources).all end diff --git a/app/decorators/include_role_space_decorator.rb b/app/decorators/include_role_space_decorator.rb index b638b0c0a81..589f3244dc1 100644 --- a/app/decorators/include_role_space_decorator.rb +++ b/app/decorators/include_role_space_decorator.rb @@ -9,7 +9,7 @@ def decorate(hash, roles) hash[:included] ||= {} space_ids = roles.select(&:for_space?).map(&:space_id).uniq unless space_ids.empty? - spaces = Space.where(id: space_ids).order(:created_at). + spaces = Space.where(id: space_ids).order(:created_at, :guid). eager(Presenters::V3::SpacePresenter.associated_resources).all end diff --git a/app/decorators/include_role_user_decorator.rb b/app/decorators/include_role_user_decorator.rb index 44ea56c9987..a1fcd3d16be 100644 --- a/app/decorators/include_role_user_decorator.rb +++ b/app/decorators/include_role_user_decorator.rb @@ -8,7 +8,7 @@ def match?(include_params) def decorate(hash, roles) hash[:included] ||= {} user_guids = roles.map(&:user_guid).uniq - users = User.where(guid: user_guids).order(:created_at). + users = User.where(guid: user_guids).order(:created_at, :guid). eager(Presenters::V3::UserPresenter.associated_resources).all uaa_users = User.uaa_users_info(user_guids) diff --git a/app/decorators/include_service_plan_service_offering_decorator.rb b/app/decorators/include_service_plan_service_offering_decorator.rb index 26e25bf4266..dc13efcc8d5 100644 --- a/app/decorators/include_service_plan_service_offering_decorator.rb +++ b/app/decorators/include_service_plan_service_offering_decorator.rb @@ -7,7 +7,7 @@ def match?(include) def decorate(hash, service_plans) hash[:included] ||= {} - service_offerings = Service.where(id: service_plans.map(&:service_id).uniq).order(:created_at). + service_offerings = Service.where(id: service_plans.map(&:service_id).uniq).order(:created_at, :guid). eager(Presenters::V3::ServiceOfferingPresenter.associated_resources).all hash[:included][:service_offerings] = service_offerings.map do |service_offering| diff --git a/app/decorators/include_service_plan_space_organization_decorator.rb b/app/decorators/include_service_plan_space_organization_decorator.rb index 673c8ef36f7..aeb0b1abccd 100644 --- a/app/decorators/include_service_plan_space_organization_decorator.rb +++ b/app/decorators/include_service_plan_space_organization_decorator.rb @@ -9,9 +9,9 @@ def decorate(hash, service_plans) hash[:included] ||= {} space_ids = service_plans.map { |p| p.service.service_broker.space_id }.compact.uniq unless space_ids.empty? - spaces = Space.where(id: space_ids).order(:created_at). + spaces = Space.where(id: space_ids).order(:created_at, :guid). eager(Presenters::V3::SpacePresenter.associated_resources).all - orgs = Organization.where(id: spaces.map(&:organization_id).uniq).order(:created_at). + orgs = Organization.where(id: spaces.map(&:organization_id).uniq).order(:created_at, :guid). eager(Presenters::V3::OrganizationPresenter.associated_resources).all end diff --git a/app/decorators/include_space_decorator.rb b/app/decorators/include_space_decorator.rb index 19959a6eb5a..180c4c49cdc 100644 --- a/app/decorators/include_space_decorator.rb +++ b/app/decorators/include_space_decorator.rb @@ -8,7 +8,7 @@ def match?(include) def decorate(hash, resources) hash[:included] ||= {} space_guids = resources.map(&:space_guid).uniq - spaces_query = Space.where(guid: space_guids).order(:created_at). + spaces_query = Space.where(guid: space_guids).order(:created_at, :guid). eager(Presenters::V3::SpacePresenter.associated_resources) spaces_query = with_readable_space_guids(spaces_query) diff --git a/app/decorators/include_space_organization_decorator.rb b/app/decorators/include_space_organization_decorator.rb index 04f57a7043c..a8299e3ac92 100644 --- a/app/decorators/include_space_organization_decorator.rb +++ b/app/decorators/include_space_organization_decorator.rb @@ -8,7 +8,7 @@ def match?(include) def decorate(hash, spaces) hash[:included] ||= {} organization_ids = spaces.map(&:organization_id).uniq - organizations = Organization.where(id: organization_ids).order(:created_at). + organizations = Organization.where(id: organization_ids).order(:created_at, :guid). eager(Presenters::V3::OrganizationPresenter.associated_resources).all hash[:included][:organizations] = organizations.map { |organization| Presenters::V3::OrganizationPresenter.new(organization).to_hash } diff --git a/app/jobs/runtime/prune_completed_builds.rb b/app/jobs/runtime/prune_completed_builds.rb index ab9565bdde6..62e95c8129f 100644 --- a/app/jobs/runtime/prune_completed_builds.rb +++ b/app/jobs/runtime/prune_completed_builds.rb @@ -20,7 +20,7 @@ def perform builds_dataset = BuildModel.where(app_guid:) builds_to_keep = builds_dataset. - order(Sequel.desc(:created_at)). + order(Sequel.desc(:created_at), Sequel.desc(:id)). limit(max_retained_builds_per_app). select(:id) diff --git a/app/jobs/runtime/prune_completed_deployments.rb b/app/jobs/runtime/prune_completed_deployments.rb index cec4cc21252..3af419d096b 100644 --- a/app/jobs/runtime/prune_completed_deployments.rb +++ b/app/jobs/runtime/prune_completed_deployments.rb @@ -20,7 +20,7 @@ def perform deployments_dataset = DeploymentModel.where(app_guid:) deployments_to_keep = deployments_dataset. - order(Sequel.desc(:created_at)). + order(Sequel.desc(:created_at), Sequel.desc(:id)). limit(max_retained_deployments_per_app). select(:id) diff --git a/app/jobs/runtime/prune_excess_app_revisions.rb b/app/jobs/runtime/prune_excess_app_revisions.rb index 794322178a2..34acf4169c8 100644 --- a/app/jobs/runtime/prune_excess_app_revisions.rb +++ b/app/jobs/runtime/prune_excess_app_revisions.rb @@ -16,7 +16,7 @@ def perform revision_dataset = RevisionModel.where(app_guid:) next if revision_dataset.count <= max_retained_revisions_per_app - revisions_to_keep = revision_dataset.order(Sequel.desc(:created_at)). + revisions_to_keep = revision_dataset.order(Sequel.desc(:created_at), Sequel.desc(:id)). limit(max_retained_revisions_per_app). select(:id) diff --git a/app/presenters/v3/route_presenter.rb b/app/presenters/v3/route_presenter.rb index 9ebf2872137..a7ef4ec1161 100644 --- a/app/presenters/v3/route_presenter.rb +++ b/app/presenters/v3/route_presenter.rb @@ -1,5 +1,5 @@ require 'presenters/v3/base_presenter' -require 'presenters/v3/route_destination_presenter' +require 'presenters/v3/route_destinations_presenter' require 'presenters/mixins/metadata_presentation_helpers' require 'presenters/helpers/censorship' diff --git a/lib/cloud_controller/bits_expiration.rb b/lib/cloud_controller/bits_expiration.rb index 9c6485554f4..f6ce4a3b939 100644 --- a/lib/cloud_controller/bits_expiration.rb +++ b/lib/cloud_controller/bits_expiration.rb @@ -58,7 +58,7 @@ def enqueue_package_delete_job(package_guid) end def filter_non_expirable(dataset, storage_count) - data_to_keep = dataset.order_by(Sequel.desc(:created_at)).limit(storage_count).select(:id) + data_to_keep = dataset.order_by(Sequel.desc(:created_at), Sequel.desc(:id)).limit(storage_count).select(:id) dataset.exclude(id: data_to_keep) end end diff --git a/lib/cloud_controller/deployment_updater/updater.rb b/lib/cloud_controller/deployment_updater/updater.rb index 8fff5a05e42..20e1f1f7b2f 100644 --- a/lib/cloud_controller/deployment_updater/updater.rb +++ b/lib/cloud_controller/deployment_updater/updater.rb @@ -97,7 +97,7 @@ def deploying_web_process end def oldest_web_process_with_instances - @oldest_web_process_with_instances ||= app.web_processes.select { |process| process.instances > 0 }.min_by(&:created_at) + @oldest_web_process_with_instances ||= app.web_processes.select { |process| process.instances > 0 }.min_by { |p| [p.created_at, p.id] } end def interim_web_process diff --git a/spec/request/roles_spec.rb b/spec/request/roles_spec.rb index 51cbb80c209..d741f507c73 100644 --- a/spec/request/roles_spec.rb +++ b/spec/request/roles_spec.rb @@ -4,8 +4,8 @@ RSpec.describe 'Roles Request' do let(:user) { VCAP::CloudController::User.make(guid: 'user_guid') } let(:admin_header) { admin_headers_for(user) } - let(:org) { VCAP::CloudController::Organization.make(guid: 'big-org') } - let(:space) { VCAP::CloudController::Space.make(guid: 'big-space', organization: org) } + let(:org) { VCAP::CloudController::Organization.make(guid: 'big-org', created_at: Time.now.utc - 1.second) } + let(:space) { VCAP::CloudController::Space.make(guid: 'big-space', organization: org, created_at: Time.now.utc - 1.second) } let(:user_with_role) { VCAP::CloudController::User.make(guid: 'user_with_role') } let(:user_guid) { user.guid } let(:space_guid) { space.guid } @@ -822,7 +822,7 @@ describe 'GET /v3/roles' do let(:api_call) { ->(user_headers) { get '/v3/roles', nil, user_headers } } - let(:other_user) { VCAP::CloudController::User.make(guid: 'other-user-guid') } + let(:other_user) { VCAP::CloudController::User.make(guid: 'other-user-guid', created_at: Time.now.utc - 1.second) } let!(:space_auditor) do VCAP::CloudController::SpaceAuditor.make( diff --git a/spec/request/service_credential_bindings_spec.rb b/spec/request/service_credential_bindings_spec.rb index d3acdd6e947..c3a9a37197f 100644 --- a/spec/request/service_credential_bindings_spec.rb +++ b/spec/request/service_credential_bindings_spec.rb @@ -55,13 +55,17 @@ end context 'given a mixture of bindings' do - let(:now) { Time.now } - let(:instance) { VCAP::CloudController::ManagedServiceInstance.make(space:) } + let(:now) { Time.now.utc } + let(:instance) { VCAP::CloudController::ManagedServiceInstance.make(space: space, created_at: now - 1.second) } let(:other_instance) { VCAP::CloudController::ManagedServiceInstance.make(space: other_space) } let!(:key_binding) { VCAP::CloudController::ServiceKey.make(service_instance: instance, created_at: now - 4.seconds) } let!(:other_key_binding) { VCAP::CloudController::ServiceKey.make(service_instance: other_instance, created_at: now - 3.seconds) } let!(:app_binding) do - VCAP::CloudController::ServiceBinding.make(service_instance: instance, created_at: now - 2.seconds).tap do |binding| + VCAP::CloudController::ServiceBinding.make( + app: VCAP::CloudController::AppModel.make(space: space, created_at: now - 1.second), + service_instance: instance, + created_at: now - 2.seconds + ).tap do |binding| operate_on(binding) end end diff --git a/spec/request/service_instances_spec.rb b/spec/request/service_instances_spec.rb index 709cb02e9b8..bd427456c3b 100644 --- a/spec/request/service_instances_spec.rb +++ b/spec/request/service_instances_spec.rb @@ -3,9 +3,9 @@ RSpec.describe 'V3 service instances' do let(:user) { VCAP::CloudController::User.make } - let(:org) { VCAP::CloudController::Organization.make } + let(:org) { VCAP::CloudController::Organization.make(created_at: Time.now.utc - 1.second) } let!(:org_annotation) { VCAP::CloudController::OrganizationAnnotationModel.make(key_prefix: 'pre.fix', key_name: 'foo', value: 'bar', resource_guid: org.guid) } - let(:space) { VCAP::CloudController::Space.make(organization: org) } + let(:space) { VCAP::CloudController::Space.make(organization: org, created_at: Time.now.utc - 1.second) } let!(:space_annotation) { VCAP::CloudController::SpaceAnnotationModel.make(key_prefix: 'pre.fix', key_name: 'baz', value: 'wow', space: space) } let(:another_space) { VCAP::CloudController::Space.make } @@ -189,8 +189,30 @@ end context 'given a mixture of managed, user-provided and shared service instances' do - let!(:msi_1) { VCAP::CloudController::ManagedServiceInstance.make(space:) } - let!(:msi_2) { VCAP::CloudController::ManagedServiceInstance.make(space: another_space) } + let!(:msi_1) do + VCAP::CloudController::ManagedServiceInstance.make( + service_plan: VCAP::CloudController::ServicePlan.make( + service: VCAP::CloudController::Service.make( + service_broker: VCAP::CloudController::ServiceBroker.make(created_at: Time.now.utc - 2.seconds), + created_at: Time.now.utc - 2.seconds + ), + created_at: Time.now.utc - 2.seconds + ), + space: space + ) + end + let!(:msi_2) do + VCAP::CloudController::ManagedServiceInstance.make( + service_plan: VCAP::CloudController::ServicePlan.make( + service: VCAP::CloudController::Service.make( + service_broker: VCAP::CloudController::ServiceBroker.make(created_at: Time.now.utc - 1.second), + created_at: Time.now.utc - 1.second + ), + created_at: Time.now.utc - 1.second + ), + space: another_space + ) + end let!(:upsi_1) { VCAP::CloudController::UserProvidedServiceInstance.make(space:) } let!(:upsi_2) { VCAP::CloudController::UserProvidedServiceInstance.make(space: another_space) } let!(:ssi) { VCAP::CloudController::ManagedServiceInstance.make(space: another_space) } diff --git a/spec/request/service_offerings_spec.rb b/spec/request/service_offerings_spec.rb index 3f387535fc0..2e9a3b34907 100644 --- a/spec/request/service_offerings_spec.rb +++ b/spec/request/service_offerings_spec.rb @@ -601,7 +601,11 @@ end describe 'fields' do - let!(:service_1) { VCAP::CloudController::Service.make } + let!(:service_1) do + VCAP::CloudController::Service.make( + service_broker: VCAP::CloudController::ServiceBroker.make(created_at: Time.now.utc - 1.second) + ) + end let!(:service_2) { VCAP::CloudController::Service.make } it 'can include service broker name and guid' do diff --git a/spec/request/service_plans_spec.rb b/spec/request/service_plans_spec.rb index 4e76751572b..644b66b9e39 100644 --- a/spec/request/service_plans_spec.rb +++ b/spec/request/service_plans_spec.rb @@ -558,7 +558,12 @@ end describe 'includes' do - let(:space_1) { VCAP::CloudController::Space.make } + let(:space_1) do + VCAP::CloudController::Space.make( + organization: VCAP::CloudController::Organization.make(created_at: Time.now.utc - 1.second), + created_at: Time.now.utc - 1.second + ) + end let(:space_2) { VCAP::CloudController::Space.make } context 'when including `space.organization`' do @@ -608,7 +613,13 @@ end describe 'fields' do - let!(:plan_1) { VCAP::CloudController::ServicePlan.make } + let!(:plan_1) do + VCAP::CloudController::ServicePlan.make( + service: VCAP::CloudController::Service.make( + service_broker: VCAP::CloudController::ServiceBroker.make(created_at: Time.now.utc - 1.second) + ) + ) + end let!(:plan_2) { VCAP::CloudController::ServicePlan.make } it 'can include service broker name and guid' do diff --git a/spec/request/service_route_bindings_spec.rb b/spec/request/service_route_bindings_spec.rb index 79401181cde..94973166d4e 100644 --- a/spec/request/service_route_bindings_spec.rb +++ b/spec/request/service_route_bindings_spec.rb @@ -215,7 +215,7 @@ describe 'include' do context 'when including `service_instance`' do - let(:instance) { VCAP::CloudController::UserProvidedServiceInstance.make(:routing) } + let(:instance) { VCAP::CloudController::UserProvidedServiceInstance.make(:routing, created_at: Time.now.utc - 1.second) } let(:other_instance) { VCAP::CloudController::UserProvidedServiceInstance.make(:routing) } before do @@ -244,7 +244,7 @@ end it 'can include `route`' do - route = VCAP::CloudController::Route.make + route = VCAP::CloudController::Route.make(created_at: Time.now.utc - 1.second) other_route = VCAP::CloudController::Route.make si = VCAP::CloudController::ManagedServiceInstance.make(:routing, space: route.space) diff --git a/spec/unit/actions/revision_create_spec.rb b/spec/unit/actions/revision_create_spec.rb index f53b55a0ea4..637e4e12d8f 100644 --- a/spec/unit/actions/revision_create_spec.rb +++ b/spec/unit/actions/revision_create_spec.rb @@ -112,7 +112,7 @@ module VCAP::CloudController ) end.to change { RevisionModel.where(app:).count }.by(1) - expect(RevisionModel.order_by(:created_at).map(&:version)).to eq([1, 2]) + expect(RevisionModel.order_by(:created_at, :id).map(&:version)).to eq([1, 2]) end it 'rolls over to version 1 when we pass version 9999' do @@ -130,7 +130,7 @@ module VCAP::CloudController commands_by_process_type: { 'web' => 'run my app' }, user_audit_info: user_audit_info ) - expect(RevisionModel.order_by(:created_at).map(&:version)).to eq([2, 9998, 9999, 1]) + expect(RevisionModel.order_by(:created_at, :id).map(&:version)).to eq([2, 9998, 9999, 1]) end it 'replaces any existing revisions after rolling over' do @@ -148,7 +148,7 @@ module VCAP::CloudController commands_by_process_type: { 'web' => 'run my app' }, user_audit_info: user_audit_info ) - expect(RevisionModel.order_by(:created_at).map(&:version)).to eq([9998, 9999, 1, 2]) + expect(RevisionModel.order_by(:created_at, :id).map(&:version)).to eq([9998, 9999, 1, 2]) end end end diff --git a/spec/unit/decorators/field_service_instance_broker_decorator_spec.rb b/spec/unit/decorators/field_service_instance_broker_decorator_spec.rb index e22a905950c..ce5d897b9af 100644 --- a/spec/unit/decorators/field_service_instance_broker_decorator_spec.rb +++ b/spec/unit/decorators/field_service_instance_broker_decorator_spec.rb @@ -5,15 +5,16 @@ module VCAP::CloudController RSpec.describe FieldServiceInstanceBrokerDecorator do describe '.decorate' do - let(:broker) { ServiceBroker.make } - let(:offering1) { Service.make(service_broker: broker) } + let(:broker1) { ServiceBroker.make(created_at: Time.now.utc - 1.second) } + + let(:offering1) { Service.make(service_broker: broker1) } let(:offering2) { Service.make } let(:plan1) { ServicePlan.make(service: offering1) } let(:plan2) { ServicePlan.make(service: offering2) } - let!(:service_instance_1) { ManagedServiceInstance.make(service_plan: plan1) } - let!(:service_instance_2) { ManagedServiceInstance.make(service_plan: plan2) } + let(:service_instance_1) { ManagedServiceInstance.make(service_plan: plan1) } + let(:service_instance_2) { ManagedServiceInstance.make(service_plan: plan2) } it 'decorated the given hash with broker name from service instances' do undecorated_hash = { foo: 'bar', included: { monkeys: %w[zach greg] } } @@ -60,9 +61,9 @@ module VCAP::CloudController end context 'when instances are from the same broker' do - let(:offering3) { Service.make(service_broker: broker) } + let(:offering3) { Service.make(service_broker: broker1) } let(:plan3) { ServicePlan.make(service: offering3) } - let!(:service_instance_3) { ManagedServiceInstance.make(service_plan: plan3) } + let(:service_instance_3) { ManagedServiceInstance.make(service_plan: plan3) } it 'does not duplicate the broker' do decorator = described_class.new({ 'service_plan.service_offering.service_broker': ['name'] }) @@ -72,7 +73,7 @@ module VCAP::CloudController end context 'for user provided service instances' do - let!(:service_instance_3) { UserProvidedServiceInstance.make } + let(:service_instance_3) { UserProvidedServiceInstance.make } it 'returns the unchanged hash' do undecorated_hash = { foo: 'bar' } diff --git a/spec/unit/decorators/field_service_instance_offering_decorator_spec.rb b/spec/unit/decorators/field_service_instance_offering_decorator_spec.rb index d9e590ad54a..bd1b6069d52 100644 --- a/spec/unit/decorators/field_service_instance_offering_decorator_spec.rb +++ b/spec/unit/decorators/field_service_instance_offering_decorator_spec.rb @@ -5,13 +5,13 @@ module VCAP::CloudController RSpec.describe FieldServiceInstanceOfferingDecorator do describe '.decorate' do let(:offering1) { Service.make(extra: '{"documentationUrl": "https://offering1.com"}', tags: %w[foo bar], created_at: Time.now.utc - 1.second) } - let(:offering2) { Service.make(extra: '{"documentationUrl": "https://offering2.com"}', tags: %w[baz], created_at: Time.now.utc) } + let(:offering2) { Service.make(extra: '{"documentationUrl": "https://offering2.com"}', tags: %w[baz]) } let(:plan1) { ServicePlan.make(service: offering1) } let(:plan2) { ServicePlan.make(service: offering2) } - let!(:service_instance_1) { ManagedServiceInstance.make(service_plan: plan1) } - let!(:service_instance_2) { ManagedServiceInstance.make(service_plan: plan2) } + let(:service_instance_1) { ManagedServiceInstance.make(service_plan: plan1) } + let(:service_instance_2) { ManagedServiceInstance.make(service_plan: plan2) } it 'can decorate with the service offering name' do undecorated_hash = { foo: 'bar', included: { monkeys: %w[zach greg] } } @@ -159,7 +159,7 @@ module VCAP::CloudController context 'when instances are from the same offering' do let(:plan3) { ServicePlan.make(service: offering1) } - let!(:service_instance_3) { ManagedServiceInstance.make(service_plan: plan3) } + let(:service_instance_3) { ManagedServiceInstance.make(service_plan: plan3) } it 'does not duplicate the offering' do decorator = described_class.new({ 'service_plan.service_offering': ['name'] }) @@ -169,7 +169,7 @@ module VCAP::CloudController end context 'for user provided service instances' do - let!(:service_instance_3) { UserProvidedServiceInstance.make } + let(:service_instance_3) { UserProvidedServiceInstance.make } it 'returns the unchanged hash' do undecorated_hash = { foo: 'bar' } diff --git a/spec/unit/decorators/field_service_instance_organization_decorator_spec.rb b/spec/unit/decorators/field_service_instance_organization_decorator_spec.rb index a8178b2364c..1acb5659c05 100644 --- a/spec/unit/decorators/field_service_instance_organization_decorator_spec.rb +++ b/spec/unit/decorators/field_service_instance_organization_decorator_spec.rb @@ -5,14 +5,14 @@ module VCAP::CloudController RSpec.describe FieldServiceInstanceOrganizationDecorator do describe '.decorate' do - let(:org1) { Organization.make } + let(:org1) { Organization.make(created_at: Time.now.utc - 1.second) } let(:org2) { Organization.make } let(:space1) { Space.make(organization: org1) } let(:space2) { Space.make(organization: org2) } - let!(:service_instance_1) { ManagedServiceInstance.make(space: space1) } - let!(:service_instance_2) { UserProvidedServiceInstance.make(space: space2) } + let(:service_instance_1) { ManagedServiceInstance.make(space: space1) } + let(:service_instance_2) { UserProvidedServiceInstance.make(space: space2) } it 'decorated the given hash with orgs names from service instances' do undecorated_hash = { foo: 'bar', included: { monkeys: %w[zach greg] } } @@ -60,7 +60,7 @@ module VCAP::CloudController context 'when instances share an org' do let(:space3) { Space.make(organization: org1) } - let!(:service_instance_3) { ManagedServiceInstance.make(space: space3) } + let(:service_instance_3) { ManagedServiceInstance.make(space: space3) } it 'does not duplicate the org' do decorator = described_class.new({ 'space.organization': ['name'] }) diff --git a/spec/unit/decorators/field_service_instance_plan_decorator_spec.rb b/spec/unit/decorators/field_service_instance_plan_decorator_spec.rb index 2648e731196..6289fadb7c4 100644 --- a/spec/unit/decorators/field_service_instance_plan_decorator_spec.rb +++ b/spec/unit/decorators/field_service_instance_plan_decorator_spec.rb @@ -5,11 +5,11 @@ module VCAP::CloudController RSpec.describe FieldServiceInstancePlanDecorator do describe '.decorate' do - let(:plan1) { ServicePlan.make } + let(:plan1) { ServicePlan.make(created_at: Time.now.utc - 1.second) } let(:plan2) { ServicePlan.make } - let!(:service_instance_1) { ManagedServiceInstance.make(service_plan: plan1) } - let!(:service_instance_2) { ManagedServiceInstance.make(service_plan: plan2) } + let(:service_instance_1) { ManagedServiceInstance.make(service_plan: plan1) } + let(:service_instance_2) { ManagedServiceInstance.make(service_plan: plan2) } it 'decorated the given hash with plan guid and name from service instances' do undecorated_hash = { foo: 'bar', included: { monkeys: %w[zach greg] } } @@ -70,7 +70,7 @@ module VCAP::CloudController end context 'when instances are from the same plan' do - let!(:service_instance_3) { ManagedServiceInstance.make(service_plan: plan1) } + let(:service_instance_3) { ManagedServiceInstance.make(service_plan: plan1) } it 'does not duplicate the plan' do decorator = described_class.new({ service_plan: ['guid'] }) @@ -80,7 +80,7 @@ module VCAP::CloudController end context 'for user provided service instances' do - let!(:service_instance_3) { UserProvidedServiceInstance.make } + let(:service_instance_3) { UserProvidedServiceInstance.make } it 'returns the unchanged hash' do undecorated_hash = { foo: 'bar' } diff --git a/spec/unit/decorators/field_service_instance_space_decorator_spec.rb b/spec/unit/decorators/field_service_instance_space_decorator_spec.rb index 7895d8bd286..5f4d25f84d4 100644 --- a/spec/unit/decorators/field_service_instance_space_decorator_spec.rb +++ b/spec/unit/decorators/field_service_instance_space_decorator_spec.rb @@ -8,11 +8,11 @@ module VCAP::CloudController let(:org1) { Organization.make } let(:org2) { Organization.make } - let(:space1) { Space.make(organization: org1) } + let(:space1) { Space.make(organization: org1, created_at: Time.now.utc - 1.second) } let(:space2) { Space.make(organization: org2) } - let!(:service_instance_1) { ManagedServiceInstance.make(space: space1) } - let!(:service_instance_2) { UserProvidedServiceInstance.make(space: space2) } + let(:service_instance_1) { ManagedServiceInstance.make(space: space1) } + let(:service_instance_2) { UserProvidedServiceInstance.make(space: space2) } context 'when space guid, name and relationship.organizations are requested' do let(:decorator) { described_class.new({ space: ['relationships.organization', 'guid', 'name'] }) } @@ -137,7 +137,7 @@ module VCAP::CloudController context 'when instances share a space' do let(:decorator) { described_class.new({ space: ['guid'] }) } - let!(:service_instance_3) { ManagedServiceInstance.make(space: space1) } + let(:service_instance_3) { ManagedServiceInstance.make(space: space1) } it 'does not duplicate the space' do hash = decorator.decorate({}, [service_instance_1, service_instance_3]) diff --git a/spec/unit/decorators/field_service_offering_service_broker_decorator_spec.rb b/spec/unit/decorators/field_service_offering_service_broker_decorator_spec.rb index 33a0f455cdf..ce4097c64d7 100644 --- a/spec/unit/decorators/field_service_offering_service_broker_decorator_spec.rb +++ b/spec/unit/decorators/field_service_offering_service_broker_decorator_spec.rb @@ -5,7 +5,9 @@ module VCAP::CloudController RSpec.describe FieldServiceOfferingServiceBrokerDecorator do describe '.decorate' do - let(:offering1) { Service.make } + let(:broker1) { ServiceBroker.make(created_at: Time.now.utc - 1.second) } + + let(:offering1) { Service.make(service_broker: broker1) } let(:offering2) { Service.make } it 'decorated the given hash with broker name and guid' do diff --git a/spec/unit/decorators/field_service_plan_service_broker_decorator_spec.rb b/spec/unit/decorators/field_service_plan_service_broker_decorator_spec.rb index f6401954f51..79e1ea060b8 100644 --- a/spec/unit/decorators/field_service_plan_service_broker_decorator_spec.rb +++ b/spec/unit/decorators/field_service_plan_service_broker_decorator_spec.rb @@ -5,7 +5,9 @@ module VCAP::CloudController RSpec.describe FieldServicePlanServiceBrokerDecorator do describe '.decorate' do - let(:offering1) { Service.make } + let(:broker1) { ServiceBroker.make(created_at: Time.now.utc - 1.second) } + + let(:offering1) { Service.make(service_broker: broker1) } let(:offering2) { Service.make } let(:plan1) { ServicePlan.make(service: offering1) } diff --git a/spec/unit/decorators/include_binding_app_decorator_spec.rb b/spec/unit/decorators/include_binding_app_decorator_spec.rb index c4c69299198..e8dac7f8e03 100644 --- a/spec/unit/decorators/include_binding_app_decorator_spec.rb +++ b/spec/unit/decorators/include_binding_app_decorator_spec.rb @@ -7,16 +7,25 @@ module VCAP::CloudController let(:service_credential_bindings) { ServiceCredentialBinding::View.dataset.all } context 'service bindings' do - let!(:bindings) { [ServiceBinding.make, ServiceBinding.make, ServiceBinding.make] } + let!(:bindings) do + service_instance = ManagedServiceInstance.make + app = AppModel.make(space: service_instance.space, created_at: Time.now.utc - 1.second) + + [ + ServiceBinding.make(service_instance:, app:), + ServiceBinding.make + ] + end + let(:apps) do bindings.map { |b| Presenters::V3::AppPresenter.new(b.app).to_hash } end - it 'decorates the given hash with apps from bindings' do + it 'decorates the given hash with apps from bindings in the correct order' do dict = { foo: 'bar' } hash = subject.decorate(dict, service_credential_bindings) expect(hash[:foo]).to eq('bar') - expect(hash[:included][:apps]).to match_array(apps) + expect(hash[:included][:apps]).to eq(apps) end it 'does not overwrite other included fields' do @@ -29,7 +38,7 @@ module VCAP::CloudController end context 'service keys' do - let!(:keys) { [ServiceKey.make] } + let(:keys) { [ServiceKey.make] } it 'does not query the database' do expect do diff --git a/spec/unit/decorators/include_binding_route_decorator_spec.rb b/spec/unit/decorators/include_binding_route_decorator_spec.rb index 6af0c670baf..df2dc52c20f 100644 --- a/spec/unit/decorators/include_binding_route_decorator_spec.rb +++ b/spec/unit/decorators/include_binding_route_decorator_spec.rb @@ -5,18 +5,26 @@ module VCAP module CloudController RSpec.describe IncludeBindingRouteDecorator do subject(:decorator) { described_class } - let(:bindings) { Array.new(3) { RouteBinding.make } } + + let(:bindings) do + service_instance = ManagedServiceInstance.make(:routing) + route = Route.make(space: service_instance.space, created_at: Time.now.utc - 1.second) + + [ + RouteBinding.make(service_instance:, route:), + RouteBinding.make + ] + end + let(:routes) do - bindings. - map(&:route). - map { |r| Presenters::V3::RoutePresenter.new(r).to_hash } + bindings.map { |r| Presenters::V3::RoutePresenter.new(r.route).to_hash } end - it 'decorates the given hash with service instances from bindings' do + it 'decorates the given hash with service instances from bindings in the correct order' do dict = { foo: 'bar' } hash = subject.decorate(dict, bindings) expect(hash[:foo]).to eq('bar') - expect(hash[:included][:routes]).to match_array(routes) + expect(hash[:included][:routes]).to eq(routes) end it 'does not overwrite other included fields' do @@ -36,7 +44,7 @@ module CloudController ) hash = subject.decorate({}, bindings) - expect(hash[:included][:routes]).to have(3).items + expect(hash[:included][:routes]).to have(2).items end describe '.match?' do diff --git a/spec/unit/decorators/include_binding_service_instance_decorator_spec.rb b/spec/unit/decorators/include_binding_service_instance_decorator_spec.rb index 33c2ee26a35..30c43de28ac 100644 --- a/spec/unit/decorators/include_binding_service_instance_decorator_spec.rb +++ b/spec/unit/decorators/include_binding_service_instance_decorator_spec.rb @@ -6,16 +6,23 @@ module CloudController def self.can_be_decorated_with_include_binding_service_instance_decorator(klazz) RSpec.describe IncludeBindingServiceInstanceDecorator do subject(:decorator) { described_class } - let(:bindings) { Array.new(3) { klazz.make } } + + let(:bindings) do + [ + klazz.make(service_instance: ManagedServiceInstance.make(:routing, created_at: Time.now.utc - 1.second)), + klazz.make + ] + end + let(:instances) do bindings.map { |b| Presenters::V3::ServiceInstancePresenter.new(b.service_instance).to_hash } end - it 'decorates the given hash with service instances from bindings' do + it 'decorates the given hash with service instances from bindings in the correct order' do dict = { foo: 'bar' } hash = subject.decorate(dict, bindings) expect(hash[:foo]).to eq('bar') - expect(hash[:included][:service_instances]).to match_array(instances) + expect(hash[:included][:service_instances]).to eq(instances) end it 'does not overwrite other included fields' do @@ -28,7 +35,7 @@ def self.can_be_decorated_with_include_binding_service_instance_decorator(klazz) it 'does not include duplicates' do hash = subject.decorate({}, bindings << klazz.make(service_instance: bindings[0].service_instance)) - expect(hash[:included][:service_instances]).to have(3).items + expect(hash[:included][:service_instances]).to have(2).items end describe '.match?' do diff --git a/spec/unit/decorators/include_organization_decorator_spec.rb b/spec/unit/decorators/include_organization_decorator_spec.rb index ce5ca91f6b7..4416b7e386e 100644 --- a/spec/unit/decorators/include_organization_decorator_spec.rb +++ b/spec/unit/decorators/include_organization_decorator_spec.rb @@ -3,18 +3,20 @@ module VCAP::CloudController RSpec.describe IncludeOrganizationDecorator do subject(:decorator) { IncludeOrganizationDecorator } - let(:organization1) { Organization.make(name: 'first-organization') } + let(:organization1) { Organization.make(name: 'first-organization', created_at: Time.now.utc - 1.second) } let(:organization2) { Organization.make(name: 'second-organization') } + let(:space1) { Space.make(name: 'first-space', organization: organization1) } let(:space2) { Space.make(name: 'second-space', organization: organization2) } + let(:apps) { [AppModel.make(space: space1), AppModel.make(space: space2), AppModel.make(space: space1)] } - it 'decorates the given hash with organizations from apps' do + it 'decorates the given hash with organizations from apps in the correct order' do wreathless_hash = { foo: 'bar' } hash = subject.decorate(wreathless_hash, apps) expect(hash[:foo]).to eq('bar') - expect(hash[:included][:organizations]).to contain_exactly(Presenters::V3::OrganizationPresenter.new(organization1).to_hash, - Presenters::V3::OrganizationPresenter.new(organization2).to_hash) + expect(hash[:included][:organizations]).to eq([Presenters::V3::OrganizationPresenter.new(organization1).to_hash, + Presenters::V3::OrganizationPresenter.new(organization2).to_hash]) end it 'does not overwrite other included fields' do diff --git a/spec/unit/decorators/include_role_organization_decorator_spec.rb b/spec/unit/decorators/include_role_organization_decorator_spec.rb index 776f171be7d..81fe567cf07 100644 --- a/spec/unit/decorators/include_role_organization_decorator_spec.rb +++ b/spec/unit/decorators/include_role_organization_decorator_spec.rb @@ -5,20 +5,22 @@ module VCAP::CloudController RSpec.describe IncludeRoleOrganizationDecorator do subject(:decorator) { IncludeRoleOrganizationDecorator } - let(:organization1) { Organization.make(name: 'first-organization') } + let(:organization1) { Organization.make(name: 'first-organization', created_at: Time.now.utc - 1.second) } let(:organization2) { Organization.make(name: 'second-organization') } + let(:org_user) { OrganizationUser.make(organization: organization1) } let(:org_auditor) { OrganizationAuditor.make(organization: organization2) } let(:space_manager) { SpaceManager.make } + # roles is an array of VCAP::CloudController::Role objects let(:roles) { Role.where(guid: [org_user, org_auditor, space_manager].map(&:guid)).all } - it 'decorates the given hash with organizations from roles' do + it 'decorates the given hash with organizations from roles in the correct order' do wreathless_hash = { foo: 'bar' } hash = subject.decorate(wreathless_hash, roles) expect(hash[:foo]).to eq('bar') - expect(hash[:included][:organizations]).to contain_exactly(Presenters::V3::OrganizationPresenter.new(organization1).to_hash, - Presenters::V3::OrganizationPresenter.new(organization2).to_hash) + expect(hash[:included][:organizations]).to eq([Presenters::V3::OrganizationPresenter.new(organization1).to_hash, + Presenters::V3::OrganizationPresenter.new(organization2).to_hash]) end it 'does not overwrite other included fields' do diff --git a/spec/unit/decorators/include_role_space_decorator_spec.rb b/spec/unit/decorators/include_role_space_decorator_spec.rb index adabcb954f9..8712a2548f3 100644 --- a/spec/unit/decorators/include_role_space_decorator_spec.rb +++ b/spec/unit/decorators/include_role_space_decorator_spec.rb @@ -5,19 +5,21 @@ module VCAP::CloudController RSpec.describe IncludeRoleSpaceDecorator do subject(:decorator) { IncludeRoleSpaceDecorator } - let(:space1) { Space.make(name: 'first-space') } + let(:space1) { Space.make(name: 'first-space', created_at: Time.now.utc - 1.second) } let(:space2) { Space.make(name: 'second-space') } + let(:space_manager) { SpaceManager.make(space: space1) } let(:space_auditor) { SpaceAuditor.make(space: space2) } let(:org_manager) { OrganizationManager.make } + # roles is an array of VCAP::CloudController::Role objects let(:roles) { Role.where(guid: [space_manager, space_auditor, org_manager].map(&:guid)).all } - it 'decorates the given hash with spaces from roles' do + it 'decorates the given hash with spaces from roles in the correct order' do wreathless_hash = { foo: 'bar' } hash = subject.decorate(wreathless_hash, roles) expect(hash[:foo]).to eq('bar') - expect(hash[:included][:spaces]).to contain_exactly(Presenters::V3::SpacePresenter.new(space1).to_hash, Presenters::V3::SpacePresenter.new(space2).to_hash) + expect(hash[:included][:spaces]).to eq([Presenters::V3::SpacePresenter.new(space1).to_hash, Presenters::V3::SpacePresenter.new(space2).to_hash]) end it 'does not overwrite other included fields' do @@ -29,7 +31,7 @@ module VCAP::CloudController end context 'only org roles' do - let!(:roles) { Role.where(guid: org_manager.guid).all } + let(:roles) { Role.where(guid: org_manager.guid).all } it 'does not query the database' do expect do diff --git a/spec/unit/decorators/include_role_user_decorator_spec.rb b/spec/unit/decorators/include_role_user_decorator_spec.rb index 0e2b368e2f9..0790ec9aa71 100644 --- a/spec/unit/decorators/include_role_user_decorator_spec.rb +++ b/spec/unit/decorators/include_role_user_decorator_spec.rb @@ -4,8 +4,10 @@ module VCAP::CloudController RSpec.describe IncludeRoleUserDecorator do subject(:decorator) { IncludeRoleUserDecorator } - let(:user1) { User.make(guid: 'user-1-guid') } + + let(:user1) { User.make(guid: 'user-1-guid', created_at: Time.now.utc - 1.second) } let(:user2) { User.make(guid: 'user-2-guid') } + let(:roles) do [ SpaceDeveloper.make(user: user1), @@ -27,12 +29,12 @@ module VCAP::CloudController allow(uaa_client).to receive(:users_for_ids).with([user1.guid, user2.guid]).and_return(user_uaa_info) end - it 'decorates the given hash with associated users' do + it 'decorates the given hash with associated users in the correct order' do undecorated_hash = { foo: 'bar' } hash = subject.decorate(undecorated_hash, roles) expect(hash[:foo]).to eq('bar') - expect(hash[:included][:users]).to contain_exactly(Presenters::V3::UserPresenter.new(user1, uaa_users: user_uaa_info).to_hash, - Presenters::V3::UserPresenter.new(user2, uaa_users: user_uaa_info).to_hash) + expect(hash[:included][:users]).to eq([Presenters::V3::UserPresenter.new(user1, uaa_users: user_uaa_info).to_hash, + Presenters::V3::UserPresenter.new(user2, uaa_users: user_uaa_info).to_hash]) end it 'does not overwrite other included fields' do diff --git a/spec/unit/decorators/include_service_plan_service_offering_decorator_spec.rb b/spec/unit/decorators/include_service_plan_service_offering_decorator_spec.rb index e883e496508..00a190acd45 100644 --- a/spec/unit/decorators/include_service_plan_service_offering_decorator_spec.rb +++ b/spec/unit/decorators/include_service_plan_service_offering_decorator_spec.rb @@ -4,13 +4,14 @@ module VCAP::CloudController RSpec.describe IncludeServicePlanServiceOfferingDecorator do describe '.decorate' do - let(:offering_1) { Service.make } + let(:offering_1) { Service.make(created_at: Time.now.utc - 1.second) } let(:offering_2) { Service.make } + let(:plan_1) { ServicePlan.make(service: offering_1) } let(:plan_2) { ServicePlan.make(service: offering_2) } let(:plan_3) { ServicePlan.make(service: offering_2) } - it 'decorates the given hash with service offerings from service plans' do + it 'decorates the given hash with service offerings from service plans in the correct order' do undecorated_hash = { foo: 'bar', included: { monkeys: %w[zach greg] } } hash = described_class.decorate(undecorated_hash, [plan_1, plan_2, plan_3]) @@ -18,8 +19,8 @@ module VCAP::CloudController expect(hash[:included][:monkeys]).to contain_exactly('zach', 'greg') expect(hash[:included].keys).to have(2).keys - expect(hash[:included][:service_offerings]).to contain_exactly(Presenters::V3::ServiceOfferingPresenter.new(offering_1).to_hash, - Presenters::V3::ServiceOfferingPresenter.new(offering_2).to_hash) + expect(hash[:included][:service_offerings]).to eq([Presenters::V3::ServiceOfferingPresenter.new(offering_1).to_hash, + Presenters::V3::ServiceOfferingPresenter.new(offering_2).to_hash]) end it 'only includes the service offerings from the specified service plans' do diff --git a/spec/unit/decorators/include_service_plan_space_organization_decorator_spec.rb b/spec/unit/decorators/include_service_plan_space_organization_decorator_spec.rb index af1b1ef97fa..253c7cfcc1a 100644 --- a/spec/unit/decorators/include_service_plan_space_organization_decorator_spec.rb +++ b/spec/unit/decorators/include_service_plan_space_organization_decorator_spec.rb @@ -4,17 +4,17 @@ module VCAP::CloudController RSpec.describe IncludeServicePlanSpaceOrganizationDecorator do describe '.decorate' do - let(:org1) { Organization.make } + let(:org1) { Organization.make(created_at: Time.now.utc - 1.second) } let(:org2) { Organization.make } - let(:space1) { Space.make(organization: org1) } + let(:space1) { Space.make(organization: org1, created_at: Time.now.utc - 1.second) } let(:space2) { Space.make(organization: org2) } - let!(:space_scoped_plan_1) { generate_space_scoped_plan(space1) } - let!(:space_scoped_plan_2) { generate_space_scoped_plan(space2) } + let(:space_scoped_plan_1) { generate_space_scoped_plan(space1) } + let(:space_scoped_plan_2) { generate_space_scoped_plan(space2) } context 'global plan' do - let!(:plans) { [ServicePlan.make(public: true)] } + let(:plans) { [ServicePlan.make(public: true)] } it 'does not add space or orgs' do hash = described_class.decorate({}, plans) @@ -29,7 +29,7 @@ module VCAP::CloudController end end - it 'decorates the given hash with spaces and orgs from service plans' do + it 'decorates the given hash with spaces and orgs from service plans in the correct order' do undecorated_hash = { foo: 'bar', included: { monkeys: %w[zach greg] } } hash = described_class.decorate(undecorated_hash, [space_scoped_plan_1, space_scoped_plan_2]) @@ -37,9 +37,9 @@ module VCAP::CloudController expect(hash[:included][:monkeys]).to contain_exactly('zach', 'greg') expect(hash[:included].keys).to have(3).keys - expect(hash[:included][:spaces]).to contain_exactly(Presenters::V3::SpacePresenter.new(space1).to_hash, Presenters::V3::SpacePresenter.new(space2).to_hash) + expect(hash[:included][:spaces]).to eq([Presenters::V3::SpacePresenter.new(space1).to_hash, Presenters::V3::SpacePresenter.new(space2).to_hash]) - expect(hash[:included][:organizations]).to contain_exactly(Presenters::V3::OrganizationPresenter.new(org1).to_hash, Presenters::V3::OrganizationPresenter.new(org2).to_hash) + expect(hash[:included][:organizations]).to eq([Presenters::V3::OrganizationPresenter.new(org1).to_hash, Presenters::V3::OrganizationPresenter.new(org2).to_hash]) end it 'only includes the spaces and orgs from the specified service plans' do @@ -49,7 +49,7 @@ module VCAP::CloudController end context 'when plans share a space' do - let!(:space_scoped_plan_same_space) { generate_space_scoped_plan(space1) } + let(:space_scoped_plan_same_space) { generate_space_scoped_plan(space1) } it 'does not duplicate the space' do hash = described_class.decorate({}, [space_scoped_plan_1, space_scoped_plan_same_space]) @@ -59,7 +59,7 @@ module VCAP::CloudController context 'when plans share an org' do let(:space3) { Space.make(organization: org2) } - let!(:space_scoped_plan_same_org) { generate_space_scoped_plan(space3) } + let(:space_scoped_plan_same_org) { generate_space_scoped_plan(space3) } it 'does not duplicate the org' do hash = described_class.decorate({}, [space_scoped_plan_2, space_scoped_plan_same_org]) diff --git a/spec/unit/decorators/include_space_decorator_spec.rb b/spec/unit/decorators/include_space_decorator_spec.rb index a0cc615bb8b..c0441760ecc 100644 --- a/spec/unit/decorators/include_space_decorator_spec.rb +++ b/spec/unit/decorators/include_space_decorator_spec.rb @@ -3,7 +3,7 @@ module VCAP::CloudController RSpec.describe IncludeSpaceDecorator do subject(:decorator) { IncludeSpaceDecorator } - let(:space1) { Space.make(name: 'first-space') } + let(:space1) { Space.make(name: 'first-space', created_at: Time.now.utc - 1.second) } let(:space2) { Space.make(name: 'second-space') } let(:apps) { [AppModel.make(space: space1), AppModel.make(space: space2), AppModel.make(space: space1)] } @@ -11,11 +11,11 @@ module VCAP::CloudController allow(Permissions).to receive(:new).and_return(double(can_read_globally?: true)) end - it 'decorates the given hash with spaces from apps' do + it 'decorates the given hash with spaces from apps in the correct order' do undecorated_hash = { foo: 'bar' } hash = subject.decorate(undecorated_hash, apps) expect(hash[:foo]).to eq('bar') - expect(hash[:included][:spaces]).to contain_exactly(Presenters::V3::SpacePresenter.new(space1).to_hash, Presenters::V3::SpacePresenter.new(space2).to_hash) + expect(hash[:included][:spaces]).to eq([Presenters::V3::SpacePresenter.new(space1).to_hash, Presenters::V3::SpacePresenter.new(space2).to_hash]) end it 'does not overwrite other included fields' do @@ -32,7 +32,7 @@ module VCAP::CloudController end it 'matches include arrays containing "space.organization"' do - expect(decorator.match?(['potato', 'space.organization', 'turnip'])).to be(true) + expect(decorator.match?(%w[potato space.organization turnip])).to be(true) end it 'does not match other include arrays' do diff --git a/spec/unit/decorators/include_space_organization_decorator_spec.rb b/spec/unit/decorators/include_space_organization_decorator_spec.rb index bc19b00b9b3..f2f6e504189 100644 --- a/spec/unit/decorators/include_space_organization_decorator_spec.rb +++ b/spec/unit/decorators/include_space_organization_decorator_spec.rb @@ -3,18 +3,18 @@ module VCAP::CloudController RSpec.describe IncludeSpaceOrganizationDecorator do subject(:decorator) { IncludeSpaceOrganizationDecorator } - let(:organization1) { Organization.make(name: 'first-organization') } + let(:organization1) { Organization.make(name: 'first-organization', created_at: Time.now.utc - 1.second) } let(:organization2) { Organization.make(name: 'second-organization') } let(:space1) { Space.make(name: 'first-space', organization: organization1) } let(:space2) { Space.make(name: 'second-space', organization: organization2) } let(:spaces) { [space1, space2] } - it 'decorates the given hash with organizations from spaces' do + it 'decorates the given hash with organizations from spaces in the correct order' do undecorated_hash = { foo: 'bar' } hash = subject.decorate(undecorated_hash, spaces) expect(hash[:foo]).to eq('bar') - expect(hash[:included][:organizations]).to contain_exactly(Presenters::V3::OrganizationPresenter.new(organization1).to_hash, - Presenters::V3::OrganizationPresenter.new(organization2).to_hash) + expect(hash[:included][:organizations]).to eq([Presenters::V3::OrganizationPresenter.new(organization1).to_hash, + Presenters::V3::OrganizationPresenter.new(organization2).to_hash]) end it 'does not overwrite other included fields' do diff --git a/spec/unit/jobs/runtime/prune_completed_builds_spec.rb b/spec/unit/jobs/runtime/prune_completed_builds_spec.rb index 3fc8b95bfdd..4d64bbff151 100644 --- a/spec/unit/jobs/runtime/prune_completed_builds_spec.rb +++ b/spec/unit/jobs/runtime/prune_completed_builds_spec.rb @@ -73,7 +73,7 @@ module Jobs::Runtime job.perform expect(BuildModel.count).to be(35) - expect(BuildModel.order(Sequel.asc(:created_at)).map(&:id)).to eq((21..40).to_a + (46..60).to_a) + expect(BuildModel.order(Sequel.asc(:created_at), Sequel.asc(:id)).map(&:id)).to eq((21..40).to_a + (46..60).to_a) end it 'calls destroy on the BuildModel so association dependencies are respected' do diff --git a/spec/unit/jobs/runtime/prune_completed_deployments_spec.rb b/spec/unit/jobs/runtime/prune_completed_deployments_spec.rb index 4f8a689d632..4ce3e4db518 100644 --- a/spec/unit/jobs/runtime/prune_completed_deployments_spec.rb +++ b/spec/unit/jobs/runtime/prune_completed_deployments_spec.rb @@ -69,7 +69,7 @@ module Jobs::Runtime job.perform expect(DeploymentModel.count).to eq(50) - expect(DeploymentModel.order(Sequel.asc(:created_at)).map(&:id)).to eq((1..50).to_a) + expect(DeploymentModel.order(Sequel.asc(:created_at), Sequel.asc(:id)).map(&:id)).to eq((1..50).to_a) end it 'does not delete in-flight deployments over the limit' do @@ -87,7 +87,7 @@ module Jobs::Runtime job.perform expect(DeploymentModel.count).to be(35) - expect(DeploymentModel.order(Sequel.asc(:created_at)).map(&:id)).to eq((21..40).to_a + (46..60).to_a) + expect(DeploymentModel.order(Sequel.asc(:created_at), Sequel.asc(:id)).map(&:id)).to eq((21..40).to_a + (46..60).to_a) end it 'destroys metadata associated with pruned deployments' do