Skip to content

Commit 7f2c7fb

Browse files
committed
Merge pull request #93 from ryanhertz/throw-error-when-finder-arg-is-nil
Raise error on `nil` argument to find()
2 parents ea408ef + 607b204 commit 7f2c7fb

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
@@ -8,6 +8,7 @@ def find(*arguments)
88
scope = arguments.slice!(0)
99
options = arguments.slice!(0) || {}
1010
case scope
11+
when nil then raise ArgumentError, "Argument for find() can't be nil"
1112
when :all then find_every(options)
1213
when :first then find_every(options).first
1314
when :last then find_every(options).last

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)