fauna 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,10 +1,12 @@
1
- v0.2.5 Anonymous class configuration
1
+ v0.2.6 Implement set paging.
2
2
 
3
- v0.2.4 Event set query API
3
+ v0.2.5 Anonymous class configuration.
4
4
 
5
- v0.2.3 Event set API enhancements
5
+ v0.2.4 Event set query API.
6
6
 
7
- v0.2.2 Support for Fauna API version 1
7
+ v0.2.3 Event set API enhancements.
8
+
9
+ v0.2.2 Support for Fauna API version 1.
8
10
 
9
11
  v0.1.2 Fauna::User.find_by_external_id returns a User or nil, not an Array.
10
12
 
data/Manifest CHANGED
@@ -17,6 +17,7 @@ lib/fauna/model/user.rb
17
17
  lib/fauna/publisher.rb
18
18
  lib/fauna/rails.rb
19
19
  lib/fauna/resource.rb
20
+ lib/tasks/fauna.rake
20
21
  test/association_test.rb
21
22
  test/class_test.rb
22
23
  test/client_test.rb
data/README.md CHANGED
@@ -95,7 +95,7 @@ Fauna::Client.context($fauna) do
95
95
 
96
96
  # fields
97
97
  user.ref # => "users/123"
98
- user.ts # => 1359579766996758
98
+ user.ts # => 2013-01-30 13:02:46 -0800
99
99
  user.deleted # => false
100
100
  user.unique_id # => "taran77"
101
101
 
@@ -120,11 +120,16 @@ controllers, based on credentials in `config/fauna.yml`:
120
120
  development:
121
121
  email: taran@example.com
122
122
  password: secret
123
+ publisher_key: secret_key
123
124
  test:
124
125
  email: taran@example.com
125
126
  password: secret
126
127
  ```
127
128
 
129
+ (In `config/fauna.yml`, if an existing publisher key is specified, the
130
+ email and password can be omitted. If a publisher key is not
131
+ specified, a new one will be created each time the app is started.)
132
+
128
133
  Then, in `config/initializers/fauna.rb`:
129
134
 
130
135
  ```ruby
@@ -170,8 +175,8 @@ Fauna.schema do
170
175
  end
171
176
  ```
172
177
 
173
- Install your schema on the server via a Rake task or the Rails
174
- console:
178
+ Install your schema on the server via the `fauna:migrate` Rake task,
179
+ or directly from the Rails console:
175
180
 
176
181
  ```ruby
177
182
  Fauna::Client.context(Fauna.connection) do
@@ -210,7 +215,7 @@ end
210
215
  Fauna::Client.context($fauna) do
211
216
  @pig = Pig.create!(name: "Henwen", unique_id: "henwen")
212
217
 
213
- @pig = Pig.find(@pig.ref)
218
+ @pig = Pig.find(@pig.id)
214
219
  @pig.update(title: "Oracular Swine")
215
220
 
216
221
  @pig.title = "Most Illustrious Oracular Swine"
@@ -232,7 +237,12 @@ Fauna::Client.context($fauna) do
232
237
 
233
238
  @vision = Vision.create!(pronouncement: "In an ominous tower...")
234
239
  @pig.visions.add @vision
235
- @pig.visions.page.events.first.resource # => @vision
240
+
241
+ page = @pig.visions.page(:size => 2)
242
+ page.events.first.resource # => @vision
243
+
244
+ next_page = @pig.visions.page(:size => 2, :before => page.before)
245
+ prev_page = @pig.visions.page(:size => 2, :after => page.after)
236
246
  end
