mv-core 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.rdoc +15 -1
- data/lib/migration_validators/active_record/base.rb +8 -3
- data/lib/migration_validators/active_record/connection_adapters/abstract_adapter.rb +6 -4
- data/lib/migration_validators/active_record/connection_adapters/native_adapter.rb +18 -7
- data/lib/migration_validators/active_record/connection_adapters/table.rb +4 -2
- data/lib/migration_validators/active_record/connection_adapters/table_definition.rb +4 -2
- data/lib/migration_validators/active_record/migration.rb +5 -4
- data/lib/migration_validators/active_record/schema.rb +4 -3
- data/lib/migration_validators/active_record/schema_dumper.rb +5 -6
- data/lib/migration_validators/adapters/containers.rb +9 -11
- data/lib/migration_validators/adapters/routing.rb +1 -3
- data/lib/migration_validators/adapters/syntax.rb +1 -3
- data/lib/migration_validators/adapters/validator_definitions.rb +14 -13
- data/lib/migration_validators/core/db_validator.rb +63 -110
- data/lib/migration_validators/core/statement_builder.rb +1 -0
- data/lib/migration_validators/core/validator_constraints_list.rb +32 -0
- data/lib/migration_validators/core/validator_container.rb +2 -2
- data/lib/migration_validators/core/validator_definition.rb +9 -9
- data/lib/mv-core.rb +7 -2
- metadata +86 -99
- data/spec/migration_validators/active_record/connection_adapters/abstract_adapter_spec.rb +0 -440
- data/spec/migration_validators/active_record/connection_adapters/table_definition_spec.rb +0 -4
- data/spec/migration_validators/active_record/migration.rb +0 -82
- data/spec/migration_validators/active_record/schema_dumper_spec.rb +0 -44
- data/spec/migration_validators/adapters/base_spec.rb +0 -89
- data/spec/migration_validators/core/adapter_wrapper_spec.rb +0 -168
- data/spec/migration_validators/core/db_validator_spec.rb +0 -347
- data/spec/migration_validators/core/statement_builder_spec.rb +0 -36
- data/spec/migration_validators/core/validator_container_spec.rb +0 -121
- data/spec/migration_validators/core/validator_definition_spec.rb +0 -131
- data/spec/migration_validators/core/validator_router_spec.rb +0 -60
- data/spec/mv-core_spec.rb +0 -4
- data/spec/spec_helper.rb +0 -15
- data/spec/support/factories/db_validator.rb +0 -43
@@ -1,36 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe MigrationValidators::Core::StatementBuilder do
|
4
|
-
before :each do
|
5
|
-
@builder = MigrationValidators::Core::StatementBuilder.new "column"
|
6
|
-
end
|
7
|
-
|
8
|
-
it "returns initial string by default" do
|
9
|
-
@builder.to_s.should == "column"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "allows to define additional action" do
|
13
|
-
@builder.operation(:and) {|stmt, value| "#{stmt} and #{value}" }
|
14
|
-
|
15
|
-
@builder.and("column_1").to_s.should == "column and column_1"
|
16
|
-
end
|
17
|
-
|
18
|
-
it "might be merged with another builder" do
|
19
|
-
@builder.operation(:and) {|stmt, value| "#{stmt} and #{value}" }
|
20
|
-
|
21
|
-
builder1 = MigrationValidators::Core::StatementBuilder.new ""
|
22
|
-
builder1.operation(:and) {|stmt, value| "#{stmt} and #{value} new" }
|
23
|
-
|
24
|
-
@builder.merge!(builder1)
|
25
|
-
|
26
|
-
@builder.and("column_1").to_s.should == "column and column_1 new"
|
27
|
-
end
|
28
|
-
|
29
|
-
it "migth be initialized by another (parent) builder" do
|
30
|
-
@builder.operation(:and) {|stmt, value| "#{stmt} and #{value}" }
|
31
|
-
|
32
|
-
builder1 = MigrationValidators::Core::StatementBuilder.new "column_2", @builder
|
33
|
-
|
34
|
-
builder1.and("column_1").to_s.should == "column_2 and column_1"
|
35
|
-
end
|
36
|
-
end
|
@@ -1,121 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe MigrationValidators::Core::ValidatorContainer, :type => :mv_test do
|
4
|
-
before :all do
|
5
|
-
use_memory_db
|
6
|
-
db.initialize_schema_migrations_table
|
7
|
-
end
|
8
|
-
|
9
|
-
before :each do
|
10
|
-
MigrationValidators::Core::DbValidator.clear_all
|
11
|
-
|
12
|
-
db.drop_table :test_table if db.table_exists?(:test_table)
|
13
|
-
db.create_table :test_table do |t|
|
14
|
-
t.string :str_column
|
15
|
-
t.string :str_column_1
|
16
|
-
end
|
17
|
-
|
18
|
-
@builder = MigrationValidators::Core::StatementBuilder.new
|
19
|
-
|
20
|
-
@builder.operation :and do |stmt, value|
|
21
|
-
"#{stmt} AND #{value}"
|
22
|
-
end
|
23
|
-
|
24
|
-
@builder.operation :or do |stmt, value|
|
25
|
-
"#{stmt} OR #{value}"
|
26
|
-
end
|
27
|
-
|
28
|
-
@definition = MigrationValidators::Core::ValidatorDefinition.new @builder
|
29
|
-
|
30
|
-
@definition.property :property_name do |property_value|
|
31
|
-
column.and(property_value)
|
32
|
-
end
|
33
|
-
|
34
|
-
@container = MigrationValidators::Core::ValidatorContainer.new :container, :validator_name => @definition
|
35
|
-
@validator = Factory.build :db_validator,
|
36
|
-
:validator_name => :validator_name,
|
37
|
-
:column_name => :column_name,
|
38
|
-
:options => {:property_name => :property_value}
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
describe :remove_validators do
|
43
|
-
it "regenerates constraint without specified validators" do
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe :add_validators do
|
48
|
-
it "returns definition processing result by default" do
|
49
|
-
@container.add_validators([@validator]).should == ["column_name AND property_value"]
|
50
|
-
end
|
51
|
-
|
52
|
-
it "adds constraint name to processed validators constraint list" do
|
53
|
-
@container.constraint_name {|group_key| "constraint" }
|
54
|
-
@container.add_validators([@validator]).should == ["column_name AND property_value"]
|
55
|
-
|
56
|
-
@validator.in_constraint?("constraint").should be_true
|
57
|
-
end
|
58
|
-
|
59
|
-
it "joins specified validator to existing ones within the same constraint" do
|
60
|
-
@container.constraint_name {|group_key| "constraint" }
|
61
|
-
|
62
|
-
validator1 = Factory.create :db_validator,
|
63
|
-
:validator_name => :validator_name,
|
64
|
-
:table_name => :test_table,
|
65
|
-
:column_name => :str_column,
|
66
|
-
:options => {:property_name => :property_value_1},
|
67
|
-
:constraints => ["constraint"]
|
68
|
-
|
69
|
-
@container.add_validators([@validator]).should == ["column_name AND property_value JOIN str_column AND property_value_1"]
|
70
|
-
end
|
71
|
-
|
72
|
-
it "creates drop statement if defined" do
|
73
|
-
@container.constraint_name {|group_key| "constraint" }
|
74
|
-
|
75
|
-
@container.operation :drop do |stmt, constraint_name, group_name|
|
76
|
-
"DROP ENTITY #{constraint_name}"
|
77
|
-
end
|
78
|
-
|
79
|
-
validator1 = Factory.create :db_validator,
|
80
|
-
:validator_name => :validator_name,
|
81
|
-
:table_name => :test_table,
|
82
|
-
:column_name => :str_column,
|
83
|
-
:options => {:property_name => :property_value_1},
|
84
|
-
:constraints => ["constraint"]
|
85
|
-
|
86
|
-
@container.add_validators([@validator]).should == ["DROP ENTITY constraint", "column_name AND property_value JOIN str_column AND property_value_1"]
|
87
|
-
end
|
88
|
-
|
89
|
-
#it "do not creates drop statement if such constraint does not exist" do
|
90
|
-
# @container.constraint_name {|group_key| "constraint" }
|
91
|
-
|
92
|
-
# @container.operation :drop do |stmt, constraint_name, group_name|
|
93
|
-
# "DROP ENTITY #{constraint_name}"
|
94
|
-
# end
|
95
|
-
|
96
|
-
# @container.add_validators([@validator]).should == ["column_name AND property_value"]
|
97
|
-
#end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe :remove_validators do
|
101
|
-
it "regenerates constraint without specified validators" do
|
102
|
-
@container.constraint_name {|group_key| "constraint" }
|
103
|
-
|
104
|
-
validator1 = Factory.create :db_validator,
|
105
|
-
:validator_name => :validator_name,
|
106
|
-
:table_name => :test_table,
|
107
|
-
:column_name => :str_column,
|
108
|
-
:options => {:property_name => :property_value_1},
|
109
|
-
:constraints => ["constraint"]
|
110
|
-
|
111
|
-
validator2 = Factory.create :db_validator,
|
112
|
-
:validator_name => :validator_name,
|
113
|
-
:table_name => :test_table,
|
114
|
-
:column_name => :str_column_1,
|
115
|
-
:options => {:property_name => :property_value_2},
|
116
|
-
:constraints => ["constraint"]
|
117
|
-
|
118
|
-
@container.remove_validators([validator2]).should == ["str_column AND property_value_1"]
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
@@ -1,131 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe MigrationValidators::Core::ValidatorDefinition, :type => :mv_test do
|
4
|
-
before :all do
|
5
|
-
use_memory_db
|
6
|
-
db.initialize_schema_migrations_table
|
7
|
-
end
|
8
|
-
|
9
|
-
before :each do
|
10
|
-
@definition = MigrationValidators::Core::ValidatorDefinition.new
|
11
|
-
|
12
|
-
@definition.operation :and do |stmt, value|
|
13
|
-
"#{stmt} AND #{value}"
|
14
|
-
end
|
15
|
-
|
16
|
-
@definition.operation :or do |stmt, value|
|
17
|
-
"#{stmt} OR #{value}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
it "might be initialized by db validator" do
|
22
|
-
validator = Factory.build :db_validator
|
23
|
-
|
24
|
-
@definition.validator = validator
|
25
|
-
|
26
|
-
@definition.to_s.should == validator.column_name
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "with validator" do
|
30
|
-
before :each do
|
31
|
-
@validator = Factory.build :db_validator
|
32
|
-
@definition.validator = @validator
|
33
|
-
end
|
34
|
-
|
35
|
-
it "supports invariant column property" do
|
36
|
-
@definition.column.and(@definition.column).to_s.should == "#{@validator.column_name} AND #{@validator.column_name}"
|
37
|
-
end
|
38
|
-
|
39
|
-
describe :process do
|
40
|
-
before :each do
|
41
|
-
@validator.options = { :property_name => :property_value }
|
42
|
-
end
|
43
|
-
|
44
|
-
it "returns empty array by default" do
|
45
|
-
@definition.process(@validator).should == []
|
46
|
-
end
|
47
|
-
|
48
|
-
it "allows to define property handlers" do
|
49
|
-
@definition.property :property_name do |property_value|
|
50
|
-
"#{column.and(property_value)}"
|
51
|
-
end
|
52
|
-
|
53
|
-
@definition.process(@validator).should == ["#{@validator.column_name} AND property_value"]
|
54
|
-
end
|
55
|
-
|
56
|
-
it "allows to define post processors" do
|
57
|
-
@definition.property :property_name do |property_value|
|
58
|
-
"#{column.and(property_value)}"
|
59
|
-
end
|
60
|
-
|
61
|
-
@definition.post do
|
62
|
-
self.and("some_post_value")
|
63
|
-
end
|
64
|
-
|
65
|
-
@definition.post :property_name => :property_value do
|
66
|
-
self.and("some_post_value_1")
|
67
|
-
end
|
68
|
-
|
69
|
-
@definition.post "property_name" => :property_value do
|
70
|
-
self.and("some_post_value_1")
|
71
|
-
end
|
72
|
-
|
73
|
-
@definition.post :property_name => :wrong_property_value do
|
74
|
-
self.and("some_post_value_2")
|
75
|
-
end
|
76
|
-
|
77
|
-
@definition.process(@validator).should == ["#{@validator.column_name} AND property_value AND some_post_value AND some_post_value_1"]
|
78
|
-
end
|
79
|
-
|
80
|
-
it "allows to define default property handler" do
|
81
|
-
@validator.options = {}
|
82
|
-
|
83
|
-
@definition.property do |property_value|
|
84
|
-
"#{column}"
|
85
|
-
end
|
86
|
-
|
87
|
-
@definition.process(@validator).should == ["#{@validator.column_name}"]
|
88
|
-
end
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
describe :bind_to_error do
|
93
|
-
before :each do
|
94
|
-
@definition.operation :bind_to_error do |stmt, error|
|
95
|
-
"SHOW '#{error}' UNLESS (#{stmt})"
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
it "takes :message validator property as default" do
|
100
|
-
@validator.options[:message] = :default_message
|
101
|
-
|
102
|
-
@definition.property :property_name do |property_value|
|
103
|
-
"#{column.and(property_value)}"
|
104
|
-
end
|
105
|
-
|
106
|
-
@definition.process(@validator).should == ["SHOW 'default_message' UNLESS (#{@validator.column_name} AND property_value)"]
|
107
|
-
end
|
108
|
-
|
109
|
-
it "allows to define message mapping" do
|
110
|
-
@validator.options[:message] = :default_message
|
111
|
-
@validator.options[:specific_message] = :some_specific_message
|
112
|
-
|
113
|
-
@definition.property :property_name, :message => :specific_message do |property_value|
|
114
|
-
"#{column.and(property_value)}"
|
115
|
-
end
|
116
|
-
|
117
|
-
@definition.process(@validator).should == ["SHOW 'some_specific_message' UNLESS (#{@validator.column_name} AND property_value)"]
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
it "allows to define options filter" do
|
122
|
-
@validator.options[:property_name_1] = :property_value_1
|
123
|
-
|
124
|
-
@definition.property(:property_name) {|property_value| "#{column.and(property_value)}"}
|
125
|
-
@definition.property(:property_name_1) {|property_value| "#{column.and(property_value)}"}
|
126
|
-
|
127
|
-
@definition.process(@validator, [:property_name]).should == ["#{@validator.column_name} AND property_value"]
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe MigrationValidators::Core::ValidatorRouter, :type => :mv_test do
|
4
|
-
before :all do
|
5
|
-
use_memory_db
|
6
|
-
db.initialize_schema_migrations_table
|
7
|
-
end
|
8
|
-
|
9
|
-
before :each do
|
10
|
-
@builder = MigrationValidators::Core::StatementBuilder.new
|
11
|
-
|
12
|
-
@builder.operation :and do |stmt, value|
|
13
|
-
"#{stmt} AND #{value}"
|
14
|
-
end
|
15
|
-
|
16
|
-
@builder.operation :or do |stmt, value|
|
17
|
-
"#{stmt} OR #{value}"
|
18
|
-
end
|
19
|
-
|
20
|
-
@definition = MigrationValidators::Core::ValidatorDefinition.new @builder
|
21
|
-
|
22
|
-
@definition.property :property_name do |property_value|
|
23
|
-
column
|
24
|
-
end
|
25
|
-
|
26
|
-
@container = MigrationValidators::Core::ValidatorContainer.new :container, :validator_name => @definition, :validator_name_1 => @definition
|
27
|
-
@container.operation :create do |stmt, group_name|
|
28
|
-
"CREATE ENTITY #{group_name} BEGIN #{stmt} END"
|
29
|
-
end
|
30
|
-
|
31
|
-
@container_1 = MigrationValidators::Core::ValidatorContainer.new :container, :validator_name => @definition
|
32
|
-
@container_1.operation :create do |stmt, group_name|
|
33
|
-
"CREATE ENTITY_1 #{group_name} BEGIN #{stmt} END"
|
34
|
-
end
|
35
|
-
|
36
|
-
@router = MigrationValidators::Core::ValidatorRouter.new :container => @container, :container_1 => @container_1
|
37
|
-
end
|
38
|
-
|
39
|
-
it "routes validators according to their properties" do
|
40
|
-
validator1 = Factory.build :db_validator, :validator_name => :validator_name, :options => {:property_name => :property_value, :on => :create}
|
41
|
-
validator2 = Factory.build :db_validator, :validator_name => :validator_name, :options => {:property_name => :property_value, :on => :update}
|
42
|
-
|
43
|
-
@router.to :container, :if => {:on => :create}
|
44
|
-
@router.to :container_1, :if => {:on => :update}
|
45
|
-
|
46
|
-
@router.add_validators([validator1, validator2]).should == ["CREATE ENTITY #{validator1.name} BEGIN #{validator1.column_name} END",
|
47
|
-
"CREATE ENTITY_1 #{validator2.name} BEGIN #{validator2.column_name} END"]
|
48
|
-
end
|
49
|
-
|
50
|
-
it "merges routes to the same container" do
|
51
|
-
validator1 = Factory.build :db_validator, :table_name => :table_name, :validator_name => :validator_name, :options => {:property_name => :property_value, :on => :create}
|
52
|
-
validator2 = Factory.build :db_validator, :table_name => :table_name, :validator_name => :validator_name_1, :options => {:property_name => :property_value, :on => :create}
|
53
|
-
|
54
|
-
@container.group {|validator| validator.table_name}
|
55
|
-
@container.constraint_name {|group_name| "trigger_name" }
|
56
|
-
@router.to :container, :if => {:on => :create}
|
57
|
-
|
58
|
-
@router.add_validators([validator1, validator2]).should == ["CREATE ENTITY trigger_name BEGIN #{validator1.column_name} JOIN #{validator2.column_name} END"]
|
59
|
-
end
|
60
|
-
end
|
data/spec/mv-core_spec.rb
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
-
require 'rspec'
|
4
|
-
require 'mv-test'
|
5
|
-
require 'mv-core'
|
6
|
-
require 'shoulda'
|
7
|
-
require 'factory_girl'
|
8
|
-
|
9
|
-
# Requires supporting files with custom matchers and macros, etc,
|
10
|
-
# in ./support/ and its subdirectories.
|
11
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
12
|
-
|
13
|
-
RSpec.configure do |config|
|
14
|
-
|
15
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
Factory.sequence :validator_table_name do |n|
|
2
|
-
"table_#{n}"
|
3
|
-
end
|
4
|
-
|
5
|
-
Factory.sequence :validator_column_name do |n|
|
6
|
-
"column_name_#{n}"
|
7
|
-
end
|
8
|
-
|
9
|
-
Factory.define :db_validator, :class => MigrationValidators::Core::DbValidator do |validator|
|
10
|
-
validator.table_name { Factory.next(:validator_table_name) }
|
11
|
-
validator.column_name Factory.next(:validator_column_name)
|
12
|
-
validator.validator_name 'presense'
|
13
|
-
end
|
14
|
-
|
15
|
-
Factory.define :db_validator_base, :parent => :db_validator do |validator|
|
16
|
-
validator.table_name 'table_name'
|
17
|
-
validator.column_name 'column_name'
|
18
|
-
end
|
19
|
-
|
20
|
-
Factory.define :uniqueness, :parent => :db_validator_base do |validator|
|
21
|
-
validator.validator_name "uniqueness"
|
22
|
-
end
|
23
|
-
|
24
|
-
Factory.define :uniqueness_check, :parent => :uniqueness do |validator|
|
25
|
-
validator.options :as => :check
|
26
|
-
end
|
27
|
-
|
28
|
-
Factory.define :uniqueness_trigger, :parent => :uniqueness do |validator|
|
29
|
-
validator.options :as => :trigger
|
30
|
-
end
|
31
|
-
|
32
|
-
Factory.define :presense, :parent => :db_validator_base do |validator|
|
33
|
-
validator.validator_name "presense"
|
34
|
-
end
|
35
|
-
|
36
|
-
Factory.define :presense_check, :parent => :presense do |validator|
|
37
|
-
validator.options :as => :check
|
38
|
-
end
|
39
|
-
|
40
|
-
Factory.define :presense_trigger, :parent => :presense do |validator|
|
41
|
-
validator.options :as => :trigger
|
42
|
-
end
|
43
|
-
|