fauna 2.4.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,7 +29,7 @@ module FaunaTestHelpers
29
29
  end
30
30
 
31
31
  def create_test_db
32
- @db_ref = Fauna::Ref.new "databases/faunadb-ruby-test-#{random_string}"
32
+ @db_ref = Fauna::Ref.new("faunadb-ruby-test-#{random_string}", Fauna::Native.databases)
33
33
 
34
34
  root = root_client
35
35
  root.query { create ref('databases'), name: @db_ref.id }
@@ -3,7 +3,7 @@ RSpec.describe Fauna::FaunaJson do
3
3
  it 'deserializes ref' do
4
4
  ref = random_ref_string
5
5
 
6
- data = { :@ref => ref }
6
+ data = { :@ref => { id: ref } }
7
7
  obj = Fauna::Ref.new(ref)
8
8
 
9
9
  expect(Fauna::FaunaJson.deserialize(data)).to eq(obj)
@@ -13,7 +13,7 @@ RSpec.describe Fauna::FaunaJson do
13
13
  ref = random_ref_string
14
14
  terms = random_string
15
15
 
16
- data = { :@set => { match: { :@ref => ref }, terms: terms } }
16
+ data = { :@set => { match: { :@ref => { id: ref } }, terms: terms } }
17
17
  obj = Fauna::SetRef.new(match: Fauna::Ref.new(ref), terms: terms)
18
18
 
19
19
  expect(Fauna::FaunaJson.deserialize(data)).to eq(obj)
@@ -59,7 +59,7 @@ RSpec.describe Fauna::FaunaJson do
59
59
  it 'recursively deserializes hashes' do
60
60
  ref = random_ref_string
61
61
 
62
- data = { test: { :@obj => { :@ref => ref } } }
62
+ data = { test: { :@obj => { :@ref => { id: ref } } } }
63
63
  obj = { test: Fauna::Ref.new(ref) }
64
64
 
65
65
  expect(Fauna::FaunaJson.deserialize(data)).to eq(obj)
@@ -69,7 +69,7 @@ RSpec.describe Fauna::FaunaJson do
69
69
  ref1 = random_ref_string
70
70
  ref2 = random_ref_string
71
71
 
72
- data = [{ :@ref => ref1 }, { :@ref => ref2 }]
72
+ data = [{ :@ref => { id: ref1 } }, { :@ref => { id: ref2 } }]
73
73
  obj = [Fauna::Ref.new(ref1), Fauna::Ref.new(ref2)]
74
74
 
75
75
  expect(Fauna::FaunaJson.deserialize(data)).to eq(obj)
@@ -80,7 +80,7 @@ RSpec.describe Fauna::FaunaJson do
80
80
  it 'serializes ref' do
81
81
  ref = random_ref_string
82
82
 
83
- data = { :@ref => ref }
83
+ data = { :@ref => { id: ref } }
84
84
  obj = Fauna::Ref.new(ref)
85
85
 
86
86
  expect(Fauna::FaunaJson.serialize(obj)).to eq(data)
@@ -89,7 +89,7 @@ RSpec.describe Fauna::FaunaJson do
89
89
  it 'serializes set' do
90
90
  ref = random_ref_string
91
91
 
92
- data = { :@ref => ref }
92
+ data = { :@ref => { id: ref } }
93
93
  obj = Fauna::Ref.new(ref)
94
94
 
95
95
  expect(Fauna::FaunaJson.serialize(obj)).to eq(data)
@@ -136,7 +136,7 @@ RSpec.describe Fauna::FaunaJson do
136
136
  ref = random_ref_string
137
137
  terms = random_string
138
138
 
139
- data = { a: { time: { :@ts => '1970-01-01T00:00:00.000000000Z' } }, b: { :@set => { match: { :@ref => ref }, terms: terms } } }
139
+ data = { a: { time: { :@ts => '1970-01-01T00:00:00.000000000Z' } }, b: { :@set => { match: { :@ref => { id: ref } }, terms: terms } } }
140
140
  obj = { a: { time: Time.at(0).utc }, b: Fauna::SetRef.new(match: Fauna::Ref.new(ref), terms: terms) }
