sam-dm-core 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/Manifest.txt +5 -0
  2. data/QUICKLINKS +1 -2
  3. data/Rakefile +3 -3
  4. data/SPECS +9 -10
  5. data/lib/dm-core.rb +15 -22
  6. data/lib/dm-core/adapters.rb +18 -0
  7. data/lib/dm-core/adapters/abstract_adapter.rb +17 -10
  8. data/lib/dm-core/adapters/data_objects_adapter.rb +18 -16
  9. data/lib/dm-core/adapters/mysql_adapter.rb +1 -1
  10. data/lib/dm-core/adapters/postgres_adapter.rb +2 -2
  11. data/lib/dm-core/adapters/sqlite3_adapter.rb +1 -1
  12. data/lib/dm-core/associations.rb +3 -2
  13. data/lib/dm-core/associations/many_to_many.rb +2 -2
  14. data/lib/dm-core/associations/many_to_one.rb +1 -1
  15. data/lib/dm-core/associations/one_to_many.rb +13 -7
  16. data/lib/dm-core/associations/relationship.rb +20 -15
  17. data/lib/dm-core/auto_migrations.rb +4 -12
  18. data/lib/dm-core/collection.rb +9 -5
  19. data/lib/dm-core/dependency_queue.rb +2 -1
  20. data/lib/dm-core/identity_map.rb +3 -6
  21. data/lib/dm-core/model.rb +44 -27
  22. data/lib/dm-core/property.rb +3 -13
  23. data/lib/dm-core/property_set.rb +29 -22
  24. data/lib/dm-core/query.rb +49 -47
  25. data/lib/dm-core/repository.rb +3 -3
  26. data/lib/dm-core/resource.rb +12 -12
  27. data/lib/dm-core/scope.rb +7 -7
  28. data/lib/dm-core/support/kernel.rb +6 -2
  29. data/lib/dm-core/transaction.rb +7 -7
  30. data/lib/dm-core/version.rb +1 -1
  31. data/script/performance.rb +109 -30
  32. data/script/profile.rb +2 -2
  33. data/spec/integration/association_spec.rb +13 -1
  34. data/spec/integration/associations/one_to_many_spec.rb +40 -3
  35. data/spec/integration/auto_migrations_spec.rb +16 -1
  36. data/spec/integration/dependency_queue_spec.rb +0 -12
  37. data/spec/integration/postgres_adapter_spec.rb +1 -1
  38. data/spec/integration/property_spec.rb +4 -4
  39. data/spec/integration/resource_spec.rb +6 -0
  40. data/spec/integration/sti_spec.rb +22 -0
  41. data/spec/integration/strategic_eager_loading_spec.rb +21 -6
  42. data/spec/integration/type_spec.rb +1 -1
  43. data/spec/lib/model_loader.rb +10 -1
  44. data/spec/models/zoo.rb +1 -0
  45. data/spec/spec_helper.rb +3 -2
  46. data/spec/unit/adapters/data_objects_adapter_spec.rb +3 -3
  47. data/spec/unit/associations/many_to_many_spec.rb +16 -1
  48. data/spec/unit/associations/many_to_one_spec.rb +9 -2
  49. data/spec/unit/model_spec.rb +12 -30
  50. data/spec/unit/property_set_spec.rb +8 -1
  51. data/spec/unit/query_spec.rb +41 -0
  52. data/spec/unit/resource_spec.rb +27 -4
  53. data/spec/unit/transaction_spec.rb +13 -13
  54. data/tasks/ci.rb +4 -36
  55. data/tasks/dm.rb +3 -3
  56. metadata +7 -16
@@ -1,15 +1,18 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
2
 
3
3
  describe 'DataMapper::Model' do
4
- module ModelSpec
5
- class Resource
6
- include DataMapper::Resource
4
+ before do
5
+ Object.send(:remove_const, :ModelSpec) if defined?(ModelSpec)
6
+ module ModelSpec
7
+ class Resource
8
+ include DataMapper::Resource
7
9
 
