light_mongo 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,9 +4,14 @@ LightMongo is a lightweight Mongo object persistence layer for Ruby which makes
4
4
 
5
5
  Status
6
6
  -----------------
7
- LightMongo is only a few days old, so while most of the features demo'd below work, there's no strong integration testing yet, so I wouldn't use it for data you particularly care about until I release a gem.
7
+ LightMongo is still new, but all the examples below are working. Please check out the integration tests for usage indications, and please post any issues you find to the the Github issues page.
8
8
 
9
- Check out the development roadmap for an idea of my current priorities.
9
+ Installation
10
+ ------------
11
+ LightMongo is best installed via `gem install light_mongo` and required as normal.
12
+
13
+ It is dependent on the gem `mongo`, which is the MongoDB Ruby driver.
14
+ For performance reasons I would recommend also installing `mongo_ext`, the C extensions for the driver.
10
15
 
11
16
  The problem
12
17
  -----------
@@ -26,6 +31,9 @@ We're Ruby developers. Let's act like it.
26
31
 
27
32
  An example
28
33
  ----------
34
+ require 'rubygems'
35
+ require 'light_mongo'
36
+
29
37
  class Article
30
38
  include LightMongo::Document
31
39
  end
@@ -118,14 +126,10 @@ LightMongo uses its Document mixin to signify a collection, so if you embed a Li
118
126
  Article.find.first.author == Person.find.first
119
127
  => true
120
128
 
121
- Roadmap
122
- -------
123
- 1. Improved testbed to allow stronger integration testing.
124
- 2. More intelligent and efficient object serialisation.
125
- 3. Proper deserialisation of cross-collection objects (currently they go in, don't come back out).
126
- 4. Nested hash serialisation.
127
- 4. Migrations (e.g. when you rename classes or modify their collection style).
128
- 5. Some kind of validations, perhaps.
129
+ Future development
130
+ ------------------
131
+ 1. Migrations (e.g. when you rename classes or modify their collection style).
132
+ 2. Some kind of validations, perhaps.
129
133
 
130
134
 
131
135
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
@@ -2,20 +2,39 @@ require File.expand_path(File.dirname(__FILE__) + '/support/integration_helper')
2
2
 
3
3
  class Article
4
4
  include LightMongo::Document
5
+
6
+ attr_accessor :title
5
7
  end
6
8
 
7
9
  describe 'The basic storage cycle' do
8
10
  before(:each) do
9
- @geology_article = Article.new(:title => (@title = 'Fluid Physics in Geology'),
10
- :abstract => (@abstract = 'Lorem ipsum dolor..'))
11
+ @geology_params = {
12
+ :title => (@title = 'Fluid Physics in Geology'),
13
+ :abstract => (@abstract = 'Lorem ipsum dolor..')
14
+ }
11
15
  end
12
16
 
13
- it "allows the storage and retrieval of documents." do
14
- @geology_article.save
17
+ it "creates and reads." do
18
+ Article.create(@geology_params)
15
19
  stored_article = Article.find.first
16
20
  stored_article.instance_variable_get('@title').should == @title
17
21
  stored_article.instance_variable_get('@abstract').should == @abstract
18
22
  end
19
23
 
24
+ it "updates." do
25
+ article = Article.create(@geology_params)
26
+ article.update!(:title => 'On CRUD in Object Persistence', :abstract => 'Rolod muspi merol..')
27
+
28
+ stored_article = Article.find.first
29
+ stored_article.instance_variable_get('@title').should == 'On CRUD in Object Persistence'
30
+ stored_article.instance_variable_get('@abstract').should == 'Rolod muspi merol..'
31
+ end
32
+
33
+ it "deletes." do
34
+ article = Article.create(@geology_params)
35
+ article.delete!
36
+ Article.find.should be_empty
37
+ end
38
+
20
39
  db_teardown
21
40
  end
@@ -36,6 +36,25 @@ module LightMongo
36
36
  @_id = collection.save(self.to_hash)
37
37
  end
38
38
 
39
+ def update(params)
40
+ params.each_pair do |attr_name, attr_value|
41
+ self.instance_variable_set '@'+attr_name.to_s, attr_value
42
+ end
43
+
44
+ return self
45
+ end
46
+
47
+ def update!(params)
48
+ self.update(params).save
49
+ end
50
+
51
+ def delete!
52
+ if result = collection.remove(:_id => @_id)
53
+ @_id = nil
54
+ return result
55
+ end
56
+ end
57
+
39
58
  def id
40
59
  @_id
41
60
  end
@@ -49,6 +49,74 @@ describe LightMongo::Document::Persistence do
49
49
  end
50
50
  end
51
51
 
52
+ describe "#update!(params)" do
53
+ before(:each) do
54
+ @test_object = TestClass.new(:name => 'Test object')
55
+ @test_object.stub!(:save => (@result = mock(:result)))
56
+ end
57
+
58
+ def update_object
59
+ @test_object.update! :name => (@name = mock(:name))
60
+ end
61
+
62
+ it "updates the object's state" do
63
+ update_object
64
+ @test_object.name.should == @name
65
+ end
66
+
67
+ it "saves the object" do
68
+ @test_object.should_receive(:save)
69
+ update_object
70
+ end
71
+
72
+ it "returns the result of the save" do
73
+ update_object.should == @result
74
+ end
75
+ end
76
+
77
+ describe "#update(params)" do
78
+ before(:each) do
79
+ @test_object = TestClass.new(:name => 'Test object')
80
+ end
81
+
82
+ def update_object
83
+ @test_object.update :name => (@name = mock(:name))
84
+ end
85
+
86
+ it "updates the object's state" do
87
+ update_object
88
+ @test_object.name.should == @name
89
+ end
90
+
91
+ it "returns the object" do
92
+ update_object.should == @test_object
93
+ end
94
+ end
95
+
96
+ describe "#delete!" do
97
+ before(:each) do
98
+ @test_object = TestClass.new(:_id => (@id = mock(:id)), :name => 'Test object')
99
+ end
100
+
101
+ it "removes the object" do
102
+ @test_class_collection.should_receive(:remove).with(:_id => @id)
103
+ @test_object.delete!
104
+ end
105
+
106
+ it "returns the result of the remove" do
107
+ @test_class_collection.stub!(:remove => (@result = mock(:result)))
108
+ @test_object.delete!.should == @result
109
+ end
110
+
111
+ it "erases the document's id" do
112
+ @test_object.id.should == @id
113
+
114
+ @test_class_collection.stub!(:remove => true)
115
+ @test_object.delete!
116
+ @test_object.id.should be_nil
117
+ end
118
+ end
119
+
52
120
  describe "#id" do
53
121
  before(:each) do
54
122
  @id = mock(:id)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: light_mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elliot Crosby-McCullough
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-03-21 00:00:00 +00:00
12
+ date: 2010-03-27 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency