Skip to content

Commit

Permalink
Move table creations to individual methods.
Browse files Browse the repository at this point in the history
Having every table creation inside a single block casued Rubocop
`Metrics/BlockLength` error. To fix it I moved each table creation
to an individual method.
  • Loading branch information
Sundus Yousuf committed Sep 4, 2024
1 parent 9ec31a0 commit 9f52020
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions spec/support/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
ActiveRecord::Base.raise_in_transactional_callbacks = true
end

ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'countries'")
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'cities'")
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'locations'")
ActiveRecord::Schema.define do
def create_countries_table
create_table :countries do |t|
t.column :name, :string
t.column :country_code, :string
t.column :rating, :integer
t.column :updated_at, :datetime
end
end

def create_cities_table
create_table :cities do |t|
t.column :country_id, :integer
t.column :name, :string
Expand All @@ -25,26 +24,45 @@
t.column :rating, :integer
t.column :updated_at, :datetime
end
end

def create_locations_table
create_table :locations do |t|
t.column :city_id, :integer
t.column :lat, :string
t.column :lon, :string
end
end

def create_comments_table
create_table :comments do |t|
t.column :content, :string
t.column :comment_type, :string
t.column :commented_id, :integer
t.column :updated_at, :datetime
end
end

def create_users_table
create_table :users, id: false do |t|
t.column :id, :string
t.column :name, :string
end
end

ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'countries'")
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'cities'")
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'locations'")
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'comments'")
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'users'")
ActiveRecord::Schema.define do
create_countries_table
create_cities_table
create_locations_table
create_comments_table
create_users_table
end

module ActiveRecordClassHelpers
extend ActiveSupport::Concern

Expand Down

0 comments on commit 9f52020

Please sign in to comment.