8
- storage_names[:legacy] = 'legacy_resource'
10
+ storage_names[:legacy] = 'legacy_resource'
9
11
 
10
- property :id, Serial
11
- property :name, String
12
- property :type, Discriminator
12
+ property :id, Serial
13
+ property :name, String
14
+ property :type, Discriminator
15
+ end
13
16
  end
14
17
  end
15
18
 
@@ -87,7 +90,7 @@ describe 'DataMapper::Model' do
87
90
  describe '#storage_names' do
88
91
  it 'should return a Hash mapping each repository to a storage location' do
89
92
  ModelSpec::Resource.storage_names.should be_kind_of(Hash)
90
- ModelSpec::Resource.storage_names.should == { :default => 'model_spec_resources', :legacy => 'legacy_resource' }
93
+ ModelSpec::Resource.storage_names.should == { :legacy => 'legacy_resource' }
91
94
  end
92
95
  end
93
96
 
@@ -147,22 +150,6 @@ describe 'DataMapper::Model' do
147
150
  end
148
151
  end
149
152
 
150
- it 'should provide #inheritance_property' do
151
- ModelSpec::Resource.should respond_to(:inheritance_property)
152
- end
153
-
154
- describe '#inheritance_property' do
155
- it 'should return a Property object' do
156
- ModelSpec::Resource.inheritance_property(:legacy).should be_kind_of(DataMapper::Property)
157
- ModelSpec::Resource.inheritance_property(:legacy).name.should == :type
158
- ModelSpec::Resource.inheritance_property(:legacy).type.should == DM::Discriminator
159
- end
160
-
161
- it 'should use default repository when not passed any arguments' do
162
- ModelSpec::Resource.inheritance_property.object_id.should == ModelSpec::Resource.inheritance_property(:default).object_id
163
- end
164
- end
165
-
166
153
  it 'should provide #get' do
167
154
  ModelSpec::Resource.should respond_to(:get)
168
155
  end
@@ -181,12 +168,7 @@ describe 'DataMapper::Model' do
181
168
 
182
169
  describe '#storage_exists?' do
183
170
  it 'should return whether or not the storage exists' do
184
- ModelSpec::Resource.should_receive(:repository).with(:default) do
185
- repository = mock('repository')
186
- repository.should_receive(:storage_exists?).with('model_spec_resources').and_return(true)
187
- repository
188
- end
189
- ModelSpec::Resource.storage_exists?.should == true
171
+ ModelSpec::Resource.storage_exists?.should == false
190
172
  end
191
173
  end
192
174
 
@@ -24,7 +24,7 @@ end
24
24
 
25
25
  describe DataMapper::PropertySet do
26
26
  before :each do
27
- @properties = Icon.properties(:default)
27
+ @properties = Icon.properties(:default).dup
28
28
  end
29
29
 
30
30
  it "#slice should find properties" do
@@ -35,6 +35,13 @@ describe DataMapper::PropertySet do
35
35
  @properties.select { |property| property.primitive == Integer }.should have(3).entries
36
36
  end
37
37
 
38
+ it "#clear should clear out set" do
39
+ @properties.clear
40
+ @properties.key.should == []
41
+ @properties.defaults.should == []
42
+ @properties.length.should == 0
43
+ end
44
+
38
45
  it "#[] should find properties by name (Symbol or String)" do
39
46
  default_properties = [ :id, 'name', :width, 'height' ]
40
47
  @properties.each_with_index do |property,i|
@@ -482,6 +482,47 @@ describe DataMapper::Query do
482
482
  @query.reverse!.object_id.should == @query.object_id
483
483
  end
484
484
  end
