scenic 1.5.2 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75afe5531011de8c35f2272af574763575bdb4d9f9650eeb2845a3f163b1e941
4
- data.tar.gz: a7ded9f2177997aba8c3c424e04c2aed14f08a2f452d4ab74d2030d692fe1e7c
3
+ metadata.gz: 23461e20bd94ffe9d2466098b04141ef8b8256d83f6c05cf5c5d9f26cca08231
4
+ data.tar.gz: 6c331ddfc7c4d658b342367e2f2fcf703bf2b376314c32520d55afdbc05e936a
5
5
  SHA512:
6
- metadata.gz: f1d00648e7f6c73b76242d43b3d49456afbc531a3a562dd43525b1f45f0b440f8650f1d4fb9459780aba7e46e87b49d33b3f7b92693ae43f03d51ea1fee39a67
7
- data.tar.gz: 7da8bfdf0cac0c7bea6a7e67f09a37767943d5e6f2608ffb478db0b2884a93bc76e06b2b0d8fcf52a7d95d7b10d154d3b7cd2065de022a44d669f61b88699cfa
6
+ metadata.gz: 23e1ab6998fb898eebdc91691684bffc694fe51001ada435593cb9e6a3857074e13e6d1ba90333acf3a76069f2e687c129595389ce60ac7790bbb82cdfdd68c2
7
+ data.tar.gz: 2d91d5a48e68ef856ea9ffb14c3abb503fcaa1c588e17f55775ef32d2ae5f4f2862fd68aa53a99b2c666a0a81d88cba026fa21cdf2f4cc5b5e8a3f8062eb4779
@@ -0,0 +1,6 @@
1
+ ARG VARIANT=2-bullseye
2
+ FROM mcr.microsoft.com/vscode/devcontainers/ruby:0-${VARIANT}
3
+
4
+ ENV RAILS_DEVELOPMENT_HOSTS=".githubpreview.dev"
5
+ ENV POSTGRES_USER="postgres"
6
+ ENV POSTGRES_PASSWORD="postgres"
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "Scenic Development",
3
+ "dockerComposeFile": "docker-compose.yml",
4
+ "service": "app",
5
+ "workspaceFolder": "/workspace",
6
+ "settings": { },
7
+ "extensions": ["rebornix.Ruby"],
8
+ "postCreateCommand": "bin/setup",
9
+ "remoteUser": "vscode",
10
+ "features": { "github-cli": "latest" }
11
+ }
@@ -0,0 +1,24 @@
1
+ version: '3'
2
+
3
+ services:
4
+ app:
5
+ build:
6
+ context: ..
7
+ dockerfile: .devcontainer/Dockerfile
8
+ args:
9
+ VARIANT: "3"
10
+ volumes:
11
+ - ..:/workspace:cached
12
+ command: sleep infinity
13
+ network_mode: service:db
14
+ db:
15
+ image: postgres:latest
16
+ restart: unless-stopped
17
+ volumes:
18
+ - postgres-data:/var/lib/postgresql/data
19
+ environment:
20
+ POSTGRES_USER: postgres
21
+ POSTGRES_DB: postgres
22
+ POSTGRES_PASSWORD: postgres
23
+ volumes:
24
+ postgres-data: null
@@ -0,0 +1,71 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: main
6
+ pull_request:
7
+ branches: "*"
8
+
9
+ jobs:
10
+ build:
11
+ name: Ruby ${{ matrix.ruby }}, Rails ${{ matrix.rails }}
12
+
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ ruby: ["2.7", "3.0", "3.1"]
17
+ rails: ["6.1", "7.0", "master"]
18
+ continue-on-error: [false]
19
+
20
+ runs-on: ubuntu-latest
21
+
22
+ services:
23
+ postgres:
24
+ image: postgres
25
+ env:
26
+ POSTGRES_USER: "postgres"
27
+ POSTGRES_PASSWORD: "postgres"
28
+ ports:
29
+ - 5432:5432
30
+ options: >-
31
+ --health-cmd pg_isready
32
+ --health-interval 10s
33
+ --health-timeout 5s
34
+ --health-retries 5
35
+
36
+ env:
37
+ RAILS_VERSION: ${{ matrix.rails }}
38
+ POSTGRES_USER: "postgres"
39
+ POSTGRES_PASSWORD: "postgres"
40
+
41
+ steps:
42
+ - name: Checkout
43
+ uses: actions/checkout@v2
44
+
45
+ - name: Install Ruby ${{ matrix.ruby }}
46
+ uses: ruby/setup-ruby@v1
47
+ with:
48
+ ruby-version: ${{ matrix.ruby }}
49
+
50
+ - name: Install dependent libraries
51
+ run: sudo apt-get install libpq-dev
52
+
53
+ - name: Generate lockfile
54
+ run: bundle lock
55
+
56
+ - name: Cache dependencies
57
+ uses: actions/cache@v1
58
+ with:
59
+ path: vendor/bundle
60
+ key: bundle-${{ hashFiles('Gemfile.lock') }}
61
+
62
+ - name: Set up Scenic
63
+ run: bin/setup
64
+
65
+ - name: Run fast tests
66
+ run: bundle exec rake spec
67
+ continue-on-error: ${{ matrix.continue-on-error }}
68
+
69
+ - name: Run acceptance tests
70
+ run: bundle exec rake spec:acceptance
71
+ continue-on-error: ${{ matrix.continue-on-error }}
data/.gitignore CHANGED
@@ -17,3 +17,4 @@ test/version_tmp
17
17
  tmp
