declare_schema 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae6f3f47d3ad4fa0b1d2e30d8f34b7ac5825b690838492ac57846dcd53396e9a
4
- data.tar.gz: 129d77729c08d2fb41e506571ead2a82dd76c0c1675c18556bc3811e0adf3362
3
+ metadata.gz: 531940d48f1fe38830944576136ff76e2b29dc69a323a2a8e3f60f431731f104
4
+ data.tar.gz: 3afe0ce91fa631f4fa07d10ef1039f788589d440e87245c859db9bbe0179972d
5
5
  SHA512:
6
- metadata.gz: 5b145fdd60646c467772034afa2a29e30d29a4d35445c7e769bab731c043cb38c8e0b365ac7f6dc416e93fafdc1edd6e77724085054a6a442934cc191e335fdf
7
- data.tar.gz: 1356d29f00f1eb4a72b567c48c57c6683bcc56852dfb68a3252b521a74c6c0afcfdf5765d94a31d3322ee297465c3ca60ec611090cf3ad5dd935e2bc343285ed
6
+ metadata.gz: 67270e128e00f45b8ed8393b85ffe65ab4bc7ae197296adacf22c37629bdf5e768d6e204987b67e2d63b3ac0cc79aadb0b02c2c4f60e7e4b85e01f4d24ef55e2
7
+ data.tar.gz: c9763a6eacd9d1d1deef9e829072e974ea53a5575f0938a8b4202e4210aa704186022a12e8704c08edde24bc73c2da7f95b467b77f3c81e422df54eddaf2352a
data/CHANGELOG.md CHANGED
@@ -4,6 +4,15 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
4
4
 
5
5
  Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.9.0] - 2021-03-01
8
+ ### Added
9
+ - Added configurable default settings for `default_text_limit`, `default_string_limit`, `default_null`,
10
+ `default_generate_foreign_keys` and `default_generate_indexing` to allow developers to adhere to project conventions.
11
+
12
+ ### Changed
13
+ - Moved and deprecated default settings for `default_charset` and `default_collation` from
14
+ `Generators::DeclareSchema::Migration::Migrator` to `::DeclareSchema`
15
+
7
16
  ## [0.8.0] - 2021-02-22
8
17
  ### Removed
9
18
  - Removed assumption that primary key is named 'id'.
@@ -131,6 +140,7 @@ using the appropriate Rails configuration attributes.
131
140
  ### Added
132
141
  - Initial version from https://github.com/Invoca/hobo_fields v4.1.0.
133
142
 
143
+ [0.9.0]: https://github.com/Invoca/declare_schema/compare/v0.8.0...v0.9.0
134
144
  [0.8.0]: https://github.com/Invoca/declare_schema/compare/v0.7.1...v0.8.0
135
145
  [0.7.1]: https://github.com/Invoca/declare_schema/compare/v0.7.0...v0.7.1
136
146
  [0.7.0]: https://github.com/Invoca/declare_schema/compare/v0.6.3...v0.7.0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- declare_schema (0.8.0)
4
+ declare_schema (0.9.0)
5
5
  rails (>= 4.2)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -70,18 +70,85 @@ DeclareSchema::Migration::Migrator.before_generating_migration do
70
70
  end
