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.
@@ -168,9 +168,9 @@ describe "with multiple schemas" do
168
168
  expect(Member.foreign_keys.map(&:references_table_name)).to include "schema_plus_test2.groups"
169
169
  end
170
170
 
171
- it "should reference table in default schema" do
171
+ it "should reference table in default schema", :mysql => :skip do
172
172
  expect(Member.foreign_keys.map(&:references_table_name)).to include "items"
173
- end unless SchemaPlusHelpers.mysql?
173
+ end
174
174
 
175
175
  it "should include the schema in the constraint name" do
176
176
  expected_names = ["fk_schema_plus_test2_members_group_id"]
@@ -179,38 +179,36 @@ describe "with multiple schemas" do
179
179
  end
180
180
  end
181
181
 
182
- if SchemaPlusHelpers.postgresql?
183
- context "when using PostGIS" do
184
- before(:all) do
185
- begin
186
- connection.execute "CREATE SCHEMA postgis"
187
- rescue ActiveRecord::StatementInvalid => e
188
- raise unless e.message =~ /already exists/
189
- end
182
+ context "when using PostGIS", :postgresql => :only do
183
+ before(:all) do
184
+ begin
185
+ connection.execute "CREATE SCHEMA postgis"
186
+ rescue ActiveRecord::StatementInvalid => e
187
+ raise unless e.message =~ /already exists/
190
188
  end
189
+ end
191
190
 
192
- around (:each) do |example|
193
- begin
194
- connection.execute "SET search_path to '$user','public','postgis'"
195
- example.run
196
- ensure
197
- connection.execute "SET search_path to '$user','public'"
198
- end
191
+ around (:each) do |example|
192
+ begin
193
+ connection.execute "SET search_path to '$user','public','postgis'"
194
+ example.run
195
+ ensure
196
+ connection.execute "SET search_path to '$user','public'"
199
197
  end
198
+ end
200
199
 
201
- before(:each) do
202
- allow(connection).to receive(:adapter_name).and_return('PostGIS')
203
- end
200
+ before(:each) do
201
+ allow(connection).to receive(:adapter_name).and_return('PostGIS')
202
+ end
204
203
 
205
- it "should hide views in postgis schema" do
206
- begin
204
+ it "should hide views in postgis schema" do
205
+ begin
207
206
  connection.create_view "postgis.hidden", "select 1", :force => true
208
207
  connection.create_view :myview, "select 2", :force => true
209
208
  expect(connection.views).to eq(["myview"])
210
- ensure
211
- connection.execute 'DROP VIEW postgis.hidden' rescue nil
212
- connection.execute 'DROP VIEW myview' rescue nil
213
- end
209
+ ensure
210
+ connection.execute 'DROP VIEW postgis.hidden' rescue nil
211
+ connection.execute 'DROP VIEW myview' rescue nil
214
212
  end
215
213
  end
216
214
  end
@@ -87,47 +87,44 @@ describe "Schema dump" do
87
87
 
88
88
  end
89
89
 
90
- context "with date default" do
91
- if SchemaPlusHelpers.postgresql?
92
- it "should dump the default hash expr as now()" do
93
- with_additional_column Post, :posted_at, :datetime, :default => :now do
94
- expect(dump_posts).to match(%r{t\.datetime\s+"posted_at",\s*(?:default:|:default =>)\s*\{\s*(?:expr:|:expr\s*=>)\s*"now\(\)"\s*\}})
95
- end
90
+ context "with date default", :postgresql => :only do
91
+ it "should dump the default hash expr as now()" do
92
+ with_additional_column Post, :posted_at, :datetime, :default => :now do
93
+ expect(dump_posts).to match(%r{t\.datetime\s+"posted_at",\s*(?:default:|:default =>)\s*\{\s*(?:expr:|:expr\s*=>)\s*"now\(\)"\s*\}})
96
94
  end
95
+ end
97
96
 
