diametric 0.0.4 → 0.1.1

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.
Files changed (67) hide show
  1. checksums.yaml +15 -0
  2. data/Gemfile +21 -18
  3. data/Jarfile +15 -1
  4. data/README.md +22 -14
  5. data/Rakefile +17 -1
  6. data/bin/datomic-rest +33 -0
  7. data/bin/download-datomic +13 -0
  8. data/datomic_version.yml +4 -0
  9. data/diametric.gemspec +9 -6
  10. data/ext/diametric/DiametricCollection.java +147 -0
  11. data/ext/diametric/DiametricConnection.java +113 -0
  12. data/ext/diametric/DiametricDatabase.java +107 -0
  13. data/ext/diametric/DiametricEntity.java +90 -0
  14. data/ext/diametric/DiametricListenableFuture.java +47 -0
  15. data/ext/diametric/DiametricObject.java +66 -0
  16. data/ext/diametric/DiametricPeer.java +414 -0
  17. data/ext/diametric/DiametricService.java +102 -0
  18. data/ext/diametric/DiametricUUID.java +61 -0
  19. data/ext/diametric/DiametricUtils.java +183 -0
  20. data/lib/boolean_type.rb +3 -0
  21. data/lib/diametric.rb +24 -0
  22. data/lib/diametric/entity.rb +219 -14
  23. data/lib/diametric/generators/active_model.rb +2 -2
  24. data/lib/diametric/persistence.rb +0 -1
  25. data/lib/diametric/persistence/common.rb +28 -9
  26. data/lib/diametric/persistence/peer.rb +122 -87
  27. data/lib/diametric/persistence/rest.rb +4 -3
  28. data/lib/diametric/query.rb +94 -23
  29. data/lib/diametric/rest_service.rb +74 -0
  30. data/lib/diametric/service_base.rb +77 -0
  31. data/lib/diametric/transactor.rb +86 -0
  32. data/lib/diametric/version.rb +1 -1
  33. data/lib/diametric_service.jar +0 -0
  34. data/lib/value_enums.rb +8 -0
  35. data/spec/conf_helper.rb +55 -0
  36. data/spec/config/free-transactor-template.properties +73 -0
  37. data/spec/config/logback.xml +59 -0
  38. data/spec/data/seattle-data0.dtm +452 -0
  39. data/spec/data/seattle-data1.dtm +326 -0
  40. data/spec/developer_create_sample.rb +39 -0
  41. data/spec/developer_query_spec.rb +120 -0
  42. data/spec/diametric/config_spec.rb +1 -1
  43. data/spec/diametric/entity_spec.rb +263 -0
  44. data/spec/diametric/peer_api_spec.rb +147 -0
  45. data/spec/diametric/persistence/peer_many2many_spec.rb +76 -0
  46. data/spec/diametric/persistence/peer_spec.rb +13 -22
  47. data/spec/diametric/persistence/rest_spec.rb +12 -19
  48. data/spec/diametric/query_spec.rb +4 -5
  49. data/spec/diametric/rest_service_spec.rb +56 -0
  50. data/spec/diametric/transactor_spec.rb +68 -0
  51. data/spec/integration_spec.rb +5 -3
  52. data/spec/parent_child_sample.rb +42 -0
  53. data/spec/peer_integration_spec.rb +106 -22
  54. data/spec/peer_seattle_spec.rb +200 -0
  55. data/spec/rc2013_seattle_big.rb +82 -0
  56. data/spec/rc2013_seattle_small.rb +60 -0
  57. data/spec/rc2013_simple_sample.rb +72 -0
  58. data/spec/seattle_integration_spec.rb +106 -0
  59. data/spec/simple_validation_sample.rb +31 -0
  60. data/spec/spec_helper.rb +31 -45
  61. data/spec/support/entities.rb +157 -0
  62. data/spec/support/gen_entity_class.rb +2 -0
  63. data/spec/support/persistence_examples.rb +9 -5
  64. data/spec/test_version_file.yml +4 -0
  65. metadata +131 -75
  66. data/Jarfile.lock +0 -134
  67. data/lib/jrclj.rb +0 -63
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+ require 'diametric/persistence/peer'
3
+ require 'securerandom'
4
+
5
+ describe Diametric::Persistence::Peer, :jruby do
6
+ before do
7
+ db_uri = "datomic:mem://hello-#{SecureRandom.uuid}"
8
+ @conn = subject.connect(:uri => db_uri)
9
+ Author.create_schema(@conn)
10
+ Book.create_schema(@conn)
11
+ end
12
+ after do
13
+ @conn.release
14
+ end
15
+
16
+ it "should save one in caridinality many associations" do
17
+ author = Author.new(:name => "wilber", :books => [])
18
+ author.save
19
+ book = Book.new(:title => "Candy", :authors => [])
20
+ book.save
21
+ author.update(:books => [book])
22
+ result = Diametric::Persistence::Peer.q("[:find ?e ?name ?books :in $ :where [?e :author/name ?name] [?e :author/books ?books]]", @conn.db)
23
+ boo_dbid = result.first[2]
24
+ boo = Author.from_dbid_or_entity(boo_dbid, @conn)
25
+ boo.title.should == "Candy"
26
+ end
27
+
28
+ it "should save two in caridinality many associations" do
29
+ author = Author.new(:name => "wilber", :books => [])
30
+ author.save
31
+ book1 = Book.new(:title => "Honey", :authors => [])
32
+ book1.save
33
+ book2 = Book.new(:title => "Chips", :authors => [])
34
+ book2.save
35
+ author.update(:books => [book1, book2])
36
+ result = Diametric::Persistence::Peer.q("[:find ?e ?name ?books :in $ :where [?e :author/name ?name] [?e :author/books ?books]]", @conn.db)
37
+ result.size.should == 2
38
+ boo_dbid = result[0][2]
39
+ boo = Book.from_dbid_or_entity(boo_dbid, @conn)
40
+ boo.title.should match(/Honey|Chips/)
41
+ foo_dbid = result[1][2]
42
+ foo = Book.from_dbid_or_entity(boo_dbid, @conn)
43
+ foo.title.should match(/Honey|Chips/)
44
+ end
45
+
46
+ it "should save two in caridinality many associations" do
47
+ author1 = Author.new(:name => "Ms. Wilber", :books => [])
48
+ author1.save
49
+ author2 = Author.new(:name => "Mr. Smith", :books => [])
50
+ author2.save
51
+ book1 = Book.new(:title => "Pie", :authors => [])
52
+ book1.save
53
+ book2 = Book.new(:title => "Donuts", :authors => [])
54
+ book2.save
55
+ author1.update(:books => [book1, book2])
56
+ book1.update(:authors => [author1, author2])
57
+
58
+ result = Diametric::Persistence::Peer.q("[:find ?e :in $ [?name] :where [?e :author/name ?name]]", @conn.db, ["Ms. Wilber"])
59
+ result.size.should == 1
60
+ result.first.first.to_s.should == author1.dbid.to_s
61
+ a = Author.from_dbid_or_entity(result.first.first, @conn)
62
+ a.books.size.should == 2
63
+ a.books.each do |b|
64
+ Author.from_dbid_or_entity(b, @conn).title.should match(/Pie|Donuts/)
65
+ end
66
+
67
+ result = Diametric::Persistence::Peer.q("[:find ?e :in $ [?title] :where [?e :book/title ?title]]", @conn.db, ["Pie"])
68
+ result.size.should == 1
69
+ result.first.first.to_s.should == book1.dbid.to_s
70
+ b = Book.from_dbid_or_entity(result.first.first, @conn)
71
+ b.authors.size.should == 2
72
+ b.authors.each do |a|
73
+ Book.from_dbid_or_entity(a, @conn).name.should match(/Ms\.\sWilber|Mr\.\sSmith/)
74
+ end
75
+ end
76
+ end
@@ -1,36 +1,27 @@
1
1
  require 'spec_helper'
