lol_dba 2.1.5 → 2.1.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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +179 -0
  3. data/.gitignore +1 -1
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +7 -0
  6. data/.travis.yml +16 -9
  7. data/Appraisals +19 -12
  8. data/Gemfile +1 -8
  9. data/Gemfile.lock +60 -59
  10. data/README.md +5 -2
  11. data/Rakefile +4 -4
  12. data/bin/lol_dba +2 -2
  13. data/gemfiles/rails_3_2.gemfile +0 -3
  14. data/gemfiles/rails_3_2.gemfile.lock +33 -31
  15. data/gemfiles/rails_4_0.gemfile +0 -3
  16. data/gemfiles/rails_4_0.gemfile.lock +31 -27
  17. data/gemfiles/rails_4_1.gemfile +0 -3
  18. data/gemfiles/rails_4_1.gemfile.lock +29 -26
  19. data/gemfiles/rails_4_2.gemfile +0 -3
  20. data/gemfiles/rails_4_2.gemfile.lock +52 -48
  21. data/gemfiles/rails_5_0.gemfile +0 -3
  22. data/gemfiles/rails_5_0.gemfile.lock +55 -51
  23. data/gemfiles/rails_5_1.gemfile +0 -3
  24. data/gemfiles/rails_5_1.gemfile.lock +57 -53
  25. data/gemfiles/rails_5_2.gemfile +9 -0
  26. data/gemfiles/rails_5_2.gemfile.lock +115 -0
  27. data/lib/lol_dba/cli.rb +26 -15
  28. data/lib/lol_dba/index_finding/belongs_to.rb +32 -0
  29. data/lib/lol_dba/index_finding/error_logging.rb +15 -0
  30. data/lib/lol_dba/index_finding/has_and_belongs_to_many.rb +20 -0
  31. data/lib/lol_dba/index_finding/has_many.rb +47 -0
  32. data/lib/lol_dba/index_finding/index_finder.rb +81 -0
  33. data/lib/lol_dba/index_finding/migration_formatter.rb +50 -0
  34. data/lib/lol_dba/index_finding/relation_inspector.rb +30 -0
  35. data/lib/lol_dba/index_finding/relation_inspector_factory.rb +13 -0
  36. data/lib/lol_dba/rails_compatibility.rb +47 -0
  37. data/lib/lol_dba/railtie.rb +2 -2
  38. data/lib/lol_dba/sql_migrations/migration.rb +51 -0
  39. data/lib/lol_dba/sql_migrations/migration_mocker.rb +70 -0
  40. data/lib/lol_dba/sql_migrations/sql_generator.rb +49 -0
  41. data/lib/lol_dba/sql_migrations/writer.rb +29 -0
  42. data/lib/lol_dba/version.rb +1 -1
  43. data/lib/lol_dba.rb +14 -188
  44. data/lib/tasks/lol_dba.rake +7 -8
  45. data/lol_dba.gemspec +19 -16
  46. data/spec/associations_index_spec.rb +43 -56
  47. data/spec/fixtures/app/models/address.rb +0 -1
  48. data/spec/fixtures/app/models/billable_week.rb +1 -3
  49. data/spec/fixtures/app/models/company.rb +0 -1
  50. data/spec/fixtures/app/models/complex_billable_week.rb +0 -1
  51. data/spec/fixtures/app/models/complex_timesheet.rb +0 -1
  52. data/spec/fixtures/app/models/country.rb +1 -1
  53. data/spec/fixtures/app/models/favourite.rb +0 -2
  54. data/spec/fixtures/app/models/freelancer.rb +1 -3
  55. data/spec/fixtures/app/models/gift.rb +0 -2
  56. data/spec/fixtures/app/models/god.rb +1 -1
  57. data/spec/fixtures/app/models/project.rb +0 -2
  58. data/spec/fixtures/app/models/timesheet.rb +1 -3
  59. data/spec/fixtures/app/models/user.rb +0 -2
  60. data/spec/fixtures/app/models/worker.rb +0 -1
  61. data/spec/fixtures/app/models/worker_user.rb +2 -3
  62. data/spec/fixtures/schema.rb +53 -53
  63. data/spec/migration_formatter_spec.rb +66 -0
  64. data/spec/spec_helper.rb +17 -9
  65. data/spec/sql_generator_spec.rb +9 -0
  66. metadata +88 -19
  67. data/lib/lol_dba/migration.rb +0 -40
  68. data/lib/lol_dba/sql_generator.rb +0 -96
  69. data/lib/lol_dba/writer.rb +0 -25
  70. data/spec/common_function_spec.rb +0 -96
