ardm-core 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.travis.yml +2 -2
  4. data/Gemfile +1 -11
  5. data/ardm-core.gemspec +3 -3
  6. data/lib/dm-core.rb +2 -2
  7. data/lib/dm-core/adapters/abstract_adapter.rb +1 -1
  8. data/lib/dm-core/associations/many_to_one.rb +6 -4
  9. data/lib/dm-core/collection.rb +1 -0
  10. data/lib/dm-core/model.rb +3 -2
  11. data/lib/dm-core/model/property.rb +2 -1
  12. data/lib/dm-core/property.rb +4 -2
  13. data/lib/dm-core/query.rb +1 -1
  14. data/lib/dm-core/resource.rb +8 -1
  15. data/lib/dm-core/resource/persistence_state/transient.rb +14 -1
  16. data/lib/dm-core/spec/lib/adapter_helpers.rb +2 -0
  17. data/lib/dm-core/spec/lib/spec_helper.rb +2 -3
  18. data/lib/dm-core/spec/setup.rb +4 -2
  19. data/lib/dm-core/spec/shared/adapter_spec.rb +116 -77
  20. data/lib/dm-core/spec/shared/resource_spec.rb +5 -1
  21. data/lib/dm-core/support/mash.rb +1 -1
  22. data/lib/dm-core/support/naming_conventions.rb +20 -1
  23. data/lib/dm-core/support/ordered_set.rb +1 -0
  24. data/lib/dm-core/support/subject_set.rb +1 -0
  25. data/lib/dm-core/version.rb +1 -1
  26. data/script/performance.rb +1 -1
  27. data/script/profile.rb +1 -1
  28. data/spec/public/associations/many_to_many_spec.rb +2 -2
  29. data/spec/public/associations/many_to_one_spec.rb +1 -1
  30. data/spec/public/associations/one_to_many_spec.rb +1 -1
  31. data/spec/public/associations/one_to_one_spec.rb +2 -2
  32. data/spec/public/finalize_spec.rb +2 -2
  33. data/spec/public/model/relationship_spec.rb +19 -19
  34. data/spec/public/model_spec.rb +1 -1
  35. data/spec/public/property/discriminator_spec.rb +2 -2
  36. data/spec/public/property/object_spec.rb +13 -2
  37. data/spec/public/property_spec.rb +0 -6
  38. data/spec/public/resource/state_spec.rb +72 -0
  39. data/spec/public/resource_spec.rb +5 -5
  40. data/spec/public/shared/association_collection_shared_spec.rb +1 -1
  41. data/spec/public/shared/collection_shared_spec.rb +24 -24
  42. data/spec/public/shared/finder_shared_spec.rb +26 -8
  43. data/spec/spec.opts +1 -3
  44. data/tasks/ci.rake +1 -1
  45. data/tasks/spec.rake +0 -21
  46. data/tasks/yardstick.rake +1 -1
  47. metadata +26 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d88a1388e05bc0987ce1ea0fcfd902bd19a91b5
4
- data.tar.gz: 185295c3d88d126fcefe257eb50894cb9fccb99f
3
+ metadata.gz: 8efb580769f20f6f9438dd38548c3a7e4f1cd482
4
+ data.tar.gz: 38b486935a5a8c73f4f300541940198500df54cd
5
5
  SHA512:
6
- metadata.gz: e3244f70503a3c2174bb896dda56ab841690761edfa2dd21b0009be74d5bd20bd7f125bb088b37066084d27ccb61677eb376817f97e7e8d560dacd26fbfdf56a
7
- data.tar.gz: 65012a3e5de43b6923fb0ac9a5e8333fb77315ebdf1bcb7ee5bab75c68127762ce8c35fbf3fb2f966d5be691cf66e6175d79e88f5287f970d5d0a7a57b85e942
6
+ metadata.gz: 7f02886cc1a7446399518d8a3999485672a7ee4d061a60fae5921feb7958f01b4a27480b6aa9204c14b24d0c139dfb8becd91a748f5119a7cc6971a67a69bd2b
7
+ data.tar.gz: 061949f62500d4c206bc1f01a1fc9ad07f406a1363eede06ea72f739524f9d3bcf3335cd28a18cc376281e5fd43416f7225328714e600b91c20e27ffdec488f9
data/.gitignore CHANGED
@@ -15,10 +15,13 @@ tmtags
15
15
 
16
16
  ## Rubinius
17
17
  *.rbc
18
+ .rbx
18
19
 
19
20
  ## PROJECT::GENERAL
20
21
  *.gem
21
22
  coverage
23
+ profiling
24
+ turbulence
22
25
  rdoc
23
26
  pkg
24
27
  tmp
@@ -9,8 +9,8 @@ before_install:
9
9
  script: "bundle exec rake spec"
10
10
  env:
11
11
  - "ADAPTER=in_memory"
12
- - "ADAPTER=yaml"
13
- - "ADAPTER=sqlite"
12
+ # - "ADAPTER=yaml"
13
+ # - "ADAPTER=sqlite"
14
14
  - "ADAPTER=mysql DM_DB_USER=root DM_DB_PASSWORD=''"
15
15
  rvm:
16
16
  - 1.9.3
data/Gemfile CHANGED
@@ -9,21 +9,11 @@ gemspec
9
9
  SOURCE = ENV.fetch('SOURCE', :git).to_sym
10
10
  REPO_POSTFIX = SOURCE == :path ? '' : '.git'
11
11
  DATAMAPPER = SOURCE == :path ? Pathname(__FILE__).dirname.parent : 'http://github.com/ar-dm'
12
- DM_VERSION = '~> 1.2.0'
12
+ DM_VERSION = '~> 1.2'
13
13
  DO_VERSION = '~> 0.10.6'
14
14
  DM_DO_ADAPTERS = %w[ sqlite postgres mysql oracle sqlserver ]
15
15
  CURRENT_BRANCH = ENV.fetch('GIT_BRANCH', 'master')
16
16
 
17
- platforms :mri_18 do
18
- group :quality do
19
-
20
- gem 'rcov', '~> 0.9.10'
21
- gem 'yard', '~> 0.7.2'
22
- gem 'yardstick', '~> 0.4'
23
-
24
- end
25
- end
26
-
27
17
  group :datamapper do
28
18
 
29
19
  adapters = ENV['ADAPTERS'] || ENV['ADAPTER']
@@ -18,8 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.test_files = `git ls-files -- spec/*`.split("\n")
19
19
  s.extra_rdoc_files = %w[LICENSE README.rdoc]
20
20
 
21
- s.add_dependency('addressable', "~> 2.3")
21
+ s.add_dependency 'addressable', '~> 2.3', '>= 2.3.5'
22
22
 
23
- s.add_development_dependency('rake', '~> 0.9')
24
- s.add_development_dependency('rspec', '~> 1.3')
23
+ s.add_development_dependency 'rake', '~> 10.0'
24
+ s.add_development_dependency 'rspec', '~> 1.3'
25
25
  end
@@ -120,7 +120,7 @@ end
120
120
  # == Setup and Configuration
121
121
  # DataMapper uses URIs or a connection hash to connect to your data-store.
122
122
  # URI connections takes the form of:
123
- # DataMapper.setup(:default, 'protocol://username:password@localhost:port/path/to/repo')
123
+ # DataMapper.setup(:default, 'protocol://username:password@127.0.0.1:port/path/to/repo')
124
124
  #
125
125
  # Breaking this down, the first argument is the name you wish to give this
126
126
  # connection. If you do not specify one, it will be assigned :default. If you
@@ -137,7 +137,7 @@ end
137
137
  #
138
138
  # Here's some examples
139
139
  # DataMapper.setup(:default, 'sqlite3://path/to/your/project/db/development.db')
140
- # DataMapper.setup(:default, 'mysql://localhost/dm_core_test')
140
+ # DataMapper.setup(:default, 'mysql://127.0.0.1/dm_core_test')
141
141
  # # no auth-info
142
142
  # DataMapper.setup(:default, 'postgres://root:supahsekret@127.0.0.1/dm_core_test')
143
143
  # # with auth-info
@@ -35,7 +35,7 @@ module DataMapper
35
35
  #
36
36
  # Note that when you use
37
37
  #
38
- # DataMapper.setup(:default, 'postgres://postgres@localhost/dm_core_test')
38
+ # DataMapper.setup(:default, 'postgres://postgres@127.0.0.1/dm_core_test')
39
39
  #
40
40
  # the adapter name is currently set to :default
41
41
  #
@@ -207,6 +207,7 @@ module DataMapper
207
207
  @required = options.fetch(:required, true)
208
208
  @key = options.fetch(:key, false)
