fauna 0.2.6 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,13 +7,13 @@ class ConnectionTest < MiniTest::Unit::TestCase
7
7
  end
8
8
 
9
9
  def test_get
10
- @publisher_connection.get("users")
10
+ @server_connection.get("users/instances")
11
11
  end
12
12
 
13
13
  def test_get_with_invalid_key
14
- connection = Fauna::Connection.new(:publisher_key => 'bad_key')
14
+ connection = Fauna::Connection.new(:secret => 'bad_key', :domain => @server_connection.domain, :scheme => @server_connection.scheme)
15
15
  assert_raises(Fauna::Connection::Unauthorized) do
16
- connection.get("users")
16
+ connection.get("users/instances")
17
17
  end
18
18
  end
19
19
 
@@ -22,16 +22,16 @@ class ConnectionTest < MiniTest::Unit::TestCase
22
22
  end
23
23
 
24
24
  def test_put
25
- user = @publisher_connection.post("users", @attributes)['resource']
26
- user = @publisher_connection.put(user['ref'], {:data => {:pockets => 2}})['resource']
25
+ user = @server_connection.post("users", @attributes)['resource']
26
+ user = @server_connection.put(user['ref'], {:data => {:pockets => 2}})['resource']
27
27
  assert_equal 2, user['data']['pockets']
28
28
  end
29
29
 
30
30
  def test_delete
31
- user = @publisher_connection.post("users", @attributes)['resource']
32
- @publisher_connection.delete(user['ref'])
31
+ user = @server_connection.post("users", @attributes)['resource']
32
+ @server_connection.delete(user['ref'])
33
33
  assert_raises(Fauna::Connection::NotFound) do
34
- @publisher_connection.get(user['ref'])
34
+ @server_connection.get(user['ref'])
35
35
  end
36
36
  end
37
37
  end
@@ -0,0 +1,47 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class DatabaseTest < MiniTest::Unit::TestCase
4
+
5
+ def setup
6
+ super
7
+ @model = Fauna::Database.new("ref" => "databases/fauna-ruby-test2")
8
+ Fauna::Client.context(@root_connection) do
9
+ @model.save
10
+ end
11
+ end
12
+
13
+ def test_create
14
+ assert_raises(Fauna::Connection::Unauthorized) do
15
+ @model.save
16
+ end
17
+ end
18
+
19
+ def test_find
20
+ assert_raises(Fauna::Connection::Unauthorized) do
21
+ Fauna::Database.find(@model.ref)
22
+ end
23
+ Fauna::Client.context(@root_connection) do
24
+ assert_equal @model, Fauna::Database.find(@model.ref)
25
+ end
26
+ end
27
+
28
+ def test_self
29
+ database = Fauna::Resource.find('databases/self')
30
+ assert_equal "databases/fauna-ruby-test", database.ref
31
+
32
+ assert_raises(Fauna::Connection::BadRequest) do
33
+ Fauna::Client.context(@root_connection) do
34
+ Fauna::Resource.find('databases/self')
35
+ end
36
+ end
37
+ end
38
+
39
+ def test_destroy
40
+ assert_raises(Fauna::Connection::Unauthorized) do
41
+ Fauna::Resource.find('databases/self').delete
42
+ end
43
+ Fauna::Client.context(@root_connection) do
44
+ @model.delete
45
+ end
46
+ end
47
+ end
data/test/readme_test.rb CHANGED
@@ -8,9 +8,7 @@ class ReadmeTest < MiniTest::Unit::TestCase
8
8
  sections.select do |text|
9
9
  if text =~ /^ruby/
10
10
  next if text =~ /ActionController|logger/
11
- text.gsub!("publisher@example.com", FAUNA_TEST_EMAIL)
12
- text.gsub!("secret", FAUNA_TEST_PASSWORD)
13
- text.gsub!("Fauna.connection", "$fauna")
11
+ text.gsub!('$fauna = Fauna::Connection.new(secret: server_key)', '$fauna = SERVER_CONNECTION')
14
12
  code << text[4..-1]
