fauna 0.0.0 → 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/CHANGELOG +6 -0
- data/Gemfile +6 -0
- data/LICENSE +12 -0
- data/Manifest +31 -0
- data/README.md +285 -0
- data/Rakefile +20 -0
- data/fauna.gemspec +53 -0
- data/lib/fauna.rb +98 -0
- data/lib/fauna/client.rb +100 -0
- data/lib/fauna/connection.rb +129 -0
- data/lib/fauna/ddl.rb +145 -0
- data/lib/fauna/model.rb +61 -0
- data/lib/fauna/model/class.rb +49 -0
- data/lib/fauna/model/follow.rb +43 -0
- data/lib/fauna/model/publisher.rb +8 -0
- data/lib/fauna/model/timeline.rb +92 -0
- data/lib/fauna/model/user.rb +44 -0
- data/lib/fauna/rails.rb +81 -0
- data/lib/fauna/resource.rb +239 -0
- data/test/client_test.rb +62 -0
- data/test/connection_test.rb +37 -0
- data/test/fixtures.rb +58 -0
- data/test/model/association_test.rb +23 -0
- data/test/model/class_test.rb +61 -0
- data/test/model/follow_test.rb +47 -0
- data/test/model/publisher_test.rb +48 -0
- data/test/model/timeline_test.rb +50 -0
- data/test/model/user_test.rb +72 -0
- data/test/model/validation_test.rb +38 -0
- data/test/readme_test.rb +31 -0
- data/test/test_helper.rb +59 -0
- metadata +234 -50
- metadata.gz.sig +1 -0
data/test/client_test.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class ClientTest < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
@attributes = { "name" => "Princess Eilonwy", "email" => email, "password" => password }
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_publisher_context
|
10
|
+
Fauna::Client.context(@publisher_connection) do
|
11
|
+
user = Fauna::Client.post("users", @attributes)
|
12
|
+
user = Fauna::Client.get(user.ref)
|
13
|
+
Fauna::Client.delete(user.ref)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_client_context
|
18
|
+
Fauna::Client.context(@client_connection) do
|
19
|
+
user = Fauna::Client.post("users", @attributes)
|
20
|
+
Fauna::Client.context(@client_connection) do
|
21
|
+
assert_raises(Fauna::Connection::Unauthorized) do
|
22
|
+
Fauna::Client.get(user.ref)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_token_context
|
29
|
+
Fauna::Client.context(@publisher_connection) do
|
30
|
+
Fauna::Client.post("users", @attributes)
|
31
|
+
end
|
32
|
+
|
33
|
+
Fauna::Client.context(@client_connection) do
|
34
|
+
@token = Fauna::Client.post("tokens", @attributes)
|
35
|
+
end
|
36
|
+
|
37
|
+
Fauna::Client.context(Fauna::Connection.new(:token => @token.token)) do
|
38
|
+
user = Fauna::Client.get(@token.user)
|
39
|
+
Fauna::Client.delete(user.ref)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_caching_1
|
44
|
+
Fauna::Client.context(@publisher_connection) do
|
45
|
+
@user = Fauna::Client.post("users", @attributes)
|
46
|
+
@publisher_connection.expects(:get).never
|
47
|
+
Fauna::Client.get(@user.ref)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_caching_2
|
52
|
+
Fauna::Client.context(@client_connection) do
|
53
|
+
@user = Fauna::Client.post("users", @attributes)
|
54
|
+
|
55
|
+
Fauna::Client.context(@publisher_connection) do
|
56
|
+
Fauna::Client.get(@user.ref)
|
57
|
+
@publisher_connection.expects(:get).never
|
58
|
+
Fauna::Client.get(@user.ref)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class ConnectionTest < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
@attributes = { "name" => "Arawn", "email" => email, "password" => password }
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_get
|
10
|
+
@publisher_connection.get("users")
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_get_with_invalid_key
|
14
|
+
connection = Fauna::Connection.new(:publisher_key => 'bad_key')
|
15
|
+
assert_raises(Fauna::Connection::Unauthorized) do
|
16
|
+
connection.get("users")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_post
|
21
|
+
@client_connection.post("users", @attributes)['resource']
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_put
|
25
|
+
user = @publisher_connection.post("users", @attributes)['resource']
|
26
|
+
user = @publisher_connection.put(user['ref'], {:data => {:pockets => 2}})['resource']
|
27
|
+
assert_equal 2, user['data']['pockets']
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_delete
|
31
|
+
user = @publisher_connection.post("users", @attributes)['resource']
|
32
|
+
@publisher_connection.delete(user['ref'])
|
33
|
+
assert_raises(Fauna::Connection::NotFound) do
|
34
|
+
@publisher_connection.get(user['ref'])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/test/fixtures.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# class Fauna::User
|
2
|
+
# field :pockets
|
3
|
+
# end
|
4
|
+
|
5
|
+
# class Fauna::Publisher
|
6
|
+
# field :visited
|
7
|
+
# end
|
8
|
+
|
9
|
+
class Fauna::User
|
10
|
+
field :pockets
|
11
|
+
end
|
12
|
+
|
13
|
+
class Fauna::Publisher
|
14
|
+
field :visited
|
15
|
+
end
|
16
|
+
|
17
|
+
class Pig < Fauna::Class
|
18
|
+
field :name, :visited
|
19
|
+
end
|
20
|
+
|
21
|
+
class Pigkeeper < Fauna::Class
|
22
|
+
field :visited, :pockets
|
23
|
+
|
24
|
+
validates :visited, :presence => true
|
25
|
+
validate :pockets_are_full
|
26
|
+
|
27
|
+
def pockets_are_full
|
28
|
+
errors.add :pockets, 'must be full of piggy treats' if pockets <= 0 unless pockets.blank?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Vision < Fauna::Class
|
33
|
+
field :pronouncement
|
34
|
+
reference :pig
|
35
|
+
end
|
36
|
+
|
37
|
+
class MessageBoard < Fauna::Class
|
38
|
+
end
|
39
|
+
|
40
|
+
class Post < Fauna::Class
|
41
|
+
field :body
|
42
|
+
end
|
43
|
+
|
44
|
+
Fauna.schema do |f|
|
45
|
+
with Pig, :class_name => "classes/pigs" do
|
46
|
+
timeline :visions
|
47
|
+
end
|
48
|
+
|
49
|
+
with Pigkeeper
|
50
|
+
|
51
|
+
with Vision
|
52
|
+
|
53
|
+
with MessageBoard, :class_name => "classes/board" do
|
54
|
+
timeline :posts
|
55
|
+
end
|
56
|
+
|
57
|
+
with Post
|
58
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class AssociationTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
|
8
|
+
@pig = Pig.create!(:name => "Henwen")
|
9
|
+
@vision = Vision.create!(:pronouncement => "It was a dark and stormy night...", :pig => @pig)
|
10
|
+
@pig.visions.add @vision
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_timeline
|
14
|
+
assert_equal @pig.visions.page.events.first.resource, @vision
|
15
|
+
assert @pig.visions.page.events.first.resource.pronouncement
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_reference
|
19
|
+
assert_equal @vision.pig, @pig
|
20
|
+
assert_equal @vision.pig_ref, @pig.ref
|
21
|
+
assert @vision.pig.visions
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class ClassTest < ActiveModel::TestCase
|
4
|
+
include ActiveModel::Lint::Tests
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
@model = Pig.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_class_name
|
12
|
+
assert_equal 'classes/pigs', Pig.ref
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_class_save
|
16
|
+
Pig.update_data! do |data|
|
17
|
+
data["class_visited"] = true
|
18
|
+
end
|
19
|
+
assert Pig.data["class_visited"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_create
|
23
|
+
pig = Pig.create(:visited => false)
|
24
|
+
assert_equal false, pig.visited
|
25
|
+
assert pig.persisted?
|
26
|
+
assert pig.ref
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_save
|
30
|
+
pig = Pig.new(:visited => false)
|
31
|
+
pig.save
|
32
|
+
assert pig.persisted?
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_update
|
36
|
+
pig = Pig.new(:visited => false)
|
37
|
+
pig.save
|
38
|
+
pig.update(:visited => true)
|
39
|
+
assert pig.visited
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_changes
|
43
|
+
pig = Pig.new(:visited => true)
|
44
|
+
pig.save
|
45
|
+
pig.update(:visited => false)
|
46
|
+
assert_equal pig.changes.page.events.length, 2
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_find
|
50
|
+
pig = Pig.create(:visited => false)
|
51
|
+
pig1 = Pig.find(pig.ref)
|
52
|
+
assert_equal pig.ref, pig1.ref
|
53
|
+
assert pig1.persisted?
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_destroy
|
57
|
+
pig = Pig.create(:visited => false)
|
58
|
+
pig.destroy
|
59
|
+
assert pig.destroyed?
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class FollowTest < ActiveModel::TestCase
|
4
|
+
#include ActiveModel::Lint::Tests
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
@pig = Pig.create!
|
9
|
+
@pigkeeper = Pigkeeper.create! :visited => true, :pockets => 1
|
10
|
+
@attributes = {:follower => @pig, :resource => @pigkeeper}
|
11
|
+
@model = Fauna::Follow.new(@attributes)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_create
|
15
|
+
follow = Fauna::Follow.create(@attributes)
|
16
|
+
assert follow.persisted?
|
17
|
+
assert follow.ref
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_save
|
21
|
+
follow = Fauna::Follow.new(@attributes)
|
22
|
+
follow.save
|
23
|
+
assert follow.persisted?
|
24
|
+
assert follow.ref
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_update
|
28
|
+
follow = Fauna::Follow.create(@attributes)
|
29
|
+
assert_raises(Fauna::Invalid) do
|
30
|
+
follow.update(@attributes)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_find
|
35
|
+
Fauna::Follow.create(@attributes)
|
36
|
+
follow = Fauna::Follow.find_by_follower_and_resource(@pig, @pigkeeper)
|
37
|
+
assert follow.persisted?
|
38
|
+
assert follow.ref
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_destroy
|
42
|
+
follow = Fauna::Follow.create(@attributes)
|
43
|
+
follow.destroy
|
44
|
+
assert !follow.persisted?
|
45
|
+
assert follow.ref
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class PublisherTest < ActiveModel::TestCase
|
4
|
+
# include ActiveModel::Lint::Tests
|
5
|
+
|
6
|
+
class Fauna::Publisher
|
7
|
+
field :visited
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup
|
11
|
+
super
|
12
|
+
@model = Fauna::Publisher.find
|
13
|
+
@attributes = {:visited => true}
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_create
|
17
|
+
assert_raises(Fauna::Invalid) do
|
18
|
+
Fauna::Publisher.create
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_save
|
23
|
+
publisher = Fauna::Publisher.new
|
24
|
+
assert !publisher.persisted?
|
25
|
+
assert_raises(Fauna::Invalid) do
|
26
|
+
publisher.save
|
27
|
+
end
|
28
|
+
|
29
|
+
publisher = Fauna::Publisher.find
|
30
|
+
publisher.save
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_update
|
34
|
+
Fauna::Publisher.find.update(@attributes)
|
35
|
+
assert_equal true, Fauna::Publisher.find.visited
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_find
|
39
|
+
publisher = Fauna::Publisher.find
|
40
|
+
assert_equal "publisher", publisher.ref
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_destroy
|
44
|
+
assert_raises(Fauna::Invalid) do
|
45
|
+
Fauna::Publisher.find.destroy
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
# TODO use association_test classes
|
4
|
+
|
5
|
+
class TimelineTest < ActiveModel::TestCase
|
6
|
+
# include ActiveModel::Lint::Tests
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
@model = MessageBoard.create!
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_page
|
14
|
+
page = @model.posts.page
|
15
|
+
assert_equal page.ref, "#{@model.ref}/timelines/posts"
|
16
|
+
assert_equal page.events.size, 0
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_any
|
20
|
+
@model.posts.add(Post.create(:body => "Hello"))
|
21
|
+
assert @model.posts.page.any?
|
22
|
+
assert @model.posts.page.events.any?
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_timeline_add
|
26
|
+
@model.posts.add(Post.create(:body => "Goodbye"))
|
27
|
+
page = @model.posts.page
|
28
|
+
assert_equal page.events.size, 1
|
29
|
+
assert_equal page.events[0].resource.body, "Goodbye"
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_timeline_remove
|
33
|
+
@model.posts.add(Post.create(:body => "Hello"))
|
34
|
+
page = @model.posts.page
|
35
|
+
assert_equal page.events.size, 1
|
36
|
+
@model.posts.remove(page.events[0].resource)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_local
|
40
|
+
user = Fauna::User.create!(:name => "user", :email => email)
|
41
|
+
|
42
|
+
follow = Fauna::Follow.new(:follower => user, :resource => @model)
|
43
|
+
follow.save!
|
44
|
+
|
45
|
+
post = Post.create(:body => "Goodbye")
|
46
|
+
@model.posts.add(post)
|
47
|
+
|
48
|
+
assert(user.local.page.events.find { |e| e.resource_ref == post.ref })
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.expand_path("../../test_helper", __FILE__)
|
2
|
+
|
3
|
+
class UserTest < ActiveModel::TestCase
|
4
|
+
# include ActiveModel::Lint::Tests
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
@model = Fauna::User.new
|
9
|
+
@attributes = {:name => "Gurgi", :email => email, :password => password, :pockets => "Piggy treats."}
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_create
|
13
|
+
user = Fauna::User.create(@attributes)
|
14
|
+
assert_equal "Gurgi", user.name
|
15
|
+
assert user.persisted?
|
16
|
+
assert user.ref
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_save
|
20
|
+
user = Fauna::User.new(@attributes)
|
21
|
+
user.save
|
22
|
+
assert user.persisted?
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_update
|
26
|
+
user = Fauna::User.new(@attributes)
|
27
|
+
user.save
|
28
|
+
user.update(:pockets => "Nothing")
|
29
|
+
assert_equal "Nothing", user.pockets
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_changes
|
33
|
+
user = Fauna::User.new(@attributes)
|
34
|
+
user.save
|
35
|
+
user.update(:pockets => "Nothing")
|
36
|
+
assert_equal user.changes.page.events.length, 2
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_find
|
40
|
+
user = Fauna::User.create(@attributes)
|
41
|
+
user1 = Fauna::User.find(user.ref)
|
42
|
+
assert_equal user.ref, user1.ref
|
43
|
+
assert user1.persisted?
|
44
|
+
assert_equal user1.pockets, user.pockets
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_destroy
|
48
|
+
user = Fauna::User.create(@attributes)
|
49
|
+
user.destroy
|
50
|
+
assert user.destroyed?
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_find_by_email
|
54
|
+
user = Fauna::User.create(@attributes.merge(:email => "test@example.com"))
|
55
|
+
assert_equal [user], Fauna::User.find_by_email("test@example.com")
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_find_by_name
|
59
|
+
user = Fauna::User.create(@attributes.merge(:name => "Gwystyl"))
|
60
|
+
assert_equal [user], Fauna::User.find_by_name("Gwystyl")
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_user_settings
|
64
|
+
user = Fauna::User.create(@attributes)
|
65
|
+
assert_equal user.settings.ref, "#{user.ref}/settings"
|
66
|
+
end
|
67
|
+
|
68
|
+
# def test_find_by_external_id
|
69
|
+
# user = Fauna::User.create(@attributes.merge(:external_id => "henwen"))
|
70
|
+
# assert_equal [user], Fauna::User.find_by_external_id("henwen")
|
71
|
+
# end
|
72
|
+
end
|