schema_plus 1.4.0 → 1.4.1

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: 0d5b988ea47657ad4e1be912509f3d17c4c4e329
4
- data.tar.gz: e4fcc4ac3d1ca3003e4a9c7fc1c0a48e687dd197
3
+ metadata.gz: 8356e7e431dc435c954901447ddeee24dfff4b7a
4
+ data.tar.gz: 4a9789ee8e6cdf5845cd6181558b267a8d368064
5
5
  SHA512:
6
- metadata.gz: 4ea4f3e69dd6fd4705146b05123e7ec245414ef77de85382a5ada63bebfce065088d4447ea9f411b82444d33c94d7a9ce6ad96a76061816a7a851023a9672e8f
7
- data.tar.gz: 9251ec18b5b5f416627162c4adecff472c22c82ac23076461d7b8d045f40744f246827da14580c17d5957efb45218a7b235d71ffbcc1092e1b7486a4547cc3f2
6
+ metadata.gz: 13e4f154b793d5c47054eacbffa293b27e2369ddc77cababec864521c67764f7867ef7be006476cbf3dc621f6ea3c2ccffd8cccd1e5254c1116653b2942bc498
7
+ data.tar.gz: acc74c44573cf7b6044cff3f3e25655d771109ec2e397a14dab887622aebea27b3b0bd8ae9ea47f4205e3b480f44a5db22b28df33e1d60fcfbc216dcddb75966
data/README.md CHANGED
@@ -297,6 +297,10 @@ of foreign key constraints, you can re-enable it:
297
297
 
298
298
  * *nothing currently waiting to be released*
299
299
 
300
+ ### 1.4.1
301
+
302
+ * Bug fixes `migration.add_references` with `polymophic: true` (issue #145 and others)
303
+
300
304
  ### 1.4.0
301
305
 
302
306
  * Supports jruby & mysql, thanks to [@rzenha](https://github.com/razenha)
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gemspec :path => File.expand_path('..', __FILE__)
3
+
4
+ gem "byebug" if RUBY_VERSION > "2"
@@ -1,4 +1,3 @@
1
- source 'https://rubygems.org'
1
+ eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
2
 
3
- gemspec :path => File.expand_path('../../..', __FILE__)
4
3
  gem "rails", "~> 3.2.0"
@@ -1,4 +1,3 @@
1
- source 'https://rubygems.org'
1
+ eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
2
 
3
- gemspec :path => File.expand_path('../../..', __FILE__)
4
3
  gem "rails", "~> 4.0.0"
@@ -1,4 +1,3 @@
1
- source 'https://rubygems.org'
1
+ eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
2
 
3
- gemspec :path => File.expand_path('../../..', __FILE__)
4
3
  gem "rails", "~> 4.1.0.beta1"
@@ -1,4 +1,3 @@
1
- source 'https://rubygems.org'
1
+ eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
2
 
3
- gemspec :path => File.expand_path('../../..', __FILE__)
4
3
  gem "rails", "~> 4.0.0"
@@ -83,6 +83,7 @@ module SchemaPlus
83
83
  # are specified simultaneously.
84
84
  #
85
85
  def add_index(table_name, column_name, options = {})
86
+ options = {} if options.nil? # some callers explicitly pass options=nil
86
87
  column_name, options = [], column_name if column_name.is_a?(Hash)
87
88
  column_names = Array(column_name).compact
88
89
  if column_names.empty?
@@ -4,10 +4,16 @@ module SchemaPlus::ActiveRecord::ConnectionAdapters
4
4
  def self.included(base) #:nodoc:
5
5
  base.class_eval do
6
6
  alias_method_chain :create_table, :schema_plus
7
+ alias_method_chain :add_reference, :schema_plus unless ::ActiveRecord::VERSION::MAJOR.to_i < 4
7
8
  include AddIndex
8
9
  end
9
10
  end
10
11
 
12
+ def add_reference_with_schema_plus(table_name, ref_name, options = {}) #:nodoc:
13
+ options[:references] = nil if options[:polymorphic]
14
+ add_reference_without_schema_plus(table_name, ref_name, options)
15
+ end
16
+
11
17
  ##
12
18
  # :method: create_table
13
19
  #
@@ -76,7 +82,7 @@ module SchemaPlus::ActiveRecord::ConnectionAdapters
76
82
  # an error.)
77
83
  #
78
84
  def add_index_with_schema_plus(table, columns, options={})
79
- options.delete(:if_exists)
85
+ options.delete(:if_exists) if options # some callers explcitly pass options=nil
80
86
  add_index_without_schema_plus(table, columns, options)
81
87
  rescue => e
82
88
  SchemaStatements.add_index_exception_handler(self, table, columns, options, e)
@@ -27,8 +27,9 @@ module SchemaPlus
27
27
  # should track it down separately and submit a patch/fix to rails
28
28
  #
29
29
  def add_reference_with_schema_plus(table_name, ref_name, options = {}) #:nodoc:
30
+ options[:references] = nil if options[:polymorphic]
30
31
  # which is the worse hack...?
31
- if RUBY_VERSION >= "2.0.0"
32
+ if RUBY_VERSION >= "2.0.0" and self.delegate.respond_to? :add_reference_sql
32
33
  # .. rebinding a method from a different module? (can't do this in ruby 1.9.3)
33
34
  ::ActiveRecord::ConnectionAdapters::SchemaStatements.instance_method(:add_reference).bind(self).call(table_name, ref_name, options)
34
35
  else
@@ -1,3 +1,3 @@
1
1
  module SchemaPlus
2
- VERSION = "1.4.0"
2
+ VERSION = "1.4.1"
3
3
  end
@@ -14,4 +14,4 @@ ActiveRecord::Base.configurations = {
14
14
 
15
15
  }
16
16
 
17
- ActiveRecord::Base.establish_connection 'schema_plus'
17
+ ActiveRecord::Base.establish_connection :schema_plus
@@ -14,4 +14,4 @@ ActiveRecord::Base.configurations = {
14
14
 
15
15
  }
16
16
 
17
- ActiveRecord::Base.establish_connection 'schema_plus'
17
+ ActiveRecord::Base.establish_connection :schema_plus
@@ -13,4 +13,4 @@ ActiveRecord::Base.configurations = {
13
13
 
14
14
  }
15
15
 
16
- ActiveRecord::Base.establish_connection 'schema_plus'
16
+ ActiveRecord::Base.establish_connection :schema_plus
@@ -11,5 +11,5 @@ ActiveRecord::Base.configurations = {
11
11
 
12
12
  }
13
13
 
14
- ActiveRecord::Base.establish_connection 'schema_plus'
14
+ ActiveRecord::Base.establish_connection :schema_plus
15
15
  ActiveRecord::Base.connection.execute "PRAGMA synchronous = OFF"
@@ -599,6 +599,44 @@ describe ActiveRecord::Migration do
599
599
 
600
600
  end
601
601
 
602
+ context "when add reference" do
603
+
604
+ before(:each) do
605
+ @model = Comment
606
+ end
607
+
608
+ it "should create foreign key" do
609
+ add_reference(:post) do
610
+ @model.should reference(:posts, :id).on(:post_id)
611
+ end
612
+ end
613
+
614
+ it "should not create a foreign_key if polymorphic" do
615
+ add_reference(:post, :polymorphic => true) do
616
+ @model.should_not reference(:posts, :id).on(:post_id)
617
+ end
618
+ end
619
+
620
+ it "should create a two-column index if polymophic and index requested" do
621
+ add_reference(:post, :polymorphic => true, :index => true) do
622
+ @model.should have_index.on([:post_id, :post_type])
623
+ end
624
+ end
625
+
626
+
627
+ protected
628
+ def add_reference(column_name, *args)
629
+ table = @model.table_name
630
+ ActiveRecord::Migration.suppress_messages do
631
+ ActiveRecord::Migration.add_reference(table, column_name, *args)
632
+ @model.reset_column_information
633
+ yield if block_given?
634
+ ActiveRecord::Migration.remove_column(table, "#{column_name}_id")
635
+ end
636
+ end
637
+
638
+ end unless ::ActiveRecord::VERSION::MAJOR.to_i < 4
639
+
602
640
  context "when column is changed" do
603
641
 
604
642
  before(:each) do
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.4.0
4
+ version: 1.4.1
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-02-08 00:00:00.000000000 Z
12
+ date: 2014-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -126,6 +126,7 @@ files:
126
126
  - MIT-LICENSE
127
127
  - README.md
128
128
  - Rakefile
129
+ - gemfiles/Gemfile.base
129
130
  - gemfiles/rails-3.2/Gemfile.base
130
131
  - gemfiles/rails-3.2/Gemfile.mysql
131
132
  - gemfiles/rails-3.2/Gemfile.mysql2