dm-core 0.9.11 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +17 -14
- data/.gitignore +3 -1
- data/FAQ +6 -5
- data/History.txt +5 -50
- data/Manifest.txt +66 -76
- data/QUICKLINKS +1 -1
- data/README.txt +21 -15
- data/Rakefile +6 -7
- data/SPECS +2 -29
- data/TODO +1 -1
- data/deps.rip +2 -0
- data/dm-core.gemspec +11 -15
- data/lib/dm-core.rb +105 -110
- data/lib/dm-core/adapters.rb +135 -16
- data/lib/dm-core/adapters/abstract_adapter.rb +251 -181
- data/lib/dm-core/adapters/data_objects_adapter.rb +482 -534
- data/lib/dm-core/adapters/in_memory_adapter.rb +90 -69
- data/lib/dm-core/adapters/mysql_adapter.rb +22 -115
- data/lib/dm-core/adapters/oracle_adapter.rb +249 -0
- data/lib/dm-core/adapters/postgres_adapter.rb +7 -173
- data/lib/dm-core/adapters/sqlite3_adapter.rb +4 -97
- data/lib/dm-core/adapters/yaml_adapter.rb +116 -0
- data/lib/dm-core/associations/many_to_many.rb +372 -90
- data/lib/dm-core/associations/many_to_one.rb +220 -73
- data/lib/dm-core/associations/one_to_many.rb +319 -255
- data/lib/dm-core/associations/one_to_one.rb +66 -53
- data/lib/dm-core/associations/relationship.rb +561 -156
- data/lib/dm-core/collection.rb +1101 -379
- data/lib/dm-core/core_ext/kernel.rb +12 -0
- data/lib/dm-core/core_ext/symbol.rb +10 -0
- data/lib/dm-core/identity_map.rb +4 -34
- data/lib/dm-core/migrations.rb +1283 -0
- data/lib/dm-core/model.rb +570 -369
- data/lib/dm-core/model/descendant_set.rb +81 -0
- data/lib/dm-core/model/hook.rb +45 -0
- data/lib/dm-core/model/is.rb +32 -0
- data/lib/dm-core/model/property.rb +247 -0
- data/lib/dm-core/model/relationship.rb +335 -0
- data/lib/dm-core/model/scope.rb +90 -0
- data/lib/dm-core/property.rb +808 -273
- data/lib/dm-core/property_set.rb +141 -98
- data/lib/dm-core/query.rb +1037 -483
- data/lib/dm-core/query/conditions/comparison.rb +872 -0
- data/lib/dm-core/query/conditions/operation.rb +221 -0
- data/lib/dm-core/query/direction.rb +43 -0
- data/lib/dm-core/query/operator.rb +84 -0
- data/lib/dm-core/query/path.rb +138 -0
- data/lib/dm-core/query/sort.rb +45 -0
- data/lib/dm-core/repository.rb +210 -94
- data/lib/dm-core/resource.rb +641 -421
- data/lib/dm-core/spec/adapter_shared_spec.rb +294 -0
- data/lib/dm-core/spec/data_objects_adapter_shared_spec.rb +106 -0
- data/lib/dm-core/support/chainable.rb +22 -0
- data/lib/dm-core/support/deprecate.rb +12 -0
- data/lib/dm-core/support/logger.rb +13 -0
- data/lib/dm-core/{naming_conventions.rb → support/naming_conventions.rb} +6 -6
- data/lib/dm-core/transaction.rb +333 -92
- data/lib/dm-core/type.rb +98 -60
- data/lib/dm-core/types/boolean.rb +1 -1
- data/lib/dm-core/types/discriminator.rb +34 -20
- data/lib/dm-core/types/object.rb +7 -4
- data/lib/dm-core/types/paranoid_boolean.rb +11 -9
- data/lib/dm-core/types/paranoid_datetime.rb +11 -9
- data/lib/dm-core/types/serial.rb +3 -3
- data/lib/dm-core/types/text.rb +3 -4
- data/lib/dm-core/version.rb +1 -1
- data/script/performance.rb +102 -109
- data/script/profile.rb +169 -38
- data/spec/lib/adapter_helpers.rb +105 -0
- data/spec/lib/collection_helpers.rb +18 -0
- data/spec/lib/counter_adapter.rb +34 -0
- data/spec/lib/pending_helpers.rb +27 -0
- data/spec/lib/rspec_immediate_feedback_formatter.rb +53 -0
- data/spec/public/associations/many_to_many_spec.rb +193 -0
- data/spec/public/associations/many_to_one_spec.rb +73 -0
- data/spec/public/associations/one_to_many_spec.rb +77 -0
- data/spec/public/associations/one_to_one_spec.rb +156 -0
- data/spec/public/collection_spec.rb +65 -0
- data/spec/public/migrations_spec.rb +359 -0
- data/spec/public/model/relationship_spec.rb +924 -0
- data/spec/public/model_spec.rb +159 -0
- data/spec/public/property_spec.rb +829 -0
- data/spec/public/resource_spec.rb +71 -0
- data/spec/public/sel_spec.rb +44 -0
- data/spec/public/setup_spec.rb +145 -0
- data/spec/public/shared/association_collection_shared_spec.rb +317 -0
- data/spec/public/shared/collection_shared_spec.rb +1670 -0
- data/spec/public/shared/finder_shared_spec.rb +1619 -0
- data/spec/public/shared/resource_shared_spec.rb +924 -0
- data/spec/public/shared/sel_shared_spec.rb +112 -0
- data/spec/public/transaction_spec.rb +129 -0
- data/spec/public/types/discriminator_spec.rb +130 -0
- data/spec/semipublic/adapters/abstract_adapter_spec.rb +30 -0
- data/spec/semipublic/adapters/in_memory_adapter_spec.rb +12 -0
- data/spec/semipublic/adapters/mysql_adapter_spec.rb +17 -0
- data/spec/semipublic/adapters/oracle_adapter_spec.rb +194 -0
- data/spec/semipublic/adapters/postgres_adapter_spec.rb +17 -0
- data/spec/semipublic/adapters/sqlite3_adapter_spec.rb +17 -0
- data/spec/semipublic/adapters/yaml_adapter_spec.rb +12 -0
- data/spec/semipublic/associations/many_to_one_spec.rb +53 -0
- data/spec/semipublic/associations/relationship_spec.rb +194 -0
- data/spec/semipublic/associations_spec.rb +177 -0
- data/spec/semipublic/collection_spec.rb +142 -0
- data/spec/semipublic/property_spec.rb +61 -0
- data/spec/semipublic/query/conditions_spec.rb +528 -0
- data/spec/semipublic/query/path_spec.rb +443 -0
- data/spec/semipublic/query_spec.rb +2626 -0
- data/spec/semipublic/resource_spec.rb +47 -0
- data/spec/semipublic/shared/condition_shared_spec.rb +9 -0
- data/spec/semipublic/shared/resource_shared_spec.rb +126 -0
- data/spec/spec.opts +3 -1
- data/spec/spec_helper.rb +80 -57
- data/tasks/ci.rb +19 -31
- data/tasks/dm.rb +43 -48
- data/tasks/doc.rb +8 -11
- data/tasks/gemspec.rb +5 -5
- data/tasks/hoe.rb +15 -16
- data/tasks/install.rb +8 -10
- metadata +74 -111
- data/lib/dm-core/associations.rb +0 -207
- data/lib/dm-core/associations/relationship_chain.rb +0 -81
- data/lib/dm-core/auto_migrations.rb +0 -105
- data/lib/dm-core/dependency_queue.rb +0 -32
- data/lib/dm-core/hook.rb +0 -11
- data/lib/dm-core/is.rb +0 -16
- data/lib/dm-core/logger.rb +0 -232
- data/lib/dm-core/migrations/destructive_migrations.rb +0 -17
- data/lib/dm-core/migrator.rb +0 -29
- data/lib/dm-core/scope.rb +0 -58
- data/lib/dm-core/support.rb +0 -7
- data/lib/dm-core/support/array.rb +0 -13
- data/lib/dm-core/support/assertions.rb +0 -8
- data/lib/dm-core/support/errors.rb +0 -23
- data/lib/dm-core/support/kernel.rb +0 -11
- data/lib/dm-core/support/symbol.rb +0 -41
- data/lib/dm-core/type_map.rb +0 -80
- data/lib/dm-core/types.rb +0 -19
- data/script/all +0 -4
- data/spec/integration/association_spec.rb +0 -1382
- data/spec/integration/association_through_spec.rb +0 -203
- data/spec/integration/associations/many_to_many_spec.rb +0 -449
- data/spec/integration/associations/many_to_one_spec.rb +0 -163
- data/spec/integration/associations/one_to_many_spec.rb +0 -188
- data/spec/integration/auto_migrations_spec.rb +0 -413
- data/spec/integration/collection_spec.rb +0 -1073
- data/spec/integration/data_objects_adapter_spec.rb +0 -32
- data/spec/integration/dependency_queue_spec.rb +0 -46
- data/spec/integration/model_spec.rb +0 -197
- data/spec/integration/mysql_adapter_spec.rb +0 -85
- data/spec/integration/postgres_adapter_spec.rb +0 -731
- data/spec/integration/property_spec.rb +0 -253
- data/spec/integration/query_spec.rb +0 -514
- data/spec/integration/repository_spec.rb +0 -61
- data/spec/integration/resource_spec.rb +0 -513
- data/spec/integration/sqlite3_adapter_spec.rb +0 -352
- data/spec/integration/sti_spec.rb +0 -273
- data/spec/integration/strategic_eager_loading_spec.rb +0 -156
- data/spec/integration/transaction_spec.rb +0 -75
- data/spec/integration/type_spec.rb +0 -275
- data/spec/lib/logging_helper.rb +0 -18
- data/spec/lib/mock_adapter.rb +0 -27
- data/spec/lib/model_loader.rb +0 -100
- data/spec/lib/publicize_methods.rb +0 -28
- data/spec/models/content.rb +0 -16
- data/spec/models/vehicles.rb +0 -34
- data/spec/models/zoo.rb +0 -48
- data/spec/unit/adapters/abstract_adapter_spec.rb +0 -133
- data/spec/unit/adapters/adapter_shared_spec.rb +0 -15
- data/spec/unit/adapters/data_objects_adapter_spec.rb +0 -632
- data/spec/unit/adapters/in_memory_adapter_spec.rb +0 -98
- data/spec/unit/adapters/postgres_adapter_spec.rb +0 -133
- data/spec/unit/associations/many_to_many_spec.rb +0 -32
- data/spec/unit/associations/many_to_one_spec.rb +0 -159
- data/spec/unit/associations/one_to_many_spec.rb +0 -393
- data/spec/unit/associations/one_to_one_spec.rb +0 -7
- data/spec/unit/associations/relationship_spec.rb +0 -71
- data/spec/unit/associations_spec.rb +0 -242
- data/spec/unit/auto_migrations_spec.rb +0 -111
- data/spec/unit/collection_spec.rb +0 -182
- data/spec/unit/data_mapper_spec.rb +0 -35
- data/spec/unit/identity_map_spec.rb +0 -126
- data/spec/unit/is_spec.rb +0 -80
- data/spec/unit/migrator_spec.rb +0 -33
- data/spec/unit/model_spec.rb +0 -321
- data/spec/unit/naming_conventions_spec.rb +0 -36
- data/spec/unit/property_set_spec.rb +0 -90
- data/spec/unit/property_spec.rb +0 -753
- data/spec/unit/query_spec.rb +0 -571
- data/spec/unit/repository_spec.rb +0 -93
- data/spec/unit/resource_spec.rb +0 -649
- data/spec/unit/scope_spec.rb +0 -142
- data/spec/unit/transaction_spec.rb +0 -493
- data/spec/unit/type_map_spec.rb +0 -114
- data/spec/unit/type_spec.rb +0 -119
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe DataMapper::Resource do
|
4
|
+
before :all do
|
5
|
+
class ::User
|
6
|
+
include DataMapper::Resource
|
7
|
+
|
8
|
+
property :name, String, :key => true
|
9
|
+
property :age, Integer
|
10
|
+
property :description, Text
|
11
|
+
end
|
12
|
+
|
13
|
+
# This is a special class that needs to be an exact copy of User
|
14
|
+
class ::Clone
|
15
|
+
include DataMapper::Resource
|
16
|
+
|
17
|
+
property :name, String, :key => true
|
18
|
+
property :age, Integer
|
19
|
+
property :description, Text
|
20
|
+
end
|
21
|
+
|
22
|
+
class ::Comment
|
23
|
+
include DataMapper::Resource
|
24
|
+
|
25
|
+
property :id, Serial
|
26
|
+
property :body, Text
|
27
|
+
|
28
|
+
belongs_to :user
|
29
|
+
end
|
30
|
+
|
31
|
+
class ::Default
|
32
|
+
include DataMapper::Resource
|
33
|
+
|
34
|
+
property :name, String, :key => true, :default => 'a default value'
|
35
|
+
end
|
36
|
+
|
37
|
+
@user_model = User
|
38
|
+
end
|
39
|
+
|
40
|
+
supported_by :all do
|
41
|
+
before :all do
|
42
|
+
@user = @user_model.create(:name => 'dbussink', :age => 25, :description => "Test")
|
43
|
+
end
|
44
|
+
|
45
|
+
it_should_behave_like 'A semipublic Resource'
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
share_examples_for 'A semipublic Resource' do
|
2
|
+
before :all do
|
3
|
+
%w[ @user_model @user ].each do |ivar|
|
4
|
+
raise "+#{ivar}+ should be defined in before block" unless instance_variable_get(ivar)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
it { @user.should respond_to(:dirty?) }
|
9
|
+
|
10
|
+
describe '#dirty?' do
|
11
|
+
|
12
|
+
describe 'on a non-dirty record' do
|
13
|
+
|
14
|
+
it { @user.should_not be_dirty }
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'on a dirty record' do
|
19
|
+
|
20
|
+
before { @user.age = 100 }
|
21
|
+
|
22
|
+
it { @user.should be_dirty }
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'on a new record, with no attributes, no default attributes, and no identity field' do
|
27
|
+
|
28
|
+
before { @user = @user_model.new }
|
29
|
+
|
30
|
+
it { @user.should_not be_dirty }
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'on a new record, with no attributes, no default attributes, and an identity field' do
|
35
|
+
|
36
|
+
before { @comment = Comment.new }
|
37
|
+
|
38
|
+
it { @comment.should be_dirty }
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'on a new record, with no attributes, default attributes, and no identity field' do
|
43
|
+
|
44
|
+
before { @default = Default.new }
|
45
|
+
|
46
|
+
it { @default.should be_dirty }
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
it { @user.should respond_to(:attribute_dirty?) }
|
54
|
+
|
55
|
+
describe '#attribute_dirty?' do
|
56
|
+
|
57
|
+
describe 'on a non-dirty record' do
|
58
|
+
|
59
|
+
it { @user.attribute_dirty?(:age).should be_false }
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'on a dirty record' do
|
64
|
+
|
65
|
+
before { @user.age = 100 }
|
66
|
+
|
67
|
+
it { @user.attribute_dirty?(:age).should be_true }
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'on a new record' do
|
72
|
+
|
73
|
+
before { @user = @user_model.new }
|
74
|
+
|
75
|
+
it { @user.attribute_dirty?(:age).should be_false }
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
it { @user.should respond_to(:repository) }
|
82
|
+
|
83
|
+
describe "#repository" do
|
84
|
+
|
85
|
+
before :all do
|
86
|
+
class ::Statistic
|
87
|
+
include DataMapper::Resource
|
88
|
+
|
89
|
+
def self.default_repository_name
|
90
|
+
:alternate
|
91
|
+
end
|
92
|
+
|
93
|
+
property :id, Serial
|
94
|
+
property :name, String
|
95
|
+
property :value, Integer
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
with_alternate_adapter do
|
100
|
+
it "should return the default adapter when nothing is specified" do
|
101
|
+
@user_model.create(:name => "carl").repository.should == @repository
|
102
|
+
@user_model.new.repository.should == @repository
|
103
|
+
@user_model.get("carl").repository.should == @repository
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should return the default repository for the model" do
|
107
|
+
statistic = Statistic.create(:name => "visits", :value => 2)
|
108
|
+
statistic.repository.should == @alternate_repository
|
109
|
+
Statistic.new.repository.should == @alternate_repository
|
110
|
+
Statistic.get(statistic.id).repository.should == @alternate_repository
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should return the repository defined by the current context" do
|
114
|
+
@alternate_repository.scope do
|
115
|
+
@user_model.new.repository.should == @alternate_repository
|
116
|
+
@user_model.create(:name => "carl").repository.should == @alternate_repository
|
117
|
+
@user_model.get("carl").repository.should == @alternate_repository
|
118
|
+
end
|
119
|
+
|
120
|
+
@alternate_repository.scope { @user_model.get("carl") }.repository.should == @alternate_repository
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
data/spec/spec.opts
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,23 +1,52 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
require 'rubygems'
|
3
3
|
|
4
|
-
gem '
|
4
|
+
gem 'addressable', '~>2.0'
|
5
|
+
gem 'rspec', '>1.1.2'
|
6
|
+
|
7
|
+
require 'addressable/uri'
|
5
8
|
require 'spec'
|
6
9
|
|
7
10
|
SPEC_ROOT = Pathname(__FILE__).dirname.expand_path
|
8
|
-
|
11
|
+
$LOAD_PATH.unshift(SPEC_ROOT.parent + 'lib')
|
12
|
+
|
13
|
+
require 'dm-core'
|
9
14
|
|
10
|
-
|
11
|
-
|
12
|
-
require file
|
15
|
+
ENV['PLUGINS'].to_s.strip.split(/\s+/).each do |plugin|
|
16
|
+
require plugin
|
13
17
|
end
|
14
18
|
|
15
|
-
|
16
|
-
DataMapper.setup(:default2, "sqlite3::memory:")
|
19
|
+
Pathname.glob((SPEC_ROOT + '{lib,*/shared}/**/*.rb').to_s).each { |file| require file }
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
+
# create sqlite3_fs directory if it doesn't exist
|
22
|
+
temp_db_dir = SPEC_ROOT.join('db')
|
23
|
+
temp_db_dir.mkpath
|
24
|
+
|
25
|
+
ENV['ADAPTERS'] ||= 'all'
|
26
|
+
|
27
|
+
HAS_DO = DataMapper::Adapters.const_defined?('DataObjectsAdapter')
|
28
|
+
|
29
|
+
ADAPTERS = []
|
30
|
+
|
31
|
+
PRIMARY = {
|
32
|
+
'in_memory' => { :adapter => :in_memory },
|
33
|
+
'yaml' => "yaml://#{temp_db_dir}/primary_yaml",
|
34
|
+
'sqlite3' => 'sqlite3::memory:',
|
35
|
+
# 'sqlite3_fs' => "sqlite3://#{temp_db_dir}/primary.db",
|
36
|
+
'mysql' => 'mysql://localhost/dm_core_test',
|
37
|
+
'postgres' => 'postgres://localhost/dm_core_test',
|
38
|
+
'oracle' => 'oracle://dm_core_test:dm_core_test@localhost/orcl'
|
39
|
+
}
|
40
|
+
|
41
|
+
ALTERNATE = {
|
42
|
+
'in_memory' => { :adapter => :in_memory },
|
43
|
+
'yaml' => "yaml://#{temp_db_dir}/secondary_yaml",
|
44
|
+
'sqlite3' => "sqlite3://#{temp_db_dir}/alternate.db", # use a FS for the alternate because there can only be one memory db at a time in SQLite3
|
45
|
+
# 'sqlite3_fs' => "sqlite3://#{temp_db_dir}/alternate.db",
|
46
|
+
'mysql' => 'mysql://localhost/dm_core_test2',
|
47
|
+
'postgres' => 'postgres://localhost/dm_core_test2',
|
48
|
+
'oracle' => 'oracle://dm_core_test2:dm_core_test2@localhost/orcl'
|
49
|
+
}
|
21
50
|
|
22
51
|
# These environment variables will override the default connection string:
|
23
52
|
# MYSQL_SPEC_URI
|
@@ -26,66 +55,60 @@ end
|
|
26
55
|
#
|
27
56
|
# For example, in the bash shell, you might use:
|
28
57
|
# export MYSQL_SPEC_URI="mysql://localhost/dm_core_test?socket=/opt/local/var/run/mysql5/mysqld.sock"
|
29
|
-
|
30
|
-
|
58
|
+
|
59
|
+
adapters = ENV['ADAPTERS'].split(' ').map { |adapter_name| adapter_name.strip.downcase }.uniq
|
60
|
+
adapters = PRIMARY.keys if adapters.include?('all')
|
61
|
+
|
62
|
+
PRIMARY.only(*adapters).each do |name, default|
|
63
|
+
connection_string = ENV["#{name.upcase}_SPEC_URI"] || default
|
31
64
|
begin
|
32
|
-
adapter = DataMapper.setup(name,
|
65
|
+
adapter = DataMapper.setup(name.to_sym, connection_string)
|
33
66
|
|
34
|
-
|
35
|
-
|
36
|
-
|
67
|
+
# test the connection if possible
|
68
|
+
if adapter.respond_to?(:query)
|
69
|
+
name == 'oracle' ? adapter.query('SELECT 1 FROM dual') : adapter.query('SELECT 1')
|
37
70
|
end
|
38
71
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
warn "Could not load #{name} adapter: #{e}"
|
44
|
-
end
|
45
|
-
false
|
72
|
+
ADAPTERS << name
|
73
|
+
PRIMARY[name] = connection_string # ensure *_SPEC_URI is saved
|
74
|
+
rescue Exception => exception
|
75
|
+
puts "Could not connect to the database using #{connection_string.inspect} because: #{exception.inspect}"
|
46
76
|
end
|
47
77
|
end
|
48
78
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
DataMapper::Logger.new(nil, :debug)
|
56
|
-
|
57
|
-
# ----------------------------------------------------------------------
|
58
|
-
# --- Do not declare new models unless absolutely necessary. Instead ---
|
59
|
-
# --- pick a metaphor and use those models. If you do need new ---
|
60
|
-
# --- models, define them according to the metaphor being used. ---
|
61
|
-
# ----------------------------------------------------------------------
|
62
|
-
|
63
|
-
Spec::Runner.configure do |config|
|
64
|
-
config.before(:each) do
|
65
|
-
# load_models_for_metaphor :vehicles
|
79
|
+
# speed up test execution on Oracle
|
80
|
+
if defined?(DataMapper::Adapters::OracleAdapter)
|
81
|
+
DataMapper::Adapters::OracleAdapter.instance_eval do
|
82
|
+
auto_migrate_with :delete # table data will be deleted instead of dropping and creating table
|
83
|
+
auto_migrate_reset_sequences false # primary key sequences will not be reset
|
66
84
|
end
|
67
85
|
end
|
68
86
|
|
69
|
-
|
70
|
-
|
71
|
-
# ----------------------------------------------------------------------
|
87
|
+
ADAPTERS.freeze
|
88
|
+
PRIMARY.freeze
|
72
89
|
|
73
|
-
|
74
|
-
|
90
|
+
logger = DataMapper::Logger.new(DataMapper.root / 'log' / 'dm.log', :debug)
|
91
|
+
logger.auto_flush = true
|
75
92
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
property :author, String
|
80
|
-
property :title, String
|
81
|
-
end
|
93
|
+
Spec::Runner.configure do |config|
|
94
|
+
config.extend(DataMapper::Spec::AdapterHelpers)
|
95
|
+
config.include(DataMapper::Spec::PendingHelpers)
|
82
96
|
|
83
|
-
|
84
|
-
|
97
|
+
config.after :all do
|
98
|
+
# global model cleanup
|
99
|
+
descendants = DataMapper::Model.descendants.to_a
|
100
|
+
while model = descendants.shift
|
101
|
+
descendants.concat(model.descendants.to_a - [ model ])
|
85
102
|
|
86
|
-
|
87
|
-
|
103
|
+
parts = model.name.split('::')
|
104
|
+
constant_name = parts.pop.to_sym
|
105
|
+
base = parts.empty? ? Object : Object.full_const_get(parts.join('::'))
|
106
|
+
|
107
|
+
if base.const_defined?(constant_name)
|
108
|
+
base.send(:remove_const, constant_name)
|
109
|
+
end
|
88
110
|
|
89
|
-
|
90
|
-
|
111
|
+
DataMapper::Model.descendants.delete(model)
|
112
|
+
end
|
113
|
+
end
|
91
114
|
end
|
data/tasks/ci.rb
CHANGED
@@ -1,36 +1,24 @@
|
|
1
|
-
|
1
|
+
desc 'Run metric_fu'
|
2
|
+
task :ci do
|
3
|
+
# sudo gem install jscruggs-metric_fu -s http://gems.github.com
|
4
|
+
require 'metric_fu'
|
2
5
|
|
3
|
-
|
6
|
+
MetricFu::Configuration.run do |config|
|
7
|
+
specs = Pathname.glob(ENV['FILES'] || (ROOT + 'spec/**/*_spec.rb').to_s).sort.map { |file| file.to_s }
|
4
8
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
t.rcov = true
|
18
|
-
t.rcov_opts << '--exclude' << "spec,gems"
|
19
|
-
t.rcov_opts << '--text-summary'
|
20
|
-
t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
|
21
|
-
t.rcov_opts << '--only-uncovered'
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
task :saikuro => :prepare do
|
26
|
-
system "saikuro -c -i lib -y 0 -w 10 -e 15 -o ci/cyclomatic"
|
27
|
-
mv 'ci/cyclomatic/index_cyclo.html', 'ci/cyclomatic/index.html'
|
28
|
-
|
29
|
-
system "saikuro -t -i lib -y 0 -w 20 -e 30 -o ci/token"
|
30
|
-
mv 'ci/token/index_token.html', 'ci/token/index.html'
|
9
|
+
config.rcov = {
|
10
|
+
:test_files => specs,
|
11
|
+
:rcov_opts => [
|
12
|
+
'--sort coverage',
|
13
|
+
'--no-html',
|
14
|
+
'--text-coverage',
|
15
|
+
'--no-color',
|
16
|
+
'--profile',
|
17
|
+
'--exclude spec',
|
18
|
+
"`which spec` -- #{specs.join(' ')}",
|
19
|
+
],
|
20
|
+
}
|
31
21
|
end
|
32
22
|
|
23
|
+
Rake::Task['metrics:all'].invoke
|
33
24
|
end
|
34
|
-
|
35
|
-
#task :ci => %w[ ci:spec ci:doc ci:saikuro install ci:publish ] # yard-related tasks do not work yet
|
36
|
-
task :ci => %w[ ci:spec ]
|
data/tasks/dm.rb
CHANGED
@@ -1,63 +1,58 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
task :rcov => 'dm:rcov'
|
1
|
+
require 'spec/rake/spectask'
|
2
|
+
require 'spec/rake/verify_rcov'
|
4
3
|
|
5
|
-
|
6
|
-
task :unit => 'dm:spec:unit'
|
7
|
-
task :integration => 'dm:spec:integration'
|
8
|
-
end
|
4
|
+
task :default => 'spec'
|
9
5
|
|
10
|
-
|
11
|
-
|
12
|
-
task :integration => 'dm:rcov:integration'
|
6
|
+
RCov::VerifyTask.new(:verify_rcov => :rcov) do |config|
|
7
|
+
config.threshold = 88.1 # Make sure you have rcov 0.7 or higher!
|
13
8
|
end
|
14
9
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
10
|
+
def run_spec(name, files, rcov)
|
11
|
+
Spec::Rake::SpecTask.new(name) do |config|
|
12
|
+
config.spec_opts << '--options' << ROOT + 'spec/spec.opts'
|
13
|
+
config.spec_files = Pathname.glob(ENV['FILES'] || files.to_s).map { |file| file.to_s }
|
14
|
+
config.rcov = rcov
|
15
|
+
config.rcov_opts << '--exclude' << 'spec'
|
16
|
+
config.rcov_opts << '--text-summary'
|
17
|
+
config.rcov_opts << '--sort' << 'coverage'
|
18
|
+
config.rcov_opts << '--only-uncovered'
|
19
|
+
config.rcov_opts << '--profile'
|
20
|
+
#config.rcov_opts << '-w' # TODO: make sure it runs with warnings enabled
|
26
21
|
end
|
22
|
+
end
|
27
23
|
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
public_specs = ROOT + 'spec/public/**/*_spec.rb'
|
25
|
+
semipublic_specs = ROOT + 'spec/semipublic/**/*_spec.rb'
|
26
|
+
all_specs = ROOT + 'spec/**/*_spec.rb'
|
31
27
|
|
32
|
-
|
33
|
-
|
28
|
+
desc 'Run all specifications'
|
29
|
+
run_spec('spec', all_specs, false)
|
34
30
|
|
35
|
-
|
36
|
-
|
31
|
+
desc 'Run all specifications with rcov'
|
32
|
+
run_spec('rcov', all_specs, true)
|
37
33
|
|
38
|
-
|
39
|
-
|
40
|
-
|
34
|
+
namespace :spec do
|
35
|
+
desc 'Run public specifications'
|
36
|
+
run_spec('public', public_specs, false)
|
41
37
|
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
desc 'Run semipublic specifications'
|
39
|
+
run_spec('semipublic', semipublic_specs, false)
|
40
|
+
end
|
45
41
|
|
46
|
-
|
47
|
-
|
48
|
-
|
42
|
+
namespace :rcov do
|
43
|
+
desc 'Run public specifications with rcov'
|
44
|
+
run_spec('public', public_specs, true)
|
49
45
|
|
50
|
-
|
51
|
-
|
52
|
-
|
46
|
+
desc 'Run semipublic specifications with rcov'
|
47
|
+
run_spec('semipublic', semipublic_specs, true)
|
48
|
+
end
|
53
49
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
50
|
+
desc 'Run all comparisons with ActiveRecord'
|
51
|
+
task :perf do
|
52
|
+
sh ROOT + 'script/performance.rb'
|
53
|
+
end
|
58
54
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
55
|
+
desc 'Profile DataMapper'
|
56
|
+
task :profile do
|
57
|
+
sh ROOT + 'script/profile.rb'
|
63
58
|
end
|