schema_plus_default_expr 0.1.4 → 1.0.1

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
- SHA1:
3
- metadata.gz: 46822d03ac2e3f6a2251dc59ba654e5f0181df8e
4
- data.tar.gz: 9ad28e0665f3ca74133da292e752d763e8c806d5
2
+ SHA256:
3
+ metadata.gz: 14597121db8f2e284e7e613c7d0b9ceedd8f98a2cd9f085d019660c34c6ef5a5
4
+ data.tar.gz: 51e9dddb7157edf31da2ec10761b38c56cf1919669bcb97f4477044441e2209f
5
5
  SHA512:
6
- metadata.gz: 60984075b8d0c18a040075b45afc7ba4638fe53eca2441726733276d0f7148daa9cbf0432c54a10d9a4297d6ada7bc2f469c10026943824c7d2359467ab14ee2
7
- data.tar.gz: b5b45b622fc4bd0363ed01702d4d6d56eed405291d7885d6685bbc3ab218aaff11a92710e6c2909d62878d836bc94c1d2bc1ffa3c764574d02272e691a8d432a
6
+ metadata.gz: f0a7b837d44f903c22ad3286bded62e008fc2c892e4e3d41ae9e7fe1f02f862a3db7532d4a178fc82cf56421d25dcfa2caff9e739ca69cd70a6c3c2c81f5c000
7
+ data.tar.gz: ae111294c25323bb9bd70c1ffad4fbbc2f41e47a21ab47d86f5e576631ab97126f8092f23b1c32d96f07de61585d6f3a023c5e8bd8517361a668000afdb24628
@@ -0,0 +1,158 @@
1
+ # This file was auto-generated by the schema_dev tool, based on the data in
2
+ # ./schema_dev.yml
3
+ # Please do not edit this file; any changes will be overwritten next time
4
+ # schema_dev gets run.
5
+ ---
6
+ name: CI PR Builds
7
+ 'on':
8
+ push:
9
+ branches:
10
+ - master
11
+ pull_request:
12
+ concurrency:
13
+ group: ci-${{ github.ref }}
14
+ cancel-in-progress: true
15
+ jobs:
16
+ test:
17
+ runs-on: ubuntu-latest
18
+ strategy:
19
+ fail-fast: false
20
+ matrix:
21
+ ruby:
22
+ - '2.5'
23
+ - '2.7'
24
+ - '3.0'
25
+ - '3.1'
26
+ activerecord:
27
+ - '5.2'
28
+ - '6.0'
29
+ - '6.1'
30
+ - '7.0'
31
+ db:
32
+ - sqlite3
33
+ - skip
34
+ dbversion:
35
+ - skip
36
+ exclude:
37
+ - ruby: '3.0'
38
+ activerecord: '5.2'
39
+ - ruby: '3.1'
40
+ activerecord: '5.2'
41
+ - ruby: '2.5'
42
+ activerecord: '7.0'
43
+ - db: skip
44
+ dbversion: skip
45
+ include:
46
+ - ruby: '2.5'
47
+ activerecord: '5.2'
48
+ db: postgresql
49
+ dbversion: '9.6'
50
+ - ruby: '2.5'
51
+ activerecord: '6.0'
52
+ db: postgresql
53
+ dbversion: '9.6'
54
+ - ruby: '2.5'
55
+ activerecord: '6.1'
56
+ db: postgresql
57
+ dbversion: '9.6'
58
+ - ruby: '2.7'
59
+ activerecord: '5.2'
60
+ db: postgresql
61
+ dbversion: '9.6'
62
+ - ruby: '2.7'
63
+ activerecord: '6.0'
64
+ db: postgresql
65
+ dbversion: '9.6'
66
+ - ruby: '2.7'
67
+ activerecord: '6.1'
68
+ db: postgresql
69
+ dbversion: '9.6'
70
+ - ruby: '2.7'
71
+ activerecord: '7.0'
72
+ db: postgresql
73
+ dbversion: '9.6'
74
+ - ruby: '3.0'
75
+ activerecord: '6.0'
76
+ db: postgresql
77
+ dbversion: '9.6'
78
+ - ruby: '3.0'
79
+ activerecord: '6.1'
80
+ db: postgresql
81
+ dbversion: '9.6'
82
+ - ruby: '3.0'
83
+ activerecord: '7.0'
84
+ db: postgresql
85
+ dbversion: '9.6'
86
+ - ruby: '3.1'
87
+ activerecord: '6.0'
88
+ db: postgresql
89
+ dbversion: '9.6'
90
+ - ruby: '3.1'
91
+ activerecord: '6.1'
92
+ db: postgresql
93
+ dbversion: '9.6'
94
+ - ruby: '3.1'
95
+ activerecord: '7.0'
96
+ db: postgresql
97
+ dbversion: '9.6'
98
+ env:
99
+ BUNDLE_GEMFILE: "${{ github.workspace }}/gemfiles/activerecord-${{ matrix.activerecord }}/Gemfile.${{ matrix.db }}"
100
+ POSTGRESQL_DB_HOST: 127.0.0.1
101
+ POSTGRESQL_DB_USER: schema_plus_test
102
+ POSTGRESQL_DB_PASS: database
103
+ steps:
104
+ - uses: actions/checkout@v2
105
+ - name: Set up Ruby
106
+ uses: ruby/setup-ruby@v1
107
+ with:
108
+ ruby-version: "${{ matrix.ruby }}"
109
+ bundler-cache: true
110
+ - name: Run bundle update
111
+ run: bundle update
112
+ - name: Start Postgresql
113
+ if: matrix.db == 'postgresql'
114
+ run: |
115
+ docker run --rm --detach \
116
+ -e POSTGRES_USER=$POSTGRESQL_DB_USER \
117
+ -e POSTGRES_PASSWORD=$POSTGRESQL_DB_PASS \
118
+ -p 5432:5432 \
119
+ --health-cmd "pg_isready -q" \
120
+ --health-interval 5s \
121
+ --health-timeout 5s \
122
+ --health-retries 5 \
123
+ --name database postgres:${{ matrix.dbversion }}
124
+ - name: Wait for database to start
125
+ if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
126
+ run: |
127
+ COUNT=0
128
+ ATTEMPTS=20
129
+ until [[ $COUNT -eq $ATTEMPTS ]]; do
130
+ [ "$(docker inspect -f {{.State.Health.Status}} database)" == "healthy" ] && break
131
+ echo $(( COUNT++ )) > /dev/null
132
+ sleep 2
133
+ done
134
+ - name: Create testing database
135
+ if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
136
+ run: bundle exec rake create_ci_database
137
+ - name: Run tests
138
+ run: bundle exec rake spec
139
+ - name: Shutdown database
140
+ if: always() && (matrix.db == 'postgresql' || matrix.db == 'mysql2')
141
+ run: docker stop database
142
+ - name: Coveralls Parallel
143
+ if: "${{ !env.ACT }}"
144
+ uses: coverallsapp/github-action@master
145
+ with:
146
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
147
+ flag-name: run-${{ matrix.ruby }}-${{ matrix.activerecord }}-${{ matrix.db }}-${{ matrix.dbversion }}
148
+ parallel: true
149
+ finish:
150
+ needs: test
151
+ runs-on: ubuntu-latest
152
+ steps:
153
+ - name: Coveralls Finished
154
+ if: "${{ !env.ACT }}"
155
+ uses: coverallsapp/github-action@master
156
+ with:
157
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
158
+ parallel-finished: true
data/.gitignore CHANGED
@@ -2,6 +2,7 @@
2
2
  /tmp