71
71
  ```
72
72
 
73
- ## Declaring Character Set and Collation
74
- _Note: This feature currently only works for MySQL database configurations._
73
+ ### Global Configuration
74
+ Configurations can be set at the global level to customize default declaration for the following values:
75
75
 
76
- MySQL originally supported UTF-8 in the range of 1-3 bytes (`mb3` or "multi-byte 3")
77
- which covered the full set of Unicode code points at the time: U+0000 - U+FFFF.
78
- But later, Unicode was extended beyond U+FFFF to make room for emojis, and with that
79
- UTF-8 require 1-4 bytes (`mb4` or "multi-byte 4"). With this addition, there has
80
- come a need to dynamically define the character set and collation for individual
81
- tables and columns in the database. With `declare_schema` this can be configured
82
- at three separate levels
76
+ #### Text Limit
77
+ The default text limit can be set using the `DeclareSchema.default_text_limit=` method.
78
+ Note that a `nil` default means that there is no default-- so every declaration must be explicit.
79
+ This will `raise` a `limit: must be provided for field :text...` error when the default value is `nil` and there is no explicit
80
+ declaration.
83
81
 
84
- ### Global Configuration
82
+ For example, adding the following to your `config/initializers` directory will
83
+ set the default `text limit` value to `0xffff`:
84
+
85
+ **declare_schema.rb**
86
+ ```ruby
87
+ # frozen_string_literal: true
88
+
89
+ DeclareSchema.default_text_limit = 0xffff
90
+ ```
91
+
92
+ #### String Limit
93
+ The default string limit can be set using the `DeclareSchema.default_string_limit=` method.
94
+ Note that a `nil` default means that there is no default-- so every declaration must be explicit.
95
+ This will `raise` a `limit: must be provided for field :string...` error when the default value is `nil` and there is no explicit
96
+ declaration.
97
+
98
+ For example, adding the following to your `config/initializers` directory will
99
+ set the default `string limit` value to `255`:
100
+
101
+ **declare_schema.rb**
102
+ ```ruby
103
+ # frozen_string_literal: true
104
+
105
+ DeclareSchema.default_string_limit = 255
106
+ ```
107
+
108
+ #### Null
109
+ The default null value can be set using the `DeclareSchema.default_null=` method.
110
+ Note that a `nil` default means that there is no default-- so every declaration must be explicit.
111
+ This will `raise` a `null: must be provided for field...` error when the default value is `nil` and there is no explicit
112
+ declaration.
113
+
114
+ For example, adding the following to your `config/initializers` directory will
115
+ set the default `null` value to `true`:
116
+
117
+ **declare_schema.rb**
118
+ ```ruby
119
+ # frozen_string_literal: true
120
+
121
+ DeclareSchema.default_null = true
122
+ ```
123
+
124
+ #### Generate Foreign Keys
125
+ The default value for generate foreign keys can be set using the `DeclareSchema.default_generate_foreign_keys=` method.
126
+ This value defaults to `true` and can only be set at the global level.
127
+
128
+ For example, adding the following to your `config/initializers` directory will set
129
+ the default `generate foreign keys` value to `false`:
130
+
131
+ **declare_schema.rb**
132
+ ```ruby
133
+ # frozen_string_literal: true
134
+
135
+ DeclareSchema.default_generate_foreign_keys = false
136
+ ```
137
+
138
+ #### Generate Indexing
139
+ The default value for generate indexing can be set using the `DeclareSchema.default_generate_indexing=` method.
140
+ This value defaults to `true` and can only be set at the global level.
141
+
142
+ For example, adding the following to your `config/initializers` directory will
143
+ set the default `generate indexing` value to `false`:
144
+
145
+ **declare_schema.rb**
146
+ ```ruby
147
+ # frozen_string_literal: true
148
+
149
+ DeclareSchema.default_generate_indexing = false
150
+ ```
151
+ #### Character Set and Collation
85
152
  The character set and collation for all tables and fields can be set at the global level
86
153
  using the `Generators::DeclareSchema::Migrator.default_charset=` and
87
154
  `Generators::DeclareSchema::Migrator.default_collation=` configuration methods.
@@ -93,10 +160,21 @@ turn all tables into `utf8mb4` supporting tables:
93
160
  ```ruby
94
161
  # frozen_string_literal: true
95
162
 
