Skip to content
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #57 from dxw/fix/discipline-can-be-nil
Browse files Browse the repository at this point in the history
Protect against nil when importing team members
  • Loading branch information
CristinaRO committed Feb 5, 2021
2 parents 1b17199 + 86a6d8a commit 09717b7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/services/fetch_projects.rb
Expand Up @@ -34,9 +34,9 @@ def call
team_member = TeamMember.find_or_initialize_by(tenk_id: user.id)
team_member.attributes = {
first_name: user.first_name.strip,
last_name: user.last_name.strip,
email: user.email.downcase.strip,
discipline: user.discipline.strip,
last_name: user.last_name&.strip,
email: user.email&.downcase&.strip,
discipline: user.discipline&.strip,
thumbnail: user.thumbnail,
billable: user.billable
}
Expand Down
27 changes: 27 additions & 0 deletions spec/services/fetch_projects_spec.rb
Expand Up @@ -62,6 +62,33 @@
expect(team_member.projects).to be_empty
end
end

context "when optional team member attributes are nil" do
it "creates the team member" do
user_no_discipline = Hashie::Array[
Tenk::Client::Response.new(
billable: true,
discipline: nil,
email: nil,
first_name: "Tom",
id: 387517,
last_name: nil,
thumbnail: "https://fake.thumbnail/123",
type: "User",
)
]

allow(fake_tenk_users_object).to receive_message_chain(:list, :data)
.and_return(user_no_discipline)

described_class.new.call

team_member = TeamMember.find_by(tenk_id: 387517)
expect(team_member.discipline).to be_nil
expect(team_member.last_name).to be_nil
expect(team_member.email).to be_nil
end
end
end

def fake_tenk_client
Expand Down

0 comments on commit 09717b7

Please sign in to comment.