Skip to content

Commit

Permalink
adds support for Post.any?/Post.empty?
Browse files Browse the repository at this point in the history
  • Loading branch information
balvig committed Jan 26, 2015
1 parent 4a929d3 commit 269a1f6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/spyke/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Relation

attr_reader :klass, :params
attr_writer :params
delegate :to_ary, :[], :empty?, :last, :size, :metadata, to: :find_some
delegate :to_ary, :[], :any?, :empty?, :last, :size, :metadata, to: :find_some

def initialize(klass, options = {})
@klass, @options, @params = klass, options, {}
Expand Down
2 changes: 1 addition & 1 deletion lib/spyke/scoping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Scoping
extend ActiveSupport::Concern

module ClassMethods
delegate :where, :build, to: :all
delegate :where, :build, :any?, :empty?, to: :all

def all
current_scope || Relation.new(self, uri: uri)
Expand Down
2 changes: 1 addition & 1 deletion lib/spyke/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Spyke
VERSION = '1.7.1'
VERSION = '1.7.2'
end
7 changes: 7 additions & 0 deletions test/relation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ def test_all
assert_equal 'meta', recipes.metadata
end

def test_any?
endpoint = stub_request(:get, 'http://sushi.com/recipes').to_return_json(result: [{ id: 1 }])

assert_equal true, Recipe.any?
assert_requested endpoint
end

def test_scope_independence
endpoint = stub_request(:get, 'http://sushi.com/recipes?query=chicken')
wrong_endpoint = stub_request(:get, 'http://sushi.com/recipes?query=chicken&page=1')
Expand Down

0 comments on commit 269a1f6

Please sign in to comment.