From 4b8f502d2d8f83ac423549e18b3ed4518ead8aee Mon Sep 17 00:00:00 2001 From: David Librera Date: Mon, 9 Apr 2018 10:32:07 +0200 Subject: [PATCH] Not run rubocop on schema dumping --- fix-db-schema-conflicts.gemspec | 2 - .../autocorrect_configuration.rb | 17 ----- lib/fix_db_schema_conflicts/tasks/db.rake | 12 ---- spec/integration/integration_spec.rb | 70 +++++++------------ spec/test-app/db/schema.rb | 25 +++---- spec/unit/autocorrect_configuration_spec.rb | 23 ------ 6 files changed, 37 insertions(+), 112 deletions(-) delete mode 100644 lib/fix_db_schema_conflicts/autocorrect_configuration.rb delete mode 100644 spec/unit/autocorrect_configuration_spec.rb diff --git a/fix-db-schema-conflicts.gemspec b/fix-db-schema-conflicts.gemspec index ddf23b1..fabc32f 100644 --- a/fix-db-schema-conflicts.gemspec +++ b/fix-db-schema-conflicts.gemspec @@ -24,7 +24,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rails', '~> 4.2.0' spec.add_development_dependency 'sqlite3', '~> 1.3.0' - spec.add_dependency 'rubocop', '>= 0.38.0' - spec.required_ruby_version = '~> 2.0' end diff --git a/lib/fix_db_schema_conflicts/autocorrect_configuration.rb b/lib/fix_db_schema_conflicts/autocorrect_configuration.rb deleted file mode 100644 index 94e80e6..0000000 --- a/lib/fix_db_schema_conflicts/autocorrect_configuration.rb +++ /dev/null @@ -1,17 +0,0 @@ -module FixDBSchemaConflicts - class AutocorrectConfiguration - def self.load - new.load - end - - def load - at_least_rubocop_49? ? '.rubocop_schema.49.yml' : '.rubocop_schema.yml' - end - - private - - def at_least_rubocop_49? - Gem::Version.new('0.49.0') <= Gem.loaded_specs['rubocop'].version - end - end -end diff --git a/lib/fix_db_schema_conflicts/tasks/db.rake b/lib/fix_db_schema_conflicts/tasks/db.rake index 11c7ca7..50be97a 100644 --- a/lib/fix_db_schema_conflicts/tasks/db.rake +++ b/lib/fix_db_schema_conflicts/tasks/db.rake @@ -1,19 +1,7 @@ -require 'shellwords' -require_relative '../autocorrect_configuration' - namespace :db do namespace :schema do task :dump do puts "Dumping database schema with fix-db-schema-conflicts gem" - - filename = ENV['SCHEMA'] || if defined? ActiveRecord::Tasks::DatabaseTasks - File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, 'schema.rb') - else - "#{Rails.root}/db/schema.rb" - end - autocorrect_config = FixDBSchemaConflicts::AutocorrectConfiguration.load - rubocop_yml = File.expand_path("../../../../#{autocorrect_config}", __FILE__) - `bundle exec rubocop --auto-correct --config #{rubocop_yml} #{filename.shellescape}` end end end diff --git a/spec/integration/integration_spec.rb b/spec/integration/integration_spec.rb index 98bc314..7fe47e4 100644 --- a/spec/integration/integration_spec.rb +++ b/spec/integration/integration_spec.rb @@ -10,54 +10,32 @@ generated_lines = File.readlines('spec/test-app/db/schema.rb') - generated_lines.zip(expected_lines).each do |generated, expected| - next if expected.nil? - next if expected.start_with?('ActiveRecord::Schema.define') - expect(generated).to eq(expected) + column_list = generated_lines.select do |line| + line.strip.start_with?("t.") end - end -end -def reference_db_schema - <<-RUBY -# encoding: UTF-8 - -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 20160322223258) do - create_table "companies", force: :cascade do |t| - t.string "addr1" - t.string "addr2" - t.string "city" - t.datetime "created_at", null: false - t.string "name" - t.string "phone" - t.string "state" - t.datetime "updated_at", null: false - t.string "zip" - end + column_names = column_list.map do |line| + line.split(",")[0].strip.split[-1].gsub(/"/, "") + end - add_index "companies", ["city"], name: "index_companies_on_city" - add_index "companies", ["name"], name: "index_companies_on_name" - add_index "companies", ["state"], name: "index_companies_on_state" - - create_table "people", force: :cascade do |t| - t.integer "age" - t.date "birthdate" - t.datetime "created_at", null: false - t.string "first_name" - t.string "last_name" - t.datetime "updated_at", null: false + expected_names = [ + "addr1", + "addr2", + "city", + "created_at", + "name", + "phone", + "state", + "updated_at", + "zip", + "age", + "birthdate", + "created_at", + "first_name", + "last_name", + "updated_at" + ] + + expect(column_names).to match expected_names end - RUBY end diff --git a/spec/test-app/db/schema.rb b/spec/test-app/db/schema.rb index 2f5f687..480c7dc 100644 --- a/spec/test-app/db/schema.rb +++ b/spec/test-app/db/schema.rb @@ -1,5 +1,4 @@ # encoding: UTF-8 - # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -13,16 +12,17 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 20160322223258) do + create_table "companies", force: :cascade do |t| - t.string "addr1" - t.string "addr2" - t.string "city" + t.string "addr1" + t.string "addr2" + t.string "city" t.datetime "created_at", null: false - t.string "name" - t.string "phone" - t.string "state" + t.string "name" + t.string "phone" + t.string "state" t.datetime "updated_at", null: false - t.string "zip" + t.string "zip" end add_index "companies", ["city"], name: "index_companies_on_city" @@ -30,11 +30,12 @@ add_index "companies", ["state"], name: "index_companies_on_state" create_table "people", force: :cascade do |t| - t.integer "age" - t.date "birthdate" + t.integer "age" + t.date "birthdate" t.datetime "created_at", null: false - t.string "first_name" - t.string "last_name" + t.string "first_name" + t.string "last_name" t.datetime "updated_at", null: false end + end diff --git a/spec/unit/autocorrect_configuration_spec.rb b/spec/unit/autocorrect_configuration_spec.rb deleted file mode 100644 index 7b492be..0000000 --- a/spec/unit/autocorrect_configuration_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'spec_helper' -require 'fix_db_schema_conflicts/autocorrect_configuration' - -RSpec.describe FixDBSchemaConflicts::AutocorrectConfiguration do - subject(:autocorrect_config) { described_class } - - it 'for versions up to 0.49.0' do - installed_rubocop(version: '0.39.0') - - expect(autocorrect_config.load).to eq('.rubocop_schema.yml') - end - - it 'for versions 0.49.0 and above' do - installed_rubocop(version: '0.49.0') - - expect(autocorrect_config.load).to eq('.rubocop_schema.49.yml') - end - - def installed_rubocop(version:) - allow(Gem).to receive_message_chain(:loaded_specs, :[], :version) - .and_return(Gem::Version.new(version)) - end -end