98
- it "should dump the default hash expr as CURRENT_TIMESTAMP" do
99
- with_additional_column Post, :posted_at, :datetime, :default => {:expr => 'date \'2001-09-28\''} do
100
- expect(dump_posts).to match(%r{t\.datetime\s+"posted_at",\s*(?:default:|:default =>)\s*'2001-09-28 00:00:00'})
101
- end
97
+ it "should dump the default hash expr as CURRENT_TIMESTAMP" do
98
+ with_additional_column Post, :posted_at, :datetime, :default => {:expr => 'date \'2001-09-28\''} do
99
+ expect(dump_posts).to match(%r{t\.datetime\s+"posted_at",\s*(?:default:|:default =>)\s*'2001-09-28 00:00:00'})
102
100
  end
101
+ end
103
102
 
104
- it "can dump a complex default expression" do
105
- with_additional_column Post, :name, :string, :default => {:expr => 'substring(random()::text from 3 for 6)'} do
106
- 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*}})
107
- end
103
+ it "can dump a complex default expression" do
104
+ with_additional_column Post, :name, :string, :default => {:expr => 'substring(random()::text from 3 for 6)'} do
105
+ 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*}})
108
106
  end
109
107
  end
108
+ end
110
109
 
111
- if SchemaPlusHelpers.sqlite3?
112
- it "should dump the default hash expr as now" do
113
- with_additional_column Post, :posted_at, :datetime, :default => :now do
114
- expect(dump_posts).to match(%r{t\.datetime\s+"posted_at",\s*(?:default:|:default =>)\s*\{\s*(?:expr:|:expr =>)\s*"\(DATETIME\('now'\)\)"\s*\}})
115
- end
110
+ context "with date default", :sqlite3 => :only do
111
+ it "should dump the default hash expr as now" do
112
+ with_additional_column Post, :posted_at, :datetime, :default => :now do
113
+ expect(dump_posts).to match(%r{t\.datetime\s+"posted_at",\s*(?:default:|:default =>)\s*\{\s*(?:expr:|:expr =>)\s*"\(DATETIME\('now'\)\)"\s*\}})
116
114
  end
115
+ end
117
116
 
118
- it "should dump the default hash expr string as now" do
119
- with_additional_column Post, :posted_at, :datetime, :default => { :expr => "(DATETIME('now'))" } do
120
- expect(dump_posts).to match(%r{t\.datetime\s+"posted_at",\s*(?:default:|:default =>)\s*\{\s*(?:expr:|:expr =>)\s*"\(DATETIME\('now'\)\)"\s*\}})
121
- end
117
+ it "should dump the default hash expr string as now" do
118
+ with_additional_column Post, :posted_at, :datetime, :default => { :expr => "(DATETIME('now'))" } do
119
+ expect(dump_posts).to match(%r{t\.datetime\s+"posted_at",\s*(?:default:|:default =>)\s*\{\s*(?:expr:|:expr =>)\s*"\(DATETIME\('now'\)\)"\s*\}})
122
120
  end
121
+ end
123
122
 
124
- it "should dump the default value normally" do
125
- with_additional_column Post, :posted_at, :string, :default => "now" do
126
- expect(dump_posts).to match(%r{t\.string\s*"posted_at",\s*(?:default:|:default =>)\s*"now"})
127
- end
123
+ it "should dump the default value normally" do
124
+ with_additional_column Post, :posted_at, :string, :default => "now" do
125
+ expect(dump_posts).to match(%r{t\.string\s*"posted_at",\s*(?:default:|:default =>)\s*"now"})
128
126
  end
129
127
  end
130
-
131
128
  end
132
129
 
133
130
  it "should leave out :default when default was changed to null" do
@@ -169,17 +166,13 @@ describe "Schema dump" do
169
166
  end
170
167
  end
171
168
 
172
- unless SchemaPlusHelpers.mysql?
173
-
174
- it "should include index order" do
175
- with_index Post, [:user_id, :first_comment_id, :short_id], :order => { :user_id => :asc, :first_comment_id => :desc } do
176
- expect(dump_posts).to match(%r{t.index \["user_id", "first_comment_id", "short_id"\],.*:order => {"user_id" => :asc, "first_comment_id" => :desc, "short_id" => :asc}})
177
- end
169
+ it "should include index order", :mysql => :skip do
170
+ with_index Post, [:user_id, :first_comment_id, :short_id], :order => { :user_id => :asc, :first_comment_id => :desc } do
171
+ expect(dump_posts).to match(%r{t.index \["user_id", "first_comment_id", "short_id"\],.*:order => {"user_id" => :asc, "first_comment_id" => :desc, "short_id" => :asc}})
178
172
  end
