schema_plus 1.5.3 → 1.6.0

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.
@@ -68,144 +68,139 @@ describe "Index definition" do
68
68
  end
69
69
 
70
70
 
71
- unless SchemaPlusHelpers.mysql?
72
- context "when index is ordered" do
73
-
74
- quotes = [
75
- ["unquoted", ''],
76
- ["double-quoted", '"'],
77
- ]
78
- quotes += [
79
- ["single-quoted", "'"],
80
- ["back-quoted", '`']
81
- ] if SchemaPlusHelpers.sqlite3?
82
-
83
- quotes.each do |quotename, quote|
84
- it "index definition includes orders for #{quotename} columns" do
85
- migration.execute "CREATE INDEX users_login_index ON users (#{quote}login#{quote} DESC, #{quote}deleted_at#{quote} ASC)"
86
- User.reset_column_information
87
- index = index_definition(%w[login deleted_at])
88
- expect(index.orders).to eq({"login" => :desc, "deleted_at" => :asc})
89
- end
90
-
71
+ context "when index is ordered", :mysql => :skip do
72
+
73
+ quotes = [
74
+ ["unquoted", ''],
75
+ ["double-quoted", '"'],
76
+ ]
77
+ quotes += [
78
+ ["single-quoted", "'"],
79
+ ["back-quoted", '`']
80
+ ] if SchemaPlusHelpers.sqlite3?
81
+
82
+ quotes.each do |quotename, quote|
83
+ it "index definition includes orders for #{quotename} columns" do
84
+ migration.execute "CREATE INDEX users_login_index ON users (#{quote}login#{quote} DESC, #{quote}deleted_at#{quote} ASC)"
85
+ User.reset_column_information
86
+ index = index_definition(%w[login deleted_at])
87
+ expect(index.orders).to eq({"login" => :desc, "deleted_at" => :asc})
91
88
  end
89
+
92
90
  end
93
91
  end
94
92
 
95
93
 
96
- if SchemaPlusHelpers.postgresql?
94
+ context "when case insensitive is added", :postgresql => :only do
97
95
 
98
- context "when case insensitive is added" do
99
-
100
- before(:each) do
101
- migration.execute "CREATE INDEX users_login_index ON users(LOWER(login))"
102
- User.reset_column_information
103
- @index = User.indexes.detect { |i| i.expression =~ /lower\(\(login\)::text\)/i }
104
- end
105
-
106
- it "is included in User.indexes" do
107
- expect(@index).not_to be_nil
108
- end
96
+ before(:each) do
97
+ migration.execute "CREATE INDEX users_login_index ON users(LOWER(login))"
98
+ User.reset_column_information
99
+ @index = User.indexes.detect { |i| i.expression =~ /lower\(\(login\)::text\)/i }
100
+ end
109
101
 
110
- it "is not case_sensitive" do
111
- expect(@index).not_to be_case_sensitive
112
- end
102
+ it "is included in User.indexes" do
103
+ expect(@index).not_to be_nil
104
+ end
113
105
 
114
- it "its column should not be case sensitive" do
115
- expect(User.columns.find{|column| column.name == "login"}).not_to be_case_sensitive
116
- end
106
+ it "is not case_sensitive" do
107
+ expect(@index).not_to be_case_sensitive
108
+ end
117
109
 
118
- it "defines expression" do
119
- expect(@index.expression).to eq("lower((login)::text)")
120
- end
110
+ it "its column should not be case sensitive" do
111
+ expect(User.columns.find{|column| column.name == "login"}).not_to be_case_sensitive
112
+ end
121
113
 
122
- it "doesn't define conditions" do
123
- expect(@index.conditions).to be_nil
124
- end
114
+ it "defines expression" do
115
+ expect(@index.expression).to eq("lower((login)::text)")
116
+ end
125
117
 
118
+ it "doesn't define conditions" do
119
+ expect(@index.conditions).to be_nil
126
120
  end
127
121
 
122
+ end
128
123
 
129
- context "when index is partial and column is not downcased" do
130
- before(:each) do
131
- migration.execute "CREATE INDEX users_login_index ON users(login) WHERE deleted_at IS NULL"
132
- User.reset_column_information
133
- @index = index_definition("login")
134
- end
135
124
 
136
- it "is included in User.indexes" do
137
- expect(User.indexes.select { |index| index.columns == ["login"] }.size).to eq(1)
138
- end
125
+ context "when index is partial and column is not downcased", :postgresql => :only do
126
+ before(:each) do
127
+ migration.execute "CREATE INDEX users_login_index ON users(login) WHERE deleted_at IS NULL"
128
+ User.reset_column_information
129
+ @index = index_definition("login")
130
+ end
139
131
 
140
- it "is case_sensitive" do
141
- expect(@index).to be_case_sensitive
142
- end
132
+ it "is included in User.indexes" do
133
+ expect(User.indexes.select { |index| index.columns == ["login"] }.size).to eq(1)
134
+ end
143
135
 
144
- it "doesn't define expression" do
145
- expect(@index.expression).to be_nil
146
- end
136
+ it "is case_sensitive" do
137
+ expect(@index).to be_case_sensitive
138
+ end
147
139
 
148
- it "defines conditions" do
149
- expect(@index.conditions).to eq("(deleted_at IS NULL)")
150
- end
140
+ it "doesn't define expression" do
141
+ expect(@index.expression).to be_nil
142
+ end
151
143
 