96
- Generators::DeclareSchema::Migration::Migrator.default_charset = "utf8mb4"
97
- Generators::DeclareSchema::Migration::Migrator.default_collation = "utf8mb4_bin"
163
+ DeclareSchema.default_charset = "utf8mb4"
164
+ DeclareSchema.default_collation = "utf8mb4_bin"
98
165
  ```
99
166
 
167
+ ## Declaring Character Set and Collation
168
+ _Note: This feature currently only works for MySQL database configurations._
169
+
170
+ MySQL originally supported UTF-8 in the range of 1-3 bytes (`mb3` or "multi-byte 3")
171
+ which covered the full set of Unicode code points at the time: U+0000 - U+FFFF.
172
+ But later, Unicode was extended beyond U+FFFF to make room for emojis, and with that
173
+ UTF-8 require 1-4 bytes (`mb4` or "multi-byte 4"). With this addition, there has
174
+ come a need to dynamically define the character set and collation for individual
175
+ tables and columns in the database. With `declare_schema` this can be configured
176
+ at three separate levels
177
+
100
178
  ### Table Configuration
101
179
  In order to configure a table's default character set and collation, the `charset` and
102
180
  `collation` arguments can be added to the `fields` block.
@@ -21,7 +21,18 @@ module DeclareSchema
21
21
  text: String
22
22
  }.freeze
23
23
 
24
+ @default_charset = "utf8mb4"
25
+ @default_collation = "utf8mb4_bin"
26
+ @default_text_limit = 0xffff_ffff
27
+ @default_string_limit = nil
28
+ @default_null = false
29
+ @default_generate_foreign_keys = true
30
+ @default_generate_indexing = true
31
+
24
32
  class << self
33
+ attr_reader :default_charset, :default_collation, :default_text_limit, :default_string_limit, :default_null,
34
+ :default_generate_foreign_keys, :default_generate_indexing
35
+
25
36
  def to_class(type)
26
37
  case type
27
38
  when Class
@@ -32,6 +43,41 @@ module DeclareSchema
32
43
  raise ArgumentError, "expected Class or Symbol or String: got #{type.inspect}"
33
44
  end
34
45
  end
46
+
47
+ def default_charset=(charset)
48
+ charset.is_a?(String) or raise ArgumentError, "charset must be a string (got #{charset.inspect})"
49
+ @default_charset = charset
50
+ end
51
+
52
+ def default_collation=(collation)
53
+ collation.is_a?(String) or raise ArgumentError, "collation must be a string (got #{collation.inspect})"
54
+ @default_collation = collation
55
+ end
56
+
57
+ def default_text_limit=(text_limit)
58
+ text_limit.nil? or text_limit.is_a?(Integer) or raise ArgumentError, "text limit must be an integer or nil (got #{text_limit.inspect})"
59
+ @default_text_limit = text_limit
60
+ end
61
+
62
+ def default_string_limit=(string_limit)
63
+ string_limit.nil? or string_limit.is_a?(Integer) or raise ArgumentError, "string limit must be an integer or nil (got #{string_limit.inspect})"
64
+ @default_string_limit = string_limit
65
+ end
66
+
67
+ def default_null=(null)
68
+ null.in?([true, false, nil]) or raise ArgumentError, "null must be either true, false, or nil (got #{null.inspect})"
69
+ @default_null = null
70
+ end
71
+
72
+ def default_generate_foreign_keys=(generate_foreign_keys)
73
+ generate_foreign_keys.in?([true, false]) or raise ArgumentError, "generate_foreign_keys must be either true or false (got #{generate_foreign_keys.inspect})"
74
+ @default_generate_foreign_keys = generate_foreign_keys
75
+ end
76
+
77
+ def default_generate_indexing=(generate_indexing)
78
+ generate_indexing.in?([true, false]) or raise ArgumentError, "generate_indexing must be either true or false (got #{generate_indexing.inspect})"
79
+ @default_generate_indexing = generate_indexing
80
+ end
35
81
  end
36
82
  end
37
83
 
@@ -15,7 +15,7 @@ module DeclareSchema
15
15
  @table_options = table_options
16
16
 
17
17
  if block
18
- dsl = DeclareSchema::FieldDeclarationDsl.new(self, null: false)
18
+ dsl = DeclareSchema::FieldDeclarationDsl.new(self)
19
19
  if block.arity == 1
20
20
  yield dsl
21
21
  else
@@ -58,18 +58,21 @@ module DeclareSchema
58
58
  @position = position
59
59
  @options = options.dup
60
60
 
61
- @options.has_key?(:null) or @options[:null] = false
61
+ @options.has_key?(:null) or @options[:null] = ::DeclareSchema.default_null
62
+ @options[:null].nil? and raise "null: must be provided for field #{model}##{@name}: #{@options.inspect} since ::DeclareSchema#default_null is set to 'nil'; do you want `null: false`?"
62
63
 
63
64
  case @type
64
65
  when :text
65
66
  if self.class.mysql_text_limits?
66
67
  @options[:default].nil? or raise MysqlTextMayNotHaveDefault, "when using MySQL, non-nil default may not be given for :text field #{model}##{@name}"
67
- @options[:limit] = self.class.round_up_mysql_text_limit(@options[:limit] || MYSQL_LONGTEXT_LIMIT)
68
+ @options[:limit] ||= ::DeclareSchema.default_text_limit or
69
+ raise("limit: must be provided for :text field #{model}##{@name}: #{@options.inspect} since ::DeclareSchema#default_text_limit is set to 'nil'; do you want `limit: 0xffff_ffff`?")
70
+ @options[:limit] = self.class.round_up_mysql_text_limit(@options[:limit])
68
71
  else
69
72
  @options.delete(:limit)
70
73
  end
71
74
  when :string
72
- @options[:limit] or raise "limit: must be given for :string field #{model}##{@name}: #{@options.inspect}; do you want `limit: 255`?"
75
+ @options[:limit] ||= ::DeclareSchema.default_string_limit or raise "limit: must be provided for :string field #{model}##{@name}: #{@options.inspect} since ::DeclareSchema#default_string_limit is set to 'nil'; do you want `limit: 255`?"
73
76
  when :bigint
74
77
  @type = :integer
75
78
  @options[:limit] = 8
@@ -96,15 +99,15 @@ module DeclareSchema
96
99
 
97
100
  if @type.in?([:text, :string])
98
101
  if ActiveRecord::Base.connection.class.name.match?(/mysql/i)
99
- @options[:charset] ||= model.table_options[:charset] || Generators::DeclareSchema::Migration::Migrator.default_charset
100
- @options[:collation] ||= model.table_options[:collation] || Generators::DeclareSchema::Migration::Migrator.default_collation
102
+ @options[:charset] ||= model.table_options[:charset] || ::DeclareSchema.default_charset
103
+ @options[:collation] ||= model.table_options[:collation] || ::DeclareSchema.default_collation
101
104
  else
102
105
  @options.delete(:charset)
103
106
  @options.delete(:collation)
104
107
  end
105
108
  else
106
109
  @options[:charset] and warn("charset may only given for :string and :text fields for SQL type #{@type} in field #{model}##{@name}")
107
- @options[:collation] and warne("collation may only given for :string and :text fields for SQL type #{@type} in field #{model}##{@name}")
110
+ @options[:collation] and warn("collation may only given for :string and :text fields for SQL type #{@type} in field #{model}##{@name}")
108
111
  end
109
112
 
110
113
  @options = Hash[@options.sort_by { |k, _v| OPTION_INDEXES[k] || 9999 }]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeclareSchema
4
- VERSION = "0.8.0"
4
+ VERSION = "0.9.0"
5
5
  end
@@ -9,29 +9,14 @@ module Generators
9
9
  class Migrator
10
10
  class Error < RuntimeError; end
11
11
 
12
- DEFAULT_CHARSET = "utf8mb4"
13
- DEFAULT_COLLATION = "utf8mb4_bin"
14
-
15
12
  @ignore_models = []
16
13
  @ignore_tables = []
17
14
  @before_generating_migration_callback = nil
18
15
  @active_record_class = ActiveRecord::Base
19
- @default_charset = DEFAULT_CHARSET
20
- @default_collation = DEFAULT_COLLATION
21
16
 
22
17
  class << self
23
- attr_accessor :ignore_models, :ignore_tables, :disable_indexing, :disable_constraints
24
- attr_reader :active_record_class, :default_charset, :default_collation, :before_generating_migration_callback
25
-
26
- def default_charset=(charset)
27
- charset.is_a?(String) or raise ArgumentError, "charset must be a string (got #{charset.inspect})"
28
- @default_charset = charset
29
- end
30
-
31
- def default_collation=(collation)
32
- collation.is_a?(String) or raise ArgumentError, "collation must be a string (got #{collation.inspect})"
33
- @default_collation = collation
34
- end
18
+ attr_accessor :ignore_models, :ignore_tables
19
+ attr_reader :active_record_class, :before_generating_migration_callback
35
20
 
36
21
  def active_record_class
37
22
  @active_record_class.is_a?(Class) or @active_record_class = @active_record_class.to_s.constantize
@@ -58,6 +43,9 @@ module Generators
58
43
  block or raise ArgumentError, 'A block is required when setting the before_generating_migration callback'
59
44
  @before_generating_migration_callback = block
60
45
  end
46
+
47
+ delegate :default_charset=, :default_collation=, :default_charset, :default_collation, to: ::DeclareSchema
48
+ deprecate :default_charset=, :default_collation=, :default_charset, :default_collation, deprecator: ActiveSupport::Deprecation.new('1.0', 'declare_schema')
61
49
  end
62
50
 
63
51
  def initialize(ambiguity_resolver = {})
@@ -279,8 +267,8 @@ module Generators
279
267
  end
280
268
 
281
269
  #{table_options_definition.alter_table_statement unless ActiveRecord::Base.connection.class.name.match?(/SQLite3Adapter/)}
282
- #{create_indexes(model).join("\n") unless Migrator.disable_indexing}
283
- #{create_constraints(model).join("\n") unless Migrator.disable_indexing}
270
+ #{create_indexes(model).join("\n") if ::DeclareSchema.default_generate_indexing}
271
+ #{create_constraints(model).join("\n") if ::DeclareSchema.default_generate_foreign_keys}
284
272
  EOS
285
273
  end
286
274
 
@@ -300,8 +288,8 @@ module Generators
300
288
  {}
301
289
  else
302
290
  {
303
- charset: model.table_options[:charset] || Migrator.default_charset,
304
- collation: model.table_options[:collation] || Migrator.default_collation
291
+ charset: model.table_options[:charset] || ::DeclareSchema.default_charset,
292
+ collation: model.table_options[:collation] || ::DeclareSchema.default_collation
305
293
  }
306
294
  end
307
295
  end
@@ -415,7 +403,7 @@ module Generators
415
403
  end
416
404
 
417
405
  def change_indexes(model, old_table_name, to_remove)
418
- Migrator.disable_constraints and return [[], []]
406
+ ::DeclareSchema.default_generate_indexing or return [[], []]
419
407
 
420
408
  new_table_name = model.table_name
421
409
  existing_indexes = ::DeclareSchema::Model::IndexDefinition.for_model(model, old_table_name)
@@ -456,7 +444,7 @@ module Generators
456
444
 
457
445
  def change_foreign_key_constraints(model, old_table_name)
458
446
  ActiveRecord::Base.connection.class.name.match?(/SQLite3Adapter/) and raise ArgumentError, 'SQLite does not support foreign keys'
459
- Migrator.disable_indexing and return [[], []]
447
+ ::DeclareSchema.default_generate_foreign_keys or return [[], []]
460
448
 
461
449
  new_table_name = model.table_name
462
450
  existing_fks = ::DeclareSchema::Model::ForeignKeyDefinition.for_model(model, old_table_name)
@@ -585,8 +573,8 @@ module Generators
585
573
  # TODO: rewrite this method to use charset and collation variables rather than manipulating strings. -Colin
586
574
  def fix_mysql_charset_and_collation(dumped_schema)
587
575
  if !dumped_schema['options: ']
588
- dumped_schema.sub!('",', "\", options: \"DEFAULT CHARSET=#{Generators::DeclareSchema::Migration::Migrator.default_charset} "+
589
- "COLLATE=#{Generators::DeclareSchema::Migration::Migrator.default_collation}\",")
576
+ dumped_schema.sub!('",', "\", options: \"DEFAULT CHARSET=#{::DeclareSchema.default_charset} "+
577
+ "COLLATE=#{::DeclareSchema.default_collation}\",")
590
578
  end
591
579
  default_charset = dumped_schema[/CHARSET=(\w+)/, 1] or raise "unable to find charset in #{dumped_schema.inspect}"
592
580
  default_collation = dumped_schema[/COLLATE=(\w+)/, 1] || default_collation_from_charset(default_charset) or
@@ -61,6 +61,15 @@ RSpec.describe DeclareSchema::Model::FieldSpec do
61
61
  expect(subject.schema_attributes(col_spec)).to eq(type: :string, limit: 100, null: true)
62
62
  end
63
63
  end
64
+
65
+ it 'raises error when default_string_limit option is nil when not explicitly set in field spec' do
66
+ if defined?(Mysql2)
67
+ expect(::DeclareSchema).to receive(:default_string_limit) { nil }
68
+ expect do
69
+ described_class.new(model, :title, :string, null: true, charset: 'utf8mb4', position: 0)
70
+ end.to raise_error(/limit: must be provided for :string field/)
71
+ end
72
+ end
64
73
  end
65
74
 
66
75
  describe 'text' do
@@ -83,6 +92,27 @@ RSpec.describe DeclareSchema::Model::FieldSpec do
83
92
  expect(subject.schema_attributes(col_spec)).to eq(type: :text, null: true, default: 'none')
84
93
  end
85
94
  end
95
+
96
+ describe 'limit' do
97
+ it 'uses default_text_limit option when not explicitly set in field spec' do
98
+ allow(::DeclareSchema).to receive(:default_text_limit) { 100 }
99
+ subject = described_class.new(model, :title, :text, null: true, charset: 'utf8mb4', position: 2)
100
+ if defined?(Mysql2)
101
+ expect(subject.schema_attributes(col_spec)).to eq(type: :text, limit: 255, null: true, charset: 'utf8mb4', collation: 'utf8mb4_bin')
102
+ else
103
+ expect(subject.schema_attributes(col_spec)).to eq(type: :text, null: true)
104
+ end
105
+ end
106
+
107
+ it 'raises error when default_text_limit option is nil when not explicitly set in field spec' do
108
+ if defined?(Mysql2)
109
+ expect(::DeclareSchema).to receive(:default_text_limit) { nil }
110
+ expect do
111
+ described_class.new(model, :title, :text, null: true, charset: 'utf8mb4', position: 2)
112
+ end.to raise_error(/limit: must be provided for :text field/)
113
+ end
114
+ end
115
+ end
86
116
  end
87
117
 
88
118
  if defined?(Mysql2)
@@ -184,5 +214,17 @@ RSpec.describe DeclareSchema::Model::FieldSpec do
184
214
  it 'excludes non-sql options' do
185
215
  expect(subject.sql_options).to eq(limit: 4, null: true, default: 0)
186
216
  end
217
+
218
+ describe 'null' do
219
+ subject { described_class.new(model, :price, :integer, limit: 4, default: 0, position: 2, encrypt_using: ->(field) { field }) }
220
+ it 'uses default_null option when not explicitly set in field spec' do
221
+ expect(subject.sql_options).to eq(limit: 4, null: false, default: 0)
222
+ end
223
+
224
+ it 'raises error if default_null is set to nil when not explicitly set in field spec' do
225
+ expect(::DeclareSchema).to receive(:default_null) { nil }
226
+ expect { subject.sql_options }.to raise_error(/null: must be provided for field/)
227
+ end
228
+ end
187
229
  end
188
230
  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 = 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 = 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.8.0
4
+ version: 0.9.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-02-22 00:00:00.000000000 Z
11
+ date: 2021-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -90,6 +90,7 @@ files:
90
90
  - spec/lib/declare_schema/model/index_definition_spec.rb
91
91
  - spec/lib/declare_schema/model/table_options_definition_spec.rb
92
92
  - spec/lib/declare_schema/prepare_testapp.rb
93
+ - spec/lib/declare_schema_spec.rb
93
94
  - spec/lib/generators/declare_schema/migration/migrator_spec.rb
94
95
  - spec/spec_helper.rb
95
96
  - spec/support/acceptance_spec_helpers.rb
@@ -98,7 +99,7 @@ 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: []