179
-
180
173
  end
181
174
 
182
- if SchemaPlusHelpers.postgresql?
175
+ context "index extras", :postgresql => :only do
183
176
 
184
177
  it "should define case insensitive index" do
185
178
  with_index Post, [:body, :string_no_default], :case_sensitive => false do
@@ -250,26 +243,46 @@ describe "Schema dump" do
250
243
 
251
244
  end
252
245
 
253
- unless SchemaPlusHelpers.sqlite3?
254
- context "with cyclic foreign key constraints" do
255
- before (:all) do
256
- ActiveRecord::Base.connection.add_foreign_key(Comment.table_name, :commenter_id, User.table_name, :id)
257
- ActiveRecord::Base.connection.add_foreign_key(Comment.table_name, :post_id, Post.table_name, :id)
258
- ActiveRecord::Base.connection.add_foreign_key(Post.table_name, :first_comment_id, Comment.table_name, :id)
259
- ActiveRecord::Base.connection.add_foreign_key(Post.table_name, :user_id, User.table_name, :id)
260
- ActiveRecord::Base.connection.add_foreign_key(User.table_name, :first_post_id, Post.table_name, :id)
261
- end
246
+ context "with cyclic foreign key constraints", :sqlite3 => :skip do
247
+ before (:all) do
248
+ ActiveRecord::Base.connection.add_foreign_key(Comment.table_name, :commenter_id, User.table_name, :id)
249
+ ActiveRecord::Base.connection.add_foreign_key(Comment.table_name, :post_id, Post.table_name, :id)
250
+ ActiveRecord::Base.connection.add_foreign_key(Post.table_name, :first_comment_id, Comment.table_name, :id)
251
+ ActiveRecord::Base.connection.add_foreign_key(Post.table_name, :user_id, User.table_name, :id)
252
+ ActiveRecord::Base.connection.add_foreign_key(User.table_name, :first_post_id, Post.table_name, :id)
253
+ end
254
+
255
+ it "should not raise an error" do
256
+ expect { dump_schema }.to_not raise_error
257
+ end
258
+
259
+ it "should dump constraints after the tables they reference" do
260
+ expect(dump_schema).to match(%r{create_table "comments".*foreign_key.*\["first_comment_id"\], "comments", \["id"\]}m)
261
+ expect(dump_schema).to match(%r{create_table "posts".*foreign_key.*\["first_post_id"\], "posts", \["id"\]}m)
262
+ expect(dump_schema).to match(%r{create_table "posts".*foreign_key.*\["post_id"\], "posts", \["id"\]}m)
263
+ expect(dump_schema).to match(%r{create_table "users".*foreign_key.*\["commenter_id"\], "users", \["id"\]}m)
264
+ expect(dump_schema).to match(%r{create_table "users".*foreign_key.*\["user_id"\], "users", \["id"\]}m)
265
+ end
266
+ end
267
+
268
+ context 'with enum', :postgresql => :only do
269
+ let(:connection) { ActiveRecord::Base.connection }
262
270
 
263
- it "should not raise an error" do
264
- expect { dump_schema }.to_not raise_error
271
+ it 'should include enum' do
272
+ begin
273
+ connection.execute "CREATE TYPE color AS ENUM ('red', 'green', 'blue')"
274
+ expect(dump_schema).to match(%r{create_enum "color", "red", "green", "blue"})
275
+ ensure
276
+ connection.execute "DROP TYPE color"
265
277
  end
278
+ end
266
279
 