485
+
486
+ describe 'inheritance properties' do
487
+ before(:each) do
488
+ class Parent
489
+ include DataMapper::Resource
490
+ property :id, Serial
491
+ property :type, Discriminator
492
+ end
493
+ @query = DataMapper::Query.new(@repository, Parent)
494
+ @other_query = DataMapper::Query.new(@repository, Article)
495
+ end
496
+
497
+ it 'should provide #inheritance_property' do
498
+ @query.should respond_to(:inheritance_property)
499
+ end
500
+
501
+ describe '#inheritance_property' do
502
+ it 'should return a Property object if there is a Discriminator field' do
503
+ @query.inheritance_property.should be_kind_of(DataMapper::Property)
504
+ @query.inheritance_property.name.should == :type
505
+ @query.inheritance_property.type.should == DM::Discriminator
506
+ end
507
+
508
+ it 'should return nil if there is no Discriminator field' do
509
+ @other_query.inheritance_property.should be_nil
510
+ end
511
+ end
512
+
513
+ it 'should provide #inheritance_property_index' do
514
+ @query.should respond_to(:inheritance_property_index)
515
+ end
516
+
517
+ describe '#inheritance_property_index' do
518
+ it 'should return integer index if there is a Discriminator field' do
519
+ @query.inheritance_property_index.should be_kind_of(Integer)
520
+ @query.inheritance_property_index.should == 1
521
+ end
522
+
523
+ it 'should return nil if there is no Discriminator field'
524
+ end
525
+ end
485
526
  end
486
527
 
487
528
  describe DataMapper::Query::Operator do
@@ -11,7 +11,7 @@ describe DataMapper::Resource do
11
11
  zoo.description = "This is a pretty awesome zoo"
12
12
  zoo.attributes.should == {
13
13
  :name => "San Francisco", :description => "This is a pretty awesome zoo",
14
- :id => nil, :inception => nil, :open => false, :size => nil
14
+ :id => nil, :inception => nil, :open => false, :size => nil, :mission => nil
15
15
  }
16
16
  end
17
17
 
@@ -24,6 +24,20 @@ describe DataMapper::Resource do
24
24
  end
25
25
  end
26
26
 
