Skip to content

Commit f177830

Browse files
committed
explicitly fail if someone attempts to use count with block (as supported by Enumerable) on UserCollectionProxy
1 parent 0756b95 commit f177830

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/intercom/user_collection_proxy.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ module Intercom
1717
# end
1818
#
1919
class UserCollectionProxy
20+
include Enumerable
21+
2022
# @return [Integer] number of users tracked on Intercom for this application
2123
def count
24+
raise ArgumentError.new("count doesn't support block argument") if block_given?
2225
response = Intercom.get("users", {:per_page => 1})
2326
response["total_count"]
2427
end
@@ -37,7 +40,5 @@ def each(&block)
3740
fetch_another_page = !current_page["next_page"].nil?
3841
end
3942
end
40-
41-
include Enumerable
4243
end
4344
end

spec/unit/intercom/user_collection_proxy_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
Intercom::User.all.count.must_equal 3
2626
end
2727

28+
it "explicitly doesn't support block argument for count" do
29+
assert_raises ArgumentError do
30+
Intercom::User.all.count {|_| true }
31+
end
32+
end
33+
2834
it "loads multiple pages" do
2935
Intercom.expects(:get).with("users", {:page => 1}).returns(page_of_users(1, 1))
3036
Intercom.expects(:get).with("users", {:page => 2}).returns(page_of_users(2, 1))

0 commit comments

Comments
 (0)