15
13
  end
16
14
  end
@@ -26,6 +24,7 @@ class ReadmeTest < MiniTest::Unit::TestCase
26
24
  puts e.backtrace
27
25
  raise
28
26
  end
27
+
29
28
  File.delete(tmp.path)
30
29
  end
31
30
  end
data/test/set_test.rb ADDED
@@ -0,0 +1,94 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ # TODO use association_test classes
4
+
5
+ class SetTest < MiniTest::Unit::TestCase
6
+
7
+ def setup
8
+ super
9
+ @model = Fauna::Resource.create 'classes/message_boards'
10
+ @posts = @model.set 'posts'
11
+ end
12
+
13
+ def test_page
14
+ page = @posts.page
15
+ assert_equal "#{@model.ref}/sets/posts", page.ref
16
+ assert_equal 0, page.refs.size
17
+ end
18
+
19
+ def test_pagination
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
+ page2 = @posts.page(:size => 2, :before => page1.before)
29
+ assert_equal 2, page2.refs.size
30
+ page3 = @posts.page(:size => 2, :before => page2.before)
31
+ assert_equal 1, page3.refs.size
32
+
33
+ page4 = @posts.page(:size => 2, :after => page3.refs.last)
34
+ assert_equal 2, page4.refs.size
35
+ page5 = @posts.page(:size => 2, :after => page4.after)
36
+ assert_equal 2, page5.refs.size
37
+ page6 = @posts.page(:size => 2, :after => page5.refs.first)
38
+ assert_equal 1, page6.refs.size
39
+ end
40
+
41
+ def test_any
42
+ @posts.add(Fauna::Resource.create 'classes/posts')
43
+ assert @posts.page.any?
44
+ assert @posts.page.refs.any?
45
+ assert @posts.events.any?
46
+ assert @posts.events.events.any?
47
+ end
48
+
49
+ def test_event_set_add
50
+ post = Fauna::Resource.create 'classes/posts'
51
+ @posts.add(post)
52
+ page = @posts.page
53
+ assert_equal 1, page.refs.size
54
+ assert_equal post.ref, page.refs[0]
55
+ end
56
+
57
+ def test_event_set_remove
58
+ @posts.add(Fauna::Resource.create 'classes/posts')
59
+ page = @posts.page
60
+ assert_equal 1, page.refs.size
61
+ @posts.remove(page.refs[0])
62
+ end
63
+
64
+ def test_event_set_refs
65
+ post = Fauna::Resource.create 'classes/posts'
66
+ @posts.add(post)
67
+ assert_equal [post.ref], @posts.page.refs
68
+ end
69
+
70
+ def test_event_set_query
71
+ posts = (1..3).map do |i|
72
+ Fauna::Resource.create('classes/posts').tap do |p|
73
+ @posts.add(p)
74
+ end
75
+ end
76
+
77
+ comments = posts.map do |p|
78
+ (1..3).map do |i|
79
+ Fauna::Resource.create('classes/comments').tap do |c|
80
+ comments = Fauna::CustomSet.new("#{p.ref}/sets/comments")
81
+ comments.add(c)
82
+ end
83
+ end
84
+ end
85
+
86
+ q = Fauna::Set.join(@posts, 'sets/comments')
87
+
88
+ assert_equal 9, q.page.size
89
+
90
+ comments.flatten.each do |c|
91
+ assert q.page.include?(c.ref)
92
+ end
93
+ end
94
+ end
data/test/test_helper.rb CHANGED
@@ -7,34 +7,46 @@ require "fauna"
7
7
  require "securerandom"
8
8
  require "mocha/setup"
9
9
 
