declare_schema 2.3.2 → 2.3.3.pre.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b38ba5f14cb9ff014da1baaf10698db6e1ad744aa50804e62c2a958d75f26c47
4
- data.tar.gz: 526ab470daae916fcb233fa397d385feef77b7933237219e733db1543bef7184
3
+ metadata.gz: 97f3a5d50a7212aac5b3688c3e2a20a87d5957f6053d243eb5d2f81b5d2d8f3e
4
+ data.tar.gz: 635a2bac38835fa207cb7467de27eaf9fb30177e565b306d12644eb3d66a8953
5
5
  SHA512:
6
- metadata.gz: 18768edfdc06e9562246243d1d91e698545f0dfceefbcd48a29894733a684493e2c521cc782bbd45767d0980479c17657a12bc7ec25242d594ac4851b62925c5
7
- data.tar.gz: 760e5374a42726af4a3eb04f3c6063c1266d3384a5c23082d671b0485ce341b58c0ac5cf6726a49b5ddeb73d01cccd8213e81ea64eee1ac19fa219b3bdefb961
6
+ metadata.gz: 03b085e2c18ed987e5660e1c1cabef1535a68d31d5188ab48abf8c1051c494c19c23a7fe20d23b0d47331d5738f533ee8e8e0b198a706eb932ed8dc66b2233db
7
+ data.tar.gz: 2d78ff8de5e66d958ec025912260a5f797f3b381d4b02b93cf023f822229e75760b482cebbc825217da877e356fbf01e858997b7f19e770ce8ae67ff01c909a6
data/CHANGELOG.md CHANGED
@@ -4,6 +4,14 @@ 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
+ ## [2.3.3] - Unreleased
8
+ ### Changed
9
+ - The `timestamps` DSL method to create `created_at` and `updated_at` columns now defaults to `null: false` for `datetime` columns
10
+ - The `timestamps` DSL method to allow additional options to be passed to the `datetime` fields
11
+
12
+ ### Fixed
13
+ - Fixed a bug where `#validate` methods on core object classes with required arguments were cuasing model validations to fail
14
+
7
15
  ## [2.3.2] - 2025-02-21
8
16
  ### Fixed
9
17
  - Removed require of `activesupport/proxy_object` which is removed in Rails 8.0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- declare_schema (2.3.2)
4
+ declare_schema (2.3.3.pre.1)
5
5
  rails (>= 6.0)
6
6
 
7
7
  GEM
@@ -17,9 +17,9 @@ module DeclareSchema
17
17
 
18
18
  attr_reader :model
19
19
 
20
- def timestamps
21
- field(:created_at, :datetime, null: true)
22
- field(:updated_at, :datetime, null: true)
20
+ def timestamps(**options)
21
+ field(:created_at, :datetime, null: false, **options)
22
+ field(:updated_at, :datetime, null: false, **options)
23
23
  end
24
24
 
25
25
  def optimistic_lock
@@ -310,7 +310,7 @@ module DeclareSchema
310
310
 
311
311
  # Support for custom validations
312
312
  if (type_class = DeclareSchema.to_class(type))
313
- if type_class.public_method_defined?("validate")
313
+ if type_class.public_method_defined?("validate") && type_class.instance_method("validate").arity.zero?
314
314
  validate do |record|
315
315
  v = record.send(name)&.validate
316
316
  record.errors.add(name, v) if v.is_a?(String)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeclareSchema
4
- VERSION = "2.3.2"
4
+ VERSION = "2.3.3.pre.1"
5
5
  end
@@ -471,8 +471,8 @@ RSpec.describe 'DeclareSchema Migration Generator' do
471
471
 
472
472
  expect(Generators::DeclareSchema::Migration::Migrator.run).to(
473
473
  migrate_up(<<~EOS.strip)
474
- add_column :adverts, :created_at, :datetime, null: true
475
- add_column :adverts, :updated_at, :datetime, null: true
474
+ add_column :adverts, :created_at, :datetime, null: false
475
+ add_column :adverts, :updated_at, :datetime, null: false
476
476
  add_column :adverts, :lock_version, :integer#{lock_version_limit}, null: false, default: 1
477
477
  EOS
478
478
  .and(migrate_down(<<~EOS.strip))
@@ -486,6 +486,30 @@ RSpec.describe 'DeclareSchema Migration Generator' do
486
486
  Advert.field_specs.delete(:created_at)
487
487
  Advert.field_specs.delete(:lock_version)
488
488
 
489
+ ### Timestamps with null: true
490
+
491
+ # `updated_at` and `created_at` can be declared with the shorthand `timestamps` passed with null: true override
492
+
493
+ class Advert < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock
494
+ declare_schema do
495
+ timestamps null: true
496
+ end
497
+ end
498
+
499
+ expect(Generators::DeclareSchema::Migration::Migrator.run).to(
500
+ migrate_up(<<~EOS.strip)
501
+ add_column :adverts, :created_at, :datetime, null: true
502
+ add_column :adverts, :updated_at, :datetime, null: true
503
+ EOS
504
+ .and(migrate_down(<<~EOS.strip))
505
+ remove_column :adverts, :updated_at
506
+ remove_column :adverts, :created_at
507
+ EOS
508
+ )
509
+
510
+ Advert.field_specs.delete(:updated_at)
511
+ Advert.field_specs.delete(:created_at)
512
+
489
513
  ### Indices
490
514
 
491
515
  # You can add an index to a field definition
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: 2.3.2
4
+ version: 2.3.3.pre.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: 2025-02-22 00:00:00.000000000 Z
11
+ date: 2025-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  - !ruby/object:Gem::Version
159
159
  version: 1.3.6
160
160
  requirements: []
161
- rubygems_version: 3.5.10
161
+ rubygems_version: 3.4.16
162
162
  signing_key:
163
163
  specification_version: 4
164
164
  summary: Database schema declaration and migration generator for Rails