18
18
  gemfiles/*.lock
19
19
  .DS_Store
20
+ .ruby-version
data/CHANGELOG.md CHANGED
@@ -5,7 +5,56 @@ changelog, see the [commits] for each version via the version links.
5
5
 
6
6
  [commits]: https://github.com/scenic-views/scenic/commits/master
7
7
 
8
- ## [1.5.2] - February 6, 2019
8
+ ## [1.6.0] - February 13, 2021
9
+
10
+ ### Fixed
11
+
12
+ * Exclude pg_stat_statements_info (#349) 76bface
13
+
14
+ *Caleb Hearth*
15
+
16
+ * Fix serialization of views with backslashes c625d1b
17
+
18
+ *Ben Sheldon*
19
+
20
+ * Handle ActiveRecord table name prefix and suffix b1544dc
21
+
22
+ *Derek Prior*
23
+
24
+ ## [1.5.5] - December 15, 2021
25
+
26
+ ### Fixed
27
+
28
+ - Fixed an issue reverting migrations under Ruby 3
29
+ - Fixed an issue in index reapplication where sometimes `say` was undefined
30
+
31
+ [1.5.5]: https://github.com/scenic-views/scenic/compare/v1.5.4...v1.5.5
32
+
33
+ ## [1.5.4] - September 16, 2020
34
+
35
+ [1.5.4]: https://github.com/scenic-views/scenic/compare/v1.5.3...v1.5.4
36
+
37
+ ### Fixed
38
+
39
+ - Added missing changelog for v1.5.3.
40
+
41
+ ## [1.5.3] - September 15, 2020
42
+
43
+ [1.5.3]: https://github.com/scenic-views/scenic/compare/v1.5.2...v1.5.3
44
+
45
+ ### Fixed
46
+
47
+ - `scenic-oracle_enhanced_adapter` has been pulled from rubygems.
48
+ `scenic-oracle_adapter` is a current, maintained alternative.
49
+ - Updated code snippets - since Rails 5.0, all models inherit from
50
+ ApplicationRecord (#302)
51
+ - Update Caleb's last name
52
+
53
+ ### Added
54
+
55
+ - Add Security Policy
56
+
57
+ ## [1.5.2] - February 6, 2020
9
58
 
10
59
  ### Fixed
11
60
 
data/CONTRIBUTING.md CHANGED
@@ -10,10 +10,12 @@ agree to abide by our [code of conduct].
10
10
  1. Fork the repository.
11
11
  2. Run `bin/setup`, which will install dependencies and create the dummy
12
12
  application database.
13
- 3. Run `bin/appraisal rake` to verify that the tests pass against all
14
- supported versions of Rails.
13
+ 3. Run `rake` to verify that the tests pass against the version of Rails you are
14
+ running locally.
15
15
  4. Make your change with new passing tests, following existing style.
16
16
  5. Write a [good commit message], push your fork, and submit a pull request.
17
+ 6. CI will run the test suite on all configured versions of Ruby and Rails.
18
+ Address any failures.
17
19
 
18
20
  [good commit message]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
19
21
 
data/Gemfile CHANGED
@@ -2,3 +2,15 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in scenic.gemspec
4
4
  gemspec
5
+
6
+ rails_version = ENV.fetch("RAILS_VERSION", "6.1")
7
+
8
+ if rails_version == "master"
9
+ rails_constraint = { github: "rails/rails" }
10
+ else
11
+ rails_constraint = "~> #{rails_version}.0"
12
+ end
13
+
14
+ gem "rails", rails_constraint
15
+ gem "sprockets", "< 4.0.0"
16
+ gem "pg", "~> 1.1"
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2016 Derek Prior, Caleb Thompson, and thoughtbot.
1
+ Copyright (c) 2014-2020 Derek Prior, Caleb Hearth, and thoughtbot.
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ![Scenic Landscape](https://user-images.githubusercontent.com/152152/49344534-a8817480-f646-11e8-8431-3d95d349c070.png)
4
4
 
5
- [![Build Status](https://travis-ci.org/scenic-views/scenic.svg?branch=master)](https://travis-ci.org/scenic-views/scenic)
5
+ [![Build Status](https://github.com/scenic-views/scenic/actions/workflows/ci.yml/badge.svg)](https://github.com/scenic-views/scenic/actions/workflows/ci.yml)
6
6
  [![Documentation Quality](http://inch-ci.org/github/scenic-views/scenic.svg?branch=master)](http://inch-ci.org/github/scenic-views/scenic)
7
7
  [![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
8
8
 
@@ -94,7 +94,7 @@ when some of those views may be materialized and take a long time to recreate.
94
94
 
95
95
  You can use `replace_view` to generate a CREATE OR REPLACE VIEW SQL statement.
96
96
 
97
- See postgresql documentation on how this works:
97
+ See Postgres documentation on how this works:
98
98
  http://www.postgresql.org/docs/current/static/sql-createview.html
99
99
 
100
100
  To start replacing a view run the generator like for a regular change:
@@ -135,7 +135,7 @@ ActiveRecord or ARel queries. As far as ActiveRecord is concerned, a view is
135
135
  no different than a table.
136
136
 
137
137
  ```ruby
138
- class SearchResult < ActiveRecord::Base
138
+ class SearchResult < ApplicationRecord
139
139
  belongs_to :searchable, polymorphic: true
140
140
 
141
141
  # this isn't strictly necessary, but it will prevent
@@ -218,7 +218,7 @@ You can get around these issues by setting the primary key column on your Rails
218
218
  model like so:
219
219
 
220
220
  ```ruby
221
- class People < ActiveRecord::Base
221
+ class People < ApplicationRecord
222
222
  self.primary_key = :my_unique_identifier_field
223
223
  end
224
224
  ```
@@ -255,12 +255,15 @@ meet your needs:
255
255
  * [scenic_sqlite_adapter](https://github.com/pdebelak/scenic_sqlite_adapter)
256
256
  * [scenic-mysql_adapter](https://github.com/EmpaticoOrg/scenic-mysql_adapter)
257
257
  * [scenic-sqlserver-adapter](https://github.com/ClickMechanic/scenic_sqlserver_adapter)
258
- * [scenic-oracle_enhanced_adapter](https://github.com/PMACS/scenic_oracle_enhanced_adapter)
258
+ * [scenic-oracle_adapter](https://github.com/cdinger/scenic-oracle_adapter)
259
+
260
+ Please note that the maintainers of Scenic make no assertions about the
261
+ quality or security of the above adapters.
259
262
 
260
263
  ## About
261
264
 
262
- Scenic is maintained by [Derek Prior], [Caleb Thompson], and you, our
265
+ Scenic is maintained by [Derek Prior], [Caleb Hearth], and you, our
263
266
  contributors.
264
267
 
265
268
  [Derek Prior]: http://prioritized.net
266
- [Caleb Thompson]: http://calebthompson.io
269
+ [Caleb Hearth]: http://calebhearth.com
data/SECURITY.md ADDED
@@ -0,0 +1,14 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Scenic maintainenance is a volunteer effort. We will do our best to fix
6
+ forward but do not offer backported fixes. As such, the only "supported" version of Scenic is whichever was most recently released.
7
+
8
+ ## Reporting a Vulnerability
9
+
10
+ Please report any discovered security vulnerabilities to Scenic's primary
11
+ volunteer maintainers, derekprior@gmail.com and caleb@calebhearth.com.
12
+
13
+ We will respond as soon as possible with any follow-up questions or details
14
+ on how we plan to handle the issue.
data/bin/setup CHANGED
@@ -2,12 +2,17 @@
2
2
 
3
3
  set -e
4
4
 
5
+ # CI-specific setup
6
+ if [ -n "$GITHUB_ACTIONS" ]; then
7
+ bundle config path vendor/bundle
8
+ bundle config jobs 4
9
+ bundle config retry 3
10
+ git config --global user.name 'GitHub Actions'
11
+ git config --global user.email 'github-actions@example.com'
12
+ fi
13
+
5
14
  gem install bundler --conservative
6
15
  bundle check || bundle install
7
16
 
8
- if [ -z "$CI" ]; then
9
- bundle exec appraisal install
10
- fi
11
-
12
17
  bundle exec rake dummy:db:drop
13
18
  bundle exec rake dummy:db:create
@@ -13,7 +13,7 @@ module Scenic
13
13
  # @param connection [Connection] The connection to execute SQL against.
14
14
  # @param speaker [#say] (ActiveRecord::Migration) The object used for
15
15
  # logging the results of reapplying indexes.
16
- def initialize(connection:, speaker: ActiveRecord::Migration)
16
+ def initialize(connection:, speaker: ActiveRecord::Migration.new)
17
17
  @connection = connection
18
18
  @speaker = speaker
19
19
  end
@@ -34,6 +34,7 @@ module Scenic
34
34
  WHERE
35
35
  c.relkind IN ('m', 'v')
36
36
  AND c.relname NOT IN (SELECT extname FROM pg_extension)
37
+ AND c.relname != 'pg_stat_statements_info'
37
38
  AND n.nspname = ANY (current_schemas(false))
38
39
  ORDER BY c.oid
39
40
  SQL
@@ -36,15 +36,25 @@ module Scenic
36
36
  @options ||= @args[1] || {}
37
37
  end
38
38
 
39
+ def keyword_hash(hash)
40
+ if Hash.respond_to? :ruby2_keywords_hash
41
+ Hash.ruby2_keywords_hash(hash)
42
+ else
43
+ hash
44
+ end
45
+ end
46
+
39
47
  def options_for_revert
40
- options.clone.tap do |revert_options|
48
+ opts = options.clone.tap do |revert_options|
41
49
  revert_options[:version] = revert_to_version
42
50
  revert_options.delete(:revert_to_version)
43
51
  end
52
+
53
+ keyword_hash(opts)
44
54
  end
45
55
 
46
56
  def options_without_version
47
- options.except(:version)
57
+ keyword_hash(options.except(:version))
48
58
  end
49
59
  end
50
60
  end
@@ -6,18 +6,22 @@ module Scenic
6
6
  def create_view(*args)
7
7
  record(:create_view, args)
8
8
  end
9
+ ruby2_keywords :create_view if respond_to?(:ruby2_keywords, true)
9
10
 
10
11
  def drop_view(*args)
11
12
  record(:drop_view, args)
12
13
  end
14
+ ruby2_keywords :drop_view if respond_to?(:ruby2_keywords, true)
13
15
 
14
16
  def update_view(*args)
15
17
  record(:update_view, args)
16
18
  end
19
+ ruby2_keywords :update_view if respond_to?(:ruby2_keywords, true)
17
20
 
18
21
  def replace_view(*args)
19
22
  record(:replace_view, args)
20
23
  end
24
+ ruby2_keywords :replace_view if respond_to?(:ruby2_keywords, true)
21
25
 
22
26
  def invert_create_view(args)
23
27
  drop_view_args = StatementArguments.new(args).remove_version.to_a
@@ -2,7 +2,7 @@ module Scenic
2
2
  # @api private
3
3
  class Definition
4
4
  def initialize(name, version)
5
- @name = name
5
+ @name = name.to_s
6
6
  @version = version.to_i
7
7
  end
8
8
 
@@ -28,8 +28,10 @@ module Scenic
28
28
 
29
29
  private
30
30
 
31
+ attr_reader :name
32
+
31
33
  def filename
32
- "#{@name.to_s.tr('.', '_')}_v#{version}.sql"
34
+ "#{UnaffixedName.for(name).tr('.', '_')}_v#{version}.sql"
33
35
  end
34
36
  end
35
37
  end
@@ -0,0 +1,31 @@
1
+ module Scenic
2
+ # The name of a view or table according to rails.
3
+ #
4
+ # This removes any table name prefix or suffix that is configured via
5
+ # ActiveRecord. This allows, for example, the SchemaDumper to dump a view with
6
+ # its unaffixed name, consistent with how rails handles table dumping.
7
+ class UnaffixedName
8
+ # Gets the unaffixed name for the provided string
9
+ # @return [String]
10
+ #
11
+ # @param name [String] The (potentially) affixed view name
12
+ def self.for(name)
13
+ new(name, config: ActiveRecord::Base).call
14
+ end
15
+
16
+ def initialize(name, config:)
17
+ @name = name
18
+ @config = config
19
+ end
20
+
21
+ def call
22
+ prefix = Regexp.escape(config.table_name_prefix)
23
+ suffix = Regexp.escape(config.table_name_suffix)
24
+ name.sub(/\A#{prefix}(.+)#{suffix}\z/, "\\1")
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :name, :config
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Scenic
2
- VERSION = "1.5.2".freeze
2
+ VERSION = "1.6.0".freeze
3
3
  end
data/lib/scenic/view.rb CHANGED
@@ -45,10 +45,14 @@ module Scenic
45
45
  materialized_option = materialized ? "materialized: true, " : ""
46
46
 
47
47
  <<-DEFINITION
48
- create_view #{name.inspect}, #{materialized_option}sql_definition: <<-\SQL
49
- #{definition.indent(2)}
48
+ create_view #{UnaffixedName.for(name).inspect}, #{materialized_option}sql_definition: <<-\SQL
49
+ #{escaped_definition.indent(2)}
50
50
  SQL
51
51
  DEFINITION
52
52
  end
53
+
54
+ def escaped_definition
55
+ definition.gsub("\\", "\\\\\\")
56
+ end
53
57
  end
54
58
  end
data/lib/scenic.rb CHANGED
@@ -5,6 +5,7 @@ require "scenic/definition"
5
5
  require "scenic/railtie"
6
6
  require "scenic/schema_dumper"
7
7
  require "scenic/statements"
8
+ require "scenic/unaffixed_name"
8
9
  require "scenic/version"
9
10
  require "scenic/view"
10
11
  require "scenic/index"
data/scenic.gemspec CHANGED
@@ -5,8 +5,8 @@ require "scenic/version"
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "scenic"
7
7
  spec.version = Scenic::VERSION
8
- spec.authors = ["Derek Prior", "Caleb Thompson"]
9
- spec.email = ["derekprior@gmail.com", "caleb@calebthompson.io"]
8
+ spec.authors = ["Derek Prior", "Caleb Hearth"]
9
+ spec.email = ["derekprior@gmail.com", "caleb@calebhearth.com"]
10
10
  spec.summary = "Support for database views in Rails migrations"
11
11
  spec.description = <<-DESCRIPTION
12
12
  Adds methods to ActiveRecord::Migration to create and manage database views
@@ -19,7 +19,6 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^spec/})
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_development_dependency "appraisal"
23
22
  spec.add_development_dependency "bundler", ">= 1.5"
24
23
  spec.add_development_dependency "database_cleaner"
25
24
  spec.add_development_dependency "rake"
@@ -2,7 +2,12 @@ development: &default
2
2
  adapter: postgresql
3
3
  database: dummy_development
4
4
  encoding: unicode
5
+ host: localhost
5
6
  pool: 5
7
+ <% if ENV.fetch("GITHUB_ACTIONS", false) || ENV.fetch("CODESPACES", false) %>
8
+ username: <%= ENV.fetch("POSTGRES_USER") %>
9
+ password: <%= ENV.fetch("POSTGRES_PASSWORD") %>
10
+ <% end %>
6
11
 
7
12
  test:
8
13
  <<: *default
@@ -0,0 +1,5 @@
1
+ class AddPgStatStatementsExtension < ActiveRecord::Migration[6.1]
2
+ def change
3
+ enable_extension 'pg_stat_statements'
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(version: 2022_01_12_154220) do
14
+
15
+ # These are extensions that must be enabled in order to support this database
16
+ enable_extension "pg_stat_statements"
17
+ enable_extension "plpgsql"
18
+
19
+ end
@@ -35,6 +35,14 @@ module Scenic
35
35
 
36
36
  expect(definition.path).to eq "db/views/non_public_searches_v01.sql"
37
37
  end
38
+
39
+ it "handles active record view prefix and suffixing" do
40
+ with_affixed_tables(prefix: "foo_", suffix: "_bar") do
41
+ definition = Definition.new("foo_searches_bar", 1)
42
+
43
+ expect(definition.path).to eq "db/views/searches_v01.sql"
44
+ end
45
+ end
38
46
  end
39
47
 
40
48
  describe "full_path" do
@@ -26,6 +26,22 @@ describe Scenic::SchemaDumper, :db do
26
26
  expect(Search.first.haystack).to eq "needle"
27
27
  end
28
28
 
29
+ it "accurately dumps create view statements with a regular expression" do
30
+ view_definition = "SELECT 'needle'::text AS haystack WHERE 'a2z' ~ '\\d+'"
31
+ Search.connection.create_view :searches, sql_definition: view_definition
32
+ stream = StringIO.new
33
+
34
+ ActiveRecord::SchemaDumper.dump(Search.connection, stream)
35
+
36
+ output = stream.string
37
+ expect(output).to include "~ '\\\\d+'::text"
38
+
39
+ Search.connection.drop_view :searches
40
+ silence_stream(STDOUT) { eval(output) }
41
+
42
+ expect(Search.first.haystack).to eq "needle"
43
+ end
44
+
29
45
  it "dumps a create_view for a materialized view in the database" do
30
46
  view_definition = "SELECT 'needle'::text AS haystack"
31
47
  Search.connection.create_view :searches, materialized: true, sql_definition: view_definition
@@ -55,6 +71,20 @@ describe Scenic::SchemaDumper, :db do
55
71
  end
56
72
  end
57
73
 
74
+ it "handles active record table name prefixes and suffixes" do
75
+ with_affixed_tables(prefix: "a_", suffix: "_z") do
76
+ view_definition = "SELECT 'needle'::text AS haystack"
77
+ Search.connection.create_view :a_searches_z, sql_definition: view_definition
78
+ stream = StringIO.new
79
+
80
+ ActiveRecord::SchemaDumper.dump(Search.connection, stream)
81
+
82
+ output = stream.string
83
+
84
+ expect(output).to include 'create_view "searches"'
85
+ end
86
+ end
87
+
58
88
  it "ignores tables internal to Rails" do
59
89
  view_definition = "SELECT 'needle'::text AS haystack"
60
90
  Search.connection.create_view :searches, sql_definition: view_definition
@@ -65,7 +95,7 @@ describe Scenic::SchemaDumper, :db do
65
95
  output = stream.string
66
96
 
67
97
  expect(output).to include 'create_view "searches"'
68
- expect(output).not_to include "ar_internal_metadata"
98
+ expect(output).not_to include "pg_stat_statements_info"
69
99
  expect(output).not_to include "schema_migrations"
70
100
  end
71
101
 
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  module Scenic
4
4
  describe Scenic::Statements do
5
5
  before do
6
- adapter = instance_double("Scenic::Adapaters::Postgres").as_null_object
6
+ adapter = instance_double("Scenic::Adapters::Postgres").as_null_object
7
7
  allow(Scenic).to receive(:database).and_return(adapter)
8
8
  end
9
9
 
data/spec/spec_helper.rb CHANGED
@@ -2,15 +2,19 @@ ENV["RAILS_ENV"] = "test"
2
2
  require "database_cleaner"
3
3
 
4
4
  require File.expand_path("dummy/config/environment", __dir__)
5
+ require "support/rails_configuration_helpers"
5
6
  require "support/generator_spec_setup"
6
7
  require "support/view_definition_helpers"
7
8
 
8
9
  RSpec.configure do |config|
9
10
  config.order = "random"
10
11
  config.include ViewDefinitionHelpers
12
+ config.include RailsConfigurationHelpers
11
13
  DatabaseCleaner.strategy = :transaction
12
14
 
13
15
  config.around(:each, db: true) do |example|
16
+ ActiveRecord::SchemaMigration.create_table
17
+
14
18
  DatabaseCleaner.start
15
19
  example.run
16
20
  DatabaseCleaner.clean
@@ -0,0 +1,10 @@
1
+ module RailsConfigurationHelpers
2
+ def with_affixed_tables(prefix: "", suffix: "")
3
+ ActiveRecord::Base.table_name_prefix = prefix
4
+ ActiveRecord::Base.table_name_suffix = suffix
5
+ yield
6
+ ensure
7
+ ActiveRecord::Base.table_name_prefix = ""
8
+ ActiveRecord::Base.table_name_suffix = ""
9
+ end
10
+ end
metadata CHANGED
@@ -1,30 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scenic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Prior
8
- - Caleb Thompson
9
- autorequire:
8
+ - Caleb Hearth
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-02-06 00:00:00.000000000 Z
12
+ date: 2022-02-13 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: appraisal
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: '0'
21
- type: :development
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- version: '0'
28
14
  - !ruby/object:Gem::Dependency
29
15
  name: bundler
30
16
  requirement: !ruby/object:Gem::Requirement
@@ -184,17 +170,19 @@ description: |2
184
170
  in Rails
185
171
  email:
186
172
  - derekprior@gmail.com
187
- - caleb@calebthompson.io
173
+ - caleb@calebhearth.com
188
174
  executables: []
189
175
  extensions: []
190
176
  extra_rdoc_files: []
191
177
  files:
178
+ - ".devcontainer/Dockerfile"
179
+ - ".devcontainer/devcontainer.json"
180
+ - ".devcontainer/docker-compose.yml"
181
+ - ".github/workflows/ci.yml"
192
182
  - ".gitignore"
193
183
  - ".hound.yml"
194
184
  - ".rubocop.yml"
195
- - ".travis.yml"
196
185
  - ".yardopts"
197
- - Appraisals
198
186
  - CHANGELOG.md
199
187
  - CODE_OF_CONDUCT.md
200
188
  - CONTRIBUTING.md
@@ -202,14 +190,11 @@ files:
202
190
  - LICENSE.txt
203
191
  - README.md
204
192
  - Rakefile
205
- - bin/appraisal
193
+ - SECURITY.md
206
194
  - bin/rake
207
195
  - bin/rspec
208
196
  - bin/setup
209
197
  - bin/yard
210
- - gemfiles/rails52.gemfile
211
- - gemfiles/rails60.gemfile
212
- - gemfiles/rails_edge.gemfile
213
198
  - lib/generators/scenic/generators.rb
214
199
  - lib/generators/scenic/materializable.rb
215
200
  - lib/generators/scenic/model/USAGE
@@ -235,6 +220,7 @@ files:
235
220
  - lib/scenic/railtie.rb
236
221
  - lib/scenic/schema_dumper.rb
237
222
  - lib/scenic/statements.rb
223
+ - lib/scenic/unaffixed_name.rb
238
224
  - lib/scenic/version.rb
239
225
  - lib/scenic/view.rb
240
226
  - scenic.gemspec
@@ -252,6 +238,8 @@ files:
252
238
  - spec/dummy/config/database.yml
253
239
  - spec/dummy/config/environment.rb
254
240
  - spec/dummy/db/migrate/.keep
241
+ - spec/dummy/db/migrate/20220112154220_add_pg_stat_statements_extension.rb
242
+ - spec/dummy/db/schema.rb
255
243
  - spec/dummy/db/views/.keep
256
244
  - spec/generators/scenic/model/model_generator_spec.rb
257
245
  - spec/generators/scenic/view/view_generator_spec.rb
@@ -268,12 +256,13 @@ files:
268
256
  - spec/scenic/statements_spec.rb
269
257
  - spec/spec_helper.rb
270
258
  - spec/support/generator_spec_setup.rb
259
+ - spec/support/rails_configuration_helpers.rb
271
260
  - spec/support/view_definition_helpers.rb
272
261
  homepage: https://github.com/scenic-views/scenic
273
262
  licenses:
274
263
  - MIT
275
264
  metadata: {}
276
- post_install_message:
265
+ post_install_message:
277
266
  rdoc_options: []
278
267
  require_paths:
279
268
  - lib
@@ -288,8 +277,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
288
277
  - !ruby/object:Gem::Version
289
278
  version: '0'
290
279
  requirements: []
291
- rubygems_version: 3.0.1
292
- signing_key:
280
+ rubygems_version: 3.2.22
281
+ signing_key:
293
282
  specification_version: 4
294
283
  summary: Support for database views in Rails migrations
295
284
  test_files:
@@ -307,6 +296,8 @@ test_files:
307
296
  - spec/dummy/config/database.yml
308
297
  - spec/dummy/config/environment.rb
309
298
  - spec/dummy/db/migrate/.keep
299
+ - spec/dummy/db/migrate/20220112154220_add_pg_stat_statements_extension.rb
300
+ - spec/dummy/db/schema.rb
310
301
  - spec/dummy/db/views/.keep
311
302
  - spec/generators/scenic/model/model_generator_spec.rb
312
303
  - spec/generators/scenic/view/view_generator_spec.rb
@@ -323,4 +314,5 @@ test_files:
323
314
  - spec/scenic/statements_spec.rb
324
315
  - spec/spec_helper.rb
325
316
  - spec/support/generator_spec_setup.rb
317
+ - spec/support/rails_configuration_helpers.rb
326
318
  - spec/support/view_definition_helpers.rb
data/.travis.yml DELETED
@@ -1,34 +0,0 @@
1
- addons:
2
- postgresql: "9.4"
3
- before_install:
4
- - "echo '--colour' > ~/.rspec"
5
- - "echo 'gem: --no-document' > ~/.gemrc"
6
- - git config --global user.name 'Travis CI'
7
- - git config --global user.email 'travis-ci@example.com'
8
- - gem update --system
9
- branches:
10
- only:
11
- - master
12
- install:
13
- - travis_retry bin/setup
14
- language:
15
- - ruby
16
- notifications:
17
- email:
18
- - false
19
- sudo: false
20
- rvm:
21
- - 2.7.0
22
- - 2.4.5
23
- gemfile:
24
- - gemfiles/rails52.gemfile
25
- - gemfiles/rails60.gemfile
26
- - gemfiles/rails_edge.gemfile
27
- matrix:
28
- allow_failures:
29
- - gemfile: gemfiles/rails_edge.gemfile
30
- exclude:
31
- - rvm: 2.4.5
32
- gemfile: gemfiles/rails60.gemfile
33
- - rvm: 2.4.5
34
- gemfile: gemfiles/rails_edge.gemfile
data/Appraisals DELETED
@@ -1,16 +0,0 @@
1
- appraise "rails52" do
2
- gem "activerecord", "~> 5.2.0"
3
- gem "railties", "~> 5.2.0"
4
- end
5
-
6
- if RUBY_VERSION >= "2.5.0"
7
- appraise "rails60" do
8
- gem "activerecord", "~> 6.0.0"
9
- gem "railties", "~> 6.0.0"
10
- end
11
-
12
- appraise "rails-edge" do
13
- gem "rails", git: "https://github.com/rails/rails"
14
- gem "arel", git: "https://github.com/rails/arel"
15
- end
16
- end
data/bin/appraisal DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'appraisal' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('appraisal', 'appraisal')
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 5.2.0"
6
- gem "railties", "~> 5.2.0"
7
-
8
- gemspec path: "../"
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 6.0.0"
6
- gem "railties", "~> 6.0.0"
7
-
8
- gemspec path: "../"
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", git: "https://github.com/rails/rails"
6
- gem "arel", git: "https://github.com/rails/arel"
7
-
8
- gemspec path: "../"