diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 67dce891..34131270 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,23 @@ on: branches: "*" jobs: + standard: + name: Lint with Standard + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Run standardrb + uses: standardrb/standard-ruby-action@f533e61f461ccb766b2d9c235abf59be02aea793 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + permissions: + checks: write + contents: read + build: name: Ruby ${{ matrix.ruby }}, Rails ${{ matrix.rails }} diff --git a/.hound.yml b/.hound.yml deleted file mode 100644 index f534df8c..00000000 --- a/.hound.yml +++ /dev/null @@ -1,2 +0,0 @@ -rubocop: - config_file: .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml deleted file mode 100644 index 2447a73d..00000000 --- a/.rubocop.yml +++ /dev/null @@ -1,129 +0,0 @@ -AllCops: - TargetRubyVersion: 2.3.0 - Exclude: - - "tmp/**/*" - - "bin/*" - - "spec/dummy/**/*" - -Bundler/OrderedGems: - Enabled: false - -Gemspec/OrderedDependencies: - Enabled: false - -Layout/AlignParameters: - Enabled: true - EnforcedStyle: with_fixed_indentation -Layout/ConditionPosition: - Enabled: false -Layout/DotPosition: - EnforcedStyle: leading -Layout/ExtraSpacing: - Enabled: true -Layout/IndentAssignment: - Enabled: False -Layout/MultilineOperationIndentation: - Enabled: true - EnforcedStyle: indented -Layout/MultilineMethodCallIndentation: - Enabled: true - EnforcedStyle: indented - -Lint/AmbiguousOperator: - Enabled: true -Lint/AmbiguousRegexpLiteral: - Enabled: true -Lint/DuplicatedKey: - Enabled: true - -Metrics/ClassLength: - Enabled: false -Metrics/ModuleLength: - Enabled: false -Metrics/AbcSize: - Enabled: false -Metrics/BlockLength: - CountComments: true # count full line comments? - Max: 25 - ExcludedMethods: [] - Exclude: - - "spec/**/*" - - "*.gemspec" -Metrics/CyclomaticComplexity: - Enabled: false -Metrics/LineLength: - Max: 80 -Metrics/MethodLength: - Enabled: false - -Security/Eval: - Enabled: true - Exclude: - - "spec/scenic/schema_dumper_spec.rb" -Style/BlockDelimiters: - Enabled: false -Style/CollectionMethods: - Enabled: true - PreferredMethods: - find: find - inject: reduce - collect: map - find_all: select -Style/ConditionalAssignment: - Enabled: false -Style/ClassAndModuleChildren: - Enabled: true - Exclude: - - "spec/**/*" -Style/Documentation: - Enabled: false -Style/FrozenStringLiteralComment: - Description: >- - Add the frozen_string_literal comment to the top of files - to help transition from Ruby 2.3.0 to Ruby 3.0. - Enabled: false -Style/GuardClause: - Enabled: false -Style/IfUnlessModifier: - Enabled: false -Style/Lambda: - Enabled: false -Style/NumericLiterals: - Enabled: false -Style/OneLineConditional: - Enabled: false -Style/PercentLiteralDelimiters: - Enabled: false -Style/StringLiterals: - EnforcedStyle: double_quotes - Enabled: true -Style/TrailingCommaInArguments: - Description: 'Checks for trailing comma in argument lists.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas' - EnforcedStyleForMultiline: comma - SupportedStylesForMultiline: - - comma - - consistent_comma - - no_comma - Enabled: true -Style/TrailingCommaInArrayLiteral: - Description: 'Checks for trailing comma in array literals.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas' - EnforcedStyleForMultiline: comma - SupportedStylesForMultiline: - - comma - - consistent_comma - - no_comma - Enabled: true -Style/TrailingCommaInHashLiteral: - Description: 'Checks for trailing comma in hash literals.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas' - EnforcedStyleForMultiline: comma - SupportedStylesForMultiline: - - comma - - consistent_comma - - no_comma - Enabled: true -Style/WordArray: - Enabled: false - diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9b817621..7aea3a3f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,6 +13,7 @@ agree to abide by our [code of conduct]. 3. Run `rake` to verify that the tests pass against the version of Rails you are running locally. 4. Make your change with new passing tests, following existing style. +5. Run `standardrb --fix` to ensure your code is formatted correctly. 5. Write a [good commit message], push your fork, and submit a pull request. 6. CI will run the test suite on all configured versions of Ruby and Rails. Address any failures. diff --git a/Gemfile b/Gemfile index cf2dafe7..5c270e1f 100644 --- a/Gemfile +++ b/Gemfile @@ -5,10 +5,10 @@ gemspec rails_version = ENV.fetch("RAILS_VERSION", "6.1") -if rails_version == "master" - rails_constraint = { github: "rails/rails" } +rails_constraint = if rails_version == "master" + {github: "rails/rails"} else - rails_constraint = "~> #{rails_version}.0" + "~> #{rails_version}.0" end gem "rails", rails_constraint diff --git a/README.md b/README.md index 8f403a94..a67db0fa 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ [![Build Status](https://github.com/scenic-views/scenic/actions/workflows/ci.yml/badge.svg)](https://github.com/scenic-views/scenic/actions/workflows/ci.yml) [![Documentation Quality](http://inch-ci.org/github/scenic-views/scenic.svg?branch=master)](http://inch-ci.org/github/scenic-views/scenic) -[![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com) Scenic adds methods to `ActiveRecord::Migration` to create and manage database views in Rails. diff --git a/Rakefile b/Rakefile index 91805257..0d6c7b76 100644 --- a/Rakefile +++ b/Rakefile @@ -26,4 +26,4 @@ RSpec::Core::RakeTask.new("spec:acceptance") do |task| end desc "Run the specs and acceptance tests" -task default: %w(spec spec:acceptance) +task default: %w[spec spec:acceptance] diff --git a/bin/standardrb b/bin/standardrb new file mode 100755 index 00000000..b329561c --- /dev/null +++ b/bin/standardrb @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'standardrb' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("standard", "standardrb") diff --git a/lib/generators/scenic/model/model_generator.rb b/lib/generators/scenic/model/model_generator.rb index 41627fcc..d5796306 100644 --- a/lib/generators/scenic/model/model_generator.rb +++ b/lib/generators/scenic/model/model_generator.rb @@ -15,7 +15,7 @@ def invoke_rails_model_generator [file_path.singularize], options.merge( fixture_replacement: false, - migration: false, + migration: false ) end @@ -34,23 +34,14 @@ def invoke_view_generator private def evaluate_template(source) - source = File.expand_path(find_in_source_paths(source.to_s)) + source = File.expand_path(find_in_source_paths(source.to_s)) context = instance_eval("binding", __FILE__, __LINE__) - if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ - erb = ERB.new( - ::File.binread(source), - trim_mode: "-", - eoutvar: "@output_buffer", - ) - else - erb = ERB.new( - ::File.binread(source), - nil, - "-", - "@output_buffer", - ) - end + erb = ERB.new( + ::File.binread(source), + trim_mode: "-", + eoutvar: "@output_buffer" + ) erb.result(context) end diff --git a/lib/generators/scenic/view/view_generator.rb b/lib/generators/scenic/view/view_generator.rb index 496035f8..555c321d 100644 --- a/lib/generators/scenic/view/view_generator.rb +++ b/lib/generators/scenic/view/view_generator.rb @@ -28,12 +28,12 @@ def create_migration_file if creating_new_view? || destroying_initial_view? migration_template( "db/migrate/create_view.erb", - "db/migrate/create_#{plural_file_name}.rb", + "db/migrate/create_#{plural_file_name}.rb" ) else migration_template( "db/migrate/update_view.erb", - "db/migrate/update_#{plural_file_name}_to_version_#{version}.rb", + "db/migrate/update_#{plural_file_name}_to_version_#{version}.rb" ) end end @@ -56,7 +56,7 @@ def version def migration_class_name if creating_new_view? - "Create#{class_name.tr('.', '').pluralize}" + "Create#{class_name.tr(".", "").pluralize}" else "Update#{class_name.pluralize}ToVersion#{version}" end @@ -73,7 +73,7 @@ def activerecord_migration_class private - alias singular_name file_name + alias_method :singular_name, :file_name def file_name super.tr(".", "_") @@ -113,7 +113,7 @@ def formatted_plural_name def create_view_options if materialized? - ", materialized: #{no_data? ? '{ no_data: true }' : true}" + ", materialized: #{no_data? ? "{ no_data: true }" : true}" else "" end diff --git a/lib/scenic/adapters/postgres.rb b/lib/scenic/adapters/postgres.rb index 2d5ccf57..ba1fb4e1 100644 --- a/lib/scenic/adapters/postgres.rb +++ b/lib/scenic/adapters/postgres.rb @@ -137,8 +137,8 @@ def create_materialized_view(name, sql_definition, no_data: false) execute <<-SQL CREATE MATERIALIZED VIEW #{quote_table_name(name)} AS - #{sql_definition.rstrip.chomp(';')} - #{'WITH NO DATA' if no_data}; + #{sql_definition.rstrip.chomp(";")} + #{"WITH NO DATA" if no_data}; SQL end @@ -271,7 +271,7 @@ def refresh_dependencies_for(name, concurrently: false) name, self, connection, - concurrently: concurrently, + concurrently: concurrently ) end end diff --git a/lib/scenic/adapters/postgres/indexes.rb b/lib/scenic/adapters/postgres/indexes.rb index 8ce36de6..5b4421c4 100644 --- a/lib/scenic/adapters/postgres/indexes.rb +++ b/lib/scenic/adapters/postgres/indexes.rb @@ -44,7 +44,7 @@ def index_from_database(result) Scenic::Index.new( object_name: result["object_name"], index_name: result["index_name"], - definition: result["definition"], + definition: result["definition"] ) end end diff --git a/lib/scenic/adapters/postgres/refresh_dependencies.rb b/lib/scenic/adapters/postgres/refresh_dependencies.rb index 9c1b7a25..75c24810 100644 --- a/lib/scenic/adapters/postgres/refresh_dependencies.rb +++ b/lib/scenic/adapters/postgres/refresh_dependencies.rb @@ -17,7 +17,7 @@ def call dependencies.each do |dependency| adapter.refresh_materialized_view( dependency, - concurrently: concurrently, + concurrently: concurrently ) end end @@ -103,8 +103,8 @@ def tsort(hash) ORDER BY class_for_rewrite.relname; SQL - private_constant "DependencyParser" - private_constant "DEPENDENCY_SQL" + private_constant :DependencyParser + private_constant :DEPENDENCY_SQL def dependencies raw_dependency_info = connection.select_rows(DEPENDENCY_SQL) diff --git a/lib/scenic/adapters/postgres/views.rb b/lib/scenic/adapters/postgres/views.rb index e7298f07..02b93588 100644 --- a/lib/scenic/adapters/postgres/views.rb +++ b/lib/scenic/adapters/postgres/views.rb @@ -43,21 +43,21 @@ def views_from_postgres def to_scenic_view(result) namespace, viewname = result.values_at "namespace", "viewname" - if namespace != "public" - namespaced_viewname = "#{pg_identifier(namespace)}.#{pg_identifier(viewname)}" + namespaced_viewname = if namespace != "public" + "#{pg_identifier(namespace)}.#{pg_identifier(viewname)}" else - namespaced_viewname = pg_identifier(viewname) + pg_identifier(viewname) end Scenic::View.new( name: namespaced_viewname, definition: result["definition"].strip, - materialized: result["kind"] == "m", + materialized: result["kind"] == "m" ) end def pg_identifier(name) - return name if name =~ /^[a-zA-Z_][a-zA-Z0-9_]*$/ + return name if /^[a-zA-Z_][a-zA-Z0-9_]*$/.match?(name) pgconn.quote_ident(name) end diff --git a/lib/scenic/definition.rb b/lib/scenic/definition.rb index 58195107..639cee3c 100644 --- a/lib/scenic/definition.rb +++ b/lib/scenic/definition.rb @@ -31,7 +31,7 @@ def version attr_reader :name def filename - "#{UnaffixedName.for(name).tr('.', '_')}_v#{version}.sql" + "#{UnaffixedName.for(name).tr(".", "_")}_v#{version}.sql" end end end diff --git a/lib/scenic/statements.rb b/lib/scenic/statements.rb index 84bf24b0..c3caa0ca 100644 --- a/lib/scenic/statements.rb +++ b/lib/scenic/statements.rb @@ -26,7 +26,7 @@ def create_view(name, version: nil, sql_definition: nil, materialized: false) if version.present? && sql_definition.present? raise( ArgumentError, - "sql_definition and version cannot both be set", + "sql_definition and version cannot both be set" ) end @@ -40,7 +40,7 @@ def create_view(name, version: nil, sql_definition: nil, materialized: false) Scenic.database.create_materialized_view( name, sql_definition, - no_data: no_data(materialized), + no_data: no_data(materialized) ) else Scenic.database.create_view(name, sql_definition) @@ -92,14 +92,14 @@ def update_view(name, version: nil, sql_definition: nil, revert_to_version: nil, if version.blank? && sql_definition.blank? raise( ArgumentError, - "sql_definition or version must be specified", + "sql_definition or version must be specified" ) end if version.present? && sql_definition.present? raise( ArgumentError, - "sql_definition and version cannot both be set", + "sql_definition and version cannot both be set" ) end @@ -109,7 +109,7 @@ def update_view(name, version: nil, sql_definition: nil, revert_to_version: nil, Scenic.database.update_materialized_view( name, sql_definition, - no_data: no_data(materialized), + no_data: no_data(materialized) ) else Scenic.database.update_view(name, sql_definition) diff --git a/scenic.gemspec b/scenic.gemspec index 5f6f069f..edafe043 100644 --- a/scenic.gemspec +++ b/scenic.gemspec @@ -3,20 +3,19 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "scenic/version" Gem::Specification.new do |spec| - spec.name = "scenic" - spec.version = Scenic::VERSION - spec.authors = ["Derek Prior", "Caleb Hearth"] - spec.email = ["derekprior@gmail.com", "caleb@calebhearth.com"] - spec.summary = "Support for database views in Rails migrations" - spec.description = <<-DESCRIPTION + spec.name = "scenic" + spec.version = Scenic::VERSION + spec.authors = ["Derek Prior", "Caleb Hearth"] + spec.email = ["derekprior@gmail.com", "caleb@calebhearth.com"] + spec.summary = "Support for database views in Rails migrations" + spec.description = <<-DESCRIPTION Adds methods to ActiveRecord::Migration to create and manage database views in Rails DESCRIPTION - spec.homepage = "https://github.com/scenic-views/scenic" - spec.license = "MIT" + spec.homepage = "https://github.com/scenic-views/scenic" + spec.license = "MIT" - spec.files = `git ls-files -z`.split("\x0") - spec.test_files = spec.files.grep(%r{^spec/}) + spec.files = `git ls-files -z`.split("\x0") spec.require_paths = ["lib"] spec.add_development_dependency "bundler", ">= 1.5" @@ -28,6 +27,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency "ammeter", ">= 1.1.3" spec.add_development_dependency "yard" spec.add_development_dependency "redcarpet" + spec.add_development_dependency "standard" spec.add_dependency "activerecord", ">= 4.0.0" spec.add_dependency "railties", ">= 4.0.0" diff --git a/spec/dummy/Rakefile b/spec/dummy/Rakefile index a64c3a76..52537448 100644 --- a/spec/dummy/Rakefile +++ b/spec/dummy/Rakefile @@ -1,13 +1,13 @@ # 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. -require File.expand_path('../config/application', __FILE__) +require File.expand_path("../config/application", __FILE__) Rails.application.load_tasks -unless Rake::Task.task_defined?('db:environment:set') - desc 'dummy task for rails versions where this task does not exist' - task 'db:environment:set' do - #no op +unless Rake::Task.task_defined?("db:environment:set") + desc "dummy task for rails versions where this task does not exist" + task "db:environment:set" do + # no op end end diff --git a/spec/dummy/bin/bundle b/spec/dummy/bin/bundle index 66e9889e..fe187450 100755 --- a/spec/dummy/bin/bundle +++ b/spec/dummy/bin/bundle @@ -1,3 +1,3 @@ #!/usr/bin/env ruby -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -load Gem.bin_path('bundler', 'bundle') +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__) +load Gem.bin_path("bundler", "bundle") diff --git a/spec/dummy/bin/rails b/spec/dummy/bin/rails index 728cd85a..8b245672 100755 --- a/spec/dummy/bin/rails +++ b/spec/dummy/bin/rails @@ -1,4 +1,4 @@ #!/usr/bin/env ruby -APP_PATH = File.expand_path('../../config/application', __FILE__) -require_relative '../config/boot' -require 'rails/commands' +APP_PATH = File.expand_path("../../config/application", __FILE__) +require_relative "../config/boot" +require "rails/commands" diff --git a/spec/dummy/bin/rake b/spec/dummy/bin/rake index 17240489..4fbf10b9 100755 --- a/spec/dummy/bin/rake +++ b/spec/dummy/bin/rake @@ -1,4 +1,4 @@ #!/usr/bin/env ruby -require_relative '../config/boot' -require 'rake' +require_relative "../config/boot" +require "rake" Rake.application.run diff --git a/spec/dummy/config.ru b/spec/dummy/config.ru index 5bc2a619..193e5fed 100644 --- a/spec/dummy/config.ru +++ b/spec/dummy/config.ru @@ -1,4 +1,4 @@ # This file is used by Rack-based servers to start the application. -require ::File.expand_path('../config/environment', __FILE__) +require ::File.expand_path("../config/environment", __FILE__) run Rails.application diff --git a/spec/dummy/db/migrate/20220112154220_add_pg_stat_statements_extension.rb b/spec/dummy/db/migrate/20220112154220_add_pg_stat_statements_extension.rb index 8cde41d0..5a5e2fef 100644 --- a/spec/dummy/db/migrate/20220112154220_add_pg_stat_statements_extension.rb +++ b/spec/dummy/db/migrate/20220112154220_add_pg_stat_statements_extension.rb @@ -1,5 +1,5 @@ class AddPgStatStatementsExtension < ActiveRecord::Migration[6.1] def change - enable_extension 'pg_stat_statements' + enable_extension "pg_stat_statements" end end diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb index e247310a..065dade7 100644 --- a/spec/dummy/db/schema.rb +++ b/spec/dummy/db/schema.rb @@ -11,9 +11,7 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 2022_01_12_154220) do - # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" enable_extension "plpgsql" - end diff --git a/spec/generators/scenic/model/model_generator_spec.rb b/spec/generators/scenic/model/model_generator_spec.rb index 8858b046..a602238f 100644 --- a/spec/generators/scenic/model/model_generator_spec.rb +++ b/spec/generators/scenic/model/model_generator_spec.rb @@ -6,7 +6,7 @@ module Scenic::Generators before do allow(ViewGenerator).to receive(:new) .and_return( - instance_double("Scenic::Generators::ViewGenerator").as_null_object, + instance_double("Scenic::Generators::ViewGenerator").as_null_object ) end diff --git a/spec/generators/scenic/view/view_generator_spec.rb b/spec/generators/scenic/view/view_generator_spec.rb index 1340c4af..6df79ac1 100644 --- a/spec/generators/scenic/view/view_generator_spec.rb +++ b/spec/generators/scenic/view/view_generator_spec.rb @@ -31,7 +31,7 @@ run_generator ["aired_episode", "--materialized"] migration = migration_file( - "db/migrate/update_aired_episodes_to_version_2.rb", + "db/migrate/update_aired_episodes_to_version_2.rb" ) expect(migration).to contain "materialized: true" end @@ -43,7 +43,7 @@ run_generator ["aired_episode", "--replace"] migration = migration_file( - "db/migrate/update_aired_episodes_to_version_2.rb", + "db/migrate/update_aired_episodes_to_version_2.rb" ) expect(migration).to contain "replace_view" end diff --git a/spec/integration/revert_spec.rb b/spec/integration/revert_spec.rb index 2131e16f..572fe84f 100644 --- a/spec/integration/revert_spec.rb +++ b/spec/integration/revert_spec.rb @@ -61,7 +61,7 @@ def migration_class end def run_migration(migration, directions) - silence_stream(STDOUT) do + silence_stream($stdout) do Array.wrap(directions).each do |direction| migration.migrate(direction) end diff --git a/spec/scenic/adapters/postgres/connection_spec.rb b/spec/scenic/adapters/postgres/connection_spec.rb index 34ef9c01..755f118b 100644 --- a/spec/scenic/adapters/postgres/connection_spec.rb +++ b/spec/scenic/adapters/postgres/connection_spec.rb @@ -9,7 +9,7 @@ module Adapters base_response = double("response from base connection") base_connection = double( "Connection", - supports_materialized_views?: base_response, + supports_materialized_views?: base_response ) connection = Postgres::Connection.new(base_connection) diff --git a/spec/scenic/adapters/postgres/refresh_dependencies_spec.rb b/spec/scenic/adapters/postgres/refresh_dependencies_spec.rb index 5811e343..523630fa 100644 --- a/spec/scenic/adapters/postgres/refresh_dependencies_spec.rb +++ b/spec/scenic/adapters/postgres/refresh_dependencies_spec.rb @@ -9,27 +9,27 @@ module Adapters before do adapter.create_materialized_view( "first", - "SELECT text 'hi' AS greeting", + "SELECT text 'hi' AS greeting" ) adapter.create_materialized_view( "second", - "SELECT * FROM first", + "SELECT * FROM first" ) adapter.create_materialized_view( "third", - "SELECT * FROM first UNION SELECT * FROM second", + "SELECT * FROM first UNION SELECT * FROM second" ) adapter.create_materialized_view( "fourth_1", - "SELECT * FROM third", + "SELECT * FROM third" ) adapter.create_materialized_view( "x_fourth", - "SELECT * FROM fourth_1", + "SELECT * FROM fourth_1" ) adapter.create_materialized_view( "fourth", - "SELECT * FROM fourth_1 UNION SELECT * FROM x_fourth", + "SELECT * FROM fourth_1 UNION SELECT * FROM x_fourth" ) expect(adapter).to receive(:refresh_materialized_view) @@ -49,7 +49,7 @@ module Adapters :fourth, adapter, ActiveRecord::Base.connection, - concurrently: true, + concurrently: true ) end @@ -58,7 +58,7 @@ module Adapters "public.fourth", adapter, ActiveRecord::Base.connection, - concurrently: true, + concurrently: true ) end end @@ -69,7 +69,7 @@ module Adapters adapter.create_materialized_view( "first", - "SELECT text 'hi' AS greeting", + "SELECT text 'hi' AS greeting" ) expect { diff --git a/spec/scenic/adapters/postgres_spec.rb b/spec/scenic/adapters/postgres_spec.rb index b3dfe3cd..d8358a16 100644 --- a/spec/scenic/adapters/postgres_spec.rb +++ b/spec/scenic/adapters/postgres_spec.rb @@ -19,7 +19,7 @@ module Adapters adapter.create_materialized_view( "greetings", - "SELECT text 'hi' AS greeting", + "SELECT text 'hi' AS greeting" ) view = adapter.views.first @@ -33,7 +33,7 @@ module Adapters adapter.create_materialized_view( "greetings", "SELECT text 'hi' AS greeting; \n", - no_data: true, + no_data: true ) view = adapter.views.first @@ -85,7 +85,7 @@ module Adapters adapter.create_materialized_view( "greetings", - "SELECT text 'hi' AS greeting", + "SELECT text 'hi' AS greeting" ) adapter.drop_materialized_view("greetings") @@ -125,7 +125,7 @@ module Adapters adapter.refresh_materialized_view( :tests, cascade: true, - concurrently: true, + concurrently: true ) end @@ -179,7 +179,7 @@ module Adapters "parents", "children", "people", - "people_with_names", + "people_with_names" ] end @@ -199,7 +199,7 @@ module Adapters expect(adapter.views.map(&:name)).to eq [ "parents", - "scenic.parents", + "scenic.parents" ] end end diff --git a/spec/scenic/command_recorder/statement_arguments_spec.rb b/spec/scenic/command_recorder/statement_arguments_spec.rb index ae21299b..c3b651da 100644 --- a/spec/scenic/command_recorder/statement_arguments_spec.rb +++ b/spec/scenic/command_recorder/statement_arguments_spec.rb @@ -4,7 +4,7 @@ module Scenic::CommandRecorder describe StatementArguments do describe "#view" do it "is the view name" do - raw_args = [:spaceships, { foo: :bar }] + raw_args = [:spaceships, {foo: :bar}] args = StatementArguments.new(raw_args) expect(args.view).to eq :spaceships @@ -13,14 +13,14 @@ module Scenic::CommandRecorder describe "#revert_to_version" do it "is the revert_to_version from the keyword arguments" do - raw_args = [:spaceships, { revert_to_version: 42 }] + raw_args = [:spaceships, {revert_to_version: 42}] args = StatementArguments.new(raw_args) expect(args.revert_to_version).to eq 42 end it "is nil if the revert_to_version was not supplied" do - raw_args = [:spaceships, { foo: :bar }] + raw_args = [:spaceships, {foo: :bar}] args = StatementArguments.new(raw_args) expect(args.revert_to_version).to be nil @@ -29,7 +29,7 @@ module Scenic::CommandRecorder describe "#invert_version" do it "returns object with version set to revert_to_version" do - raw_args = [:meatballs, { version: 42, revert_to_version: 15 }] + raw_args = [:meatballs, {version: 42, revert_to_version: 15}] inverted_args = StatementArguments.new(raw_args).invert_version diff --git a/spec/scenic/command_recorder_spec.rb b/spec/scenic/command_recorder_spec.rb index edc1016f..a33d2bc8 100644 --- a/spec/scenic/command_recorder_spec.rb +++ b/spec/scenic/command_recorder_spec.rb @@ -24,7 +24,7 @@ recorder.revert { recorder.create_view :greetings, materialized: true } expect(recorder.commands).to eq [ - [:drop_view, [:greetings, materialized: true]], + [:drop_view, [:greetings, materialized: true]] ] end end @@ -37,8 +37,8 @@ end it "reverts to create_view with specified revert_to_version" do - args = [:users, { revert_to_version: 3 }] - revert_args = [:users, { version: 3 }] + args = [:users, {revert_to_version: 3}] + revert_args = [:users, {version: 3}] recorder.revert { recorder.drop_view(*args) } @@ -46,7 +46,7 @@ end it "raises when reverting without revert_to_version set" do - args = [:users, { another_argument: 1 }] + args = [:users, {another_argument: 1}] expect { recorder.revert { recorder.drop_view(*args) } } .to raise_error(ActiveRecord::IrreversibleMigration) @@ -55,7 +55,7 @@ describe "#update_view" do it "records the updated view" do - args = [:users, { version: 2 }] + args = [:users, {version: 2}] recorder.update_view(*args) @@ -63,8 +63,8 @@ end it "reverts to update_view with the specified revert_to_version" do - args = [:users, { version: 2, revert_to_version: 1 }] - revert_args = [:users, { version: 1 }] + args = [:users, {version: 2, revert_to_version: 1}] + revert_args = [:users, {version: 1}] recorder.revert { recorder.update_view(*args) } @@ -72,7 +72,7 @@ end it "raises when reverting without revert_to_version set" do - args = [:users, { version: 42, another_argument: 1 }] + args = [:users, {version: 42, another_argument: 1}] expect { recorder.revert { recorder.update_view(*args) } } .to raise_error(ActiveRecord::IrreversibleMigration) @@ -81,7 +81,7 @@ describe "#replace_view" do it "records the replaced view" do - args = [:users, { version: 2 }] + args = [:users, {version: 2}] recorder.replace_view(*args) @@ -89,8 +89,8 @@ end it "reverts to replace_view with the specified revert_to_version" do - args = [:users, { version: 2, revert_to_version: 1 }] - revert_args = [:users, { version: 1 }] + args = [:users, {version: 2, revert_to_version: 1}] + revert_args = [:users, {version: 1}] recorder.revert { recorder.replace_view(*args) } @@ -98,7 +98,7 @@ end it "raises when reverting without revert_to_version set" do - args = [:users, { version: 42, another_argument: 1 }] + args = [:users, {version: 42, another_argument: 1}] expect { recorder.revert { recorder.replace_view(*args) } } .to raise_error(ActiveRecord::IrreversibleMigration) diff --git a/spec/scenic/schema_dumper_spec.rb b/spec/scenic/schema_dumper_spec.rb index 893dd9f9..c9f285eb 100644 --- a/spec/scenic/schema_dumper_spec.rb +++ b/spec/scenic/schema_dumper_spec.rb @@ -21,7 +21,7 @@ class SearchInAHaystack < ActiveRecord::Base Search.connection.drop_view :searches - silence_stream(STDOUT) { eval(output) } + silence_stream($stdout) { eval(output) } # standard:disable Security/Eval expect(Search.first.haystack).to eq "needle" end @@ -37,7 +37,7 @@ class SearchInAHaystack < ActiveRecord::Base expect(output).to include "~ '\\\\d+'::text" Search.connection.drop_view :searches - silence_stream(STDOUT) { eval(output) } + silence_stream($stdout) { eval(output) } # standard:disable Security/Eval expect(Search.first.haystack).to eq "needle" end @@ -67,7 +67,7 @@ class SearchInAHaystack < ActiveRecord::Base output = stream.string expect(output).to include 'create_view "scenic.searches",' - Search.connection.drop_view :'scenic.searches' + Search.connection.drop_view :"scenic.searches" end end @@ -113,7 +113,7 @@ class SearchInAHaystack < ActiveRecord::Base Search.connection.drop_view :'"search in a haystack"' - silence_stream(STDOUT) { eval(output) } + silence_stream($stdout) { eval(output) } # standard:disable Security/Eval expect(SearchInAHaystack.take.haystack).to eq "needle" end @@ -123,7 +123,7 @@ class SearchInAHaystack < ActiveRecord::Base it "dumps a create_view for a view in the database" do view_definition = "SELECT 'needle'::text AS haystack" Search.connection.execute( - "CREATE SCHEMA scenic; SET search_path TO scenic, public", + "CREATE SCHEMA scenic; SET search_path TO scenic, public" ) Search.connection.create_view 'scenic."search in a haystack"', sql_definition: view_definition @@ -137,7 +137,7 @@ class SearchInAHaystack < ActiveRecord::Base Search.connection.drop_view :'scenic."search in a haystack"' - silence_stream(STDOUT) { eval(output) } + silence_stream($stdout) { eval(output) } # standard:disable Security/Eval expect(SearchInAHaystack.take.haystack).to eq "needle" end diff --git a/spec/scenic/statements_spec.rb b/spec/scenic/statements_spec.rb index b0aa5120..39cf1387 100644 --- a/spec/scenic/statements_spec.rb +++ b/spec/scenic/statements_spec.rb @@ -70,7 +70,7 @@ module Scenic connection.create_view( :views, version: 1, - materialized: { no_data: true }, + materialized: {no_data: true} ) expect(Scenic.database).to have_received(:create_materialized_view) @@ -137,7 +137,7 @@ module Scenic connection.update_view( :name, version: 3, - materialized: { no_data: true }, + materialized: {no_data: true} ) expect(Scenic.database).to have_received(:update_materialized_view) @@ -147,7 +147,7 @@ module Scenic it "raises an error if not supplied a version or sql_defintion" do expect { connection.update_view :views }.to raise_error( ArgumentError, - /sql_definition or version must be specified/, + /sql_definition or version must be specified/ ) end @@ -156,7 +156,7 @@ module Scenic connection.update_view( :views, version: 1, - sql_definition: "a defintion", + sql_definition: "a defintion" ) end.to raise_error ArgumentError, /cannot both be set/ end diff --git a/spec/support/generator_spec_setup.rb b/spec/support/generator_spec_setup.rb index fdeaa9d1..ead31fc6 100644 --- a/spec/support/generator_spec_setup.rb +++ b/spec/support/generator_spec_setup.rb @@ -1,6 +1,6 @@ require "rspec/rails" -require "ammeter/rspec/generator/example.rb" -require "ammeter/rspec/generator/matchers.rb" +require "ammeter/rspec/generator/example" +require "ammeter/rspec/generator/matchers" require "ammeter/init" RSpec.configure do |config| diff --git a/spec/support/view_definition_helpers.rb b/spec/support/view_definition_helpers.rb index d1688bdf..0862fdd3 100644 --- a/spec/support/view_definition_helpers.rb +++ b/spec/support/view_definition_helpers.rb @@ -2,7 +2,7 @@ module ViewDefinitionHelpers def with_view_definition(name, version, schema) definition = Scenic::Definition.new(name, version) FileUtils.mkdir_p(File.dirname(definition.full_path)) - File.open(definition.full_path, "w") { |f| f.write(schema) } + File.write(definition.full_path, schema) yield ensure FileUtils.rm_f(definition.full_path)