2
- require 'diametric/persistence/peer' if RUBY_ENGINE == 'jruby'
3
-
4
- # Prevent CRuby from blowing up
5
- module Diametric
6
- module Persistence
7
- module Peer
8
- end
9
- end
10
- end
2
+ require 'diametric/persistence/peer'
3
+ require 'securerandom'
11
4
 
12
5
  describe Diametric::Persistence::Peer, :jruby do
13
- class Rat
14
- include Diametric::Entity
15
- include Diametric::Persistence::Peer
16
-
17
- attribute :name, String, :index => true
18
- attribute :age, Integer
6
+ before do
7
+ @db_uri = "datomic:mem://hello-#{SecureRandom.uuid}"
19
8
  end
20
9
 
21
- let(:db_uri) { 'datomic:mem://hello' }
22
-
23
10
  it "can connect to a Datomic database" do
24
- subject.connect(:uri => db_uri)
25
- subject.connection.should be_a(Java::DatomicPeer::LocalConnection)
11
+ connection = subject.connect(:uri => @db_uri)
12
+ connection.should be_a(Diametric::Persistence::Connection)
26
13
  end
27
14
 
28
15
  it_behaves_like "persistence API" do
29
16
  let(:model_class) { Rat }
30
17
 
31
- before(:all) do
32
- subject.connect(:uri => db_uri)
33
- Diametric::Persistence::Peer.create_schemas
18
+ before do
19
+ @connection = Diametric::Persistence::Peer.connect(:uri => @db_uri)
20
+ Diametric::Persistence::Peer.create_schemas(@connection)
21
+ end
22
+
23
+ after do
24
+ @connection.release
34
25
  end