141
141
 
142
142
  expect(Fauna::FaunaJson.serialize(obj)).to eq(data)
@@ -146,7 +146,7 @@ RSpec.describe Fauna::FaunaJson do
146
146
  ref1 = random_ref_string
147
147
  ref2 = random_ref_string
148
148
 
149
- data = [{ :@ref => ref1 }, { :@ref => ref2 }]
149
+ data = [{ :@ref => { id: ref1 } }, { :@ref => { id: ref2 } }]
150
150
  obj = [Fauna::Ref.new(ref1), Fauna::Ref.new(ref2)]
151
151
 
152
152
  expect(Fauna::FaunaJson.serialize(obj)).to eq(data)
@@ -5,7 +5,7 @@ RSpec.describe Fauna::Page do
5
5
  @foreach_class = client.query { create ref('classes'), name: 'page_foreach' }[:ref]
6
6
 
7
7
  index_refs = client.query { create ref('indexes'), name: 'page_refs', source: @test_class }
8
- index_values = client.query { create ref('indexes'), name: 'page_values', source: @test_class, values: [{ path: 'data.value' }] }
8
+ index_values = client.query { create ref('indexes'), name: 'page_values', source: @test_class, values: [{ field: %w(data value) }] }
9
9
  index_foreach = client.query { create ref('indexes'), name: 'page_apply', source: @foreach_class }
10
10
 
11
11
  wait_for_index(index_refs[:ref], index_values[:ref], index_foreach[:ref])
@@ -4,10 +4,10 @@ RSpec.describe Fauna::Query do
4
4
  @test_class = client.query { create ref('classes'), name: 'query_test' }[:ref]
5
5
 
6
6
  index_x = client.query do
7
- create ref('indexes'), name: 'query_by_x', source: @test_class, terms: [{ path: 'data.x' }]
7
+ create ref('indexes'), name: 'query_by_x', source: @test_class, terms: [{ field: %w(data x) }]
8
8
  end
9
9
  index_y = client.query do
10
- create ref('indexes'), name: 'query_by_y', source: @test_class, terms: [{ path: 'data.y' }]
10
+ create ref('indexes'), name: 'query_by_y', source: @test_class, terms: [{ field: %w(data y) }]
11
11
  end
12
12
 
13
13
  wait_for_index(index_x[:ref], index_y[:ref])
@@ -106,13 +106,21 @@ RSpec.describe Fauna::Query do
106
106
 
107
107
  describe '#ref' do
108
108
  it 'returns a ref from a string' do
109
- str = random_ref_string
110
- expect(Fauna::Query.ref(str)).to eq(Fauna::Ref.new(str))
109
+ cls = random_string
110
+ id = random_number.to_s
111
+ str = "classes/#{cls}/#{id}"
112
+ expect(client.query { ref(str) }).to eq(Fauna::Ref.new(id, Fauna::Ref.new(cls, Fauna::Native.classes)))
111
113
  end
112
114
 
113
115
  it 'constructs a ref' do
114
- expect(client.query { ref(@test_class, '123') }).to eq(Fauna::Ref.new('classes/query_test/123'))
115
- expect(client.query { ref(@test_class, next_id) }.value).to match(%r{^classes/query_test/\d+$})
116
+ expect(client.query { ref(@test_class, '123') }).to eq(Fauna::Ref.new('123', @test_class))
117
+ expect(client.query { ref(@test_class, new_id) }.id).to match(%r{\d+$})
118
+ end
119
+ end
120
+
121
+ describe '#abort' do
122
+ it 'aborts the execution' do
123
+ expect { client.query { abort('message') }}.to raise_error(Fauna::BadRequest)
116
124
  end
117
125
  end
118
126
 
@@ -387,7 +395,7 @@ RSpec.describe Fauna::Query do
387
395
  it 'performs create' do