3
3
  /pkg
4
4
  /Gemfile.local
5
+ /.idea
5
6
 
6
7
  .byebug_history
7
8
  *.lock
data/.simplecov ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ SimpleCov.configure do
4
+ enable_coverage :branch
5
+ add_filter '/spec/'
6
+
7
+ add_group 'Binaries', '/bin/'
8
+ add_group 'Libraries', '/lib/'
9
+
10
+ if ENV['CI']
11
+ require 'simplecov-lcov'
12
+
13
+ SimpleCov::Formatter::LcovFormatter.config do |c|
14
+ c.report_with_single_file = true
15
+ c.single_report_path = 'coverage/lcov.info'
16
+ end
17
+
18
+ formatter SimpleCov::Formatter::LcovFormatter
19
+ end
20
+ end
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/schema_plus_default_expr.svg)](http://badge.fury.io/rb/schema_plus_default_expr)
2
- [![Build Status](https://secure.travis-ci.org/SchemaPlus/schema_plus_default_expr.svg)](http://travis-ci.org/SchemaPlus/schema_plus_default_expr)
3
- [![Coverage Status](https://img.shields.io/coveralls/SchemaPlus/schema_plus_default_expr.svg)](https://coveralls.io/r/SchemaPlus/schema_plus_default_expr)
4
- [![Dependency Status](https://gemnasium.com/lomba/schema_plus_default_expr.svg)](https://gemnasium.com/SchemaPlus/schema_plus_default_expr)
2
+ [![Build Status](https://github.com/SchemaPlus/schema_plus_default_expr/actions/workflows/prs.yml/badge.svg)](https://github.com/SchemaPlus/schema_plus_default_expr/actions)
3
+ [![Coverage Status](https://coveralls.io/repos/github/SchemaPlus/schema_plus_default_expr/badge.svg?branch=master)](https://coveralls.io/github/SchemaPlus/schema_plus_default_expr?branch=master)
5
4
 
6
5
  # SchemaPlus::DefaultExpr
7
6
 
@@ -30,7 +29,19 @@ SchemaPlus::DefaultExpr is tested on:
30
29
 
31
30
  <!-- SCHEMA_DEV: MATRIX - begin -->
32
31
  <!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
33
- * ruby **2.1.5** with activerecord **4.2**, using **sqlite3** and **postgresql**
32
+ * ruby **2.5** with activerecord **5.2**, using **sqlite3** and **postgresql:9.6**
33
+ * ruby **2.5** with activerecord **6.0**, using **sqlite3** and **postgresql:9.6**
34
+ * ruby **2.5** with activerecord **6.1**, using **sqlite3** and **postgresql:9.6**
35
+ * ruby **2.7** with activerecord **5.2**, using **sqlite3** and **postgresql:9.6**
36
+ * ruby **2.7** with activerecord **6.0**, using **sqlite3** and **postgresql:9.6**
37
+ * ruby **2.7** with activerecord **6.1**, using **sqlite3** and **postgresql:9.6**
38
+ * ruby **2.7** with activerecord **7.0**, using **sqlite3** and **postgresql:9.6**
39
+ * ruby **3.0** with activerecord **6.0**, using **sqlite3** and **postgresql:9.6**
40
+ * ruby **3.0** with activerecord **6.1**, using **sqlite3** and **postgresql:9.6**
41
+ * ruby **3.0** with activerecord **7.0**, using **sqlite3** and **postgresql:9.6**
42
+ * ruby **3.1** with activerecord **6.0**, using **sqlite3** and **postgresql:9.6**
43
+ * ruby **3.1** with activerecord **6.1**, using **sqlite3** and **postgresql:9.6**
44
+ * ruby **3.1** with activerecord **7.0**, using **sqlite3** and **postgresql:9.6**
34
45
 
35
46
  <!-- SCHEMA_DEV: MATRIX - end -->
36
47
 
@@ -40,16 +51,22 @@ MySQL only supports SQL expression defaults for `TIMESTAMP` column types, which
40
51
 
41
52
  SchemaPlus::DefaultExpr augments the syntax for setting column defaults, to support expressions or constant values:
42
53
 
43
- t.datetime :seen_at, default: { expr: 'NOW()' }
44
- t.datetime :seen_at, default: { value: "2011-12-11 00:00:00" }
54
+ ```ruby
55
+ t.datetime :seen_at, default: { expr: 'NOW()' }
56
+ t.datetime :seen_at, default: { value: "2011-12-11 00:00:00" }
57
+ ```
45
58
 
46
59
  The standard syntax will still work as usual:
47
60
 
48
- t.datetime :seen_at, default: "2011-12-11 00:00:00"
61
+ ```ruby
62
+ t.datetime :seen_at, default: "2011-12-11 00:00:00"
63
+ ```
49
64
 
50
65
  Also, as a convenience
51
66
 
52
- t.datetime :seen_at, default: :now
67
+ ```ruby
68
+ t.datetime :seen_at, default: :now
69
+ ```
53
70
 
54
71
  resolves to:
55
72
 
@@ -61,17 +78,21 @@ resolves to:
61
78
 
62
79
  If you are using Postgresql with a `json` column, ActiveRecord allows you to use a Hash for a default value. Be aware that if the hash contains just one key which is `:expr` or `:value`, then SchemaPlus::DefaultExpr will interpret, and use the corresponding value for the default. That is, these are equivalent:
63
80
 
64
- t.json :fields, default: { value: { field1: 'a', field2: 'b' } }
65
- t.json :fields, default: { field1: 'a', field2: 'b' }
66
-
81
+ ```ruby
82
+ t.json :fields, default: { value: { field1: 'a', field2: 'b' } }
83
+ t.json :fields, default: { field1: 'a', field2: 'b' }
84
+ ```
67
85
 
68
86
  ## History
69
87
 
70
- * 0.1.4 - Compatibility with AR 5. Thanks to [@pedantic-git](https://github.com/pedantic-git)
71
- * 0.1.3 - Missing require
72
- * 0.1.2 - Explicit gem dependencies
73
- * 0.1.1 - Fix dumping bug (#1); upgrade to schema_plus_core 1.0
74
- * 0.1.0 - Initial release, extracted from schema_plus 1.x
88
+ * **1.0.1** - Add AR 6.1, 7.0 and Ruby 3.1
89
+ * **1.0.0** - Add AR 6.0, Ruby 3.0 and dropped AR < 5.2 and Ruby < 5.2
90
+ * **0.1.5** - Compatibility with AR 5.2.
91
+ * **0.1.4** - Compatibility with AR 5. Thanks to [@pedantic-git](https://github.com/pedantic-git)
92
+ * **0.1.3** - Missing require
93
+ * **0.1.2** - Explicit gem dependencies
94
+ * **0.1.1** - Fix dumping bug (#1); upgrade to schema_plus_core 1.0
95
+ * **0.1.0** - Initial release, extracted from schema_plus 1.x
75
96
 
76
97
  ## Development & Testing
77
98
 
@@ -86,7 +107,7 @@ Some things to know about to help you develop and test:
86
107
  * **schema_dev**: SchemaPlus::DefaultExpr uses [schema_dev](https://github.com/SchemaPlus/schema_dev) to
87
108
  facilitate running rspec tests on the matrix of ruby, activerecord, and database
88
109
  versions that the gem supports, both locally and on
89
- [travis-ci](http://travis-ci.org/SchemaPlus/schema_plus_default_expr)
110
+ [github actions](https://github.com/SchemaPlus/schema_plus_default_expr/actions)
90
111
 
91
112
  To to run rspec locally on the full matrix, do:
92
113
 
@@ -98,7 +119,6 @@ Some things to know about to help you develop and test:
98
119
  The matrix of configurations is specified in `schema_dev.yml` in
99
120
  the project root.
100
121
 
101
-
102
122
  <!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_DEV - end -->
103
123
 
104
124
  <!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_PLUS_CORE - begin -->
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
- gemspec :path => File.expand_path('..', __FILE__)
2
+ gemspec path: File.expand_path('..', __FILE__)
3
3
 
4
4
  File.exist?(gemfile_local = File.expand_path('../Gemfile.local', __FILE__)) and eval File.read(gemfile_local), binding, gemfile_local
@@ -0,0 +1,4 @@
1
+ base_gemfile = File.expand_path('../../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile)
3
+
4
+ gem "activerecord", ">= 5.2.0.beta0", "< 5.3"
@@ -0,0 +1,10 @@
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
+
4
+ platform :ruby do
5
+ gem "pg"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcpostgresql-adapter'
10
+ end
@@ -1,5 +1,5 @@
1
- require "pathname"
2
- eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
3
 
4
4
  platform :ruby do
5
5
  gem "sqlite3"
@@ -7,4 +7,4 @@ end
7
7
 
8
8
  platform :jruby do
9
9
  gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
10
- end
10
+ end
@@ -0,0 +1,4 @@
1
+ base_gemfile = File.expand_path('../../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile)
3
+
4
+ gem "activerecord", ">= 6.0", "< 6.1"
@@ -0,0 +1,10 @@
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
+
4
+ platform :ruby do
5
+ gem "pg"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcpostgresql-adapter'
10
+ end
@@ -0,0 +1,10 @@
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
+
4
+ platform :ruby do
5
+ gem "sqlite3"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
10
+ end
@@ -0,0 +1,4 @@
1
+ base_gemfile = File.expand_path('../../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile)
3
+
4
+ gem "activerecord", ">= 6.1", "< 6.2"
@@ -0,0 +1,10 @@
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
+
4
+ platform :ruby do
5
+ gem "pg"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcpostgresql-adapter'
10
+ end
@@ -0,0 +1,10 @@
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
+
4
+ platform :ruby do
5
+ gem "sqlite3"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
10
+ end
@@ -0,0 +1,4 @@
1
+ base_gemfile = File.expand_path('../../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile)
3
+
4
+ gem "activerecord", ">= 7.0", "< 7.1"
@@ -0,0 +1,10 @@
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
+
4
+ platform :ruby do
5
+ gem "pg"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcpostgresql-adapter'
10
+ end
@@ -0,0 +1,10 @@
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
+
4
+ platform :ruby do
5
+ gem "sqlite3"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
10
+ end
@@ -41,7 +41,7 @@ module SchemaPlus::DefaultExpr
41
41
  def after(env)
42
42
  env.connection.columns(env.table.name).each do |column|
43
43
  if !column.default_function.nil?
44
- if col = env.table.columns.find(&its.name == column.name)
44
+ if col = env.table.columns.find { |it| it.name == column.name }
45
45
  col.options[:default] = { expr: column.default_function }
46
46
  end
47
47
  end
@@ -1,5 +1,5 @@
1
1
  module SchemaPlus
2
2
  module DefaultExpr
3
- VERSION = "0.1.4"
3
+ VERSION = '1.0.1'
4
4
  end
5
5
  end
@@ -1,5 +1,4 @@
1
1
  require 'schema_plus/core'
2
- require 'its-it'
3
2
 
4
3
  require_relative 'default_expr/version'
5
4
  require_relative 'default_expr/middleware'
data/schema_dev.yml CHANGED
@@ -1,7 +1,13 @@
1
1
  ruby:
2
- - 2.1.5
2
+ - 2.5
3
+ - 2.7
4
+ - 3.0
5
+ - 3.1
3
6
  activerecord:
4
- - 4.2
7
+ - 5.2
8
+ - 6.0
9
+ - 6.1
10
+ - 7.0
5
11
  db:
6
12
  - sqlite3
7
13
  - postgresql
@@ -17,14 +17,13 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency "activerecord", ">= 4.2", "< 6.0"
21
- gem.add_dependency "schema_plus_core", ">= 1.0", "< 3.0"
22
- gem.add_dependency "its-it", "~> 1.2"
20
+ gem.required_ruby_version = ">= 2.5.0"
23
21
 
24
- gem.add_development_dependency "bundler", "~> 1.7"
25
- gem.add_development_dependency "rake", "~> 10.0"
22
+ gem.add_dependency "activerecord", ">= 5.2", "< 7.1"
23
+ gem.add_dependency "schema_plus_core", '~> 3.1.0'
24
+
25
+ gem.add_development_dependency "bundler"
26
+ gem.add_development_dependency "rake", "~> 13.0"
26
27
  gem.add_development_dependency "rspec", "~> 3.0"
27
- gem.add_development_dependency "schema_dev", "~> 3.6"
28
- gem.add_development_dependency "simplecov"
29
- gem.add_development_dependency "simplecov-gem-profile"
28
+ gem.add_development_dependency "schema_dev", "~> 4.2.0"
30
29
  end
@@ -2,11 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  describe "Column definition" do
4
4
  before(:each) do
5
- define_schema do
5
+ apply_migration do
6
6
  create_table :models, :force => true do |t|
7
7
  end
8
8
  end
9
- class Model < ::ActiveRecord::Base ; end
9
+ stub_model('Model')
10
10
  end
11
11
 
12
12
  subject {
@@ -114,10 +114,10 @@ describe "Column definition" do
114
114
 
115
115
  private
116
116
 
117
- def define_test_column(type, *args)
118
- ActiveRecord::Migration.suppress_messages do
119
- ActiveRecord::Migration.create_table Model.table_name, :force => true do |t|
120
- t.send type, :test_column, *args
117
+ def define_test_column(type, **options)
118
+ apply_migration do
119
+ create_table Model.table_name, :force => true do |t|
120
+ t.send type, :test_column, **options
121
121
  t.integer :dummy
122
122
  end
123
123
  end
@@ -3,41 +3,37 @@ require 'spec_helper'
3
3
  describe ActiveRecord::Migration do
4
4
 
5
5
  before(:each) do
6
- define_schema do
6
+ apply_migration do
7
7
  create_table :posts, :force => true do |t|
8
8
  t.string :content
9
9
  end
10
10
  end
11
- class Post < ::ActiveRecord::Base ; end
12
11
  end
13
12
 
14
13
  context "when table is created" do
15
-
16
- before(:each) do
17
- @model = Post
18
- end
14
+ let(:model) { stub_model('Post') }
19
15
 
20
16
  it "should properly handle default values for booleans" do
21
17
  expect {
22
- recreate_table(@model) do |t|
18
+ recreate_table(model) do |t|
23
19
  t.boolean :bool, :default => true
24
20
  end
25
21
  }.to_not raise_error
26
- expect(@model.create.reload.bool).to be true
22
+ expect(model.create.reload.bool).to be true
27
23
  end
28
24
 
29
25
  it "should properly handle default values for json (#195)", :postgresql => :only do
30
- recreate_table(@model) do |t|
26
+ recreate_table(model) do |t|
31
27
  t.json :json, :default => {}
32
28
  end
33
- expect(@model.create.reload.json).to eq({})
29
+ expect(model.create.reload.json).to eq({})
34
30
  end
35
31
 
36
32
  end
37
33
 
38
34
  def recreate_table(model, opts={}, &block)
39
- ActiveRecord::Migration.suppress_messages do
40
- ActiveRecord::Migration.create_table model.table_name, opts.merge(:force => true), &block
35
+ apply_migration do
36
+ create_table model.table_name, **opts.merge(:force => true), &block
41
37
  end
42
38
  model.reset_column_information
43
39
  end
@@ -2,93 +2,92 @@ require 'spec_helper'
2
2
  require 'stringio'
3
3
 
4
4
  describe "Schema dump" do
5
+ let(:model) { stub_model('Post') }
5
6
 
6
- before(:all) do
7
- ActiveRecord::Migration.suppress_messages do
8
- ActiveRecord::Schema.define do
9
- connection.tables.each do |table| drop_table table, force: :cascade end
10
-
7
+ context "with date default", :postgresql => :only do
8
+ before do
9
+ apply_migration do
11
10
  create_table :posts, :force => true do |t|
12
- t.text :body
13
- t.integer :user_id
14
- t.integer :first_comment_id
15
- t.string :string_no_default
16
- t.integer :short_id
17
- t.string :str_short
18
- t.integer :integer_col
19
- t.float :float_col
20
- t.decimal :decimal_col
21
- t.datetime :datetime_col
22
- t.timestamp :timestamp_col
23
- t.time :time_col
24
- t.date :date_col
25
- t.binary :binary_col
26
- t.boolean :boolean_col
27
11
  end
28
-
29
12
  end
30
13
  end
31
- class ::Post < ActiveRecord::Base ; end
32
- end
33
14
 
34
- context "with date default", :postgresql => :only do
35
15
  it "should dump the default hash expr as now()" do
36
- with_additional_column Post, :posted_at, :datetime, :default => :now do
16
+ with_additional_column model, :posted_at, :datetime, :default => :now do
37
17
  expect(dump_posts).to match(%r{t\.datetime\s+"posted_at",\s*(?:default:|:default\s*=>)\s*\{\s*(?:expr:|:expr\s*=>)\s*"now\(\)"\s*\}\s*$})
38
18
  end
39
19
  end
40
20
 
41
21
  it "should dump the default hash expr as CURRENT_TIMESTAMP" do
42
- with_additional_column Post, :posted_at, :datetime, :default => {:expr => 'date \'2001-09-28\''} do
22
+ with_additional_column model, :posted_at, :datetime, :default => { :expr => 'date \'2001-09-28\'' } do
43
23
  expect(dump_posts).to match(%r{t\.datetime\s+"posted_at",\s*(?:default:|:default\s*=>).*2001-09-28.*})
44
24
  end
45
25
  end
26
+ end
27
+
28
+ context 'with a complex expression', postgresql: :only do
29
+ before do
30
+ apply_migration do
31
+ create_table :posts, :force => true do |t|
32
+ end
33
+ end
34
+ end
46
35
 
47
36
  it "can dump a complex default expression" do
48
- with_additional_column Post, :name, :string, :default => {:expr => 'substring(random()::text from 3 for 6)'} do
37
+ with_additional_column model, :name, :string, :default => { :expr => 'substring(random()::text from 3 for 6)' } do
49
38
  expect(dump_posts).to match(%r{t\.string\s+"name",\s*(?:default:|:default\s*=>)\s*{\s*(?:expr:|:expr\s*=>)\s*"\\"substring\\"\(\(random\(\)\)::text, 3, 6\)"\s*}})
50
39
  end
51
40
  end
52
41
  end
53
42
 
54
43
  context "with date default", :sqlite3 => :only do
44
+ before do
45
+ apply_migration do
46
+ create_table :posts, :force => true do |t|
47
+ end
48
+ end
49
+ end
50
+
55
51
  it "should dump the default hash expr as now" do
56
- with_additional_column Post, :posted_at, :datetime, :default => :now do
57
- expect(dump_posts).to match(%r{t\.datetime\s+"posted_at",\s*(default:|:default\s*=>)\s*\{\s*(?:expr:|:expr\s*=>)\s*"\(DATETIME\('now'\)\)"\s*\}})
52
+ with_additional_column model, :posted_at, :datetime, :default => :now do
53
+ expect(dump_posts).to match(%r{t\.datetime\s+"posted_at",\s*(default:|:default\s*=>)\s*\{\s*(?:expr:|:expr\s*=>)\s*"\(?DATETIME\('now'\)\)?"\s*\}})
58
54
  end
59
55
  end
60
56
 
61
57
  it "should dump the default hash expr string as now" do
62
- with_additional_column Post, :posted_at, :datetime, :default => { :expr => "(DATETIME('now'))" } do
63
- expect(dump_posts).to match(%r{t\.datetime\s+"posted_at",\s*(default:|:default\s*=>)\s*\{\s*(?:expr:|:expr\s*=>)\s*"\(DATETIME\('now'\)\)"\s*\}})
58
+ with_additional_column model, :posted_at, :datetime, :default => { :expr => "(DATETIME('now'))" } do
59
+ expect(dump_posts).to match(%r{t\.datetime\s+"posted_at",\s*(default:|:default\s*=>)\s*\{\s*(?:expr:|:expr\s*=>)\s*"\(?DATETIME\('now'\)\)?"\s*\}})
64
60
  end
65
61
  end
66
62
 
67
63
  it "should dump the default value normally" do
68
- with_additional_column Post, :posted_at, :string, :default => "now" do
64
+ with_additional_column model, :posted_at, :string, :default => "now" do
69
65
  expect(dump_posts).to match(%r{t\.string\s*"posted_at",\s*(?:default:|:default\s*=>)\s*"now"})
70
66
  end
71
67
  end
72
68
  end
73
69
 
74
70
  it "should leave out :default when default was changed to null" do
75
- ActiveRecord::Migration.suppress_messages do
76
- ActiveRecord::Migration.change_column_default :posts, :string_no_default, nil
71
+ apply_migration do
72
+ create_table :posts, :force => true do |t|
73
+ t.datetime :date_column, default: { expr: :now }
74
+ end
75
+
76
+ change_column_default :posts, :date_column, nil
77
77
  end
78
- # mysql2 includes 'limit: 255' in the output. that's OK, just want to
79
- # make sure the full line doesn't have 'default' in it.
80
- expect(dump_posts).to match(%r{t\.string\s+"string_no_default"\s*(,\s*limit:\s*\d+)?$})
78
+ expect(dump_posts).to match(%r{t\.datetime\s+"date_column"$})
81
79
  end
82
80
 
83
81
  protected
82
+
84
83
  def to_regexp(string)
85
84
  Regexp.new(Regexp.escape(string))
86
85
  end
87
86
 
88
87
  def with_additional_column(model, column_name, column_type, options)
89
- table_columns = model.columns.reject{|column| column.name == 'id'}
90
- ActiveRecord::Migration.suppress_messages do
91
- ActiveRecord::Migration.create_table model.table_name, :force => true do |t|
88
+ table_columns = model.columns.reject { |column| column.name == 'id' }
89
+ apply_migration do
90
+ create_table model.table_name, :force => true do |t|
92
91
  table_columns.each do |column|
93
92
  t.column column.name, column.type, :default => column.default
94
93
  end
@@ -98,8 +97,8 @@ describe "Schema dump" do
98
97
  yield
99
98
  end
100
99
 
101
- def dump_schema(opts={})
102
- stream = StringIO.new
100
+ def dump_schema(opts = {})
101
+ stream = StringIO.new
103
102
  ActiveRecord::SchemaDumper.ignore_tables = Array.wrap(opts[:ignore]) || []
104
103
  ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
105
104
  stream.string
@@ -110,4 +109,3 @@ describe "Schema dump" do
110
109
  end
111
110
 
112
111
  end
113
-
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'simplecov'
2
- require 'simplecov-gem-profile'
3
- SimpleCov.start "gem"
2
+ SimpleCov.start unless SimpleCov.running
4
3
 
5
4
  $LOAD_PATH.unshift(File.dirname(__FILE__))
6
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
@@ -16,18 +15,36 @@ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
16
15
 
17
16
  RSpec.configure do |config|
18
17
  config.warnings = true
18
+
19
+ config.around do |example|
20
+ begin
21
+ example.run
22
+ ensure
23
+ apply_migration do
24
+ ActiveRecord::Base.connection.tables.each do |table|
25
+ drop_table table, force: :cascade
26
+ end
27
+ end
28
+ end
29
+ end
19
30
  end
20
31
 
21
- def define_schema(&block)
32
+ def stub_model(name, base = ActiveRecord::Base, &block)
33
+ klass = Class.new(base)
34
+
35
+ if block_given?
36
+ klass.instance_eval(&block)
37
+ end
38
+
39
+ stub_const(name, klass)
40
+ end
41
+
42
+ def apply_migration(&block)
22
43
  ActiveRecord::Migration.suppress_messages do
23
44
  ActiveRecord::Schema.define do
24
- connection.tables.each do |table|
25
- drop_table table, force: :cascade
26
- end
27
45
  instance_eval &block
28
46
  end
29
47
  end
30
48
  end
31
49
 
32
-
33
50
  SimpleCov.command_name "[ruby#{RUBY_VERSION}-activerecord#{::ActiveRecord.version}-#{ActiveRecord::Base.connection.adapter_name}]"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_plus_default_expr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ronen barzel
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-28 00:00:00.000000000 Z
11
+ date: 2022-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,82 +16,62 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '5.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6.0'
22
+ version: '7.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '4.2'
29
+ version: '5.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6.0'
32
+ version: '7.1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: schema_plus_core
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: '1.0'
40
- - - "<"
41
- - !ruby/object:Gem::Version
42
- version: '3.0'
43
- type: :runtime
44
- prerelease: false
45
- version_requirements: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: '1.0'
50
- - - "<"
51
- - !ruby/object:Gem::Version
52
- version: '3.0'
53
- - !ruby/object:Gem::Dependency
54
- name: its-it
55
35
  requirement: !ruby/object:Gem::Requirement
56
36
  requirements:
57
37
  - - "~>"
58
38
  - !ruby/object:Gem::Version
59
- version: '1.2'
39
+ version: 3.1.0
60
40
  type: :runtime
61
41
  prerelease: false
62
42
  version_requirements: !ruby/object:Gem::Requirement
63
43
  requirements:
64
44
  - - "~>"
65
45
  - !ruby/object:Gem::Version
66
- version: '1.2'
46
+ version: 3.1.0
67
47
  - !ruby/object:Gem::Dependency
68
48
  name: bundler
69
49
  requirement: !ruby/object:Gem::Requirement
70
50
  requirements:
71
- - - "~>"
51
+ - - ">="
72
52
  - !ruby/object:Gem::Version
73
- version: '1.7'
53
+ version: '0'
74
54
  type: :development
75
55
  prerelease: false
76
56
  version_requirements: !ruby/object:Gem::Requirement
77
57
  requirements:
78
- - - "~>"
58
+ - - ">="
79
59
  - !ruby/object:Gem::Version
80
- version: '1.7'
60
+ version: '0'
81
61
  - !ruby/object:Gem::Dependency
82
62
  name: rake
83
63
  requirement: !ruby/object:Gem::Requirement
84
64
  requirements:
85
65
  - - "~>"
86
66
  - !ruby/object:Gem::Version
87
- version: '10.0'
67
+ version: '13.0'
88
68
  type: :development
89
69
  prerelease: false
90
70
  version_requirements: !ruby/object:Gem::Requirement
91
71
  requirements:
92
72
  - - "~>"
93
73
  - !ruby/object:Gem::Version
94
- version: '10.0'
74
+ version: '13.0'
95
75
  - !ruby/object:Gem::Dependency
96
76
  name: rspec
97
77
  requirement: !ruby/object:Gem::Requirement
@@ -112,59 +92,41 @@ dependencies:
112
92
  requirements:
113
93
  - - "~>"
114
94
  - !ruby/object:Gem::Version
115
- version: '3.6'
95
+ version: 4.2.0
116
96
  type: :development
117
97
  prerelease: false
118
98
  version_requirements: !ruby/object:Gem::Requirement
119
99
  requirements:
120
100
  - - "~>"
121
101
  - !ruby/object:Gem::Version
122
- version: '3.6'
123
- - !ruby/object:Gem::Dependency
124
- name: simplecov
125
- requirement: !ruby/object:Gem::Requirement
126
- requirements:
127
- - - ">="
128
- - !ruby/object:Gem::Version
129
- version: '0'
130
- type: :development
131
- prerelease: false
132
- version_requirements: !ruby/object:Gem::Requirement
133
- requirements:
134
- - - ">="
135
- - !ruby/object:Gem::Version
136
- version: '0'
137
- - !ruby/object:Gem::Dependency
138
- name: simplecov-gem-profile
139
- requirement: !ruby/object:Gem::Requirement
140
- requirements:
141
- - - ">="
142
- - !ruby/object:Gem::Version
143
- version: '0'
144
- type: :development
145
- prerelease: false
146
- version_requirements: !ruby/object:Gem::Requirement
147
- requirements:
148
- - - ">="
149
- - !ruby/object:Gem::Version
150
- version: '0'
151
- description:
102
+ version: 4.2.0
103
+ description:
152
104
  email:
153
105
  - ronen@barzel.org
154
106
  executables: []
155
107
  extensions: []
156
108
  extra_rdoc_files: []
157
109
  files:
110
+ - ".github/workflows/prs.yml"
158
111
  - ".gitignore"
159
- - ".travis.yml"
112
+ - ".simplecov"
160
113
  - Gemfile
161
114
  - LICENSE.txt
162
115
  - README.md
163
116
  - Rakefile
164
117
  - gemfiles/Gemfile.base
165
- - gemfiles/activerecord-4.2/Gemfile.base
166
- - gemfiles/activerecord-4.2/Gemfile.postgresql
167
- - gemfiles/activerecord-4.2/Gemfile.sqlite3
118
+ - gemfiles/activerecord-5.2/Gemfile.base
119
+ - gemfiles/activerecord-5.2/Gemfile.postgresql
120
+ - gemfiles/activerecord-5.2/Gemfile.sqlite3
121
+ - gemfiles/activerecord-6.0/Gemfile.base
122
+ - gemfiles/activerecord-6.0/Gemfile.postgresql
123
+ - gemfiles/activerecord-6.0/Gemfile.sqlite3
124
+ - gemfiles/activerecord-6.1/Gemfile.base
125
+ - gemfiles/activerecord-6.1/Gemfile.postgresql
126
+ - gemfiles/activerecord-6.1/Gemfile.sqlite3
127
+ - gemfiles/activerecord-7.0/Gemfile.base
128
+ - gemfiles/activerecord-7.0/Gemfile.postgresql
129
+ - gemfiles/activerecord-7.0/Gemfile.sqlite3
168
130
  - lib/schema_plus/default_expr.rb
169
131
  - lib/schema_plus/default_expr/active_record/connection_adapters/abstract_adapter.rb
170
132
  - lib/schema_plus/default_expr/active_record/connection_adapters/column.rb
@@ -183,7 +145,7 @@ homepage: https://github.com/SchemaPlus/schema_plus_default_expr
183
145
  licenses:
184
146
  - MIT
185
147
  metadata: {}
186
- post_install_message:
148
+ post_install_message:
187
149
  rdoc_options: []
188
150
  require_paths:
189
151
  - lib
@@ -191,16 +153,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
191
153
  requirements:
192
154
  - - ">="
193
155
  - !ruby/object:Gem::Version
194
- version: '0'
156
+ version: 2.5.0
195
157
  required_rubygems_version: !ruby/object:Gem::Requirement
196
158
  requirements:
197
159
  - - ">="
198
160
  - !ruby/object:Gem::Version
199
161
  version: '0'
200
162
  requirements: []
201
- rubyforge_project:
202
- rubygems_version: 2.5.1
203
- signing_key:
163
+ rubygems_version: 3.1.6
164
+ signing_key:
204
165
  specification_version: 4
205
166
  summary: Extends ActiveRecord migrations to allow an SQL expression for the default
206
167
  value of a column
data/.travis.yml DELETED
@@ -1,17 +0,0 @@
1
- # This file was auto-generated by the schema_dev tool, based on the data in
2
- # ./schema_dev.yml
3
- # Please do not edit this file; any changes will be overwritten next time
4
- # schema_dev gets run.
5
- ---
6
- sudo: false
7
- rvm:
8
- - 2.1.5
9
- gemfile:
10
- - gemfiles/activerecord-4.2/Gemfile.postgresql
11
- - gemfiles/activerecord-4.2/Gemfile.sqlite3
12
- env: POSTGRESQL_DB_USER=postgres
13
- addons:
14
- postgresql: '9.4'
15
- before_script: bundle exec rake create_databases
16
- after_script: bundle exec rake drop_databases
17
- script: bundle exec rake travis
@@ -1,3 +0,0 @@
1
- eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
-
3
- gem "activerecord", "~> 4.2.6"
@@ -1,10 +0,0 @@
1
- require "pathname"
2
- eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
-
4
- platform :ruby do
5
- gem "pg"
6
- end
7
-
8
- platform :jruby do
9
- gem 'activerecord-jdbcpostgresql-adapter'
10
- end