Skip to content

Commit 8d638da

Browse files
committed
added check argument in finders
1 parent ea408ef commit 8d638da

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/spark_api/models/finders.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Finders
66

77
def find(*arguments)
88
scope = arguments.slice!(0)
9+
raise ArgumentError, "argument can't be nil" if scope.nil?
910
options = arguments.slice!(0) || {}
1011
case scope
1112
when :all then find_every(options)

spec/unit/spark_api/models/finders_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,21 @@ class MyResource < Base
3232
resource.Id.should eq(1)
3333
end
3434

35+
describe "find" do
36+
37+
it "should throw an error if no argument is passed" do
38+
stub_api_get("/my_resource/", 'finders.json')
39+
lambda {
40+
MyResource.find()
41+
}.should raise_error(ArgumentError)
42+
end
43+
44+
it "should throw an error when the first argument is nil" do
45+
stub_api_get("/my_resource/", 'finders.json', {:_limit => 1})
46+
lambda {
47+
MyResource.find(nil, {:_limit => 1})
48+
}.should raise_error(ArgumentError)
49+
end
50+
51+
end
3552
end

0 commit comments

Comments
 (0)