schema_plus 1.8.1 → 1.8.2

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
2
  SHA1:
3
- metadata.gz: f00387f0bf66660aab6b1f709a62fce866066d56
4
- data.tar.gz: 5ade39b8c3bc992972ee8abbebfd875a5184da5a
3
+ metadata.gz: c0fa513513788b541ef9a1f0f9bc50ca6f3360e5
4
+ data.tar.gz: 26caef3cbcf5b870bd4484e903d57d33ff999b15
5
5
  SHA512:
6
- metadata.gz: 4108531c8c1eba2925ceca04f2e40d859f53cbd9c8f32a45630cd4f29435cc593378ea18bbb188cf5bc7f1344ebe840802987b5909bbea63f7ac877bf889b765
7
- data.tar.gz: 70f615c970117764694a12739e2fa461a88775fff9e9d969106558cb4c71e994e6a8dd6be8386a31b42d7e4ebf7b277b3bb3b42487d2c79fb3027506cb825032
6
+ metadata.gz: cd84595cfdb830f928a4f06bb6dc13960ca144121b5f4dd88d29415a540807f36e0b7d5abe1f5f34d34e2421b482755ec42a0111a4a5ed67f072836fb6f4f881
7
+ data.tar.gz: 1d7350d3629ae83ace5180dd907c6dbf76fe6b33ffc31d3196888530bfe3fb5e89a4cb1545df110ab67457a552c58ccd1365f579dc1fe8865fcda96ff80480cb
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Change Log
4
4
 