27
+ describe "#attributes=" do
28
+ before(:each) do
29
+ @zoo = Zoo.new(:name => "San Francisco", :size => 10)
30
+ @zoo.attributes = {:size => 12 }
31
+ end
32
+ it "should change a public property" do
33
+ @zoo.size.should == 12
34
+ end
35
+ it "should raise when attempting to change a property with a non-public writer" do
36
+ lambda { @zoo.attributes = {:mission => "Just keep some odd
37
+ critters, y'know?" } }.should raise_error
38
+ end
39
+ end
40
+
27
41
  # ---------- REPOSITORY WRITE METHODS ---------------
28
42
 
29
43
  describe '#save' do
@@ -115,6 +129,7 @@ describe DataMapper::Resource do
115
129
  property :victories, Integer
116
130
  end
117
131
 
132
+ Fruit.auto_migrate!
118
133
  Planet.auto_migrate!
119
134
  Cyclist.auto_migrate!
120
135
  end
@@ -173,11 +188,19 @@ describe DataMapper::Resource do
173
188
  resource.should be_new_record
174
189
  resource.model.key.any? { |p| p.serial? }.should be_false
175
190
 
176
- @adapter.should_not_receive(:create)
177
-
178
191
  resource.save.should be_false
179
192
  end
180
193
 
194
+ it 'should return true even if the object is not dirty' do
195
+ resource = Cyclist.new
196
+ resource.victories = "0 victories"
197
+ resource.save.should be_true
198
+
199
+ resource.should_not be_dirty
200
+ resource.should_not be_new_record
201
+ resource.save.should be_true
202
+ end
203
+
181
204
  describe 'for integer fields' do
182
205
 
183
206
  it "should save strings without digits as nil" do
@@ -339,7 +362,7 @@ describe DataMapper::Resource do
339
362
  it "should not be able to set private attributes" do
340
363
  lambda {
341
364
  jupiter = Planet.new({ :core => "Molten Metal" })
342
- }.should raise_error(NameError)
365
+ }.should raise_error(ArgumentError)
343
366
  end
344
367
 
345
368
  it "should not mark attributes dirty if they are similar after update" do
@@ -240,9 +240,9 @@ describe DataMapper::Transaction do
240
240
  @transaction_primitive.should_receive(:begin)
241
241
  @transaction_primitive.should_receive(:rollback)
242
242
  @transaction_primitive.should_receive(:close)
243
- p = Proc.new do raise "test exception, never mind me" end
244
- @transaction.should_receive(:within).with(&p)
245
- lambda do @transaction.commit(&p) end.should raise_error(Exception, /test exception, never mind me/)
243
+ p = Proc.new do end
244
+ @transaction.should_receive(:within).with(&p).and_raise(Exception.new('test exception, never mind me'))
245
+ lambda { @transaction.commit(&p) }.should raise_error(Exception, /test exception, never mind me/)
246
246
  end
247
247
  end
248
248
  end
@@ -280,8 +280,8 @@ describe DataMapper::Transaction do
280
280
  describe "#method_missing" do
281
281
  before :each do
282
282
  @transaction = DataMapper::Transaction.new(@adapter, @repository)
283
- @adapter.should_receive(:is_a?).any_number_of_times.with(Spec::Mocks::AnyArgsConstraint).and_return(false)
284
- @adapter.should_receive(:is_a?).any_number_of_times.with(Spec::Mocks::NoArgsConstraint).and_return(false)
283
+ @adapter.should_receive(:is_a?).any_number_of_times.with(any_args).and_return(false)
284
+ @adapter.should_receive(:is_a?).any_number_of_times.with(no_args).and_return(false)
285
285
  @adapter.should_receive(:is_a?).any_number_of_times.with(Regexp).and_return(false)
286
286
  end
287
287
  it "should delegate calls to [a method we have]_if_[state](adapter) to [a method we have](adapter) if state of adapter is [state]" do
@@ -326,11 +326,11 @@ describe DataMapper::Transaction do
326
326
  describe "#each_adapter" do
327
327
  before :each do
328
328
  @transaction = DataMapper::Transaction.new(@adapter, @repository)
329
- @adapter.should_receive(:is_a?).any_number_of_times.with(Spec::Mocks::AnyArgsConstraint).and_return(false)
330
- @adapter.should_receive(:is_a?).any_number_of_times.with(Spec::Mocks::NoArgsConstraint).and_return(false)
329
+ @adapter.should_receive(:is_a?).any_number_of_times.with(any_args).and_return(false)
330
+ @adapter.should_receive(:is_a?).any_number_of_times.with(no_args).and_return(false)
331
331
  @adapter.should_receive(:is_a?).any_number_of_times.with(Regexp).and_return(false)
332
- @repository_adapter.should_receive(:is_a?).any_number_of_times.with(Spec::Mocks::AnyArgsConstraint).and_return(false)
333
- @repository_adapter.should_receive(:is_a?).any_number_of_times.with(Spec::Mocks::NoArgsConstraint).and_return(false)
332
+ @repository_adapter.should_receive(:is_a?).any_number_of_times.with(any_args).and_return(false)
333
+ @repository_adapter.should_receive(:is_a?).any_number_of_times.with(no_args).and_return(false)
334
334
  @repository_adapter.should_receive(:is_a?).any_number_of_times.with(Regexp).and_return(false)
335
335
  end
336
336
  it "should send the first argument to itself once for each adapter" do
@@ -386,8 +386,8 @@ describe DataMapper::Transaction do
386
386
  describe "#do_adapter" do
387
387
  before :each do
388
388
  @transaction = DataMapper::Transaction.new(@adapter, @repository)
389
- @adapter.should_receive(:is_a?).any_number_of_times.with(Spec::Mocks::AnyArgsConstraint).and_return(false)
390
- @adapter.should_receive(:is_a?).any_number_of_times.with(Spec::Mocks::NoArgsConstraint).and_return(false)
389
+ @adapter.should_receive(:is_a?).any_number_of_times.with(any_args).and_return(false)
390
+ @adapter.should_receive(:is_a?).any_number_of_times.with(no_args).and_return(false)
391
391
  @adapter.should_receive(:is_a?).any_number_of_times.with(Regexp).and_return(false)
392
392
  end
393
393
  it "should raise if there is no connection for the adapter" do
@@ -447,8 +447,8 @@ describe DataMapper::Transaction do
447
447
  @other_adapter = mock("adapter")
448
448
  @other_adapter.should_receive(:is_a?).any_number_of_times.with(Array).and_return(false)
449
449
  @other_adapter.should_receive(:is_a?).any_number_of_times.with(DataMapper::Adapters::AbstractAdapter).and_return(true)
450
- @other_adapter.should_receive(:is_a?).any_number_of_times.with(Spec::Mocks::AnyArgsConstraint).and_return(false)
451
- @other_adapter.should_receive(:is_a?).any_number_of_times.with(Spec::Mocks::NoArgsConstraint).and_return(false)
450
+ @other_adapter.should_receive(:is_a?).any_number_of_times.with(any_args).and_return(false)
451
+ @other_adapter.should_receive(:is_a?).any_number_of_times.with(no_args).and_return(false)
452
452
  @other_adapter.should_receive(:is_a?).any_number_of_times.with(Regexp).and_return(false)
453
453
  @transaction = DataMapper::Transaction.new(@other_adapter)
454
454
  end
data/tasks/ci.rb CHANGED
@@ -10,9 +10,9 @@ namespace :ci do
10
10
  mkdir_p ROOT + "ci/token"
11
11
  end
12
12
 
13
- Spec::Rake::SpecTask.new("spec:unit" => :prepare) do |t|
14
- t.spec_opts = ["--format", "specdoc", "--format", "html:#{ROOT}/ci/unit_rspec_report.html", "--diff"]
15
- t.spec_files = Pathname.glob(ROOT + "spec/unit/**/*_spec.rb")
13
+ Spec::Rake::SpecTask.new(:spec => :prepare) do |t|
14
+ t.spec_opts = ["--colour", "--format", "specdoc", "--format", "html:#{ROOT}/ci/rspec_report.html", "--diff"]
15
+ t.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s)
16
16
  unless ENV['NO_RCOV']
