fauna 1.3.4 → 2.0.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.
@@ -1,48 +0,0 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
-
3
- class DatabaseTest < MiniTest::Unit::TestCase
4
- def setup
5
- super
6
- @model = Fauna::Resource.new 'databases', :name => 'fauna-ruby-test2'
7
- Fauna::Client.context(@root_connection) do
8
- @model.save
9
- end
10
- end
11
-
12
- def test_get
13
- assert_raises(Fauna::Connection::PermissionDenied) do
14
- Fauna::Resource.find('databases/fauna-ruby-test')
15
- end
16
-
17
- assert_raises(Fauna::Connection::PermissionDenied) do
18
- Fauna::Resource.find('databases/nonexistent')
19
- end
20
-
21
- Fauna::Client.context(@root_connection) do
22
- Fauna::Resource.find('databases/fauna-ruby-test')
23
- Fauna::Resource.find('databases/fauna-ruby-test2')
24
-
25
- assert_raises(Fauna::Connection::NotFound) do
26
- Fauna::Resource.find('databases/nonexistent')
27
- end
28
- end
29
- end
30
-
31
- def test_create
32
- assert_raises(Fauna::Connection::PermissionDenied) do
33
- @model.save
34
- end
35
- Fauna::Client.context(@root_connection) do
36
- @model.save
37
- end
38
- end
39
-
40
- def test_destroy
41
- assert_raises(Fauna::Connection::PermissionDenied) do
42
- @model.delete
43
- end
44
- Fauna::Client.context(@root_connection) do
45
- @model.delete
46
- end
47
- end
48
- end
@@ -1,48 +0,0 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
-
3
- # TODO: use association_test classes
4
-
5
- class QueryTest < MiniTest::Unit::TestCase
6
- def setup # rubocop:disable Metrics/MethodLength
7
- super
8
- @model = Fauna::Resource.create 'classes/message_boards'
9
- @posts_set = @model.set 'posts'
10
- @posts = []
11
- @comments = []
12
-
13
- 3.times do
14
- post = Fauna::Resource.create(
15
- 'classes/posts',
16
- :data =>
17
- { :topic => 'The Horned King' },
18
- )
19
-
20
- @posts << post
21
- @posts_set.add(post)
22
-
23
- 3.times do
24
- comment = Fauna::Resource.create(
25
- 'classes/comments',
26
- :data =>
27
- { :text => 'Do not show the Horned King the whereabouts of the Black Cauldron!' },
28
- )
29
-
30
- @comments << comment
31
- Fauna::CustomSet.new("#{post.ref}/sets/comments").add(comment)
32
- end
33
- end
34
- end
35
-
36
- def test_join
37
- query = Fauna::Set.join @posts_set, '_/sets/comments'
38
- assert_equal 9, query.page.size
39
- @comments.flatten.each do |comment|
40
- assert query.page.include? comment.ref
41
- end
42
- end
43
-
44
- def test_match
45
- query = Fauna::Set.match 'classes/posts', 'data.topic', 'The Horned King'
46
- assert query.page.size > 1
47
- end
48
- end
@@ -1,30 +0,0 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
-
3
- class ReadmeTest < MiniTest::Unit::TestCase
4
- def test_readme # rubocop:disable Metrics/MethodLength
5
- code = ''
6
-
7
- sections = File.read(File.expand_path('../../README.md', __FILE__)).split('```')
8
- sections.select do |text| # rubocop:disable Style/Next
9
- if text =~ /^ruby/
10
- next if text =~ /ActionController|logger/
11
- text.gsub!('$fauna = Fauna::Connection.new(secret: server_key)', '$fauna = SERVER_CONNECTION')
12
- code << text[4..-1]
13
- end
14
- end
15
-
16
- tmp = File.open('/tmp/fauna-ruby-readme-eval.rb', 'w')
17
- tmp.write(code)
18
- tmp.close
19
-
20
- begin
21
- load tmp.path
22
- rescue => e
23
- puts e.inspect
24
- puts e.backtrace
25
- raise
26
- end
27
-
28
- File.delete(tmp.path)
29
- end
30
- end
@@ -1,71 +0,0 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
-
3
- # TODO: use association_test classes
4
-
5
- class SetTest < MiniTest::Unit::TestCase
6
- def setup
7
- super
8
- @model = Fauna::Resource.create 'classes/message_boards'
9
- @posts = @model.set 'posts'
10
- end
11
-
12
- def test_page
13
- page = @posts.page
14
- assert_equal "#{@model.ref}/sets/posts", page.ref
15
- assert_equal 0, page.refs.size
16
- assert_equal 0, page.fauna_count
17
- end
18
-
19
- def test_pagination # rubocop:disable Metrics/MethodLength
20
- @posts.add(Fauna::Resource.create 'classes/posts')
21
- @posts.add(Fauna::Resource.create 'classes/posts')
22
- @posts.add(Fauna::Resource.create 'classes/posts')
23
- @posts.add(Fauna::Resource.create 'classes/posts')
24
- @posts.add(Fauna::Resource.create 'classes/posts')
25
-
26
- page1 = @posts.page(:size => 2)
27
- assert_equal 2, page1.refs.size
28
- assert_equal 5, page1.fauna_count
29
- page2 = @posts.page(:size => 2, :before => page1.before)
30
- assert_equal 2, page2.refs.size
31
- page3 = @posts.page(:size => 2, :before => page2.before)
32
- assert_equal 1, page3.refs.size
33
-
34
- page4 = @posts.page(:size => 2, :after => page3.refs.last)
35
- assert_equal 2, page4.refs.size
36
- page5 = @posts.page(:size => 2, :after => page4.after)
37
- assert_equal 2, page5.refs.size
38
- page6 = @posts.page(:size => 2, :after => page5.after)
39
- assert_equal 1, page6.refs.size
40
- assert_equal 5, page6.fauna_count
41
- end
42
-
43
- def test_any
44
- @posts.add(Fauna::Resource.create 'classes/posts')
45
- assert @posts.page.any?
46
- assert @posts.page.refs.any?
47
- assert @posts.events.any?
48
- assert @posts.events.events.any?
49
- end
50
-
51
- def test_event_set_add
52
- post = Fauna::Resource.create 'classes/posts'
53
- @posts.add(post)
54
- page = @posts.page
55
- assert_equal 1, page.refs.size
56
- assert_equal post.ref, page.refs[0]
57
- end
58
-
59
- def test_event_set_remove
60
- @posts.add(Fauna::Resource.create 'classes/posts')
61
- page = @posts.page
62
- assert_equal 1, page.refs.size
63
- @posts.remove(page.refs[0])
64
- end
65
-
66
- def test_event_set_refs
67
- post = Fauna::Resource.create 'classes/posts'
68
- @posts.add(post)
69
- assert_equal [post.ref], @posts.page.refs
70
- end
71
- end
@@ -1,86 +0,0 @@
1
- libdir = File.dirname(File.dirname(__FILE__)) + '/lib'
2
- $LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir)
3
-
4
- require 'rubygems'
5
- require 'test/unit'
6
- require 'fauna'
7
- require 'securerandom'
8
- require 'mocha/setup'
9
-
10
- FAUNA_ROOT_KEY = ENV['FAUNA_ROOT_KEY']
11
- FAUNA_DOMAIN = ENV['FAUNA_DOMAIN']
12
- FAUNA_SCHEME = ENV['FAUNA_SCHEME']
13
- FAUNA_PORT = ENV['FAUNA_PORT']
14
-
15
- unless FAUNA_ROOT_KEY
16
- fail 'FAUNA_ROOT_KEY must be defined in your environment to run tests.'
17
- end
18
-
19
- ROOT_CONNECTION = Fauna::Connection.new(:secret => FAUNA_ROOT_KEY, :domain => FAUNA_DOMAIN, :scheme => FAUNA_SCHEME, :port => FAUNA_PORT)
20
-
21
- Fauna::Client.context(ROOT_CONNECTION) do
22
- Fauna::Resource.new('databases', :name => 'fauna-ruby-test').delete rescue nil # rubocop:disable Style/RescueModifier
23
- Fauna::Resource.create 'databases', :name => 'fauna-ruby-test'
24
-
25
- server_key = Fauna::Resource.create 'keys', :database => 'databases/fauna-ruby-test', :role => 'server'
26
- client_key = Fauna::Resource.create 'keys', :database => 'databases/fauna-ruby-test', :role => 'client'
27
-
28
- SERVER_CONNECTION = Fauna::Connection.new(:secret => server_key.secret, :domain => FAUNA_DOMAIN, :scheme => FAUNA_SCHEME, :port => FAUNA_PORT)
29
- CLIENT_CONNECTION = Fauna::Connection.new(:secret => client_key.secret, :domain => FAUNA_DOMAIN, :scheme => FAUNA_SCHEME, :port => FAUNA_PORT)
30
- end
31
-
32
- # fixtures
33
-
34
- Fauna::Client.context(SERVER_CONNECTION) do
35
- Fauna::Resource.create 'classes', :name => 'pigs'
36
- Fauna::Resource.create 'classes', :name => 'pigkeepers'
37
- Fauna::Resource.create 'classes', :name => 'visions'
38
- Fauna::Resource.create 'classes', :name => 'message_boards'
39
- Fauna::Resource.create 'classes', :name => 'posts'
40
- Fauna::Resource.create 'classes', :name => 'comments'
41
-
42
- # open client key user creation
43
- users = Fauna::Resource.find 'users'
44
- users.permissions = { :create => 'public' }
45
- users.save
46
-
47
- # Fixture for readme_test
48
- pig = Fauna::Resource.new('classes/pigs/42471470493859841')
49
- pig.ref = 'classes/pigs/42471470493859841'
50
- pig.class = 'classes/pigs'
51
- pig.save
52
- end
53
-
54
- # test harness
55
- module MiniTest
56
- class Unit
57
- class TestCase
58
- def setup
59
- @root_connection = ROOT_CONNECTION
60
- @server_connection = SERVER_CONNECTION
61
- @client_connection = CLIENT_CONNECTION
62
- Fauna::Client.push_context(@server_connection)
63
- end
64
-
65
- def teardown
66
- Fauna::Client.pop_context
67
- end
68
-
69
- def email
70
- "#{SecureRandom.random_number}@example.com"
71
- end
72
-
73
- def fail
74
- assert false, 'Not implemented'
75
- end
76
-
77
- def pass
78
- assert true
79
- end
80
-
81
- def password
82
- SecureRandom.random_number.to_s
83
- end
84
- end
85
- end
86
- end