5
+ ## 1.8.2
6
+
7
+ * Bug fix when using t.references in change_table (#194). Thanks to [@boone](https://github.com/boone)
8
+
5
9
  ## 1.8.1
6
10
 
7
11
  * Bug fix for AR 4.2, spurious add_foreign_key statements at the top of schema dump. Thanks to [@tovodeverett](https://github.com/tovodeverett) for doing better testing than me!
data/README.md CHANGED
@@ -1,5 +1,11 @@
1
+ > ## This is the README for schema_plus 1.8.x
2
+ > which supports Rails 3.2, 4.0, 4.1, and 4.2. Ongoing development towards schema_plus 2.0 takes place in the [master branch](https://github.com/SchemaPlus/schema_plus/tree/master), supporting only Rails >= 4.2
3
+
4
+ ---
5
+
1
6
  # SchemaPlus
2
7
 
8
+
3
9
  SchemaPlus is an ActiveRecord extension that provides enhanced capabilities
4
10
  for schema definition and querying, including: enhanced and more DRY index
5
11
  capabilities, support and automation for foreign key constraints, and support
@@ -2,17 +2,19 @@ module SchemaPlus::ActiveRecord
2
2
  module ColumnOptionsHandler
3
3
  def schema_plus_normalize_column_options(options)
4
4
  # replace some shortcuts with full versions
5
- case options[:index]
6
- when true then options[:index] = {}
7
- when :unique then options[:index] = { :unique => true }
8
- when Hash
9
- if options[:index][:length].is_a? Hash
10
- normalize = if "#{::ActiveRecord::VERSION::MAJOR}.#{::ActiveRecord::VERSION::MINOR}".to_r >= "4.2".to_r
11
- :stringify_keys!
12
- else
13
- :symbolize_keys!
14
- end
15
- options[:index][:length].send normalize
5
+ [:index, :_index].each do |key|
6
+ case options[key]
7
+ when true then options[key] = {}
8
+ when :unique then options[key] = { :unique => true }
9
+ when Hash
10
+ if options[key][:length].is_a? Hash
11
+ normalize = if "#{::ActiveRecord::VERSION::MAJOR}.#{::ActiveRecord::VERSION::MINOR}".to_r >= "4.2".to_r
12
+ :stringify_keys!
13
+ else
14
+ :symbolize_keys!
15
+ end
16
+ options[key][:length].send normalize
17
+ end
16
18
  end
17
19
  end
18
20
  end
@@ -54,8 +54,8 @@ module SchemaPlus::ActiveRecord::ConnectionAdapters
54
54
  end
55
55
 
56
56
  def add_index_options_with_schema_plus(table_name, column_name, options = {})
57
- columns = options.delete(:with) { |_| [] }
58
- add_index_options_without_schema_plus(table_name, Array(column_name).concat(Array(columns).map(&:to_s)), options)
57
+ with_columns = options.delete(:with) { |_| [] }
58
+ add_index_options_without_schema_plus(table_name, Array(column_name).concat(Array(with_columns).map(&:to_s)), options)
59
59
  end
60
60
 
61
61
  def self.add_index_exception_handler(connection, table, columns, options, e) #:nodoc:
@@ -40,7 +40,7 @@ module SchemaPlus
40
40
  index_options = options.delete(:index)
41
41
  add_column(table_name, "#{ref_name}_id", :integer, options)
42
42
  add_column(table_name, "#{ref_name}_type", :string, polymorphic.is_a?(Hash) ? polymorphic : options) if polymorphic
43
- add_index(table_name, polymorphic ? %w[id type].map{ |t| "#{ref_name}_#{t}" } : "#{ref_name}_id", index_options.is_a?(Hash) ? index_options : nil) if index_options
43
+ add_index(table_name, polymorphic ? %w[id type].map{ |t| "#{ref_name}_#{t}" } : "#{ref_name}_id", index_options.is_a?(Hash) ? index_options : {}) if index_options
44
44
  end
45
45
 
46
46
  self
@@ -1,3 +1,3 @@
1
1
  module SchemaPlus
2
- VERSION = "1.8.1"
2
+ VERSION = "1.8.2"
3
3
  end
@@ -32,7 +32,7 @@ describe "Column" do
32
32
 
33
33
  context "if not unique" do
34
34
 
35
- before (:each) do
35
+ before(:each) do
36
36
  create_table(User, :login => { :index => true})
37
37
  @login = User.columns.find{|column| column.name == "login"}
38
38
  end
@@ -48,7 +48,7 @@ describe "Column" do
48
48
  end
49
49
 
50
50
  context "if unique single column" do
51
- before (:each) do
51
+ before(:each) do
52
52
  create_table(User, :login => { :index => :unique})
53
53
  @login = User.columns.find{|column| column.name == "login"}
54
54
  end
@@ -64,7 +64,7 @@ describe "Column" do
64
64
 
65
65
  context "if unique multicolumn" do
66
66
 
67
- before (:each) do
67
+ before(:each) do
68
68
  create_table(User, :first => {}, :middle => {}, :last => { :index => {:with => [:first, :middle], :unique => true}})
69
69
  @first = User.columns.find{|column| column.name == "first"}
70
70
  @middle = User.columns.find{|column| column.name == "middle"}
@@ -482,6 +482,16 @@ describe ActiveRecord::Migration do
482
482
  expect(@model).to reference(:users, :id).on(:user_id)
483
483
  end
484
484
 
485
+ it "should accept index shorthand when using :references"+suffix, :sqlite3 => :skip do
486
+ with_fk_config(:auto_index => false) do
487
+ change_table(@model, :bulk => bulk) do |t|
488
+ t.references :user, :index => true
489
+ end
490
+ end
491
+ expect(@model).to have_index.on(:user_id)
492
+ end
493
+
494
+
485
495
  it "should create a foreign key constraint using :belongs_to"+suffix, :sqlite3 => :skip do
486
496
  change_table(@model, :bulk => bulk) do |t|
487
497
  t.belongs_to :user
@@ -188,7 +188,7 @@ describe "with multiple schemas" do
188
188
  end
189
189
  end
190
190
 
191
- around (:each) do |example|
191
+ around(:each) do |example|
192
192
  begin
193
193
  connection.execute "SET search_path to '$user','public','postgis'"
194
194
  example.run
@@ -259,7 +259,7 @@ describe "Schema dump" do
259
259
  end
260
260
 
261
261
  context "with cyclic foreign key constraints", :sqlite3 => :skip do
262
- before (:all) do
262
+ before(:all) do
263
263
  ActiveRecord::Base.connection.add_foreign_key(Comment.table_name, :commenter_id, User.table_name, :id)
264
264
  ActiveRecord::Base.connection.add_foreign_key(Comment.table_name, :post_id, Post.table_name, :id)
265
265
  ActiveRecord::Base.connection.add_foreign_key(Post.table_name, :first_comment_id, Comment.table_name, :id)
@@ -19,7 +19,7 @@ describe ActiveRecord do
19
19
 
20
20
  context "views" do
21
21
 
22
- around (:each) do |example|
22
+ around(:each) do |example|
23
23
  define_schema_and_data
24
24
  example.run
25
25
  drop_definitions
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.8.1
4
+ version: 1.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ronen Barzel
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-31 00:00:00.000000000 Z
12
+ date: 2015-01-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord