From aaed66b1174c6ef9319221954af91dbdddbff62d Mon Sep 17 00:00:00 2001 From: Camilla Date: Sun, 1 Mar 2020 10:10:30 +0000 Subject: [PATCH] Rubocop tidyup --- .rubocop.yml | 25 +++ Gemfile | 4 +- Rakefile | 13 +- .../application_controller.rb | 2 + .../application_helper.rb | 2 + .../association_mapping_service.rb | 4 +- .../model_retrieval_service.rb | 10 +- .../validation_mapping_service.rb | 26 +-- bin/console | 7 +- bin/rails | 10 +- config/routes.rb | 2 + lib/mission_kontrol_relay.rb | 4 +- lib/mission_kontrol_relay/engine.rb | 4 +- lib/mission_kontrol_relay/version.rb | 5 +- mission_kontrol_relay.gemspec | 31 ++-- spec/mission_kontrol_relay_spec.rb | 2 +- spec/rails_helper.rb | 10 +- .../association_mapping_service_spec.rb | 36 ++--- .../model_retrieval_service_spec.rb | 4 +- .../validation_mapping_service_spec.rb | 74 +++++---- spec/spec_helper.rb | 10 +- test/dummy/Rakefile | 4 +- .../app/channels/application_cable/channel.rb | 2 + .../channels/application_cable/connection.rb | 2 + .../app/controllers/application_controller.rb | 2 + test/dummy/app/helpers/application_helper.rb | 2 + test/dummy/app/jobs/application_job.rb | 2 + test/dummy/app/mailers/application_mailer.rb | 2 + test/dummy/app/models/account.rb | 4 +- test/dummy/app/models/account_history.rb | 4 +- test/dummy/app/models/application_record.rb | 2 + test/dummy/app/models/appointment.rb | 4 +- test/dummy/app/models/assembly.rb | 4 +- test/dummy/app/models/author.rb | 6 +- test/dummy/app/models/book.rb | 4 +- test/dummy/app/models/company.rb | 8 +- test/dummy/app/models/part.rb | 10 +- test/dummy/app/models/patient.rb | 4 +- test/dummy/app/models/physician.rb | 4 +- test/dummy/app/models/supplier.rb | 4 +- test/dummy/app/models/user.rb | 5 +- test/dummy/bin/bundle | 4 +- test/dummy/bin/rails | 2 + test/dummy/bin/rake | 2 + test/dummy/bin/setup | 5 +- test/dummy/bin/update | 4 +- test/dummy/bin/yarn | 14 +- test/dummy/config.ru | 2 + test/dummy/config/application.rb | 5 +- test/dummy/config/boot.rb | 2 + test/dummy/config/environment.rb | 2 + test/dummy/config/environments/development.rb | 2 + test/dummy/config/environments/production.rb | 6 +- test/dummy/config/environments/test.rb | 2 + .../application_controller_renderer.rb | 1 + test/dummy/config/initializers/assets.rb | 2 + .../initializers/backtrace_silencers.rb | 1 + .../config/initializers/cookies_serializer.rb | 2 + .../initializers/filter_parameter_logging.rb | 2 + test/dummy/config/initializers/inflections.rb | 1 + test/dummy/config/initializers/mime_types.rb | 1 + .../config/initializers/wrap_parameters.rb | 2 + test/dummy/config/puma.rb | 8 +- test/dummy/config/routes.rb | 4 +- test/dummy/config/spring.rb | 6 +- .../20200223104535_create_associations.rb | 4 +- ...20200225070228_create_more_associations.rb | 16 +- ...229112828_create_fields_for_validations.rb | 2 + test/dummy/db/schema.rb | 152 +++++++++--------- test/integration/navigation_test.rb | 2 +- test/mission_kontrol_relay_test.rb | 4 +- .../association_mapping_service_test.rb | 48 ------ .../validation_mapping_service_test.rb | 39 ----- test/test_helper.rb | 17 +- 74 files changed, 393 insertions(+), 337 deletions(-) create mode 100644 .rubocop.yml mode change 100644 => 100755 bin/console mode change 100644 => 100755 bin/rails delete mode 100644 test/services/mission_kontrol_relay/association_mapping_service_test.rb delete mode 100644 test/services/mission_kontrol_relay/validation_mapping_service_test.rb diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..3cc6994 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,25 @@ +AllCops: + Exclude: + - 'db/**/*' + - 'test/dummy/db/**/*' + - 'config/**/*' + - 'test/dummy/config/**/*' + - 'script/**/*' + - 'test/dummy/script/**/*' + - 'bin/{rails,rake}' + - 'test/dummy/bin/*' + - 'test/test_helper.rb' + - 'spec/rails_helper.rb' + - 'mission_kontrol_relay.gemspec' + +Style/Documentation: + Enabled: false + +Metrics/LineLength: + IgnoredPatterns: ['(\A|\s)#'] + Exclude: + - 'spec/**/*' + +Metrics/BlockLength: + Exclude: + - 'spec/**/*' diff --git a/Gemfile b/Gemfile index a881890..051082f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec @@ -9,4 +11,4 @@ group :development, :test do gem 'rspec-rails', '3.8.2' gem 'rubocop' gem 'simplecov' -end \ No newline at end of file +end diff --git a/Rakefile b/Rakefile index 1256bb0..5dada1a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,19 +1,18 @@ -require "bundler/gem_tasks" -require "rspec/core/rake_task" +# frozen_string_literal: true + +require 'bundler/gem_tasks' +require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) -APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__) +APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__) # load 'rails/tasks/engine.rake' # load 'rails/tasks/statistics.rake' load 'rails/tasks/engine.rake' - load 'rails/tasks/statistics.rake' - - require 'bundler/gem_tasks' Bundler::GemHelper.install_tasks @@ -26,4 +25,4 @@ Rake::TestTask.new(:test) do |t| t.verbose = false end -task :default => :test +task default: :test diff --git a/app/controllers/mission_kontrol_relay/application_controller.rb b/app/controllers/mission_kontrol_relay/application_controller.rb index faeb822..cfead8f 100644 --- a/app/controllers/mission_kontrol_relay/application_controller.rb +++ b/app/controllers/mission_kontrol_relay/application_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module MissionKontrolRelay class ApplicationController < ActionController::Base def index; end diff --git a/app/helpers/mission_kontrol_relay/application_helper.rb b/app/helpers/mission_kontrol_relay/application_helper.rb index f5bac0f..fd3ee2f 100644 --- a/app/helpers/mission_kontrol_relay/application_helper.rb +++ b/app/helpers/mission_kontrol_relay/application_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module MissionKontrolRelay module ApplicationHelper end diff --git a/app/services/mission_kontrol_relay/association_mapping_service.rb b/app/services/mission_kontrol_relay/association_mapping_service.rb index c968872..2e09ff1 100644 --- a/app/services/mission_kontrol_relay/association_mapping_service.rb +++ b/app/services/mission_kontrol_relay/association_mapping_service.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module MissionKontrolRelay class AssociationMappingService def initialize(model) @@ -42,4 +44,4 @@ def model_associations associations end end -end \ No newline at end of file +end diff --git a/app/services/mission_kontrol_relay/model_retrieval_service.rb b/app/services/mission_kontrol_relay/model_retrieval_service.rb index 1d1feaa..e37f09e 100644 --- a/app/services/mission_kontrol_relay/model_retrieval_service.rb +++ b/app/services/mission_kontrol_relay/model_retrieval_service.rb @@ -1,9 +1,13 @@ +# frozen_string_literal: true + module MissionKontrolRelay class ModelRetrievalService class << self def build Rails.application.eager_load! - ActiveRecord::Base.descendants.collect{ |t| t.to_s if valid_table?(t) }.compact + ActiveRecord::Base.descendants.collect do |t| + t.to_s if valid_table?(t) + end .compact end private @@ -13,8 +17,8 @@ def valid_table?(table) end def not_join_table?(table) - table.to_s.split('::').last.split('_').first != "HABTM" + table.to_s.split('::').last.split('_').first != 'HABTM' end end end -end \ No newline at end of file +end diff --git a/app/services/mission_kontrol_relay/validation_mapping_service.rb b/app/services/mission_kontrol_relay/validation_mapping_service.rb index 76a3a25..5b411af 100644 --- a/app/services/mission_kontrol_relay/validation_mapping_service.rb +++ b/app/services/mission_kontrol_relay/validation_mapping_service.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module MissionKontrolRelay class ValidationMappingService def initialize(model) @@ -17,18 +19,22 @@ def model_validations validations = [] @model._validate_callbacks.to_a.each do |validation| - validations << { - key: validation.instance_variable_get(:@key), - type: validation.instance_variable_get(:@key).try(:kind), - kind: validation.kind, - name: validation.name, - attributes: validation.try(:filter).try(:attributes), - if: validation.instance_variable_get(:@if), - unless: validation.instance_variable_get(:@unless) - } + validations << validation_attributes(validation) end validations end + + def validation_attributes(validation) + { + key: validation.instance_variable_get(:@key), + type: validation.instance_variable_get(:@key).try(:kind), + kind: validation.kind, + name: validation.name, + attributes: validation.try(:filter).try(:attributes), + if: validation.instance_variable_get(:@if), + unless: validation.instance_variable_get(:@unless) + } + end end -end \ No newline at end of file +end diff --git a/bin/console b/bin/console old mode 100644 new mode 100755 index da08fc6..7762ec6 --- a/bin/console +++ b/bin/console @@ -1,7 +1,8 @@ #!/usr/bin/env ruby +# frozen_string_literal: true -require "bundler/setup" -require "mission_kontrol_relay" +require 'bundler/setup' +require 'mission_kontrol_relay' # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. @@ -10,5 +11,5 @@ require "mission_kontrol_relay" # require "pry" # Pry.start -require "irb" +require 'irb' IRB.start(__FILE__) diff --git a/bin/rails b/bin/rails old mode 100644 new mode 100755 index 367310d..7c385fc --- a/bin/rails +++ b/bin/rails @@ -1,12 +1,14 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application. -ENGINE_ROOT = File.expand_path('../..', __FILE__) -ENGINE_PATH = File.expand_path('../../lib/mission_kontrol_relay/engine', __FILE__) -APP_PATH = File.expand_path('../../test/dummy/config/application', __FILE__) +ENGINE_ROOT = File.expand_path('..', __dir__) +ENGINE_PATH = File.expand_path('../lib/mission_kontrol_relay/engine', __dir__) +APP_PATH = File.expand_path('../test/dummy/config/application', __dir__) # Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) require 'rails/all' diff --git a/config/routes.rb b/config/routes.rb index 89b2b57..d4aea43 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + MissionKontrolRelay::Engine.routes.draw do get '/' => 'application#index' end diff --git a/lib/mission_kontrol_relay.rb b/lib/mission_kontrol_relay.rb index cb7e40f..e95b15c 100644 --- a/lib/mission_kontrol_relay.rb +++ b/lib/mission_kontrol_relay.rb @@ -1,4 +1,6 @@ -require "mission_kontrol_relay/engine" +# frozen_string_literal: true + +require 'mission_kontrol_relay/engine' module MissionKontrolRelay end diff --git a/lib/mission_kontrol_relay/engine.rb b/lib/mission_kontrol_relay/engine.rb index 73eaa7f..55b0c14 100644 --- a/lib/mission_kontrol_relay/engine.rb +++ b/lib/mission_kontrol_relay/engine.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + module MissionKontrolRelay class Engine < ::Rails::Engine isolate_namespace MissionKontrolRelay end -end \ No newline at end of file +end diff --git a/lib/mission_kontrol_relay/version.rb b/lib/mission_kontrol_relay/version.rb index 47c3ce3..3bce79a 100644 --- a/lib/mission_kontrol_relay/version.rb +++ b/lib/mission_kontrol_relay/version.rb @@ -1,4 +1,5 @@ +# frozen_string_literal: true + module MissionKontrolRelay - VERSION = "0.1.0" + VERSION = '0.1.0' end - \ No newline at end of file diff --git a/mission_kontrol_relay.gemspec b/mission_kontrol_relay.gemspec index cd81b19..df29d58 100644 --- a/mission_kontrol_relay.gemspec +++ b/mission_kontrol_relay.gemspec @@ -1,29 +1,30 @@ +# frozen_string_literal: true -lib = File.expand_path("../lib", __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require "mission_kontrol_relay/version" +require 'mission_kontrol_relay/version' Gem::Specification.new do |spec| - spec.name = "mission_kontrol_relay" + spec.name = 'mission_kontrol_relay' spec.version = MissionKontrolRelay::VERSION - spec.authors = ["Camilla"] - spec.email = ["camillavk@gmail.com"] + spec.authors = ['Camilla'] + spec.email = ['camillavk@gmail.com'] - spec.summary = "Write a short summary, because RubyGems requires one." - spec.description = "Write a longer description or delete this line." - spec.homepage = "https://kuwinda.io" + spec.summary = 'Write a short summary, because RubyGems requires one.' + spec.description = 'Write a longer description or delete this line.' + spec.homepage = 'https://kuwinda.io' # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. - spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do + spec.files = Dir.chdir(File.expand_path(__dir__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } end - spec.bindir = "exe" + spec.bindir = 'exe' spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } - spec.require_paths = ["lib"] + spec.require_paths = ['lib'] - spec.add_development_dependency "bundler", "~> 1.17" - spec.add_development_dependency "rake", "~> 10.0" - spec.add_development_dependency "sqlite3" - spec.add_dependency "rails", "~> 5.1" + spec.add_development_dependency 'bundler', '~> 1.17' + spec.add_development_dependency 'rake', '~> 10.0' + spec.add_development_dependency 'sqlite3' + spec.add_dependency 'rails', '~> 5.1' end diff --git a/spec/mission_kontrol_relay_spec.rb b/spec/mission_kontrol_relay_spec.rb index dc92d9e..6f0725b 100644 --- a/spec/mission_kontrol_relay_spec.rb +++ b/spec/mission_kontrol_relay_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe MissionKontrolRelay do - it "has a version number" do + it 'has a version number' do expect(MissionKontrolRelay::VERSION).not_to be nil end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index ba2d689..528c59a 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,18 +1,18 @@ # frozen_string_literal: true ENV['RAILS_ENV'] ||= 'test' -require File.expand_path("../../test/dummy/config/environment.rb", __FILE__) +require File.expand_path('../test/dummy/config/environment.rb', __dir__) require 'rspec/rails' -ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../') +ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../') -ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)] -ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate', __FILE__) +ActiveRecord::Migrator.migrations_paths = [File.expand_path('../test/dummy/db/migrate', __dir__)] +ActiveRecord::Migrator.migrations_paths << File.expand_path('../db/migrate', __dir__) # Prevent database truncation if the environment is production abort('The Rails environment is in production mode!') if Rails.env.production? -Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } +Dir[Rails.root.join('spec/support/**/*.rb')].sort.each { |f| require f } RSpec.configure do |config| config.backtrace_exclusion_patterns = [ diff --git a/spec/services/mission_kontrol_relay/association_mapping_service_spec.rb b/spec/services/mission_kontrol_relay/association_mapping_service_spec.rb index 160892b..be0ad1e 100644 --- a/spec/services/mission_kontrol_relay/association_mapping_service_spec.rb +++ b/spec/services/mission_kontrol_relay/association_mapping_service_spec.rb @@ -6,15 +6,15 @@ context 'general' do let(:model) { Company } - let(:expected_result) { + let(:expected_result) do [ { associated_model: :user, - options: {foreign_key: 'owner'}, + options: { foreign_key: 'owner' }, type: :belongs_to } ] - } + end it 'returns a hash containing the model name' do expect(subject[:model]).to eq 'Company' @@ -54,7 +54,7 @@ expect(result[:options][:foreign_key]).to eq 'owner' end end - + it 'returns the type of association' do expect(result[:type]).to eq :belongs_to end @@ -63,7 +63,7 @@ context 'has_one' do let(:model) { User } let(:result) { subject[:associations].first } - let(:expected_result) { + let(:expected_result) do [ { associated_model: :company, @@ -71,12 +71,12 @@ type: :has_one } ] - } + end it 'returns the name of the related model in the association' do expect(result[:associated_model]).to eq :company end - + it 'returns the type of association' do expect(result[:type]).to eq :has_one end @@ -88,7 +88,7 @@ context 'has_many' do let(:model) { Author } - let(:expected_result) { + let(:expected_result) do [ { associated_model: :books, @@ -96,8 +96,8 @@ type: :has_many } ] - } - + end + it 'returns the name of the related model in the association (pluralised)' do expect(subject[:associations].first[:associated_model]).to eq :books end @@ -117,7 +117,7 @@ context 'has_many :through' do let(:model) { Physician } - let(:expected_result) { + let(:expected_result) do [ { associated_model: :appointments, @@ -126,11 +126,11 @@ }, { associated_model: :patients, - options: {through: :appointments}, + options: { through: :appointments }, type: :has_many } ] - } + end it 'returns the association through in the options' do expect(subject[:associations]).to eq expected_result @@ -140,7 +140,7 @@ context 'has_one :through' do let(:model) { Supplier } - let(:expected_result) { + let(:expected_result) do [ { associated_model: :account, @@ -149,11 +149,11 @@ }, { associated_model: :account_history, - options: {through: :account}, + options: { through: :account }, type: :has_one } ] - } + end it 'returns the association through in the options' do expect(subject[:associations]).to eq expected_result @@ -163,7 +163,7 @@ context 'has_and_belongs_to_many' do let(:model) { Assembly } - let(:expected_result) { + let(:expected_result) do [ { associated_model: :parts, @@ -171,7 +171,7 @@ type: :has_and_belongs_to_many } ] - } + end it 'returns the association through in the options' do expect(subject[:associations]).to eq expected_result diff --git a/spec/services/mission_kontrol_relay/model_retrieval_service_spec.rb b/spec/services/mission_kontrol_relay/model_retrieval_service_spec.rb index d41d104..14bf26c 100644 --- a/spec/services/mission_kontrol_relay/model_retrieval_service_spec.rb +++ b/spec/services/mission_kontrol_relay/model_retrieval_service_spec.rb @@ -3,9 +3,9 @@ RSpec.describe MissionKontrolRelay::ModelRetrievalService do describe 'build' do let(:subject) { described_class.build } - + it 'returns an array of the models' do - expect(subject).to match_array ["Company", "User", "Account", "AccountHistory", "Appointment", "Assembly", "Author", "Book", "Part", "Patient", "Physician", "Supplier"] + expect(subject).to match_array %w[Company User Account AccountHistory Appointment Assembly Author Book Part Patient Physician Supplier] end end end diff --git a/spec/services/mission_kontrol_relay/validation_mapping_service_spec.rb b/spec/services/mission_kontrol_relay/validation_mapping_service_spec.rb index f7981ad..cf8d26f 100644 --- a/spec/services/mission_kontrol_relay/validation_mapping_service_spec.rb +++ b/spec/services/mission_kontrol_relay/validation_mapping_service_spec.rb @@ -20,14 +20,14 @@ context 'validation helpers' do context 'confirmation' do let(:model) { Patient } - let(:expected_result) { + let(:expected_result) do { attributes: [:email], kind: :before, name: :validate, type: :confirmation } - } + end it 'returns the validation details' do confirmation_result = result.select { |validation| validation[:type] == :confirmation }.first @@ -37,14 +37,14 @@ context 'exclusion' do let(:model) { Company } - let(:expected_result) { + let(:expected_result) do { attributes: [:subdomain], kind: :before, name: :validate, type: :exclusion } - } + end let(:confirmation_result) { result.select { |validation| validation[:type] == :exclusion }.first } it 'returns the validation details' do @@ -52,20 +52,20 @@ end it 'returns the exclusion options in the key' do - expect(confirmation_result[:key].instance_variable_get(:@options)[:in]).to eq %w(www us ca jp) + expect(confirmation_result[:key].instance_variable_get(:@options)[:in]).to eq %w[www us ca jp] end end context 'format' do let(:model) { Part } - let(:expected_result) { + let(:expected_result) do { attributes: [:legacy_code], kind: :before, name: :validate, type: :format } - } + end let(:confirmation_result) { result.select { |validation| validation[:type] == :format }.first } it 'returns the validation details' do @@ -73,20 +73,20 @@ end it 'returns the exclusion options in the key' do - expect(confirmation_result[:key].instance_variable_get(:@options)[:with]).to eq /\A[a-zA-Z]+\z/ + expect(confirmation_result[:key].instance_variable_get(:@options)[:with]).to eq(/\A[a-zA-Z]+\z/) end end context 'inclusion' do let(:model) { Part } - let(:expected_result) { + let(:expected_result) do { attributes: [:size], kind: :before, name: :validate, type: :inclusion } - } + end let(:confirmation_result) { result.select { |validation| validation[:type] == :inclusion }.first } it 'returns the validation details' do @@ -94,20 +94,20 @@ end it 'returns the exclusion options in the key' do - expect(confirmation_result[:key].instance_variable_get(:@options)[:in]).to eq %w(small medium large) + expect(confirmation_result[:key].instance_variable_get(:@options)[:in]).to eq %w[small medium large] end end context 'length' do let(:model) { User } - let(:expected_result) { + let(:expected_result) do { attributes: [:name], kind: :before, name: :validate, type: :length } - } + end let(:confirmation_result) { result.select { |validation| validation[:type] == :length }.first } it 'returns the validation details' do @@ -121,14 +121,14 @@ context 'numericality' do let(:model) { Assembly } - let(:expected_result) { + let(:expected_result) do { attributes: [:points], kind: :before, name: :validate, type: :numericality } - } + end let(:confirmation_result) { result.select { |validation| validation[:type] == :numericality }.first } it 'returns the validation details' do @@ -138,22 +138,22 @@ context 'presence' do let(:model) { Company } - + it 'returns type presence' do expect(result.first[:type]).to eq :presence - end + end end context 'uniqueness' do let(:model) { User } - let(:expected_result) { + let(:expected_result) do { attributes: [:name], kind: :before, name: :validate, type: :uniqueness } - } + end let(:confirmation_result) { result.select { |validation| validation[:type] == :uniqueness }.first } it 'returns the validation details' do @@ -168,18 +168,17 @@ context 'custom validations' do let(:model) { Company } - let(:expected_result) { - { - attributes: nil, - kind: :before, - name: :validate, - type: nil, - key: :something - } + let(:expected_result) do + { + attributes: nil, + kind: :before, + name: :validate, + type: nil, + key: :something } + end let(:confirmation_result) { result.select { |validation| validation[:type].nil? }.first } - it 'returns the validation details' do expect(confirmation_result).to include expected_result end @@ -187,19 +186,18 @@ context 'conditional validations' do let(:model) { Company } - let(:expected_result) { - { - attributes: nil, - kind: :before, - name: :validate, - type: nil, - key: :something, - if: [:something_else?] - } + let(:expected_result) do + { + attributes: nil, + kind: :before, + name: :validate, + type: nil, + key: :something, + if: [:something_else?] } + end let(:confirmation_result) { result.select { |validation| validation[:type].nil? }.first } - it 'returns the validation details' do expect(confirmation_result).to include expected_result end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index aeb3b1c..7d7d6a4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,12 +1,14 @@ -require "bundler/setup" -require "rails_helper" -require "mission_kontrol_relay" +# frozen_string_literal: true + +require 'bundler/setup' +require 'rails_helper' +require 'mission_kontrol_relay' require 'simplecov' SimpleCov.start RSpec.configure do |config| # Enable flags like --only-failures and --next-failure - config.example_status_persistence_file_path = ".rspec_status" + config.example_status_persistence_file_path = '.rspec_status' # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching! diff --git a/test/dummy/Rakefile b/test/dummy/Rakefile index e0f6a9f..0e04610 100644 --- a/test/dummy/Rakefile +++ b/test/dummy/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. @@ -5,6 +7,6 @@ # Rails.application.load_tasks -require File.expand_path('../config/application', __FILE__) +require File.expand_path('config/application', __dir__) Rails.application.load_tasks diff --git a/test/dummy/app/channels/application_cable/channel.rb b/test/dummy/app/channels/application_cable/channel.rb index d672697..9aec230 100644 --- a/test/dummy/app/channels/application_cable/channel.rb +++ b/test/dummy/app/channels/application_cable/channel.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Channel < ActionCable::Channel::Base end diff --git a/test/dummy/app/channels/application_cable/connection.rb b/test/dummy/app/channels/application_cable/connection.rb index 0ff5442..8d6c2a1 100644 --- a/test/dummy/app/channels/application_cable/connection.rb +++ b/test/dummy/app/channels/application_cable/connection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Connection < ActionCable::Connection::Base end diff --git a/test/dummy/app/controllers/application_controller.rb b/test/dummy/app/controllers/application_controller.rb index 1c07694..280cc28 100644 --- a/test/dummy/app/controllers/application_controller.rb +++ b/test/dummy/app/controllers/application_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::Base protect_from_forgery with: :exception end diff --git a/test/dummy/app/helpers/application_helper.rb b/test/dummy/app/helpers/application_helper.rb index de6be79..15b06f0 100644 --- a/test/dummy/app/helpers/application_helper.rb +++ b/test/dummy/app/helpers/application_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module ApplicationHelper end diff --git a/test/dummy/app/jobs/application_job.rb b/test/dummy/app/jobs/application_job.rb index a009ace..d92ffdd 100644 --- a/test/dummy/app/jobs/application_job.rb +++ b/test/dummy/app/jobs/application_job.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class ApplicationJob < ActiveJob::Base end diff --git a/test/dummy/app/mailers/application_mailer.rb b/test/dummy/app/mailers/application_mailer.rb index 286b223..d84cb6e 100644 --- a/test/dummy/app/mailers/application_mailer.rb +++ b/test/dummy/app/mailers/application_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationMailer < ActionMailer::Base default from: 'from@example.com' layout 'mailer' diff --git a/test/dummy/app/models/account.rb b/test/dummy/app/models/account.rb index 3d35d28..43101a1 100644 --- a/test/dummy/app/models/account.rb +++ b/test/dummy/app/models/account.rb @@ -1,4 +1,6 @@ +# frozen_string_literal: true + class Account < ApplicationRecord belongs_to :supplier has_one :account_history -end \ No newline at end of file +end diff --git a/test/dummy/app/models/account_history.rb b/test/dummy/app/models/account_history.rb index 3460fa5..bd3e0aa 100644 --- a/test/dummy/app/models/account_history.rb +++ b/test/dummy/app/models/account_history.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AccountHistory < ApplicationRecord belongs_to :account -end \ No newline at end of file +end diff --git a/test/dummy/app/models/application_record.rb b/test/dummy/app/models/application_record.rb index 10a4cba..71fbba5 100644 --- a/test/dummy/app/models/application_record.rb +++ b/test/dummy/app/models/application_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationRecord < ActiveRecord::Base self.abstract_class = true end diff --git a/test/dummy/app/models/appointment.rb b/test/dummy/app/models/appointment.rb index cc7ff41..b57d74e 100644 --- a/test/dummy/app/models/appointment.rb +++ b/test/dummy/app/models/appointment.rb @@ -1,4 +1,6 @@ +# frozen_string_literal: true + class Appointment < ApplicationRecord belongs_to :physician belongs_to :patient -end \ No newline at end of file +end diff --git a/test/dummy/app/models/assembly.rb b/test/dummy/app/models/assembly.rb index 9d68cf7..e84e399 100644 --- a/test/dummy/app/models/assembly.rb +++ b/test/dummy/app/models/assembly.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + class Assembly < ApplicationRecord has_and_belongs_to_many :parts validates :points, numericality: true -end \ No newline at end of file +end diff --git a/test/dummy/app/models/author.rb b/test/dummy/app/models/author.rb index 0dacd13..499e0c7 100644 --- a/test/dummy/app/models/author.rb +++ b/test/dummy/app/models/author.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + class Author < ApplicationRecord has_many :books validates :terms_of_service, acceptance: { accept: 'yes' } - validates :eula, acceptance: { accept: ['TRUE', 'accepted'] } + validates :eula, acceptance: { accept: %w[TRUE accepted] } validates_associated :books -end \ No newline at end of file +end diff --git a/test/dummy/app/models/book.rb b/test/dummy/app/models/book.rb index 06b3953..6369d88 100644 --- a/test/dummy/app/models/book.rb +++ b/test/dummy/app/models/book.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Book < ApplicationRecord belongs_to :author -end \ No newline at end of file +end diff --git a/test/dummy/app/models/company.rb b/test/dummy/app/models/company.rb index 03270bc..8301557 100644 --- a/test/dummy/app/models/company.rb +++ b/test/dummy/app/models/company.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + class Company < ActiveRecord::Base - belongs_to :user, foreign_key: "owner" + belongs_to :user, foreign_key: 'owner' validates :owner, presence: true validate :something, if: :something_else? - validates :subdomain, exclusion: { in: %w(www us ca jp), - message: "%{value} is reserved." } + validates :subdomain, exclusion: { in: %w[www us ca jp], + message: '% is reserved.' } end diff --git a/test/dummy/app/models/part.rb b/test/dummy/app/models/part.rb index 60048ea..e54c793 100644 --- a/test/dummy/app/models/part.rb +++ b/test/dummy/app/models/part.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + class Part < ApplicationRecord has_and_belongs_to_many :assemblies validates :legacy_code, format: { with: /\A[a-zA-Z]+\z/, - message: "only allows letters" } + message: 'only allows letters' } - validates :size, inclusion: { in: %w(small medium large), - message: "%{value} is not a valid size" } -end \ No newline at end of file + validates :size, inclusion: { in: %w[small medium large], + message: '% is not a valid size' } +end diff --git a/test/dummy/app/models/patient.rb b/test/dummy/app/models/patient.rb index 23c7940..062cd9f 100644 --- a/test/dummy/app/models/patient.rb +++ b/test/dummy/app/models/patient.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + class Patient < ApplicationRecord has_many :appointments has_many :physicians, through: :appointments validates :email, confirmation: true validates :email_confirmation, presence: true -end \ No newline at end of file +end diff --git a/test/dummy/app/models/physician.rb b/test/dummy/app/models/physician.rb index cb1f463..7e03fcc 100644 --- a/test/dummy/app/models/physician.rb +++ b/test/dummy/app/models/physician.rb @@ -1,4 +1,6 @@ +# frozen_string_literal: true + class Physician < ApplicationRecord has_many :appointments has_many :patients, through: :appointments -end \ No newline at end of file +end diff --git a/test/dummy/app/models/supplier.rb b/test/dummy/app/models/supplier.rb index ae086d3..9a7c473 100644 --- a/test/dummy/app/models/supplier.rb +++ b/test/dummy/app/models/supplier.rb @@ -1,4 +1,6 @@ +# frozen_string_literal: true + class Supplier < ApplicationRecord has_one :account has_one :account_history, through: :account -end \ No newline at end of file +end diff --git a/test/dummy/app/models/user.rb b/test/dummy/app/models/user.rb index 7ea2423..6853487 100644 --- a/test/dummy/app/models/user.rb +++ b/test/dummy/app/models/user.rb @@ -1,8 +1,11 @@ +# frozen_string_literal: true + class User < ActiveRecord::Base has_one :company validates_uniqueness_of :name - validates :name, length: { minimum: 2 }, confirmation: { case_sensitive: false } + validates :name, length: { minimum: 2 }, + confirmation: { case_sensitive: false } validates :active, inclusion: { in: [true, false] } validate :company_id_exists diff --git a/test/dummy/bin/bundle b/test/dummy/bin/bundle index 66e9889..2dbb717 100755 --- a/test/dummy/bin/bundle +++ b/test/dummy/bin/bundle @@ -1,3 +1,5 @@ #!/usr/bin/env ruby -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +# frozen_string_literal: true + +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) load Gem.bin_path('bundler', 'bundle') diff --git a/test/dummy/bin/rails b/test/dummy/bin/rails index 0739660..a31728a 100755 --- a/test/dummy/bin/rails +++ b/test/dummy/bin/rails @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands' diff --git a/test/dummy/bin/rake b/test/dummy/bin/rake index 1724048..c199955 100755 --- a/test/dummy/bin/rake +++ b/test/dummy/bin/rake @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require_relative '../config/boot' require 'rake' Rake.application.run diff --git a/test/dummy/bin/setup b/test/dummy/bin/setup index 78c4e86..3b7333e 100755 --- a/test/dummy/bin/setup +++ b/test/dummy/bin/setup @@ -1,10 +1,12 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require 'pathname' require 'fileutils' include FileUtils # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = Pathname.new File.expand_path('..', __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -21,7 +23,6 @@ chdir APP_ROOT do # Install JavaScript dependencies if using Yarn # system('bin/yarn') - # puts "\n== Copying sample files ==" # unless File.exist?('config/database.yml') # cp 'config/database.yml.sample', 'config/database.yml' diff --git a/test/dummy/bin/update b/test/dummy/bin/update index a8e4462..1d6aa6a 100755 --- a/test/dummy/bin/update +++ b/test/dummy/bin/update @@ -1,10 +1,12 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require 'pathname' require 'fileutils' include FileUtils # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = Pathname.new File.expand_path('..', __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") diff --git a/test/dummy/bin/yarn b/test/dummy/bin/yarn index c2bacef..80b670d 100755 --- a/test/dummy/bin/yarn +++ b/test/dummy/bin/yarn @@ -1,11 +1,11 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + VENDOR_PATH = File.expand_path('..', __dir__) Dir.chdir(VENDOR_PATH) do - begin - exec "yarnpkg #{ARGV.join(" ")}" - rescue Errno::ENOENT - $stderr.puts "Yarn executable was not detected in the system." - $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" - exit 1 - end + exec "yarnpkg #{ARGV.join(' ')}" +rescue Errno::ENOENT + warn 'Yarn executable was not detected in the system.' + warn 'Download Yarn at https://yarnpkg.com/en/docs/install' + exit 1 end diff --git a/test/dummy/config.ru b/test/dummy/config.ru index f7ba0b5..842bccc 100644 --- a/test/dummy/config.ru +++ b/test/dummy/config.ru @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is used by Rack-based servers to start the application. require_relative 'config/environment' diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index 04545ed..9cbf79f 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + require_relative 'boot' require 'rails/all' Bundler.require(*Rails.groups) -require "mission_kontrol_relay" +require 'mission_kontrol_relay' module Dummy class Application < Rails::Application @@ -16,4 +18,3 @@ class Application < Rails::Application config.active_record.sqlite3.represent_boolean_as_integer = true end end - diff --git a/test/dummy/config/boot.rb b/test/dummy/config/boot.rb index c9aef85..6d2cba0 100644 --- a/test/dummy/config/boot.rb +++ b/test/dummy/config/boot.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__) diff --git a/test/dummy/config/environment.rb b/test/dummy/config/environment.rb index 426333b..d5abe55 100644 --- a/test/dummy/config/environment.rb +++ b/test/dummy/config/environment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Load the Rails application. require_relative 'application' diff --git a/test/dummy/config/environments/development.rb b/test/dummy/config/environments/development.rb index b55e214..b67a201 100644 --- a/test/dummy/config/environments/development.rb +++ b/test/dummy/config/environments/development.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. diff --git a/test/dummy/config/environments/production.rb b/test/dummy/config/environments/production.rb index 6ea0018..13179fb 100644 --- a/test/dummy/config/environments/production.rb +++ b/test/dummy/config/environments/production.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -52,7 +54,7 @@ config.log_level = :debug # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store @@ -80,7 +82,7 @@ # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') - if ENV["RAILS_LOG_TO_STDOUT"].present? + if ENV['RAILS_LOG_TO_STDOUT'].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb index bc15387..5c253e9 100644 --- a/test/dummy/config/environments/test.rb +++ b/test/dummy/config/environments/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. diff --git a/test/dummy/config/initializers/application_controller_renderer.rb b/test/dummy/config/initializers/application_controller_renderer.rb index 89d2efa..f4556db 100644 --- a/test/dummy/config/initializers/application_controller_renderer.rb +++ b/test/dummy/config/initializers/application_controller_renderer.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # ActiveSupport::Reloader.to_prepare do diff --git a/test/dummy/config/initializers/assets.rb b/test/dummy/config/initializers/assets.rb index 4b828e8..a9b0d0f 100644 --- a/test/dummy/config/initializers/assets.rb +++ b/test/dummy/config/initializers/assets.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. diff --git a/test/dummy/config/initializers/backtrace_silencers.rb b/test/dummy/config/initializers/backtrace_silencers.rb index 59385cd..d0f0d3b 100644 --- a/test/dummy/config/initializers/backtrace_silencers.rb +++ b/test/dummy/config/initializers/backtrace_silencers.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. diff --git a/test/dummy/config/initializers/cookies_serializer.rb b/test/dummy/config/initializers/cookies_serializer.rb index 5a6a32d..ee8dff9 100644 --- a/test/dummy/config/initializers/cookies_serializer.rb +++ b/test/dummy/config/initializers/cookies_serializer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Specify a serializer for the signed and encrypted cookie jars. diff --git a/test/dummy/config/initializers/filter_parameter_logging.rb b/test/dummy/config/initializers/filter_parameter_logging.rb index 4a994e1..7a4f47b 100644 --- a/test/dummy/config/initializers/filter_parameter_logging.rb +++ b/test/dummy/config/initializers/filter_parameter_logging.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. diff --git a/test/dummy/config/initializers/inflections.rb b/test/dummy/config/initializers/inflections.rb index ac033bf..aa7435f 100644 --- a/test/dummy/config/initializers/inflections.rb +++ b/test/dummy/config/initializers/inflections.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections diff --git a/test/dummy/config/initializers/mime_types.rb b/test/dummy/config/initializers/mime_types.rb index dc18996..6e1d16f 100644 --- a/test/dummy/config/initializers/mime_types.rb +++ b/test/dummy/config/initializers/mime_types.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: diff --git a/test/dummy/config/initializers/wrap_parameters.rb b/test/dummy/config/initializers/wrap_parameters.rb index bbfc396..2f3c0db 100644 --- a/test/dummy/config/initializers/wrap_parameters.rb +++ b/test/dummy/config/initializers/wrap_parameters.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which diff --git a/test/dummy/config/puma.rb b/test/dummy/config/puma.rb index 1e19380..6ec461f 100644 --- a/test/dummy/config/puma.rb +++ b/test/dummy/config/puma.rb @@ -1,19 +1,21 @@ +# frozen_string_literal: true + # Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 } threads threads_count, threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch('PORT') { 3000 } # Specifies the `environment` that Puma will run in. # -environment ENV.fetch("RAILS_ENV") { "development" } +environment ENV.fetch('RAILS_ENV') { 'development' } # Specifies the number of `workers` to boot in clustered mode. # Workers are forked webserver processes. If using threads and workers together diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb index e6f5384..091150f 100644 --- a/test/dummy/config/routes.rb +++ b/test/dummy/config/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.routes.draw do - mount MissionKontrolRelay::Engine => "/mission_kontrol_relay" + mount MissionKontrolRelay::Engine => '/mission_kontrol_relay' end diff --git a/test/dummy/config/spring.rb b/test/dummy/config/spring.rb index c9119b4..c5933e4 100644 --- a/test/dummy/config/spring.rb +++ b/test/dummy/config/spring.rb @@ -1,6 +1,8 @@ -%w( +# frozen_string_literal: true + +%w[ .ruby-version .rbenv-vars tmp/restart.txt tmp/caching-dev.txt -).each { |path| Spring.watch(path) } +].each { |path| Spring.watch(path) } diff --git a/test/dummy/db/migrate/20200223104535_create_associations.rb b/test/dummy/db/migrate/20200223104535_create_associations.rb index 2e90fe4..753c35a 100644 --- a/test/dummy/db/migrate/20200223104535_create_associations.rb +++ b/test/dummy/db/migrate/20200223104535_create_associations.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateAssociations < ActiveRecord::Migration[5.2] def change create_table :users do |t| @@ -11,7 +13,7 @@ def change t.timestamps end - create_table(:companies_users, :id => false) do |t| + create_table(:companies_users, id: false) do |t| t.references :company t.references :user end diff --git a/test/dummy/db/migrate/20200225070228_create_more_associations.rb b/test/dummy/db/migrate/20200225070228_create_more_associations.rb index ce45ccc..27bf604 100644 --- a/test/dummy/db/migrate/20200225070228_create_more_associations.rb +++ b/test/dummy/db/migrate/20200225070228_create_more_associations.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + class CreateMoreAssociations < ActiveRecord::Migration[5.2] def change create_table :authors do |t| t.string :name t.timestamps end - + create_table :books do |t| t.belongs_to :author t.datetime :published_at @@ -15,12 +17,12 @@ def change t.string :name t.timestamps end - + create_table :patients do |t| t.string :name t.timestamps end - + create_table :appointments do |t| t.belongs_to :physician t.belongs_to :patient @@ -32,13 +34,13 @@ def change t.string :name t.timestamps end - + create_table :accounts do |t| t.belongs_to :supplier t.string :account_number t.timestamps end - + create_table :account_histories do |t| t.belongs_to :account t.integer :credit_rating @@ -49,12 +51,12 @@ def change t.string :name t.timestamps end - + create_table :parts do |t| t.string :part_number t.timestamps end - + create_table :assemblies_parts, id: false do |t| t.belongs_to :assembly t.belongs_to :part diff --git a/test/dummy/db/migrate/20200229112828_create_fields_for_validations.rb b/test/dummy/db/migrate/20200229112828_create_fields_for_validations.rb index 38afb4a..d83f8ee 100644 --- a/test/dummy/db/migrate/20200229112828_create_fields_for_validations.rb +++ b/test/dummy/db/migrate/20200229112828_create_fields_for_validations.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateFieldsForValidations < ActiveRecord::Migration[5.2] def change add_column :patients, :email, :string diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index 4a1249c..d4db4c7 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # 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. @@ -10,107 +12,105 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_02_29_112828) do - - create_table "account_histories", force: :cascade do |t| - t.integer "account_id" - t.integer "credit_rating" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["account_id"], name: "index_account_histories_on_account_id" +ActiveRecord::Schema.define(version: 20_200_229_112_828) do + create_table 'account_histories', force: :cascade do |t| + t.integer 'account_id' + t.integer 'credit_rating' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['account_id'], name: 'index_account_histories_on_account_id' end - create_table "accounts", force: :cascade do |t| - t.integer "supplier_id" - t.string "account_number" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["supplier_id"], name: "index_accounts_on_supplier_id" + create_table 'accounts', force: :cascade do |t| + t.integer 'supplier_id' + t.string 'account_number' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['supplier_id'], name: 'index_accounts_on_supplier_id' end - create_table "appointments", force: :cascade do |t| - t.integer "physician_id" - t.integer "patient_id" - t.datetime "appointment_date" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["patient_id"], name: "index_appointments_on_patient_id" - t.index ["physician_id"], name: "index_appointments_on_physician_id" + create_table 'appointments', force: :cascade do |t| + t.integer 'physician_id' + t.integer 'patient_id' + t.datetime 'appointment_date' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['patient_id'], name: 'index_appointments_on_patient_id' + t.index ['physician_id'], name: 'index_appointments_on_physician_id' end - create_table "assemblies", force: :cascade do |t| - t.string "name" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "points" + create_table 'assemblies', force: :cascade do |t| + t.string 'name' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.integer 'points' end - create_table "assemblies_parts", id: false, force: :cascade do |t| - t.integer "assembly_id" - t.integer "part_id" - t.index ["assembly_id"], name: "index_assemblies_parts_on_assembly_id" - t.index ["part_id"], name: "index_assemblies_parts_on_part_id" + create_table 'assemblies_parts', id: false, force: :cascade do |t| + t.integer 'assembly_id' + t.integer 'part_id' + t.index ['assembly_id'], name: 'index_assemblies_parts_on_assembly_id' + t.index ['part_id'], name: 'index_assemblies_parts_on_part_id' end - create_table "authors", force: :cascade do |t| - t.string "name" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table 'authors', force: :cascade do |t| + t.string 'name' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false end - create_table "books", force: :cascade do |t| - t.integer "author_id" - t.datetime "published_at" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["author_id"], name: "index_books_on_author_id" + create_table 'books', force: :cascade do |t| + t.integer 'author_id' + t.datetime 'published_at' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['author_id'], name: 'index_books_on_author_id' end - create_table "companies", force: :cascade do |t| - t.integer "owner" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "subdomain" + create_table 'companies', force: :cascade do |t| + t.integer 'owner' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.string 'subdomain' end - create_table "companies_users", id: false, force: :cascade do |t| - t.integer "company_id" - t.integer "user_id" - t.index ["company_id"], name: "index_companies_users_on_company_id" - t.index ["user_id"], name: "index_companies_users_on_user_id" + create_table 'companies_users', id: false, force: :cascade do |t| + t.integer 'company_id' + t.integer 'user_id' + t.index ['company_id'], name: 'index_companies_users_on_company_id' + t.index ['user_id'], name: 'index_companies_users_on_user_id' end - create_table "parts", force: :cascade do |t| - t.string "part_number" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "legacy_code" - t.string "size" + create_table 'parts', force: :cascade do |t| + t.string 'part_number' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.string 'legacy_code' + t.string 'size' end - create_table "patients", force: :cascade do |t| - t.string "name" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "email" + create_table 'patients', force: :cascade do |t| + t.string 'name' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.string 'email' end - create_table "physicians", force: :cascade do |t| - t.string "name" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table 'physicians', force: :cascade do |t| + t.string 'name' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false end - create_table "suppliers", force: :cascade do |t| - t.string "name" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table 'suppliers', force: :cascade do |t| + t.string 'name' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false end - create_table "users", force: :cascade do |t| - t.string "name" - t.boolean "active" - t.integer "company_id" + create_table 'users', force: :cascade do |t| + t.string 'name' + t.boolean 'active' + t.integer 'company_id' end - end diff --git a/test/integration/navigation_test.rb b/test/integration/navigation_test.rb index 682fe72..e842842 100644 --- a/test/integration/navigation_test.rb +++ b/test/integration/navigation_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # require 'test_helper' # class NavigationTest < ActionDispatch::IntegrationTest @@ -5,4 +6,3 @@ # # assert true # # end # end - diff --git a/test/mission_kontrol_relay_test.rb b/test/mission_kontrol_relay_test.rb index 3374f73..9724f50 100644 --- a/test/mission_kontrol_relay_test.rb +++ b/test/mission_kontrol_relay_test.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + require 'test_helper' class MissionKontrolRelayTest < ActiveSupport::TestCase - test "truth" do + test 'truth' do assert_kind_of Module, MissionKontrolRelay end end diff --git a/test/services/mission_kontrol_relay/association_mapping_service_test.rb b/test/services/mission_kontrol_relay/association_mapping_service_test.rb deleted file mode 100644 index 67818ba..0000000 --- a/test/services/mission_kontrol_relay/association_mapping_service_test.rb +++ /dev/null @@ -1,48 +0,0 @@ -module MissionKontrolRelay - class AssociationMappingServiceTest < ActiveSupport::TestCase - def setup - @association_mapping_company = AssociationMappingService.new(Company).build - @association_mapping_user = AssociationMappingService.new(User).build - end - - test 'returns a hash with the model name' do - assert_equal @association_mapping_company[:model], 'Company' - end - - test 'returns an array of columns on the model' do - assert_kind_of Array, @association_mapping_company[:columns] - end - - test 'returns the name on the columns' do - assert_equal @association_mapping_company[:columns].first[:column], "id" - end - - test 'returns the sql type on the columns' do - assert_equal @association_mapping_company[:columns].first[:type], :integer - end - - test 'returns an array of associations on the model' do - assert_kind_of Array, @association_mapping_company[:associations] - end - - test 'returns name of related model when belongs_to relationship present' do - assert_equal @association_mapping_company[:associations].first[:associated_model], :user - end - - test 'returns foreign_key of related model when belongs_to relationship present' do - assert_equal @association_mapping_company[:associations].first[:foreign_key], "owner" - end - - test 'returns type of related model when belongs_to relationship present' do - assert_equal @association_mapping_company[:associations].first[:type], :belongs_to - end - - test 'returns name of related model when has_one relationship present' do - assert_equal @association_mapping_user[:associations].first[:associated_model], :company - end - - test 'returns type of related model when has_one relationship present' do - assert_equal @association_mapping_user[:associations].first[:type], :has_one - end - end -end \ No newline at end of file diff --git a/test/services/mission_kontrol_relay/validation_mapping_service_test.rb b/test/services/mission_kontrol_relay/validation_mapping_service_test.rb deleted file mode 100644 index 378d2b1..0000000 --- a/test/services/mission_kontrol_relay/validation_mapping_service_test.rb +++ /dev/null @@ -1,39 +0,0 @@ -module MissionKontrolRelay - class ValidationMappingServiceTest < ActiveSupport::TestCase - def setup - @validation_mapping_company = ValidationMappingService.new(Company).build - @validation_mapping_user = ValidationMappingService.new(User).build - end - - test 'returns a hash with the model name' do - assert_equal 'User', @validation_mapping_user[:model] - end - - test 'returns an array of validations on the model' do - assert_kind_of Array, @validation_mapping_user[:validations] - end - - test 'returns a hash with the validation information for user' do - expected_result = { - key: nil, - kind: :before, - name: :validate, - attributes: [:name] - } - - assert_equal expected_result, @validation_mapping_user[:validations] - end - - test 'returns a hash with the validation information for company' do - expected_result = { - key: nil, - kind: :before, - name: :validate, - attributes: [:owner], - if: [:something_else?] - } - - assert_equal expected_result, @validation_mapping_company[:validations] - end - end -end \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index cdca8fd..6c14ac8 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,19 +1,20 @@ +# frozen_string_literal: true + # Configure Rails Environment -ENV["RAILS_ENV"] = "test" -require File.expand_path("../../test/dummy/config/environment.rb", __FILE__) -ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)] -ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate', __FILE__) -require "rails/test_help" +ENV['RAILS_ENV'] = 'test' +require File.expand_path('../test/dummy/config/environment.rb', __dir__) +ActiveRecord::Migrator.migrations_paths = [File.expand_path('../test/dummy/db/migrate', __dir__)] +ActiveRecord::Migrator.migrations_paths << File.expand_path('../db/migrate', __dir__) +require 'rails/test_help' # Filter out Minitest backtrace while allowing backtrace from other libraries # to be shown. Minitest.backtrace_filter = Minitest::BacktraceFilter.new - # Load fixtures from the engine if ActiveSupport::TestCase.respond_to?(:fixture_path=) - ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__) + ActiveSupport::TestCase.fixture_path = File.expand_path('fixtures', __dir__) ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path - ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files" + ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + '/files' ActiveSupport::TestCase.fixtures :all end