10
- FAUNA_TEST_EMAIL = ENV["FAUNA_TEST_EMAIL"]
11
- FAUNA_TEST_PASSWORD = ENV["FAUNA_TEST_PASSWORD"]
10
+ FAUNA_TEST_ROOTKEY = ENV["FAUNA_TEST_ROOTKEY"]
11
+ FAUNA_TEST_DOMAIN = ENV["FAUNA_TEST_DOMAIN"]
12
+ FAUNA_TEST_SCHEME = ENV["FAUNA_TEST_SCHEME"]
12
13
 
13
- if !(FAUNA_TEST_PASSWORD && FAUNA_TEST_PASSWORD)
14
- raise "FAUNA_TEST_EMAIL and FAUNA_TEST_PASSWORD must be defined in your environment to run tests."
14
+ if !(FAUNA_TEST_ROOTKEY && FAUNA_TEST_DOMAIN && FAUNA_TEST_SCHEME)
15
+ raise "FAUNA_TEST_ROOTKEY, FAUNA_TEST_DOMAIN and FAUNA_TEST_SCHEME must be defined in your environment to run tests."
15
16
  end
16
17
 
17
- ROOT_CONNECTION = Fauna::Connection.new(:email => FAUNA_TEST_EMAIL, :password => FAUNA_TEST_PASSWORD)
18
- ROOT_CONNECTION.delete("everything")
18
+ ROOT_CONNECTION = Fauna::Connection.new(:secret => FAUNA_TEST_ROOTKEY, :domain => FAUNA_TEST_DOMAIN, :scheme => FAUNA_TEST_SCHEME)
19
19
 
20
- key = ROOT_CONNECTION.post("keys/publisher")['resource']['key']
21
- PUBLISHER_CONNECTION = Fauna::Connection.new(:publisher_key => key)
20
+ Fauna::Client.context(ROOT_CONNECTION) do
21
+ Fauna::Database.new(:name => "fauna-ruby-test").delete rescue nil
22
+ Fauna::Database.create(:name => "fauna-ruby-test")
22
23
 
23
- key = ROOT_CONNECTION.post("keys/client")['resource']['key']
24
- CLIENT_CONNECTION = Fauna::Connection.new(:client_key => key)
24
+ server_key = Fauna::Key.create :database => "databases/fauna-ruby-test", :role => "server"
25
+ client_key = Fauna::Key.create :database => "databases/fauna-ruby-test", :role => "client"
25
26
 
26
- load "#{File.dirname(__FILE__)}/fixtures.rb"
27
+ SERVER_CONNECTION = Fauna::Connection.new(:secret => server_key.secret, :domain => FAUNA_TEST_DOMAIN, :scheme => FAUNA_TEST_SCHEME)
28
+ CLIENT_CONNECTION = Fauna::Connection.new(:secret => client_key.secret, :domain => FAUNA_TEST_DOMAIN, :scheme => FAUNA_TEST_SCHEME)
29
+ end
30
+
31
+ # fixtures
27
32
 
28
- Fauna::Client.context(PUBLISHER_CONNECTION) do
29
- Fauna.migrate_schema!
33
+ Fauna::Client.context(SERVER_CONNECTION) do
34
+ Fauna::Class.create :name => 'pigs'
35
+ Fauna::Class.create :name => 'pigkeepers'
36
+ Fauna::Class.create :name => 'visions'
37
+ Fauna::Class.create :name => 'message_boards'
38
+ Fauna::Class.create :name => 'posts'
39
+ Fauna::Class.create :name => 'comments'
30
40
  end
31
41
 
42
+ # test harness
43
+
32
44
  class MiniTest::Unit::TestCase
33
45
  def setup
34
46
  @root_connection = ROOT_CONNECTION
35
- @publisher_connection = PUBLISHER_CONNECTION
47
+ @server_connection = SERVER_CONNECTION
36
48
  @client_connection = CLIENT_CONNECTION
37
- Fauna::Client.push_context(@publisher_connection)
49
+ Fauna::Client.push_context(@server_connection)
38
50
  end