17
17
  t.rcov = true
18
18
  t.rcov_opts << '--exclude' << "spec,gems"
@@ -22,26 +22,6 @@ namespace :ci do
22
22
  end
23
23
  end
24
24
 
25
- Spec::Rake::SpecTask.new("spec:integration" => :prepare) do |t|
26
- t.spec_opts = ["--format", "specdoc", "--format", "html:#{ROOT}/ci/integration_rspec_report.html", "--diff"]
27
- t.spec_files = Pathname.glob(ROOT + "spec/integration/**/*_spec.rb")
28
- unless ENV['NO_RCOV']
29
- t.rcov = true
30
- t.rcov_opts << '--exclude' << "spec,gems"
31
- t.rcov_opts << '--text-summary'
32
- t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
33
- t.rcov_opts << '--only-uncovered'
34
- end
35
- end
36
-
37
- task :spec do
38
- Rake::Task["ci:spec:unit"].invoke
39
- mv ROOT + "coverage", ROOT + "ci/unit_coverage"
40
-
41
- Rake::Task["ci:spec:integration"].invoke
42
- mv ROOT + "coverage", ROOT + "ci/integration_coverage"
43
- end
44
-
45
25
  task :saikuro => :prepare do
46
26
  system "saikuro -c -i lib -y 0 -w 10 -e 15 -o ci/cyclomatic"
