ruby-fs-stack 0.2.2 → 0.2.3

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -28,7 +28,7 @@ module FamilytreeV2
28
28
  end
29
29
 
30
30
  # ===params
31
- # <tt>id</tt> should be a string of the persons identifier. For the 'me' person, use :me or 'me'
31
+ # <tt>id_or_ids</tt> should be a string of the persons identifier. For the 'me' person, use :me or 'me'. Can also accept an array of ID strings.
32
32
  # <tt>options</tt> accepts a hash of parameters as documented by the API.
33
33
  # For full parameter documentation, see DevNet[https://devnet.familysearch.org/docs/api-manual-reference-system/familytree-v2/r_api_family_tree_person_read_v2.html]
34
34
  #
@@ -39,19 +39,29 @@ module FamilytreeV2
39
39
  #
40
40
  # p.version # => '90194378772'
41
41
  # p.id # => 'KW3B-NNM'
42
- def person(id, options = {})
43
- id = id.to_s
44
- if id == 'me'
45
- url = Base + 'person'
42
+ def person(id_or_ids, options = {})
43
+ if id_or_ids.kind_of? Array
44
+ multiple_ids = true
45
+ url = Base + 'person/' + id_or_ids.join(',')
46
46
  else
47
- url = Base + 'person/' + id
47
+ multiple_ids = false
48
+ id = id_or_ids.to_s
49
+ if id == 'me'
50
+ url = Base + 'person'
51
+ else
52
+ url = Base + 'person/' + id
53
+ end
48
54
  end
49
55
  url += "?"+FsUtils.querystring_from_hash(options) unless options.empty?
50
56
  response = @fs_communicator.get(url)
51
57
  familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.from_json JSON.parse(response.body)
52
- person = familytree.persons.find{|p| p.requestedId == id }
53
- person ||= familytree.persons.first if id == 'me'
54
- person
58
+ if multiple_ids
59
+ return familytree.persons
60
+ else
61
+ person = familytree.persons.find{|p| p.requestedId == id }
62
+ person ||= familytree.persons.first if id == 'me'
63
+ return person
64
+ end
55
65
  end
56
66
 
57
67
  def save_person(person)
@@ -189,6 +199,22 @@ module FamilytreeV2
189
199
  end
190
200
  end
191
201
 
202
+ # Combines person into a new person
203
+ #
204
+ # ====Params
205
+ # * <tt>person_array</tt> - an array of person IDs.
206
+ def combine(person_array)
207
+ url = Base + 'person'
208
+ version_persons = self.person person_array, :genders => 'none', :events => 'none', :names => 'none'
209
+ combine_person = Org::Familysearch::Ws::Familytree::V2::Schema::Person.new
210
+ combine_person.create_combine(version_persons)
211
+ familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.new
212
+ familytree.persons = [combine_person]
213
+ res = @fs_communicator.post(url,familytree.to_json)
214
+ familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.from_json JSON.parse(res.body)
215
+ return familytree.persons[0]
216
+ end
217
+
192
218
  private
193
219
  #options will either have a :parent, :child, or :spouse key. We need to find which one
194
220
  def get_relationship_type(options)
@@ -785,6 +811,20 @@ module Org::Familysearch::Ws::Familytree::V2::Schema
785
811
  add_relationships!
786
812
  self.relationships.add_relationship(options)
787
813
  end
814
+
815
+ # This method should only be called from FamilytreeV2::Communicator#combine
816
+ #
817
+ # ====Params
818
+ # * <tt>persons</tt> - an array of person objects. All persons must have an id and version
819
+ def create_combine(persons)
820
+ self.personas = Org::Familysearch::Ws::Familytree::V2::Schema::PersonPersonas.new
821
+ self.personas.personas = persons.map do |person|
822
+ persona = Org::Familysearch::Ws::Familytree::V2::Schema::PersonPersona.new
823
+ persona.id = person.id
824
+ persona.version = person.version
825
+ persona
826
+ end
827
+ end
788
828
 
789
829
  private
790
830
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruby-fs-stack}
8
- s.version = "0.2.2"
8
+ s.version = "0.2.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jimmy Zimmerman"]
12
- s.date = %q{2009-12-10}
12
+ s.date = %q{2009-12-14}
13
13
  s.description = %q{A library that enables you to read and update information with the new.familysearch.org API.}
