mv-core 0.1.1 → 1.0.0
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.
- 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
@@ -0,0 +1,32 @@
|
|
1
|
+
module MigrationValidators
|
2
|
+
module Core
|
3
|
+
class ValidatorConstraintsList
|
4
|
+
attr_reader :raw_list
|
5
|
+
|
6
|
+
def initialize *constraints
|
7
|
+
@raw_list = constraints.collect(&:to_s)
|
8
|
+
end
|
9
|
+
|
10
|
+
def add constraint
|
11
|
+
@raw_list << constraint.to_s
|
12
|
+
@raw_list.uniq!
|
13
|
+
end
|
14
|
+
|
15
|
+
def remove constraint
|
16
|
+
@raw_list.delete(constraint.to_s)
|
17
|
+
end
|
18
|
+
|
19
|
+
def include? constraint
|
20
|
+
@raw_list.include?(constraint.to_s)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.load(raw_list)
|
24
|
+
new(*(YAML.load(raw_list || "") || []))
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.dump(list)
|
28
|
+
YAML.dump(list.raw_list)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -43,7 +43,7 @@ module MigrationValidators
|
|
43
43
|
validators + existing_validators
|
44
44
|
end
|
45
45
|
|
46
|
-
validators.each {|validator| validator.
|
46
|
+
validators.each {|validator| validator.constraints.add(constraint_name) }
|
47
47
|
|
48
48
|
res
|
49
49
|
end
|
@@ -53,7 +53,7 @@ module MigrationValidators
|
|
53
53
|
existing_validators - validators
|
54
54
|
end
|
55
55
|
|
56
|
-
validators.each {|validator| validator.
|
56
|
+
validators.each {|validator| validator.constraints.remove(constraint_name) }
|
57
57
|
|
58
58
|
res
|
59
59
|
end
|
@@ -63,18 +63,18 @@ module MigrationValidators
|
|
63
63
|
private
|
64
64
|
|
65
65
|
def handle_property property_name, property_value
|
66
|
-
|
66
|
+
opts, block = @properties[property_name.to_s]
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
68
|
+
if (block)
|
69
|
+
# at_least_one_property_handled = true
|
70
|
+
change(property_value, &block)
|
71
|
+
apply_posts
|
72
|
+
bind_to_error(message(opts))
|
73
73
|
|
74
|
-
|
75
|
-
|
74
|
+
return true
|
75
|
+
end
|
76
76
|
|
77
|
-
|
77
|
+
false
|
78
78
|
end
|
79
79
|
|
80
80
|
def apply_posts
|
data/lib/mv-core.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# require 'active_support'
|
1
2
|
require 'active_support'
|
2
3
|
require 'active_record'
|
4
|
+
# require 'active_record/railtie'
|
3
5
|
|
4
6
|
require File.expand_path(File.dirname(__FILE__)) + '/options'
|
5
7
|
|
@@ -12,6 +14,7 @@ require File.expand_path(File.dirname(__FILE__)) + '/migration_validators/active
|
|
12
14
|
require File.expand_path(File.dirname(__FILE__)) + '/migration_validators/active_record/schema'
|
13
15
|
require File.expand_path(File.dirname(__FILE__)) + '/migration_validators/active_record/schema_dumper'
|
14
16
|
|
17
|
+
require File.expand_path(File.dirname(__FILE__)) + '/migration_validators/core/validator_constraints_list'
|
15
18
|
require File.expand_path(File.dirname(__FILE__)) + '/migration_validators/core/db_validator'
|
16
19
|
require File.expand_path(File.dirname(__FILE__)) + '/migration_validators/core/adapter_wrapper'
|
17
20
|
require File.expand_path(File.dirname(__FILE__)) + '/migration_validators/core/statement_builder'
|
@@ -72,15 +75,16 @@ module MigrationValidators
|
|
72
75
|
def load!
|
73
76
|
::ActiveRecord::ConnectionAdapters::TableDefinition.class_eval { include MigrationValidators::ActiveRecord::ConnectionAdapters::TableDefinition }
|
74
77
|
::ActiveRecord::ConnectionAdapters::Table.class_eval { include MigrationValidators::ActiveRecord::ConnectionAdapters::Table }
|
75
|
-
::ActiveRecord::ConnectionAdapters::AbstractAdapter.class_eval { include MigrationValidators::ActiveRecord::ConnectionAdapters::AbstractAdapter }
|
78
|
+
# ::ActiveRecord::ConnectionAdapters::AbstractAdapter.class_eval { include MigrationValidators::ActiveRecord::ConnectionAdapters::AbstractAdapter }
|
76
79
|
::ActiveRecord::Base.instance_eval { include MigrationValidators::ActiveRecord::Base }
|
77
80
|
::ActiveRecord::Migration.instance_eval { include MigrationValidators::ActiveRecord::Migration }
|
78
81
|
::ActiveRecord::Schema.instance_eval { include MigrationValidators::ActiveRecord::Schema }
|
79
82
|
::ActiveRecord::SchemaDumper.instance_eval { include MigrationValidators::ActiveRecord::SchemaDumper }
|
80
|
-
|
81
83
|
::ActiveRecord::SchemaDumper.ignore_tables << MigrationValidators.migration_validators_table_name.to_s
|
84
|
+
|
82
85
|
end
|
83
86
|
end
|
87
|
+
|
84
88
|
end
|
85
89
|
|
86
90
|
Dir.glob('adapters/**/*.rb').each {|file_name| require file_name}
|
@@ -98,3 +102,4 @@ if defined?(Rails::Railtie)
|
|
98
102
|
else
|
99
103
|
MigrationValidators.load!
|
100
104
|
end
|
105
|
+
|
metadata
CHANGED
@@ -1,72 +1,93 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mv-core
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.1.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
6
|
+
authors:
|
8
7
|
- Valeriy Prokopchuk
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2014-10-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
17
14
|
name: activerecord
|
18
|
-
requirement:
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
version: 2.3.5
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.1.6
|
24
20
|
type: :runtime
|
25
21
|
prerelease: false
|
26
|
-
version_requirements:
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.1.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.1.6
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.1.6
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: i18n
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
36
49
|
prerelease: false
|
37
|
-
version_requirements:
|
38
|
-
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
39
56
|
name: jeweler
|
40
|
-
requirement:
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
version: 1.5.2
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.1
|
46
62
|
type: :development
|
47
63
|
prerelease: false
|
48
|
-
version_requirements:
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.0.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
57
76
|
type: :development
|
58
77
|
prerelease: false
|
59
|
-
version_requirements:
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
60
83
|
description: Migration Validators project core classes
|
61
84
|
email: vprokopchuk@gmail.com
|
62
85
|
executables: []
|
63
|
-
|
64
86
|
extensions: []
|
65
|
-
|
66
|
-
extra_rdoc_files:
|
87
|
+
extra_rdoc_files:
|
67
88
|
- LICENSE.txt
|
68
89
|
- README.rdoc
|
69
|
-
files:
|
90
|
+
files:
|
70
91
|
- lib/migration_validators/active_record/base.rb
|
71
92
|
- lib/migration_validators/active_record/connection_adapters/abstract_adapter.rb
|
72
93
|
- lib/migration_validators/active_record/connection_adapters/native_adapter.rb
|
@@ -83,6 +104,7 @@ files:
|
|
83
104
|
- lib/migration_validators/core/adapter_wrapper.rb
|
84
105
|
- lib/migration_validators/core/db_validator.rb
|
85
106
|
- lib/migration_validators/core/statement_builder.rb
|
107
|
+
- lib/migration_validators/core/validator_constraints_list.rb
|
86
108
|
- lib/migration_validators/core/validator_container.rb
|
87
109
|
- lib/migration_validators/core/validator_definition.rb
|
88
110
|
- lib/migration_validators/core/validator_router.rb
|
@@ -90,63 +112,28 @@ files:
|
|
90
112
|
- lib/options.rb
|
91
113
|
- LICENSE.txt
|
92
114
|
- README.rdoc
|
93
|
-
- spec/migration_validators/active_record/connection_adapters/abstract_adapter_spec.rb
|
94
|
-
- spec/migration_validators/active_record/connection_adapters/table_definition_spec.rb
|
95
|
-
- spec/migration_validators/active_record/migration.rb
|
96
|
-
- spec/migration_validators/active_record/schema_dumper_spec.rb
|
97
|
-
- spec/migration_validators/adapters/base_spec.rb
|
98
|
-
- spec/migration_validators/core/adapter_wrapper_spec.rb
|
99
|
-
- spec/migration_validators/core/db_validator_spec.rb
|
100
|
-
- spec/migration_validators/core/statement_builder_spec.rb
|
101
|
-
- spec/migration_validators/core/validator_container_spec.rb
|
102
|
-
- spec/migration_validators/core/validator_definition_spec.rb
|
103
|
-
- spec/migration_validators/core/validator_router_spec.rb
|
104
|
-
- spec/mv-core_spec.rb
|
105
|
-
- spec/spec_helper.rb
|
106
|
-
- spec/support/factories/db_validator.rb
|
107
|
-
has_rdoc: true
|
108
115
|
homepage: http://github.com/vprokopchuk256/mv-core
|
109
|
-
licenses:
|
116
|
+
licenses:
|
110
117
|
- MIT
|
118
|
+
metadata: {}
|
111
119
|
post_install_message:
|
112
120
|
rdoc_options: []
|
113
|
-
|
114
|
-
require_paths:
|
121
|
+
require_paths:
|
115
122
|
- lib
|
116
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
none: false
|
127
|
-
requirements:
|
128
|
-
- - ">="
|
129
|
-
- !ruby/object:Gem::Version
|
130
|
-
version: "0"
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
131
133
|
requirements: []
|
132
|
-
|
133
134
|
rubyforge_project:
|
134
|
-
rubygems_version: 1.
|
135
|
+
rubygems_version: 2.1.10
|
135
136
|
signing_key:
|
136
|
-
specification_version:
|
137
|
+
specification_version: 4
|
137
138
|
summary: Migration Validators project core classes
|
138
|
-
test_files:
|
139
|
-
- spec/migration_validators/active_record/connection_adapters/abstract_adapter_spec.rb
|
140
|
-
- spec/migration_validators/active_record/connection_adapters/table_definition_spec.rb
|
141
|
-
- spec/migration_validators/active_record/migration.rb
|
142
|
-
- spec/migration_validators/active_record/schema_dumper_spec.rb
|
143
|
-
- spec/migration_validators/adapters/base_spec.rb
|
144
|
-
- spec/migration_validators/core/adapter_wrapper_spec.rb
|
145
|
-
- spec/migration_validators/core/db_validator_spec.rb
|
146
|
-
- spec/migration_validators/core/statement_builder_spec.rb
|
147
|
-
- spec/migration_validators/core/validator_container_spec.rb
|
148
|
-
- spec/migration_validators/core/validator_definition_spec.rb
|
149
|
-
- spec/migration_validators/core/validator_router_spec.rb
|
150
|
-
- spec/mv-core_spec.rb
|
151
|
-
- spec/spec_helper.rb
|
152
|
-
- spec/support/factories/db_validator.rb
|
139
|
+
test_files: []
|
@@ -1,440 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
2
|
-
|
3
|
-
AbstractAdapter = ::ActiveRecord::ConnectionAdapters::AbstractAdapter
|
4
|
-
|
5
|
-
describe ::ActiveRecord::ConnectionAdapters::AbstractAdapter, "migration validators extension", :type => :mv_test do
|
6
|
-
|
7
|
-
before :all do
|
8
|
-
use_memory_db
|
9
|
-
@migrations_table = ::ActiveRecord::Migrator::schema_migrations_table_name
|
10
|
-
@validators_table = MigrationValidators.migration_validators_table_name
|
11
|
-
end
|
12
|
-
|
13
|
-
before :each do
|
14
|
-
MigrationValidators::Core::DbValidator.rollback
|
15
|
-
end
|
16
|
-
|
17
|
-
describe :initialize_migration_validators_table do
|
18
|
-
before :each do
|
19
|
-
db.drop_table @validators_table if db.table_exists?(@validators_table)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "creates table if it's not created" do
|
23
|
-
db.initialize_migration_validators_table
|
24
|
-
db.table_exists?(@validators_table).should be_true
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should not throw an error if table already exists" do
|
28
|
-
db.initialize_migration_validators_table
|
29
|
-
|
30
|
-
lambda { db.initialize_migration_validators_table }.should_not raise_error
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe :initialize_schema_migrations_table do
|
35
|
-
before :each do
|
36
|
-
|
37
|
-
db.do_internally do
|
38
|
-
db.drop_table @migrations_table if db.table_exists?(@migrations_table)
|
39
|
-
db.drop_table @validators_table if db.table_exists?(@validators_table)
|
40
|
-
end
|
41
|
-
db.initialize_schema_migrations_table
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should initialize migrations table as usuall" do
|
45
|
-
db.table_exists?(@migrations_table).should be_true
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should also initialize validators table" do
|
49
|
-
db.table_exists?(@validators_table).should be_true
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "synchronization with schema statements" do
|
54
|
-
before :each do
|
55
|
-
|
56
|
-
db.do_internally do
|
57
|
-
db.drop_table :new_table_name if db.table_exists?(:new_table_name)
|
58
|
-
db.drop_table :table_name if db.table_exists?(:table_name)
|
59
|
-
db.create_table(:table_name) do |t|
|
60
|
-
t.string :column_name
|
61
|
-
t.string :column_name1
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
MigrationValidators::Core::DbValidator.delete_all
|
66
|
-
end
|
67
|
-
|
68
|
-
describe :drop_table do
|
69
|
-
it "drops all validators of the dropped table" do
|
70
|
-
db.validate_column :table_name, :column_name, :uniqueness => {:message => "some message"}
|
71
|
-
MigrationValidators::Core::DbValidator.commit
|
72
|
-
|
73
|
-
db.drop_table :table_name
|
74
|
-
MigrationValidators::Core::DbValidator.commit
|
75
|
-
|
76
|
-
MigrationValidators::Core::DbValidator.count.should be_zero
|
77
|
-
end
|
78
|
-
|
79
|
-
it "still drops table" do
|
80
|
-
db.drop_table :table_name
|
81
|
-
db.table_exists?(:table_name).should be_false
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe :remove_column do
|
86
|
-
it "removes column validators" do
|
87
|
-
db.validate_column :table_name, :column_name, :uniqueness => {:message => "some message"}
|
88
|
-
db.validate_column :table_name, :column_name1, :uniqueness => {:message => "some message"}
|
89
|
-
MigrationValidators::Core::DbValidator.commit
|
90
|
-
|
91
|
-
db.remove_column :table_name, :column_name1
|
92
|
-
MigrationValidators::Core::DbValidator.commit
|
93
|
-
|
94
|
-
MigrationValidators::Core::DbValidator.count.should == 1
|
95
|
-
MigrationValidators::Core::DbValidator.first.column_name.should == "column_name"
|
96
|
-
end
|
97
|
-
|
98
|
-
it "still removes column" do
|
99
|
-
db.remove_column :table_name, :column_name1
|
100
|
-
db.column_exists?(:table_name, :column_name1).should be_false
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
|
105
|
-
describe :rename_column do
|
106
|
-
it "updates column name in validators table" do
|
107
|
-
db.validate_column :table_name, :column_name, :uniqueness => {:message => "some message"}
|
108
|
-
db.validate_column :table_name, :column_name1, :uniqueness => {:message => "some message"}
|
109
|
-
MigrationValidators::Core::DbValidator.commit
|
110
|
-
|
111
|
-
db.rename_column :table_name, :column_name1, :column_name2
|
112
|
-
MigrationValidators::Core::DbValidator.commit
|
113
|
-
|
114
|
-
MigrationValidators::Core::DbValidator.column_validators(:table_name, :column_name2).should_not be_blank
|
115
|
-
end
|
116
|
-
|
117
|
-
it "still renames column" do
|
118
|
-
db.rename_column :table_name, :column_name1, :column_name2
|
119
|
-
MigrationValidators::Core::DbValidator.commit
|
120
|
-
|
121
|
-
db.column_exists?(:table_name, :column_name1).should be_false
|
122
|
-
db.column_exists?(:table_name, :column_name2).should be_true
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe :rename_table do
|
127
|
-
it "updates table name in validators table" do
|
128
|
-
db.validate_column :table_name, :column_name, :uniqueness => {:message => "some message"}
|
129
|
-
MigrationValidators::Core::DbValidator.commit
|
130
|
-
|
131
|
-
db.rename_table :table_name, :new_table_name
|
132
|
-
MigrationValidators::Core::DbValidator.commit
|
133
|
-
|
134
|
-
MigrationValidators::Core::DbValidator.table_validators(:new_table_name).should_not be_blank
|
135
|
-
end
|
136
|
-
|
137
|
-
it "still renames table" do
|
138
|
-
db.rename_table :table_name, :new_table_name
|
139
|
-
|
140
|
-
db.table_exists?(:table_name).should be_false
|
141
|
-
db.table_exists?(:new_table_name).should be_true
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
describe :add_column do
|
146
|
-
before :each do
|
147
|
-
db.add_column :table_name, :new_column, :integer, :validates => {:uniqueness => true}
|
148
|
-
MigrationValidators::Core::DbValidator.commit
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should update validators table" do
|
152
|
-
MigrationValidators::Core::DbValidator.column_validators(:table_name, :new_column).should_not be_blank
|
153
|
-
end
|
154
|
-
|
155
|
-
it "should still add column" do
|
156
|
-
db.column_exists?(:table_name, :new_column).should be_true
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
describe :change_column do
|
161
|
-
before :each do
|
162
|
-
db.add_column :table_name, :new_column, :integer, :validates => {:uniqueness => true}
|
163
|
-
MigrationValidators::Core::DbValidator.commit
|
164
|
-
|
165
|
-
db.change_column :table_name, :new_column, :string, :validates => {:presense => true}
|
166
|
-
MigrationValidators::Core::DbValidator.commit
|
167
|
-
end
|
168
|
-
|
169
|
-
it "should update validators table" do
|
170
|
-
MigrationValidators::Core::DbValidator.column_validators(:table_name, :new_column).first.validator_name.should == "presense"
|
171
|
-
end
|
172
|
-
|
173
|
-
it "should still change column" do
|
174
|
-
db.columns(:table_name).find{|col| col.name.to_sym == :new_column}.type.should == :string
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
describe :create_table do
|
179
|
-
before :each do
|
180
|
-
db.drop_table :created_table if db.table_exists?(:created_table)
|
181
|
-
db.create_table :created_table do |t|
|
182
|
-
t.column :column, :string, :validates => {:presense => true}
|
183
|
-
t.string :string_column, :validates => {:presense => true}
|
184
|
-
t.text :text_column, :validates => {:presense => true}
|
185
|
-
t.integer :integer_column, :validates => {:presense => true}
|
186
|
-
t.float :float_column, :validates => {:presense => true}
|
187
|
-
t.decimal :decimal_column, :validates => {:presense => true}
|
188
|
-
t.datetime :datetime_column, :validates => {:presense => true}
|
189
|
-
t.time :time_column, :validates => {:presense => true}
|
190
|
-
t.date :date_column, :validates => {:presense => true}
|
191
|
-
t.binary :binary_column, :validates => {:presense => true}
|
192
|
-
t.boolean :boolean_column, :validates => {:presense => true}
|
193
|
-
end
|
194
|
-
|
195
|
-
MigrationValidators::Core::DbValidator.commit
|
196
|
-
end
|
197
|
-
|
198
|
-
it "with generall column should update validators table" do
|
199
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :column).should_not be_blank
|
200
|
-
end
|
201
|
-
|
202
|
-
it "with string column should update validators table" do
|
203
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :string_column).should_not be_blank
|
204
|
-
end
|
205
|
-
|
206
|
-
it "with text column should update validators table" do
|
207
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :text_column).should_not be_blank
|
208
|
-
end
|
209
|
-
|
210
|
-
it "with integer column should update validators table" do
|
211
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :integer_column).should_not be_blank
|
212
|
-
end
|
213
|
-
|
214
|
-
it "with float column should update validators table" do
|
215
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :float_column).should_not be_blank
|
216
|
-
end
|
217
|
-
|
218
|
-
it "with decimal column should update validators table" do
|
219
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :decimal_column).should_not be_blank
|
220
|
-
end
|
221
|
-
|
222
|
-
it "with datetime column should update validators table" do
|
223
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :datetime_column).should_not be_blank
|
224
|
-
end
|
225
|
-
|
226
|
-
it "with time column should update validators table" do
|
227
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :time_column).should_not be_blank
|
228
|
-
end
|
229
|
-
|
230
|
-
it "with date column should update validators table" do
|
231
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :date_column).should_not be_blank
|
232
|
-
end
|
233
|
-
|
234
|
-
it "with binary column should update validators table" do
|
235
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :binary_column).should_not be_blank
|
236
|
-
end
|
237
|
-
|
238
|
-
it "with boolean column should update validators table" do
|
239
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :boolean_column).should_not be_blank
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
describe :change_table do
|
245
|
-
describe "create_columns" do
|
246
|
-
before :each do
|
247
|
-
db.drop_table :created_table if db.table_exists?(:created_table)
|
248
|
-
db.create_table(:created_table) {|t| t.string :dummy_column }
|
249
|
-
db.change_table :created_table do |t|
|
250
|
-
t.column :column, :string, :validates => {:presense => true}
|
251
|
-
t.string :string_column, :validates => {:presense => true}
|
252
|
-
t.text :text_column, :validates => {:presense => true}
|
253
|
-
t.integer :integer_column, :validates => {:presense => true}
|
254
|
-
t.float :float_column, :validates => {:presense => true}
|
255
|
-
t.decimal :decimal_column, :validates => {:presense => true}
|
256
|
-
t.datetime :datetime_column, :validates => {:presense => true}
|
257
|
-
t.time :time_column, :validates => {:presense => true}
|
258
|
-
t.date :date_column, :validates => {:presense => true}
|
259
|
-
t.binary :binary_column, :validates => {:presense => true}
|
260
|
-
t.boolean :boolean_column, :validates => {:presense => true}
|
261
|
-
end
|
262
|
-
|
263
|
-
MigrationValidators::Core::DbValidator.commit
|
264
|
-
end
|
265
|
-
|
266
|
-
it "with generall column should update validators table" do
|
267
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :column).should_not be_blank
|
268
|
-
end
|
269
|
-
|
270
|
-
it "with string column should update validators table" do
|
271
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :string_column).should_not be_blank
|
272
|
-
end
|
273
|
-
|
274
|
-
it "with text column should update validators table" do
|
275
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :text_column).should_not be_blank
|
276
|
-
end
|
277
|
-
|
278
|
-
it "with integer column should update validators table" do
|
279
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :integer_column).should_not be_blank
|
280
|
-
end
|
281
|
-
|
282
|
-
it "with float column should update validators table" do
|
283
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :float_column).should_not be_blank
|
284
|
-
end
|
285
|
-
|
286
|
-
it "with decimal column should update validators table" do
|
287
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :decimal_column).should_not be_blank
|
288
|
-
end
|
289
|
-
|
290
|
-
it "with datetime column should update validators table" do
|
291
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :datetime_column).should_not be_blank
|
292
|
-
end
|
293
|
-
|
294
|
-
it "with time column should update validators table" do
|
295
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :time_column).should_not be_blank
|
296
|
-
end
|
297
|
-
|
298
|
-
it "with date column should update validators table" do
|
299
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :date_column).should_not be_blank
|
300
|
-
end
|
301
|
-
|
302
|
-
it "with binary column should update validators table" do
|
303
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :binary_column).should_not be_blank
|
304
|
-
end
|
305
|
-
|
306
|
-
it "with boolean column should update validators table" do
|
307
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :boolean_column).should_not be_blank
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|
311
|
-
describe "change_existing_columns" do
|
312
|
-
before :each do
|
313
|
-
db.drop_table :created_table if db.table_exists?(:created_table)
|
314
|
-
|
315
|
-
db.create_table :created_table do |t|
|
316
|
-
t.column :column, :string, :validates => {:presense => true}
|
317
|
-
t.column :column_1, :string, :validates => {:presense => true}
|
318
|
-
t.column :column_to_remove, :string, :validates => {:presense => true}
|
319
|
-
t.column :old_column_name, :string, :validates => {:presense => true}
|
320
|
-
end
|
321
|
-
|
322
|
-
MigrationValidators::Core::DbValidator.commit
|
323
|
-
|
324
|
-
|
325
|
-
db.change_table :created_table do |t|
|
326
|
-
t.change :column, :string, :validates => {:presense => false}
|
327
|
-
t.remove :column_to_remove
|
328
|
-
t.rename :old_column_name, :new_column_name
|
329
|
-
t.change_validates :column_1, :presense => false
|
330
|
-
end
|
331
|
-
|
332
|
-
MigrationValidators::Core::DbValidator.commit
|
333
|
-
end
|
334
|
-
|
335
|
-
it "with generall column should update validators table" do
|
336
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :column).should be_blank
|
337
|
-
end
|
338
|
-
|
339
|
-
it "should track column removing" do
|
340
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :column_to_remove).should be_blank
|
341
|
-
end
|
342
|
-
|
343
|
-
it "should trach column renaming" do
|
344
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :old_column_name).should be_blank
|
345
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :new_column_name).should_not be_blank
|
346
|
-
end
|
347
|
-
|
348
|
-
it "supports special change_validates method" do
|
349
|
-
MigrationValidators::Core::DbValidator.column_validators(:created_table, :column_1).should be_blank
|
350
|
-
end
|
351
|
-
end
|
352
|
-
end
|
353
|
-
|
354
|
-
|
355
|
-
describe "operations with validators" do
|
356
|
-
before :each do
|
357
|
-
db.create_table(:table_name) do |t|
|
358
|
-
t.string :column_name
|
359
|
-
end unless db.table_exists?(:table_name)
|
360
|
-
|
361
|
-
MigrationValidators::Core::DbValidator.remove_table_validators :table_name
|
362
|
-
MigrationValidators::Core::DbValidator.commit
|
363
|
-
end
|
364
|
-
|
365
|
-
describe :validate_column do
|
366
|
-
it "raises an exception if 0 validators defined" do
|
367
|
-
lambda {
|
368
|
-
db.validate_column :table_name, :column_name, {}
|
369
|
-
}.should raise_error(MigrationValidators::MigrationValidatorsException, /at least one column validator should be defined/)
|
370
|
-
end
|
371
|
-
|
372
|
-
it "adds all specified validators to the validator table" do
|
373
|
-
|
374
|
-
db.validate_column :table_name,
|
375
|
-
:column_name,
|
376
|
-
:uniqueness => {:message => "unique"},
|
377
|
-
:inclusion => {:message => "inclusion"}
|
378
|
-
MigrationValidators::Core::DbValidator.commit
|
379
|
-
|
380
|
-
MigrationValidators::Core::DbValidator.column_validators("table_name", "column_name").length.should == 2
|
381
|
-
end
|
382
|
-
|
383
|
-
it "stores validator options if they defined as hash" do
|
384
|
-
db.validate_column :table_name,
|
385
|
-
:column_name,
|
386
|
-
:uniqueness => {:message => "unique"}
|
387
|
-
MigrationValidators::Core::DbValidator.commit
|
388
|
-
|
389
|
-
|
390
|
-
MigrationValidators::Core::DbValidator.table_validators("table_name").first.options[:message].should == "unique"
|
391
|
-
end
|
392
|
-
|
393
|
-
it "should treat true in validator options as empty options list" do
|
394
|
-
db.validate_column :table_name,
|
395
|
-
:column_name,
|
396
|
-
:uniqueness => true
|
397
|
-
MigrationValidators::Core::DbValidator.commit
|
398
|
-
|
399
|
-
MigrationValidators::Core::DbValidator.table_validators("table_name").first.options.should == {}
|
400
|
-
end
|
401
|
-
|
402
|
-
it "should treat false in validator option as validator removing request" do
|
403
|
-
db.validate_column :table_name,
|
404
|
-
:column_name,
|
405
|
-
:uniqueness => true
|
406
|
-
MigrationValidators::Core::DbValidator.commit
|
407
|
-
|
408
|
-
db.validate_column :table_name,
|
409
|
-
:column_name,
|
410
|
-
:uniqueness => false
|
411
|
-
MigrationValidators::Core::DbValidator.commit
|
412
|
-
|
413
|
-
MigrationValidators::Core::DbValidator.table_validators(:table_name).should be_blank
|
414
|
-
end
|
415
|
-
|
416
|
-
it "should not allow nil instead of false as validator parameter" do
|
417
|
-
lambda {
|
418
|
-
db.validate_column :table_name,
|
419
|
-
:column_name,
|
420
|
-
:uniqueness => nil
|
421
|
-
MigrationValidators::Core::DbValidator.commit
|
422
|
-
}.should raise_error(MigrationValidators::MigrationValidatorsException, /use false to remove column validator/)
|
423
|
-
end
|
424
|
-
|
425
|
-
it "takes name of the context table if blank table name specified as parameter" do
|
426
|
-
db.in_context_of_table :table_name do
|
427
|
-
db.validate_column nil,
|
428
|
-
:column_name,
|
429
|
-
:uniqueness => true
|
430
|
-
MigrationValidators::Core::DbValidator.commit
|
431
|
-
end
|
432
|
-
|
433
|
-
MigrationValidators::Core::DbValidator.column_validators("table_name", "column_name").length.should == 1
|
434
|
-
end
|
435
|
-
end
|
436
|
-
|
437
|
-
describe :validate_table, "supports" do
|
438
|
-
end
|
439
|
-
end
|
440
|
-
end
|