Skip to content

Commit

Permalink
Allow create_in_provider to fail
Browse files Browse the repository at this point in the history
Credentials should already be valid at this point, if not, that is the
problem of the refresh.
We should raise an error if the record is not found in our database
  • Loading branch information
bdunne committed Feb 23, 2017
1 parent 13acb63 commit affb2af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ def create_in_provider(manager_id, params)

# Get the record in our database
# TODO: This needs to be targeted refresh so it doesn't take too long
EmsRefresh.queue_refresh(manager, nil, true) if !manager.missing_credentials? && manager.authentication_status_ok?
find_by(:manager_id => manager.id, :manager_ref => job_template.id)
EmsRefresh.queue_refresh(manager, nil, true)

find_by!(:manager_id => manager.id, :manager_ref => job_template.id)
end

def create_in_provider_queue(manager_id, params, auth_user = nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,22 @@
}
end

it ".create_in_provider" do
expect(AnsibleTowerClient::Connection).to receive(:new).and_return(atc)
expect(EmsRefresh).to receive(:queue_refresh).and_return(store_new_job_template(job_template, manager))
expect(ExtManagementSystem).to receive(:find).with(manager.id).and_return(manager)

expect(described_class.create_in_provider(manager.id, params)).to be_a(described_class)
context ".create_in_provider" do
it "successfully created in provider" do
expect(AnsibleTowerClient::Connection).to receive(:new).and_return(atc)
expect(EmsRefresh).to receive(:queue_refresh).and_return(store_new_job_template(job_template, manager))
expect(ExtManagementSystem).to receive(:find).with(manager.id).and_return(manager)

expect(described_class.create_in_provider(manager.id, params)).to be_a(described_class)
end

it "not found during refresh" do
expect(AnsibleTowerClient::Connection).to receive(:new).and_return(atc)
expect(EmsRefresh).to receive(:queue_refresh)
expect(ExtManagementSystem).to receive(:find).with(manager.id).and_return(manager)

expect { described_class.create_in_provider(manager.id, params) }.to raise_error(ActiveRecord::RecordNotFound)
end
end

it ".create_in_provider_queue" do
Expand Down

0 comments on commit affb2af

Please sign in to comment.