lol_dba 2.1.0 → 2.1.1
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 +4 -4
- data/Gemfile.lock +1 -1
- data/gemfiles/rails_3_2.gemfile.lock +1 -1
- data/gemfiles/rails_4_0.gemfile.lock +1 -1
- data/gemfiles/rails_4_1.gemfile.lock +1 -1
- data/gemfiles/rails_4_2.gemfile.lock +1 -1
- data/gemfiles/rails_5_0.gemfile.lock +1 -1
- data/lib/lol_dba.rb +3 -2
- data/lib/lol_dba/version.rb +1 -1
- data/spec/associations_index_spec.rb +37 -29
- data/spec/fixtures/app/models/favourite.rb +6 -0
- data/spec/fixtures/app/models/project.rb +6 -0
- data/spec/fixtures/app/models/user.rb +4 -0
- data/spec/fixtures/schema.rb +9 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 095775b96e5bc0e22e261e1e55fc03d3f2c0dc94
|
4
|
+
data.tar.gz: 84ae3baeef1d90f247acde65f52518d3b2c4079d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38aa20f992b87c89f3635dbded75b1236f09872a68f1c25268328fb5fb1b6acb5dd69fd428c7021759b3df8cd9613fe9afb871c6a253835d64762ea94f4b1c37
|
7
|
+
data.tar.gz: 481dfd01822e773ae806f85654a99e7bddf32fd60827cb60a133fd02edf61bc8cef9d6d0ee7735ba8dc639d4d31ca43019d0c0f80f18e01b4238dab82a9698ad
|
data/Gemfile.lock
CHANGED
data/lib/lol_dba.rb
CHANGED
@@ -127,8 +127,9 @@ EOM
|
|
127
127
|
foreign_key = get_through_foreign_key(class_name, reflection_options)
|
128
128
|
|
129
129
|
if source = reflection_options.options[:source]
|
130
|
-
|
131
|
-
|
130
|
+
association_reflection = through_class.reflections.stringify_keys[source.to_s]
|
131
|
+
next if association_reflection.options[:polymorphic]
|
132
|
+
association_foreign_key = get_through_foreign_key(association_reflection.klass, reflection_options)
|
132
133
|
elsif through_reflections = through_class.reflections.stringify_keys[reflection_name.singularize]
|
133
134
|
# go to joining model through has_many and find belongs_to
|
134
135
|
association_foreign_key = through_reflections.options[:foreign_key]
|
data/lib/lol_dba/version.rb
CHANGED
@@ -2,80 +2,88 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Collect indexes based on associations:" do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
before :all do
|
6
|
+
lol_dba = LolDba.check_for_indexes
|
7
|
+
@relationship_indexes = lol_dba[0]
|
8
|
+
@warning_messages = lol_dba[1]
|
9
|
+
end
|
8
10
|
|
9
11
|
it "find relationship indexes" do
|
10
|
-
expect(relationship_indexes).not_to be_empty
|
12
|
+
expect(@relationship_indexes).not_to be_empty
|
11
13
|
|
12
|
-
expect(relationship_indexes).to have_key("companies")
|
13
|
-
expect(relationship_indexes).to have_key("companies_freelancers")
|
14
|
-
expect(relationship_indexes).to have_key("addresses")
|
15
|
-
expect(relationship_indexes).to have_key("purchases")
|
14
|
+
expect(@relationship_indexes).to have_key("companies")
|
15
|
+
expect(@relationship_indexes).to have_key("companies_freelancers")
|
16
|
+
expect(@relationship_indexes).to have_key("addresses")
|
17
|
+
expect(@relationship_indexes).to have_key("purchases")
|
16
18
|
end
|
17
19
|
|
18
20
|
it "find indexes for belongs_to" do
|
19
|
-
expect(relationship_indexes["addresses"]).to include("country_id")
|
21
|
+
expect(@relationship_indexes["addresses"]).to include("country_id")
|
20
22
|
end
|
21
23
|
|
22
24
|
it "find indexes for polymorphic belongs_to" do
|
23
|
-
expect(relationship_indexes["addresses"]).to include(["addressable_id", "addressable_type"])
|
25
|
+
expect(@relationship_indexes["addresses"]).to include(["addressable_id", "addressable_type"])
|
24
26
|
end
|
25
27
|
|
26
28
|
it "find indexes for belongs_to with custom foreign key" do
|
27
|
-
expect(relationship_indexes["companies"]).to include("owner_id")
|
29
|
+
expect(@relationship_indexes["companies"]).to include("owner_id")
|
28
30
|
end
|
29
31
|
|
30
32
|
it "find indexes for has_and_belongs_to_many" do
|
31
|
-
expect(relationship_indexes["companies_freelancers"]).to include(["company_id", "freelancer_id"])
|
32
|
-
expect(relationship_indexes["companies_freelancers"]).not_to include(["freelancer_id", "company_id"])
|
33
|
+
expect(@relationship_indexes["companies_freelancers"]).to include(["company_id", "freelancer_id"])
|
34
|
+
expect(@relationship_indexes["companies_freelancers"]).not_to include(["freelancer_id", "company_id"])
|
33
35
|
end
|
34
36
|
|
35
37
|
it "find indexes for has_and_belongs_to_many with custom join_table, primary and foreign keys" do
|
36
|
-
expect(relationship_indexes["purchases"]).to include(["buyer_id", "present_id"])
|
38
|
+
expect(@relationship_indexes["purchases"]).to include(["buyer_id", "present_id"])
|
37
39
|
end
|
38
40
|
|
39
41
|
it "find indexes for has_and_belongs_to_many but don't create the left_side index" do
|
40
|
-
expect(relationship_indexes["purchases"]).not_to include("left_side_id")
|
42
|
+
expect(@relationship_indexes["purchases"]).not_to include("left_side_id")
|
41
43
|
end
|
42
44
|
|
43
45
|
it "do not add an already existing index" do
|
44
|
-
expect(relationship_indexes["companies"]).not_to include("country_id")
|
46
|
+
expect(@relationship_indexes["companies"]).not_to include("country_id")
|
45
47
|
end
|
46
48
|
|
47
49
|
it "find indexes for has_many :through" do
|
48
|
-
expect(relationship_indexes["billable_weeks"]).to include("remote_worker_id", "timesheet_id")
|
49
|
-
expect(relationship_indexes["billable_weeks"]).not_to include(["billable_week_id", "remote_worker_id"])
|
50
|
+
expect(@relationship_indexes["billable_weeks"]).to include("remote_worker_id", "timesheet_id")
|
51
|
+
expect(@relationship_indexes["billable_weeks"]).not_to include(["billable_week_id", "remote_worker_id"])
|
50
52
|
end
|
51
53
|
|
52
54
|
it "find indexes for has_many :through with source and foreign key" do
|
53
|
-
expect(relationship_indexes["complex_billable_week"]).to include(["freelancer_id", "id_complex_timesheet"])
|
55
|
+
expect(@relationship_indexes["complex_billable_week"]).to include(["freelancer_id", "id_complex_timesheet"])
|
54
56
|
end
|
55
57
|
|
56
58
|
it "do not include wrong class" do
|
57
|
-
expect(relationship_indexes["wrongs"]).to be_nil
|
58
|
-
expect(relationship_indexes["addresses_wrongs"]).to be_nil
|
59
|
+
expect(@relationship_indexes["wrongs"]).to be_nil
|
60
|
+
expect(@relationship_indexes["addresses_wrongs"]).to be_nil
|
59
61
|
end
|
60
62
|
|
61
63
|
it "have warnings(non-existent table) on test data" do
|
62
|
-
expect(warning_messages).not_to be_empty
|
63
|
-
expect(warning_messages).to match(/\'wrongs\'/)
|
64
|
-
expect(warning_messages).to match(/\'addresses_wrongs\'/)
|
64
|
+
expect(@warning_messages).not_to be_empty
|
65
|
+
expect(@warning_messages).to match(/\'wrongs\'/)
|
66
|
+
expect(@warning_messages).to match(/\'addresses_wrongs\'/)
|
65
67
|
end
|
66
68
|
|
67
69
|
it "find indexes for STI" do
|
68
|
-
expect(relationship_indexes["users"]).to include(["id", "type"])
|
70
|
+
expect(@relationship_indexes["users"]).to include(["id", "type"])
|
69
71
|
end
|
70
72
|
|
71
73
|
it "find indexes for STI with custom inheritance column" do
|
72
|
-
expect(relationship_indexes["freelancers"]).to include(["id", "worker_type"])
|
74
|
+
expect(@relationship_indexes["freelancers"]).to include(["id", "worker_type"])
|
73
75
|
end
|
74
76
|
|
75
77
|
it "find indexes, than use custom class name option in association" do
|
76
|
-
expect(relationship_indexes["employers_freelancers"]).to be_nil
|
77
|
-
expect(relationship_indexes["companies_freelancers"]).to include(["company_id", "freelancer_id"])
|
78
|
-
expect(relationship_indexes["companies_freelancers"]).not_to include(["freelancer_id", "company_id"])
|
78
|
+
expect(@relationship_indexes["employers_freelancers"]).to be_nil
|
79
|
+
expect(@relationship_indexes["companies_freelancers"]).to include(["company_id", "freelancer_id"])
|
80
|
+
expect(@relationship_indexes["companies_freelancers"]).not_to include(["freelancer_id", "company_id"])
|
79
81
|
end
|
80
82
|
|
83
|
+
it "HABTM with polymorphic relationship" do
|
84
|
+
expect(@relationship_indexes["favourites"]).to include("user_id")
|
85
|
+
expect(@relationship_indexes["favourites"]).to include(["favourable_id", "favourable_type"])
|
86
|
+
expect(@relationship_indexes["favourites"]).not_to include(["project_id", "user_id"])
|
87
|
+
expect(@relationship_indexes["favourites"]).not_to include(["project_id", "worker_user_id"])
|
88
|
+
end
|
81
89
|
end
|
@@ -5,6 +5,10 @@ class User < ActiveRecord::Base
|
|
5
5
|
|
6
6
|
has_and_belongs_to_many :users, join_table: :purchases, association_foreign_key: :present_id, foreign_key: :buyer_id
|
7
7
|
|
8
|
+
has_many :projects
|
9
|
+
has_many :favourites
|
10
|
+
has_many :favourite_projects, through: :favourites, source: :favourable, source_type: 'Project'
|
11
|
+
|
8
12
|
validates_uniqueness_of :name
|
9
13
|
|
10
14
|
end
|
data/spec/fixtures/schema.rb
CHANGED
@@ -78,5 +78,14 @@ ActiveRecord::Schema.define do
|
|
78
78
|
create_table "groups", force: :cascade do |t|
|
79
79
|
end
|
80
80
|
|
81
|
+
create_table "projects", :force => true do |t|
|
82
|
+
t.column "name", :string
|
83
|
+
t.column "user_id", :integer
|
84
|
+
end
|
81
85
|
|
86
|
+
create_table "favourites", :force => true do |t|
|
87
|
+
t.column "user_id", :integer
|
88
|
+
t.column "favourable_id", :integer
|
89
|
+
t.column "favourable_type", :string
|
90
|
+
end
|
82
91
|
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: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diego Plentz
|
@@ -119,11 +119,13 @@ files:
|
|
119
119
|
- spec/fixtures/app/models/complex_timesheet.rb
|
120
120
|
- spec/fixtures/app/models/component.rb
|
121
121
|
- spec/fixtures/app/models/country.rb
|
122
|
+
- spec/fixtures/app/models/favourite.rb
|
122
123
|
- spec/fixtures/app/models/freelancer.rb
|
123
124
|
- spec/fixtures/app/models/gift.rb
|
124
125
|
- spec/fixtures/app/models/god.rb
|
125
126
|
- spec/fixtures/app/models/group.rb
|
126
127
|
- spec/fixtures/app/models/group_component.rb
|
128
|
+
- spec/fixtures/app/models/project.rb
|
127
129
|
- spec/fixtures/app/models/timesheet.rb
|
128
130
|
- spec/fixtures/app/models/user.rb
|
129
131
|
- spec/fixtures/app/models/worker.rb
|
@@ -167,11 +169,13 @@ test_files:
|
|
167
169
|
- spec/fixtures/app/models/complex_timesheet.rb
|
168
170
|
- spec/fixtures/app/models/component.rb
|
169
171
|
- spec/fixtures/app/models/country.rb
|
172
|
+
- spec/fixtures/app/models/favourite.rb
|
170
173
|
- spec/fixtures/app/models/freelancer.rb
|
171
174
|
- spec/fixtures/app/models/gift.rb
|
172
175
|
- spec/fixtures/app/models/god.rb
|
173
176
|
- spec/fixtures/app/models/group.rb
|
174
177
|
- spec/fixtures/app/models/group_component.rb
|
178
|
+
- spec/fixtures/app/models/project.rb
|
175
179
|
- spec/fixtures/app/models/timesheet.rb
|
176
180
|
- spec/fixtures/app/models/user.rb
|
177
181
|
- spec/fixtures/app/models/worker.rb
|