fauna 0.2.6 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Manifest +0 -31
- data/README.md +18 -150
- data/Rakefile +1 -1
- data/examples/welcome.rb +3 -3
- data/fauna.gemspec +5 -11
- data/lib/fauna.rb +11 -88
- data/lib/fauna/cache.rb +58 -0
- data/lib/fauna/client.rb +14 -67
- data/lib/fauna/connection.rb +21 -27
- data/lib/fauna/provided_classes.rb +39 -0
- data/lib/fauna/rails.rb +28 -8
- data/lib/fauna/resource.rb +34 -121
- data/lib/fauna/set.rb +184 -0
- data/lib/fauna/util.rb +19 -0
- data/lib/tasks/fauna.rake +61 -1
- data/test/class_test.rb +29 -58
- data/test/client_test.rb +18 -18
- data/test/connection_test.rb +8 -8
- data/test/database_test.rb +47 -0
- data/test/readme_test.rb +2 -3
- data/test/set_test.rb +94 -0
- data/test/test_helper.rb +27 -15
- metadata +14 -57
- data/lib/fauna/ddl.rb +0 -157
- data/lib/fauna/event_set.rb +0 -197
- data/lib/fauna/model.rb +0 -73
- data/lib/fauna/model/class.rb +0 -32
- data/lib/fauna/model/user.rb +0 -23
- data/lib/fauna/publisher.rb +0 -8
- data/test/association_test.rb +0 -23
- data/test/event_set_test.rb +0 -92
- data/test/fixtures.rb +0 -70
- data/test/publisher_test.rb +0 -48
- data/test/user_test.rb +0 -80
- data/test/validation_test.rb +0 -28
data/test/fixtures.rb
DELETED
@@ -1,70 +0,0 @@
|
|
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 :name
|
11
|
-
field :pockets
|
12
|
-
end
|
13
|
-
|
14
|
-
class Fauna::Publisher
|
15
|
-
field :visited
|
16
|
-
end
|
17
|
-
|
18
|
-
class Pig < Fauna::Class
|
19
|
-
field :name, :visited
|
20
|
-
end
|
21
|
-
|
22
|
-
class Pigkeeper < Fauna::Class
|
23
|
-
field :visited, :pockets
|
24
|
-
|
25
|
-
validates :visited, :presence => true
|
26
|
-
validate :pockets_are_full
|
27
|
-
|
28
|
-
def pockets_are_full
|
29
|
-
errors.add :pockets, 'must be full of piggy treats' if pockets <= 0 unless pockets.blank?
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class Vision < Fauna::Class
|
34
|
-
field :pronouncement
|
35
|
-
reference :pig
|
36
|
-
end
|
37
|
-
|
38
|
-
class MessageBoard < Fauna::Class
|
39
|
-
end
|
40
|
-
|
41
|
-
class Post < Fauna::Class
|
42
|
-
field :body
|
43
|
-
end
|
44
|
-
|
45
|
-
class Comment < Fauna::Class
|
46
|
-
field :body
|
47
|
-
end
|
48
|
-
|
49
|
-
Fauna.schema do |f|
|
50
|
-
with Pig, :class_name => "classes/pigs" do
|
51
|
-
event_set :visions
|
52
|
-
end
|
53
|
-
|
54
|
-
with Pigkeeper
|
55
|
-
|
56
|
-
with Vision
|
57
|
-
|
58
|
-
with MessageBoard, :class_name => "classes/board" do
|
59
|
-
event_set :posts
|
60
|
-
end
|
61
|
-
|
62
|
-
with Post do
|
63
|
-
event_set :comments
|
64
|
-
end
|
65
|
-
|
66
|
-
with Comment
|
67
|
-
|
68
|
-
# use-case: using the ruby gem to define a schema for another environment.
|
69
|
-
with :class_name => "classes/anon"
|
70
|
-
end
|
data/test/publisher_test.rb
DELETED
@@ -1,48 +0,0 @@
|
|
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
|
data/test/user_test.rb
DELETED
@@ -1,80 +0,0 @@
|
|
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_all
|
20
|
-
user = Fauna::User.create(@attributes)
|
21
|
-
assert Fauna::User.all.resources.include?(user)
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_save
|
25
|
-
user = Fauna::User.new(@attributes)
|
26
|
-
user.save
|
27
|
-
assert user.persisted?
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_update
|
31
|
-
user = Fauna::User.new(@attributes)
|
32
|
-
user.save
|
33
|
-
user.update(:pockets => "Nothing")
|
34
|
-
assert_equal "Nothing", user.pockets
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_changes
|
38
|
-
user = Fauna::User.new(@attributes)
|
39
|
-
user.save
|
40
|
-
user.update(:pockets => "Nothing")
|
41
|
-
assert_equal user.changes.page.events.length, 2
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_find_by_ref
|
45
|
-
user = Fauna::User.create(@attributes)
|
46
|
-
user1 = Fauna::User.find_by_ref(user.ref)
|
47
|
-
assert_equal user.ref, user1.ref
|
48
|
-
assert user1.persisted?
|
49
|
-
assert_equal user1.pockets, user.pockets
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_destroy
|
53
|
-
user = Fauna::User.create(@attributes)
|
54
|
-
user.destroy
|
55
|
-
assert user.destroyed?
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_find_by_email
|
59
|
-
user = Fauna::User.create(@attributes.merge(:email => "test@example.com"))
|
60
|
-
assert_equal user, Fauna::User.find_by_email("test@example.com")
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_user_config
|
64
|
-
user = Fauna::User.create(@attributes)
|
65
|
-
assert_equal user.config.ref, "#{user.ref}/config"
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_find_by_unique_id
|
69
|
-
user = Fauna::User.create(@attributes.merge(:unique_id => "henwen"))
|
70
|
-
assert_equal user, Fauna::User.find_by_unique_id("henwen")
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_find
|
74
|
-
user = Fauna::User.create(@attributes)
|
75
|
-
user1 = Fauna::User.find(user.id)
|
76
|
-
assert_equal user.ref, user1.ref
|
77
|
-
assert user1.persisted?
|
78
|
-
assert_equal user1.pockets, user.pockets
|
79
|
-
end
|
80
|
-
end
|
data/test/validation_test.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class ClassValidationTest < MiniTest::Unit::TestCase
|
4
|
-
def test_validates_presence_of_field
|
5
|
-
h = Pigkeeper.new(:visited => nil)
|
6
|
-
refute h.valid?
|
7
|
-
refute h.save
|
8
|
-
assert_equal ["can't be blank"], h.errors[:visited],
|
9
|
-
|
10
|
-
h.visited = true
|
11
|
-
assert h.save
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_fails_save!
|
15
|
-
h = Pigkeeper.new(:visited => nil)
|
16
|
-
assert_raises(Fauna::Invalid) { h.save! }
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_validate_callback
|
20
|
-
h = Pigkeeper.new(:visited => true, :pockets => 0)
|
21
|
-
refute h.valid?
|
22
|
-
refute h.save
|
23
|
-
assert_equal ["must be full of piggy treats"], h.errors[:pockets]
|
24
|
-
|
25
|
-
h.pockets = 1
|
26
|
-
assert h.save
|
27
|
-
end
|
28
|
-
end
|