Skip to content

Commit f6fa4e8

Browse files
committed
Merge pull request #197 from intercom/jo/fix-puts-api-resources
fix puts on api resources
2 parents 8028cff + 38b8cf8 commit f6fa4e8

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/intercom/lib/dynamic_accessors_on_method_missing.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def define_accessors_or_call(&block)
1818
Lib::DynamicAccessors.define_accessors(attribute_name, *arguments, object)
1919
object.send(method_sym, *arguments)
2020
else # getter
21-
if trying_to_access_private_variable?
21+
if trying_to_access_private_variable? || trying_to_access_print_method?
2222
yield
2323
else
2424
raise Intercom::AttributeNotSetError, attribute_not_set_error_message
@@ -44,6 +44,10 @@ def trying_to_access_private_variable?
4444
object.instance_variable_defined?("@#{method_string}")
4545
end
4646

47+
def trying_to_access_print_method?
48+
[:to_ary, :to_s].include? method_sym
49+
end
50+
4751
def attribute_not_set_error_message
4852
"'#{method_string}' called on #{klass} but it has not been set an " +
4953
"attribute or does not exist as a method"

spec/unit/intercom/user_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,11 @@
235235
all.must_be_instance_of(Intercom::ClientCollectionProxy)
236236
end
237237

238+
it 'can print users without crashing' do
239+
client.expects(:get).with("/users", {"email" => "[email protected]"}).returns(test_user)
240+
user = client.users.find("email" => "[email protected]")
241+
puts user
242+
p user
243+
end
244+
238245
end

0 commit comments

Comments
 (0)