39
51
 
40
52
  def teardown
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fauna
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,40 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-03 00:00:00.000000000 Z
12
+ date: 2013-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: activemodel
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: activesupport
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :runtime
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
14
  - !ruby/object:Gem::Dependency
47
15
  name: rest-client
48
16
  requirement: !ruby/object:Gem::Requirement
@@ -132,16 +100,14 @@ extra_rdoc_files:
132
100
  - LICENSE
133
101
  - README.md
134
102
  - lib/fauna.rb
103
+ - lib/fauna/cache.rb
135
104
  - lib/fauna/client.rb
136
105
  - lib/fauna/connection.rb
137
- - lib/fauna/ddl.rb
138
- - lib/fauna/event_set.rb
139
- - lib/fauna/model.rb
140
- - lib/fauna/model/class.rb
141
- - lib/fauna/model/user.rb
142
- - lib/fauna/publisher.rb
106
+ - lib/fauna/provided_classes.rb
143
107
  - lib/fauna/rails.rb
144
108
  - lib/fauna/resource.rb
109
+ - lib/fauna/set.rb
110
+ - lib/fauna/util.rb
145
111
  - lib/tasks/fauna.rake
146
112
  files:
147
113
  - CHANGELOG
@@ -153,28 +119,22 @@ files:
153
119
  - examples/welcome.rb
154
120
  - fauna.gemspec
155
121
  - lib/fauna.rb
122
+ - lib/fauna/cache.rb
156
123
  - lib/fauna/client.rb
157
124
  - lib/fauna/connection.rb
158
- - lib/fauna/ddl.rb
159
- - lib/fauna/event_set.rb
160
- - lib/fauna/model.rb
161
- - lib/fauna/model/class.rb
162
- - lib/fauna/model/user.rb
163
- - lib/fauna/publisher.rb
125
+ - lib/fauna/provided_classes.rb
164
126
  - lib/fauna/rails.rb
165
127
  - lib/fauna/resource.rb
128
+ - lib/fauna/set.rb
129
+ - lib/fauna/util.rb
166
130
  - lib/tasks/fauna.rake
167
- - test/association_test.rb
168
131
  - test/class_test.rb
169
132
  - test/client_test.rb
170
133
  - test/connection_test.rb
171
- - test/event_set_test.rb
172
- - test/fixtures.rb
173
- - test/publisher_test.rb
134
+ - test/database_test.rb
174
135
  - test/readme_test.rb
136
+ - test/set_test.rb
175
137
  - test/test_helper.rb
176
- - test/user_test.rb
177
- - test/validation_test.rb
178
138
  homepage: http://fauna.github.com/fauna/
179
139
  licenses: []
180
140
  post_install_message:
@@ -206,13 +166,10 @@ signing_key:
206
166
  specification_version: 3
207
167
  summary: Official Ruby client for the Fauna API.
208
168
  test_files:
209
- - test/association_test.rb
210
169
  - test/class_test.rb
211
170
  - test/client_test.rb
212
171
  - test/connection_test.rb
213
- - test/event_set_test.rb
214
- - test/publisher_test.rb
172
+ - test/database_test.rb
215
173
  - test/readme_test.rb
174
+ - test/set_test.rb
216
175
  - test/test_helper.rb