14
14
  s.email = %q{jimmy.zimmerman@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -39,9 +39,12 @@ Gem::Specification.new do |s|
39
39
  "ruby-fs-stack.gemspec",
40
40
  "spec/communicator_spec.rb",
41
41
  "spec/familytree_v2/familytree_communicator_spec.rb",
42
+ "spec/familytree_v2/json/combine_request.js",
43
+ "spec/familytree_v2/json/combine_response.js",
42
44
  "spec/familytree_v2/json/match_KW3B-NNM.js",
43
45
  "spec/familytree_v2/json/person/KJ86-3VD_all.js",
44
46
  "spec/familytree_v2/json/person/KJ86-3VD_version.js",
47
+ "spec/familytree_v2/json/person/multiple_version_read.js",
45
48
  "spec/familytree_v2/json/person/post_response.js",
46
49
  "spec/familytree_v2/json/person/relationship_not_found.js",
47
50
  "spec/familytree_v2/json/person/relationship_read.js",
@@ -1,11 +1,23 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe FamilytreeV2::Communicator do
4
+ FamilyTreeV2 = Org::Familysearch::Ws::Familytree::V2::Schema
5
+
4
6
  def read_file(filename)
5
7
  fname = File.join(File.dirname(__FILE__),'json','person',filename)
6
8
  File.read(fname)
7
9
  end
8
10
 
11
+ def new_person
12
+ Org::Familysearch::Ws::Familytree::V2::Schema::Person.new
13
+ end
14
+
15
+ def existing_person
16
+ person_json = read_file('KJ86-3VD_version.js')
17
+ ft = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.from_json JSON.parse(person_json)
18
+ ft.persons.first
19
+ end
20
+
9
21
  describe "fs_familytree_v1 call on the FsCommunicator" do
10
22
  before(:each) do
11
23
  @com = FsCommunicator.new
@@ -64,24 +76,31 @@ describe FamilytreeV2::Communicator do
64
76
 
65
77
  end
66
78
 
67
- describe "save_person" do
79
+ describe "person read w/ multiple IDs" do
68
80
  before(:each) do
69
81
  @fs_com_mock = mock("FsCommunicator")
70
82
  @res = mock("HTTP::Response")
71
- @json = read_file('post_response.js')
83
+ @json = read_file('multiple_version_read.js')
72
84
  @res.stub!(:body).and_return(@json)
73
- @fs_com_mock.stub!(:post).and_return(@res)
85
+ @fs_com_mock.stub!(:get).and_return(@res)
74
86
  @ft_v2_com = FamilytreeV2::Communicator.new @fs_com_mock
75
87
  end
76
88
 
77
- def new_person
78
- Org::Familysearch::Ws::Familytree::V2::Schema::Person.new
89
+ it "should accept an array of person IDs" do
90
+ @fs_com_mock.should_receive(:get).with('/familytree/v2/person/KW3B-VCY,KW3B-VCB,KW3B-VC1?names=none').and_return(@res)
91
+ results = @ft_v2_com.person ["KW3B-VCY", "KW3B-VCB", "KW3B-VC1"], :names => 'none'
92
+ results.should be_a_kind_of(Array)
79
93
  end
80
-
81
- def existing_person
82
- person_json = read_file('KJ86-3VD_version.js')
83
- ft = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.from_json JSON.parse(person_json)
84
- ft.persons.first
94
+ end
95
+
96
+ describe "save_person" do
97
+ before(:each) do
98
+ @fs_com_mock = mock("FsCommunicator")
99
+ @res = mock("HTTP::Response")
100
+ @json = read_file('post_response.js')
101
+ @res.stub!(:body).and_return(@json)
102
+ @fs_com_mock.stub!(:post).and_return(@res)
103
+ @ft_v2_com = FamilytreeV2::Communicator.new @fs_com_mock
85
104
  end
86
105
 
87
106
  describe "saving new persons" do
@@ -122,229 +141,279 @@ describe FamilytreeV2::Communicator do
122
141
  end
123
142
 
124
143
  end
144
+ end
145
+
146
+ describe "search" do
147
+
148
+ before(:each) do
149
+ @fs_com_mock = mock("FsCommunicator")
150
+ @res = mock("HTTP::Response")
151
+ @ft_v2_com = FamilytreeV2::Communicator.new @fs_com_mock
152
+
153
+ @json = read_file('../search.js')
154
+ @res.stub!(:body).and_return(@json)
155
+ @res.stub!(:code).and_return('200')
156
+ @fs_com_mock.stub!(:get).and_return(@res)
157
+ end
158
+
159
+ it "should call the search endpoint" do
160
+ @fs_com_mock.should_receive(:get).with("/familytree/v2/search?name=John")
161
+ @ft_v2_com.search :name => "John"
162
+ end
163
+
164
+ it "should return the SearchResult element" do
165
+ search_results = @ft_v2_com.search :name => "John"
166
+ search_results.class.should == Org::Familysearch::Ws::Familytree::V2::Schema::SearchResults
167
+ search_results.partial.should == 246
168
+ search_results.close.should == 100
169
+ search_results.count.should == 40
170
+ end
171
+
172
+ it "should serialize embedded parent parameters" do
173
+ @fs_com_mock.should_receive(:get).with("/familytree/v2/search?father.name=John")
174
+ @ft_v2_com.search :father => {:name => "John"}
175
+ end
176
+
177
+ end
178
+
179
+ describe "match" do
125
180
 
126
- describe "search" do
181
+ before(:each) do
182
+ @fs_com_mock = mock("FsCommunicator")
183
+ @res = mock("HTTP::Response")
184
+ @ft_v2_com = FamilytreeV2::Communicator.new @fs_com_mock
127
185
 
186
+ @json = read_file('../match_KW3B-NNM.js')
187
+ @res.stub!(:body).and_return(@json)
188
+ @res.stub!(:code).and_return('200')
189
+ @fs_com_mock.stub!(:get).and_return(@res)
190
+ end
191
+
192
+ it "should call the match endpoint" do
193
+ @fs_com_mock.should_receive(:get).with("/familytree/v2/match?name=John")
194
+ @ft_v2_com.match :name => "John"
195
+ end
196
+
197
+ it "should return the MatchResults element" do
198
+ search_results = @ft_v2_com.match :name => "John"
199
+ search_results.class.should == Org::Familysearch::Ws::Familytree::V2::Schema::MatchResults
200
+ search_results.count.should == 4
201
+ end
202
+
203
+ it "should serialize embedded parent parameters" do
204
+ @fs_com_mock.should_receive(:get).with("/familytree/v2/match?father.name=John")
205
+ @ft_v2_com.match :father => {:name => "John"}
206
+ end
207
+
208
+ it "should accept an id as the first parameter" do
209
+ @fs_com_mock.should_receive(:get).with("/familytree/v2/match/KWQS-BBQ")
210
+ @ft_v2_com.match 'KWQS-BBQ'
211
+ end
212
+
213
+ it "should accept an id AND hash if passed" do
214
+ @fs_com_mock.should_receive(:get).with("/familytree/v2/match/KWQS-BBQ?maxResults=5")
215
+ @ft_v2_com.match 'KWQS-BBQ', :maxResults => 5
216
+ end
217
+
218
+ end
219
+
220
+ describe "reading relationships" do
221
+ before(:each) do
222
+ @fs_com_mock = mock("FsCommunicator")
223
+ @res = mock("HTTP::Response")
224
+ @ft_v2_com = FamilytreeV2::Communicator.new @fs_com_mock
225
+ end
226
+
227
+
228
+ describe "for relationships that already exist" do
128
229
  before(:each) do
129
- @fs_com_mock = mock("FsCommunicator")
130
- @res = mock("HTTP::Response")
131
- @ft_v2_com = FamilytreeV2::Communicator.new @fs_com_mock
230
+ @json = read_file('relationship_read.js')
132
231
 
133
- @json = read_file('../search.js')
134
232
  @res.stub!(:body).and_return(@json)
135
233
  @res.stub!(:code).and_return('200')
136
- @fs_com_mock.stub!(:get).and_return(@res)
137
- end
138
-
139
- it "should call the search endpoint" do
140
- @fs_com_mock.should_receive(:get).with("/familytree/v2/search?name=John")
141
- @ft_v2_com.search :name => "John"
234
+ @fs_com_mock.stub!(:get).and_return(@res)
235
+
142
236
  end
143
237
 
144
- it "should return the SearchResult element" do
145
- search_results = @ft_v2_com.search :name => "John"
146
- search_results.class.should == Org::Familysearch::Ws::Familytree::V2::Schema::SearchResults
147
- search_results.partial.should == 246
148
- search_results.close.should == 100
149
- search_results.count.should == 40
238
+ it "should read the relationship" do
239
+ @fs_com_mock.should_receive(:get).with('/familytree/v2/person/KWQS-BBQ/parent/KWQS-BBR').and_return(@res)
240
+ @ft_v2_com.relationship 'KWQS-BBQ', :parent => 'KWQS-BBR'
150
241
  end
151
242
 
152
- it "should serialize embedded parent parameters" do
153
- @fs_com_mock.should_receive(:get).with("/familytree/v2/search?father.name=John")
154
- @ft_v2_com.search :father => {:name => "John"}
243
+ it "should return a person" do
244
+ @fs_com_mock.should_receive(:get).with('/familytree/v2/person/KWQS-BBQ/parent/KWQS-BBR').and_return(@res)
245
+ person = @ft_v2_com.relationship 'KWQS-BBQ', :parent => 'KWQS-BBR'
246
+ person.id.should == 'KWQS-BBQ'
247
+ person.relationships.parents[0].id.should == 'KWQS-BBR'
155
248
  end
156
249
 
157
250
  end
158
251
 
159
- describe "match" do
160
-
252
+ end
253
+
254
+ describe "writing relationships" do
255
+ before(:each) do
256
+ @fs_com_mock = mock("FsCommunicator")
257
+ @res = mock("HTTP::Response")
258
+ @ft_v2_com = FamilytreeV2::Communicator.new @fs_com_mock
259
+ end
260
+
261
+ describe "for relationships that don't yet exist" do
161
262
  before(:each) do
162
- @fs_com_mock = mock("FsCommunicator")
163
- @res = mock("HTTP::Response")
164
- @ft_v2_com = FamilytreeV2::Communicator.new @fs_com_mock
165
-
166
- @json = read_file('../match_KW3B-NNM.js')
263
+ @json = read_file('relationship_not_found.js')
167
264
  @res.stub!(:body).and_return(@json)
168
- @res.stub!(:code).and_return('200')
265
+ @res.stub!(:code).and_return('404')
169
266
  @fs_com_mock.stub!(:get).and_return(@res)
267
+
268
+ @post_json = read_file('relationship_update.js')
269
+ @post_res = mock("HTTP::Response")
270
+ @post_res.stub!(:body).and_return(@post_json)
271
+ @fs_com_mock.stub!(:post).and_return(@post_res)
272
+
273
+ @person = new_person
274
+ @person2 = new_person
275
+ Org::Familysearch::Ws::Familytree::V2::Schema::Person.stub!(:new).and_return(@person)
276
+
170
277
  end
171
278
 
172
- it "should call the match endpoint" do
173
- @fs_com_mock.should_receive(:get).with("/familytree/v2/match?name=John")
174
- @ft_v2_com.match :name => "John"
279
+ it "should first try to read the relationship" do
280
+ @fs_com_mock.should_receive(:get).with('/familytree/v2/person/KWQS-BBQ/parent/KWQS-BBR').and_return(@res)
281
+ @ft_v2_com.write_relationship 'KWQS-BBQ', :parent => 'KWQS-BBR', :lineage => 'Biological'
175
282
  end
176
283
 
177
- it "should return the MatchResults element" do
178
- search_results = @ft_v2_com.match :name => "John"
179
- search_results.class.should == Org::Familysearch::Ws::Familytree::V2::Schema::MatchResults
180
- search_results.count.should == 4
284
+ it "should create a new person with a relationship since it wasn't yet found" do
285
+ Org::Familysearch::Ws::Familytree::V2::Schema::Person.should_receive(:new).and_return(@person)
286
+ @person.should_receive(:id=).with('KWQS-BBQ')
287
+ @person.should_receive(:create_relationship).with(:type => 'parent', :with => 'KWQS-BBR', :lineage => 'Biological')
288
+ @ft_v2_com.write_relationship 'KWQS-BBQ', :parent => 'KWQS-BBR', :lineage => 'Biological'
181
289
  end
182
290
 
183
- it "should serialize embedded parent parameters" do
184
- @fs_com_mock.should_receive(:get).with("/familytree/v2/match?father.name=John")
185
- @ft_v2_com.match :father => {:name => "John"}
291
+ it "should add a marriage event if sent an event key" do
292
+ Org::Familysearch::Ws::Familytree::V2::Schema::Person.should_receive(:new).and_return(@person)
293
+ @person.should_receive(:id=).with('KWQS-BBQ')
294
+ @person.should_receive(:create_relationship).with(:type => 'spouse', :with => 'KWQS-BBR', :event => {:type => 'Marriage', :place => 'United States', :date => '1800'})
295
+ @ft_v2_com.write_relationship 'KWQS-BBQ', :spouse => 'KWQS-BBR', :event => {:type => 'Marriage', :place => 'United States', :date => '1800'}
186
296
  end
187
297
 
188
- it "should accept an id as the first parameter" do
189
- @fs_com_mock.should_receive(:get).with("/familytree/v2/match/KWQS-BBQ")
190
- @ft_v2_com.match 'KWQS-BBQ'
298
+ it "should add an ordinances if sent an ordinance key" do
299
+ Org::Familysearch::Ws::Familytree::V2::Schema::Person.should_receive(:new).and_return(@person)
300
+ @person.should_receive(:id=).with('KWQS-BBQ')
301
+ @person.should_receive(:create_relationship).with(:type => 'spouse', :with => 'KWQS-BBR', :ordinance => {:type => 'Sealing_to_Spouse', :place => 'United States', :date => '1800', :temple => 'SLAKE'})
302
+ @ft_v2_com.write_relationship 'KWQS-BBQ', :spouse => 'KWQS-BBR', :ordinance => {:type => 'Sealing_to_Spouse', :place => 'United States', :date => '1800', :temple => 'SLAKE'}
191
303
  end
192
304
 
193
- it "should accept an id AND hash if passed" do
194
- @fs_com_mock.should_receive(:get).with("/familytree/v2/match/KWQS-BBQ?maxResults=5")
195
- @ft_v2_com.match 'KWQS-BBQ', :maxResults => 5
305
+ it "should post a familytree request with the person to the correct endpoint" do
306
+ @person2.create_relationship(:type => 'parent', :with => 'KWQS-BBR', :lineage => 'Biological')
307
+ @person2.id = 'KWQS-BBQ'
308
+ familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.new
309
+
310
+ familytree.persons = [@person2]
311
+ @fs_com_mock.should_receive(:post).with('/familytree/v2/person/KWQS-BBQ/parent/KWQS-BBR', familytree.to_json).and_return(@post_res)
312
+ @ft_v2_com.write_relationship 'KWQS-BBQ', :parent => 'KWQS-BBR', :lineage => 'Biological'
196
313
  end
197
314
 
198
315
  end
199
316
 
200
- describe "reading relationships" do
201
-
202
- describe "for relationships that already exist" do
203
- before(:each) do
204
- @json = read_file('relationship_read.js')
205
-
206
- @res.stub!(:body).and_return(@json)
207
- @res.stub!(:code).and_return('200')
208
- @fs_com_mock.stub!(:get).and_return(@res)
209
-
210
- end
317
+ describe "for relationships that already exist" do
318
+ before(:each) do
319
+ @json = read_file('relationship_read.js')
211
320
 
212
- it "should read the relationship" do
213
- @fs_com_mock.should_receive(:get).with('/familytree/v2/person/KWQS-BBQ/parent/KWQS-BBR').and_return(@res)
214
- @ft_v2_com.relationship 'KWQS-BBQ', :parent => 'KWQS-BBR'
215
- end
321
+ @res.stub!(:body).and_return(@json)
322
+ @res.stub!(:code).and_return('200')
323
+ @fs_com_mock.stub!(:get).and_return(@res)
324
+
325
+ @post_json = read_file('relationship_update.js')
326
+ @post_res = mock("HTTP::Response")
327
+ @post_res.stub!(:body).and_return(@post_json)
328
+ @fs_com_mock.stub!(:post).and_return(@post_res)
216
329
 
217
- it "should return a person" do
218
- @fs_com_mock.should_receive(:get).with('/familytree/v2/person/KWQS-BBQ/parent/KWQS-BBR').and_return(@res)
219
- person = @ft_v2_com.relationship 'KWQS-BBQ', :parent => 'KWQS-BBR'
220
- person.id.should == 'KWQS-BBQ'
221
- person.relationships.parents[0].id.should == 'KWQS-BBR'
222
- end
330
+ # Create a payload to compare against
331
+ ft = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.from_json JSON.parse(@json)
332
+ person = ft.persons.find{|p|p.id=='KWQS-BBQ'}
333
+ person.create_relationship :type => 'parent', :with => 'KWQS-BBR', :lineage => 'Biological'
334
+ familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.new
335
+ familytree.persons = [person]
336
+ @req_payload = familytree.to_json
337
+
338
+ @familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.from_json JSON.parse(@json)
339
+ Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.stub!(:from_json).and_return(@familytree)
223
340
 
341
+ @person = @familytree.persons.find{|p|p.id=='KWQS-BBQ'}
224
342
  end
225
343
 
226
- end
227
-
228
- describe "writing relationships" do
229
- before(:each) do
230
- @fs_com_mock = mock("FsCommunicator")
231
- @res = mock("HTTP::Response")
232
- @ft_v2_com = FamilytreeV2::Communicator.new @fs_com_mock
344
+ it "should first try to read the relationship" do
345
+ @fs_com_mock.should_receive(:get).with('/familytree/v2/person/KWQS-BBQ/parent/KWQS-BBR').and_return(@res)
346
+ @ft_v2_com.write_relationship 'KWQS-BBQ', :parent => 'KWQS-BBR', :lineage => 'Biological'
233
347
  end
234
348
 
235
- describe "for relationships that don't yet exist" do
236
- before(:each) do
237
- @json = read_file('relationship_not_found.js')
238
- @res.stub!(:body).and_return(@json)
239
- @res.stub!(:code).and_return('404')
240
- @fs_com_mock.stub!(:get).and_return(@res)
241
-
242
- @post_json = read_file('relationship_update.js')
243
- @post_res = mock("HTTP::Response")
244
- @post_res.stub!(:body).and_return(@post_json)
245
- @fs_com_mock.stub!(:post).and_return(@post_res)
246
-
247
- @person = new_person
248
- @person2 = new_person
249
- Org::Familysearch::Ws::Familytree::V2::Schema::Person.stub!(:new).and_return(@person)
250
-
251
- end
252
-
253
- it "should first try to read the relationship" do
254
- @fs_com_mock.should_receive(:get).with('/familytree/v2/person/KWQS-BBQ/parent/KWQS-BBR').and_return(@res)
255
- @ft_v2_com.write_relationship 'KWQS-BBQ', :parent => 'KWQS-BBR', :lineage => 'Biological'
256
- end
257
-
258
- it "should create a new person with a relationship since it wasn't yet found" do
259
- Org::Familysearch::Ws::Familytree::V2::Schema::Person.should_receive(:new).and_return(@person)
260
- @person.should_receive(:id=).with('KWQS-BBQ')
261
- @person.should_receive(:create_relationship).with(:type => 'parent', :with => 'KWQS-BBR', :lineage => 'Biological')
262
- @ft_v2_com.write_relationship 'KWQS-BBQ', :parent => 'KWQS-BBR', :lineage => 'Biological'
263
- end
264
-
265
- it "should add a marriage event if sent an event key" do
266
- Org::Familysearch::Ws::Familytree::V2::Schema::Person.should_receive(:new).and_return(@person)
267
- @person.should_receive(:id=).with('KWQS-BBQ')
268
- @person.should_receive(:create_relationship).with(:type => 'spouse', :with => 'KWQS-BBR', :event => {:type => 'Marriage', :place => 'United States', :date => '1800'})
269
- @ft_v2_com.write_relationship 'KWQS-BBQ', :spouse => 'KWQS-BBR', :event => {:type => 'Marriage', :place => 'United States', :date => '1800'}
270
- end
271
-
272
- it "should add an ordinances if sent an ordinance key" do
273
- Org::Familysearch::Ws::Familytree::V2::Schema::Person.should_receive(:new).and_return(@person)
274
- @person.should_receive(:id=).with('KWQS-BBQ')
275
- @person.should_receive(:create_relationship).with(:type => 'spouse', :with => 'KWQS-BBR', :ordinance => {:type => 'Sealing_to_Spouse', :place => 'United States', :date => '1800', :temple => 'SLAKE'})
276
- @ft_v2_com.write_relationship 'KWQS-BBQ', :spouse => 'KWQS-BBR', :ordinance => {:type => 'Sealing_to_Spouse', :place => 'United States', :date => '1800', :temple => 'SLAKE'}
277
- end
278
-
279
- it "should post a familytree request with the person to the correct endpoint" do
280
- @person2.create_relationship(:type => 'parent', :with => 'KWQS-BBR', :lineage => 'Biological')
281
- @person2.id = 'KWQS-BBQ'
282
- familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.new
283
-
284
- familytree.persons = [@person2]
285
- @fs_com_mock.should_receive(:post).with('/familytree/v2/person/KWQS-BBQ/parent/KWQS-BBR', familytree.to_json).and_return(@post_res)
286
- @ft_v2_com.write_relationship 'KWQS-BBQ', :parent => 'KWQS-BBR', :lineage => 'Biological'
287
- end
288
-
349
+ it "should create a new person with a relationship since it wasn't yet found" do
350
+ @person.should_not_receive(:id=).with('KWQS-BBQ')
351
+ @person.should_receive(:create_relationship).with(:type => 'parent', :with => 'KWQS-BBR', :lineage => 'Biological')
352
+ @ft_v2_com.write_relationship 'KWQS-BBQ', :parent => 'KWQS-BBR', :lineage => 'Biological'
289
353
  end
290
354
 
291
- describe "for relationships that already exist" do
292
- before(:each) do
293
- @json = read_file('relationship_read.js')
294
-
295
- @res.stub!(:body).and_return(@json)
296
- @res.stub!(:code).and_return('200')
297
- @fs_com_mock.stub!(:get).and_return(@res)
298
-
299
- @post_json = read_file('relationship_update.js')
300
- @post_res = mock("HTTP::Response")
301
- @post_res.stub!(:body).and_return(@post_json)
302
- @fs_com_mock.stub!(:post).and_return(@post_res)
303
-
304
- # Create a payload to compare against
305
- ft = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.from_json JSON.parse(@json)
306
- person = ft.persons.find{|p|p.id=='KWQS-BBQ'}
307
- person.create_relationship :type => 'parent', :with => 'KWQS-BBR', :lineage => 'Biological'
308
- familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.new
309
- familytree.persons = [person]
310
- @req_payload = familytree.to_json
311
-
312
- @familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.from_json JSON.parse(@json)
313
- Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.stub!(:from_json).and_return(@familytree)
314
-
315
- @person = @familytree.persons.find{|p|p.id=='KWQS-BBQ'}
316
- end
317
-
318
- it "should first try to read the relationship" do
319
- @fs_com_mock.should_receive(:get).with('/familytree/v2/person/KWQS-BBQ/parent/KWQS-BBR').and_return(@res)
320
- @ft_v2_com.write_relationship 'KWQS-BBQ', :parent => 'KWQS-BBR', :lineage => 'Biological'
321
- end
322
-
323
- it "should create a new person with a relationship since it wasn't yet found" do
324
- @person.should_not_receive(:id=).with('KWQS-BBQ')
325
- @person.should_receive(:create_relationship).with(:type => 'parent', :with => 'KWQS-BBR', :lineage => 'Biological')
326
- @ft_v2_com.write_relationship 'KWQS-BBQ', :parent => 'KWQS-BBR', :lineage => 'Biological'
327
- end
328
-
329
- it "should add a marriage event if sent an event key" do
330
- @person.should_receive(:create_relationship).with(:type => 'spouse', :with => 'KWQS-BBR', :event => {:type => 'Marriage', :place => 'United States', :date => '1800'})
331
- @ft_v2_com.write_relationship 'KWQS-BBQ', :spouse => 'KWQS-BBR', :event => {:type => 'Marriage', :place => 'United States', :date => '1800'}
332
- end
333
-
334
- it "should add an ordinances if sent an ordinance key" do
335
- @person.should_receive(:create_relationship).with(:type => 'spouse', :with => 'KWQS-BBR', :ordinance => {:type => 'Sealing_to_Spouse', :place => 'United States', :date => '1800', :temple => 'SLAKE'})
336
- @ft_v2_com.write_relationship 'KWQS-BBQ', :spouse => 'KWQS-BBR', :ordinance => {:type => 'Sealing_to_Spouse', :place => 'United States', :date => '1800', :temple => 'SLAKE'}
337
- end
338
-
339
- it "should post a familytree request with the person to the correct endpoint" do
340
-
341
- @fs_com_mock.should_receive(:post).with('/familytree/v2/person/KWQS-BBQ/parent/KWQS-BBR', @req_payload).and_return(@post_res)
342
- @ft_v2_com.write_relationship 'KWQS-BBQ', :parent => 'KWQS-BBR', :lineage => 'Biological'
343
- end
355
+ it "should add a marriage event if sent an event key" do
356
+ @person.should_receive(:create_relationship).with(:type => 'spouse', :with => 'KWQS-BBR', :event => {:type => 'Marriage', :place => 'United States', :date => '1800'})
357
+ @ft_v2_com.write_relationship 'KWQS-BBQ', :spouse => 'KWQS-BBR', :event => {:type => 'Marriage', :place => 'United States', :date => '1800'}
358
+ end
359
+
360
+ it "should add an ordinances if sent an ordinance key" do
361
+ @person.should_receive(:create_relationship).with(:type => 'spouse', :with => 'KWQS-BBR', :ordinance => {:type => 'Sealing_to_Spouse', :place => 'United States', :date => '1800', :temple => 'SLAKE'})
362
+ @ft_v2_com.write_relationship 'KWQS-BBQ', :spouse => 'KWQS-BBR', :ordinance => {:type => 'Sealing_to_Spouse', :place => 'United States', :date => '1800', :temple => 'SLAKE'}
363
+ end
364
+
365
+ it "should post a familytree request with the person to the correct endpoint" do
344
366
 
367
+ @fs_com_mock.should_receive(:post).with('/familytree/v2/person/KWQS-BBQ/parent/KWQS-BBR', @req_payload).and_return(@post_res)
368
+ @ft_v2_com.write_relationship 'KWQS-BBQ', :parent => 'KWQS-BBR', :lineage => 'Biological'
345
369
  end
370
+
371
+ end
372
+ end
373
+
374
+ describe "combining persons" do
375
+ def new_person(id,version)
376
+ p = FamilyTreeV2::Person.new
377
+ p.id = id
378
+ p.version = version
379
+ p
380
+ end
381
+
382
+ before(:each) do
383
+ @fs_com_mock = mock("FsCommunicator")
384
+ @post_res = mock("HTTP::Response")
385
+ @post_res.stub!(:body).and_return(read_file('../combine_response.js'))
386
+
387
+ @ft_v2_com = FamilytreeV2::Communicator.new @fs_com_mock
388
+
389
+ @persons = [new_person('KWQS-BBQ','1'),new_person('KWQS-BBR','2'),new_person('KWQS-BBB','3')]
390
+ @ft_v2_com.stub!(:person).and_return(@persons)
391
+ @fs_com_mock.stub!(:post).and_return(@post_res)
392
+ end
393
+
394
+ it "should accept an array of IDs and return the response person" do
395
+ new_person = @ft_v2_com.combine ['KWQS-BBQ','KWQS-BBR','KWQS-BBB']
396
+ new_person.should be_instance_of(FamilyTreeV2::Person)
397
+ end
398
+
399
+ it "should perform a person (version) read on all of the IDs passed" do
400
+ @ft_v2_com.should_receive(:person).with(['KWQS-BBQ','KWQS-BBR','KWQS-BBB'],{:genders => 'none', :events => 'none', :names => 'none'}).and_return(@persons)
401
+ result = @ft_v2_com.combine ['KWQS-BBQ','KWQS-BBR','KWQS-BBB']
402
+ end
403
+
404
+ it "should call post on /familytree/v2/person" do
405
+ familytree = FamilyTreeV2::FamilyTree.new
406
+ FamilyTreeV2::FamilyTree.should_receive(:new).and_return(familytree,familytree)
407
+ familytree.should_receive(:to_json).and_return('ftjson')
408
+ @fs_com_mock.should_receive(:post).with('/familytree/v2/person','ftjson').and_return(@post_res)
409
+ result = @ft_v2_com.combine ['KWQS-BBQ','KWQS-BBR','KWQS-BBB']
346
410
  end
347
411
 
412
+ it "should result in a new person record with an id and version" do
413
+ result = @ft_v2_com.combine ['KWQS-BBQ','KWQS-BBR','KWQS-BBB']
414
+ result.id.should == "KW3B-VZC"
415
+ result.version.should == "65537"
416
+ end
348
417
  end
349
418
 
350
419
  end
@@ -0,0 +1 @@
1
+ {"persons":[{"personas":{"persona":[{"id":"KW3B-VCY","version":"65537"},{"id":"KW3B-VCB","version":"65537"},{"id":"KW3B-VC1","version":"65537"}]}}]}
@@ -0,0 +1 @@
1
+ {"persons":[{"id":"KW3B-VZC","version":"65537"}],"version":"2.0.20091103.5176","statusCode":200,"statusMessage":"OK"}
@@ -0,0 +1 @@
1
+ {"persons":[{"id":"KW3B-VCY","version":"65537","requestedId":"KW3B-VCY"},{"id":"KW3B-VCB","version":"65537","requestedId":"KW3B-VCB"},{"id":"KW3B-VC1","version":"65537","requestedId":"KW3B-VC1"}],"version":"2.0.20091103.5176","statusCode":200,"statusMessage":"OK"}
@@ -576,4 +576,29 @@ describe Org::Familysearch::Ws::Familytree::V2::Schema::Person do
576
576
 
577
577
  end
578
578
 
579
+ describe "create_combine" do
580
+ def new_combine_person(id,version)
581
+ person = new_person
582
+ person.id = id
583
+ person.version = version
584
+ person
585
+ end
586
+
587
+ before(:each) do
588
+ @person = new_person
589
+ @persons = [new_combine_person('KWQS-BBR','1'),new_combine_person('KWQS-BBQ','2'),new_combine_person('KWQS-BBZ','3')]
590
+ end
591
+
592
+ it "should accept an array of person objects" do
593
+ @person.create_combine(@persons)
594
+ @person.personas.personas[0].id.should == 'KWQS-BBR'
595
+ @person.personas.personas[0].version.should == '1'
596
+ @person.personas.personas[1].id.should == 'KWQS-BBQ'
597
+ @person.personas.personas[1].version.should == '2'
598
+ @person.personas.personas[2].id.should == 'KWQS-BBZ'
599
+ @person.personas.personas[2].version.should == '3'
600
+ end
601
+
602
+ end
603
+
579
604
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-fs-stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Zimmerman
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-10 00:00:00 -07:00
12
+ date: 2009-12-14 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -64,9 +64,12 @@ files:
64
64
  - ruby-fs-stack.gemspec
65
65
  - spec/communicator_spec.rb
66
66
  - spec/familytree_v2/familytree_communicator_spec.rb
67
+ - spec/familytree_v2/json/combine_request.js
68
+ - spec/familytree_v2/json/combine_response.js
67
69
  - spec/familytree_v2/json/match_KW3B-NNM.js
68
70
  - spec/familytree_v2/json/person/KJ86-3VD_all.js
69
71
  - spec/familytree_v2/json/person/KJ86-3VD_version.js
72
+ - spec/familytree_v2/json/person/multiple_version_read.js
70
73
  - spec/familytree_v2/json/person/post_response.js
71
74
  - spec/familytree_v2/json/person/relationship_not_found.js
72
75
  - spec/familytree_v2/json/person/relationship_read.js