Skip to content

Commit b2af03f

Browse files
committed
Merge pull request #107 from intercom/jo/handle-emprty-email-updates
dont try to update empty emails
2 parents 576ec51 + ef665da commit b2af03f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/ext/sliceable_hash.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ def initialize(hash)
77
# Return a hash that includes only the given keys.
88
def slice(*keys)
99
keys.map! { |key| @hash.convert_key(key) } if @hash.respond_to?(:convert_key, true)
10-
keys.each_with_object(@hash.class.new) { |k, hash| hash[k] = @hash[k] if @hash.has_key?(k) }
10+
keys.each_with_object(@hash.class.new) { |k, hash| hash[k] = @hash[k] if @hash.has_key?(k) && if_string_not_empty(@hash[k]) }
11+
end
12+
13+
def if_string_not_empty(val)
14+
val.kind_of?(String) ? !val.empty? : true
1115
end
1216
end

spec/unit/intercom/user_spec.rb

+6
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@
165165
Intercom.expects(:post).with("/users", {'custom_attributes' => {}, "email" => "[email protected]", "user_id" => "i-1224242", "companies" => [{"company_id" => 6, "name" => "Intercom"}]}).returns({"email" => "[email protected]", "user_id" => "i-1224242"})
166166
user.save
167167
end
168+
169+
it 'can save a user with a nil email' do
170+
user = Intercom::User.new("email" => nil, :user_id => "i-1224242", :companies => [{'company_id' => 6, 'name' => "Intercom"}])
171+
Intercom.expects(:post).with("/users", {'custom_attributes' => {}, "email" => nil, "user_id" => "i-1224242", "companies" => [{"company_id" => 6, "name" => "Intercom"}]}).returns({"email" => nil, "user_id" => "i-1224242"})
172+
user.save
173+
end
168174

169175
it "deletes a user" do
170176
user = Intercom::User.new("id" => "1")

0 commit comments

Comments
 (0)