json_api_client_mock 0.2.4 → 0.3.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 844a5078f3405888a37610b10c0a7198f2e0d600
|
4
|
+
data.tar.gz: 026b8a493d59ca83bc36313ffd86f81ec8782386
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3465ab1c2b5704d5fb26515e6d321da9f40885ee518982148e0b3f4b69ba397163959184e4d76e1adc9097ad2578460c004582dda85cb8c2add91e85f5a2fde
|
7
|
+
data.tar.gz: 1e3ff9b9863978837356aae7d98c7ef70341a5fe37ffde8a3ffd83b0c457994ab0f81b74d5d41203cb1e00f97e744b207dae9b93fefc1141a935240b7319c25d
|
data/README.md
CHANGED
@@ -39,6 +39,24 @@ MyResource.set_test_results([
|
|
39
39
|
|
40
40
|
MyResource.where(condition1: 'value1', condition2: 'value2').all
|
41
41
|
=> [<#MyResource foo:'asdf', qwer:'bar'>]
|
42
|
+
```
|
43
|
+
To set the response meta for `MyResource`:
|
44
|
+
|
45
|
+
```
|
46
|
+
MyResource.set_test_results([
|
47
|
+
{foo: 'asdf', 'qwer': 'bar'}
|
48
|
+
], {
|
49
|
+
condition1: 'value1',
|
50
|
+
condition2: 'value2',
|
51
|
+
}, {
|
52
|
+
meta_attribute: 1000
|
53
|
+
})
|
54
|
+
|
55
|
+
response = MyResource.where(condition1: 'value1', condition2: 'value2').all
|
56
|
+
=> [<#MyResource foo:'asdf', qwer:'bar'>]
|
57
|
+
puts response.meta
|
58
|
+
=> { :meta_attribute => 1000 }
|
59
|
+
```
|
42
60
|
|
43
61
|
# condition order should not matter
|
44
62
|
MyResource.where(condition2: 'value2', condition1: 'value1').all
|
@@ -13,16 +13,17 @@ module JsonApiClientMock
|
|
13
13
|
def execute(query)
|
14
14
|
if results = find_test_results(query)
|
15
15
|
OpenStruct.new(:body => {
|
16
|
-
query.klass.table_name => results[:results]
|
16
|
+
query.klass.table_name => results[:results],
|
17
|
+
"meta" => results[:meta]
|
17
18
|
})
|
18
19
|
else
|
19
20
|
raise MissingMock, missing_message(query)
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
|
-
def set_test_results(klass, results, conditions = nil)
|
24
|
+
def set_test_results(klass, results, conditions = nil, response_meta = {})
|
24
25
|
self.class.mocks[klass.name] ||= []
|
25
|
-
self.class.mocks[klass.name].unshift({results: results, conditions: conditions})
|
26
|
+
self.class.mocks[klass.name].unshift({results: results, conditions: conditions, meta: response_meta })
|
26
27
|
end
|
27
28
|
|
28
29
|
def clear_test_results
|
@@ -8,8 +8,8 @@ module JsonApiClientMock
|
|
8
8
|
end
|
9
9
|
|
10
10
|
module ClassMethods
|
11
|
-
def set_test_results(results, conditions = nil)
|
12
|
-
connection.set_test_results(self, results, conditions)
|
11
|
+
def set_test_results(results, conditions = nil, meta = {})
|
12
|
+
connection.set_test_results(self, results, conditions, meta)
|
13
13
|
end
|
14
14
|
|
15
15
|
def clear_test_results
|
@@ -50,6 +50,13 @@ class JsonApiClientMockTest < MiniTest::Unit::TestCase
|
|
50
50
|
assert_equal('asdf', first.qwer)
|
51
51
|
end
|
52
52
|
|
53
|
+
def test_meta_response
|
54
|
+
BarResource.set_test_results([{foo: 'bar', qwer: 'asdf'}], {foo: 'bar'}, {meta_attr: 1000})
|
55
|
+
results = BarResource.where(foo: 'bar').all
|
56
|
+
|
57
|
+
assert_equal(1000, results.meta[:meta_attr])
|
58
|
+
end
|
59
|
+
|
53
60
|
def test_by_conditional_request_path_mocking
|
54
61
|
BarResource.set_test_results([{foo: 'bar', qwer: 'asdf'}], {path: 'bar_resources/10'})
|
55
62
|
assert_raises(JsonApiClientMock::MissingMock) do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_api_client_mock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Ching
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json_api_client
|