dm-couchdb-adapter 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,310 @@
1
+ share_examples_for 'An Adapter' do
2
+
3
+ def self.adapter_supports?(*methods)
4
+ methods.all? do |method|
5
+ # TODO: figure out a way to see if the instance method is only inherited
6
+ # from the Abstract Adapter, and not defined in it's class. If that is
7
+ # the case return false
8
+
9
+ # CRUD methods can be inherited from parent class
10
+ described_type.instance_methods.any? { |instance_method| method.to_s == instance_method.to_s }
11
+ end
12
+ end
13
+
14
+ before :all do
15
+ raise '+@adapter+ should be defined in before block' unless instance_variable_get('@adapter')
16
+
17
+ class ::Heffalump
18
+ include DataMapper::Resource
19
+
20
+ property :id, Serial
21
+ property :color, String
22
+ property :num_spots, Integer
23
+ property :striped, Boolean
24
+ end
25
+
26
+ # create all tables and constraints before each spec
27
+ if @repository.respond_to?(:auto_migrate!)
28
+ Heffalump.auto_migrate!
29
+ end
30
+ end
31
+
32
+ if adapter_supports?(:create)
33
+ describe '#create' do
34
+ it 'should not raise any errors' do
35
+ lambda {
36
+ Heffalump.create(:color => 'peach')
37
+ }.should_not raise_error
38
+ end
39
+
40
+ it 'should set the identity field for the resource' do
41
+ heffalump = Heffalump.new(:color => 'peach')
42
+ heffalump.id.should be_nil
43
+ heffalump.save
44
+ heffalump.id.should_not be_nil
45
+ end
46
+ end
47
+ else
48
+ it 'needs to support #create'
49
+ end
50
+
51
+ if adapter_supports?(:read)
52
+ describe '#read' do
53
+ before :all do
54
+ @heffalump = Heffalump.create(:color => 'brownish hue')
55
+ #just going to borrow this, so I can check the return values
56
+ @query = Heffalump.all.query
57
+ end
58
+
59
+ it 'should not raise any errors' do
60
+ lambda {
61
+ Heffalump.all()
62
+ }.should_not raise_error
63
+ end
64
+
65
+ it 'should return stuff' do
66
+ Heffalump.all.should be_include(@heffalump)
67
+ end
68
+ end
69
+ else
70
+ it 'needs to support #read'
71
+ end
72
+
73
+ if adapter_supports?(:update)
74
+ describe '#update' do
75
+ before do
76
+ @heffalump = Heffalump.create(:color => 'indigo')
77
+ end
78
+
79
+ it 'should not raise any errors' do
80
+ lambda {
81
+ @heffalump.color = 'violet'
82
+ @heffalump.save
83
+ }.should_not raise_error
84
+ end
85
+
86
+ it 'should not alter the identity field' do
87
+ id = @heffalump.id
88
+ @heffalump.color = 'violet'
89
+ @heffalump.save
90
+ @heffalump.id.should == id
91
+ end
92
+
93
+ it 'should update altered fields' do
94
+ @heffalump.color = 'violet'
95
+ @heffalump.save
96
+ Heffalump.get(*@heffalump.key).color.should == 'violet'
97
+ end
98
+
99
+ it 'should not alter other fields' do
100
+ color = @heffalump.color
101
+ @heffalump.num_spots = 3
102
+ @heffalump.save
103
+ Heffalump.get(*@heffalump.key).color.should == color
104
+ end
105
+ end
106
+ else
107
+ it 'needs to support #update'
108
+ end
109
+
110
+ if adapter_supports?(:delete)
111
+ describe '#delete' do
112
+ before do
113
+ @heffalump = Heffalump.create(:color => 'forest green')
114
+ end
115
+
116
+ it 'should not raise any errors' do
117
+ lambda {
118
+ @heffalump.destroy
119
+ }.should_not raise_error
120
+ end
121
+
122
+ it 'should delete the requested resource' do
123
+ id = @heffalump.id
124
+ @heffalump.destroy
125
+ Heffalump.get(id).should be_nil
126
+ end
127
+ end
128
+ else
129
+ it 'needs to support #delete'
130
+ end
131
+
132
+ if adapter_supports?(:read, :create)
133
+ describe 'query matching' do
134
+ before :all do
135
+ @red = Heffalump.create(:color => 'red')
136
+ @two = Heffalump.create(:num_spots => 2)
137
+ @five = Heffalump.create(:num_spots => 5)
138
+ end
139
+
140
+ describe 'conditions' do
141
+ describe 'eql' do
142
+ it 'should be able to search for objects included in an inclusive range of values' do
143
+ Heffalump.all(:num_spots => 1..5).should be_include(@five)
144
+ end
145
+
146
+ it 'should be able to search for objects included in an exclusive range of values' do
147
+ Heffalump.all(:num_spots => 1...6).should be_include(@five)
148
+ end
149
+
150
+ it 'should not be able to search for values not included in an inclusive range of values' do
151
+ Heffalump.all(:num_spots => 1..4).should_not be_include(@five)
152
+ end
153
+
154
+ it 'should not be able to search for values not included in an exclusive range of values' do
155
+ Heffalump.all(:num_spots => 1...5).should_not be_include(@five)
156
+ end
157
+ end
158
+
159
+ describe 'not' do
160
+ it 'should be able to search for objects with not equal value' do
161
+ Heffalump.all(:color.not => 'red').should_not be_include(@red)
162
+ end
163
+
164
+ it 'should include objects that are not like the value' do
165
+ Heffalump.all(:color.not => 'black').should be_include(@red)
166
+ end
167
+
168
+ it 'should be able to search for objects with not nil value' do
169
+ Heffalump.all(:color.not => nil).should be_include(@red)
170
+ end
171
+
172
+ it 'should not include objects with a nil value' do
173
+ Heffalump.all(:color.not => nil).should_not be_include(@two)
174
+ end
175
+
176
+ it 'should be able to search for object with a nil value using required properties' do
177
+ Heffalump.all(:id.not => nil).should == [ @red, @two, @five ]
178
+ end
179
+
180
+ it 'should be able to search for objects not in an empty list (match all)' do
181
+ Heffalump.all(:color.not => []).should == [ @red, @two, @five ]
182
+ end
183
+
184
+ it 'should be able to search for objects in an empty list and another OR condition (match none on the empty list)' do
185
+ Heffalump.all(:conditions => DataMapper::Query::Conditions::Operation.new(
186
+ :or,
187
+ DataMapper::Query::Conditions::Comparison.new(:in, Heffalump.properties[:color], []),
188
+ DataMapper::Query::Conditions::Comparison.new(:in, Heffalump.properties[:num_spots], [5]))).should == [ @five ]
189
+ end
190
+
191
+ it 'should be able to search for objects not included in an array of values' do
192
+ Heffalump.all(:num_spots.not => [ 1, 3, 5, 7 ]).should be_include(@two)
193
+ end
194
+
195
+ it 'should be able to search for objects not included in an array of values' do
196
+ Heffalump.all(:num_spots.not => [ 1, 3, 5, 7 ]).should_not be_include(@five)
197
+ end
198
+
199
+ it 'should be able to search for objects not included in an inclusive range of values' do
200
+ Heffalump.all(:num_spots.not => 1..4).should be_include(@five)
201
+ end
202
+
203
+ it 'should be able to search for objects not included in an exclusive range of values' do
204
+ Heffalump.all(:num_spots.not => 1...5).should be_include(@five)
205
+ end
206
+
207
+ it 'should not be able to search for values not included in an inclusive range of values' do
208
+ Heffalump.all(:num_spots.not => 1..5).should_not be_include(@five)
209
+ end
210
+
211
+ it 'should not be able to search for values not included in an exclusive range of values' do
212
+ Heffalump.all(:num_spots.not => 1...6).should_not be_include(@five)
213
+ end
214
+ end
215
+
216
+ describe 'like' do
217
+ it 'should be able to search for objects that match value' do
218
+ Heffalump.all(:color.like => '%ed').should be_include(@red)
219
+ end
220
+
221
+ it 'should not search for objects that do not match the value' do
222
+ Heffalump.all(:color.like => '%blak%').should_not be_include(@red)
223
+ end
224
+ end
225
+
226
+ describe 'regexp' do
227
+ before do
228
+ if (defined?(DataMapper::Adapters::Sqlite3Adapter) && @adapter.kind_of?(DataMapper::Adapters::Sqlite3Adapter) ||
229
+ defined?(DataMapper::Adapters::SqlserverAdapter) && @adapter.kind_of?(DataMapper::Adapters::SqlserverAdapter))
230
+ pending 'delegate regexp matches to same system that the InMemory and YAML adapters use'
231
+ end
232
+ end
233
+
234
+ it 'should be able to search for objects that match value' do
235
+ Heffalump.all(:color => /ed/).should be_include(@red)
236
+ end
237
+
238
+ it 'should not be able to search for objects that do not match the value' do
239
+ Heffalump.all(:color => /blak/).should_not be_include(@red)
240
+ end
241
+
242
+ it 'should be able to do a negated search for objects that match value' do
243
+ Heffalump.all(:color.not => /blak/).should be_include(@red)
244
+ end
245
+
246
+ it 'should not be able to do a negated search for objects that do not match value' do
247
+ Heffalump.all(:color.not => /ed/).should_not be_include(@red)
248
+ end
249
+
250
+ end
251
+
252
+ describe 'gt' do
253
+ it 'should be able to search for objects with value greater than' do
254
+ Heffalump.all(:num_spots.gt => 1).should be_include(@two)
255
+ end
256
+
257
+ it 'should not find objects with a value less than' do
258
+ Heffalump.all(:num_spots.gt => 3).should_not be_include(@two)
259
+ end
260
+ end
261
+
262
+ describe 'gte' do
263
+ it 'should be able to search for objects with value greater than' do
264
+ Heffalump.all(:num_spots.gte => 1).should be_include(@two)
265
+ end
266
+
267
+ it 'should be able to search for objects with values equal to' do
268
+ Heffalump.all(:num_spots.gte => 2).should be_include(@two)
269
+ end
270
+
271
+ it 'should not find objects with a value less than' do
272
+ Heffalump.all(:num_spots.gte => 3).should_not be_include(@two)
273
+ end
274
+ end
275
+
276
+ describe 'lt' do
277
+ it 'should be able to search for objects with value less than' do
278
+ Heffalump.all(:num_spots.lt => 3).should be_include(@two)
279
+ end
280
+
281
+ it 'should not find objects with a value less than' do
282
+ Heffalump.all(:num_spots.gt => 2).should_not be_include(@two)
283
+ end
284
+ end
285
+
286
+ describe 'lte' do
287
+ it 'should be able to search for objects with value less than' do
288
+ Heffalump.all(:num_spots.lte => 3).should be_include(@two)
289
+ end
290
+
291
+ it 'should be able to search for objects with values equal to' do
292
+ Heffalump.all(:num_spots.lte => 2).should be_include(@two)
293
+ end
294
+
295
+ it 'should not find objects with a value less than' do
296
+ Heffalump.all(:num_spots.lte => 1).should_not be_include(@two)
297
+ end
298
+ end
299
+ end
300
+
301
+ describe 'limits' do
302
+ it 'should be able to limit the objects' do
303
+ Heffalump.all(:limit => 2).length.should == 2
304
+ end
305
+ end
306
+ end
307
+ else
308
+ it 'needs to support #read and #create to test query matching'
309
+ end
310
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format sn
@@ -0,0 +1,22 @@
1
+ require "spec"
2
+ require 'pathname'
3
+ require Pathname(__FILE__).dirname.parent.expand_path + 'lib/couchdb_adapter'
4
+
5
+ # use local copy of dm-core if available
6
+ local_dm_core_lib = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'dm-core', 'lib'))
7
+ $LOAD_PATH.unshift(local_dm_core_lib) if File.directory?(local_dm_core_lib)
8
+
9
+ begin
10
+ gem 'dm-serializer'
11
+ require 'dm-serializer'
12
+ DMSERIAL_AVAILABLE = true
13
+ rescue LoadError
14
+ DMSERIAL_AVAILABLE = false
15
+ end
16
+
17
+ Spec::Runner.configure do |config|
18
+ config.before(:all) do
19
+ @adapter = DataMapper.setup(:default, "couchdb://localhost:5984/test_cdb_adapter")
20
+ @repository = DataMapper.repository(@adapter.name)
21
+ end
22
+ end
data/spec/testfile.txt ADDED
@@ -0,0 +1 @@
1
+ test string
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ # shared adapter spec
4
+ require File.join(File.dirname(__FILE__), *%w[.. shared adapter_shared_spec])
5
+
6
+ describe DataMapper::Adapters::CouchDBAdapter do
7
+ it_should_behave_like "An Adapter"
8
+ end
data/tasks/install.rb ADDED
@@ -0,0 +1,13 @@
1
+ def sudo_gem(cmd)
2
+ sh "#{SUDO} #{RUBY} -S gem #{cmd}", :verbose => false
3
+ end
4
+
5
+ desc "Install #{GEM_NAME} #{GEM_VERSION}"
6
+ task :install => [ :package ] do
7
+ sudo_gem "install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources"
8
+ end
9
+
10
+ desc "Uninstall #{GEM_NAME} #{GEM_VERSION}"
11
+ task :uninstall => [ :clobber ] do
12
+ sudo_gem "uninstall #{GEM_NAME} -v#{GEM_VERSION} -Ix"
13
+ end
data/tasks/spec.rb ADDED
@@ -0,0 +1,25 @@
1
+ begin
2
+ gem 'rspec', '~>1.1.11'
3
+ require 'spec'
4
+ require 'spec/rake/spectask'
5
+
6
+ task :default => [ :spec ]
7
+
8
+ desc 'Run specifications'
9
+ Spec::Rake::SpecTask.new(:spec) do |t|
10
+ t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
11
+ t.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s).map { |f| f.to_s }
12
+
13
+ begin
14
+ gem 'rcov', '~>0.8'
15
+ t.rcov = JRUBY ? false : (ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true)
16
+ t.rcov_opts << '--exclude' << 'spec'
17
+ t.rcov_opts << '--text-summary'
18
+ t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
19
+ rescue LoadError
20
+ # rcov not installed
21
+ end
22
+ end
23
+ rescue LoadError
24
+ # rspec not installed
25
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dm-couchdb-adapter
3
+ version: !ruby/object:Gem::Version
4
+ hash: 51
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 10
9
+ - 2
10
+ version: 0.10.2
11
+ platform: ruby
12
+ authors:
13
+ - Kabari Hendrick
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-21 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: extlib
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 45
29
+ segments:
30
+ - 0
31
+ - 9
32
+ - 11
33
+ version: 0.9.11
34
+ prerelease: false
35
+ type: :runtime
36
+ requirement: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: mime-types
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 17
45
+ segments:
46
+ - 1
47
+ - 15
48
+ version: "1.15"
49
+ prerelease: false
50
+ type: :runtime
51
+ requirement: *id002
52
+ description:
53
+ email: kabari [a] gmail [d] com
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files:
59
+ - LICENSE
60
+ - README.rdoc
61
+ - TODO
62
+ files:
63
+ - Gemfile
64
+ - History.txt
65
+ - LICENSE
66
+ - Manifest.txt
67
+ - README.rdoc
68
+ - Rakefile
69
+ - TODO
70
+ - VERSION
71
+ - lib/couchdb_adapter.rb
72
+ - lib/couchdb_adapter/adapter.rb
73
+ - lib/couchdb_adapter/attachments.rb
74
+ - lib/couchdb_adapter/collection.rb
75
+ - lib/couchdb_adapter/conditions.rb
76
+ - lib/couchdb_adapter/couch_resource.rb
77
+ - lib/couchdb_adapter/design.rb
78
+ - lib/couchdb_adapter/json_object.rb
79
+ - lib/couchdb_adapter/migrations.rb
80
+ - lib/couchdb_adapter/model.rb
81
+ - lib/couchdb_adapter/query.rb
82
+ - lib/couchdb_adapter/resource.rb
83
+ - lib/couchdb_adapter/version.rb
84
+ - lib/couchdb_adapter/view.rb
85
+ - spec/integration/couchdb_adapter_spec.rb
86
+ - spec/integration/couchdb_attachments_spec.rb
87
+ - spec/integration/couchdb_view_spec.rb
88
+ - spec/integration_spec.rb
89
+ - spec/shared/adapter_shared_spec.rb
90
+ - spec/spec.opts
91
+ - spec/spec_helper.rb
92
+ - spec/testfile.txt
93
+ - spec/unit/couch_db_adapter_spec.rb
94
+ - tasks/install.rb
95
+ - tasks/spec.rb
96
+ has_rdoc: true
97
+ homepage: http://github.com/kabari/dm-couchdb-adapter/tree/master
98
+ licenses: []
99
+
100
+ post_install_message:
101
+ rdoc_options: []
102
+
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ hash: 59
111
+ segments:
112
+ - 1
113
+ - 8
114
+ - 6
115
+ version: 1.8.6
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ hash: 3
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ requirements: []
126
+
127
+ rubyforge_project:
128
+ rubygems_version: 1.5.0
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: CouchDB Adapter for DataMapper
132
+ test_files:
133
+ - spec/integration/couchdb_adapter_spec.rb
134
+ - spec/integration/couchdb_attachments_spec.rb
135
+ - spec/integration/couchdb_view_spec.rb
136
+ - spec/integration_spec.rb
137
+ - spec/shared/adapter_shared_spec.rb
138
+ - spec/spec_helper.rb
139
+ - spec/unit/couch_db_adapter_spec.rb