mongo_adaptor 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,6 +26,11 @@ 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 }
31
+ @collection.update query, command, safe_mode.merge(upsert_mode false)
32
+ end
33
+
29
34
  def fetch selector = {}, opts = { :fields => fields }
30
35
  @collection.find_one selector, opts.merge( :transformer => builder )
31
36
  end
@@ -1,3 +1,3 @@
1
1
  class MongoAdaptor
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -51,8 +51,8 @@ describe 'adapting structs into mongo' do
51
51
  end
52
52
 
53
53
  describe 'with an existing model' do
54
- let(:model) { klass.new 'Test Model','Some Data','Some Members' }
55
- let(:id) { collection.insert({ :name => 'My Model', :other => 'Some Value', :members => 'Some Members' },{ :safe => true }) }
54
+ 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'] },{ :safe => true }) }
56
56
 
57
57
  before do
58
58
  model.id = id
@@ -72,7 +72,7 @@ describe 'adapting structs into mongo' do
72
72
  data['_id'].should == model.id
73
73
  data['name'].should == 'Test Model'
74
74
  data['other'].should == 'Some Data'
75
- data['members'].should == 'Some Members'
75
+ data['members'].should == ['Some Other Members']
76
76
  end
77
77
  end
78
78
 
@@ -86,13 +86,29 @@ describe 'adapting structs into mongo' do
86
86
  it_should_behave_like 'modifying an existing model'
87
87
  end
88
88
 
89
+ describe 'to update it with a custom operation' do
90
+ let(:data) { collection.find({}).to_a[-1] }
91
+ subject { adaptor.execute model, "$addToSet" => { members: "Some Other Members" } }
92
+
93
+ it 'doesnt change the number of items in the collection' do
94
+ expect { subject }.to change { collection.size }.by(0)
95
+ end
96
+ it 'doesnt change the id' do
97
+ expect { subject }.to_not change { collection.find_one['_id'] }
98
+ end
99
+ it 'executes my command' do
100
+ subject
101
+ data['members'].should == ['Some Members','Some Other Members']
102
+ end
103
+ end
104
+
89
105
  describe 'to fetch it' do
90
106
  subject { adaptor.fetch({ :_id => id }) }
91
107
  it { should be_a klass }
92
108
  its(:id) { should == id }
93
109
  its(:name) { should == 'My Model' }
94
110
  its(:other) { should == 'Some Value' }
95
- its(:members) { should == 'Some Members' }
111
+ its(:members) { should == ['Some Members'] }
96
112
  end
97
113
 
98
114
  describe 'to remove 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.10
4
+ version: 0.0.11
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-05-01 00:00:00.000000000 Z
12
+ date: 2013-05-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongo
@@ -122,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
122
  version: '0'
123
123
  segments:
124
124
  - 0
125
- hash: -4332199509229713282
125
+ hash: 1205970240633467803
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: -4332199509229713282
134
+ hash: 1205970240633467803
135
135
  requirements: []
136
136
  rubyforge_project:
137
137
  rubygems_version: 1.8.25