Skip to content

Commit

Permalink
Add logic to filter out workflow job node that is for inventory sync …
Browse files Browse the repository at this point in the history
  • Loading branch information
lfu committed Jun 19, 2019
1 parent 887eebf commit b398b0d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/ansible_tower_client/base_models/workflow_job_node.rb
Expand Up @@ -5,7 +5,14 @@ def workflow_job
end

def job
api.jobs.find(job_id) if respond_to?(:job_id) && job_id
api.jobs.find(job_id) if job?
end

# to filter out WorkflowJobNode that is inventory sync or project sync
def job?
return false if !respond_to?(:job_id) || job_id.nil?

related.job.match?(/jobs/)
end
end
end
9 changes: 8 additions & 1 deletion spec/workflow_job_node_spec.rb
Expand Up @@ -34,10 +34,17 @@ def response_with_job(response, id)
end

it "returns a Job when the job_id is set" do
obj = described_class.new(api, response_with_job(raw_instance, 12345))
obj = described_class.new(api, response_with_job(raw_instance, "/api/v1/jobs/2710/"))
allow(api).to receive(:get).and_return(instance_double("Faraday::Result", :body => {}.to_json))

expect(obj.job).to be_a AnsibleTowerClient::Job
end

it "returns nil when it is a inventory sync" do
obj = described_class.new(api, response_with_job(raw_instance, "/api/v1/inventory_updates/2710/"))
allow(api).to receive(:get).and_return(instance_double("Faraday::Result", :body => {}.to_json))

expect(obj.job).to be_nil
end
end
end

0 comments on commit b398b0d

Please sign in to comment.