217
- - test/user_test.rb
218
- - test/validation_test.rb
data/lib/fauna/ddl.rb DELETED
@@ -1,157 +0,0 @@
1
- module Fauna
2
- class DDL
3
-
4
- def initialize
5
- @ddls = []
6
- end
7
-
8
- def configure!
9
- @ddls.each { |ddl| ddl.configure! }
10
- end
11
-
12
- def load!
13
- @ddls.each { |ddl| ddl.load! }
14
- end
15
-
16
- # resources
17
-
18
- def with(*args, &block)
19
- options = args.last.is_a?(Hash) ? args.pop : {}
20
- klass = args.first
21
- res = ResourceDDL.new(klass, options)
22
- res.instance_eval(&block) if block_given?
23
- @ddls << res
24
- nil
25
- end
26
-
27
- class ResourceDDL
28
- def initialize(klass, args = {})
29
- unless klass || args[:class_name]
30
- raise ArgumentError, "Must either provide a class or specify :class_name."
31
- end
32
-
33
- @event_sets = []
34
- @class = klass || derived_class(args[:class_name])
35
- @fauna_class = args[:class_name] || derived_fauna_class(@class)
36
-
37
- unless @class <= max_super(@fauna_class)
38
- raise ArgumentError, "#{@class} must be a subclass of #{max_super(@fauna_class)}."
39
- end
40
-
41
- if @fauna_class =~ %r{^classes/[^/]+$} && @fauna_class != 'classes/config'
42
- @meta = Fauna::ClassConfig.alloc('ref' => "#{@fauna_class}/config")
43
- end
44
- end
45
-
46
- def configure!
47
- Fauna.add_class(@fauna_class, @class) if @class
48
- end
49
-
50
- def load!
51
- @meta.save! if @meta
52
- @event_sets.each { |t| t.load! }
53
- end
54
-
55
- def event_set(*name)
56
- args = name.last.is_a?(Hash) ? name.pop : {}
57
- @class.send :event_set, *name
58
-
59
- name.each { |n| @event_sets << EventSetDDL.new(@fauna_class, n, args) }
60
- end
61
-
62
- def field(*name)
63
- @class.send :field, *name
64
- end
65
-
66
- def reference(*name)
67
- @class.send :reference, *name
68
- end
69
-
70
- private
71
-
72
- def max_super(name)
73
- case name
74
- when "users" then Fauna::User
75
- when "publisher" then Fauna::Publisher
76
- when "classes/config" then Fauna::Resource
77
- when %r{^classes/[^/]+$} then Fauna::Class
78
- else Fauna::Resource
79
- end
80
- end
81
-
82
- def derived_class(name)
83
- s = max_super(name)
84
- case s
85
- when Fauna::Class then Class.new(Fauna::Class)
86
- when Fauna::Resource then Class.new(Fauna::Resource)
87
- else s
88
- end
89
- end
90
-
91
- def derived_fauna_class(klass)
92
- if klass < Fauna::User
93
- "users"
94
- elsif klass < Fauna::Publisher
95
- "publisher"
96
- elsif klass < Fauna::Class
97
- "classes/#{klass.name.tableize}"
98
- else
99
- raise ArgumentError, "Must specify a :class_name for non-default resource class #{klass.name}"
100
- end
101
- end
102
- end
103
-
104
- # event_sets
105
-
106
- class EventSetDDL
107
- def initialize(parent_class, name, args)
108
- @meta = EventSetConfig.new(parent_class, name, args)
109
- end
110
-
111
- def configure!
112
- end
113
-
114
- def load!
115
- @meta.save!
116
- end
117
- end
118
-
119
- # commands
120
-
121
- # def command(name)
122
- # cmd = CommandDDL.new(name)
123
-
124
- # yield cmd
125
- # @ddls << cmd
126
-
127
- # nil
128
- # end
129
-
130
- # class CommandDDL
131
- # attr_accessor :comment
132
-
133
- # def initialize(name)
134
- # @actions = []
135
- # end
136
-
137
- # def configure!
138
- # end
139
-
140
- # def load!
141
- # end
142
-
143
- # def get(path, args = {})
144
- # args.update method: 'GET', path: path
145
- # args.stringify_keys!
146
-
147
- # @actions << args
148
- # end
149
- # end
150
- end
151
-
152
- # c.command "name" do |cmd|
153
- # cmd.comment = "foo bar"
154
-
155
- # cmd.get "users/self", :actor => "blah", :body => {}
156
- # end
157
- end