Skip to content

Commit

Permalink
Merge pull request #8 from engineyard/search_database_services_by_acc…
Browse files Browse the repository at this point in the history
…ount

Update mocks: search database_services by account
  • Loading branch information
lanej committed Jul 10, 2015
2 parents e2f30eb + 910a389 commit 7d8310b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/ey-core/requests/get_database_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ def get_database_services(_params={})
params["provider"] = url_for("/providers/#{provider_id}")
end

if account_id = resource_identity(params.delete("account"))
if provider = self.data[:providers].values.detect{|p| p["account"].index(account_id)}
params["provider"] = url_for("/providers/#{provider["id"]}")
end
end

resources = if environment_id = resource_identity(params.delete("environment") || params.delete("environment_id"))
self.data[:connectors].
select { |_,c| c["_environment"] == url_for("/environments/#{environment_id}") }.
Expand Down
6 changes: 6 additions & 0 deletions spec/database_services_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,11 @@

expect(client.get_environment_database_services(environment_id: environment.id).body["database_services"].first["id"]).to eq(environment_database_service.id)
end

it 'should list database services in an account' do
environment_database_service, environment = load_blueprint

expect(client.database_services.all(account: environment.account.id).map(&:id)).to include(environment_database_service.id)
end
end
end
4 changes: 2 additions & 2 deletions spec/support/resource_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ResourceHelper
def load_blueprint(options={})
logical_database = create_logical_database(client: options[:client])
logical_database = create_logical_database(client: options[:client], provider: account.providers.first)

application = account.applications.create!(name: "application#{SecureRandom.hex(4)}", repository: "git://github.com/engineyard/todo.git", type: "rails3")
environment = account.environments.create!(name: "environment#{SecureRandom.hex(4)}")
Expand Down Expand Up @@ -82,7 +82,7 @@ def create_cluster_update(options={})
end

def create_database_service(options={})
provider = options.fetch(:provider) { create_provider(options.merge(client: client)) }
provider = options[:provider] || create_provider(options.merge(client: client))

database_service_params = Hashie::Mash.new(
:name => Faker::Name.first_name,
Expand Down

0 comments on commit 7d8310b

Please sign in to comment.