@@ -1,89 +1,76 @@
1
- require 'spec_helper'
1
+ RSpec.describe 'Collect indexes based on associations:' do
2
+ let (:indexes) { LolDba::IndexFinder.check_for_indexes }
2
3
 
3
- RSpec.describe "Collect indexes based on associations:" do
4
+ it 'find relationship indexes' do
5
+ expect(indexes).not_to be_empty
4
6
 
5
- before :all do
6
- lol_dba = LolDba.check_for_indexes
7
- @relationship_indexes = lol_dba[0]
8
- @warning_messages = lol_dba[1]
7
+ expect(indexes).to have_key('companies')
8
+ expect(indexes).to have_key('companies_freelancers')
9
+ expect(indexes).to have_key('addresses')
10
+ expect(indexes).to have_key('purchases')
9
11
  end
10
12
 
11
- it "find relationship indexes" do
12
- expect(@relationship_indexes).not_to be_empty
13
-
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")
18
- end
19
-
20
- it "find indexes for belongs_to" do
21
- expect(@relationship_indexes["addresses"]).to include("country_id")
22
- expect(@relationship_indexes["favourites"]).to include("user_id")
13
+ it 'find indexes for belongs_to' do
14
+ expect(indexes['addresses']).to include('country_id')
15
+ expect(indexes['favourites']).to include('user_id')
23
16
  end
24
17
 
25
- it "find indexes for polymorphic belongs_to" do
26
- expect(@relationship_indexes["addresses"]).to include(["addressable_id", "addressable_type"])
18
+ it 'find indexes for polymorphic belongs_to' do
19
+ expect(indexes['addresses']).to include(%w[addressable_id addressable_type])
27
20
  end
28
21
 
29
- it "find indexes for belongs_to with custom foreign key" do
30
- expect(@relationship_indexes["companies"]).to include("owner_id")
22
+ it 'find indexes for belongs_to with custom foreign key' do
23
+ expect(indexes['companies']).to include('owner_id')
31
24
  end
32
25
 
33
- it "find indexes for has_and_belongs_to_many" do
34
- expect(@relationship_indexes["companies_freelancers"]).to include(["company_id", "freelancer_id"])
35
- expect(@relationship_indexes["companies_freelancers"]).not_to include(["freelancer_id", "company_id"])
26
+ it 'find indexes for has_and_belongs_to_many' do
27
+ expect(indexes['companies_freelancers']).to include(%w[company_id freelancer_id])
28
+ expect(indexes['companies_freelancers']).not_to include(%w[freelancer_id company_id])
36
29
  end
37
30
 
38
- it "find indexes for has_and_belongs_to_many with custom join_table, primary and foreign keys" do
39
- expect(@relationship_indexes["purchases"]).to include(["buyer_id", "present_id"])
31
+ it 'find indexes for has_and_belongs_to_many with custom join_table, primary and foreign keys' do
32
+ expect(indexes['purchases']).to include(%w[buyer_id present_id])
40
33
  end
41
34
 
42
35
  it "find indexes for has_and_belongs_to_many but don't create the left_side index" do
43
- expect(@relationship_indexes["purchases"]).not_to include("left_side_id")
44
- end
45
-
46
- it "do not add an already existing index" do
47
- expect(@relationship_indexes["companies"]).not_to include("country_id")
36
+ expect(indexes['purchases']).not_to include('left_side_id')
48
37
  end
49
38
 
50
- it "find indexes for has_many :through" do
51
- expect(@relationship_indexes["billable_weeks"]).to include("remote_worker_id", "timesheet_id")
52
- expect(@relationship_indexes["billable_weeks"]).not_to include(["billable_week_id", "remote_worker_id"])
39
+ it 'do not add an already existing index' do
40
+ expect(indexes['companies']).not_to include('country_id')
53
41
  end
54
42
 