209
209
  @unique = options.fetch(:unique, false)
210
+ @unique_index = options.fetch(:unique_index, @unique)
210
211
  target_model ||= DataMapper::Inflector.camelize(name)
211
212
  options = { :min => @required ? 1 : 0, :max => 1 }.update(options)
212
213
  super
@@ -260,10 +261,11 @@ module DataMapper
260
261
  # @api private
261
262
  def source_key_options(target_property)
262
263
  options = DataMapper::Ext::Hash.only(target_property.options, :length, :precision, :scale).update(
263
- :index => name,
264
- :required => required?,
265
- :key => key?,
266
- :unique => @unique
264
+ :index => name,
265
+ :required => required?,
266
+ :key => key?,
267
+ :unique => @unique,
268
+ :unique_index => @unique_index
267
269
  )
268
270
 
269
271
  if target_property.primitive == Integer
@@ -501,6 +501,7 @@ module DataMapper
501
501
  #
502
502
  # @api public
503
503
  def each
504
+ return to_enum unless block_given?
504
505
  super do |resource|
505
506
  begin
506
507
  original, resource.collection = resource.collection, self
@@ -314,6 +314,7 @@ module DataMapper
314
314
  end
315
315
 
316
316
  def each(&block)
317
+ return to_enum unless block_given?
317
318
  all.each(&block)
318
319
  self
319
320
  end
@@ -847,7 +848,7 @@ module DataMapper
847
848
  repository_name = self.repository_name
848
849
  if properties(repository_name).empty? &&
849
850
  !relationships(repository_name).any? { |relationship| relationship.kind_of?(Associations::ManyToOne::Relationship) }
850
- raise IncompleteModelError, "#{name} must have at least one property or many to one relationship to be valid"
851
+ raise IncompleteModelError, "#{name} must have at least one property or many to one relationship in #{repository_name} to be valid"
851
852
  end
852
853
  end
853
854
 
@@ -861,7 +862,7 @@ module DataMapper
861
862
  # @api private
862
863
  def assert_valid_key
863
864
  if key(repository_name).empty?
864
- raise IncompleteModelError, "#{name} must have a key to be valid"
865
+ raise IncompleteModelError, "#{name} must have a key in #{repository_name} to be valid"
865
866
  end
866
867
  end
867
868
 
@@ -175,7 +175,7 @@ module DataMapper
175
175
 
176
176
  # @api private
177
177
  def key_conditions(repository, key)
178
- Hash[ self.key(repository.name).zip(key.nil? ? [] : key) ]
178
+ Hash[self.key(repository.name).zip(Array(key))]
179
179
  end
180
180
 
181
181
  private
@@ -234,6 +234,7 @@ module DataMapper
234
234
  #{writer_visibility}
235
235
  def #{writer_name}(value)
