dm-persevere-adapter 0.50.0 → 0.51.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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.50.0
1
+ 0.51.0
@@ -194,7 +194,7 @@ module DataMapper
194
194
  RESERVED_CLASSNAMES = ['User','Transaction','Capability','File','Class', 'Object', 'Versioned']
195
195
 
196
196
  include Migrations::PersevereAdapter
197
-
197
+
198
198
  # Default types for all data object based adapters.
199
199
  #
200
200
  # @return [Hash] default types for data objects adapters.
@@ -225,6 +225,9 @@ module DataMapper
225
225
  end
226
226
  end
227
227
 
228
+ # This should go away when we have more methods exposed to retrieve versioned data (and schemas)
229
+ attr_accessor :persevere
230
+
228
231
  ##
229
232
  # Used by DataMapper to put records into a data-store: "INSERT"
230
233
  # in SQL-speak. It takes an array of the resources (model
@@ -598,36 +601,54 @@ module DataMapper
598
601
  # If the user specified a versioned datastore load the versioning REST code
599
602
  #
600
603
  if ! @classes.include?("Versioned") && @options[:versioned]
601
- json_contents = <<-EOF
604
+ versioned_class = <<-EOF
602
605
  {
603
- id:"Versioned",
604
- prototype: {
605
- getVersionMethod: function() {
606
- return java.lang.Class.forName("org.persvr.data.Persistable").getMethod("getVersion");
607
- },
608
- isCurrentVersion: function() { return this.getVersionMethod.invoke(this).isCurrent(); },
609
- getVersion: function() { return this.getVersionMethod.invoke(this).getVersionNumber(); },
610
- getPreviousVersion: function() {
611
- var prev = getVersionMethod.invoke(this).getPreviousVersion();
612
- return prev;
613
- },
614
- "representation:application/json+versioned": {
615
- quality:0.2,
616
- output:function(object) {
617
- var prev = object.getPreviousVersion();
618
- response.setContentType("application/json+versioned");
619
- response.getOutputStream().print(serialize({
620
- version: object.getVersion(),
621
- "parent-versions": prev ? [prev] : [],
622
- content: object
623
- }));
624
- }
606
+ id: "Versioned",
607
+ prototype: {
608
+ getVersionMethod: function() {
609
+ return java.lang.Class.forName("org.persvr.data.Persistable").getMethod("getVersion");
610
+ },
611
+ isCurrentVersion: function() {
612
+ return this.getVersionMethod().invoke(this).isCurrent();
613
+ },
614
+ getVersionNumber: function() {
615
+ return this.getVersionMethod().invoke(this).getVersionNumber();
616
+ },
617
+ getPrevious: function() {
618
+ var prev = this.getVersionMethod().invoke(this).getPreviousVersion();
619
+ return prev;
620
+ },
621
+ getAllPrevious: function() {
622
+
623
+ var current = this;
624
+ var prev = current && current.getPrevious();
625
+
626
+ var versions = []
627
+ while(current && prev) {
628
+ versions.push(prev);
629
+ current = prev;
630
+ prev = current.getPrevious();
631
+ }
632
+
633
+ return versions;
634
+ },
635
+ "representation:application/json+versioned": {
636
+ quality: 0.2,
637
+ output: function(object) {
638
+ var previous = object.getAllPrevious();
639
+ response.setContentType("application/json+versioned");
640
+ response.getOutputStream().print(JSON.stringify({
641
+ version: object.getVersionNumber(),
642
+ current: object,
643
+ versions: previous
644
+ }));
645
+ }
646
+ }
625
647
  }
626
- }
627
648
  }
628
649
  EOF
629
650
  begin
630
- response = @persevere.persevere.send_request('POST', URI.encode('/Class/'), json_contents, { 'Content-Type' => 'application/javascript' } )
651
+ response = @persevere.persevere.send_request('POST', URI.encode('/Class/'), versioned_class, { 'Content-Type' => 'application/javascript' } )
631
652
  rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
632
653
  Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
633
654
  puts "Persevere Create Failed: #{e}, Trying again."
@@ -116,7 +116,6 @@ describe DataMapper::Adapters::PersevereAdapter do
116
116
  it 'should create the schema as an extension of the Versioned schema' do
117
117
  @adapter.put_schema(@test_schema_hash).should_not == false
118
118
  test_result = @adapter.get_schema(@test_schema_hash['id'])
119
- puts test_result.inspect
120
119
  test_result[0]['extends']['$ref'].should eql "Versioned"
121
120
  end
122
121
 
@@ -191,8 +190,11 @@ describe DataMapper::Adapters::PersevereAdapter do
191
190
  @dragons = Dragon.all
192
191
  @countries = Country.all
193
192
  end
193
+
194
194
  it_should_behave_like 'An Aggregatable Class'
195
195
 
196
+ it "should be able to get a count of objects within a range of dates"
197
+
196
198
  it "should count with like conditions" do
197
199
  Country.count(:name.like => '%n%').should == 4
198
200
  end
@@ -241,6 +243,56 @@ describe DataMapper::Adapters::PersevereAdapter do
241
243
  end
242
244
  end
243
245
 
246
+ # From Ryan's Gist:
247
+ # s = Patron::Session.new
248
+ # s.base_url = "http://localhost:8080"
249
+ # s.headers['Content-Type'] = "application/json"
250
+ # resp = []
251
+ # resp << s.put("/Versioned/1", %{{"id":1, "name":"first version"}})
252
+ # resp << s.put("/Versioned/1", %{{"id":1, "name":"second version"}})
253
+ # resp << s.put("/Versioned/1", %{{"id":1, "name":"third version"}})
254
+ # resp << s.get("/Versioned/1")
255
+ # resp << s.get("/Versioned/1", {"Accept" => "application/json+versioned"})
256
+ #
257
+ # resp.each do |r|
258
+ # puts r.status
259
+ # puts r.headers['Content-Type']
260
+ # puts r.body
261
+ # puts
262
+ # end
263
+
264
+ describe 'when using versioned data' do
265
+ before(:each) do
266
+ Nugaton.auto_migrate!
267
+ end
268
+
269
+ it "should store all the versions of the data element" do
270
+ version = 1
271
+
272
+ # Create the first version
273
+ nugat = Nugaton.create(:name => "version #{version}")
274
+
275
+ # Create a second version
276
+ nugat.name = "version #{version += 1}"
277
+ nugat.save
278
+
279
+ # Create a third version
280
+
281
+ nugat.name = "version #{version += 1}"
282
+ nugat.save
283
+
284
+ # Retrieve all versions and see if there are three
285
+ raw_result = @adapter.persevere.retrieve("/nugaton/1", { "Accept" => "application/json+versioned" })
286
+ results = JSON.parse( raw_result.body )
287
+ results['current']['name'].should eql "version #{version}"
288
+ results['versions'].length.should eql 2
289
+ end
290
+
291
+ after(:each) do
292
+ Nugaton.auto_migrate_down!
293
+ end
294
+ end
295
+
244
296
  describe 'when finding models,' do
245
297
  before(:each) do
246
298
  Bozon.auto_migrate!
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 50
7
+ - 51
8
8
  - 0
9
- version: 0.50.0
9
+ version: 0.51.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ivan R. Judson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-04-22 00:00:00 -06:00
18
+ date: 2010-04-23 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency