mongo_adaptor 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
data/lib/mongo_adaptor.rb CHANGED
@@ -26,8 +26,12 @@ class MongoAdaptor
26
26
  @collection.update query, set(process(model)), safe_mode.merge(upsert_mode false)
27
27
  end
28
28
 
29
- def execute model, command
30
- query = { "_id" => model.id }
29
+ def execute query_or_model, command
30
+ if query_or_model.respond_to? :id
31
+ query = { "_id" => query_or_model.id }
32
+ else
33
+ query = query_or_model
34
+ end
31
35
  @collection.update query, command, safe_mode.merge(upsert_mode false)
32
36
  end
33
37
 
@@ -1,3 +1,3 @@
1
1
  class MongoAdaptor
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
@@ -88,7 +88,7 @@ describe 'adapting structs into mongo' do
88
88
 
89
89
  describe 'to update it with a custom operation' do
90
90
  let(:data) { collection.find({}).to_a[-1] }
91
- subject { adaptor.execute model, "$addToSet" => { members: "Some Other Members" } }
91
+ subject { adaptor.execute model, "$addToSet" => { "members" => "Some Other Members" } }
92
92
 
93
93
  it 'doesnt change the number of items in the collection' do
94
94
  expect { subject }.to change { collection.size }.by(0)
@@ -100,6 +100,10 @@ describe 'adapting structs into mongo' do
100
100
  subject
101
101
  data['members'].should == ['Some Members','Some Other Members']
102
102
  end
103
+ it 'also can execute my command by query' do
104
+ adaptor.execute({ "name" => 'My Model'}, "$addToSet" => { "members" => "Some Other Members" })
105
+ data['members'].should == ['Some Members','Some Other Members']
106
+ end
103
107
  end
104
108
 
105
109
  describe 'to fetch it' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_adaptor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -122,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
122
  version: '0'
123
123
  segments:
124
124
  - 0
125
- hash: 1205970240633467803
125
+ hash: -2106155663836769840
126
126
  required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  version: '0'
132
132
  segments:
133
133
  - 0
134
- hash: 1205970240633467803
134
+ hash: -2106155663836769840
135
135
  requirements: []
136
136
  rubyforge_project:
137
137
  rubygems_version: 1.8.25