From 9f520201d623fb91ff99d682f91ee21c5b44af97 Mon Sep 17 00:00:00 2001 From: Sundus Yousuf Date: Wed, 4 Sep 2024 11:04:23 -0500 Subject: [PATCH] Move table creations to individual methods. 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. --- spec/support/active_record.rb | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/spec/support/active_record.rb b/spec/support/active_record.rb index 8e517ec8..e6466056 100644 --- a/spec/support/active_record.rb +++ b/spec/support/active_record.rb @@ -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 @@ -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