144
+ it "defines conditions" do
145
+ expect(@index.conditions).to eq("(deleted_at IS NULL)")
152
146
  end
153
147
 
154
- context "when index contains expression" do
155
- before(:each) do
156
- migration.execute "CREATE INDEX users_login_index ON users (extract(EPOCH from deleted_at)) WHERE deleted_at IS NULL"
157
- User.reset_column_information
158
- @index = User.indexes.detect { |i| i.expression.present? }
159
- end
148
+ end
160
149
 
161
- it "exists" do
162
- expect(@index).not_to be_nil
163
- end
150
+ context "when index contains expression", :postgresql => :only do
151
+ before(:each) do
152
+ migration.execute "CREATE INDEX users_login_index ON users (extract(EPOCH from deleted_at)) WHERE deleted_at IS NULL"
153
+ User.reset_column_information
154
+ @index = User.indexes.detect { |i| i.expression.present? }
155
+ end
164
156
 
165
- it "doesnt have columns defined" do
166
- expect(@index.columns).to be_empty
167
- end
157
+ it "exists" do
158
+ expect(@index).not_to be_nil
159
+ end
168
160
 
169
- it "is case_sensitive" do
170
- expect(@index).to be_case_sensitive
171
- end
161
+ it "doesnt have columns defined" do
162
+ expect(@index.columns).to be_empty
163
+ end
172
164
 
173
- it "defines expression" do
174
- expect(@index.expression).to eq("date_part('epoch'::text, deleted_at)")
175
- end
165
+ it "is case_sensitive" do
166
+ expect(@index).to be_case_sensitive
167
+ end
176
168
 
177
- it "defines conditions" do
178
- expect(@index.conditions).to eq("(deleted_at IS NULL)")
179
- end
169
+ it "defines expression" do
170
+ expect(@index.expression).to eq("date_part('epoch'::text, deleted_at)")
171
+ end
180
172
 
173
+ it "defines conditions" do
174
+ expect(@index.conditions).to eq("(deleted_at IS NULL)")
181
175
  end
182
176
 
183
- context "when index has a non-btree type" do
184
- before(:each) do
185
- migration.execute "CREATE INDEX users_login_index ON users USING hash(login)"
186
- User.reset_column_information
187
- @index = User.indexes.detect { |i| i.name == "users_login_index" }
188
- end
177
+ end
189
178
 
190
- it "exists" do
191
- expect(@index).not_to be_nil
192
- end
179
+ context "when index has a non-btree type", :postgresql => :only do
180
+ before(:each) do
181
+ migration.execute "CREATE INDEX users_login_index ON users USING hash(login)"
182
+ User.reset_column_information
183
+ @index = User.indexes.detect { |i| i.name == "users_login_index" }
184
+ end
193
185
 
194
- it "defines kind" do
195
- expect(@index.kind).to eq("hash")
196
- end
186
+ it "exists" do
187
+ expect(@index).not_to be_nil
188
+ end
197
189
 
198
- it "does not define expression" do
199
- expect(@index.expression).to be_nil
200
- end
190
+ it "defines kind" do
191
+ expect(@index.kind).to eq("hash")
192
+ end
201
193
 
202
- it "does not define order" do
203
- expect(@index.orders).to be_blank
204
- end
194
+ it "does not define expression" do
195
+ expect(@index.expression).to be_nil
196
+ end
197
+
198
+ it "does not define order" do
199
+ expect(@index.orders).to be_blank
205
200
  end
201
+ end
206
202
 
207
203
 
208
- end # of postgresql specific examples
209
204
 
210
205
  protected
211
206
  def index_definition(column_names)
data/spec/index_spec.rb CHANGED
@@ -55,11 +55,9 @@ describe "index" do
55
55
  expect(index_for(:login).name).to eq('users_login_index')
56
56
  end
57
57
 
58
- unless SchemaPlusHelpers.mysql?
59
- it "should assign order" do
60
- add_index(:users, [:login, :deleted_at], :order => {:login => :desc, :deleted_at => :asc})
61
- expect(index_for([:login, :deleted_at]).orders).to eq({"login" => :desc, "deleted_at" => :asc})
62
- end
58
+ it "should assign order", :mysql => :skip do
59
+ add_index(:users, [:login, :deleted_at], :order => {:login => :desc, :deleted_at => :asc})
60
+ expect(index_for([:login, :deleted_at]).orders).to eq({"login" => :desc, "deleted_at" => :asc})
63
61
  end
64
62
 
65
63
  context "for duplicate index" do
@@ -78,7 +76,7 @@ describe "index" do
78
76
  end
79
77
  end
80
78
 
81
- if SchemaPlusHelpers.postgresql?
79
+ context "extra features", :postgresql => :only do
82
80
 
83
81
  it "should assign conditions" do
84
82
  add_index(:users, :login, :conditions => 'deleted_at IS NULL')
@@ -124,8 +122,7 @@ describe "index" do
124
122
  expect { add_index(:users, :name => 'users_login_index', :expression => "USING btree (login)", :case_sensitive => false) }.to raise_error(ArgumentError, /use LOWER/i)
125
123
  end
126
124
 
127
-
128
- end # of postgresql specific examples
125
+ end
129
126
 
130
127
  protected
131
128