388
396
  instance = client.query { create(@test_class, {}) }
389
397
 
390
- expect(instance[:class]).to eq(@test_class)
398
+ expect(instance[:ref].class_).to eq(@test_class)
391
399
  expect(client.query { exists instance[:ref] }).to be(true)
392
400
  end
393
401
  end
@@ -517,6 +525,43 @@ RSpec.describe Fauna::Query do
517
525
  @ref_xy = create_instance(x: @x_value, y: @y_value)[:ref]
518
526
  end
519
527
 
528
+ describe '#events' do
529
+ it 'performs events' do
530
+ client.query { update @ref_x, data: {x: random_number} }
531
+ client.query { delete @ref_x }
532
+
533
+ events = client.query { paginate events(@ref_x) }[:data]
534
+
535
+ expect(events.count).to be(3)
536
+
537
+ expect(events[0][:action]).to eq('create')
538
+ expect(events[0][:instance]).to eq(@ref_x)
539
+
540
+ expect(events[1][:action]).to eq('update')
541
+ expect(events[1][:instance]).to eq(@ref_x)
542
+
543
+ expect(events[2][:action]).to eq('delete')
544
+ expect(events[2][:instance]).to eq(@ref_x)
545
+ end
546
+ end
547
+
548
+ describe '#singleton' do
549
+ it 'performs singleton' do
550
+ client.query { update @ref_x, data: {x: random_number} }
551
+ client.query { delete @ref_x }
552
+
553
+ events = client.query { paginate events(singleton(@ref_x)) }[:data]
554
+
555
+ expect(events.count).to be(2)
556
+
557
+ expect(events[0][:action]).to eq('add')
558
+ expect(events[0][:instance]).to eq(@ref_x)
559
+
560
+ expect(events[1][:action]).to eq('remove')
561
+ expect(events[1][:instance]).to eq(@ref_x)
562
+ end
563
+ end
564
+
520
565
  describe '#match' do
521
566
  it 'performs match' do
522
567
  set = Fauna::Query.expr { match(@test_by_x, @x_value) }
@@ -549,7 +594,7 @@ RSpec.describe Fauna::Query do
549
594
  describe '#distinct' do
550
595
  before do
551
596
  over_z = client.query do
552
- create ref('indexes'), name: 'query_over_z', source: @test_class, values: [{ path: 'data.z' }]
597
+ create ref('indexes'), name: 'query_over_z', source: @test_class, values: [{ field: %w(data z) }]
553
598
  end
554
599
  wait_for_index(over_z[:ref])
555
600
  @test_over_z = over_z[:ref]
@@ -621,7 +666,8 @@ RSpec.describe Fauna::Query do
621
666
  token = client.query { login @user[:ref], password: @password }
622
667
  user_client = get_client secret: token[:secret]
623
668
 
624
- expect(user_client.query { select(:ref, get(ref('tokens/self'))) }).to eq(token[:ref])
669
+ self_ = Fauna::Ref.new('self', Fauna::Native.tokens)
670
+ expect(user_client.query { select(:ref, get(self_)) }).to eq(token[:ref])
625
671
  end
626
672
  end
627
673
 
@@ -639,6 +685,25 @@ RSpec.describe Fauna::Query do
639
685
  expect(client.query { identify(@user[:ref], @password) }).to be(true)
640
686
  end
641
687
  end
688
+
689
+ describe '#has_identity' do
690
+ it 'performs has_identity' do
691
+ token = client.query { login @user[:ref], password: @password }
692
+ user_client = get_client secret: token[:secret]
693
+
694
+ expect(client.query { has_identity }).to be(false)
695
+ expect(user_client.query { has_identity }).to be(true)
696
+ end
697
+ end
698
+
699
+ describe '#identity' do
700
+ it 'performs identity' do
701
+ token = client.query { login @user[:ref], password: @password }
702
+ user_client = get_client secret: token[:secret]
703
+
704
+ expect(user_client.query { identity }).to eq(@user[:ref])
705
+ end
706
+ end
642
707
  end
