spyke 2.0.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/lib/spyke/attribute_assignment.rb +6 -1
- data/lib/spyke/relation.rb +1 -1
- data/lib/spyke/scoping.rb +1 -1
- data/lib/spyke/version.rb +1 -1
- data/test/attributes_test.rb +12 -0
- data/test/custom_request_test.rb +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ce71952fe595064f132a92bbbc41179614be927
|
4
|
+
data.tar.gz: bdf0fc8ed096c28303c3014ddcb588a666a39a04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8799dbc60fb64c096241990fb35d53d802dcc83c98a45f71e1573649261b3b11ea8558af102e335ed7eabde7678056bc13912984de7a7e51665d75be9cae6f82
|
7
|
+
data.tar.gz: df55a3f1dc825c5a10d3e0c142b42bed0739cb942e8c32bc2da501a9215f897200fa3fd6a162cdcebb19241369868fafd802dd7ab5349f9f0a858e2d0b63fc1f
|
data/README.md
CHANGED
@@ -128,16 +128,16 @@ Post.find(4) # => GET http://api.com/posts/4
|
|
128
128
|
|
129
129
|
### Custom requests
|
130
130
|
|
131
|
-
Custom request methods and the `
|
131
|
+
Custom request methods and the `with` scope methods allow you to
|
132
132
|
perform requests for non-REST actions:
|
133
133
|
|
134
|
-
The `.
|
134
|
+
The `.with` scope:
|
135
135
|
|
136
136
|
```ruby
|
137
|
-
Post.
|
138
|
-
Post.
|
139
|
-
Post.
|
140
|
-
Post.
|
137
|
+
Post.with('posts/recent') # => GET http://api.com/posts/recent
|
138
|
+
Post.with(:recent) # => GET http://api.com/posts/recent
|
139
|
+
Post.with(:recent).where(status: 'draft') # => GET http://api.com/posts/recent?status=draft
|
140
|
+
Post.with(:recent).post # => POST http://api.com/posts/recent
|
141
141
|
```
|
142
142
|
|
143
143
|
Custom requests from instance:
|
@@ -48,9 +48,14 @@ module Spyke
|
|
48
48
|
attributes[:id] = value if value.present?
|
49
49
|
end
|
50
50
|
|
51
|
+
def hash
|
52
|
+
id.hash
|
53
|
+
end
|
54
|
+
|
51
55
|
def ==(other)
|
52
|
-
other.
|
56
|
+
other.instance_of?(self.class) && id? && id == other.id
|
53
57
|
end
|
58
|
+
alias :eql? :==
|
54
59
|
|
55
60
|
def inspect
|
56
61
|
"#<#{self.class}(#{uri}) id: #{id.inspect} #{inspect_attributes}>"
|
data/lib/spyke/relation.rb
CHANGED
data/lib/spyke/scoping.rb
CHANGED
data/lib/spyke/version.rb
CHANGED
data/test/attributes_test.rb
CHANGED
@@ -63,6 +63,18 @@ module Spyke
|
|
63
63
|
assert_equal Recipe.new(id: 2, title: 'Fish'), Recipe.new(id: 2, title: 'Fish')
|
64
64
|
refute_equal Recipe.new(id: 2, title: 'Fish'), Recipe.new(id: 1, title: 'Fish')
|
65
65
|
refute_equal Recipe.new(id: 2, title: 'Fish'), 'not_a_spyke_object'
|
66
|
+
refute_equal Recipe.new(id: 2, title: 'Fish'), Image.new(id: 2, title: 'Fish')
|
67
|
+
refute_equal Recipe.new, Recipe.new
|
68
|
+
refute_equal StepImage.new(id: 1), Image.new(id: 1)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_uniqueness
|
72
|
+
recipe_1 = Recipe.new(id: 1)
|
73
|
+
recipe_2 = Recipe.new(id: 1)
|
74
|
+
recipe_3 = Recipe.new(id: 2)
|
75
|
+
image_1 = Image.new(id: 2)
|
76
|
+
records = [recipe_1, recipe_2, recipe_3, image_1]
|
77
|
+
assert_equal [recipe_1, recipe_3, image_1], records.uniq
|
66
78
|
end
|
67
79
|
|
68
80
|
def test_explicit_attributes
|
data/test/custom_request_test.rb
CHANGED
@@ -4,38 +4,38 @@ module Spyke
|
|
4
4
|
class CustomRequestTest < MiniTest::Test
|
5
5
|
def test_custom_get_request_from_class
|
6
6
|
endpoint = stub_request(:get, 'http://sushi.com/recipes/recent').to_return_json(result: [{ id: 1, title: 'Bread' }])
|
7
|
-
recipes = Recipe.
|
7
|
+
recipes = Recipe.with('/recipes/recent').get
|
8
8
|
assert_equal %w{ Bread }, recipes.map(&:title)
|
9
9
|
assert_requested endpoint
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_custom_put_request_from_class
|
13
13
|
endpoint = stub_request(:put, 'http://sushi.com/recipes/publish_all')
|
14
|
-
Recipe.
|
14
|
+
Recipe.with('/recipes/publish_all').put
|
15
15
|
assert_requested endpoint
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_custom_request_with_prepended_scope
|
19
19
|
endpoint = stub_request(:get, 'http://sushi.com/recipes/recent?status=published')
|
20
|
-
Recipe.published.
|
20
|
+
Recipe.published.with('/recipes/recent').to_a
|
21
21
|
assert_requested endpoint
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_custom_request_with_appended_scope
|
25
25
|
endpoint = stub_request(:get, 'http://sushi.com/recipes/recent?status=published')
|
26
|
-
Recipe.
|
26
|
+
Recipe.with('/recipes/recent').published.to_a
|
27
27
|
assert_requested endpoint
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_custom_request_with_symbol_and_appended_scope
|
31
31
|
endpoint = stub_request(:get, 'http://sushi.com/recipes/recent?status=published')
|
32
|
-
Recipe.
|
32
|
+
Recipe.with(:recent).published.to_a
|
33
33
|
assert_requested endpoint
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_create_on_custom_request
|
37
37
|
endpoint = stub_request(:post, 'http://sushi.com/recipes/recent').with(body: { recipe: { status: 'published' } })
|
38
|
-
Recipe.
|
38
|
+
Recipe.with(:recent).published.create
|
39
39
|
assert_requested endpoint
|
40
40
|
end
|
41
41
|
|
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:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Balvig
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|