Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't run rubocop on schema dumping #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions fix-db-schema-conflicts.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 0 additions & 17 deletions lib/fix_db_schema_conflicts/autocorrect_configuration.rb

This file was deleted.

12 changes: 0 additions & 12 deletions lib/fix_db_schema_conflicts/tasks/db.rake
Original file line number Diff line number Diff line change
@@ -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
70 changes: 24 additions & 46 deletions spec/integration/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 13 additions & 12 deletions spec/test-app/db/schema.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -13,28 +12,30 @@
# 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"
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.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
23 changes: 0 additions & 23 deletions spec/unit/autocorrect_configuration_spec.rb

This file was deleted.