643
708
 
644
709
  describe '#concat' do
@@ -655,6 +720,14 @@ RSpec.describe Fauna::Query do
655
720
  describe '#casefold' do
656
721
  it 'performs casefold' do
657
722
  expect(client.query { casefold 'Hen Wen' }).to eq('hen wen')
723
+
724
+ # https://unicode.org/reports/tr15/
725
+ expect(client.query { casefold("\u212B", "NFD") } ).to eq("A\u030A")
726
+ expect(client.query { casefold("\u212B", "NFC") } ).to eq("\u00C5")
727
+ expect(client.query { casefold("\u1E9B\u0323", "NFKD") } ).to eq("\u0073\u0323\u0307")
728
+ expect(client.query { casefold("\u1E9B\u0323", "NFKC") } ).to eq("\u1E69")
729
+
730
+ expect(client.query { casefold("\u212B", "NFKCCaseFold") } ).to eq("\u00E5")
658
731
  end
659
732
  end
660
733
 
@@ -688,9 +761,9 @@ RSpec.describe Fauna::Query do
688
761
  end
689
762
  end
690
763
 
691
- describe '#next_id' do
764
+ describe '#new_id' do
692
765
  it 'gets a new id' do
693
- expect(client.query { next_id }).to be_a(String)
766
+ expect(client.query { new_id }).to be_a(String)
694
767
  end
695
768
  end
696
769
 
@@ -775,6 +848,22 @@ RSpec.describe Fauna::Query do
775
848
  end
776
849
  end
777
850
 
851
+ describe '#select_all' do
852
+ it 'performs select_all with hash' do
853
+ obj1 = { foo: 'bar' }
854
+ obj2 = { foo: 'baz' }
855
+
856
+ expect(client.query { select_all(:foo, [obj1, obj2]) }).to eq(['bar', 'baz'])
857
+ end
858
+
859
+ it 'performs select_all with array' do
860
+ obj1 = { foo: [0, 1] }
861
+ obj2 = { foo: [2, 3] }
862
+
863
+ expect(client.query { select_all([:foo, 0], [obj1, obj2]) }).to eq([0, 2])
864
+ end
865
+ end
866
+
778
867
  describe '#add' do
779
868
  it 'performs add' do
780
869
  expect(client.query { add(2, 3, 5) }).to eq(10)
@@ -861,4 +950,43 @@ RSpec.describe Fauna::Query do
861
950
  expect(client.query { not_(false) }).to be(true)
862
951
  end
863
952
  end
953
+
954
+ describe '#recursive references' do
955
+ it 'create nested keys' do
956
+ new_client = create_new_database(admin_client, 'db-for-keys')
957
+ new_client.query { create_database name: 'db-test' }
958
+
959
+ server_key = new_client.query { create_key database: database('db-test'), role: 'server' }
960
+ admin_key = new_client.query { create_key database: database('db-test'), role: 'admin' }
961
+
962
+ expect(new_client.query { paginate keys() }).to eq(data: [server_key[:ref], admin_key[:ref]])
963
+ expect(admin_client.query { paginate keys(database('db-for-keys')) }).to eq(data: [server_key[:ref], admin_key[:ref]])
964
+ end
965
+
966
+ it 'create nested class' do
967
+ client1 = create_new_database(admin_client, 'parent-database')
968
+ create_new_database(client1, 'child-database')
969
+
970
+ key = client1.query { create_key database: database('child-database'), role: 'server' }
971
+ client2 = get_client secret: key[:secret]
972
+ client2.query { create_class name: 'a_class' }
973
+
974
+ nested_database = Fauna::Query.database('child-database', Fauna::Query.database('parent-database'))
975
+ nested_class = Fauna::Query.class_('a_class', nested_database)
976
+ all_nested_classes = Fauna::Query.classes(nested_database)
977
+
978
+ parent_database_ref = Fauna::Ref.new('parent-database', Fauna::Native.databases)
979
+ child_database_ref = Fauna::Ref.new('child-database', Fauna::Native.databases, parent_database_ref)
980
+ a_class_ref = Fauna::Ref.new('a_class', Fauna::Native.classes, child_database_ref)
981
+
982
+ expect(client.query { exists nested_class }).to be(true)
983
+ expect(client.query { paginate all_nested_classes }).to eq(data: [a_class_ref])
984
+ end
985
+ end
986
+
987
+ def create_new_database(client, name)
988
+ client.query { create_database name: name }
989
+ key = client.query { create_key database: database(name), role: 'admin' }
990
+ get_client secret: key[:secret]
991
+ end
864
992
  end