47
27
  mv 'ci/cyclomatic/index_cyclo.html', 'ci/cyclomatic/index.html'
@@ -50,19 +30,7 @@ namespace :ci do
50
30
  mv 'ci/token/index_token.html', 'ci/token/index.html'
51
31
  end
52
32
 
53
- task :publish do
54
- out = ENV['CC_BUILD_ARTIFACTS'] || "out"
55
- mkdir_p out unless File.directory? out
56
-
57
- mv "ci/unit_rspec_report.html", "#{out}/unit_rspec_report.html"
58
- mv "ci/unit_coverage", "#{out}/unit_coverage"
59
- mv "ci/integration_rspec_report.html", "#{out}/integration_rspec_report.html"
60
- mv "ci/integration_coverage", "#{out}/integration_coverage"
61
- mv "ci/doc", "#{out}/doc"
62
- mv "ci/cyclomatic", "#{out}/cyclomatic_complexity"
63
- mv "ci/token", "#{out}/token_complexity"
64
- end
65
33
  end
66
34
 
67
35
  #task :ci => %w[ ci:spec ci:doc ci:saikuro install ci:publish ] # yard-related tasks do not work yet
68
- task :ci => %w[ ci:spec ci:saikuro install ]
36
+ task :ci => %w[ ci:spec ]
data/tasks/dm.rb CHANGED
@@ -16,7 +16,7 @@ namespace :dm do
16
16
  def run_spec(name, files, rcov)
17
17
  Spec::Rake::SpecTask.new(name) do |t|
18
18
  t.spec_opts << '--colour' << '--loadby' << 'random'
19
- t.spec_files = Pathname.glob(ENV['FILES'] || files)
19
+ t.spec_files = Pathname.glob(ENV['FILES'] || files.to_s)
20
20
  t.rcov = rcov
21
21
  t.rcov_opts << '--exclude' << 'spec,environment.rb'
22
22
  t.rcov_opts << '--text-summary'
@@ -25,9 +25,9 @@ namespace :dm do
25
25
  end
26
26
  end
27
27
 
28
- unit_specs = ROOT + 'spec/unit/**/*_spec.rb'
28
+ unit_specs = ROOT + 'spec/unit/**/*_spec.rb'
29
29
  integration_specs = ROOT + 'spec/integration/**/*_spec.rb'
30
- all_specs = ROOT + 'spec/**/*_spec.rb'
30
+ all_specs = ROOT + 'spec/**/*_spec.rb'
31
31
 
32
32
  desc "Run all specifications"
33
33
  run_spec('spec', all_specs, false)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sam-dm-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Smoot
@@ -17,36 +17,27 @@ dependencies:
17
17
  version_requirement:
18
18
  version_requirements: !ruby/object:Gem::Requirement
19
19
  requirements:
20
- - - ">="
20
+ - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: 0.9.5
22
+ version: 0.9.9
23
23
  version:
24
24
  - !ruby/object:Gem::Dependency
25
25
  name: extlib
26
26
  version_requirement:
27
27
  version_requirements: !ruby/object:Gem::Requirement
28
28
  requirements:
29
- - - ">="
29
+ - - ~>
30
30
  - !ruby/object:Gem::Version
31
- version: 0.9.5
32
- version:
33
- - !ruby/object:Gem::Dependency
34
- name: rspec
35
- version_requirement:
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: 1.1.3
31
+ version: 0.9.9
41
32
  version:
42
33
  - !ruby/object:Gem::Dependency
43
34
  name: addressable
44
35
  version_requirement:
45
36
  version_requirements: !ruby/object:Gem::Requirement
46
37
  requirements:
47
- - - ">="
38
+ - - ~>
48
39
  - !ruby/object:Gem::Version
49
- version: 1.0.4
40
+ version: 2.0.1
50
41
  version:
51
42
  description: Faster, Better, Simpler!
52
43
  email: