declare_schema 0.8.0.pre.5 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/declare_schema_build.yml +1 -1
- data/CHANGELOG.md +21 -1
- data/Gemfile.lock +1 -1
- data/README.md +91 -13
- data/lib/declare_schema.rb +46 -0
- data/lib/declare_schema/dsl.rb +39 -0
- data/lib/declare_schema/extensions/active_record/fields_declaration.rb +23 -4
- data/lib/declare_schema/model.rb +51 -59
- data/lib/declare_schema/model/column.rb +2 -0
- data/lib/declare_schema/model/field_spec.rb +11 -8
- data/lib/declare_schema/model/habtm_model_shim.rb +1 -1
- data/lib/declare_schema/version.rb +1 -1
- data/lib/generators/declare_schema/migration/migrator.rb +22 -33
- data/lib/generators/declare_schema/support/model.rb +4 -4
- data/spec/lib/declare_schema/api_spec.rb +7 -7
- data/spec/lib/declare_schema/field_declaration_dsl_spec.rb +41 -15
- data/spec/lib/declare_schema/field_spec_spec.rb +73 -22
- data/spec/lib/declare_schema/generator_spec.rb +3 -3
- data/spec/lib/declare_schema/interactive_primary_key_spec.rb +78 -26
- data/spec/lib/declare_schema/migration_generator_spec.rb +1989 -815
- data/spec/lib/declare_schema/model/column_spec.rb +47 -17
- data/spec/lib/declare_schema/model/foreign_key_definition_spec.rb +146 -57
- data/spec/lib/declare_schema/model/habtm_model_shim_spec.rb +3 -3
- data/spec/lib/declare_schema/model/index_definition_spec.rb +188 -77
- data/spec/lib/declare_schema/model/table_options_definition_spec.rb +75 -11
- data/spec/lib/declare_schema_spec.rb +101 -0
- data/spec/lib/generators/declare_schema/migration/migrator_spec.rb +12 -2
- metadata +7 -6
- data/test_responses.txt +0 -2
@@ -8,19 +8,20 @@ end
|
|
8
8
|
require_relative '../../../../lib/declare_schema/model/table_options_definition'
|
9
9
|
|
10
10
|
RSpec.describe DeclareSchema::Model::TableOptionsDefinition do
|
11
|
-
|
12
|
-
|
11
|
+
let(:model_class) { TableOptionsDefinitionTestModel }
|
12
|
+
|
13
|
+
context 'Using fields' do
|
14
|
+
before do
|
15
|
+
load File.expand_path('../prepare_testapp.rb', __dir__)
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
class TableOptionsDefinitionTestModel < ActiveRecord::Base
|
18
|
+
fields do
|
19
|
+
name :string, limit: 127, index: true
|
20
|
+
end
|
17
21
|
end
|
18
22
|
end
|
19
|
-
end
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
context 'instance methods' do
|
24
|
+
context 'instance methods' do
|
24
25
|
let(:table_options) { { charset: "utf8", collation: "utf8_general"} }
|
25
26
|
let(:model) { described_class.new('table_options_definition_test_models', table_options) }
|
26
27
|
|
@@ -50,8 +51,7 @@ RSpec.describe DeclareSchema::Model::TableOptionsDefinition do
|
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
53
|
-
|
54
|
-
context 'class << self' do
|
54
|
+
context 'class << self' do
|
55
55
|
describe '#for_model' do
|
56
56
|
context 'when database migrated' do
|
57
57
|
let(:options) do
|
@@ -70,5 +70,69 @@ RSpec.describe DeclareSchema::Model::TableOptionsDefinition do
|
|
70
70
|
it { should eq(described_class.new(model_class.table_name, options)) }
|
71
71
|
end
|
72
72
|
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'Using declare_schema' do
|
77
|
+
before do
|
78
|
+
load File.expand_path('../prepare_testapp.rb', __dir__)
|
79
|
+
|
80
|
+
class TableOptionsDefinitionTestModel < ActiveRecord::Base
|
81
|
+
declare_schema do
|
82
|
+
string :name, limit: 127, index: true
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'instance methods' do
|
88
|
+
let(:table_options) { { charset: "utf8", collation: "utf8_general"} }
|
89
|
+
let(:model) { described_class.new('table_options_definition_test_models', table_options) }
|
90
|
+
|
91
|
+
describe '#to_key' do
|
92
|
+
subject { model.to_key }
|
93
|
+
it { should eq(['table_options_definition_test_models', '{:charset=>"utf8", :collation=>"utf8_general"}']) }
|
94
|
+
end
|
95
|
+
|
96
|
+
describe '#settings' do
|
97
|
+
subject { model.settings }
|
98
|
+
it { should eq("CHARACTER SET utf8 COLLATE utf8_general") }
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#hash' do
|
102
|
+
subject { model.hash }
|
103
|
+
it { should eq(['table_options_definition_test_models', '{:charset=>"utf8", :collation=>"utf8_general"}'].hash) }
|
104
|
+
end
|
105
|
+
|
106
|
+
describe '#to_s' do
|
107
|
+
subject { model.to_s }
|
108
|
+
it { should eq("CHARACTER SET utf8 COLLATE utf8_general") }
|
109
|
+
end
|
110
|
+
|
111
|
+
describe '#alter_table_statement' do
|
112
|
+
subject { model.alter_table_statement }
|
113
|
+
it { should match(/execute "ALTER TABLE .*table_options_definition_test_models.* CHARACTER SET utf8 COLLATE utf8_general"/) }
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'class << self' do
|
118
|
+
describe '#for_model' do
|
119
|
+
context 'when database migrated' do
|
120
|
+
let(:options) do
|
121
|
+
if defined?(Mysql2)
|
122
|
+
{ charset: "utf8mb4", collation: "utf8mb4_bin" }
|
123
|
+
else
|
124
|
+
{ }
|
125
|
+
end
|
126
|
+
end
|
127
|
+
subject { described_class.for_model(model_class) }
|
128
|
+
|
129
|
+
before do
|
130
|
+
generate_migrations '-n', '-m'
|
131
|
+
end
|
132
|
+
|
133
|
+
it { should eq(described_class.new(model_class.table_name, options)) }
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
73
137
|
end
|
74
138
|
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe DeclareSchema do
|
4
|
+
describe '#default_charset' do
|
5
|
+
subject { described_class.default_charset }
|
6
|
+
|
7
|
+
context 'when not explicitly set' do
|
8
|
+
it { should eq("utf8mb4") }
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'when explicitly set' do
|
12
|
+
before { described_class.default_charset = "utf8" }
|
13
|
+
after { described_class.default_charset = "utf8mb4" }
|
14
|
+
it { should eq("utf8") }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#default_collation' do
|
19
|
+
subject { described_class.default_collation }
|
20
|
+
|
21
|
+
context 'when not explicitly set' do
|
22
|
+
it { should eq("utf8mb4_bin") }
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when explicitly set' do
|
26
|
+
before { described_class.default_collation = "utf8mb4_general_ci" }
|
27
|
+
after { described_class.default_collation = "utf8mb4_bin" }
|
28
|
+
it { should eq("utf8mb4_general_ci") }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#default_text_limit' do
|
33
|
+
subject { described_class.default_text_limit }
|
34
|
+
|
35
|
+
context 'when not explicitly set' do
|
36
|
+
it { should eq(0xffff_ffff) }
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when explicitly set' do
|
40
|
+
before { described_class.default_text_limit = 0xffff }
|
41
|
+
after { described_class.default_text_limit = 0xffff_ffff }
|
42
|
+
it { should eq(0xffff) }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#default_string_limit' do
|
47
|
+
subject { described_class.default_string_limit }
|
48
|
+
|
49
|
+
context 'when not explicitly set' do
|
50
|
+
it { should eq(nil) }
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when explicitly set' do
|
54
|
+
before { described_class.default_string_limit = 225 }
|
55
|
+
after { described_class.default_string_limit = nil }
|
56
|
+
it { should eq(225) }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#default_null' do
|
61
|
+
subject { described_class.default_null }
|
62
|
+
|
63
|
+
context 'when not explicitly set' do
|
64
|
+
it { should eq(false) }
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when explicitly set' do
|
68
|
+
before { described_class.default_null = true }
|
69
|
+
after { described_class.default_null = false }
|
70
|
+
it { should eq(true) }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#default_generate_foreign_keys' do
|
75
|
+
subject { described_class.default_generate_foreign_keys }
|
76
|
+
|
77
|
+
context 'when not explicitly set' do
|
78
|
+
it { should eq(true) }
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when explicitly set' do
|
82
|
+
before { described_class.default_generate_foreign_keys = false }
|
83
|
+
after { described_class.default_generate_foreign_keys = true }
|
84
|
+
it { should eq(false) }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#default_generate_indexing' do
|
89
|
+
subject { described_class.default_generate_indexing }
|
90
|
+
|
91
|
+
context 'when not explicitly set' do
|
92
|
+
it { should eq(true) }
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'when explicitly set' do
|
96
|
+
before { described_class.default_generate_indexing = false }
|
97
|
+
after { described_class.default_generate_indexing = true }
|
98
|
+
it { should eq(false) }
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -38,9 +38,14 @@ module Generators
|
|
38
38
|
|
39
39
|
context 'when explicitly set' do
|
40
40
|
before { described_class.default_charset = "utf8" }
|
41
|
-
after { described_class.default_charset =
|
41
|
+
after { described_class.default_charset = "utf8mb4" }
|
42
42
|
it { should eq("utf8") }
|
43
43
|
end
|
44
|
+
|
45
|
+
it 'should output deprecation warning' do
|
46
|
+
expect { described_class.default_charset = "utf8mb4" }.to output(/DEPRECATION WARNING: default_charset= is deprecated/).to_stderr
|
47
|
+
expect { subject }.to output(/DEPRECATION WARNING: default_charset is deprecated/).to_stderr
|
48
|
+
end
|
44
49
|
end
|
45
50
|
|
46
51
|
describe '#default_collation' do
|
@@ -52,9 +57,14 @@ module Generators
|
|
52
57
|
|
53
58
|
context 'when explicitly set' do
|
54
59
|
before { described_class.default_collation = "utf8mb4_general_ci" }
|
55
|
-
after { described_class.default_collation =
|
60
|
+
after { described_class.default_collation = "utf8mb4_bin" }
|
56
61
|
it { should eq("utf8mb4_general_ci") }
|
57
62
|
end
|
63
|
+
|
64
|
+
it 'should output deprecation warning' do
|
65
|
+
expect { described_class.default_collation = "utf8mb4_bin" }.to output(/DEPRECATION WARNING: default_collation= is deprecated/).to_stderr
|
66
|
+
expect { subject }.to output(/DEPRECATION WARNING: default_collation is deprecated/).to_stderr
|
67
|
+
end
|
58
68
|
end
|
59
69
|
|
60
70
|
describe 'load_rails_models' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: declare_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Invoca Development adapted from hobo_fields by Tom Locke
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- gemfiles/rails_6_sqlite.gemfile
|
58
58
|
- lib/declare_schema.rb
|
59
59
|
- lib/declare_schema/command.rb
|
60
|
+
- lib/declare_schema/dsl.rb
|
60
61
|
- lib/declare_schema/extensions/active_record/fields_declaration.rb
|
61
62
|
- lib/declare_schema/extensions/module.rb
|
62
63
|
- lib/declare_schema/field_declaration_dsl.rb
|
@@ -90,15 +91,15 @@ files:
|
|
90
91
|
- spec/lib/declare_schema/model/index_definition_spec.rb
|
91
92
|
- spec/lib/declare_schema/model/table_options_definition_spec.rb
|
92
93
|
- spec/lib/declare_schema/prepare_testapp.rb
|
94
|
+
- spec/lib/declare_schema_spec.rb
|
93
95
|
- spec/lib/generators/declare_schema/migration/migrator_spec.rb
|
94
96
|
- spec/spec_helper.rb
|
95
97
|
- spec/support/acceptance_spec_helpers.rb
|
96
|
-
- test_responses.txt
|
97
98
|
homepage: https://github.com/Invoca/declare_schema
|
98
99
|
licenses: []
|
99
100
|
metadata:
|
100
101
|
allowed_push_host: https://rubygems.org
|
101
|
-
post_install_message:
|
102
|
+
post_install_message:
|
102
103
|
rdoc_options: []
|
103
104
|
require_paths:
|
104
105
|
- lib
|
@@ -114,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
115
|
version: 1.3.6
|
115
116
|
requirements: []
|
116
117
|
rubygems_version: 3.0.3
|
117
|
-
signing_key:
|
118
|
+
signing_key:
|
118
119
|
specification_version: 4
|
119
120
|
summary: Database schema declaration and migration generator for Rails
|
120
121
|
test_files: []
|
data/test_responses.txt
DELETED