factory_girl_remote_strategy 0.0.6 → 0.0.7
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: ce58337e23b72366c09ab620b0d6c70ce38da4e7
|
4
|
+
data.tar.gz: f7882563ab29647fcb1409f99359ca4b8f4aa45c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77531f5ee48247c23d5b8ae304988d1dad2e2d1a76e07ffc0a69a80c2b0c0f2ef04f7fa070f6a0fc247da726523355b3b5cdf16843210b14d2f28de4f69ce4c1
|
7
|
+
data.tar.gz: cc7d8714e9c337663e87d775564e1974c6be33e481d5939e73d66c10789e168e4b020c3c2e99efe3f8d8adfbc708cf732e078e7d3ca2adf1278d1c9c2f0c1342
|
@@ -61,14 +61,27 @@ module FactoryGirl
|
|
61
61
|
"#{entity.class.site}#{entity.class.prefix}#{entity.class.collection_name}/#{entity.id}.json"
|
62
62
|
end
|
63
63
|
|
64
|
-
def collection_url(collection)
|
65
|
-
(collection.first.is_a?(Class) ? collection.first : collection.first.class).instance_eval { "#{site}#{prefix}#{collection_name}.json" }
|
64
|
+
def collection_url(collection, params = {})
|
65
|
+
(collection.first.is_a?(Class) ? collection.first : collection.first.class).instance_eval { "#{site}#{prefix}#{collection_name}.json#{'?' if params.any?}#{params.to_query}" }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class RemoteNotFoundStrategy < RemoteStrategy
|
71
|
+
def result(evaluation)
|
72
|
+
@strategy.result(evaluation).tap do |e|
|
73
|
+
body = { errors: [{ code: 'resource_not_found',
|
74
|
+
message: "Couldn't find #{e.class} with #{e.class.primary_key}=#{e.public_send(e.class.primary_key)}" } ] }.to_json
|
75
|
+
FakeWeb.register_uri(:get, self.class.entity_url(e), body: body, status: 404)
|
76
|
+
remote_search(e.class, search: { :"#{e.class.primary_key}_eq" => e.public_send(e.class.primary_key) }) # empty search
|
77
|
+
remote_search(e.class, search: { :"#{e.class.primary_key}_in" => [e.public_send(e.class.primary_key)] }) # empty search
|
66
78
|
end
|
67
79
|
end
|
68
80
|
end
|
69
81
|
end
|
70
82
|
|
71
83
|
FactoryGirl.register_strategy(:remote, FactoryGirl::RemoteStrategy)
|
84
|
+
FactoryGirl.register_strategy(:remote_not_found, FactoryGirl::RemoteNotFoundStrategy)
|
72
85
|
|
73
86
|
##
|
74
87
|
# Helper method for register search url with provided params and serialized collection as response.
|
@@ -76,6 +89,6 @@ FactoryGirl.register_strategy(:remote, FactoryGirl::RemoteStrategy)
|
|
76
89
|
def remote_search(*args)
|
77
90
|
params = args.extract_options!
|
78
91
|
collection = args.flatten
|
79
|
-
FakeWeb.register_uri(:get,
|
92
|
+
FakeWeb.register_uri(:get, FactoryGirl::RemoteStrategy.collection_url(collection, params),
|
80
93
|
body: (collection.first.is_a?(Class) ? "[]" : collection.map { |e| FactoryGirl::RemoteStrategy.entity_hash(e) }.to_json))
|
81
94
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FactoryGirl::RemoteNotFoundStrategy do
|
4
|
+
before { FactoryGirl.remote_not_found(:incident, id: 1) }
|
5
|
+
|
6
|
+
it "registers 404 get url with FakeWeb" do
|
7
|
+
expect { Incident.find(1) }.to raise_error ActiveResource::ResourceNotFound
|
8
|
+
end
|
9
|
+
|
10
|
+
it "registers search by id as one in array request with empty array" do
|
11
|
+
incident = Incident.find(:first, params: { search: { id_in: [1] } })
|
12
|
+
expect(incident).to be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it "registers search by id as exact value request with empty array" do
|
16
|
+
incident = Incident.find(:first, params: { search: { id_eq: 1 } })
|
17
|
+
expect(incident).to be_nil
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factory_girl_remote_strategy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Avoyants
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -130,6 +130,7 @@ files:
|
|
130
130
|
- spec/factories/postcode.rb
|
131
131
|
- spec/factories/user.rb
|
132
132
|
- spec/factories/victim.rb
|
133
|
+
- spec/factory_girl_remote_not_found_strategy_spec.rb
|
133
134
|
- spec/factory_girl_remote_strategy_spec.rb
|
134
135
|
- spec/spec_helper.rb
|
135
136
|
- spec/support/group.rb
|
@@ -170,6 +171,7 @@ test_files:
|
|
170
171
|
- spec/factories/postcode.rb
|
171
172
|
- spec/factories/user.rb
|
172
173
|
- spec/factories/victim.rb
|
174
|
+
- spec/factory_girl_remote_not_found_strategy_spec.rb
|
173
175
|
- spec/factory_girl_remote_strategy_spec.rb
|
174
176
|
- spec/spec_helper.rb
|
175
177
|
- spec/support/group.rb
|