torque-postgresql 2.2.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/torque/postgresql/adapter/database_statements.rb +12 -1
- data/lib/torque/postgresql/adapter/oid/enum_set.rb +1 -1
- data/lib/torque/postgresql/adapter/oid.rb +0 -3
- data/lib/torque/postgresql/adapter/quoting.rb +14 -19
- data/lib/torque/postgresql/adapter/schema_creation.rb +1 -2
- data/lib/torque/postgresql/adapter/schema_definitions.rb +0 -37
- data/lib/torque/postgresql/adapter/schema_dumper.rb +0 -40
- data/lib/torque/postgresql/adapter/schema_statements.rb +0 -15
- data/lib/torque/postgresql/adapter.rb +0 -9
- data/lib/torque/postgresql/associations/belongs_to_many_association.rb +5 -3
- data/lib/torque/postgresql/associations/{association.rb → foreign_association.rb} +1 -4
- data/lib/torque/postgresql/associations/preloader/association.rb +53 -26
- data/lib/torque/postgresql/associations/preloader/loader_query.rb +36 -0
- data/lib/torque/postgresql/associations/preloader.rb +1 -0
- data/lib/torque/postgresql/associations.rb +6 -1
- data/lib/torque/postgresql/attributes/builder/period.rb +6 -2
- data/lib/torque/postgresql/config.rb +2 -11
- data/lib/torque/postgresql/reflection/abstract_reflection.rb +5 -7
- data/lib/torque/postgresql/relation.rb +10 -12
- data/lib/torque/postgresql/schema_cache.rb +2 -1
- data/lib/torque/postgresql/version.rb +1 -1
- data/lib/torque-postgresql.rb +0 -1
- data/spec/models/question_select.rb +2 -0
- data/spec/schema.rb +147 -147
- data/spec/spec_helper.rb +7 -6
- data/spec/tests/arel_spec.rb +29 -7
- data/spec/tests/belongs_to_many_spec.rb +14 -0
- data/spec/tests/enum_set_spec.rb +7 -5
- data/spec/tests/enum_spec.rb +1 -84
- data/spec/tests/interval_spec.rb +2 -1
- metadata +49 -57
- data/lib/torque/range.rb +0 -20
- data/spec/tests/range_spec.rb +0 -36
data/spec/schema.rb
CHANGED
@@ -10,151 +10,151 @@
|
|
10
10
|
#
|
11
11
|
# It's strongly recommended that you check this file into your version control system.
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
end
|
159
|
-
rescue SystemExit
|
13
|
+
version = 2
|
14
|
+
|
15
|
+
return if ActiveRecord::Migrator.current_version == version
|
16
|
+
ActiveRecord::Schema.define(version: version) do
|
17
|
+
self.verbose = false
|
18
|
+
|
19
|
+
# These are extensions that must be enabled in order to support this database
|
20
|
+
enable_extension "pgcrypto"
|
21
|
+
enable_extension "plpgsql"
|
22
|
+
|
23
|
+
# Custom types defined in this database.
|
24
|
+
# Note that some types may not work with other database engines. Be careful if changing database.
|
25
|
+
create_enum "content_status", ["created", "draft", "published", "archived"]
|
26
|
+
create_enum "specialties", ["books", "movies", "plays"]
|
27
|
+
create_enum "roles", ["visitor", "assistant", "manager", "admin"]
|
28
|
+
create_enum "conflicts", ["valid", "invalid", "untrusted"]
|
29
|
+
create_enum "types", ["A", "B", "C", "D"]
|
30
|
+
|
31
|
+
create_table "geometries", force: :cascade do |t|
|
32
|
+
t.point "point"
|
33
|
+
t.line "line"
|
34
|
+
t.lseg "lseg"
|
35
|
+
t.box "box"
|
36
|
+
t.path "closed_path"
|
37
|
+
t.path "open_path"
|
38
|
+
t.polygon "polygon"
|
39
|
+
t.circle "circle"
|
40
|
+
end
|
41
|
+
|
42
|
+
create_table "time_keepers", force: :cascade do |t|
|
43
|
+
t.daterange "available"
|
44
|
+
t.tsrange "period"
|
45
|
+
t.tstzrange "tzperiod"
|
46
|
+
t.interval "th"
|
47
|
+
end
|
48
|
+
|
49
|
+
create_table "tags", force: :cascade do |t|
|
50
|
+
t.string "name"
|
51
|
+
end
|
52
|
+
|
53
|
+
create_table "videos", force: :cascade do |t|
|
54
|
+
t.bigint "tag_ids", array: true
|
55
|
+
t.string "title"
|
56
|
+
t.string "url"
|
57
|
+
t.enum "type", enum_type: :types
|
58
|
+
t.enum "conflicts", enum_type: :conflicts, array: true
|
59
|
+
t.datetime "created_at", null: false
|
60
|
+
t.datetime "updated_at", null: false
|
61
|
+
end
|
62
|
+
|
63
|
+
create_table "authors", force: :cascade do |t|
|
64
|
+
t.string "name"
|
65
|
+
t.string "type"
|
66
|
+
t.enum "specialty", enum_type: :specialties
|
67
|
+
end
|
68
|
+
|
69
|
+
create_table "texts", force: :cascade do |t|
|
70
|
+
t.integer "user_id"
|
71
|
+
t.string "content"
|
72
|
+
t.enum "conflict", enum_type: :conflicts
|
73
|
+
end
|
74
|
+
|
75
|
+
create_table "comments", force: :cascade do |t|
|
76
|
+
t.integer "user_id", null: false
|
77
|
+
t.integer "comment_id"
|
78
|
+
t.integer "video_id"
|
79
|
+
t.text "content", null: false
|
80
|
+
t.string "kind"
|
81
|
+
t.index ["user_id"], name: "index_comments_on_user_id", using: :btree
|
82
|
+
t.index ["comment_id"], name: "index_comments_on_comment_id", using: :btree
|
83
|
+
end
|
84
|
+
|
85
|
+
create_table "courses", force: :cascade do |t|
|
86
|
+
t.string "title", null: false
|
87
|
+
t.interval "duration"
|
88
|
+
t.enum "types", enum_type: :types, array: true
|
89
|
+
t.datetime "created_at", null: false
|
90
|
+
t.datetime "updated_at", null: false
|
91
|
+
end
|
92
|
+
|
93
|
+
create_table "images", force: :cascade, id: false do |t|
|
94
|
+
t.string "file"
|
95
|
+
end
|
96
|
+
|
97
|
+
create_table "posts", force: :cascade do |t|
|
98
|
+
t.integer "author_id"
|
99
|
+
t.integer "activity_id"
|
100
|
+
t.string "title"
|
101
|
+
t.text "content"
|
102
|
+
t.enum "status", enum_type: :content_status
|
103
|
+
t.index ["author_id"], name: "index_posts_on_author_id", using: :btree
|
104
|
+
end
|
105
|
+
|
106
|
+
create_table "items", force: :cascade do |t|
|
107
|
+
t.string "name"
|
108
|
+
t.bigint "tag_ids", array: true, default: "{1}"
|
109
|
+
t.datetime "created_at", null: false
|
110
|
+
t.datetime "updated_at", null: false
|
111
|
+
end
|
112
|
+
|
113
|
+
create_table "users", force: :cascade do |t|
|
114
|
+
t.string "name", null: false
|
115
|
+
t.enum "role", enum_type: :roles, default: :visitor
|
116
|
+
t.datetime "created_at", null: false
|
117
|
+
t.datetime "updated_at", null: false
|
118
|
+
end
|
119
|
+
|
120
|
+
create_table "activities", force: :cascade do |t|
|
121
|
+
t.integer "author_id"
|
122
|
+
t.string "title"
|
123
|
+
t.boolean "active"
|
124
|
+
t.enum "kind", enum_type: :types
|
125
|
+
t.datetime "created_at", null: false
|
126
|
+
t.datetime "updated_at", null: false
|
127
|
+
end
|
128
|
+
|
129
|
+
create_table "questions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
130
|
+
t.string "title"
|
131
|
+
t.datetime "created_at", null: false
|
132
|
+
t.datetime "updated_at", null: false
|
133
|
+
end
|
134
|
+
|
135
|
+
create_table "activity_books", force: :cascade, inherits: :activities do |t|
|
136
|
+
t.text "description"
|
137
|
+
t.string "url"
|
138
|
+
t.boolean "activated"
|
139
|
+
end
|
140
|
+
|
141
|
+
create_table "activity_posts", force: :cascade, inherits: [:activities, :images] do |t|
|
142
|
+
t.integer "post_id"
|
143
|
+
t.string "url"
|
144
|
+
t.integer "activated"
|
145
|
+
end
|
146
|
+
|
147
|
+
create_table "activity_post_samples", force: :cascade, inherits: :activity_posts
|
148
|
+
|
149
|
+
create_table "question_selects", force: :cascade, inherits: :questions do |t|
|
150
|
+
t.string "options", array: true
|
151
|
+
end
|
152
|
+
|
153
|
+
# create_table "activity_blanks", force: :cascade, inherits: :activities
|
154
|
+
|
155
|
+
# create_table "activity_images", force: :cascade, inherits: [:activities, :images]
|
156
|
+
|
157
|
+
add_foreign_key "posts", "authors"
|
160
158
|
end
|
159
|
+
|
160
|
+
ActiveRecord::Base.connection.schema_cache.clear!
|
data/spec/spec_helper.rb
CHANGED
@@ -8,9 +8,13 @@ require 'byebug'
|
|
8
8
|
|
9
9
|
Dotenv.load
|
10
10
|
|
11
|
-
ActiveRecord::Base.establish_connection(ENV['DATABASE_URL']
|
12
|
-
|
11
|
+
ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'] || {
|
12
|
+
adapter: 'postgresql',
|
13
|
+
username: 'travis',
|
14
|
+
port: 5433,
|
15
|
+
})
|
13
16
|
|
17
|
+
cache = ActiveRecord::Base.connection.schema_cache
|
14
18
|
cleaner = ->() do
|
15
19
|
cache.instance_variable_set(:@inheritance_loaded, false)
|
16
20
|
cache.instance_variable_set(:@inheritance_dependencies, {})
|
@@ -27,6 +31,7 @@ I18n.load_path << Pathname.pwd.join('spec', 'en.yml')
|
|
27
31
|
RSpec.configure do |config|
|
28
32
|
config.extend Mocks::CreateTable
|
29
33
|
config.include Mocks::CacheQuery
|
34
|
+
config.include FactoryBot::Syntax::Methods
|
30
35
|
|
31
36
|
config.formatter = :documentation
|
32
37
|
config.color = true
|
@@ -41,10 +46,6 @@ RSpec.configure do |config|
|
|
41
46
|
DatabaseCleaner.strategy = :transaction
|
42
47
|
end
|
43
48
|
|
44
|
-
config.before(:each, js: true) do
|
45
|
-
DatabaseCleaner.strategy = :truncation
|
46
|
-
end
|
47
|
-
|
48
49
|
config.before(:each) do
|
49
50
|
DatabaseCleaner.start
|
50
51
|
end
|
data/spec/tests/arel_spec.rb
CHANGED
@@ -51,10 +51,14 @@ RSpec.describe 'Arel' do
|
|
51
51
|
context 'on default value' do
|
52
52
|
let(:connection) { ActiveRecord::Base.connection }
|
53
53
|
|
54
|
-
before(:context) { Torque::PostgreSQL.config.use_extended_defaults = true }
|
55
|
-
after(:context) { Torque::PostgreSQL.config.use_extended_defaults = false }
|
56
54
|
after { Author.reset_column_information }
|
57
55
|
|
56
|
+
it 'does not break the change column default value method' do
|
57
|
+
connection.add_column(:authors, :enabled, :boolean)
|
58
|
+
expect { connection.change_column_default(:authors, :enabled, { from: nil, to: true }) }.not_to raise_error
|
59
|
+
expect(Author.columns_hash['enabled'].default).to eq('true')
|
60
|
+
end
|
61
|
+
|
58
62
|
it 'does not break jsonb' do
|
59
63
|
expect { connection.add_column(:authors, :profile, :jsonb, default: []) }.not_to raise_error
|
60
64
|
expect(Author.columns_hash['profile'].default).to eq('[]')
|
@@ -62,19 +66,37 @@ RSpec.describe 'Arel' do
|
|
62
66
|
|
63
67
|
it 'works properly when column is an array' do
|
64
68
|
expect { connection.add_column(:authors, :tag_ids, :bigint, array: true, default: []) }.not_to raise_error
|
65
|
-
expect(Author.
|
69
|
+
expect(Author.new.tag_ids).to eq([])
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'works with an array with enum values for a new enum' do
|
73
|
+
value = ['a', 'b']
|
74
|
+
|
75
|
+
expect do
|
76
|
+
connection.create_enum(:samples, %i[a b c d])
|
77
|
+
connection.add_column(:authors, :samples, :enum, enum_type: :samples, array: true, default: value)
|
78
|
+
end.not_to raise_error
|
79
|
+
|
80
|
+
expect(Author.new.samples).to eq(value)
|
66
81
|
end
|
67
82
|
|
68
|
-
it 'works with an array with enum values' do
|
83
|
+
it 'works with an array with enum values for an existing enum' do
|
69
84
|
value = ['visitor', 'assistant']
|
70
|
-
expect { connection.add_column(:authors, :roles, :roles, array: true, default: value) }.not_to raise_error
|
71
|
-
expect(Author.
|
85
|
+
expect { connection.add_column(:authors, :roles, :enum, enum_type: :roles, array: true, default: value) }.not_to raise_error
|
86
|
+
expect(Author.new.roles).to eq(value)
|
72
87
|
end
|
73
88
|
|
74
89
|
it 'works with multi dimentional array' do
|
75
90
|
value = [['1', '2'], ['3', '4']]
|
76
91
|
expect { connection.add_column(:authors, :tag_ids, :string, array: true, default: value) }.not_to raise_error
|
77
|
-
expect(Author.
|
92
|
+
expect(Author.new.tag_ids).to eq(value)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'works with change column default value' do
|
96
|
+
value = ['2', '3']
|
97
|
+
connection.add_column(:authors, :tag_ids, :string, array: true)
|
98
|
+
expect { connection.change_column_default(:authors, :tag_ids, { from: nil, to: value }) }.not_to raise_error
|
99
|
+
expect(Author.new.tag_ids).to eq(value)
|
78
100
|
end
|
79
101
|
end
|
80
102
|
|
@@ -339,6 +339,20 @@ RSpec.describe 'BelongsToMany' do
|
|
339
339
|
expect(entries.first.tags.size).to be_eql(5)
|
340
340
|
end
|
341
341
|
|
342
|
+
it 'can preload records using ActiveRecord::Associations::Preloader' do
|
343
|
+
records = FactoryBot.create_list(:tag, 5)
|
344
|
+
subject.tags.concat(records)
|
345
|
+
|
346
|
+
entries = Video.all
|
347
|
+
arguments = { records: entries, associations: :tags, available_records: Tag.all.to_a }
|
348
|
+
ActiveRecord::Associations::Preloader.new(**arguments).call
|
349
|
+
entries = entries.load
|
350
|
+
|
351
|
+
expect(entries.size).to be_eql(1)
|
352
|
+
expect(entries.first.tags).to be_loaded
|
353
|
+
expect(entries.first.tags.size).to be_eql(5)
|
354
|
+
end
|
355
|
+
|
342
356
|
it 'can joins records' do
|
343
357
|
query = Video.all.joins(:tags)
|
344
358
|
expect(query.to_sql).to match(/INNER JOIN "tags"/)
|
data/spec/tests/enum_set_spec.rb
CHANGED
@@ -3,6 +3,7 @@ require 'spec_helper'
|
|
3
3
|
RSpec.describe 'Enum' do
|
4
4
|
let(:connection) { ActiveRecord::Base.connection }
|
5
5
|
let(:attribute_klass) { Torque::PostgreSQL::Attributes::EnumSet }
|
6
|
+
let(:table_definition) { ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition }
|
6
7
|
|
7
8
|
def decorate(model, field, options = {})
|
8
9
|
attribute_klass.include_on(model, :enum_set)
|
@@ -25,12 +26,13 @@ RSpec.describe 'Enum' do
|
|
25
26
|
end
|
26
27
|
|
27
28
|
context 'on table definition' do
|
28
|
-
subject {
|
29
|
+
subject { table_definition.new(connection, 'articles') }
|
29
30
|
|
30
31
|
it 'can be defined as an array' do
|
31
|
-
subject.enum(:content_status, array: true)
|
32
|
+
subject.enum(:content_status, array: true, enum_type: :content_status)
|
32
33
|
expect(subject['content_status'].name).to be_eql('content_status')
|
33
|
-
expect(subject['content_status'].type).to be_eql(:
|
34
|
+
expect(subject['content_status'].type).to be_eql(:enum)
|
35
|
+
expect(subject['content_status'].options[:enum_type]).to be_eql(:content_status)
|
34
36
|
|
35
37
|
array = subject['content_status'].respond_to?(:options) \
|
36
38
|
? subject['content_status'].options[:array] \
|
@@ -43,14 +45,14 @@ RSpec.describe 'Enum' do
|
|
43
45
|
context 'on schema' do
|
44
46
|
it 'can be used on tables' do
|
45
47
|
dump_io = StringIO.new
|
46
|
-
checker = /t\.enum +"conflicts", +array: true, +
|
48
|
+
checker = /t\.enum +"conflicts", +array: true, +enum_type: "conflicts"/
|
47
49
|
ActiveRecord::SchemaDumper.dump(connection, dump_io)
|
48
50
|
expect(dump_io.string).to match checker
|
49
51
|
end
|
50
52
|
|
51
53
|
xit 'can have a default value as an array of symbols' do
|
52
54
|
dump_io = StringIO.new
|
53
|
-
checker = /t\.enum +"types", +default: \[:A, :B\], +array: true, +
|
55
|
+
checker = /t\.enum +"types", +default: \[:A, :B\], +array: true, +enum_type: "types"/
|
54
56
|
ActiveRecord::SchemaDumper.dump(connection, dump_io)
|
55
57
|
expect(dump_io.string).to match checker
|
56
58
|
end
|
data/spec/tests/enum_spec.rb
CHANGED
@@ -3,6 +3,7 @@ require 'spec_helper'
|
|
3
3
|
RSpec.describe 'Enum' do
|
4
4
|
let(:connection) { ActiveRecord::Base.connection }
|
5
5
|
let(:attribute_klass) { Torque::PostgreSQL::Attributes::Enum }
|
6
|
+
let(:table_definition) { ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition }
|
6
7
|
|
7
8
|
def decorate(model, field, options = {})
|
8
9
|
attribute_klass.include_on(model, :pg_enum)
|
@@ -25,12 +26,6 @@ RSpec.describe 'Enum' do
|
|
25
26
|
end
|
26
27
|
|
27
28
|
context 'on migration' do
|
28
|
-
it 'can be created' do
|
29
|
-
connection.create_enum(:status, %i(foo bar))
|
30
|
-
expect(connection.type_exists?(:status)).to be_truthy
|
31
|
-
expect(connection.enum_values(:status)).to be_eql(['foo', 'bar'])
|
32
|
-
end
|
33
|
-
|
34
29
|
it 'can be deleted' do
|
35
30
|
connection.create_enum(:status, %i(foo bar))
|
36
31
|
expect(connection.type_exists?(:status)).to be_truthy
|
@@ -45,16 +40,6 @@ RSpec.describe 'Enum' do
|
|
45
40
|
expect(connection.type_exists?(:status)).to be_truthy
|
46
41
|
end
|
47
42
|
|
48
|
-
it 'can have prefix' do
|
49
|
-
connection.create_enum(:status, %i(foo bar), prefix: true)
|
50
|
-
expect(connection.enum_values(:status)).to be_eql(['status_foo', 'status_bar'])
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'can have suffix' do
|
54
|
-
connection.create_enum(:status, %i(foo bar), suffix: 'tst')
|
55
|
-
expect(connection.enum_values(:status)).to be_eql(['foo_tst', 'bar_tst'])
|
56
|
-
end
|
57
|
-
|
58
43
|
it 'inserts values at the end' do
|
59
44
|
connection.create_enum(:status, %i(foo bar))
|
60
45
|
connection.add_enum_values(:status, %i(baz qux))
|
@@ -84,74 +69,6 @@ RSpec.describe 'Enum' do
|
|
84
69
|
end
|
85
70
|
end
|
86
71
|
|
87
|
-
context 'on table definition' do
|
88
|
-
subject { ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition.new('articles') }
|
89
|
-
|
90
|
-
it 'has the enum method' do
|
91
|
-
expect(subject).to respond_to(:enum)
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'can be used in a single form' do
|
95
|
-
subject.enum('content_status')
|
96
|
-
expect(subject['content_status'].name).to be_eql('content_status')
|
97
|
-
expect(subject['content_status'].type).to be_eql(:content_status)
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'can be used in a multiple form' do
|
101
|
-
subject.enum('foo', 'bar', 'baz', subtype: :content_status)
|
102
|
-
expect(subject['foo'].type).to be_eql(:content_status)
|
103
|
-
expect(subject['bar'].type).to be_eql(:content_status)
|
104
|
-
expect(subject['baz'].type).to be_eql(:content_status)
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'can have custom type' do
|
108
|
-
subject.enum('foo', subtype: :content_status)
|
109
|
-
expect(subject['foo'].name).to be_eql('foo')
|
110
|
-
expect(subject['foo'].type).to be_eql(:content_status)
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'raises StatementInvalid when type isn\'t defined' do
|
114
|
-
subject.enum('foo')
|
115
|
-
creation = connection.send(:schema_creation).accept subject
|
116
|
-
expect{ connection.execute creation }.to raise_error(ActiveRecord::StatementInvalid)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context 'on schema' do
|
121
|
-
it 'dumps when has it' do
|
122
|
-
dump_io = StringIO.new
|
123
|
-
ActiveRecord::SchemaDumper.dump(connection, dump_io)
|
124
|
-
expect(dump_io.string).to match /create_enum \"content_status\", \[/
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'sorts the enum entries to better consistency' do
|
128
|
-
dump_io = StringIO.new
|
129
|
-
ActiveRecord::SchemaDumper.dump(connection, dump_io)
|
130
|
-
items = dump_io.string.scan(/create_enum "(\w+)"/).flatten
|
131
|
-
expect(items).to be_eql(items.sort)
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'do not dump when has none' do
|
135
|
-
connection.drop_type(:content_status, force: :cascade)
|
136
|
-
|
137
|
-
dump_io = StringIO.new
|
138
|
-
ActiveRecord::SchemaDumper.dump(connection, dump_io)
|
139
|
-
expect(dump_io.string).not_to match /create_enum \"content_status\", \[/
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'can be used on tables too' do
|
143
|
-
dump_io = StringIO.new
|
144
|
-
ActiveRecord::SchemaDumper.dump(connection, dump_io)
|
145
|
-
expect(dump_io.string).to match /t\.enum +"status", +subtype: :content_status/
|
146
|
-
end
|
147
|
-
|
148
|
-
it 'can have a default value as symbol' do
|
149
|
-
dump_io = StringIO.new
|
150
|
-
ActiveRecord::SchemaDumper.dump(connection, dump_io)
|
151
|
-
expect(dump_io.string).to match /t\.enum +"role", +default: :visitor, +subtype: :roles/
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
72
|
context 'on value' do
|
156
73
|
subject { Enum::ContentStatus }
|
157
74
|
let(:values) { %w(created draft published archived) }
|
data/spec/tests/interval_spec.rb
CHANGED
@@ -2,6 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe 'Interval' do
|
4
4
|
let(:connection) { ActiveRecord::Base.connection }
|
5
|
+
let(:table_definition) { ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition }
|
5
6
|
|
6
7
|
context 'on settings' do
|
7
8
|
it 'must be set to ISO 8601' do
|
@@ -10,7 +11,7 @@ RSpec.describe 'Interval' do
|
|
10
11
|
end
|
11
12
|
|
12
13
|
context 'on table definition' do
|
13
|
-
subject {
|
14
|
+
subject { table_definition.new(connection, 'articles') }
|
14
15
|
|
15
16
|
it 'has the interval method' do
|
16
17
|
expect(subject).to respond_to(:interval)
|