From 909d47906cfd9da2282b1958a22a368c4eed6a28 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Tue, 26 Nov 2024 17:08:39 -0700 Subject: [PATCH] Modernize gem setup Modernize the gem structure and setup to match that of fresh gem generated with Bundler: $ bundle gem spectacles including an updated license, and new changelog and code of conduct. Also use the conventional Mintest test/ directory and tests named with the "_test" suffix. --- .github/workflows/main.yml | 1 + .gitignore | 19 +-- .standard.yml | 4 +- CHANGELOG.md | 53 +++++++ CODE_OF_CONDUCT.md | 132 ++++++++++++++++++ Gemfile | 2 +- LICENSE | 20 --- LICENSE.txt | 21 +++ Rakefile | 31 ++-- spectacles.gemspec | 62 ++++---- .../adapters/mysql2_adapter_test.rb | 2 +- .../adapters/postgresql_adapter_test.rb | 2 +- .../adapters/sqlite3_adapter_test.rb | 4 +- .../abstract_adapter_override_test.rb | 2 +- .../abstract_adapter_test.rb | 2 +- .../spectacles/view_test.rb | 2 +- .../support/minitest/shared_examples.rb | 0 .../support/schema_statement_examples.rb | 0 test/support/test_classes.rb | 27 ++++ {specs => test}/support/view_examples.rb | 0 specs/spec_helper.rb => test/test_helper.rb | 37 +---- 21 files changed, 312 insertions(+), 111 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 CODE_OF_CONDUCT.md delete mode 100644 LICENSE create mode 100644 LICENSE.txt rename specs/adapters/mysql2_adapter_spec.rb => test/adapters/mysql2_adapter_test.rb (95%) rename specs/adapters/postgresql_adapter_spec.rb => test/adapters/postgresql_adapter_test.rb (99%) rename specs/adapters/sqlite3_adapter_spec.rb => test/adapters/sqlite3_adapter_test.rb (86%) rename specs/spectacles/abstract_adapter_override_spec.rb => test/spectacles/abstract_adapter_override_test.rb (96%) rename specs/spectacles/schema_statements/abstract_adapter_spec.rb => test/spectacles/schema_statements/abstract_adapter_test.rb (98%) rename specs/spectacles/view_spec.rb => test/spectacles/view_test.rb (85%) rename specs/support/minitest_shared.rb => test/support/minitest/shared_examples.rb (100%) rename {specs => test}/support/schema_statement_examples.rb (100%) create mode 100644 test/support/test_classes.rb rename {specs => test}/support/view_examples.rb (100%) rename specs/spec_helper.rb => test/test_helper.rb (63%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 81a5716..2cc129b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,6 +34,7 @@ jobs: image: mysql:5.7 ports: - 3306 + env: JRUBY_OPTS: "-J-Xms64M -J-Xmx1024M" MYSQL_USER: root diff --git a/.gitignore b/.gitignore index c73727a..d5c67a8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,10 @@ -.DS_Store -*.gem -.bundle -.rvmrc -Gemfile.lock -pkg/* -specs/*.db -coverage -gemfiles/ +/Gemfile.lock +/.bundle/ +/.yardoc +/_yardoc/ +/coverage/ +/doc/ +/pkg/ +/spec/reports/ +/test/*.db +/tmp/ diff --git a/.standard.yml b/.standard.yml index d8dda41..b4d9477 100644 --- a/.standard.yml +++ b/.standard.yml @@ -1,2 +1,4 @@ -parallel: true # default: false +# For available configuration options, see: +# https://github.com/standardrb/standard +ruby_version: 2.7 # default: RUBY_VERSION format: progress # default: Standard::Formatter diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..aa36160 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,53 @@ +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +- Add Rails 7.0 support +- Add support for dumping views from multiple schemas in Postgres +- Require Ruby 2.7+ +- Require Rails 7.0 + +## [6.0.0] – 2022-02-21 + +- Add Rails 6.0 support + +## [2.0.0] – 2019-12-17 + +- Add support for materialized views +- Drop support for the the mysql gem +- Require Ruby 2.2+ + +## [1.2.0] – 2017-07-21 + +- Add support for skipping views when dumping the schema + +## [1.1.0] – 2016-01-15 + +## [1.0.1] – 2015-09-29 + +## [1.0.0] – 2015-09-28 + +## [0.5.3] – 2015-03-16 + +## [0.5.2] – 2014-12-05 + +## [0.5.1] – 2014-02-07 + +## [0.5.0] – 2014-01-03 + +## [0.4.1] – 2013-11-14 + +## [0.4.0] – 2013-10-10 + +## [0.3.1] – 2013-10-04 + +## [0.3.0] – 2013-09-27 + +## [0.2.0] – 2013-04-22 + +## [0.1.0] – 2013-01-14 + +## [0.0.2] – 2012-02-10 diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..67fe8ce --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,132 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall + community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or advances of + any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email address, + without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official email address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +[INSERT CONTACT METHOD]. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of +actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or permanent +ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the +community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at +[https://www.contributor-covenant.org/translations][translations]. + +[homepage]: https://www.contributor-covenant.org +[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations diff --git a/Gemfile b/Gemfile index 99b5980..dd8c853 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source "http://rubygems.org" +source "https://rubygems.org" # Specify your gem's dependencies in spectacles.gemspec gemspec diff --git a/LICENSE b/LICENSE deleted file mode 100644 index afa9147..0000000 --- a/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2012-2019 Adam Hutchison, Brandon Dewitt - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..c83891d --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2012-2024 Adam Hutchison, Brandon Dewitt + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/Rakefile b/Rakefile index cbc0f52..276256b 100644 --- a/Rakefile +++ b/Rakefile @@ -1,26 +1,25 @@ +# frozen_string_literal: true + require "bundler/gem_tasks" -require "rake/testtask" -require "standard/rake" +require "minitest/test_task" namespace :test do - adapters = [:mysql2, :postgresql, :sqlite3] - task all: [:spectacles] + adapters + Minitest::TestTask.create :spectacles do |t| + t.test_globs = ["test/spectacles/**/*_test.rb"] + t.warning = false + end + adapters = %i[mysql2 postgresql sqlite3] adapters.each do |adapter| - Rake::TestTask.new(adapter) do |t| - t.libs.push "lib" - t.libs.push "specs" - t.pattern = "specs/adapters/#{t.name}*_spec.rb" - t.verbose = true + Minitest::TestTask.create adapter do |t| + t.test_globs = ["test/adapters/#{t.name}*_test.rb"] + t.warning = false end end - Rake::TestTask.new(:spectacles) do |t| - t.libs.push "lib" - t.libs.push "specs" - t.pattern = "specs/spectacles/**/*_spec.rb" - t.verbose = true - end + task all: %i[spectacles] + adapters end -task default: ["test:all", "standard:fix"] +require "standard/rake" + +task default: %i[test:all standard:fix] diff --git a/spectacles.gemspec b/spectacles.gemspec index 13cf846..806b061 100644 --- a/spectacles.gemspec +++ b/spectacles.gemspec @@ -1,32 +1,40 @@ -lib = File.expand_path("../lib", __FILE__) -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require "spectacles/version" +# frozen_string_literal: true -Gem::Specification.new do |gem| - gem.version = Spectacles::VERSION - gem.name = "spectacles" - gem.authors = ["Adam Hutchison, Brandon Dewitt"] - gem.email = ["liveh2o@gmail.com, brandonsdewitt@gmail.com"] - gem.homepage = "http://github.com/liveh2o/spectacles" - gem.summary = "Spectacles (derived from RailsSQLViews) adds database view functionality to ActiveRecord." - gem.description = "Spectacles adds database view functionality to ActiveRecord. Current supported adapters include Postgres, SQLite, Vertica, and MySQL." - gem.license = "MIT" +require_relative "lib/spectacles/version" - gem.files = `git ls-files`.split($\) - gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) } - gem.require_paths = ["lib"] +Gem::Specification.new do |spec| + spec.version = Spectacles::VERSION + spec.name = "spectacles" + spec.authors = ["Adam Hutchison, Brandon Dewitt"] + spec.email = ["liveh2o@gmail.com, brandonsdewitt@gmail.com"] - ## - # Dependencies - # - gem.required_ruby_version = ">= 2.7.0" - gem.add_dependency "activerecord", "~> 7.0.0" - gem.add_dependency "activesupport", "~> 7.0.0" + spec.summary = "Spectacles adds database view functionality to ActiveRecord." + spec.description = "Spectacles adds database view functionality to ActiveRecord. Current supported adapters include Postgres, SQLite, Vertica, and MySQL." + spec.homepage = "http://github.com/liveh2o/spectacles" + spec.license = "MIT" + spec.required_ruby_version = ">= 2.7.0" - ## - # Development dependencies - # - gem.add_development_dependency "minitest", ">= 5.0" - gem.add_development_dependency "rake" - gem.add_development_dependency "standard" + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = spec.homepage + spec.metadata["changelog_uri"] = spec.homepage + "/blob/main/CHANGELOG.md" + + # 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. + gemspec = File.basename(__FILE__) + spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls| + ls.readlines("\x0", chomp: true).reject do |f| + (f == gemspec) || + f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile]) + end + end + spec.bindir = "exe" + spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } + spec.require_paths = ["lib"] + + spec.add_dependency "activerecord", "~> 7.0.0" + spec.add_dependency "activesupport", "~> 7.0.0" + + spec.add_development_dependency "minitest", ">= 5.0" + spec.add_development_dependency "rake" + spec.add_development_dependency "standard" end diff --git a/specs/adapters/mysql2_adapter_spec.rb b/test/adapters/mysql2_adapter_test.rb similarity index 95% rename from specs/adapters/mysql2_adapter_spec.rb rename to test/adapters/mysql2_adapter_test.rb index 08d23ea..b7d50c7 100644 --- a/specs/adapters/mysql2_adapter_spec.rb +++ b/test/adapters/mysql2_adapter_test.rb @@ -1,4 +1,4 @@ -require "spec_helper" +require "test_helper" describe "Spectacles::SchemaStatements::Mysql2Adapter" do config = { diff --git a/specs/adapters/postgresql_adapter_spec.rb b/test/adapters/postgresql_adapter_test.rb similarity index 99% rename from specs/adapters/postgresql_adapter_spec.rb rename to test/adapters/postgresql_adapter_test.rb index 0141518..60d736c 100644 --- a/specs/adapters/postgresql_adapter_spec.rb +++ b/test/adapters/postgresql_adapter_test.rb @@ -1,4 +1,4 @@ -require "spec_helper" +require "test_helper" describe "Spectacles::SchemaStatements::PostgreSQLAdapter" do config = { diff --git a/specs/adapters/sqlite3_adapter_spec.rb b/test/adapters/sqlite3_adapter_test.rb similarity index 86% rename from specs/adapters/sqlite3_adapter_spec.rb rename to test/adapters/sqlite3_adapter_test.rb index 9d76c05..f53545a 100644 --- a/specs/adapters/sqlite3_adapter_spec.rb +++ b/test/adapters/sqlite3_adapter_test.rb @@ -1,4 +1,4 @@ -require "spec_helper" +require "test_helper" describe "Spectacles::SchemaStatements::SQLite3Adapter" do begin @@ -9,7 +9,7 @@ ActiveRecord::Base.establish_connection( adapter: "sqlite3", - database: "specs/test.db" + database: "test/test.db" ) load_schema diff --git a/specs/spectacles/abstract_adapter_override_spec.rb b/test/spectacles/abstract_adapter_override_test.rb similarity index 96% rename from specs/spectacles/abstract_adapter_override_spec.rb rename to test/spectacles/abstract_adapter_override_test.rb index 343dd88..4242642 100644 --- a/specs/spectacles/abstract_adapter_override_spec.rb +++ b/test/spectacles/abstract_adapter_override_test.rb @@ -1,4 +1,4 @@ -require "spec_helper" +require "test_helper" describe "loading an adapter" do it "calls the original AR::CA::AbstractAdapter.inherited method" do diff --git a/specs/spectacles/schema_statements/abstract_adapter_spec.rb b/test/spectacles/schema_statements/abstract_adapter_test.rb similarity index 98% rename from specs/spectacles/schema_statements/abstract_adapter_spec.rb rename to test/spectacles/schema_statements/abstract_adapter_test.rb index a2b6ff0..86c0a4f 100644 --- a/specs/spectacles/schema_statements/abstract_adapter_spec.rb +++ b/test/spectacles/schema_statements/abstract_adapter_test.rb @@ -1,4 +1,4 @@ -require "spec_helper" +require "test_helper" describe Spectacles::SchemaStatements::AbstractAdapter do describe "#create_view" do diff --git a/specs/spectacles/view_spec.rb b/test/spectacles/view_test.rb similarity index 85% rename from specs/spectacles/view_spec.rb rename to test/spectacles/view_test.rb index 04520b4..850ec33 100644 --- a/specs/spectacles/view_spec.rb +++ b/test/spectacles/view_test.rb @@ -1,4 +1,4 @@ -require "spec_helper" +require "test_helper" describe Spectacles::View do it "is an abstract class" do diff --git a/specs/support/minitest_shared.rb b/test/support/minitest/shared_examples.rb similarity index 100% rename from specs/support/minitest_shared.rb rename to test/support/minitest/shared_examples.rb diff --git a/specs/support/schema_statement_examples.rb b/test/support/schema_statement_examples.rb similarity index 100% rename from specs/support/schema_statement_examples.rb rename to test/support/schema_statement_examples.rb diff --git a/test/support/test_classes.rb b/test/support/test_classes.rb new file mode 100644 index 0000000..49ab936 --- /dev/null +++ b/test/support/test_classes.rb @@ -0,0 +1,27 @@ +class User < ActiveRecord::Base + has_many :products +end + +class Product < ActiveRecord::Base + belongs_to :user +end + +class NewProductUser < Spectacles::View + scope :duck_lovers, lambda { where(product_name: "Rubber Duck") } +end + +class TestBase + extend Spectacles::SchemaStatements::AbstractAdapter + + def self.materialized_views + @materialized_views ||= nil + @materialized_views || super + end + + def self.with_materialized_views(list) + @materialized_views = list + yield + ensure + @materialized_views = nil + end +end diff --git a/specs/support/view_examples.rb b/test/support/view_examples.rb similarity index 100% rename from specs/support/view_examples.rb rename to test/support/view_examples.rb diff --git a/specs/spec_helper.rb b/test/test_helper.rb similarity index 63% rename from specs/spec_helper.rb rename to test/test_helper.rb index 6132881..40b608d 100644 --- a/specs/spec_helper.rb +++ b/test/test_helper.rb @@ -1,6 +1,9 @@ +# frozen_string_literal: true + require "simplecov" + SimpleCov.start do - add_filter "/specs" + add_filter "/spec" end require "rubygems" @@ -10,38 +13,12 @@ require "minitest/spec" require "minitest/autorun" require "minitest/pride" -require "support/minitest_shared" + +require "support/minitest/shared_examples" require "support/schema_statement_examples" +require "support/test_classes" require "support/view_examples" -class User < ActiveRecord::Base - has_many :products -end - -class Product < ActiveRecord::Base - belongs_to :user -end - -class NewProductUser < Spectacles::View - scope :duck_lovers, lambda { where(product_name: "Rubber Duck") } -end - -class TestBase - extend Spectacles::SchemaStatements::AbstractAdapter - - def self.materialized_views - @materialized_views ||= nil - @materialized_views || super - end - - def self.with_materialized_views(list) - @materialized_views = list - yield - ensure - @materialized_views = nil - end -end - ActiveRecord::Schema.verbose = false def configure_database(config)