236
236
  property = properties[#{name.inspect}]
237
+ value = property.typecast(value)
237
238
  self.persistence_state = persistence_state.set(property, value)
238
239
  persistence_state.get(property)
239
240
  end
@@ -622,7 +622,7 @@ module DataMapper
622
622
  #
623
623
  # @api private
624
624
  def set(resource, value)
625
- set!(resource, typecast(value))
625
+ set!(resource, value)
626
626
  end
627
627
 
628
628
  # Set the ivar value in the resource
@@ -682,8 +682,10 @@ module DataMapper
682
682
  def typecast(value)
683
683
  if value.nil? || primitive?(value)
684
684
  value
685
- elsif respond_to?(:typecast_to_primitive)
685
+ elsif respond_to?(:typecast_to_primitive, true)
686
686
  typecast_to_primitive(value)
687
+ else
688
+ value
687
689
  end
688
690
  end
689
691
 
@@ -1017,7 +1017,7 @@ module DataMapper
1017
1017
  add_condition(condition)
1018
1018
 
1019
1019
  when Hash
1020
- condition.each { |kv| append_condition(*kv) }
1020
+ condition.each { |key, value| append_condition(key, value) }
1021
1021
 
1022
1022
  when Array
1023
1023
  statement, *bind_values = *condition
@@ -280,7 +280,10 @@ module DataMapper
280
280
  # @api public
281
281
  def attribute_set(name, value)
282
282
  property = properties[name]
283
- self.persistence_state = persistence_state.set(property, value) if property
283
+ if property
284
+ value = property.typecast(value)
285
+ self.persistence_state = persistence_state.set(property, value)
286
+ end
284
287
  end
285
288
 
286
289
  alias_method :[]=, :attribute_set
@@ -335,6 +338,10 @@ module DataMapper
335
338
  raise ArgumentError, "The attribute '#{name}' is not accessible in #{model}"
336
339
  end
337
340
  when Associations::Relationship, Property
341
+ # only call a public #typecast (e.g. on Property instances)
342
+ if name.respond_to?(:typecast)
343
+ value = name.typecast(value)
344
+ end
338
345
  self.persistence_state = persistence_state.set(name, value)
339
346
  end
340
347
  end
@@ -50,7 +50,20 @@ module DataMapper
50
50
 
51
51
  def set_default_value(subject)
52
52
  return if subject.loaded?(resource) || !subject.default?
53
- set(subject, subject.default_for(resource))
53
+ default = typecast_default(subject, subject.default_for(resource))
54
+ set(subject, default)
55
+ end
56
+
57
+ def typecast_default(subject, default)
58
+ return default unless subject.respond_to?(:typecast)
59
+
60
+ typecasted_default = subject.send(:typecast, default)
61
+ unless typecasted_default.eql?(default)
62
+ warn "Automatic typecasting of default property values is deprecated " +
63
+ "(#{default.inspect} was casted to #{typecasted_default.inspect}). " +
64
+ "Specify the correct type for #{resource.class}."
65
+ end
66
+ typecasted_default
54
67
  end
55
68
 
56
69
  def track(subject)
@@ -18,6 +18,8 @@ module DataMapper
18
18
 
19
19
  def describe_adapter(kind, &block)
20
20
  describe("with #{kind} adapter") do
21
+ let(:adapter) { @adapter }
22
+ let(:repository) { @repository }
21
23
 
22
24
  before :all do
23
25
  # store these in instance vars for the shared adapter specs
@@ -45,12 +45,11 @@ module DataMapper
45
45
  next if object.kind_of?(DataMapper::Logger) ||
46
46
  object.kind_of?(DataMapper::DescendantSet) ||
47
47
  object.kind_of?(DataMapper::Adapters::AbstractAdapter) ||
48
- object.class.name[0, 13] == 'DataObjects::'
48
+ object.class.name.to_s[0, 13] == 'DataObjects::'
49
49
 
50
50
  # skip classes and modules in the DataMapper namespace
51
51
  next if object.kind_of?(Module) &&
52
- !object.name.nil? &&
53
- object.name[0, 12] == 'DataMapper::'
52
+ object.name.to_s[0, 12] == 'DataMapper::'
54
53
 
55
54
  # skip when the ivar is no longer defined in the object
56
55
  next unless object.instance_variable_defined?(ivar)
@@ -115,7 +115,9 @@ module DataMapper
115
115
  end
116
116
 
117
117
  def connection_uri
118
- "#{adapter_name}://#{username}:#{password}@#{host}/#{storage_name}"
118
+ "#{adapter_name}://#{username}%s@#{host}/#{storage_name}".tap do |s|
119
+ return s % ((password.empty?) ? "" : ":#{password}")
120
+ end
119
121
  end
120
122
 
121
123
  def storage_name
@@ -139,7 +141,7 @@ module DataMapper
139
141
  end
140
142
 
141
143
  def host
142
- ENV.fetch('DM_DB_HOST', 'localhost')
144
+ ENV.fetch('DM_DB_HOST', '127.0.0.1')
143
145
  end
144
146
 
145
147
  # Test the connection
@@ -22,38 +22,58 @@ share_examples_for 'An Adapter' do
22
22
  end
23
23
  end
24
24
 
25
- before :all do
26
- raise '+@adapter+ should be defined in before block' unless instance_variable_get('@adapter')
25
+ # Hack to detect cases a let(:heffalump_model) is not present
26
+ unless instance_methods.map(&:to_s).include?('heffalump_model')
27
+ # This is the default Heffalump model. You can replace it with your own
28
+ # (using let/let!) # but # be shure the replacement provides the required
29
+ # properties.
30
+ let(:heffalump_model) do
31
+ model = Class.new do
32
+ include DataMapper::Resource
33
+
34
+ property :id, DataMapper::Property::Serial
35
+ property :color, DataMapper::Property::String
36
+ property :num_spots, DataMapper::Property::Integer
37
+ property :striped, DataMapper::Property::Boolean
38
+
39
+ # This is needed for DataMapper.finalize
40
+ def self.name; 'Heffalump'; end
41
+ end
27
42
 
28
- class ::Heffalump
29
- include DataMapper::Resource
43
+ DataMapper.finalize
30
44
 
31
- property :id, Serial
32
- property :color, String
33
- property :num_spots, Integer
34
- property :striped, Boolean
45
+ model
35
46
  end
47
+ end
48
+
49
+ before :all do
50
+ raise '+#adapter+ should be defined in a let(:adapter) block' unless respond_to?(:adapter)
51
+ raise '+#repository+ should be defined in a let(:repository) block' unless respond_to?(:repository)
36
52
 
37
53
  DataMapper.finalize
38
54
 
39
55
  # create all tables and constraints before each spec
40
- if @repository.respond_to?(:auto_migrate!)
41
- Heffalump.auto_migrate!
56
+ if repository.respond_to?(:auto_migrate!)
57
+ heffalump_model.auto_migrate!
42
58
  end
43
59
  end
44
60
 
45
61
  if adapter_supports?(:create)
46
62
  describe '#create' do
63
+ after do
64
+ heffalump_model.destroy
65
+ end
66
+
47
67
  it 'should not raise any errors' do
48
68
  lambda {
49
- Heffalump.create(:color => 'peach')
69
+ heffalump_model.new(:color => 'peach').save.should be(true)
50
70
  }.should_not raise_error
51
71
  end
52
72
 
53
73
  it 'should set the identity field for the resource' do
54
- heffalump = Heffalump.new(:color => 'peach')
74
+ heffalump = heffalump_model.new(:color => 'peach')
55
75
  heffalump.id.should be_nil
56
- heffalump.save
76
+ heffalump.save.should be(true)
57
77
  heffalump.id.should_not be_nil
58
78
  end
59
79
  end
@@ -64,19 +84,23 @@ share_examples_for 'An Adapter' do
64
84
  if adapter_supports?(:read)
65
85
  describe '#read' do
66
86
  before :all do
67
- @heffalump = Heffalump.create(:color => 'brownish hue')
68
- #just going to borrow this, so I can check the return values
69
- @query = Heffalump.all.query
87
+ @heffalump = heffalump_model.create(:color => 'brownish hue')
88
+ @heffalump.should be_saved
89
+ @query = heffalump_model.all.query
90
+ end
91
+
92
+ after :all do
93
+ heffalump_model.destroy
70
94
  end
71
95
 
72
96
  it 'should not raise any errors' do
73
97
  lambda {
74
- Heffalump.all()
98
+ heffalump_model.all()
75
99
  }.should_not raise_error
76
100
  end
77
101
 
78
- it 'should return stuff' do
79
- Heffalump.all.should be_include(@heffalump)
102
+ it 'should return expected results' do
103
+ heffalump_model.all.should == [ @heffalump ]
80
104
  end
81
105
  end
82
106
  else
@@ -86,34 +110,39 @@ share_examples_for 'An Adapter' do
86
110
  if adapter_supports?(:update)
87
111
  describe '#update' do
88
112
  before do
89
- @heffalump = Heffalump.create(:color => 'indigo')
113
+ @heffalump = heffalump_model.create(:color => 'peach', :num_spots => 1, :striped => false)
114
+ @heffalump.should be_saved
115
+ end
116
+
117
+ after do
118
+ heffalump_model.destroy
90
119
  end
91
120
 
92
121
  it 'should not raise any errors' do
93
122
  lambda {
94
- @heffalump.color = 'violet'
95
- @heffalump.save
123
+ @heffalump.num_spots = 0
124
+ @heffalump.save.should be(true)
96
125
  }.should_not raise_error
97
126
  end
98
127
 
99
128
  it 'should not alter the identity field' do
100
- id = @heffalump.id
101
- @heffalump.color = 'violet'
102
- @heffalump.save
103
- @heffalump.id.should == id
129
+ key = @heffalump.key
130
+ @heffalump.num_spots = 0
131
+ @heffalump.save.should be(true)
132
+ @heffalump.key.should == key
104
133
  end
105
134
 
106
135
  it 'should update altered fields' do
107
- @heffalump.color = 'violet'
108
- @heffalump.save
109
- Heffalump.get(*@heffalump.key).color.should == 'violet'
136
+ @heffalump.num_spots = 0
137
+ @heffalump.save.should be(true)
138
+ heffalump_model.get!(*@heffalump.key).num_spots.should be(0)
110
139
  end
111
140
 
112
141
  it 'should not alter other fields' do
113
- color = @heffalump.color
114
- @heffalump.num_spots = 3
115
- @heffalump.save
116
- Heffalump.get(*@heffalump.key).color.should == color
142
+ num_spots = @heffalump.num_spots
143
+ @heffalump.striped = true
144
+ @heffalump.save.should be(true)
145
+ heffalump_model.get!(*@heffalump.key).num_spots.should be(num_spots)
117
146
  end
118
147
  end
119
148
  else
@@ -123,7 +152,12 @@ share_examples_for 'An Adapter' do
123
152
  if adapter_supports?(:delete)
124
153
  describe '#delete' do
125
154
  before do
126
- @heffalump = Heffalump.create(:color => 'forest green')
155
+ @heffalump = heffalump_model.create(:color => 'forest green')
156
+ @heffalump.should be_saved
157
+ end
158
+
159
+ after do
160
+ heffalump_model.destroy
127
161
  end
128
162
 
129
163
  it 'should not raise any errors' do
@@ -133,9 +167,9 @@ share_examples_for 'An Adapter' do
133
167
  end
134
168
 
135
169
  it 'should delete the requested resource' do
136
- id = @heffalump.id
170
+ key = @heffalump.key
137
171
  @heffalump.destroy
138
- Heffalump.get(id).should be_nil
172
+ heffalump_model.get(*key).should be_nil
139
173
  end
140
174
  end
141
175
  else
@@ -145,178 +179,183 @@ share_examples_for 'An Adapter' do
145
179
  if adapter_supports?(:read, :create)
146
180
  describe 'query matching' do
147
181
  before :all do
148
- @red = Heffalump.create(:color => 'red')
149
- @two = Heffalump.create(:num_spots => 2)
150
- @five = Heffalump.create(:num_spots => 5)
182
+ @red = heffalump_model.create(:color => 'red')
183
+ @two = heffalump_model.create(:num_spots => 2)
184
+ @five = heffalump_model.create(:num_spots => 5)
185
+ [ @red, @two, @five ].each { |resource| resource.should be_saved }
186
+ end
187
+
188
+ after :all do
189
+ heffalump_model.destroy
151
190
  end
152
191
 
153
192
  describe 'conditions' do
154
193
  describe 'eql' do
155
194
  it 'should be able to search for objects included in an inclusive range of values' do
156
- Heffalump.all(:num_spots => 1..5).should be_include(@five)
195
+ heffalump_model.all(:num_spots => 1..5).should include(@five)
157
196
  end
158
197
 
159
198
  it 'should be able to search for objects included in an exclusive range of values' do
160
- Heffalump.all(:num_spots => 1...6).should be_include(@five)
199
+ heffalump_model.all(:num_spots => 1...6).should include(@five)
161
200
  end
162
201
 
163
202
  it 'should not be able to search for values not included in an inclusive range of values' do
164
- Heffalump.all(:num_spots => 1..4).should_not be_include(@five)
203
+ heffalump_model.all(:num_spots => 1..4).should_not include(@five)
165
204
  end
166
205
 
167
206
  it 'should not be able to search for values not included in an exclusive range of values' do
168
- Heffalump.all(:num_spots => 1...5).should_not be_include(@five)
207
+ heffalump_model.all(:num_spots => 1...5).should_not include(@five)
169
208
  end
170
209
  end
171
210
 
172
211
  describe 'not' do
173
212
  it 'should be able to search for objects with not equal value' do
174
- Heffalump.all(:color.not => 'red').should_not be_include(@red)
213
+ heffalump_model.all(:color.not => 'red').should_not include(@red)
175
214
  end
176
215
 
177
216
  it 'should include objects that are not like the value' do
178
- Heffalump.all(:color.not => 'black').should be_include(@red)
217
+ heffalump_model.all(:color.not => 'black').should include(@red)
179
218
  end
180
219
 
181
220
  it 'should be able to search for objects with not nil value' do
182
- Heffalump.all(:color.not => nil).should be_include(@red)
221
+ heffalump_model.all(:color.not => nil).should include(@red)
183
222
  end
184
223
 
185
224
  it 'should not include objects with a nil value' do
186
- Heffalump.all(:color.not => nil).should_not be_include(@two)
225
+ heffalump_model.all(:color.not => nil).should_not include(@two)
187
226
  end
188
227
 
189
228
  it 'should be able to search for object with a nil value using required properties' do
190
- Heffalump.all(:id.not => nil).should == [ @red, @two, @five ]
229
+ heffalump_model.all(:id.not => nil).should == [ @red, @two, @five ]
191
230
  end
192
231
 
193
232
  it 'should be able to search for objects not in an empty list (match all)' do
194
- Heffalump.all(:color.not => []).should == [ @red, @two, @five ]
233
+ heffalump_model.all(:color.not => []).should == [ @red, @two, @five ]
195
234
  end
196
235
 
197
236
  it 'should be able to search for objects in an empty list and another OR condition (match none on the empty list)' do
198
- Heffalump.all(
237
+ heffalump_model.all(
199
238
  :conditions => DataMapper::Query::Conditions::Operation.new(
200
239
  :or,
201
- DataMapper::Query::Conditions::Comparison.new(:in, Heffalump.properties[:color], []),
202
- DataMapper::Query::Conditions::Comparison.new(:in, Heffalump.properties[:num_spots], [5])
240
+ DataMapper::Query::Conditions::Comparison.new(:in, heffalump_model.properties[:color], []),
241
+ DataMapper::Query::Conditions::Comparison.new(:in, heffalump_model.properties[:num_spots], [5])
203
242
  )
204
243
  ).should == [ @five ]
205
244
  end
206
245
 
207
246
  it 'should be able to search for objects not included in an array of values' do
208
- Heffalump.all(:num_spots.not => [ 1, 3, 5, 7 ]).should be_include(@two)
247
+ heffalump_model.all(:num_spots.not => [ 1, 3, 5, 7 ]).should include(@two)
209
248
  end
210
249
 
211
250
  it 'should be able to search for objects not included in an array of values' do
212
- Heffalump.all(:num_spots.not => [ 1, 3, 5, 7 ]).should_not be_include(@five)
251
+ heffalump_model.all(:num_spots.not => [ 1, 3, 5, 7 ]).should_not include(@five)
213
252
  end
214
253
 
215
254
  it 'should be able to search for objects not included in an inclusive range of values' do
216
- Heffalump.all(:num_spots.not => 1..4).should be_include(@five)
255
+ heffalump_model.all(:num_spots.not => 1..4).should include(@five)
217
256
  end
218
257
 
219
258
  it 'should be able to search for objects not included in an exclusive range of values' do
220
- Heffalump.all(:num_spots.not => 1...5).should be_include(@five)
259
+ heffalump_model.all(:num_spots.not => 1...5).should include(@five)
221
260
  end
222
261
 
223
262
  it 'should not be able to search for values not included in an inclusive range of values' do
224
- Heffalump.all(:num_spots.not => 1..5).should_not be_include(@five)
263
+ heffalump_model.all(:num_spots.not => 1..5).should_not include(@five)
225
264
  end
226
265
 
227
266
  it 'should not be able to search for values not included in an exclusive range of values' do
228
- Heffalump.all(:num_spots.not => 1...6).should_not be_include(@five)
267
+ heffalump_model.all(:num_spots.not => 1...6).should_not include(@five)
229
268
  end
230
269
  end
231
270
 
232
271
  describe 'like' do
233
272
  it 'should be able to search for objects that match value' do
234
- Heffalump.all(:color.like => '%ed').should be_include(@red)
273
+ heffalump_model.all(:color.like => '%ed').should include(@red)
235
274
  end
236
275
 
237
276
  it 'should not search for objects that do not match the value' do
238
- Heffalump.all(:color.like => '%blak%').should_not be_include(@red)
277
+ heffalump_model.all(:color.like => '%blak%').should_not include(@red)
239
278
  end
240
279
  end
241
280
 
242
281
  describe 'regexp' do
243
282
  before do
244
- if (defined?(DataMapper::Adapters::SqliteAdapter) && @adapter.kind_of?(DataMapper::Adapters::SqliteAdapter) ||
245
- defined?(DataMapper::Adapters::SqlserverAdapter) && @adapter.kind_of?(DataMapper::Adapters::SqlserverAdapter))
283
+ if (defined?(DataMapper::Adapters::SqliteAdapter) && adapter.kind_of?(DataMapper::Adapters::SqliteAdapter) ||
284
+ defined?(DataMapper::Adapters::SqlserverAdapter) && adapter.kind_of?(DataMapper::Adapters::SqlserverAdapter))
246
285
  pending 'delegate regexp matches to same system that the InMemory and YAML adapters use'
247
286
  end
248
287
  end
249
288
 
250
289
  it 'should be able to search for objects that match value' do
251
- Heffalump.all(:color => /ed/).should be_include(@red)
290
+ heffalump_model.all(:color => /ed/).should include(@red)
252
291
  end
253
292
 
254
293
  it 'should not be able to search for objects that do not match the value' do
255
- Heffalump.all(:color => /blak/).should_not be_include(@red)
294
+ heffalump_model.all(:color => /blak/).should_not include(@red)
256
295
  end
257
296
 
258
297
  it 'should be able to do a negated search for objects that match value' do
259
- Heffalump.all(:color.not => /blak/).should be_include(@red)
298
+ heffalump_model.all(:color.not => /blak/).should include(@red)
260
299
  end
261
300
 
262
301
  it 'should not be able to do a negated search for objects that do not match value' do
263
- Heffalump.all(:color.not => /ed/).should_not be_include(@red)
302
+ heffalump_model.all(:color.not => /ed/).should_not include(@red)
264
303
  end
265
304
 
266
305
  end
267
306
 
268
307
  describe 'gt' do
269
308
  it 'should be able to search for objects with value greater than' do
270
- Heffalump.all(:num_spots.gt => 1).should be_include(@two)
309
+ heffalump_model.all(:num_spots.gt => 1).should include(@two)
271
310
  end
272
311
 
273
312
  it 'should not find objects with a value less than' do
274
- Heffalump.all(:num_spots.gt => 3).should_not be_include(@two)
313
+ heffalump_model.all(:num_spots.gt => 3).should_not include(@two)
275
314
  end
276
315
  end
277
316
 
278
317
  describe 'gte' do
279
318
  it 'should be able to search for objects with value greater than' do
280
- Heffalump.all(:num_spots.gte => 1).should be_include(@two)
319
+ heffalump_model.all(:num_spots.gte => 1).should include(@two)
281
320
  end
282
321
 
283
322
  it 'should be able to search for objects with values equal to' do
284
- Heffalump.all(:num_spots.gte => 2).should be_include(@two)
323
+ heffalump_model.all(:num_spots.gte => 2).should include(@two)
285
324
  end
286
325
 
287
326
  it 'should not find objects with a value less than' do
288
- Heffalump.all(:num_spots.gte => 3).should_not be_include(@two)
327
+ heffalump_model.all(:num_spots.gte => 3).should_not include(@two)
289
328
  end
290
329
  end
291
330
 
292
331
  describe 'lt' do
293
332
  it 'should be able to search for objects with value less than' do
294
- Heffalump.all(:num_spots.lt => 3).should be_include(@two)
333
+ heffalump_model.all(:num_spots.lt => 3).should include(@two)
295
334
  end
296
335
 
297
336
  it 'should not find objects with a value less than' do
298
- Heffalump.all(:num_spots.gt => 2).should_not be_include(@two)
337
+ heffalump_model.all(:num_spots.gt => 2).should_not include(@two)
299
338
  end
300
339
  end
301
340
 
302
341
  describe 'lte' do
303
342
  it 'should be able to search for objects with value less than' do
304
- Heffalump.all(:num_spots.lte => 3).should be_include(@two)
343
+ heffalump_model.all(:num_spots.lte => 3).should include(@two)
305
344
  end
306
345
 
307
346
  it 'should be able to search for objects with values equal to' do
308
- Heffalump.all(:num_spots.lte => 2).should be_include(@two)
347
+ heffalump_model.all(:num_spots.lte => 2).should include(@two)
309
348
  end
310
349
 
311
350
  it 'should not find objects with a value less than' do
312
- Heffalump.all(:num_spots.lte => 1).should_not be_include(@two)
351
+ heffalump_model.all(:num_spots.lte => 1).should_not include(@two)
313
352
  end
314
353
  end
315
354
  end
316
355
 
317
356
  describe 'limits' do
318
357
  it 'should be able to limit the objects' do
319
- Heffalump.all(:limit => 2).length.should == 2
358
+ heffalump_model.all(:limit => 2).length.should == 2
320
359
  end
321
360
  end
322
361
  end