spyke 3.1.5 → 4.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 +1 -1
- data/lib/spyke/orm.rb +2 -6
- data/lib/spyke/version.rb +1 -1
- data/test/orm_test.rb +10 -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: e980ff30e66724a75b850bd1f34c55e61811982a
|
4
|
+
data.tar.gz: 6445b6f21a1636cdd84ecb64228583f7abb3fde1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72b27fd9fc2e31c0d20a0d6659fe3df37e7608c35a86fa65d9f770ff9c5f86e7f54efcbed52cc277496ca321f82c30f729a337aa8a2ec6db91e9839e8d9b5978
|
7
|
+
data.tar.gz: 366d92028af07c902f6e7a7dd4ef5c3938f1059de6e39caff50fa8dba158e70923b37b918f9e852ea33557cb9f18d471d2f872ab7eb5ba34fc4734201620fe85
|
data/README.md
CHANGED
@@ -93,7 +93,7 @@ user = User.find(3)
|
|
93
93
|
user.posts
|
94
94
|
# => find embedded in returned JSON or GET http://api.com/users/3/posts
|
95
95
|
|
96
|
-
user.
|
96
|
+
user.update(name: 'Alice')
|
97
97
|
# => PUT http://api.com/users/3 - { user: { name: 'Alice' } }
|
98
98
|
|
99
99
|
user.destroy
|
data/lib/spyke/orm.rb
CHANGED
@@ -24,7 +24,6 @@ module Spyke
|
|
24
24
|
|
25
25
|
def find(id)
|
26
26
|
raise ResourceNotFound if id.blank?
|
27
|
-
id = strip_slug(id)
|
28
27
|
where(id: id).find_one || raise(ResourceNotFound)
|
29
28
|
end
|
30
29
|
|
@@ -41,10 +40,6 @@ module Spyke
|
|
41
40
|
def destroy(id = nil)
|
42
41
|
new(id: id).destroy
|
43
42
|
end
|
44
|
-
|
45
|
-
def strip_slug(id)
|
46
|
-
id.to_s.split('-').first
|
47
|
-
end
|
48
43
|
end
|
49
44
|
|
50
45
|
def to_params
|
@@ -72,10 +67,11 @@ module Spyke
|
|
72
67
|
self.attributes = delete
|
73
68
|
end
|
74
69
|
|
75
|
-
def
|
70
|
+
def update(new_attributes)
|
76
71
|
self.attributes = new_attributes
|
77
72
|
save
|
78
73
|
end
|
74
|
+
alias :update_attributes :update
|
79
75
|
|
80
76
|
def reload
|
81
77
|
self.attributes = self.class.find(id).attributes
|
data/lib/spyke/version.rb
CHANGED
data/test/orm_test.rb
CHANGED
@@ -25,12 +25,6 @@ module Spyke
|
|
25
25
|
assert_equal 'Sashimi', recipe.title
|
26
26
|
end
|
27
27
|
|
28
|
-
def test_find_with_slug
|
29
|
-
endpoint = stub_request(:get, 'http://sushi.com/recipes/1').to_return_json(result: { id: 1 })
|
30
|
-
Recipe.find('1-delicious-soup')
|
31
|
-
assert_requested endpoint
|
32
|
-
end
|
33
|
-
|
34
28
|
def test_404
|
35
29
|
stub_request(:get, 'http://sushi.com/recipes/1').to_return(status: 404, body: { message: 'Not found' }.to_json)
|
36
30
|
|
@@ -70,6 +64,16 @@ module Spyke
|
|
70
64
|
assert_requested endpoint
|
71
65
|
end
|
72
66
|
|
67
|
+
def test_update
|
68
|
+
endpoint = stub_request(:put, 'http://sushi.com/recipes/1').with(body: { recipe: { title: 'Sushi' } }).to_return_json(result: { id: 1, title: 'Sushi (saved)' })
|
69
|
+
|
70
|
+
recipe = Recipe.new(id: 1, title: 'Sashimi')
|
71
|
+
recipe.update(title: 'Sushi')
|
72
|
+
|
73
|
+
assert_equal 'Sushi (saved)', recipe.title
|
74
|
+
assert_requested endpoint
|
75
|
+
end
|
76
|
+
|
73
77
|
def test_create
|
74
78
|
endpoint = stub_request(:post, 'http://sushi.com/recipes').with(body: { recipe: { title: 'Sushi' } }).to_return_json(result: { id: 1, title: 'Sushi' })
|
75
79
|
|
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: 4.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-10-
|
11
|
+
date: 2015-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|