35
26
  end
36
27
  end
@@ -1,36 +1,29 @@
1
1
  require 'spec_helper'
2
2
  require 'diametric/persistence/rest'
3
+ require 'securerandom'
3
4
 
4
5
  describe Diametric::Persistence::REST, :integration do
5
- class Mouse
6
- include Diametric::Entity
7
- include Diametric::Persistence::REST
8
-
9
- attribute :name, String, :index => true
10
- attribute :age, Integer
11
- end
12
-
13
- let(:connection_options) do
14
- {
15
- :uri => db_uri,
16
- :storage => storage,
17
- :database => dbname
6
+ before do
7
+ @db_uri = ENV['DATOMIC_URI'] || 'http://localhost:46291'
8
+ @storage = ENV['DATOMIC_STORAGE'] || 'free'
9
+ @dbname = ENV['DATOMIC_NAME'] || "test-#{SecureRandom.uuid}"
10
+ @connection_options = {
11
+ :uri => @db_uri,
12
+ :storage => @storage,
13
+ :database => @dbname
18
14
  }
19
15
  end
20
- let(:db_uri) { ENV['DATOMIC_URI'] || 'http://localhost:9000' }
21
- let(:storage) { ENV['DATOMIC_STORAGE'] || 'free' }
22
- let(:dbname) { ENV['DATOMIC_NAME'] || "test-#{Time.now.to_i}" }
23
16
 
24
17
  it "can connect to a Datomic database" do
25
- subject.connect(connection_options)
18
+ subject.connect(@connection_options)
26
19
  subject.connection.should be_a(Datomic::Client)
27
20
  end
28
21
 
29
22
  it_behaves_like "persistence API" do
30
23
  let(:model_class) { Mouse }
31
24
 
32
- before(:all) do
33
- subject.connect(connection_options)
25
+ before do
26
+ Diametric::Persistence::REST.connect(@connection_options)
34
27
  Diametric::Persistence::REST.create_schemas
35
28
  end
36
29
  end
@@ -26,9 +26,8 @@ describe Diametric::Query do
26
26
  attribute :likes, String, :cardinality => :many
27
27
  end
28
28
  model.stub(:q => [[1, "Stu", "chocolate"], [1, "Stu", "vanilla"]])
29
-
30
- model.should_receive(:from_query).with([1, "Stu", ["chocolate", "vanilla"]])
31
- Diametric::Query.new(model).each {|x| x}
29
+ model.should_receive(:from_query).with([1, "Stu", ["chocolate", "vanilla"]], nil, true)
30
+ Diametric::Query.new(model, nil, true).each {|x| x}
32
31
  end
33
32
  end
34
33
 
@@ -39,7 +38,7 @@ describe Diametric::Query do
39
38
  attribute :likes, String, :cardinality => :many
40
39
  end
41
40
  end
42
- let(:query) { Diametric::Query.new(model) }
41
+ let(:query) { Diametric::Query.new(model, nil, true) }
43
42
 
44
43
  context "with multiple results per entity" do
45
44
  it "collapses cardinality/many attributes into lists" do
@@ -65,7 +64,7 @@ describe Diametric::Query do
65
64
  attribute :likes, String, :cardinality => :many
66
65
  end
67
66
  model.stub(:q => [[1, "Stu", "chocolate"], [1, "Stu", "vanilla"]])
68
- Diametric::Query.new(model).all.each do |e|
67
+ Diametric::Query.new(model, nil, true).all.each do |e|
69
68
  e.name.should == "Stu"
70
69
  e.likes.class.should == Set
71
70
  e.likes.should include "chocolate"
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+ require 'net/http'
3
+
4
+ describe Diametric::RestService, :service =>true do
5
+ let(:service) { Diametric::RestService }
6
+
7
+ before do
8
+ dir = File.join(File.dirname(__FILE__), "../..", "tmp/datomic")
9
+ FileUtils.rm_rf(dir)
10
+ FileUtils.mkdir_p(dir)
11
+ end
12
+
13
+ it "should find a class" do
14
+ service.should be_true
15
+ end
16
+
17
+ it "should find a default conf file" do
18
+ service.datomic_conf_file?.should be_true
19
+ end
20
+
21
+ it "should find a specified conf file" do
22
+ service.datomic_conf_file?("spec/test_version_file.yml").should be_true
23
+ end
24
+
25
+ it "should return false for version no" do
26
+ service.datomic_conf_file?("datomic-free-0.8.4122").should be_false
27
+ end
28
+
29
+ it "should know datomic version specified" do
30
+ service.datomic_version("spec/test_version_file.yml").should == "datomic-free-0.8.4122"
31
+ service.datomic_version("datomic-free-0.8.4122").should == "datomic-free-0.8.4122"
32
+ end
33
+
34
+ it "should know the specified version of datomic has been downloaded" do
35
+ service.downloaded?("spec/test_version_file.yml", "tmp/datomic").should be_false
36
+ service.downloaded?("datomic-free-0.8.4122", "tmp/datomic").should be_false
37
+
38
+ service.download("spec/test_version_file.yml", "tmp/datomic")
39
+
40
+ service.downloaded?("spec/test_version_file.yml", "tmp/datomic").should be_true
41
+ service.downloaded?("datomic-free-0.8.4122", "tmp/datomic").should be_true
42
+ end
43
+
44
+ context Diametric::RestService do
45
+ let(:rest) { Diametric::RestService.new("spec/test_version_file.yml", "tmp/datomic") }
46
+
47
+ it "should start and stop rest service" do
48
+ uri = URI("http://localhost:49621")
49
+ expect { Net::HTTP.get_response(uri) }.to raise_error
50
+ rest.start(:port => 49621, :db_alias => "free", :uri => "datomic:mem://")
51
+ expect { Net::HTTP.get_response(uri) }.not_to raise_error
52
+ rest.stop
53
+ expect { Net::HTTP.get_response(uri) }.to raise_error
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+ require 'net/http'
3
+
4
+ describe "Transactor Service", :transactor =>true do
5
+ let(:transactor) { Diametric::Transactor }
6
+
7
+ before do
8
+ dir = File.join(File.dirname(__FILE__), "../..", "tmp/datomic")
9
+ FileUtils.rm_rf(dir)
10
+ FileUtils.mkdir_p(dir)
11
+ end
12
+
13
+ it "should find a class" do
14
+ transactor.should be_true
15
+ end
16
+
17
+ it "should find a default conf file" do
18
+ transactor.datomic_conf_file?.should be_true
19
+ end
20
+
21
+ it "should find a specified conf file" do
22
+ transactor.datomic_conf_file?("spec/test_version_file.yml").should be_true
23
+ end
24
+
25
+ it "should return false for version no" do
26
+ transactor.datomic_conf_file?("datomic-free-0.8.4122").should be_false
27
+ end
28
+
29
+ it "should know datomic version specified" do
30
+ transactor.datomic_version("spec/test_version_file.yml").should == "datomic-free-0.8.4122"
31
+ transactor.datomic_version("datomic-free-0.8.4122").should == "datomic-free-0.8.4122"
32
+ end
33
+
34
+ it "should know the specified version of datomic has been downloaded" do
35
+ transactor.downloaded?("spec/test_version_file.yml", "tmp/datomic").should be_false
36
+ transactor.downloaded?("datomic-free-0.8.4122", "tmp/datomic").should be_false
37
+
38
+ transactor.download("spec/test_version_file.yml", "tmp/datomic")
39
+
40
+ transactor.downloaded?("spec/test_version_file.yml", "tmp/datomic").should be_true
41
+ transactor.downloaded?("datomic-free-0.8.4122", "tmp/datomic").should be_true
42
+ end
43
+
44
+ context Diametric::Transactor do
45
+ let(:transactor) { Diametric::Transactor.new("spec/test_version_file.yml", "tmp/datomic") }
46
+
47
+ it "should start and stop transactor" do
48
+ filename = File.join(File.dirname(__FILE__), "..", "config", "free-transactor-template.properties")
49
+ File.exists?(filename).should be_true
50
+ transactor.start(filename).should be_true
51
+ transactor.stop
52
+ end
53
+ end
54
+
55
+ context Diametric::Transactor do
56
+ let(:transactor) { Diametric::Transactor.new("spec/test_version_file.yml", "tmp/datomic") }
57
+
58
+ it "should be available to create_database and connect to" do
59
+ filename = File.join(File.dirname(__FILE__), "..", "config", "free-transactor-template.properties")
60
+ transactor.start(filename).should be_true
61
+ uri = "datomic:free://localhost:39082/transactor-#{SecureRandom.uuid}"
62
+ Diametric::Persistence::Peer.create_database(uri).should be_true
63
+ Diametric::Persistence::Peer.connect(uri).should be_true
64
+ transactor.stop
65
+ end
66
+ end
67
+
68
+ end
@@ -1,14 +1,16 @@
1
1
  require 'spec_helper'
2
+ require 'diametric/entity'
2
3
  require 'datomic/client'
4
+ require 'securerandom'
3
5
 
4
6
  # Datomic's `rest` needs to run for these tests to pass:
5
7
  # bin/rest 9000 test datomic:mem://
6
8
 
7
9
  describe Diametric::Entity, :integration => true do
8
10
  before(:all) do
9
- @datomic_uri = ENV['DATOMIC_URI'] || 'http://localhost:9000'
11
+ @datomic_uri = ENV['DATOMIC_URI'] || 'http://localhost:46291'
10
12
  @storage = ENV['DATOMIC_STORAGE'] || 'free'
11
- @dbname = ENV['DATOMIC_NAME'] || "test-#{Time.now.to_i}"
13
+ @dbname = ENV['DATOMIC_NAME'] || "test-#{SecureRandom.uuid}"
12
14
  @client = Datomic::Client.new @datomic_uri, @storage
13
15
  @client.create_database(@dbname)
14
16
  sleep 0.5
@@ -77,7 +79,7 @@ describe Diametric::Entity, :integration => true do
77
79
  robin.save.should be_false
78
80
  robin.name = "Mary"
79
81
  robin.age = 3
80
- expect { robin.save! }.to_not raise_error(Diametric::Errors::ValidationError)
82
+ expect { robin.save! }.not_to raise_error()
81
83
  robin.persisted?.should be_true
82
84
  end
83
85
  it "can update entity" do
@@ -0,0 +1,42 @@
1
+ require 'conf_helper'
2
+
3
+ class Somebody
4
+ include Diametric::Entity
5
+ include Diametric::Persistence::Peer
6
+
7
+ attribute :name, String
8
+ attribute :parent, Ref, :cardinality => :one
9
+ end
10
+
11
+ describe "RailsConf 2013", :jruby => true do
12
+ context Somebody do
13
+ before(:all) do
14
+ datomic_uri = "datomic:mem://somebody-#{SecureRandom.uuid}"
15
+ @conn = Diametric::Persistence::Peer.connect(datomic_uri)
16
+ end
17
+ after(:all) do
18
+ @conn.release
19
+ end
20
+
21
+ it "should create schema" do
22
+ binding.pry
23
+ Sombody.create_schema(@conn)
24
+ end
25
+
26
+ it "should create instances" do
27
+ alice = Somebody.new
28
+ alice.name = "Alice Wonderland"
29
+ alice.parent = ""
30
+ yoko.save
31
+ binding.pry
32
+
33
+ clinton = Developer.new(:name => "Clinton N. Dreisbach", :friends => [yoko])
34
+ clinton.save
35
+ binding.pry
36
+
37
+ ryan = Developer.new(:name => "Ryan Neufeld", :friends => [clinton, yoko])
38
+ ryan.save
39
+ binding.pry
40
+ end
41
+ end
42
+ end
@@ -1,37 +1,121 @@
1
1
  require 'spec_helper'
2
+ require 'diametric/entity'
2
3
  require 'datomic/client'
3
4
 
4
5
  # Datomic's `rest` needs to run for these tests to pass:
5
6
  # bin/rest 9000 test datomic:mem://
6
7
 
7
8
  describe Diametric::Entity, :integration => true, :jruby => true do
8
- before(:all) do
9
- @datomic_uri = ENV['DATOMIC_URI'] || 'datomic:mem://animals'
10
- Diametric::Persistence.establish_base_connection({:uri => @datomic_uri})
11
- Penguin.create_schema
9
+ context Penguin do
10
+ before(:all) do
11
+ @datomic_uri = ENV['DATOMIC_URI'] || 'datomic:mem://animals'
12
+ @conn = Diametric::Persistence.establish_base_connection({:uri => @datomic_uri})
13
+ Penguin.create_schema(@conn)
14
+ end
15
+
16
+ after(:all) do
17
+ @conn.release
18
+ end
19
+
20
+ let(:query) { Diametric::Query.new(Penguin, @conn, true) }
21
+ it "should update entity" do
22
+ penguin = Penguin.new(:name => "Mary", :age => 2)
23
+ penguin.save(@conn)
24
+ penguin.update(:age => 3)
25
+ penguin.name.should == "Mary"
26
+ penguin.age.should == 3
27
+ end
28
+
29
+ it "should search upadated attributes" do
30
+ penguin = query.where(:name => "Mary").first
31
+ penguin.name.should == "Mary"
32
+ penguin.age.should == 3
33
+ end
34
+
35
+ it "should destroy entity" do
36
+ penguin = Penguin.new(:name => "Mary", :age => 2)
37
+ penguin.save(@conn)
38
+ number_of_penguins = Penguin.all.size
39
+ number_of_penguins.should >= 1
40
+ penguin.destroy
41
+ Penguin.all.size.should == (number_of_penguins -1)
42
+ end
12
43
  end
13
44
 
14
- let(:query) { Diametric::Query.new(Penguin) }
15
- it "should update entity" do
16
- penguin = Penguin.new(:name => "Mary", :age => 2)
17
- penguin.save
18
- penguin.update(:age => 3)
19
- penguin.name.should == "Mary"
20
- penguin.age.should == 3
45
+ context Choice do
46
+ before(:all) do
47
+ @datomic_uri = ENV['DATOMIC_URI'] || 'datomic:mem://choices'
48
+ @conn2 = Diametric::Persistence.establish_base_connection({:uri => @datomic_uri})
49
+ Choice.create_schema(@conn2)
50
+ end
51
+
52
+ after(:all) do
53
+ @conn2.release
54
+ end
55
+
56
+ it "should save entity" do
57
+ choice = Choice.new(:item => "Boots", :checked => true)
58
+ choice.save.should_not be_nil
59
+ result = Diametric::Persistence::Peer.q("[:find ?e :in $ :where [?e :choice/checked]]", @conn2.db)
60
+ choice = Choice.from_dbid_or_entity(result.first.first, @conn2.db)
61
+ choice.checked.should be_true
62
+ end
21
63
  end
22
64
 
23
- it "should search upadated attributes" do
24
- penguin = query.where(:name => "Mary").first
25
- penguin.name.should == "Mary"
26
- penguin.age.should == 3
65
+ context Customer do
66
+ before(:all) do
67
+ @datomic_uri = ENV['DATOMIC_URI'] || 'datomic:mem://choices'
68
+ @conn3 = Diametric::Persistence.establish_base_connection({:uri => @datomic_uri})
69
+ Customer.create_schema(@conn3)
70
+ end
71
+
72
+ after(:all) do
73
+ @conn3.release
74
+ end
75
+
76
+ it "should save entity with Diametric uuid" do
77
+ id = Diametric::Persistence::Peer.squuid
78
+ customer = Customer.new(:name => "John Smith", :id => id)
79
+ customer.save.should_not be_nil
80
+ result = Diametric::Persistence::Peer.q("[:find ?e :in $ :where [?e :customer/name]]", @conn3.db)
81
+ customer2 = Customer.from_dbid_or_entity(result.first.first, @conn3.db)
82
+ customer2.name.should == "John Smith"
83
+ customer2.id.to_s.should == id.to_s
84
+ end
85
+
86
+ it "should save entity with Ruby uuid" do
87
+ require 'uuid'
88
+ id = UUID.new.generate
89
+ customer = Customer.new(:name => "Wilber Hoe", :id => id)
90
+ customer.save.should_not be_nil
91
+ result = Diametric::Persistence::Peer.q("[:find ?e :in $ [?name] :where [?e :customer/name ?name]]", @conn3.db, ["Wilber Hoe"])
92
+ customer2 = Customer.from_dbid_or_entity(result.first.first, @conn3.db)
93
+ customer2.name.should == "Wilber Hoe"
94
+ customer2.id.to_s.should == id.to_s
95
+ end
27
96
  end
28
97
 
29
- it "should destroy entity" do
30
- penguin = Penguin.new(:name => "Mary", :age => 2)
31
- penguin.save
32
- number_of_penguins = Penguin.all.size
33
- number_of_penguins.should >= 1
34
- penguin.destroy
35
- Penguin.all.size.should == (number_of_penguins -1)
98
+ context Account do
99
+ before(:all) do
100
+ @datomic_uri = ENV['DATOMIC_URI'] || 'datomic:mem://account'
101
+ @conn4 = Diametric::Persistence.establish_base_connection({:uri => @datomic_uri})
102
+ Account.create_schema(@conn4)
103
+ end
104
+
105
+ after(:all) do
106
+ @conn4.release
107
+ end
108
+
109
+ it "should save entity" do
110
+ account = Account.new(:name => "This month's deposits", :deposit => [100.0, 200.0], :amount => 0.0)
111
+ account.save.should_not be_nil
112
+ result = Diametric::Persistence::Peer.q("[:find ?e :in $ :where [?e :account/name]]", @conn4.db)
113
+ account2 = Customer.from_dbid_or_entity(result.first.first, @conn4.db)
114
+ account2.name.should == account.name
115
+ account2.amount.should == 0.0
116
+ account2.deposit.should include(100.0)
117
+ account2.deposit.should include(200.0)
118
+ end
119
+
36
120
  end
37
121
  end