mongo-hashie 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/Rakefile +13 -40
- data/lib/mongo-hashie/base.rb +2 -2
- data/lib/mongo-hashie/version.rb +3 -0
- data/spec/mongo-hashie_spec.rb +76 -0
- data/spec/spec_helper.rb +6 -0
- metadata +79 -31
- data/.document +0 -5
- data/.gitignore +0 -21
- data/VERSION +0 -1
- data/mongo-hashie.gemspec +0 -63
- data/test/helper.rb +0 -12
- data/test/test_mongo-hashie.rb +0 -76
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -1,51 +1,24 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'bundler'
|
2
|
+
require 'rspec/core/rake_task'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "mongo-hashie"
|
8
|
-
gem.summary = "Simple MongoDB Object Wrapper based on Hashie"
|
9
|
-
gem.description = "Simple MongoDB Object Wrapper based on Hashie"
|
10
|
-
gem.email = "kiessler@inceedo.com"
|
11
|
-
gem.homepage = "http://github.com/okiess/mongo-hashie"
|
12
|
-
gem.authors = ["Oliver Kiessler"]
|
13
|
-
gem.add_development_dependency "shoulda", ">= 0"
|
14
|
-
gem.add_dependency "hashie"
|
15
|
-
gem.add_dependency "mongo"
|
16
|
-
end
|
17
|
-
Jeweler::GemcutterTasks.new
|
18
|
-
rescue LoadError
|
19
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
-
end
|
4
|
+
$:.push File.expand_path("../lib", __FILE__)
|
5
|
+
require "mongo-hashie/version"
|
21
6
|
|
22
|
-
|
23
|
-
Rake::TestTask.new(:test) do |test|
|
24
|
-
test.libs << 'lib' << 'test'
|
25
|
-
test.pattern = 'test/**/test_*.rb'
|
26
|
-
test.verbose = true
|
27
|
-
end
|
7
|
+
Bundler::GemHelper.install_tasks
|
28
8
|
|
29
|
-
|
30
|
-
require 'rcov/rcovtask'
|
31
|
-
Rcov::RcovTask.new do |test|
|
32
|
-
test.libs << 'test'
|
33
|
-
test.pattern = 'test/**/test_*.rb'
|
34
|
-
test.verbose = true
|
35
|
-
end
|
36
|
-
rescue LoadError
|
37
|
-
task :rcov do
|
38
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
-
end
|
40
|
-
end
|
9
|
+
RSpec::Core::RakeTask.new(:spec)
|
41
10
|
|
42
|
-
|
11
|
+
RSpec::Core::RakeTask.new(:rcov) do |t|
|
12
|
+
t.rcov = true
|
13
|
+
t.rcov_opts = %w{--include lib -Ispec --exclude spec\,gems}
|
14
|
+
t.rspec_opts = ["-c"]
|
15
|
+
end
|
43
16
|
|
44
|
-
task :default => :
|
17
|
+
task :default => :spec
|
45
18
|
|
46
19
|
require 'rake/rdoctask'
|
47
20
|
Rake::RDocTask.new do |rdoc|
|
48
|
-
version =
|
21
|
+
version = MongoHashie::VERSION
|
49
22
|
|
50
23
|
rdoc.rdoc_dir = 'rdoc'
|
51
24
|
rdoc.title = "mongo-hashie #{version}"
|
data/lib/mongo-hashie/base.rb
CHANGED
@@ -17,7 +17,7 @@ module MongoHashie
|
|
17
17
|
|
18
18
|
def save
|
19
19
|
if self._id.nil?
|
20
|
-
self._id =
|
20
|
+
self._id = BSON::ObjectId.new
|
21
21
|
collection.insert(self)
|
22
22
|
else
|
23
23
|
collection.update({'_id' => self._id}, self)
|
@@ -34,7 +34,7 @@ module MongoHashie
|
|
34
34
|
module ClassMethods
|
35
35
|
def connection
|
36
36
|
Mongo::Connection.new(MongoHashie::Configuration.host, MongoHashie::Configuration.port,
|
37
|
-
:pool_size => MongoHashie::Configuration.pool_size, :
|
37
|
+
:pool_size => MongoHashie::Configuration.pool_size, :pool_timeout => MongoHashie::Configuration.timeout)
|
38
38
|
end
|
39
39
|
|
40
40
|
def db; @@db ||= connection.db(MongoHashie::Configuration.database); end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
3
|
+
|
4
|
+
describe MongoHashie do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
BlogPost.destroy_all; MongoHashie::MetaDataProperties.destroy_all
|
8
|
+
@blog_post_hash = {:title => 'Test Title', :text => 'Bodytext', :author => 'Oliver Kiessler', :views => 1,
|
9
|
+
:tags => ['test1', 'test2', 'test3']}
|
10
|
+
end
|
11
|
+
|
12
|
+
context "basic operations" do
|
13
|
+
it "has a connection and database set" do
|
14
|
+
MongoHashie::Configuration.database.should == 'mongo-hashie-testdb'
|
15
|
+
BlogPost.connection.should_not be_nil
|
16
|
+
BlogPost.db.should_not be_nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "can create a new object" do
|
20
|
+
blog_post = BlogPost.new(@blog_post_hash)
|
21
|
+
BlogPost.count.should == 0
|
22
|
+
blog_post.save
|
23
|
+
blog_post._id.should_not be_nil
|
24
|
+
BlogPost.count.should == 1
|
25
|
+
end
|
26
|
+
|
27
|
+
it "can destroy an object" do
|
28
|
+
blog_post = BlogPost.new(@blog_post_hash)
|
29
|
+
blog_post.save
|
30
|
+
BlogPost.count.should == 1
|
31
|
+
blog_post.destroy
|
32
|
+
BlogPost.count.should == 0
|
33
|
+
end
|
34
|
+
|
35
|
+
it "can create an object by passing a hash" do
|
36
|
+
BlogPost.count.should == 0
|
37
|
+
BlogPost.create(@blog_post_hash)
|
38
|
+
BlogPost.count.should == 1
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "meta data" do
|
43
|
+
it "can have meta data properties" do
|
44
|
+
BlogPost.count.should == 0
|
45
|
+
MongoHashie::MetaDataProperties.count.should == 0
|
46
|
+
BlogPost.create(@blog_post_hash)
|
47
|
+
BlogPost.count.should == 1
|
48
|
+
MongoHashie::MetaDataProperties.count.should == 1
|
49
|
+
end
|
50
|
+
|
51
|
+
it "can include all keys in the meta data properties" do
|
52
|
+
blog_post = BlogPost.create(@blog_post_hash)
|
53
|
+
BlogPost.properties_used.keys.size.should == 5
|
54
|
+
BlogPost.properties_used.keys.include?('title').should be_true
|
55
|
+
BlogPost.properties_used.keys.include?('text').should be_true
|
56
|
+
BlogPost.properties_used.keys.include?('author').should be_true
|
57
|
+
BlogPost.properties_used.keys.include?('views').should be_true
|
58
|
+
BlogPost.properties_used.keys.include?('tags').should be_true
|
59
|
+
end
|
60
|
+
|
61
|
+
it "updates keys in the meta data properties" do
|
62
|
+
BlogPost.create(@blog_post_hash)
|
63
|
+
BlogPost.properties_used.keys.size.should == 5
|
64
|
+
BlogPost.create(@blog_post_hash.merge(:likes => 2))
|
65
|
+
BlogPost.properties_used.keys.size.should == 6
|
66
|
+
end
|
67
|
+
|
68
|
+
it "resets keys in the meta data properties when destroy_all is called" do
|
69
|
+
2.times {BlogPost.create(@blog_post_hash)}
|
70
|
+
MongoHashie::MetaDataProperties.first(:class_name => 'BlogPost').should_not be_nil
|
71
|
+
BlogPost.destroy_all
|
72
|
+
MongoHashie::MetaDataProperties.first(:class_name => 'BlogPost').should be_nil
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo-hashie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 31
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Oliver Kiessler
|
@@ -9,62 +15,98 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2011-10-10 00:00:00 +02:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
17
33
|
type: :development
|
18
|
-
|
19
|
-
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rcov
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
20
40
|
requirements:
|
21
41
|
- - ">="
|
22
42
|
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
23
46
|
version: "0"
|
24
|
-
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
25
49
|
- !ruby/object:Gem::Dependency
|
26
50
|
name: hashie
|
27
|
-
|
28
|
-
|
29
|
-
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
30
54
|
requirements:
|
31
55
|
- - ">="
|
32
56
|
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
33
60
|
version: "0"
|
34
|
-
|
61
|
+
type: :runtime
|
62
|
+
version_requirements: *id003
|
35
63
|
- !ruby/object:Gem::Dependency
|
36
64
|
name: mongo
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
37
75
|
type: :runtime
|
38
|
-
|
39
|
-
|
76
|
+
version_requirements: *id004
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: bson_ext
|
79
|
+
prerelease: false
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
40
82
|
requirements:
|
41
83
|
- - ">="
|
42
84
|
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
43
88
|
version: "0"
|
44
|
-
|
89
|
+
type: :runtime
|
90
|
+
version_requirements: *id005
|
45
91
|
description: Simple MongoDB Object Wrapper based on Hashie
|
46
92
|
email: kiessler@inceedo.com
|
47
93
|
executables: []
|
48
94
|
|
49
95
|
extensions: []
|
50
96
|
|
51
|
-
extra_rdoc_files:
|
52
|
-
|
53
|
-
- README.rdoc
|
97
|
+
extra_rdoc_files: []
|
98
|
+
|
54
99
|
files:
|
55
|
-
- .document
|
56
|
-
- .gitignore
|
57
|
-
- LICENSE
|
58
|
-
- README.rdoc
|
59
|
-
- Rakefile
|
60
|
-
- VERSION
|
61
|
-
- lib/mongo-hashie.rb
|
62
100
|
- lib/mongo-hashie/base.rb
|
63
101
|
- lib/mongo-hashie/meta_data.rb
|
64
102
|
- lib/mongo-hashie/rails.rb
|
65
|
-
- mongo-hashie.
|
66
|
-
-
|
67
|
-
-
|
103
|
+
- lib/mongo-hashie/version.rb
|
104
|
+
- lib/mongo-hashie.rb
|
105
|
+
- LICENSE
|
106
|
+
- README.rdoc
|
107
|
+
- Rakefile
|
108
|
+
- spec/mongo-hashie_spec.rb
|
109
|
+
- spec/spec_helper.rb
|
68
110
|
has_rdoc: true
|
69
111
|
homepage: http://github.com/okiess/mongo-hashie
|
70
112
|
licenses: []
|
@@ -75,24 +117,30 @@ rdoc_options:
|
|
75
117
|
require_paths:
|
76
118
|
- lib
|
77
119
|
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
78
121
|
requirements:
|
79
122
|
- - ">="
|
80
123
|
- !ruby/object:Gem::Version
|
124
|
+
hash: 3
|
125
|
+
segments:
|
126
|
+
- 0
|
81
127
|
version: "0"
|
82
|
-
version:
|
83
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
84
130
|
requirements:
|
85
131
|
- - ">="
|
86
132
|
- !ruby/object:Gem::Version
|
133
|
+
hash: 3
|
134
|
+
segments:
|
135
|
+
- 0
|
87
136
|
version: "0"
|
88
|
-
version:
|
89
137
|
requirements: []
|
90
138
|
|
91
139
|
rubyforge_project:
|
92
|
-
rubygems_version: 1.
|
140
|
+
rubygems_version: 1.5.2
|
93
141
|
signing_key:
|
94
142
|
specification_version: 3
|
95
143
|
summary: Simple MongoDB Object Wrapper based on Hashie
|
96
144
|
test_files:
|
97
|
-
-
|
98
|
-
-
|
145
|
+
- spec/mongo-hashie_spec.rb
|
146
|
+
- spec/spec_helper.rb
|
data/.document
DELETED
data/.gitignore
DELETED
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.1
|
data/mongo-hashie.gemspec
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{mongo-hashie}
|
8
|
-
s.version = "0.1.1"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Oliver Kiessler"]
|
12
|
-
s.date = %q{2010-01-02}
|
13
|
-
s.description = %q{Simple MongoDB Object Wrapper based on Hashie}
|
14
|
-
s.email = %q{kiessler@inceedo.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"LICENSE",
|
23
|
-
"README.rdoc",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"lib/mongo-hashie.rb",
|
27
|
-
"lib/mongo-hashie/base.rb",
|
28
|
-
"lib/mongo-hashie/meta_data.rb",
|
29
|
-
"lib/mongo-hashie/rails.rb",
|
30
|
-
"mongo-hashie.gemspec",
|
31
|
-
"test/helper.rb",
|
32
|
-
"test/test_mongo-hashie.rb"
|
33
|
-
]
|
34
|
-
s.homepage = %q{http://github.com/okiess/mongo-hashie}
|
35
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
-
s.require_paths = ["lib"]
|
37
|
-
s.rubygems_version = %q{1.3.5}
|
38
|
-
s.summary = %q{Simple MongoDB Object Wrapper based on Hashie}
|
39
|
-
s.test_files = [
|
40
|
-
"test/helper.rb",
|
41
|
-
"test/test_mongo-hashie.rb"
|
42
|
-
]
|
43
|
-
|
44
|
-
if s.respond_to? :specification_version then
|
45
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
|
-
s.specification_version = 3
|
47
|
-
|
48
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
49
|
-
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
50
|
-
s.add_runtime_dependency(%q<hashie>, [">= 0"])
|
51
|
-
s.add_runtime_dependency(%q<mongo>, [">= 0"])
|
52
|
-
else
|
53
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
54
|
-
s.add_dependency(%q<hashie>, [">= 0"])
|
55
|
-
s.add_dependency(%q<mongo>, [">= 0"])
|
56
|
-
end
|
57
|
-
else
|
58
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
59
|
-
s.add_dependency(%q<hashie>, [">= 0"])
|
60
|
-
s.add_dependency(%q<mongo>, [">= 0"])
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
data/test/helper.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'test/unit'
|
3
|
-
require 'shoulda'
|
4
|
-
|
5
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
-
require 'mongo-hashie'
|
8
|
-
|
9
|
-
class Test::Unit::TestCase
|
10
|
-
end
|
11
|
-
|
12
|
-
MongoHashie::Configuration.database = 'mongo-hashie-testdb'
|
data/test/test_mongo-hashie.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class BlogPost < MongoHashie::Base
|
4
|
-
end
|
5
|
-
|
6
|
-
class TestMongoHashie < Test::Unit::TestCase
|
7
|
-
def setup
|
8
|
-
BlogPost.destroy_all; MongoHashie::MetaDataProperties.destroy_all
|
9
|
-
@blog_post_hash = {:title => 'Test Title', :text => 'Bodytext', :author => 'Oliver Kiessler', :views => 1,
|
10
|
-
:tags => ['test1', 'test2', 'test3']}
|
11
|
-
end
|
12
|
-
|
13
|
-
context "basic operations" do
|
14
|
-
should "have a connection and database set" do
|
15
|
-
assert_equal MongoHashie::Configuration.database, 'mongo-hashie-testdb'
|
16
|
-
assert_not_nil BlogPost.connection
|
17
|
-
assert_not_nil BlogPost.db
|
18
|
-
end
|
19
|
-
|
20
|
-
should "create a new object" do
|
21
|
-
blog_post = BlogPost.new(@blog_post_hash)
|
22
|
-
assert_equal BlogPost.count, 0
|
23
|
-
blog_post.save
|
24
|
-
assert_not_nil blog_post._id
|
25
|
-
assert_equal BlogPost.count, 1
|
26
|
-
end
|
27
|
-
|
28
|
-
should "destroy object" do
|
29
|
-
blog_post = BlogPost.new(@blog_post_hash)
|
30
|
-
blog_post.save
|
31
|
-
assert_equal BlogPost.count, 1
|
32
|
-
blog_post.destroy
|
33
|
-
assert_equal BlogPost.count, 0
|
34
|
-
end
|
35
|
-
|
36
|
-
should "create object by passing a hash" do
|
37
|
-
assert_equal BlogPost.count, 0
|
38
|
-
blog_post = BlogPost.create(@blog_post_hash)
|
39
|
-
assert_equal BlogPost.count, 1
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context "meta data" do
|
44
|
-
should "have meta data properties" do
|
45
|
-
assert_equal BlogPost.count, 0
|
46
|
-
assert_equal MongoHashie::MetaDataProperties.count, 0
|
47
|
-
blog_post = BlogPost.create(@blog_post_hash)
|
48
|
-
assert_equal BlogPost.count, 1
|
49
|
-
assert_equal MongoHashie::MetaDataProperties.count, 1
|
50
|
-
end
|
51
|
-
|
52
|
-
should "include all keys in the meta data properties" do
|
53
|
-
blog_post = BlogPost.create(@blog_post_hash)
|
54
|
-
assert_equal BlogPost.properties_used.keys.size, 5
|
55
|
-
assert BlogPost.properties_used.keys.include?('title')
|
56
|
-
assert BlogPost.properties_used.keys.include?('text')
|
57
|
-
assert BlogPost.properties_used.keys.include?('author')
|
58
|
-
assert BlogPost.properties_used.keys.include?('views')
|
59
|
-
assert BlogPost.properties_used.keys.include?('tags')
|
60
|
-
end
|
61
|
-
|
62
|
-
should "update keys in the meta data properties" do
|
63
|
-
BlogPost.create(@blog_post_hash)
|
64
|
-
assert_equal BlogPost.properties_used.keys.size, 5
|
65
|
-
BlogPost.create(@blog_post_hash.merge(:likes => 2))
|
66
|
-
assert_equal BlogPost.properties_used.keys.size, 6
|
67
|
-
end
|
68
|
-
|
69
|
-
should "reset keys in the meta data properties when destroy_all is called" do
|
70
|
-
2.times {BlogPost.create(@blog_post_hash)}
|
71
|
-
assert_not_nil MongoHashie::MetaDataProperties.first(:class_name => 'BlogPost')
|
72
|
-
BlogPost.destroy_all
|
73
|
-
assert_nil MongoHashie::MetaDataProperties.first(:class_name => 'BlogPost')
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|