declare_schema 0.9.0 → 0.10.0.pre.dc.1
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 +4 -4
- data/.github/workflows/declare_schema_build.yml +1 -1
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/declare_schema/dsl.rb +40 -0
- data/lib/declare_schema/extensions/active_record/fields_declaration.rb +22 -3
- data/lib/declare_schema/model.rb +1 -1
- data/lib/declare_schema/version.rb +1 -1
- 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/generator_spec.rb +3 -3
- data/spec/lib/declare_schema/interactive_primary_key_spec.rb +79 -27
- 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/index_definition_spec.rb +188 -77
- data/spec/lib/declare_schema/model/table_options_definition_spec.rb +75 -11
- metadata +3 -3
- 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
|
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.pre.dc.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Invoca Development adapted from hobo_fields by Tom Locke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-03 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
|
@@ -94,7 +95,6 @@ files:
|
|
94
95
|
- spec/lib/generators/declare_schema/migration/migrator_spec.rb
|
95
96
|
- spec/spec_helper.rb
|
96
97
|
- spec/support/acceptance_spec_helpers.rb
|
97
|
-
- test_responses.txt
|
98
98
|
homepage: https://github.com/Invoca/declare_schema
|
99
99
|
licenses: []
|
100
100
|
metadata:
|
data/test_responses.txt
DELETED