schema_plus 1.5.1 → 1.5.3
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/CHANGELOG.md +134 -0
- data/README.md +43 -114
- data/gemfiles/rails-4.1/Gemfile.base +1 -1
- data/lib/schema_plus/active_record/column_options_handler.rb +1 -0
- data/lib/schema_plus/active_record/connection_adapters/column.rb +1 -1
- data/lib/schema_plus/active_record/connection_adapters/schema_statements.rb +1 -0
- data/lib/schema_plus/active_record/connection_adapters/table_definition.rb +2 -0
- data/lib/schema_plus/version.rb +1 -1
- data/runspecs +2 -2
- data/schema_plus.gemspec +2 -2
- data/spec/column_default_spec.rb +156 -0
- data/spec/column_spec.rb +20 -20
- data/spec/connection_spec.rb +1 -1
- data/spec/foreign_key_definition_spec.rb +3 -3
- data/spec/foreign_key_spec.rb +14 -12
- data/spec/index_definition_spec.rb +23 -23
- data/spec/index_spec.rb +34 -34
- data/spec/migration_spec.rb +132 -120
- data/spec/named_schemas_spec.rb +15 -15
- data/spec/schema_dumper_spec.rb +36 -36
- data/spec/schema_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- data/spec/support/matchers/have_index.rb +20 -13
- data/spec/support/matchers/reference.rb +3 -3
- data/spec/views_spec.rb +17 -17
- metadata +10 -9
- data/spec/column_definition_spec.rb +0 -212
data/spec/column_spec.rb
CHANGED
|
@@ -14,7 +14,7 @@ describe "Column" do
|
|
|
14
14
|
@login = User.columns.find{|column| column.name == "login"}
|
|
15
15
|
end
|
|
16
16
|
it "works properly" do
|
|
17
|
-
JSON.parse(@login.to_json).
|
|
17
|
+
expect(JSON.parse(@login.to_json)).to include("name" => "login", "type" => "string")
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
@@ -28,12 +28,12 @@ describe "Column" do
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
it "should report not unique" do
|
|
31
|
-
@login.
|
|
31
|
+
expect(@login).not_to be_unique
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
it "should report nil unique scope" do
|
|
35
35
|
create_table(User, :login => { :index => true})
|
|
36
|
-
@login.unique_scope.
|
|
36
|
+
expect(@login.unique_scope).to be_nil
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
@@ -44,11 +44,11 @@ describe "Column" do
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
it "should report unique" do
|
|
47
|
-
@login.
|
|
47
|
+
expect(@login).to be_unique
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
it "should report an empty unique scope" do
|
|
51
|
-
@login.unique_scope.
|
|
51
|
+
expect(@login.unique_scope).to eq([])
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
|
|
@@ -62,15 +62,15 @@ describe "Column" do
|
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
it "should report unique for each" do
|
|
65
|
-
@first.
|
|
66
|
-
@middle.
|
|
67
|
-
@last.
|
|
65
|
+
expect(@first).to be_unique
|
|
66
|
+
expect(@middle).to be_unique
|
|
67
|
+
expect(@last).to be_unique
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
it "should report unique scope for each" do
|
|
71
|
-
@first.unique_scope.
|
|
72
|
-
@middle.unique_scope.
|
|
73
|
-
@last.unique_scope.
|
|
71
|
+
expect(@first.unique_scope).to match_array(%W[middle last])
|
|
72
|
+
expect(@middle.unique_scope).to match_array(%W[first last])
|
|
73
|
+
expect(@last.unique_scope).to match_array(%W[first middle])
|
|
74
74
|
end
|
|
75
75
|
end
|
|
76
76
|
|
|
@@ -80,17 +80,17 @@ describe "Column" do
|
|
|
80
80
|
|
|
81
81
|
it "not required if the column can be null" do
|
|
82
82
|
create_table(User, :login => { :null => true})
|
|
83
|
-
User.columns.find{|column| column.name == "login"}.required_on.
|
|
83
|
+
expect(User.columns.find{|column| column.name == "login"}.required_on).to be_nil
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
it "must have a value on :save if there's no default" do
|
|
87
87
|
create_table(User, :login => { :null => false })
|
|
88
|
-
User.columns.find{|column| column.name == "login"}.required_on.
|
|
88
|
+
expect(User.columns.find{|column| column.name == "login"}.required_on).to eq(:save)
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
it "must have a value on :update if there's default" do
|
|
92
92
|
create_table(User, :login => { :null => false, :default => "foo" })
|
|
93
|
-
User.columns.find{|column| column.name == "login"}.required_on.
|
|
93
|
+
expect(User.columns.find{|column| column.name == "login"}.required_on).to eq(:update)
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
end
|
|
@@ -113,19 +113,19 @@ describe "Column" do
|
|
|
113
113
|
|
|
114
114
|
it "creating a record should respect default expression" do
|
|
115
115
|
User.create!(:alpha => ActiveRecord::DB_DEFAULT, :beta => "hello")
|
|
116
|
-
User.last.alpha.
|
|
117
|
-
User.last.beta.
|
|
116
|
+
expect(User.last.alpha).to eq("gabba")
|
|
117
|
+
expect(User.last.beta).to eq("hello")
|
|
118
118
|
end
|
|
119
119
|
|
|
120
120
|
it "updating a record should respect default expression" do
|
|
121
121
|
u = User.create!(:alpha => "hey", :beta => "hello")
|
|
122
122
|
u.reload
|
|
123
|
-
u.alpha.
|
|
124
|
-
u.beta.
|
|
123
|
+
expect(u.alpha).to eq("hey")
|
|
124
|
+
expect(u.beta).to eq("hello")
|
|
125
125
|
u.update_attributes(:alpha => ActiveRecord::DB_DEFAULT, :beta => "goodbye")
|
|
126
126
|
u.reload
|
|
127
|
-
u.alpha.
|
|
128
|
-
u.beta.
|
|
127
|
+
expect(u.alpha).to eq("gabba")
|
|
128
|
+
expect(u.beta).to eq("goodbye")
|
|
129
129
|
end
|
|
130
130
|
end
|
|
131
131
|
end
|
data/spec/connection_spec.rb
CHANGED
|
@@ -5,17 +5,17 @@ describe "Foreign Key definition" do
|
|
|
5
5
|
let(:definition) { SchemaPlus::ActiveRecord::ConnectionAdapters::ForeignKeyDefinition.new("posts_user_fkey", :posts, :user, :users, :id) }
|
|
6
6
|
|
|
7
7
|
it "dumps to sql with quoted values" do
|
|
8
|
-
definition.to_sql.
|
|
8
|
+
expect(definition.to_sql).to eq(%Q{CONSTRAINT posts_user_fkey FOREIGN KEY (#{quote_column_name('user')}) REFERENCES #{quote_table_name('users')} (#{quote_column_name('id')})})
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
it "dumps to sql with deferrable values" do
|
|
12
12
|
deferred_definition = SchemaPlus::ActiveRecord::ConnectionAdapters::ForeignKeyDefinition.new("posts_user_fkey", :posts, :user, :users, :id, nil, nil, true)
|
|
13
|
-
deferred_definition.to_sql.
|
|
13
|
+
expect(deferred_definition.to_sql).to eq(%Q{CONSTRAINT posts_user_fkey FOREIGN KEY (#{quote_column_name('user')}) REFERENCES #{quote_table_name('users')} (#{quote_column_name('id')}) DEFERRABLE})
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
it "dumps to sql with initially deferrable values" do
|
|
17
17
|
initially_deferred_definition = SchemaPlus::ActiveRecord::ConnectionAdapters::ForeignKeyDefinition.new("posts_user_fkey", :posts, :user, :users, :id, nil, nil, :initially_deferred)
|
|
18
|
-
initially_deferred_definition.to_sql.
|
|
18
|
+
expect(initially_deferred_definition.to_sql).to eq(%Q{CONSTRAINT posts_user_fkey FOREIGN KEY (#{quote_column_name('user')}) REFERENCES #{quote_table_name('users')} (#{quote_column_name('id')}) DEFERRABLE INITIALLY DEFERRED})
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def quote_table_name(table)
|
data/spec/foreign_key_spec.rb
CHANGED
|
@@ -20,11 +20,11 @@ describe "Foreign Key" do
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
it "should report foreign key constraints" do
|
|
23
|
-
Comment.foreign_keys.collect(&:column_names).flatten.
|
|
23
|
+
expect(Comment.foreign_keys.collect(&:column_names).flatten).to eq([ "user_id" ])
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
it "should report reverse foreign key constraints" do
|
|
27
|
-
User.reverse_foreign_keys.collect(&:column_names).flatten.
|
|
27
|
+
expect(User.reverse_foreign_keys.collect(&:column_names).flatten).to eq([ "user_id" ])
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
end
|
|
@@ -32,7 +32,9 @@ describe "Foreign Key" do
|
|
|
32
32
|
if ::ActiveRecord::VERSION::MAJOR.to_i >= 4
|
|
33
33
|
context "with modifications to SQL generated by upstream visit_TableDefinition" do
|
|
34
34
|
before(:each) do
|
|
35
|
-
ActiveRecord::Base.connection.class.const_get(:SchemaCreation)
|
|
35
|
+
allow_any_instance_of(ActiveRecord::Base.connection.class.const_get(:SchemaCreation))
|
|
36
|
+
.to receive(:visit_TableDefinition_without_schema_plus)
|
|
37
|
+
.and_return('this is unexpected')
|
|
36
38
|
end
|
|
37
39
|
|
|
38
40
|
it "raises an exception when attempting to create a table" do
|
|
@@ -105,23 +107,23 @@ describe "Foreign Key" do
|
|
|
105
107
|
end
|
|
106
108
|
|
|
107
109
|
it "references users(id)" do
|
|
108
|
-
Post.
|
|
110
|
+
expect(Post).to reference(:users, :id).on(:author_id)
|
|
109
111
|
end
|
|
110
112
|
|
|
111
113
|
it "cascades on update" do
|
|
112
|
-
Post.
|
|
114
|
+
expect(Post).to reference(:users).on_update(:cascade)
|
|
113
115
|
end
|
|
114
116
|
|
|
115
117
|
it "restricts on delete" do
|
|
116
|
-
Post.
|
|
118
|
+
expect(Post).to reference(:users).on_delete(:restrict)
|
|
117
119
|
end
|
|
118
120
|
|
|
119
121
|
it "is available in Post.foreign_keys" do
|
|
120
|
-
Post.foreign_keys.collect(&:column_names).
|
|
122
|
+
expect(Post.foreign_keys.collect(&:column_names)).to include(%w[author_id])
|
|
121
123
|
end
|
|
122
124
|
|
|
123
125
|
it "is available in User.reverse_foreign_keys" do
|
|
124
|
-
User.reverse_foreign_keys.collect(&:column_names).
|
|
126
|
+
expect(User.reverse_foreign_keys.collect(&:column_names)).to include(%w[author_id])
|
|
125
127
|
end
|
|
126
128
|
|
|
127
129
|
end
|
|
@@ -139,15 +141,15 @@ describe "Foreign Key" do
|
|
|
139
141
|
end
|
|
140
142
|
|
|
141
143
|
it "doesn't reference posts(id)" do
|
|
142
|
-
Comment.
|
|
144
|
+
expect(Comment).not_to reference(:posts).on(:post_id)
|
|
143
145
|
end
|
|
144
146
|
|
|
145
147
|
it "is no longer available in Post.foreign_keys" do
|
|
146
|
-
Comment.foreign_keys.collect(&:column_names).
|
|
148
|
+
expect(Comment.foreign_keys.collect(&:column_names)).not_to include(%w[post_id])
|
|
147
149
|
end
|
|
148
150
|
|
|
149
151
|
it "is no longer available in User.reverse_foreign_keys" do
|
|
150
|
-
Post.reverse_foreign_keys.collect(&:column_names).
|
|
152
|
+
expect(Post.reverse_foreign_keys.collect(&:column_names)).not_to include(%w[post_id])
|
|
151
153
|
end
|
|
152
154
|
|
|
153
155
|
end
|
|
@@ -158,7 +160,7 @@ describe "Foreign Key" do
|
|
|
158
160
|
|
|
159
161
|
it "should remove foreign keys" do
|
|
160
162
|
remove_foreign_key(:comments, foreign_key_name)
|
|
161
|
-
Post.reverse_foreign_keys.collect { |fk| fk.column_names == %w[post_id] && fk.table_name == "comments" }.
|
|
163
|
+
expect(Post.reverse_foreign_keys.collect { |fk| fk.column_names == %w[post_id] && fk.table_name == "comments" }).to be_empty
|
|
162
164
|
end
|
|
163
165
|
|
|
164
166
|
end
|
|
@@ -47,7 +47,7 @@ describe "Index definition" do
|
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
it "is included in User.indexes" do
|
|
50
|
-
@index.
|
|
50
|
+
expect(@index).not_to be_nil
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
end
|
|
@@ -55,16 +55,16 @@ describe "Index definition" do
|
|
|
55
55
|
it "should correctly report supports_partial_indexes?" do
|
|
56
56
|
query = lambda { migration.execute "CREATE INDEX users_login_index ON users(login) WHERE deleted_at IS NULL" }
|
|
57
57
|
if migration.supports_partial_indexes?
|
|
58
|
-
query.
|
|
58
|
+
expect(query).not_to raise_error
|
|
59
59
|
else
|
|
60
|
-
query.
|
|
60
|
+
expect(query).to raise_error
|
|
61
61
|
end
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
it "should not crash on equality test with nil" do
|
|
65
65
|
index = ActiveRecord::ConnectionAdapters::IndexDefinition.new(:table, :column)
|
|
66
66
|
expect{index == nil}.to_not raise_error
|
|
67
|
-
(index == nil).
|
|
67
|
+
expect(index == nil).to be false
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
|
|
@@ -85,7 +85,7 @@ describe "Index definition" do
|
|
|
85
85
|
migration.execute "CREATE INDEX users_login_index ON users (#{quote}login#{quote} DESC, #{quote}deleted_at#{quote} ASC)"
|
|
86
86
|
User.reset_column_information
|
|
87
87
|
index = index_definition(%w[login deleted_at])
|
|
88
|
-
index.orders.
|
|
88
|
+
expect(index.orders).to eq({"login" => :desc, "deleted_at" => :asc})
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
end
|
|
@@ -104,23 +104,23 @@ describe "Index definition" do
|
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
it "is included in User.indexes" do
|
|
107
|
-
@index.
|
|
107
|
+
expect(@index).not_to be_nil
|
|
108
108
|
end
|
|
109
109
|
|
|
110
110
|
it "is not case_sensitive" do
|
|
111
|
-
@index.
|
|
111
|
+
expect(@index).not_to be_case_sensitive
|
|
112
112
|
end
|
|
113
113
|
|
|
114
114
|
it "its column should not be case sensitive" do
|
|
115
|
-
User.columns.find{|column| column.name == "login"}.
|
|
115
|
+
expect(User.columns.find{|column| column.name == "login"}).not_to be_case_sensitive
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
it "defines expression" do
|
|
119
|
-
@index.expression.
|
|
119
|
+
expect(@index.expression).to eq("lower((login)::text)")
|
|
120
120
|
end
|
|
121
121
|
|
|
122
122
|
it "doesn't define conditions" do
|
|
123
|
-
@index.conditions.
|
|
123
|
+
expect(@index.conditions).to be_nil
|
|
124
124
|
end
|
|
125
125
|
|
|
126
126
|
end
|
|
@@ -134,19 +134,19 @@ describe "Index definition" do
|
|
|
134
134
|
end
|
|
135
135
|
|
|
136
136
|
it "is included in User.indexes" do
|
|
137
|
-
User.indexes.select { |index| index.columns == ["login"] }.
|
|
137
|
+
expect(User.indexes.select { |index| index.columns == ["login"] }.size).to eq(1)
|
|
138
138
|
end
|
|
139
139
|
|
|
140
140
|
it "is case_sensitive" do
|
|
141
|
-
@index.
|
|
141
|
+
expect(@index).to be_case_sensitive
|
|
142
142
|
end
|
|
143
143
|
|
|
144
144
|
it "doesn't define expression" do
|
|
145
|
-
@index.expression.
|
|
145
|
+
expect(@index.expression).to be_nil
|
|
146
146
|
end
|
|
147
147
|
|
|
148
148
|
it "defines conditions" do
|
|
149
|
-
@index.conditions.
|
|
149
|
+
expect(@index.conditions).to eq("(deleted_at IS NULL)")
|
|
150
150
|
end
|
|
151
151
|
|
|
152
152
|
end
|
|
@@ -159,23 +159,23 @@ describe "Index definition" do
|
|
|
159
159
|
end
|
|
160
160
|
|
|
161
161
|
it "exists" do
|
|
162
|
-
@index.
|
|
162
|
+
expect(@index).not_to be_nil
|
|
163
163
|
end
|
|
164
164
|
|
|
165
165
|
it "doesnt have columns defined" do
|
|
166
|
-
@index.columns.
|
|
166
|
+
expect(@index.columns).to be_empty
|
|
167
167
|
end
|
|
168
168
|
|
|
169
169
|
it "is case_sensitive" do
|
|
170
|
-
@index.
|
|
170
|
+
expect(@index).to be_case_sensitive
|
|
171
171
|
end
|
|
172
172
|
|
|
173
173
|
it "defines expression" do
|
|
174
|
-
@index.expression.
|
|
174
|
+
expect(@index.expression).to eq("date_part('epoch'::text, deleted_at)")
|
|
175
175
|
end
|
|
176
176
|
|
|
177
177
|
it "defines conditions" do
|
|
178
|
-
@index.conditions.
|
|
178
|
+
expect(@index.conditions).to eq("(deleted_at IS NULL)")
|
|
179
179
|
end
|
|
180
180
|
|
|
181
181
|
end
|
|
@@ -188,19 +188,19 @@ describe "Index definition" do
|
|
|
188
188
|
end
|
|
189
189
|
|
|
190
190
|
it "exists" do
|
|
191
|
-
@index.
|
|
191
|
+
expect(@index).not_to be_nil
|
|
192
192
|
end
|
|
193
193
|
|
|
194
194
|
it "defines kind" do
|
|
195
|
-
@index.kind.
|
|
195
|
+
expect(@index.kind).to eq("hash")
|
|
196
196
|
end
|
|
197
197
|
|
|
198
198
|
it "does not define expression" do
|
|
199
|
-
@index.expression.
|
|
199
|
+
expect(@index.expression).to be_nil
|
|
200
200
|
end
|
|
201
201
|
|
|
202
202
|
it "does not define order" do
|
|
203
|
-
@index.orders.
|
|
203
|
+
expect(@index.orders).to be_blank
|
|
204
204
|
end
|
|
205
205
|
end
|
|
206
206
|
|
data/spec/index_spec.rb
CHANGED
|
@@ -42,39 +42,39 @@ describe "index" do
|
|
|
42
42
|
|
|
43
43
|
it "should create index when called without additional options" do
|
|
44
44
|
add_index(:users, :login)
|
|
45
|
-
index_for(:login).
|
|
45
|
+
expect(index_for(:login)).not_to be_nil
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
it "should create unique index" do
|
|
49
49
|
add_index(:users, :login, :unique => true)
|
|
50
|
-
index_for(:login).unique.
|
|
50
|
+
expect(index_for(:login).unique).to eq(true)
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
it "should assign given name" do
|
|
54
54
|
add_index(:users, :login, :name => 'users_login_index')
|
|
55
|
-
index_for(:login).name.
|
|
55
|
+
expect(index_for(:login).name).to eq('users_login_index')
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
unless SchemaPlusHelpers.mysql?
|
|
59
59
|
it "should assign order" do
|
|
60
60
|
add_index(:users, [:login, :deleted_at], :order => {:login => :desc, :deleted_at => :asc})
|
|
61
|
-
index_for([:login, :deleted_at]).orders.
|
|
61
|
+
expect(index_for([:login, :deleted_at]).orders).to eq({"login" => :desc, "deleted_at" => :asc})
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
context "for duplicate index" do
|
|
66
66
|
it "should not complain if the index is the same" do
|
|
67
67
|
add_index(:users, :login)
|
|
68
|
-
index_for(:login).
|
|
69
|
-
ActiveRecord::Base.logger.
|
|
68
|
+
expect(index_for(:login)).not_to be_nil
|
|
69
|
+
expect(ActiveRecord::Base.logger).to receive(:warn).with(/login.*Skipping/)
|
|
70
70
|
expect { add_index(:users, :login) }.to_not raise_error
|
|
71
|
-
index_for(:login).
|
|
71
|
+
expect(index_for(:login)).not_to be_nil
|
|
72
72
|
end
|
|
73
73
|
it "should complain if the index is different" do
|
|
74
74
|
add_index(:users, :login, :unique => true)
|
|
75
|
-
index_for(:login).
|
|
75
|
+
expect(index_for(:login)).not_to be_nil
|
|
76
76
|
expect { add_index(:users, :login) }.to raise_error
|
|
77
|
-
index_for(:login).
|
|
77
|
+
expect(index_for(:login)).not_to be_nil
|
|
78
78
|
end
|
|
79
79
|
end
|
|
80
80
|
|
|
@@ -82,34 +82,34 @@ describe "index" do
|
|
|
82
82
|
|
|
83
83
|
it "should assign conditions" do
|
|
84
84
|
add_index(:users, :login, :conditions => 'deleted_at IS NULL')
|
|
85
|
-
index_for(:login).conditions.
|
|
85
|
+
expect(index_for(:login).conditions).to eq('(deleted_at IS NULL)')
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
it "should assign expression, conditions and kind" do
|
|
89
89
|
add_index(:users, :expression => "USING hash (upper(login)) WHERE deleted_at IS NULL", :name => 'users_login_index')
|
|
90
90
|
@index = User.indexes.detect { |i| i.expression.present? }
|
|
91
|
-
@index.expression.
|
|
92
|
-
@index.conditions.
|
|
93
|
-
@index.kind.
|
|
91
|
+
expect(@index.expression).to eq("upper((login)::text)")
|
|
92
|
+
expect(@index.conditions).to eq("(deleted_at IS NULL)")
|
|
93
|
+
expect(@index.kind).to eq("hash")
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
it "should allow to specify expression, conditions and kind separately" do
|
|
97
97
|
add_index(:users, :kind => "hash", :expression => "upper(login)", :conditions => "deleted_at IS NULL", :name => 'users_login_index')
|
|
98
98
|
@index = User.indexes.detect { |i| i.expression.present? }
|
|
99
|
-
@index.expression.
|
|
100
|
-
@index.conditions.
|
|
101
|
-
@index.kind.
|
|
99
|
+
expect(@index.expression).to eq("upper((login)::text)")
|
|
100
|
+
expect(@index.conditions).to eq("(deleted_at IS NULL)")
|
|
101
|
+
expect(@index.kind).to eq("hash")
|
|
102
102
|
end
|
|
103
103
|
|
|
104
104
|
it "should allow to specify kind" do
|
|
105
105
|
add_index(:users, :login, :kind => "hash")
|
|
106
|
-
index_for(:login).kind.
|
|
106
|
+
expect(index_for(:login).kind).to eq('hash')
|
|
107
107
|
end
|
|
108
108
|
|
|
109
109
|
it "should allow to specify actual expression only" do
|
|
110
110
|
add_index(:users, :expression => "upper(login)", :name => 'users_login_index')
|
|
111
111
|
@index = User.indexes.detect { |i| i.name == 'users_login_index' }
|
|
112
|
-
@index.expression.
|
|
112
|
+
expect(@index.expression).to eq("upper((login)::text)")
|
|
113
113
|
end
|
|
114
114
|
|
|
115
115
|
it "should raise if no column given and expression is missing" do
|
|
@@ -151,58 +151,58 @@ describe "index" do
|
|
|
151
151
|
|
|
152
152
|
it "removes index by column name (symbols)" do
|
|
153
153
|
add_index :users, :login
|
|
154
|
-
User.indexes.length.
|
|
154
|
+
expect(User.indexes.length).to eq(1)
|
|
155
155
|
remove_index :users, :login
|
|
156
|
-
User.indexes.length.
|
|
156
|
+
expect(User.indexes.length).to eq(0)
|
|
157
157
|
end
|
|
158
158
|
|
|
159
159
|
it "removes index by column name (symbols)" do
|
|
160
160
|
add_index :users, :login
|
|
161
|
-
User.indexes.length.
|
|
161
|
+
expect(User.indexes.length).to eq(1)
|
|
162
162
|
remove_index 'users', 'login'
|
|
163
|
-
User.indexes.length.
|
|
163
|
+
expect(User.indexes.length).to eq(0)
|
|
164
164
|
end
|
|
165
165
|
|
|
166
166
|
it "removes multi-column index by column names (symbols)" do
|
|
167
167
|
add_index :users, [:login, :deleted_at]
|
|
168
|
-
User.indexes.length.
|
|
168
|
+
expect(User.indexes.length).to eq(1)
|
|
169
169
|
remove_index :users, [:login, :deleted_at]
|
|
170
|
-
User.indexes.length.
|
|
170
|
+
expect(User.indexes.length).to eq(0)
|
|
171
171
|
end
|
|
172
172
|
|
|
173
173
|
it "removes multi-column index by column names (strings)" do
|
|
174
174
|
add_index 'users', [:login, :deleted_at]
|
|
175
|
-
User.indexes.length.
|
|
175
|
+
expect(User.indexes.length).to eq(1)
|
|
176
176
|
remove_index 'users', ['login', 'deleted_at']
|
|
177
|
-
User.indexes.length.
|
|
177
|
+
expect(User.indexes.length).to eq(0)
|
|
178
178
|
end
|
|
179
179
|
|
|
180
180
|
it "removes index using column option" do
|
|
181
181
|
add_index :users, :login
|
|
182
|
-
User.indexes.length.
|
|
182
|
+
expect(User.indexes.length).to eq(1)
|
|
183
183
|
remove_index :users, column: :login
|
|
184
|
-
User.indexes.length.
|
|
184
|
+
expect(User.indexes.length).to eq(0)
|
|
185
185
|
end
|
|
186
186
|
|
|
187
187
|
it "removes index if_exists" do
|
|
188
188
|
add_index :users, :login
|
|
189
|
-
User.indexes.length.
|
|
189
|
+
expect(User.indexes.length).to eq(1)
|
|
190
190
|
remove_index :users, :login, :if_exists => true
|
|
191
|
-
User.indexes.length.
|
|
191
|
+
expect(User.indexes.length).to eq(0)
|
|
192
192
|
end
|
|
193
193
|
|
|
194
194
|
it "removes multi-column index if exists" do
|
|
195
195
|
add_index :users, [:login, :deleted_at]
|
|
196
|
-
User.indexes.length.
|
|
196
|
+
expect(User.indexes.length).to eq(1)
|
|
197
197
|
remove_index :users, [:login, :deleted_at], :if_exists => true
|
|
198
|
-
User.indexes.length.
|
|
198
|
+
expect(User.indexes.length).to eq(0)
|
|
199
199
|
end
|
|
200
200
|
|
|
201
201
|
it "removes index if_exists using column option" do
|
|
202
202
|
add_index :users, :login
|
|
203
|
-
User.indexes.length.
|
|
203
|
+
expect(User.indexes.length).to eq(1)
|
|
204
204
|
remove_index :users, column: :login, :if_exists => true
|
|
205
|
-
User.indexes.length.
|
|
205
|
+
expect(User.indexes.length).to eq(0)
|
|
206
206
|
end
|
|
207
207
|
|
|
208
208
|
it "raises exception if doesn't exist" do
|