mongo_adaptor 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mongo_adaptor.rb +2 -2
- data/lib/mongo_adaptor/version.rb +1 -1
- data/spec/mongo_adaptor_spec.rb +13 -2
- metadata +89 -91
data/lib/mongo_adaptor.rb
CHANGED
@@ -26,13 +26,13 @@ class MongoAdaptor
|
|
26
26
|
@collection.update query, set(process(model)), safe_mode.merge(upsert_mode false)
|
27
27
|
end
|
28
28
|
|
29
|
-
def execute query_or_model, command
|
29
|
+
def execute query_or_model, command, options = {}
|
30
30
|
if query_or_model.is_a? Hash
|
31
31
|
query = query_or_model
|
32
32
|
else
|
33
33
|
query = { "_id" => query_or_model.id }
|
34
34
|
end
|
35
|
-
@collection.update query, command, safe_mode.merge(upsert_mode false)
|
35
|
+
@collection.update query, command, safe_mode.merge(upsert_mode false).merge(options)
|
36
36
|
end
|
37
37
|
|
38
38
|
def fetch selector = {}, opts = { :fields => fields }
|
data/spec/mongo_adaptor_spec.rb
CHANGED
@@ -23,7 +23,7 @@ describe 'adapting structs into mongo' do
|
|
23
23
|
let(:model) { klass.new 'Test Model','Some Data','Some Members','fake key' }
|
24
24
|
let(:data) { collection.find({}).to_a[-1] }
|
25
25
|
|
26
|
-
shared_examples_for '
|
26
|
+
shared_examples_for 'creates a document' do
|
27
27
|
it 'changes the number of items in the collection' do
|
28
28
|
expect { subject }.to change { collection.size }.by(1)
|
29
29
|
end
|
@@ -32,6 +32,9 @@ describe 'adapting structs into mongo' do
|
|
32
32
|
data['_id'].should be_a BSON::ObjectId
|
33
33
|
data['id'].should be_nil
|
34
34
|
end
|
35
|
+
end
|
36
|
+
shared_examples_for 'new model' do
|
37
|
+
it_should_behave_like 'creates a document'
|
35
38
|
it 'sets my fields and values' do
|
36
39
|
subject
|
37
40
|
data['name'].should == 'Test Model'
|
@@ -48,11 +51,19 @@ describe 'adapting structs into mongo' do
|
|
48
51
|
subject { adaptor.upsert model, {} }
|
49
52
|
it_should_behave_like 'new model'
|
50
53
|
end
|
54
|
+
describe 'upserting with a custom operation' do
|
55
|
+
subject { adaptor.execute({ name: 'value' }, { '$push' => { "key" => "value" } }, { :upsert => true }) }
|
56
|
+
it_should_behave_like 'creates a document'
|
57
|
+
it 'will execute my command' do
|
58
|
+
subject
|
59
|
+
data['key'].should eq ['value']
|
60
|
+
end
|
61
|
+
end
|
51
62
|
end
|
52
63
|
|
53
64
|
describe 'with an existing model' do
|
54
65
|
let(:model) { klass.new 'Test Model','Some Data',['Some Other Members'] }
|
55
|
-
let(:id) { collection.insert({ :name => 'My Model', :other => 'Some Value', :members => ['Some Members'] },{ :
|
66
|
+
let(:id) { collection.insert({ :name => 'My Model', :other => 'Some Value', :members => ['Some Members'] },{ :w => 1 }) }
|
56
67
|
|
57
68
|
before do
|
58
69
|
model.id = id
|
metadata
CHANGED
@@ -1,102 +1,103 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_adaptor
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.14
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 13
|
10
|
-
version: 0.0.13
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Jon Rowe
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-05-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: mongo
|
22
|
-
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
23
17
|
none: false
|
24
|
-
requirements:
|
25
|
-
- -
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
version: "0"
|
31
|
-
prerelease: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
32
22
|
type: :runtime
|
33
|
-
|
34
|
-
|
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
|
35
31
|
name: bson
|
36
|
-
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
37
33
|
none: false
|
38
|
-
requirements:
|
39
|
-
- -
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
|
42
|
-
segments:
|
43
|
-
- 0
|
44
|
-
version: "0"
|
45
|
-
prerelease: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
46
38
|
type: :runtime
|
47
|
-
|
48
|
-
|
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
|
+
- !ruby/object:Gem::Dependency
|
49
47
|
name: mongo-configure
|
50
|
-
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
51
49
|
none: false
|
52
|
-
requirements:
|
53
|
-
- -
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
|
56
|
-
segments:
|
57
|
-
- 0
|
58
|
-
version: "0"
|
59
|
-
prerelease: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
60
54
|
type: :runtime
|
61
|
-
|
62
|
-
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
63
|
name: rake
|
64
|
-
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
|
-
requirements:
|
67
|
-
- -
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
|
70
|
-
segments:
|
71
|
-
- 0
|
72
|
-
version: "0"
|
73
|
-
prerelease: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
74
70
|
type: :development
|
75
|
-
|
76
|
-
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
77
79
|
name: rspec
|
78
|
-
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
79
81
|
none: false
|
80
|
-
requirements:
|
81
|
-
- -
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
|
84
|
-
segments:
|
85
|
-
- 0
|
86
|
-
version: "0"
|
87
|
-
prerelease: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
88
86
|
type: :development
|
89
|
-
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
90
94
|
description: A simple mongo handler. Translates Structs into Mongo and back.
|
91
|
-
email:
|
95
|
+
email:
|
92
96
|
- hello@jonrowe.co.uk
|
93
97
|
executables: []
|
94
|
-
|
95
98
|
extensions: []
|
96
|
-
|
97
99
|
extra_rdoc_files: []
|
98
|
-
|
99
|
-
files:
|
100
|
+
files:
|
100
101
|
- .gitignore
|
101
102
|
- .travis.yml
|
102
103
|
- Gemfile
|
@@ -109,36 +110,33 @@ files:
|
|
109
110
|
- spec/mongo_adaptor_spec.rb
|
110
111
|
homepage: https://github.com/JonRowe/MongoAdaptor
|
111
112
|
licenses: []
|
112
|
-
|
113
113
|
post_install_message:
|
114
114
|
rdoc_options: []
|
115
|
-
|
116
|
-
require_paths:
|
115
|
+
require_paths:
|
117
116
|
- lib
|
118
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
118
|
none: false
|
120
|
-
requirements:
|
121
|
-
- -
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
|
124
|
-
segments:
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
segments:
|
125
124
|
- 0
|
126
|
-
|
127
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
hash: 309314115556500517
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
127
|
none: false
|
129
|
-
requirements:
|
130
|
-
- -
|
131
|
-
- !ruby/object:Gem::Version
|
132
|
-
|
133
|
-
segments:
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
segments:
|
134
133
|
- 0
|
135
|
-
|
134
|
+
hash: 309314115556500517
|
136
135
|
requirements: []
|
137
|
-
|
138
136
|
rubyforge_project:
|
139
137
|
rubygems_version: 1.8.25
|
140
138
|
signing_key:
|
141
139
|
specification_version: 3
|
142
140
|
summary: A simple mongo handler. Translates Structs into Mongo and back.
|
143
|
-
test_files:
|
141
|
+
test_files:
|
144
142
|
- spec/mongo_adaptor_spec.rb
|