ork 0.0.1 → 0.1.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.
data/test/model.rb DELETED
@@ -1,139 +0,0 @@
1
- # encoding: UTF-8
2
- require_relative 'helper'
3
-
4
- class Event
5
- include Ork::Model
6
-
7
- attribute :name
8
- attribute :location
9
-
10
- unique :name
11
- index :location
12
- end
13
-
14
- Protest.describe 'Ork::Model' do
15
- context 'Definition' do
16
- test 'have an attributes list' do
17
- assert_equal [:name, :location], Event.attributes
18
- end
19
-
20
- test 'have a uniques list' do
21
- assert_equal [:name], Event.uniques
22
- end
23
-
24
- test 'have an indices list' do
25
- assert_equal [:location], Event.indices
26
- end
27
-
28
- test 'model owns a bucket name by default' do
29
- assert_equal 'event', Event.bucket_name
30
- end
31
-
32
- test 'generate accessors for attributes' do
33
- event = Event.new
34
-
35
- assert event.respond_to? :name
36
- assert event.respond_to? :name=
37
- assert event.respond_to? :location
38
- assert event.respond_to? :location=
39
- end
40
-
41
- test 'cast to different types' do
42
- pending 'Define how to cast objects'
43
- end
44
-
45
- test 'model can change bucket name' do
46
- Event.bucket_name= 'other_bucket_for_event'
47
- assert_equal 'other_bucket_for_event', Event.bucket_name
48
- end
49
-
50
- test 'there is a Riak::Bucket corresponding to the model' do
51
- assert_equal Riak::Bucket, Event.bucket.class
52
- end
53
- end
54
-
55
- context 'Instance' do
56
- setup do
57
- @event = Event.new(name: 'Ruby')
58
- end
59
-
60
- test 'determine if it is a new instance or it was saved' do
61
- assert @event.new?
62
- @event.save
63
- assert !@event.new?
64
- end
65
-
66
- test 'assign attributes from the hash' do
67
- assert_equal 'Ruby', @event.name
68
- end
69
-
70
- test 'inspect a new object shows the class, attributes with id nil' do
71
- assert_equal '#<Event:nil {:name=>"Ruby"}>', @event.inspect
72
- end
73
-
74
- test 'inspect a saved object shows the class, attributes with id nil' do
75
- @event.save
76
- assert_equal '#<Event:' + @event.id + ' {:name=>"Ruby"}>', @event.inspect
77
- end
78
-
79
- test 'assign an ID and save the object' do
80
- event = Event.create(name: 'Ruby')
81
-
82
- assert !event.new?
83
- assert !event.id.nil?
84
- end
85
-
86
- test 'update and save the attributes in UTF8' do
87
- @event.update(name: '32° Kisei-sen')
88
- assert_equal '32° Kisei-sen', Event[@event.id].name
89
- end
90
-
91
- test 'update_attributes changes attributes but does not save the object' do
92
- assert @event.new?
93
- assert_equal 'Ruby', @event.name
94
-
95
- @event.update_attributes(name: 'Emerald', location: 4)
96
-
97
- assert @event.new?
98
- assert_equal 'Emerald', @event.name
99
- assert_equal 4, @event.location
100
- end
101
-
102
- context 'Deletion' do
103
- test 'freeze the object' do
104
- assert !@event.frozen?
105
- @event.delete
106
- assert @event.frozen?
107
- end
108
-
109
- test 'delete the object from the bucket' do
110
- @event.save
111
- assert Event.bucket.exist?(@event.id)
112
- @event.delete
113
- assert !Event.bucket.exist?(@event.id)
114
- end
115
- end
116
- end
117
-
118
- context "Equality" do
119
- setup do
120
- @event = Event.new(name: 'Ruby')
121
- @other = Event.new(name: 'Emerald')
122
- end
123
-
124
- test 'different types' do
125
- assert @event != 'Not an event'
126
- end
127
-
128
- test 'saved instances with different ids' do
129
- @event.save
130
- @other.save
131
-
132
- assert @event != @other
133
- end
134
-
135
- test 'unsaved intances' do
136
- pending 'Define how equality will be'
137
- end
138
- end
139
- end
data/test/reference.rb DELETED
@@ -1,73 +0,0 @@
1
- require_relative 'helper'
2
-
3
- class Post
4
- include Ork::Model
5
- attribute :name
6
- end
7
-
8
- class Comment
9
- include Ork::Model
10
- attribute :text
11
-
12
- reference :post, :Post
13
- reference :weird_post, :Post
14
- end
15
-
16
- Protest.describe 'reference' do
17
- teardown do
18
- flush_db!
19
- end
20
-
21
- should 'return nil when there is no reference object' do
22
- comment = Comment.new
23
-
24
- assert comment.post.nil?
25
- end
26
-
27
- should 'raise an exception assigning an object of the wrong type' do
28
- pending 'Not sure to support this'
29
- assert_raise(Error) do
30
- Comment.new post: 'Not a post'
31
- end
32
- end
33
-
34
- should 'return the object referenced' do
35
- post = Post.create name: 'New'
36
- comment = Comment.new post: post
37
-
38
- assert_equal post, comment.post
39
- assert_equal post.id, comment.post_id
40
- end
41
-
42
- test 'object reference with not default key' do
43
- post = Post.create name: 'New'
44
- comment = Comment.new weird_post: post
45
-
46
- assert_equal post, comment.weird_post
47
- assert_equal post.id, comment.weird_post_id
48
- end
49
-
50
- should 'update reference to an object given the id or object' do
51
- post = Post.create name: 'New'
52
- comment = Comment.new
53
-
54
- assert comment.post.nil?
55
- assert comment.post_id.nil?
56
-
57
- comment.post = post
58
-
59
- assert_equal post, comment.post
60
- assert_equal post.id, comment.post_id
61
-
62
- post = Post.create name: 'Other'
63
- comment.post_id = post.id
64
-
65
- assert_equal post, comment.post
66
- assert_equal post.id, comment.post_id
67
- end
68
-
69
- context 'Deletion' do
70
- # Discuss if we want cascade all deletetion and that sort of things
71
- end
72
-
73
- end
@@ -1,15 +0,0 @@
1
- # This is where the test server node will be generated. Something on
2
- # /tmp is usually ok.
3
- root = "/tmp/.ork_node"
4
- min_port = 15000
5
-
6
- # This is where Riak is installed on your system, that is, the path to
7
- # the 'riak' and 'riak-admin' scripts. I use a self-built node, but
8
- # here's where it will generally be on various platforms:
9
- #
10
- # Linux: /usr/sbin
11
- # Solaris/OpenSolaris: /opt/riak/bin
12
- # Mac OS/X (Homebrew): /usr/local/bin
13
- # Source/Self built: /path/to/your/install/rel/riak/bin
14
- #
15
- source = "/usr/local/bin"
@@ -1,15 +0,0 @@
1
- # This is where the test server node will be generated. Something on
2
- # /tmp is usually ok.
3
- root = "/tmp/.ork_node"
4
- min_port = 15000
5
-
6
- # This is where Riak is installed on your system, that is, the path to
7
- # the 'riak' and 'riak-admin' scripts. I use a self-built node, but
8
- # here's where it will generally be on various platforms:
9
- #
10
- # Linux: /usr/sbin
11
- # Solaris/OpenSolaris: /opt/riak/bin
12
- # Mac OS/X (Homebrew): /usr/local/bin
13
- # Source/Self built: /path/to/your/install/rel/riak/bin
14
- #
15
- source = "/usr/local/bin"