267
- it "should dump constraints after the tables they reference" do
268
- expect(dump_schema).to match(%r{create_table "comments".*foreign_key.*\["first_comment_id"\], "comments", \["id"\]}m)
269
- expect(dump_schema).to match(%r{create_table "posts".*foreign_key.*\["first_post_id"\], "posts", \["id"\]}m)
270
- expect(dump_schema).to match(%r{create_table "posts".*foreign_key.*\["post_id"\], "posts", \["id"\]}m)
271
- expect(dump_schema).to match(%r{create_table "users".*foreign_key.*\["commenter_id"\], "users", \["id"\]}m)
272
- expect(dump_schema).to match(%r{create_table "users".*foreign_key.*\["user_id"\], "users", \["id"\]}m)
280
+ it 'should include enum with schema' do
281
+ begin
282
+ connection.execute "CREATE SCHEMA cmyk; CREATE TYPE cmyk.color AS ENUM ('cyan', 'magenta', 'yellow', 'black')"
283
+ expect(dump_schema).to match(%r{create_enum "color", "cyan", "magenta", "yellow", "black", :schema => "cmyk"})
284
+ ensure
285
+ connection.execute "DROP SCHEMA cmyk CASCADE"
273
286
  end
274
287
  end
275
288
  end
data/spec/spec_helper.rb CHANGED
@@ -17,6 +17,12 @@ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
17
17
  RSpec.configure do |config|
18
18
  config.include(SchemaPlusMatchers)
19
19
  config.include(SchemaPlusHelpers)
20
+ config.filter_run_excluding :postgresql => :only unless SchemaPlusHelpers.postgresql?
21
+ config.filter_run_excluding :postgresql => :skip if SchemaPlusHelpers.postgresql?
22
+ config.filter_run_excluding :mysql => :only unless SchemaPlusHelpers.mysql?
23
+ config.filter_run_excluding :mysql => :skip if SchemaPlusHelpers.mysql?
24
+ config.filter_run_excluding :sqlite3 => :only unless SchemaPlusHelpers.sqlite3?
25
+ config.filter_run_excluding :sqlite3 => :skip if SchemaPlusHelpers.sqlite3?
20
26
  end
21
27
 
22
28
  def with_fk_config(opts, &block)
data/spec/views_spec.rb CHANGED
@@ -95,35 +95,52 @@ describe ActiveRecord do
95
95
  end
96
96
  end
97
97
 
98
- if SchemaPlusHelpers.mysql?
99
- context "in mysql" do
100
-
101
- around(:each) do |example|
102
- migration.suppress_messages do
103
- begin
104
- migration.drop_view :check if connection.views.include? 'check'
105
- example.run
106
- ensure
107
- migration.drop_view :check if connection.views.include? 'check'
108
- end
109
- end
110
- end
98
+ context "dropping views" do
99
+ it "should raise an error if the view doesn't exist" do
100
+ expect { migration.drop_view('doesnt_exist') }.to raise_error ActiveRecord::StatementInvalid
101
+ end
111
102
 
112
- it "should introspect WITH CHECK OPTION" do
113
- migration.create_view :check, 'SELECT * FROM items WHERE (a=2) WITH CHECK OPTION'
114
- expect(connection.view_definition('check')).to match(%r{WITH CASCADED CHECK OPTION$})
115
- end
103
+ it "should fail silently when using if_exists option" do
104
+ expect { migration.drop_view('doesnt_exist', :if_exists => true) }.not_to raise_error
105
+ end
106
+
107
+ context "with a view that exists" do
108
+ before { migration.create_view('view_that_exists', 'SELECT * FROM items WHERE (a=1)') }
116
109
 
117
- it "should introspect WITH CASCADED CHECK OPTION" do
118
- migration.create_view :check, 'SELECT * FROM items WHERE (a=2) WITH CASCADED CHECK OPTION'
119
- expect(connection.view_definition('check')).to match(%r{WITH CASCADED CHECK OPTION$})
110
+ it "should succeed" do
111
+ migration.drop_view('view_that_exists')
112
+ expect(connection.views).not_to include('view_that_exists')
120
113
  end
114
+ end
115
+ end
116
+
117
+ context "in mysql", :mysql => :only do
121
118
 
122
- it "should introspect WITH LOCAL CHECK OPTION" do
123
- migration.create_view :check, 'SELECT * FROM items WHERE (a=2) WITH LOCAL CHECK OPTION'
124
- expect(connection.view_definition('check')).to match(%r{WITH LOCAL CHECK OPTION$})
119
+ around(:each) do |example|
120
+ migration.suppress_messages do
121
+ begin
122
+ migration.drop_view :check if connection.views.include? 'check'
123
+ example.run
124
+ ensure
125
+ migration.drop_view :check if connection.views.include? 'check'
126
+ end
125
127
  end