55
- it "find indexes for has_many :through with source and foreign key" do
56
- expect(@relationship_indexes["complex_billable_week"]).to include(["freelancer_id", "id_complex_timesheet"])
43
+ it 'find indexes for has_many :through' do
44
+ expect(indexes['billable_weeks']).to include('remote_worker_id', 'timesheet_id')
45
+ expect(indexes['billable_weeks']).not_to include(%w[billable_week_id remote_worker_id])
57
46
  end
58
47
 
59
- it "do not include wrong class" do
60
- expect(@relationship_indexes["wrongs"]).to be_nil
61
- expect(@relationship_indexes["addresses_wrongs"]).to be_nil
48
+ it 'find indexes for has_many :through with source and foreign key' do
49
+ expect(indexes['complex_billable_week']).to include(%w[freelancer_id id_complex_timesheet])
62
50
  end
63
51
 
64
- it "have warnings(non-existent table) on test data" do
65
- expect(@warning_messages).not_to be_empty
66
- expect(@warning_messages).to match(/\'wrongs\'/)
67
- expect(@warning_messages).to match(/\'addresses_wrongs\'/)
52
+ it 'do not include wrong class' do
53
+ expect(indexes['wrongs']).to be_nil
54
+ expect(indexes['addresses_wrongs']).to be_nil
68
55
  end
69
56
 
70
- it "find indexes for STI" do
71
- expect(@relationship_indexes["users"]).to include(["id", "type"])
57
+ it 'find indexes for STI' do
58
+ expect(indexes['users']).to include(%w[id type])
72
59
  end
73
60
 
74
- it "find indexes for STI with custom inheritance column" do
75
- expect(@relationship_indexes["freelancers"]).to include(["id", "worker_type"])
61
+ it 'find indexes for STI with custom inheritance column' do
62
+ expect(indexes['freelancers']).to include(%w[id worker_type])
76
63
  end
77
64
 
78
- it "find indexes, than use custom class name option in association" do
79
- expect(@relationship_indexes["employers_freelancers"]).to be_nil
80
- expect(@relationship_indexes["companies_freelancers"]).to include(["company_id", "freelancer_id"])
81
- expect(@relationship_indexes["companies_freelancers"]).not_to include(["freelancer_id", "company_id"])
65
+ it 'find indexes, than use custom class name option in association' do
66
+ expect(indexes['employers_freelancers']).to be_nil
67
+ expect(indexes['companies_freelancers']).to include(%w[company_id freelancer_id])
68
+ expect(indexes['companies_freelancers']).not_to include(%w[freelancer_id company_id])
82
69
  end
83
70
 
84
- it "create index for HABTM with polymorphic relationship" do
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"])
71
+ it 'create index for HABTM with polymorphic relationship' do
72
+ expect(indexes['favourites']).to include(%w[favourable_id favourable_type])
73
+ expect(indexes['favourites']).not_to include(%w[project_id user_id])
74
+ expect(indexes['favourites']).not_to include(%w[project_id worker_user_id])
88
75
  end
89
76
  end
@@ -1,5 +1,4 @@
1
1
  class Address < ActiveRecord::Base
2
-
3
2
  belongs_to :addressable, polymorphic: true
4
3
  belongs_to :country
5
4
  end
@@ -1,6 +1,4 @@
1
1
  class BillableWeek < ActiveRecord::Base
2
-
3
- belongs_to :remote_worker, class_name: "Freelancer"
2
+ belongs_to :remote_worker, class_name: 'Freelancer'
4
3
  belongs_to :timesheet
5
-
6
4
  end
@@ -1,5 +1,4 @@
1
1
  class Company < ActiveRecord::Base
2
-
3
2
  belongs_to :owner, foreign_key: :owner_id, class_name: 'User'
4
3
  belongs_to :country
5
4
 
@@ -5,5 +5,4 @@ class ComplexBillableWeek < ActiveRecord::Base
5
5
 
6
6
  belongs_to :slave, class_name: 'Freelancer'
7
7
  belongs_to :complex_timesheet, foreign_key: :id_complex_timesheet
8
-
9
8
  end
@@ -3,5 +3,4 @@ class ComplexTimesheet < ActiveRecord::Base
3
3
 
4
4
  has_many :complex_billable_weeks, foreign_key: :id_complex_timesheet
5
5
  has_many :workers, through: :complex_billable_weeks, source: :slave
6
-
7
6
  end
@@ -1,4 +1,4 @@
1
1
  class Country < ActiveRecord::Base
2
2
  has_many :addresses
3
3
  has_many :companies
4
- end
4
+ end
@@ -1,6 +1,4 @@
1
1
  class Favourite < ActiveRecord::Base
2
-
3
2
  belongs_to :user
4
3
  belongs_to :favourable, polymorphic: true
5
-
6
4
  end
@@ -1,8 +1,7 @@
1
1
  class Freelancer < ActiveRecord::Base
2
-
3
2
  self.inheritance_column = 'worker_type'
4
3
  # use for testing custom class_name FK
5
- has_and_belongs_to_many :employers, class_name: "Company"
4
+ has_and_belongs_to_many :employers, class_name: 'Company'
6
5
 
7
6
  has_many :billable_weeks, foreign_key: :remote_worker_id
8
7
  has_many :timesheets, through: :billable_weeks
@@ -10,5 +9,4 @@ class Freelancer < ActiveRecord::Base
10
9
  # Use for testing custom has_many :through
11
10
  has_many :complex_billable_weeks
12
11
  has_many :complex_timesheets, through: :complex_billable_weeks
13
-
14
12
  end
@@ -1,6 +1,4 @@
1
1
  class Gift < ActiveRecord::Base
2
-
3
2
  self.primary_key = :custom_primary_key
4
3
  has_and_belongs_to_many :users, join_table: :purchases, association_foreign_key: :buyer_id, foreign_key: :present_id
5
-
6
4
  end
@@ -1,3 +1,3 @@
1
1
  class God < ActiveRecord::Base
2
2
  self.abstract_class = true
3
- end
3
+ end
@@ -1,6 +1,4 @@
1
1
  class Project < ActiveRecord::Base
2
-
3
2
  belongs_to :user
4
3
  has_many :favourites, as: :favourable
5
-
6
4
  end
@@ -1,6 +1,4 @@
1
1
  class Timesheet < ActiveRecord::Base
2
-
3
- has_many :paiment_weeks, class_name: "BillableWeek"
2
+ has_many :paiment_weeks, class_name: 'BillableWeek'
4
3
  has_many :remote_workers, through: :paiment_weeks
5
-
6
4
  end
@@ -1,5 +1,4 @@
1
1
  class User < ActiveRecord::Base
2
-
3
2
  has_one :company, foreign_key: :owner_id
4
3
  has_one :address, as: :addressable
5
4
 
@@ -10,5 +9,4 @@ class User < ActiveRecord::Base
10
9
  has_many :favourite_projects, through: :favourites, source: :favourable, source_type: 'Project'
11
10
 
12
11
  validates_uniqueness_of :name
13
-
14
12
  end
@@ -1,4 +1,3 @@
1
1
  # Check custom STI
2
2
  class Worker < Freelancer
3
-
4
3
  end
@@ -1,4 +1,3 @@
1
- #Test STI
1
+ # Test STI
2
2
  class WorkerUser < User
3
-
4
- end
3
+ end
@@ -1,91 +1,91 @@
1
1
  ActiveRecord::Schema.define do
2
- create_table "users", :force => true do |t|
3
- t.column "name", :string
4
- t.column "email", :string
5
- t.column "type", :string
2
+ create_table 'users', force: true do |t|
3
+ t.column 'name', :string
4
+ t.column 'email', :string
5
+ t.column 'type', :string
6
6
  end
7
7
 
8
- create_table "companies", :force => true do |t|
9
- t.column "name", :text
10
- t.column "owned_id", :integer
11
- t.column "country_id", :integer
8
+ create_table 'companies', force: true do |t|
9
+ t.column 'name', :text
10
+ t.column 'owned_id', :integer
11
+ t.column 'country_id', :integer
12
12
  end
13
13
 
14
14
  add_index :companies, :country_id
15
15
 
16
- create_table "addresses", :force => true do |t|
17
- t.column "addressable_type", :string
18
- t.column "addressable_id", :integer
19
- t.column "address", :text
20
- t.column "country_id", :integer
16
+ create_table 'addresses', force: true do |t|
17
+ t.column 'addressable_type', :string
18
+ t.column 'addressable_id', :integer
19
+ t.column 'address', :text
20
+ t.column 'country_id', :integer
21
21
  end
22
22
 
23
- create_table "freelancers", :force => true do |t|
24
- t.column "name", :string
25
- t.column "price_per_hour", :integer
23
+ create_table 'freelancers', force: true do |t|
24
+ t.column 'name', :string
25
+ t.column 'price_per_hour', :integer
26
26
  t.column 'worker_type', :string
27
27
  end
28
28
 
29
- create_table "timesheets", :force => true do |t|
30
- t.column "price_per_hour", :integer
31
- t.column "hours", :integer
29
+ create_table 'timesheets', force: true do |t|
30
+ t.column 'price_per_hour', :integer
31
+ t.column 'hours', :integer
32
32
  end
33
33
 
34
- create_table "complex_timesheets", :force => true do |t|
35
- t.column "price_per_hour", :integer
36
- t.column "hours", :integer
34
+ create_table 'complex_timesheets', force: true do |t|
35
+ t.column 'price_per_hour', :integer
36
+ t.column 'hours', :integer
37
37
  end
38
38
 
39
- create_table "billable_weeks", :force => true do |t|
40
- t.column "date", :date
41
- t.column "timesheet_id", :integer
42
- t.column "remote_worker_id", :integer
39
+ create_table 'billable_weeks', force: true do |t|
40
+ t.column 'date', :date
41
+ t.column 'timesheet_id', :integer
42
+ t.column 'remote_worker_id', :integer
43
43
  end
44
44
 
45
- create_table "complex_billable_week", :force => true do |t|
46
- t.column "date", :date
47
- t.column "id_complex_timesheet", :integer
48
- t.column "freelancer_id", :integer
45
+ create_table 'complex_billable_week', force: true do |t|
46
+ t.column 'date', :date
47
+ t.column 'id_complex_timesheet', :integer
48
+ t.column 'freelancer_id', :integer
49
49
  end
50
50
 
51
- create_table "companies_freelancers", :id => false, :force => true do |t|
52
- t.column "freelancer_id", :integer
53
- t.column "company_id", :integer
51
+ create_table 'companies_freelancers', id: false, force: true do |t|
52
+ t.column 'freelancer_id', :integer
53
+ t.column 'company_id', :integer
54
54
  end
55
55
 
56
- create_table "gifts", :primary_key => "custom_primary_key", :force => true do |t|
57
- t.column "name", :string
58
- t.column "price", :integer
56
+ create_table 'gifts', primary_key: 'custom_primary_key', force: true do |t|
57
+ t.column 'name', :string
58
+ t.column 'price', :integer
59
59
  end
60
60
 
61
- create_table "purchases", :id => false, :force => true do |t|
62
- t.column "present_id", :integer
63
- t.column "buyer_id", :integer
61
+ create_table 'purchases', id: false, force: true do |t|
62
+ t.column 'present_id', :integer
63
+ t.column 'buyer_id', :integer
64
64
  end
65
65
 
66
- create_table "countries", :force => true do |t|
67
- t.column "name", :string
66
+ create_table 'countries', force: true do |t|
67
+ t.column 'name', :string
68
68
  end
69
69
 
70
- create_table "components", force: :cascade do |t|
70
+ create_table 'components', force: :cascade do |t|
71
71
  end
72
72
 
73
- create_table "group_components", force: :cascade do |t|
74
- t.column "group_id", :integer
75
- t.column "component_id", :integer
73
+ create_table 'group_components', force: :cascade do |t|
74
+ t.column 'group_id', :integer
75
+ t.column 'component_id', :integer
76
76
  end
77
77
 
78
- create_table "groups", force: :cascade do |t|
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
81
+ create_table 'projects', force: true do |t|
82
+ t.column 'name', :string
83
+ t.column 'user_id', :integer
84
84
  end
85
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
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
90
  end
91
91
  end
@@ -0,0 +1,66 @@
1
+ RSpec.describe LolDba::MigrationFormatter do
2
+ describe '#migration_instructions' do
3
+ subject(:formatter) { LolDba::MigrationFormatter.new('') }
4
+ let(:index_to_add) { ['add_index :report, :_id_test_plan'] }
5
+
6
+ it 'print migration skeleton with set name' do
7
+ migration = formatter.migration_instructions(index_to_add)
8
+ expect(migration).to match(/class AddMissingIndexes/i)
9
+ end
10
+
11
+ it 'print migration with add_keys params' do
12
+ migration = formatter.migration_instructions(index_to_add)
13
+ expect(migration).to match(/add_index :report, :_id_test_plan/i)
14
+ end
15
+ end
16
+
17
+ describe '#format_for_migration' do
18
+ subject(:formatter) { LolDba::MigrationFormatter.new('') }
19
+
20
+ it 'return data for migrations for non-indexed single key in table' do
21
+ relationship_indexes = { users: [:user_id] }
22
+
23
+ add_indexes = formatter.format_for_migration(relationship_indexes)
24
+
25
+ expect(add_indexes.first).to eq('add_index :users, :user_id')
26
+ end
27
+
28
+ it 'return data for migrations for non-indexed composite key in table' do
29
+ relationship_indexes = { friends: [%i[user_id friend_id]] }
30
+
31
+ add_indexes = formatter.format_for_migration(relationship_indexes)
32
+
33
+ expect(add_indexes.first).to eq('add_index :friends, [:user_id, :friend_id]')
34
+ end
35
+
36
+ it 'ignore empty or nil keys for table' do
37
+ relationship_indexes = { table: [''], table2: [nil] }
38
+ add_indexes = formatter.format_for_migration(relationship_indexes)
39
+
40
+ expect(add_indexes).to be_empty
41
+ end
42
+ end
43
+
44
+ describe '#puts_migration_content' do
45
+ before do
46
+ @indexes = LolDba::IndexFinder.check_for_indexes
47
+ end
48
+
49
+ it 'print migration code' do
50
+ expect($stdout).to receive(:puts).with(/AddMissingIndexes/i)
51
+ LolDba::MigrationFormatter.new(@indexes).puts_migration_content
52
+ end
53
+
54
+ it 'print warning messages if they exist' do
55
+ warning = 'warning text here'
56
+ expect($stdout).to receive(:puts)
57
+
58
+ LolDba::MigrationFormatter.new({}).puts_migration_content
59
+ end
60
+
61
+ it 'print nothing if no indexes and warning messages exist' do
62
+ expect($stdout).to receive(:puts).with('Yey, no missing indexes found!')
63
+ LolDba::MigrationFormatter.new({}).puts_migration_content
64
+ end
65
+ end
66
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,16 +1,20 @@
1
+ require 'bundler/setup'
1
2
  require 'rails/all'
2
3
  require 'lol_dba'
4
+ require 'simplecov'
3
5
 
4
- ENV["RAILS_ENV"] ||= 'test'
6
+ ENV['RAILS_ENV'] ||= 'test'
7
+
8
+ SimpleCov.start
5
9
 
6
10
  ActiveRecord::Base.establish_connection(
7
- :adapter => "sqlite3",
8
- :database => ":memory:"
11
+ adapter: 'sqlite3',
12
+ database: ':memory:'
9
13
  )
10
14
 
11
15
  module Rails
12
16
  def self.root
13
- "spec/fixtures/"
17
+ 'spec/fixtures/'
14
18
  end
15
19
  end
16
20
  Dir.glob("#{Rails.root}/app/models/*.rb").sort.each { |file| require_dependency file }
@@ -20,15 +24,19 @@ load 'fixtures/schema.rb'
20
24
 
21
25
  root_dir = File.dirname(__FILE__)
22
26
 
23
- #add current dir to the load path
24
- $:.unshift('.')
27
+ # add current dir to the load path
28
+ $LOAD_PATH.unshift('.')
29
+
25
30
  RSpec.configure do |config|
26
- config.expect_with :rspec do |expectations|
27
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
31
+ config.disable_monkey_patching!
32
+
33
+ config.expect_with :rspec do |c|
34
+ c.syntax = :expect
35
+ c.include_chain_clauses_in_custom_matcher_descriptions = true
28
36
  end
37
+
29
38
  config.mock_with :rspec do |mocks|
30
39
  mocks.allow_message_expectations_on_nil = true
31
40
  mocks.verify_partial_doubles = true
32
41
  end
33
- config.disable_monkey_patching!
34
42
  end
@@ -0,0 +1,9 @@
1
+ RSpec.describe LolDba::SqlGenerator do
2
+ before do
3
+ FileUtils.mkdir_p(Pathname.new(Rails.root).join('db', 'migrate_sql'))
4
+ end
5
+
6
+ it 'generates migrations without error' do
7
+ expect { LolDba::SqlGenerator.new('all').run }.not_to raise_error
8
+ end
9
+ end