237
247
  ```
238
248
 
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+ # Ruby 1.9 required
3
+
4
+ require "rubygems"
5
+ require "pp"
6
+ begin
7
+ require "fauna"
8
+ rescue LoadError
9
+ puts "Please run: sudo gem install fauna"
10
+ exit!
11
+ end
12
+
13
+ print "Email: "
14
+ email = gets.chomp
15
+
16
+ print "Password: "
17
+ pass = gets.chomp
18
+
19
+ puts "\nConnected to Fauna Cloud Platform."
20
+
21
+ puts "\nCreating a publisher key:"
22
+ root = Fauna::Connection.new(email: email, password: pass)
23
+ key = root.post("keys/publisher")['resource']['key']
24
+ $fauna = Fauna::Connection.new(publisher_key: key)
25
+ pp key
26
+
27
+ puts "\nCreating classes:"
28
+ class User < Fauna::User
29
+ pp self
30
+ end
31
+
32
+ class Spell < Fauna::Class
33
+ pp self
34
+ end
35
+
36
+ puts "\nCreating an event set."
37
+ Fauna.schema do
38
+ with User do
39
+ event_set :spellbook
40
+ end
41
+
42
+ with Spell
43
+ end
44
+
45
+ Fauna::Client.context($fauna) do
46
+ puts "\nMigrating."
47
+ Fauna.migrate_schema!
48
+
49
+ puts "\nCreating a user:"
50
+ user = User.create!(
51
+ email: "#{object_id}@example.com",
52
+ password: "1234",
53
+ data: {
54
+ name: "Taran",
55
+ profession: "Pigkeeper",
56
+ location: "Caer Dallben"
57
+ })
58
+ pp user.struct
59
+
60
+ puts "\nCreating an instance:"
61
+ spell = Spell.create!(
62
+ data: {
63
+ pronouncement: "Draw Dyrnwyn only thou of royal blood.",
64
+ title: "Protector of Dyrnwyn"
65
+ })
66
+ pp spell.struct
67
+
68
+ puts "\nAdding the instance to the user's event set."
69
+ user.spellbook.add(spell)
70
+
71
+ puts "\nFetching the event set:"
72
+ pp user.spellbook.page.struct
73
+ end
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "fauna"
5
- s.version = "0.2.5"
5
+ s.version = "0.2.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Fauna, Inc."]
9
- s.date = "2013-03-11"
9
+ s.date = "2013-04-03"
10
10
  s.description = "Official Ruby client for the Fauna API."
11
11
  s.email = ""
12
- s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.md", "lib/fauna.rb", "lib/fauna/client.rb", "lib/fauna/connection.rb", "lib/fauna/ddl.rb", "lib/fauna/event_set.rb", "lib/fauna/model.rb", "lib/fauna/model/class.rb", "lib/fauna/model/user.rb", "lib/fauna/publisher.rb", "lib/fauna/rails.rb", "lib/fauna/resource.rb"]
13
- s.files = ["CHANGELOG", "Gemfile", "LICENSE", "Manifest", "README.md", "Rakefile", "fauna.gemspec", "lib/fauna.rb", "lib/fauna/client.rb", "lib/fauna/connection.rb", "lib/fauna/ddl.rb", "lib/fauna/event_set.rb", "lib/fauna/model.rb", "lib/fauna/model/class.rb", "lib/fauna/model/user.rb", "lib/fauna/publisher.rb", "lib/fauna/rails.rb", "lib/fauna/resource.rb", "test/association_test.rb", "test/class_test.rb", "test/client_test.rb", "test/connection_test.rb", "test/event_set_test.rb", "test/fixtures.rb", "test/publisher_test.rb", "test/readme_test.rb", "test/test_helper.rb", "test/user_test.rb", "test/validation_test.rb"]
12
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.md", "lib/fauna.rb", "lib/fauna/client.rb", "lib/fauna/connection.rb", "lib/fauna/ddl.rb", "lib/fauna/event_set.rb", "lib/fauna/model.rb", "lib/fauna/model/class.rb", "lib/fauna/model/user.rb", "lib/fauna/publisher.rb", "lib/fauna/rails.rb", "lib/fauna/resource.rb", "lib/tasks/fauna.rake"]
13
+ s.files = ["CHANGELOG", "Gemfile", "LICENSE", "Manifest", "README.md", "Rakefile", "examples/welcome.rb", "fauna.gemspec", "lib/fauna.rb", "lib/fauna/client.rb", "lib/fauna/connection.rb", "lib/fauna/ddl.rb", "lib/fauna/event_set.rb", "lib/fauna/model.rb", "lib/fauna/model/class.rb", "lib/fauna/model/user.rb", "lib/fauna/publisher.rb", "lib/fauna/rails.rb", "lib/fauna/resource.rb", "lib/tasks/fauna.rake", "test/association_test.rb", "test/class_test.rb", "test/client_test.rb", "test/connection_test.rb", "test/event_set_test.rb", "test/fixtures.rb", "test/publisher_test.rb", "test/readme_test.rb", "test/test_helper.rb", "test/user_test.rb", "test/validation_test.rb"]
14
14
  s.homepage = "http://fauna.github.com/fauna/"
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Fauna", "--main", "README.md"]
16
16
  s.require_paths = ["lib"]
@@ -1,5 +1,6 @@
1
1
  require "json"
2
2
  require "logger"
3
+ require "uri"
3
4
 
4
5
  require "restclient"
5
6
  require "active_model"
@@ -7,6 +8,10 @@ require "active_support/inflector"
7
8
  require "active_support/core_ext/module/delegation"
8
9
  require "active_support/core_ext/hash/slice"
9
10
 
11
+ if defined?(Rake)
12
+ load "#{File.dirname(__FILE__)}/tasks/fauna.rake"
13
+ end
14
+
10
15
  module Fauna
11
16
  class Invalid < RuntimeError
12
17
  end
@@ -48,9 +48,12 @@ module Fauna
48
48
  end
49
49
 
50
50
  def cohere(ref, res)
51
- @cache[ref] = res['resource'] if ref =~ %r{^users/self}
52
- @cache[res['resource']['ref']] = res['resource']
53
- @cache.merge!(res['references'] || {})
51
+ # FIXME Implement set range caching
52
+ if (res['resource']['class'] != "sets")
53
+ @cache[ref] = res['resource'] if ref =~ %r{^users/self}
54
+ @cache[res['resource']['ref']] = res['resource']
55
+ @cache.merge!(res['references'] || {})
56
+ end
54
57
  end
55
58
  end
56
59
 
@@ -100,6 +100,14 @@ module Fauna
100
100
  end
101
101
  end
102
102
 
103
+ def query_string_for_logging(query)
104
+ if query
105
+ "?" + query.map do |k,v|
106
+ "#{k}=#{v}"
107
+ end.join("&")
108
+ end
109
+ end
110
+
103
111
  def execute(action, ref, data = nil, query = nil)
104
112
  args = { :method => action, :url => url(ref), :headers => {} }
105
113
 
@@ -113,8 +121,7 @@ module Fauna
113
121
  end
114
122
 
115
123
  if @logger
116
- log(2) { "Fauna #{action.to_s.upcase}(\"#{ref}\")" }
117
- log(4) { "Request query: #{JSON.pretty_generate(query)}" } if query
124
+ log(2) { "Fauna #{action.to_s.upcase}(\"#{ref}#{query_string_for_logging(query)}\")" }
118
125
  log(4) { "Request JSON: #{JSON.pretty_generate(data)}" } if @debug && data
119
126
 
120
127
  t0, r0 = Process.times, Time.now
@@ -1,25 +1,30 @@
1
1
 
2
2
  module Fauna
3
3
  class SetRef
4
- attr_reader :ts, :resource_ref
5
-
6
4
  def initialize(attrs)
7
- @ts = attrs['ts']
8
- @resource_ref = attrs['resource']
5
+ @attrs = attrs
6
+ end
7
+
8
+ def ts
9
+ Resource.time_from_usecs(@attrs['ts'])
10
+ end
11
+
12
+ def resource_ref
13
+ @attrs['resource']
9
14
  end
10
15
 
11
16
  def resource
12
- Fauna::Resource.find(resource_ref)
17
+ Fauna::Resource.find_by_ref(resource_ref)
13
18
  end
14
19
  end
15
20
 
16
21
  class Event < SetRef
17
- attr_reader :set_ref, :action
22
+ def set_ref
23
+ @attrs['set']
24
+ end
18
25
 
19
- def initialize(attrs)
20
- super(attrs)
21
- @set_ref = attrs['set']
22
- @action = attrs['action']
26
+ def action
27
+ @attrs['action']
23
28
  end
24
29
 
25
30
  def set
@@ -31,9 +36,22 @@ module Fauna
31
36
  include Enumerable
32
37
 
33
38
  def self.find(ref, query = nil)
39
+ if query
40
+ query = query.merge(:before => usecs_from_time(query[:before])) if query[:before]
41
+ query = query.merge(:after => usecs_from_time(query[:after])) if query[:after]
42
+ end
43
+
34
44
  alloc(Fauna::Client.get(ref, query).to_hash)
35
45
  end
36
46
 
47
+ def before
48
+ struct['before'] ? Resource.time_from_usecs(struct['before']) : nil
49
+ end
50
+
51
+ def after
52
+ struct['after'] ? Resource.time_from_usecs(struct['after']) : nil
53
+ end
54
+
37
55
  def events
38
56
  @events ||= struct['events'].map { |e| Event.new(e) }
39
57
  end
@@ -18,12 +18,20 @@ module Fauna
18
18
  Fauna::EventSet.new(fauna_class)
19
19
  end
20
20
 
21
- def self.find_by_id(id)
22
- Fauna::Resource.find("#{fauna_class}/#{id}")
21
+ def self.find_by_ref(ref)
22
+ Fauna::Resource.find_by_ref(URI.escape(ref))
23
23
  end
24
24
 
25
25
  def self.find_by_unique_id(unique_id)
26
- find("#{fauna_class}/unique_id/#{unique_id}")
26
+ find_by_ref("#{fauna_class}/unique_id/#{unique_id}")
27
+ end
28
+
29
+ def self.find(id)
30
+ find_by_ref("#{fauna_class}/#{id}")
31
+ end
32
+
33
+ class << self
34
+ alias find_by_id find
27
35
  end
28
36
 
29
37
  def id
@@ -13,17 +13,17 @@ module Fauna
13
13
  end
14
14
 
15
15
  def data
16
- Fauna::Resource.find(config_ref).data
16
+ Fauna::Resource.find_by_ref(config_ref).data
17
17
  end
18
18
 
19
19
  def update_data!(hash = {})
20
- meta = Fauna::Resource.find(config_ref)
20
+ meta = Fauna::Resource.find_by_ref(config_ref)
21
21
  block_given? ? yield(meta.data) : meta.data = hash
22
22
  meta.save!
23
23
  end
24
24
 
25
25
  def update_data(hash = {})
26
- meta = Fauna::Resource.find(config_ref)
26
+ meta = Fauna::Resource.find_by_ref(config_ref)
27
27
  block_given? ? yield(meta.data) : meta.data = hash
28
28
  meta.save
29
29
  end
@@ -5,15 +5,15 @@ module Fauna
5
5
  class Config < Fauna::Resource; end
6
6
 
7
7
  def self.self
8
- find("users/self")
8
+ find_by_ref("users/self")
9
9
  end
10
10
 
11
11
  def self.find_by_email(email)
12
- find("users/email/#{email}")
12
+ find_by_ref("users/email/#{email}")
13
13
  end
14
14
 
15
15
  def config
16
- Fauna::User::Config.find("#{ref}/config")
16
+ Fauna::User::Config.find_by_ref("#{ref}/config")
17
17
  end
18
18
 
19
19
  # set on user create
@@ -2,7 +2,7 @@
2
2
  module Fauna
3
3
  class Publisher < Fauna::Resource
4
4
  def self.find
5
- super("publisher")
5
+ find_by_ref("publisher")
6
6
  end
7
7
  end
8
8
  end
@@ -22,16 +22,26 @@ if defined?(Rails)
22
22
  end
23
23
 
24
24
  if !@silent
25
- STDERR.puts ">> Using Fauna account #{credentials["email"].inspect} for #{APP_NAME.inspect}."
25
+ if credentials["publisher_key"]
26
+ STDERR.puts ">> Using Fauna publisher key #{credentials["publisher_key"].inspect} for #{APP_NAME.inspect}."
27
+ else
28
+ STDERR.puts ">> Using Fauna account #{credentials["email"].inspect} for #{APP_NAME.inspect}."
29
+ end
30
+
26
31
  STDERR.puts ">> You can change this in config/fauna.yml or ~/.fauna.yml."
27
32
  end
28
33
 
29
- self.root_connection = Connection.new(
30
- :email => credentials["email"],
31
- :password => credentials["password"],
32
- :logger => Rails.logger)
34
+ if credentials["publisher_key"]
35
+ publisher_key = credentials["publisher_key"]
36
+ else
37
+ self.root_connection = Connection.new(
38
+ :email => credentials["email"],
39
+ :password => credentials["password"],
40
+ :logger => Rails.logger)
41
+
42
+ publisher_key = root_connection.post("keys/publisher")["resource"]["key"]
43
+ end
33
44
 
34
- publisher_key = root_connection.post("keys/publisher")["resource"]["key"]
35
45
  self.connection = Connection.new(publisher_key: publisher_key, logger: Rails.logger)
36
46
  else
37
47
  if !@silent
@@ -48,7 +48,7 @@ module Fauna
48
48
  define_method("#{name}_ref") { references[name] }
49
49
  define_method("#{name}_ref=") { |ref| (ref.nil? || ref.empty?) ? references.delete(name) : references[name] = ref }
50
50
 
51
- define_method(name) { Fauna::Resource.find(references[name]) if references[name] }
51
+ define_method(name) { Fauna::Resource.find_by_ref(references[name]) if references[name] }
52
52
  define_method("#{name}=") { |obj| obj.nil? ? references.delete(name) : references[name] = obj.ref }
53
53
  end
54
54
  end
@@ -64,7 +64,7 @@ module Fauna
64
64
  end
65
65
  end
66
66
 
67
- def self.find(ref, query = nil)
67
+ def self.find_by_ref(ref, query = nil)
68
68
  res = Fauna::Client.get(ref, query)
69
69
  Fauna.class_for_name(res.fauna_class).alloc(res.to_hash)
70
70
  end
@@ -83,6 +83,14 @@ module Fauna
83
83
  obj
84
84
  end
85
85
 
86
+ def self.time_from_usecs(microseconds)
87
+ Time.at(microseconds/1_000_000, microseconds % 1_000_000)
88
+ end
89
+
90
+ def self.usecs_from_time(time)
91
+ time.to_i * 1000000 + time.usec
92
+ end
93
+
86
94
  attr_reader :struct
87
95
 
88
96
  alias :to_hash :struct
@@ -92,9 +100,16 @@ module Fauna
92
100
  assign(attrs)
93
101
  end
94
102
 
103
+ def ts
104
+ struct['ts'] ? Resource.time_from_usecs(struct['ts']) : nil
105
+ end
106
+
107
+ def ts=(time)
108
+ struct['ts'] = Resource.usecs_from_time(time)
109
+ end
110
+
95
111
  def ref; struct['ref'] end
96
112
  def fauna_class; struct['class'] end
97
- def ts; struct['ts'] end
98
113
  def deleted; struct['deleted'] end
99
114
  def unique_id; struct['unique_id'] end
100
115
  def data; struct['data'] ||= {} end
@@ -106,7 +121,6 @@ module Fauna
106
121
  end
107
122
  alias :== :eql?
108
123
 
109
-
110
124
  # dynamic field access
111
125
 
112
126
  def respond_to?(method, *args)
@@ -0,0 +1,11 @@
1
+
2
+ task :environment
3
+
4
+ namespace :fauna do
5
+ desc "Migrate your fauna database to the latest version"
6
+ task :migrate => :environment do
7
+ Fauna::Client.context(Fauna.connection) do
8
+ Fauna.migrate_schema!
9
+ end
10
+ end
11
+ end
@@ -28,12 +28,12 @@ class ClassTest < ActiveModel::TestCase
28
28
  end
29
29
 
30
30
  def test_all
31
- pig = Pig.create(:visited => false)
31
+ pig = Pig.create
32
32
  assert Pig.all.resources.include?(pig)
33
33
  end
34
34
 
35
35
  def test_save
36
- pig = Pig.new(:visited => false)
36
+ pig = Pig.new
37
37
  pig.save
38
38
  assert pig.persisted?
39
39
  end
@@ -52,16 +52,62 @@ class ClassTest < ActiveModel::TestCase
52
52
  assert_equal pig.changes.page.events.length, 2
53
53
  end
54
54
 
55
+ def test_find_by_ref
56
+ pig = Pig.create
57
+ pig1 = Pig.find_by_ref(pig.ref)
58
+ assert_equal pig.ref, pig1.ref
59
+ assert pig1.persisted?
60
+ end
61
+
62
+ def test_find_by_unique_id
63
+ pig = Pig.create(:unique_id => "the pig")
64
+ pig1 = Pig.find_by_unique_id("the pig")
65
+ assert_equal pig.ref, pig1.ref
66
+ assert pig1.persisted?
67
+ end
68
+
55
69
  def test_find
56
- pig = Pig.create(:visited => false)
57
- pig1 = Pig.find(pig.ref)
70
+ pig = Pig.create
71
+
72
+ pig1 = Pig.find(pig.id)
58
73
  assert_equal pig.ref, pig1.ref
59
74
  assert pig1.persisted?
75
+
76
+ pig2 = Pig.find_by_id(pig.id)
77
+ assert_equal pig.ref, pig2.ref
78
+ assert pig2.persisted?
60
79
  end
61
80
 
62
81
  def test_destroy
63
- pig = Pig.create(:visited => false)
82
+ pig = Pig.create
64
83
  pig.destroy
65
84
  assert pig.destroyed?
66
85
  end
86
+
87
+ def test_ts
88
+ pig = Pig.create
89
+ assert_instance_of(Time, pig.ts)
90
+
91
+ pig = Pig.new
92
+ assert_nil pig.ts
93
+ end
94
+
95
+ def test_ts_assignment
96
+ time = Time.at(0)
97
+ pig = Pig.create
98
+ pig.ts = time
99
+
100
+ Fauna::Client.context(@publisher_connection) do
101
+ pig2 = Pig.find(pig.id)
102
+ assert_not_equal time, pig2.ts
103
+ end
104
+
105
+ pig.save
106
+
107
+ Fauna::Client.context(@publisher_connection) do
108
+ pig3 = Pig.find(pig.id)
109
+ # Waiting on server support for timestamp overrides
110
+ # assert_equal time, pig3.ts
111
+ end
112
+ end
67
113
  end
@@ -12,8 +12,30 @@ class EventSetTest < ActiveModel::TestCase
12
12
 
13
13
  def test_page
14
14
  page = @model.posts.page
15
- assert_equal page.ref, "#{@model.ref}/sets/posts"
16
- assert_equal page.events.size, 0
15
+ assert_equal "#{@model.ref}/sets/posts", page.ref
16
+ assert_equal 0, page.events.size
17
+ end
18
+
19
+ def test_pagination
20
+ @model.posts.add(Post.create(:body => "Flewdyr Flam, called also Flewdyr Wledig."))
21
+ @model.posts.add(Post.create(:body => "Recorded in the Triads as one of the three sovereigns."))
22
+ @model.posts.add(Post.create(:body => "They preferred remaining as knights in the court of Arthur."))
23
+ @model.posts.add(Post.create(:body => "Even so, they had dominions of their own."))
24
+ @model.posts.add(Post.create(:body => "He is mentioned in the Mabinogi of Cilhwch and Olwen."))
25
+
26
+ page1 = @model.posts.page(:size => 2)
27
+ assert_equal 2, page1.events.size
28
+ page2 = @model.posts.page(:size => 2, :before => page1.before)
29
+ assert_equal 2, page2.events.size
30
+ page3 = @model.posts.page(:size => 2, :before => page2.before)
31
+ assert_equal 1, page3.events.size
32
+
33
+ page4 = @model.posts.page(:size => 2, :after => page3.events.last.ts)
34
+ assert_equal 2, page4.events.size
35
+ page5 = @model.posts.page(:size => 2, :after => page4.after)
36
+ assert_equal 2, page5.events.size
37
+ page6 = @model.posts.page(:size => 2, :after => page5.after)
38
+ assert_equal 1, page6.events.size
17
39
  end
18
40
 
19
41
  def test_any
@@ -25,14 +47,14 @@ class EventSetTest < ActiveModel::TestCase
25
47
  def test_event_set_add
26
48
  @model.posts.add(Post.create(:body => "Goodbye"))
27
49
  page = @model.posts.page
28
- assert_equal page.events.size, 1
29
- assert_equal page.events[0].resource.body, "Goodbye"
50
+ assert_equal 1, page.events.size
51
+ assert_equal "Goodbye", page.events[0].resource.body
30
52
  end
31
53
 
32
54
  def test_event_set_remove
33
55
  @model.posts.add(Post.create(:body => "Hello"))
34
56
  page = @model.posts.page
35
- assert_equal page.events.size, 1
57
+ assert_equal 1, page.events.size
36
58
  @model.posts.remove(page.events[0].resource)
37
59
  end
38
60
 
@@ -41,9 +41,9 @@ class UserTest < ActiveModel::TestCase
41
41
  assert_equal user.changes.page.events.length, 2
42
42
  end
43
43
 
44
- def test_find
44
+ def test_find_by_ref
45
45
  user = Fauna::User.create(@attributes)
46
- user1 = Fauna::User.find(user.ref)
46
+ user1 = Fauna::User.find_by_ref(user.ref)
47
47
  assert_equal user.ref, user1.ref
48
48
  assert user1.persisted?
49
49
  assert_equal user1.pockets, user.pockets
@@ -69,4 +69,12 @@ class UserTest < ActiveModel::TestCase
69
69
  user = Fauna::User.create(@attributes.merge(:unique_id => "henwen"))
70
70
  assert_equal user, Fauna::User.find_by_unique_id("henwen")
71
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
72
80
  end
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.5
4
+ version: 0.2.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-11 00:00:00.000000000 Z
12
+ date: 2013-04-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -142,6 +142,7 @@ extra_rdoc_files:
142
142
  - lib/fauna/publisher.rb
143
143
  - lib/fauna/rails.rb
144
144
  - lib/fauna/resource.rb
145
+ - lib/tasks/fauna.rake
145
146
  files:
146
147
  - CHANGELOG
147
148
  - Gemfile
@@ -149,6 +150,7 @@ files:
149
150
  - Manifest
150
151
  - README.md
151
152
  - Rakefile
153
+ - examples/welcome.rb
152
154
  - fauna.gemspec
153
155
  - lib/fauna.rb
154
156
  - lib/fauna/client.rb
@@ -161,6 +163,7 @@ files:
161
163
  - lib/fauna/publisher.rb
162
164
  - lib/fauna/rails.rb
163
165
  - lib/fauna/resource.rb
166
+ - lib/tasks/fauna.rake
164
167
  - test/association_test.rb
165
168
  - test/class_test.rb
166
169
  - test/client_test.rb