126
- end
128
+ end
129
+
130
+ it "should introspect WITH CHECK OPTION" do
131
+ migration.create_view :check, 'SELECT * FROM items WHERE (a=2) WITH CHECK OPTION'
132
+ expect(connection.view_definition('check')).to match(%r{WITH CASCADED CHECK OPTION$})
133
+ end
134
+
135
+ it "should introspect WITH CASCADED CHECK OPTION" do
136
+ migration.create_view :check, 'SELECT * FROM items WHERE (a=2) WITH CASCADED CHECK OPTION'
137
+ expect(connection.view_definition('check')).to match(%r{WITH CASCADED CHECK OPTION$})
138
+ end
139
+
140
+ it "should introspect WITH LOCAL CHECK OPTION" do
141
+ migration.create_view :check, 'SELECT * FROM items WHERE (a=2) WITH LOCAL CHECK OPTION'
142
+ expect(connection.view_definition('check')).to match(%r{WITH LOCAL CHECK OPTION$})
143
+ end
127
144
  end
128
145
  end
129
146
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ronen Barzel
@@ -9,104 +9,104 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-07 00:00:00.000000000 Z
12
+ date: 2014-09-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '3.2'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '3.2'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: valuable
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rake
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - '>='
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - '>='
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rspec
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ~>
60
+ - - "~>"
61
61
  - !ruby/object:Gem::Version
62
62
  version: 3.0.0
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ~>
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
69
  version: 3.0.0
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rdoc
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - '>='
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - '>='
81
+ - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: simplecov
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - '>='
88
+ - - ">="
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0'
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - '>='
95
+ - - ">="
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: simplecov-gem-profile
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - '>='
102
+ - - ">="
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - '>='
109
+ - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  description: 'SchemaPlus is an ActiveRecord extension that provides enhanced capabilities
@@ -119,9 +119,9 @@ executables: []
119
119
  extensions: []
120
120
  extra_rdoc_files: []
121
121
  files:
122
- - .gitignore
123
- - .rspec
124
- - .travis.yml
122
+ - ".gitignore"
123
+ - ".rspec"
124
+ - ".travis.yml"
125
125
  - CHANGELOG.md
126
126
  - Gemfile
127
127
  - MIT-LICENSE
@@ -175,6 +175,7 @@ files:
175
175
  - spec/connections/mysql2/connection.rb
176
176
  - spec/connections/postgresql/connection.rb
177
177
  - spec/connections/sqlite3/connection.rb
178
+ - spec/enum_spec.rb
178
179
  - spec/foreign_key_definition_spec.rb
179
180
  - spec/foreign_key_spec.rb
180
181
  - spec/index_definition_spec.rb
@@ -201,17 +202,17 @@ require_paths:
201
202
  - lib
202
203
  required_ruby_version: !ruby/object:Gem::Requirement
203
204
  requirements:
204
- - - '>='
205
+ - - ">="
205
206
  - !ruby/object:Gem::Version
206
207
  version: 1.9.2
207
208
  required_rubygems_version: !ruby/object:Gem::Requirement
208
209
  requirements:
209
- - - '>='
210
+ - - ">="
210
211
  - !ruby/object:Gem::Version
211
212
  version: '0'
212
213
  requirements: []
213
214
  rubyforge_project: schema_plus
214
- rubygems_version: 2.0.3
215
+ rubygems_version: 2.2.2
215
216
  signing_key:
216
217
  specification_version: 4
217
218
  summary: Enhances ActiveRecord schema mechanism, including more DRY index creation
@@ -224,6 +225,7 @@ test_files:
224
225
  - spec/connections/mysql2/connection.rb
225
226
  - spec/connections/postgresql/connection.rb
226
227
  - spec/connections/sqlite3/connection.rb
228
+ - spec/enum_spec.rb
227
229
  - spec/foreign_key_definition_spec.rb
228
230
  - spec/foreign_key_spec.rb
229
231
  - spec/index_definition_spec.rb