@@ -1,63 +1,99 @@
1
1
  RSpec.describe Fauna::Ref do
2
2
  it 'converts to string' do
3
- expect(Fauna::Ref.new('classes/test').to_s).to eq('classes/test')
3
+ db = Fauna::Ref.new('db', Fauna::Native.databases)
4
+ expect(db.to_s).to eq('Ref(id=db,class=Ref(id=databases))')
5
+
6
+ cls = Fauna::Ref.new('cls', Fauna::Native.classes, db)
7
+ expect(cls.to_s).to eq('Ref(id=cls,class=Ref(id=classes),database=Ref(id=db,class=Ref(id=databases)))')
8
+
9
+ expect(Fauna::Ref.new('test', cls).to_s).to eq('Ref(id=test,class=Ref(id=cls,class=Ref(id=classes),database=Ref(id=db,class=Ref(id=databases))))')
4
10
  end
5
11
 
6
- describe '#initalize' do
7
- it 'creates from string' do
8
- name = random_string
9
- expect(Fauna::Ref.new("classes/#{name}").value).to eq("classes/#{name}")
12
+ describe '#id' do
13
+ it 'returns id portion' do
14
+ expect(Fauna::Ref.new('test', Fauna::Native.classes).id).to eq('test')
15
+ end
16
+
17
+ it 'raises error' do
18
+ expect { Fauna::Ref.new(nil) }.to raise_error(ArgumentError)
10
19
  end
11
20
  end
12
21
 
13
- describe '#id' do
14
- context 'with multiple elements' do
15
- it 'returns id portion' do
16
- expect(Fauna::Ref.new('classes/test').id).to eq('test')
22
+ describe '#class_' do
23
+ context 'with id and user class' do
24
+ it 'returns class portion' do
25
+ expect(Fauna::Ref.new('1234', Fauna::Ref.new('test', Fauna::Native.classes)).class_).to eq(Fauna::Ref.new('test', Fauna::Native.classes))
26
+ end
27
+ end
28
+
29
+ context 'user class only' do
30
+ it 'returns class portion' do
31
+ expect(Fauna::Ref.new('test', Fauna::Native.classes).class_).to eq(Fauna::Native.classes)
17
32
  end
18
33
  end
19
34
 
20
- context 'with single element' do
21
- it 'raises error' do
22
- expect { Fauna::Ref.new('classes').id }.to raise_error(ArgumentError)
35
+ context 'without id and user class' do
36
+ it 'does not return class portion' do
37
+ expect(Fauna::Ref.new('classes').class_).to be_nil
38
+ end
39
+ end
40
+
41
+ context 'with native classes' do
42
+ it 'does not return class portion' do
43
+ expect(Fauna::Native.classes.class_).to be_nil
44
+ expect(Fauna::Native.indexes.class_).to be_nil
45
+ expect(Fauna::Native.databases.class_).to be_nil
46
+ expect(Fauna::Native.functions.class_).to be_nil
47
+ expect(Fauna::Native.keys.class_).to be_nil
23
48
  end
24
49
  end
25
50
  end
26
51
 
