spyke 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 966940526b348b3fbf28422233a7e512320cda54
4
- data.tar.gz: 9ad09f29e1ed32fe872c2765730f367f670bcefa
3
+ metadata.gz: 9261f1e664c27242d946133701985395af962417
4
+ data.tar.gz: 11bba7b0d4ca6a79a0066e1faeddf43d19cd339e
5
5
  SHA512:
6
- metadata.gz: 0977ba9818ab15ac582baf91f24e1970da2c44da2b3de6834a3d3b7d9931ac4a9844d418227b5923f0885656311b04a1d0847d44a2d3f8f15d70d50d2fdb4165
7
- data.tar.gz: b5032eda8fce1dd746ea94f1ef5dced990fd5f16877654b2631e2a2d334bfd6eae8d6951c645f34a5bf1567d204a36ef906b3209f9284bd4bc1cfe75d0fcf800
6
+ metadata.gz: 1bd18ad389c88b9831ea2b028fb2179064283d7b359a0d4cb99ab4d7fb88edefc1f2fabb45993ef4fea00773eb8f36add91610165b3eaa312a61714b3fcb1389
7
+ data.tar.gz: 8b392cff15ce16f2d473f27aa967bd91121e1a80e78a0cbccef1669ae28791fa6501a07eee81079590eb58c2b302c0097eb202025a1f22e9d217bffd7b5226a3
data/README.md CHANGED
@@ -70,11 +70,20 @@ class User < Spyke::Base
70
70
  has_many :posts
71
71
  end
72
72
 
73
- user = User.find(3) # => GET http://api.com/users/3
74
- user.posts # => find embedded in user or GET http://api.com/users/3/posts
75
- user = User.create(name: 'Bob') # => POST http://api.com/users - { user: { name: 'Bob' } }
76
- user.update_attributes(name: 'Alice') # => PUT http://api.com/users/3 - { user: { name: 'Alice' } }
77
- user.destroy # => DELETE http://api.com/users/3
73
+ user = User.find(3)
74
+ # => GET http://api.com/users/3
75
+
76
+ user.posts
77
+ # => find embedded in returned JSON or GET http://api.com/users/3/posts
78
+
79
+ user.update_attributes(name: 'Alice')
80
+ # => PUT http://api.com/users/3 - { user: { name: 'Alice' } }
81
+
82
+ user.destroy
83
+ # => DELETE http://api.com/users/3
84
+
85
+ User.create(name: 'Bob')
86
+ # => POST http://api.com/users - { user: { name: 'Bob' } }
78
87
  ```
79
88
 
80
89
  ### Custom URIs
data/lib/spyke/scopes.rb CHANGED
@@ -9,7 +9,7 @@ module Spyke
9
9
  delegate :all, :where, to: :current_scope
10
10
 
11
11
  def scope(name, code)
12
- self.class.send :define_method, name, code
12
+ define_singleton_method name, code
13
13
  end
14
14
 
15
15
  def current_scope=(scope)
data/lib/spyke/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Spyke
2
- VERSION = '1.2.0'
2
+ VERSION = '1.2.1'
3
3
  end
@@ -51,6 +51,16 @@ module Spyke
51
51
  assert_requested endpoint
52
52
  end
53
53
 
54
+ def test_scope_class_method_doesnt_get_overridden
55
+ recipe_endpoint = stub_request(:get, 'http://sushi.com/recipes?approved=true')
56
+ comment_endpoint = stub_request(:get, 'http://sushi.com/comments?comment_approved=true')
57
+
58
+ Recipe.approved.to_a
59
+ assert_requested recipe_endpoint
60
+ Comment.approved.to_a
61
+ assert_requested comment_endpoint
62
+ end
63
+
54
64
  def test_scope_doesnt_get_stuck
55
65
  endpoint_1 = stub_request(:get, 'http://sushi.com/recipes?per_page=3&status=published')
56
66
  endpoint_2 = stub_request(:get, 'http://sushi.com/recipes?status=published')
@@ -6,6 +6,7 @@ class Recipe < Spyke::Base
6
6
  belongs_to :user
7
7
 
8
8
  scope :published, -> { where(status: 'published') }
9
+ scope :approved, -> { where(approved: true) }
9
10
  attributes :title
10
11
 
11
12
  before_save :before_save_callback
@@ -63,3 +64,7 @@ end
63
64
  class Photo < Spyke::Base
64
65
  uri '/images/photos/:id'
65
66
  end
67
+
68
+ class Comment < Spyke::Base
69
+ scope :approved, -> { where(comment_approved: true) }
70
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spyke
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Balvig
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-09 00:00:00.000000000 Z
11
+ date: 2014-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport