lol_dba 1.6.5 → 1.6.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9641b91bac129bd6c79d4283c72ecaa32dc2f1b
4
- data.tar.gz: dcbdfafeb25f68cf9ed8b330994b148e60279d38
3
+ metadata.gz: ac0b85b66b11cef7a5a9f061f9882e174ebd6873
4
+ data.tar.gz: dc82fa017c77d78ba1d29e2ab7eea95713f0d7a7
5
5
  SHA512:
6
- metadata.gz: 865bc86214659eda2e6ad1b588d57904349ffa34af15c99b2b1baec6a1981b7ddce319a4d16d1cf2dd80c06ad5cfdcf0ead04b55e9b80bc44c1d7e212b127b1a
7
- data.tar.gz: 6364656d074e6e2029d7fc62658d76026b26258ac3274f12183f291394e2e52e48da751c24d5d85bf881032fb51ed59d048d782dfac5f1d1f8299872d6a7c691
6
+ metadata.gz: 4104dea3e0f47a9af87cebd86baa446088b2e4bbebceedadfa57f753fa2e55cccd2c47278ae1906d7d77eb7464c8fb70c75c65e4da3f868bbaddec1fc579af6c
7
+ data.tar.gz: 772690ccc91087cec77b7b2451fdf246638351f3d821b8c581b828bdff64777c9d94847d4d934d8ca9b155a3397b3213f8dd7dedfab6d3a5f4365b576c7a2c2a
data/README.md CHANGED
@@ -74,6 +74,7 @@ All feedback, bug reports and thoughts on this gratefully received.
74
74
  * [Adrian Hooper](https://twitter.com/PaReeOhNos)
75
75
  * [Ray Zane](https://github.com/rzane)
76
76
  * [Grant Gongaware](https://github.com/ggongaware)
77
+ * [Przemysław “Szeryf” Kowalczyk](https://szeryf.wordpress.com)
77
78
  * [Philipp Weissensteiner](http://philippweissensteiner.com)
78
79
 
79
80
  ### License
@@ -28,8 +28,6 @@ EOM
28
28
  # Guess foreign key?
29
29
  if reflection.options[:foreign_key]
30
30
  association_foreign_key = reflection.options[:foreign_key]
31
- elsif reflection.options[:class_name]
32
- association_foreign_key = reflection.options[:class_name].foreign_key
33
31
  else
34
32
  association_foreign_key = "#{target_class.name.tableize.singularize}_id"
35
33
  end
@@ -99,10 +97,10 @@ EOM
99
97
  poly_type = "#{reflection_options.name.to_s}_type"
100
98
  poly_id = "#{reflection_options.name.to_s}_id"
101
99
 
102
- @index_migrations[@table_name.to_s] += [[poly_type, poly_id].sort] unless @index_migrations[@table_name.to_s].include?([poly_type, poly_id].sort)
100
+ @index_migrations[@table_name] += [[poly_type, poly_id].sort] unless @index_migrations[@table_name].include?([poly_type, poly_id].sort)
103
101
  else
104
102
  foreign_key = reflection_options.options[:foreign_key] ||= reflection_options.respond_to?(:primary_key_name) ? reflection_options.primary_key_name : reflection_options.foreign_key
105
- @index_migrations[@table_name.to_s] += [foreign_key] unless @index_migrations[@table_name.to_s].include?(foreign_key)
103
+ @index_migrations[@table_name] += [foreign_key.to_s] unless @index_migrations[@table_name].include?(foreign_key) || reflection_options.options.include?(:class)
106
104
  end
107
105
  when :has_and_belongs_to_many
108
106
  table_name = reflection_options.options[:join_table] ||= [class_name.table_name, reflection_name.to_s].sort.join('_')
@@ -111,8 +109,7 @@ EOM
111
109
 
112
110
  foreign_key = get_through_foreign_key(class_name, reflection_options)
113
111
 
114
- composite_keys = [association_foreign_key, foreign_key]
115
-
112
+ composite_keys = [association_foreign_key, foreign_key].sort
116
113
  @index_migrations[table_name.to_s] += [composite_keys] unless @index_migrations[table_name].include?(composite_keys)
117
114
  when :has_many
118
115
  # has_many tables are threaten by the other side of the relation
@@ -1,3 +1,3 @@
1
1
  module LolDba
2
- VERSION = "1.6.5" unless defined? LolDba::VERSION
2
+ VERSION = "1.6.6" unless defined? LolDba::VERSION
3
3
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe "Collect indexes based on associations:" do
4
4
 
5
- let!(:lol_dba){ LolDba.check_for_indexes }
5
+ let(:lol_dba){ LolDba.check_for_indexes }
6
6
  let(:relationship_indexes){ lol_dba[0] }
7
7
  let(:warning_messages){ lol_dba[1] }
8
8
 
@@ -24,11 +24,17 @@ describe "Collect indexes based on associations:" do
24
24
  end
25
25
 
26
26
  it "find indexes for has_and_belongs_to_many" do
27
- expect(relationship_indexes["companies_freelancers"]).to include(["freelancer_id", "company_id"])
27
+ expect(relationship_indexes["companies_freelancers"]).to include(["company_id", "freelancer_id"])
28
+ expect(relationship_indexes["companies_freelancers"]).not_to include(["freelancer_id", "company_id"])
28
29
  end
29
30
 
30
31
  it "find indexes for has_and_belongs_to_many with custom join_table, primary and foreign keys" do
31
- expect(relationship_indexes["purchases"]).to include(["present_id", "buyer_id"])
32
+ expect(relationship_indexes["purchases"]).to include(["buyer_id", "present_id"])
33
+ expect(relationship_indexes["purchases"]).not_to include(["present_id", "buyer_id"])
34
+ end
35
+
36
+ it "find indexes for has_and_belongs_to_many but don't create the left_side index" do
37
+ expect(relationship_indexes["purchases"]).not_to include("left_side_id")
32
38
  end
33
39
 
34
40
  it "do not add an already existing index" do
@@ -37,6 +43,7 @@ describe "Collect indexes based on associations:" do
37
43
 
38
44
  it "find indexes for has_many :through" do
39
45
  expect(relationship_indexes["billable_weeks"]).to include(["remote_worker_id", "timesheet_id"])
46
+ expect(relationship_indexes["billable_weeks"]).not_to include(["billable_week_id", "remote_worker_id"])
40
47
  end
41
48
 
42
49
  it "find indexes for has_many :through with source and foreign key" do
@@ -64,7 +71,8 @@ describe "Collect indexes based on associations:" do
64
71
 
65
72
  it "find indexes, than use custom class name option in association" do
66
73
  expect(relationship_indexes["employers_freelancers"]).to be_nil
67
- expect(relationship_indexes["companies_freelancers"]).to include(["freelancer_id", "company_id"])
74
+ expect(relationship_indexes["companies_freelancers"]).to include(["company_id", "freelancer_id"])
75
+ expect(relationship_indexes["companies_freelancers"]).not_to include(["freelancer_id", "company_id"])
68
76
  end
69
77
 
70
78
  end
@@ -3,8 +3,4 @@ class Gift < ActiveRecord::Base
3
3
  self.primary_key = :custom_primary_key
4
4
  has_and_belongs_to_many :users, :join_table => "purchases", :association_foreign_key => 'buyer_id', :foreign_key => 'present_id'
5
5
 
6
- def search_all(name, price)
7
- Gift.find_all_by_name_and_price(name, price)
8
- end
9
-
10
- end
6
+ end
@@ -7,11 +7,4 @@ class User < ActiveRecord::Base
7
7
 
8
8
  validates_uniqueness_of :name
9
9
 
10
- def search_via_email(email = "user@domain.com")
11
- self.find_by_email(email)
12
- end
13
-
14
- def search_via_email_and_name(email, name)
15
- self.find_by_email_and_name(email, name)
16
- end
17
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lol_dba
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.5
4
+ version: 1.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Plentz