27
- describe '#to_class' do
28
- context 'with three elements' do
29
- it 'returns class portion' do
30
- expect(Fauna::Ref.new('classes/test/1234').to_class).to eq(Fauna::Ref.new('classes/test'))
52
+ describe '#database' do
53
+ db = Fauna::Ref.new('db', Fauna::Native.databases)
54
+
55
+ context 'with simple database' do
56
+ it 'returns database portion' do
57
+ expect(Fauna::Ref.new('test', Fauna::Native.classes, db).database).to eq(Fauna::Ref.new('db', Fauna::Native.databases))
31
58
  end
32
59
  end
33
60
 
34
- context 'with two elements' do
35
- it 'returns class portion' do
36
- expect(Fauna::Ref.new('classes/test').to_class).to eq(Fauna::Ref.new('classes'))
61
+ context 'with nested database' do
62
+ it 'returns database portion' do
63
+ nested_db = Fauna::Ref.new('nested-db', Fauna::Native.databases, db)
64
+ deep_db = Fauna::Ref.new('deep-db', Fauna::Native.databases, nested_db)
65
+
66
+ expect(nested_db.database).to eq(db)
67
+ expect(deep_db.database.database).to eq(db)
37
68
  end
38
69
  end
39
70
 
40
- context 'with one element' do
41
- it 'returns class portion' do
42
- expect(Fauna::Ref.new('classes').to_class).to eq(Fauna::Ref.new('classes'))
71
+ context 'with native classes' do
72
+ it 'does not return database portion' do
73
+ expect(Fauna::Native.classes.database).to be_nil
74
+ expect(Fauna::Native.indexes.database).to be_nil
75
+ expect(Fauna::Native.databases.database).to be_nil
76
+ expect(Fauna::Native.functions.database).to be_nil
77
+ expect(Fauna::Native.keys.database).to be_nil
43
78
  end
44
79
  end
45
80
  end
46
81
 
47
82
  describe '#==' do
48
83
  it 'equals same ref' do
49
- ref = Fauna::Ref.new('classes/test')
84
+ ref = Fauna::Ref.new('123', Fauna::Ref.new('test', Fauna::Native.classes))
50
85
 
51
- expect(ref).to eq(Fauna::Ref.new('classes/test'))
52
- expect(ref.to_class).to eq(Fauna::Ref.new('classes'))
86
+ expect(ref).to eq(Fauna::Ref.new('123', Fauna::Ref.new('test', Fauna::Native.classes)))
53
87
  end
54
88
 
55
89
  it 'does not equal different ref' do
56
- expect(Fauna::Ref.new('classes/test')).not_to eq(Fauna::Ref.new('classes'))
90
+ ref = Fauna::Ref.new('123', Fauna::Ref.new('test', Fauna::Native.classes))
91
+
92
+ expect(ref).not_to eq(Fauna::Ref.new('321', Fauna::Ref.new('test', Fauna::Native.classes)))
57
93
  end
58
94
 
59
95
  it 'does not equal other type' do
60
- expect(Fauna::Ref.new('classes/test')).not_to eq('classes/test')
96
+ expect(Fauna::Ref.new('test', Fauna::Native.classes)).not_to eq('classes/test')
61
97
  end
62
98
  end
63
99
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fauna
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fauna, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-12 00:00:00.000000000 Z
11
+ date: 2018-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -81,19 +81,33 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.38.0
83
83
  - !ruby/object:Gem::Dependency
84
- name: codecov
84
+ name: simplecov-json
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.1.5
89
+ version: 0.2.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.1.5
96
+ version: 0.2.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec_junit_formatter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.3.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.3.0
97
111
  description: Ruby driver for FaunaDB.
98
112
  email: priority@fauna.com
99
113
  executables: []
@@ -113,6 +127,7 @@ files:
113
127
  - lib/fauna/client.rb
114
128
  - lib/fauna/client_logger.rb
115
129
  - lib/fauna/context.rb
130
+ - lib/fauna/deprecate.rb
116
131
  - lib/fauna/errors.rb
117
132
  - lib/fauna/json.rb
118
133
  - lib/fauna/objects.rb