├── .all-contributorsrc ├── .gitignore ├── .hound.yml ├── Appraisals ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── Gemfile ├── Gemfile.lock ├── MIT-LICENSE ├── Rakefile ├── circle.yml ├── config └── .rubocop.yml ├── gemfiles ├── rails_5_2_1.gemfile └── rails_5_2_1.gemfile.lock ├── lib ├── squint.rb └── squint │ └── version.rb ├── readme.md ├── squint.gemspec └── test ├── dummy ├── Rakefile ├── app │ ├── assets │ │ └── config │ │ │ └── manifest.js │ └── models │ │ ├── .keep │ │ ├── concerns │ │ └── .keep │ │ ├── post.rb │ │ └── user.rb ├── config.ru ├── config │ ├── application.rb │ ├── boot.rb │ ├── database.yml │ ├── environment.rb │ └── environments │ │ └── test.rb ├── db │ ├── migrate │ │ ├── 20170512185941_create_posts.rb │ │ ├── 20200318185942_create_users.rb │ │ └── 20200318185943_add_settings_to_posts.rb │ └── schema.rb ├── log │ └── .keep ├── test │ └── fixtures │ │ └── posts.yml └── user.rb ├── squint_test.rb └── test_helper.rb /.all-contributorsrc: -------------------------------------------------------------------------------- 1 | { 2 | "projectName": "squint", 3 | "projectOwner": "ProctorU", 4 | "files": [ 5 | "readme.md" 6 | ], 7 | "imageSize": 100, 8 | "commit": true, 9 | "contributors": [ 10 | { 11 | "login": "chevinbrown", 12 | "name": "Kevin Brown", 13 | "avatar_url": "https://avatars2.githubusercontent.com/u/864581?v=3", 14 | "profile": "https://github.com/chevinbrown", 15 | "contributions": [ 16 | "design", 17 | "review" 18 | ] 19 | }, 20 | { 21 | "login": "king601", 22 | "name": "Andrew Fomera", 23 | "avatar_url": "https://avatars2.githubusercontent.com/u/1741179?v=3", 24 | "profile": "http://andrewfomera.com", 25 | "contributions": [ 26 | "review", 27 | "code" 28 | ] 29 | }, 30 | { 31 | "login": "rthbound", 32 | "name": "Ryan T. Hosford", 33 | "avatar_url": "https://avatars2.githubusercontent.com/u/708692?v=3", 34 | "profile": "https://github.com/rthbound", 35 | "contributions": [ 36 | "code" 37 | ] 38 | }, 39 | { 40 | "login": "Jaehdawg", 41 | "name": "Matthew Jaeh", 42 | "avatar_url": "https://avatars2.githubusercontent.com/u/1785682?v=3", 43 | "profile": "https://github.com/Jaehdawg", 44 | "contributions": [ 45 | "design", 46 | "review" 47 | ] 48 | }, 49 | { 50 | "login": "licatajustin", 51 | "name": "Justin Licata", 52 | "avatar_url": "https://avatars0.githubusercontent.com/u/3933204?v=3", 53 | "profile": "https://twitter.com/justinlicata", 54 | "contributions": [ 55 | "code", 56 | "design", 57 | "doc", 58 | "review" 59 | ] 60 | }, 61 | { 62 | "login": "kmiracle86", 63 | "name": "Kyle Miracle", 64 | "avatar_url": "https://avatars3.githubusercontent.com/u/24704300?v=4", 65 | "profile": "https://github.com/kmiracle86", 66 | "contributions": [ 67 | "bug", 68 | "review" 69 | ] 70 | }, 71 | { 72 | "login": "dwilkins", 73 | "name": "David H. Wilkins", 74 | "avatar_url": "https://avatars2.githubusercontent.com/u/97011?v=3", 75 | "profile": "http://conecuh.com", 76 | "contributions": [ 77 | "question", 78 | "bug", 79 | "code", 80 | "design", 81 | "doc", 82 | "example", 83 | "review", 84 | "test" 85 | ] 86 | }, 87 | { 88 | "login": "TheJayWright", 89 | "name": "Jay Wright", 90 | "avatar_url": "https://avatars3.githubusercontent.com/u/19173815?v=3", 91 | "profile": "https://github.com/TheJayWright", 92 | "contributions": [ 93 | "review" 94 | ] 95 | }, 96 | { 97 | "login": "jamescook", 98 | "name": "James Cook", 99 | "avatar_url": "https://avatars1.githubusercontent.com/u/4067?s=460&u=cb404cc0f1737c2fc53411e300cc8e158ef29295&v=4", 100 | "profile": "https://github.com/jamescook", 101 | "contributions": [ 102 | "code", 103 | "test", 104 | "review" 105 | ] 106 | } 107 | ] 108 | } 109 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .bundle/ 2 | .byebug_history 3 | .ruby-version 4 | .ruby-gemset 5 | log/*.log 6 | pkg/ 7 | test/dummy/db/*.sqlite3 8 | test/dummy/db/*.sqlite3-journal 9 | test/dummy/log/*.log 10 | test/dummy/tmp/ 11 | test/dummy/.sass-cache 12 | test/reports -------------------------------------------------------------------------------- /.hound.yml: -------------------------------------------------------------------------------- 1 | # https://houndci.com/configuration 2 | 3 | ruby: 4 | enabled: true 5 | config_file: config/.rubocop.yml 6 | -------------------------------------------------------------------------------- /Appraisals: -------------------------------------------------------------------------------- 1 | appraise 'rails-5-1-6-2' do 2 | gem "rails", "5.1.6.2" 3 | end 4 | 5 | appraise 'rails-5-2-1' do 6 | gem "rails", "5.2.1" 7 | end 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 6 | and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 7 | 8 | ## Unreleased 9 | 10 | ### Added 11 | 12 | - No changes. 13 | 14 | ### Changed 15 | 16 | - No changes. 17 | 18 | ### Removed 19 | 20 | - No changes. 21 | 22 | ## 1.1.1 - 2019-09-12 23 | 24 | ### Added 25 | 26 | - No additions. 27 | 28 | ### Changed 29 | 30 | - Remove `warning: already initialized constant Squint::HASH_DATA_COLUMNS` on initializaton 31 | 32 | ### Removed 33 | 34 | - No removals. 35 | 36 | ## 1.1.0 - 2018-12-07 37 | 38 | ### Added 39 | 40 | - Added Support for Rails 5.2 (#18) [Andrew Fomera @king601] 41 | 42 | ### Changed 43 | 44 | - No changes. 45 | 46 | ### Removed 47 | 48 | - No removals. 49 | 50 | ## 1.0.1 51 | 52 | - Previous release of Gem 53 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers 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, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at techteam@proctoru.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Declare your gem's dependencies in squint.gemspec. 4 | # Bundler will treat runtime dependencies like base dependencies, and 5 | # development dependencies will be added by default to the :development group. 6 | gemspec 7 | 8 | # Declare any dependencies that are still in development here instead of in 9 | # your gemspec. These might include edge Rails or gems from your path or 10 | # Git. Remember to move these dependencies to your gemspec before releasing 11 | # your gem to rubygems.org. 12 | 13 | gem 'minitest-ci' # for CircleCI 14 | gem 'minitest-focus', group: %i[development test], require: false 15 | gem 'pg', '~> 0.18', group: %i[development test] 16 | gem 'rubocop', require: false 17 | 18 | gem 'storext' 19 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | squint (2.0.0) 5 | pg 6 | rails (>= 5.1.6.2) 7 | 8 | GEM 9 | remote: https://rubygems.org/ 10 | specs: 11 | actioncable (5.1.7) 12 | actionpack (= 5.1.7) 13 | nio4r (~> 2.0) 14 | websocket-driver (~> 0.6.1) 15 | actionmailer (5.1.7) 16 | actionpack (= 5.1.7) 17 | actionview (= 5.1.7) 18 | activejob (= 5.1.7) 19 | mail (~> 2.5, >= 2.5.4) 20 | rails-dom-testing (~> 2.0) 21 | actionpack (5.1.7) 22 | actionview (= 5.1.7) 23 | activesupport (= 5.1.7) 24 | rack (~> 2.0) 25 | rack-test (>= 0.6.3) 26 | rails-dom-testing (~> 2.0) 27 | rails-html-sanitizer (~> 1.0, >= 1.0.2) 28 | actionview (5.1.7) 29 | activesupport (= 5.1.7) 30 | builder (~> 3.1) 31 | erubi (~> 1.4) 32 | rails-dom-testing (~> 2.0) 33 | rails-html-sanitizer (~> 1.0, >= 1.0.3) 34 | activejob (5.1.7) 35 | activesupport (= 5.1.7) 36 | globalid (>= 0.3.6) 37 | activemodel (5.1.7) 38 | activesupport (= 5.1.7) 39 | activerecord (5.1.7) 40 | activemodel (= 5.1.7) 41 | activesupport (= 5.1.7) 42 | arel (~> 8.0) 43 | activesupport (5.1.7) 44 | concurrent-ruby (~> 1.0, >= 1.0.2) 45 | i18n (>= 0.7, < 2) 46 | minitest (~> 5.1) 47 | tzinfo (~> 1.1) 48 | appraisal (2.2.0) 49 | bundler 50 | rake 51 | thor (>= 0.14.0) 52 | arel (8.0.0) 53 | ast (2.3.0) 54 | axiom-types (0.1.1) 55 | descendants_tracker (~> 0.0.4) 56 | ice_nine (~> 0.11.0) 57 | thread_safe (~> 0.3, >= 0.3.1) 58 | builder (3.2.4) 59 | coercible (1.0.0) 60 | descendants_tracker (~> 0.0.1) 61 | concurrent-ruby (1.0.5) 62 | crass (1.0.6) 63 | descendants_tracker (0.0.4) 64 | thread_safe (~> 0.3, >= 0.3.1) 65 | equalizer (0.0.11) 66 | erubi (1.9.0) 67 | globalid (0.4.2) 68 | activesupport (>= 4.2.0) 69 | i18n (0.8.6) 70 | ice_nine (0.11.2) 71 | loofah (2.2.3) 72 | crass (~> 1.0.2) 73 | nokogiri (>= 1.5.9) 74 | mail (2.6.6) 75 | mime-types (>= 1.16, < 4) 76 | method_source (0.8.2) 77 | mime-types (3.1) 78 | mime-types-data (~> 3.2015) 79 | mime-types-data (3.2016.0521) 80 | mini_portile2 (2.3.0) 81 | minitest (5.10.3) 82 | minitest-ci (3.2.0) 83 | minitest (>= 5.0.6) 84 | minitest-focus (1.1.2) 85 | minitest (>= 4, < 6) 86 | nio4r (2.1.0) 87 | nokogiri (1.8.5) 88 | mini_portile2 (~> 2.3.0) 89 | parallel (1.11.2) 90 | parser (2.4.0.0) 91 | ast (~> 2.2) 92 | pg (0.21.0) 93 | powerpack (0.1.1) 94 | rack (2.0.9) 95 | rack-test (0.6.3) 96 | rack (>= 1.0) 97 | rails (5.1.7) 98 | actioncable (= 5.1.7) 99 | actionmailer (= 5.1.7) 100 | actionpack (= 5.1.7) 101 | actionview (= 5.1.7) 102 | activejob (= 5.1.7) 103 | activemodel (= 5.1.7) 104 | activerecord (= 5.1.7) 105 | activesupport (= 5.1.7) 106 | bundler (>= 1.3.0) 107 | railties (= 5.1.7) 108 | sprockets-rails (>= 2.0.0) 109 | rails-dom-testing (2.0.3) 110 | activesupport (>= 4.2.0) 111 | nokogiri (>= 1.6) 112 | rails-html-sanitizer (1.0.4) 113 | loofah (~> 2.2, >= 2.2.2) 114 | railties (5.1.7) 115 | actionpack (= 5.1.7) 116 | activesupport (= 5.1.7) 117 | method_source 118 | rake (>= 0.8.7) 119 | thor (>= 0.18.1, < 2.0) 120 | rainbow (2.2.2) 121 | rake 122 | rake (12.0.0) 123 | rubocop (0.49.1) 124 | parallel (~> 1.10) 125 | parser (>= 2.3.3.1, < 3.0) 126 | powerpack (~> 0.1) 127 | rainbow (>= 1.99.1, < 3.0) 128 | ruby-progressbar (~> 1.7) 129 | unicode-display_width (~> 1.0, >= 1.0.1) 130 | ruby-progressbar (1.8.1) 131 | sprockets (3.7.2) 132 | concurrent-ruby (~> 1.0) 133 | rack (> 1, < 3) 134 | sprockets-rails (3.2.2) 135 | actionpack (>= 4.0) 136 | activesupport (>= 4.0) 137 | sprockets (>= 3.0.0) 138 | storext (2.2.2) 139 | rails (>= 4.0, < 6.0) 140 | virtus 141 | thor (0.19.4) 142 | thread_safe (0.3.6) 143 | tzinfo (1.2.7) 144 | thread_safe (~> 0.1) 145 | unicode-display_width (1.3.0) 146 | virtus (1.0.5) 147 | axiom-types (~> 0.1) 148 | coercible (~> 1.0) 149 | descendants_tracker (~> 0.0, >= 0.0.3) 150 | equalizer (~> 0.0, >= 0.0.9) 151 | websocket-driver (0.6.5) 152 | websocket-extensions (>= 0.1.0) 153 | websocket-extensions (0.1.5) 154 | 155 | PLATFORMS 156 | ruby 157 | 158 | DEPENDENCIES 159 | appraisal 160 | minitest-ci 161 | minitest-focus 162 | pg (~> 0.18) 163 | rubocop 164 | squint! 165 | storext 166 | 167 | BUNDLED WITH 168 | 2.1.4 169 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2017 David H. Wilkins 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | begin 2 | require 'bundler/setup' 3 | rescue LoadError 4 | puts 'You must `gem install bundler` and `bundle install` to run rake tasks' 5 | end 6 | 7 | require 'rdoc/task' 8 | 9 | RDoc::Task.new(:rdoc) do |rdoc| 10 | rdoc.rdoc_dir = 'rdoc' 11 | rdoc.title = 'Squint' 12 | rdoc.options << '--line-numbers' 13 | rdoc.rdoc_files.include('README.rdoc') 14 | rdoc.rdoc_files.include('lib/**/*.rb') 15 | end 16 | 17 | Bundler::GemHelper.install_tasks 18 | 19 | require 'rake/testtask' 20 | 21 | Rake::TestTask.new(:test) do |t| 22 | t.libs << 'lib' 23 | t.libs << 'test' 24 | t.pattern = 'test/**/*_test.rb' 25 | t.verbose = false 26 | end 27 | 28 | task default: :test 29 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | orbs: 4 | ruby: circleci/ruby@1.1.0 5 | node: circleci/node@2 6 | 7 | jobs: 8 | # build: 9 | # docker: 10 | # - image: cimg/ruby:2.7-node 11 | # steps: 12 | # - checkout 13 | # - ruby/install-deps 14 | # - node/install-packages: 15 | # package-mgr: yarn 16 | # cache-key: "yarn.lock" 17 | 18 | test: 19 | parallelism: 1 20 | docker: 21 | - image: cimg/ruby:2.7-node 22 | - image: circleci/postgres:9.6-alpine 23 | environment: 24 | POSTGRES_USER: squint-ruby 25 | POSTGRES_DB: squint_test 26 | POSTGRES_PASSWORD: "" 27 | environment: 28 | BUNDLE_JOBS: "1" 29 | BUNDLE_RETRY: "3" 30 | PGHOST: 127.0.0.1 31 | PGUSER: squint-ruby 32 | PGPASSWORD: "" 33 | RAILS_ENV: test 34 | steps: 35 | - checkout 36 | - ruby/install-deps 37 | - run: 38 | name: Wait for DB 39 | command: dockerize -wait tcp://localhost:5432 -timeout 1m 40 | - run: gem install bundler:2.0.2 && bundle version 41 | - run: bundle install 42 | - run: bundle exec appraisal generate 43 | - run: bundle exec appraisal install 44 | - run: 45 | name: Database setup 46 | command: bundle exec appraisal rails-5-1-6-2 rake --rakefile test/dummy/Rakefile db:setup --trace 47 | - run: bundle exec appraisal rake 48 | 49 | workflows: 50 | version: 2 51 | test: 52 | jobs: 53 | - test 54 | 55 | -------------------------------------------------------------------------------- /config/.rubocop.yml: -------------------------------------------------------------------------------- 1 | # https://raw.githubusercontent.com/thoughtbot/hound/master/config/style_guides/ruby.yml 2 | 3 | AllCops: 4 | Exclude: 5 | - 'docs/**' 6 | - 'test/dummy/db/schema.rb' 7 | Layout/AlignArray: 8 | Enabled: false 9 | Layout/AlignHash: 10 | Enabled: false 11 | Layout/AlignParameters: 12 | Enabled: false 13 | Style/StringLiterals: 14 | Enabled: false 15 | Layout/MultilineOperationIndentation: 16 | Enabled: false 17 | Style/ClassAndModuleChildren: 18 | Enabled: false 19 | LineLength: 20 | Max: 100 21 | ExtraSpacing: 22 | Enabled: false 23 | AbcSize: 24 | Enabled: false 25 | Layout/SpaceBeforeFirstArg: 26 | Enabled: false 27 | AmbiguousOperator: 28 | Enabled: false 29 | MultilineMethodCallIndentation: 30 | Enabled: false 31 | Style/FrozenStringLiteralComment: 32 | Enabled: false 33 | Style/ParenthesesAroundCondition: 34 | Enabled: false 35 | -------------------------------------------------------------------------------- /gemfiles/rails_5_2_1.gemfile: -------------------------------------------------------------------------------- 1 | # This file was generated by Appraisal 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "minitest-ci" 6 | gem "minitest-focus", group: [:development, :test], require: false 7 | gem "pg", "~> 0.18", group: [:development, :test] 8 | gem "rubocop", require: false 9 | gem "storext" 10 | gem "rails", "5.2.1" 11 | 12 | gemspec path: "../" 13 | -------------------------------------------------------------------------------- /gemfiles/rails_5_2_1.gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: .. 3 | specs: 4 | squint (1.1.0) 5 | pg 6 | rails (>= 4.2.8) 7 | 8 | GEM 9 | remote: https://rubygems.org/ 10 | specs: 11 | actioncable (5.2.1) 12 | actionpack (= 5.2.1) 13 | nio4r (~> 2.0) 14 | websocket-driver (>= 0.6.1) 15 | actionmailer (5.2.1) 16 | actionpack (= 5.2.1) 17 | actionview (= 5.2.1) 18 | activejob (= 5.2.1) 19 | mail (~> 2.5, >= 2.5.4) 20 | rails-dom-testing (~> 2.0) 21 | actionpack (5.2.1) 22 | actionview (= 5.2.1) 23 | activesupport (= 5.2.1) 24 | rack (~> 2.0) 25 | rack-test (>= 0.6.3) 26 | rails-dom-testing (~> 2.0) 27 | rails-html-sanitizer (~> 1.0, >= 1.0.2) 28 | actionview (5.2.1) 29 | activesupport (= 5.2.1) 30 | builder (~> 3.1) 31 | erubi (~> 1.4) 32 | rails-dom-testing (~> 2.0) 33 | rails-html-sanitizer (~> 1.0, >= 1.0.3) 34 | activejob (5.2.1) 35 | activesupport (= 5.2.1) 36 | globalid (>= 0.3.6) 37 | activemodel (5.2.1) 38 | activesupport (= 5.2.1) 39 | activerecord (5.2.1) 40 | activemodel (= 5.2.1) 41 | activesupport (= 5.2.1) 42 | arel (>= 9.0) 43 | activestorage (5.2.1) 44 | actionpack (= 5.2.1) 45 | activerecord (= 5.2.1) 46 | marcel (~> 0.3.1) 47 | activesupport (5.2.1) 48 | concurrent-ruby (~> 1.0, >= 1.0.2) 49 | i18n (>= 0.7, < 2) 50 | minitest (~> 5.1) 51 | tzinfo (~> 1.1) 52 | appraisal (2.2.0) 53 | bundler 54 | rake 55 | thor (>= 0.14.0) 56 | arel (9.0.0) 57 | ast (2.4.0) 58 | axiom-types (0.1.1) 59 | descendants_tracker (~> 0.0.4) 60 | ice_nine (~> 0.11.0) 61 | thread_safe (~> 0.3, >= 0.3.1) 62 | builder (3.2.3) 63 | byebug (10.0.2) 64 | coderay (1.1.2) 65 | coercible (1.0.0) 66 | descendants_tracker (~> 0.0.1) 67 | concurrent-ruby (1.0.5) 68 | crass (1.0.4) 69 | descendants_tracker (0.0.4) 70 | thread_safe (~> 0.3, >= 0.3.1) 71 | equalizer (0.0.11) 72 | erubi (1.7.1) 73 | globalid (0.4.1) 74 | activesupport (>= 4.2.0) 75 | i18n (1.1.1) 76 | concurrent-ruby (~> 1.0) 77 | ice_nine (0.11.2) 78 | jaro_winkler (1.5.1-x86_64-darwin-17) 79 | json (2.1.0) 80 | loofah (2.2.2) 81 | crass (~> 1.0.2) 82 | nokogiri (>= 1.5.9) 83 | mail (2.7.1) 84 | mini_mime (>= 0.1.1) 85 | marcel (0.3.3) 86 | mimemagic (~> 0.3.2) 87 | method_source (0.9.0) 88 | mimemagic (0.3.2) 89 | mini_mime (1.0.1) 90 | mini_portile2 (2.3.0) 91 | minitest (5.11.3) 92 | minitest-ci (3.4.0) 93 | minitest (>= 5.0.6) 94 | minitest-focus (1.1.2) 95 | minitest (>= 4, < 6) 96 | nio4r (2.3.1) 97 | nokogiri (1.8.5) 98 | mini_portile2 (~> 2.3.0) 99 | parallel (1.12.1) 100 | parser (2.5.1.2) 101 | ast (~> 2.4.0) 102 | pg (0.21.0) 103 | powerpack (0.1.2) 104 | pry (0.11.3) 105 | coderay (~> 1.1.0) 106 | method_source (~> 0.9.0) 107 | pry-byebug (3.6.0) 108 | byebug (~> 10.0) 109 | pry (~> 0.10) 110 | pry-highlight (0.1.0) 111 | coderay 112 | json 113 | nokogiri 114 | pry 115 | pry-rails (0.3.6) 116 | pry (>= 0.10.4) 117 | pry-remote (0.1.8) 118 | pry (~> 0.9) 119 | slop (~> 3.0) 120 | rack (2.0.5) 121 | rack-test (1.1.0) 122 | rack (>= 1.0, < 3) 123 | rails (5.2.1) 124 | actioncable (= 5.2.1) 125 | actionmailer (= 5.2.1) 126 | actionpack (= 5.2.1) 127 | actionview (= 5.2.1) 128 | activejob (= 5.2.1) 129 | activemodel (= 5.2.1) 130 | activerecord (= 5.2.1) 131 | activestorage (= 5.2.1) 132 | activesupport (= 5.2.1) 133 | bundler (>= 1.3.0) 134 | railties (= 5.2.1) 135 | sprockets-rails (>= 2.0.0) 136 | rails-dom-testing (2.0.3) 137 | activesupport (>= 4.2.0) 138 | nokogiri (>= 1.6) 139 | rails-html-sanitizer (1.0.4) 140 | loofah (~> 2.2, >= 2.2.2) 141 | railties (5.2.1) 142 | actionpack (= 5.2.1) 143 | activesupport (= 5.2.1) 144 | method_source 145 | rake (>= 0.8.7) 146 | thor (>= 0.19.0, < 2.0) 147 | rainbow (3.0.0) 148 | rake (12.3.1) 149 | rubocop (0.59.2) 150 | jaro_winkler (~> 1.5.1) 151 | parallel (~> 1.10) 152 | parser (>= 2.5, != 2.5.1.1) 153 | powerpack (~> 0.1) 154 | rainbow (>= 2.2.2, < 4.0) 155 | ruby-progressbar (~> 1.7) 156 | unicode-display_width (~> 1.0, >= 1.0.1) 157 | ruby-progressbar (1.10.0) 158 | slop (3.6.0) 159 | sprockets (3.7.2) 160 | concurrent-ruby (~> 1.0) 161 | rack (> 1, < 3) 162 | sprockets-rails (3.2.1) 163 | actionpack (>= 4.0) 164 | activesupport (>= 4.0) 165 | sprockets (>= 3.0.0) 166 | storext (2.2.2) 167 | rails (>= 4.0, < 6.0) 168 | virtus 169 | thor (0.20.0) 170 | thread_safe (0.3.6) 171 | tzinfo (1.2.5) 172 | thread_safe (~> 0.1) 173 | unicode-display_width (1.4.0) 174 | virtus (1.0.5) 175 | axiom-types (~> 0.1) 176 | coercible (~> 1.0) 177 | descendants_tracker (~> 0.0, >= 0.0.3) 178 | equalizer (~> 0.0, >= 0.0.9) 179 | websocket-driver (0.7.0) 180 | websocket-extensions (>= 0.1.0) 181 | websocket-extensions (0.1.3) 182 | 183 | PLATFORMS 184 | ruby 185 | 186 | DEPENDENCIES 187 | appraisal 188 | minitest-ci 189 | minitest-focus 190 | pg (~> 0.18) 191 | pry-byebug 192 | pry-highlight 193 | pry-rails 194 | pry-remote 195 | rails (= 5.2.1) 196 | rubocop 197 | squint! 198 | storext 199 | 200 | BUNDLED WITH 201 | 1.16.6 202 | -------------------------------------------------------------------------------- /lib/squint.rb: -------------------------------------------------------------------------------- 1 | require 'active_support/concern' 2 | 3 | # Squint json, jsonb, hstore queries 4 | module Squint 5 | extend ActiveSupport::Concern 6 | if ActiveRecord::VERSION::STRING < '5' 7 | include ::ActiveRecord::QueryMethods 8 | end 9 | 10 | module WhereMethods 11 | # Args may be passed to build/build_where like: 12 | # build_where(jsonb_column: {key1: value1}) 13 | # build_where(jsonb_column: {key1: value1}, jsonb_column: {key2: value2}) 14 | # build_where(jsonb_column: {key1: value1}, regular_column: value) 15 | # build_where(jsonb_column: {key1: value1}, association: {column: value)) 16 | if ActiveRecord::VERSION::STRING > '5' 17 | method_name = :build 18 | elsif ActiveRecord::VERSION::STRING < '5' 19 | method_name = :build_where 20 | end 21 | send :define_method, method_name do |*args| 22 | # For Rails 5, we end up monkey patching WhereClauseFactory for everyone 23 | # so need to return super if our methods aren't on the AR class 24 | # doesn't hurt for 4.2.x either 25 | return super(*args) unless klass.respond_to?(:squint_hash_field_reln) 26 | save_args = [] 27 | reln = args.inject([]) do |memo, arg| 28 | if arg.is_a?(Hash) 29 | arg.keys.each do |key| 30 | if arg[key].is_a?(Hash) && klass::HASH_DATA_COLUMNS[key] 31 | memo << klass.squint_hash_field_reln(key => arg[key]) 32 | else 33 | save_args[0] ||= {} 34 | save_args[0][key] = arg[key] 35 | end 36 | end 37 | elsif arg.present? 38 | save_args << arg 39 | end 40 | memo 41 | end 42 | if ActiveRecord::VERSION::STRING >= '5.2' 43 | # In 5.2 the WhereClause private class no longer takes two arguments. 44 | # Commit where it was removed: 45 | # https://github.com/rails/rails/commit/213796fb4936dce1da2f0c097a054e1af5c25c2c#diff-c9d167bac00ff2f45c5b5e035e8a80e8 46 | reln = ActiveRecord::Relation::WhereClause.new(reln) 47 | elsif ActiveRecord::VERSION::STRING > '5' 48 | reln = ActiveRecord::Relation::WhereClause.new(reln, []) 49 | end 50 | save_args << [] if save_args.size == 1 51 | reln += super(*save_args) unless save_args.empty? 52 | reln 53 | end 54 | end 55 | 56 | included do |base| 57 | if ActiveRecord::VERSION::STRING < '5' 58 | ar_reln_module = base::ActiveRecord_Relation 59 | ar_association_module = base::ActiveRecord_AssociationRelation 60 | elsif ActiveRecord::VERSION::STRING > '5.1' 61 | # ActiveRecord_Relation is now a private_constant in 5.1.x 62 | ar_reln_module = base.relation_delegate_class(ActiveRecord::Relation)::WhereClauseFactory 63 | ar_association_module = nil 64 | elsif ActiveRecord::VERSION::STRING > '5.0' 65 | ar_reln_module = base::ActiveRecord_Relation::WhereClauseFactory 66 | ar_association_module = nil 67 | # ar_association_module = base::ActiveRecord_AssociationRelation 68 | end 69 | 70 | # put together a list of columns in this model 71 | # that are hstore, json, or jsonb and will benefit from 72 | # searchability 73 | base::HASH_DATA_COLUMNS = base.columns_hash.keys.map do |col_name| 74 | if %w[hstore json jsonb].include?(base.columns_hash[col_name].sql_type) 75 | [col_name.to_sym, base.columns_hash[col_name].sql_type] 76 | end 77 | end.compact.to_h 78 | 79 | ar_reln_module.class_eval do 80 | prepend WhereMethods 81 | end 82 | 83 | ar_association_module.try(:class_eval) do 84 | prepend WhereMethods 85 | end 86 | 87 | # squint_hash_field_reln 88 | # return an Arel object with the appropriate query 89 | # Strings want to be a SQL Literal, other things can be 90 | # passed in bare to the eq or in operator 91 | def self.squint_hash_field_reln(*args) 92 | temp_attr = args[0] 93 | contains_nil = false 94 | column_type = self::HASH_DATA_COLUMNS[args[0].keys.first] 95 | column_name_segments = [] 96 | quote_char = '"'.freeze 97 | while temp_attr.is_a?(Hash) 98 | attribute_sym = temp_attr.keys.first.to_sym 99 | column_name_segments << (quote_char + temp_attr.keys.first.to_s + quote_char) 100 | quote_char = '\''.freeze 101 | temp_attr = temp_attr[temp_attr.keys.first] 102 | end 103 | 104 | check_attr_missing = squint_storext_default?(temp_attr, attribute_sym) 105 | 106 | # Check for nil in array 107 | if temp_attr.is_a? Array 108 | contains_nil = temp_attr.include?(nil) 109 | # remove the nil from the array - we'll handle that later 110 | temp_attr.compact! 111 | # if the Array is now just 1 element, it doesn't need to be 112 | # an Array any longer 113 | temp_attr = temp_attr[0] if temp_attr.size == 1 114 | end 115 | 116 | if temp_attr.is_a? Array 117 | temp_attr = temp_attr.map(&:to_s) 118 | elsif ![FalseClass, TrueClass, NilClass].include?(temp_attr.class) 119 | temp_attr = temp_attr.to_s 120 | end 121 | 122 | query_value = if [Array, NilClass].include?(temp_attr.class) 123 | temp_attr 124 | else # strings or string-like things 125 | Arel::Nodes::Quoted.new(temp_attr.to_s) 126 | end 127 | # column_name_segments[0] = column_name_segments[0] 128 | attribute_selector = column_name_segments.join('->'.freeze) 129 | 130 | # JSON(B) data needs to have the last accessor be ->> instead of 131 | # -> . The ->> returns the data as text instead of jsonb. 132 | # hstore columns generally don't have nested keys / hashes 133 | # Possibly need to raise an error if the hash for an hstore 134 | # column references nested arrays? 135 | unless column_type == 'hstore'.freeze 136 | attribute_selector[attribute_selector.rindex('>'.freeze)] = '>>'.freeze 137 | end 138 | 139 | reln = if query_value.is_a?(Array) 140 | arel_table[Arel::Nodes::SqlLiteral.new(attribute_selector)].in(query_value) 141 | else 142 | arel_table[Arel::Nodes::SqlLiteral.new(attribute_selector)].eq(query_value) 143 | end 144 | 145 | # If a nil is present in an Array, need add a specific IS NULL comparison 146 | if contains_nil 147 | reln = Arel::Nodes::Grouping.new( 148 | reln.or(arel_table[Arel::Nodes::SqlLiteral.new(attribute_selector)].eq(nil)) 149 | ) 150 | end 151 | 152 | # check_attr_missing for StoreXT attributes where the default is 153 | # specified as a query value 154 | if check_attr_missing 155 | reln = if column_type == 'hstore'.freeze 156 | squint_hstore_element_missing(column_name_segments, reln) 157 | else 158 | squint_jsonb_element_missing(column_name_segments, reln) 159 | end 160 | end 161 | reln 162 | end 163 | 164 | def self.squint_storext_default?(temp_attr, attribute_sym) 165 | return false unless respond_to?(:storext_definitions) 166 | if storext_definitions.keys.include?(attribute_sym) && 167 | !(storext_definitions[attribute_sym][:opts] && 168 | storext_definitions[attribute_sym][:opts][:default]).nil? && 169 | [temp_attr].compact.map(&:to_s). 170 | flatten. 171 | include?(storext_definitions[attribute_sym][:opts][:default].to_s) 172 | true 173 | end 174 | end 175 | 176 | def self.squint_hstore_element_exists(element, attribute_hash_column, value) 177 | Arel::Nodes::Equality.new( 178 | Arel::Nodes::NamedFunction.new( 179 | "exist", 180 | [arel_table[Arel::Nodes::SqlLiteral.new(attribute_hash_column)], 181 | Arel::Nodes::SqlLiteral.new(element)] 182 | ), value 183 | ) 184 | end 185 | 186 | def self.squint_hstore_element_missing(column_name_segments, reln) 187 | element = column_name_segments.pop 188 | attribute_hash_column = column_name_segments.join('->'.freeze) 189 | # Query generated is equals default or attribute present is null or equals false 190 | # * Is null happens the the column is null 191 | # * equals false is when the column has jsonb data, but the key doesn't exist 192 | # ("posts"."storext_attributes"->>'is_awesome' = 'false' OR 193 | # (exists("posts"."storext_attributes", 'is_awesome') IS NULL OR 194 | # exists("posts"."storext_attributes", 'is_awesome') = FALSE) 195 | # ) 196 | Arel::Nodes::Grouping.new( 197 | reln.or( 198 | Arel::Nodes::Grouping.new( 199 | squint_hstore_element_exists(element, attribute_hash_column, Arel::Nodes::False.new) 200 | ).or( 201 | squint_hstore_element_exists(element, attribute_hash_column, nil) 202 | ) 203 | ) 204 | ) 205 | end 206 | 207 | def self.squint_jsonb_element_equality(element, attribute_hash_column, value) 208 | Arel::Nodes::Equality.new( 209 | Arel::Nodes::Grouping.new( 210 | Arel::Nodes::InfixOperation.new( 211 | Arel::Nodes::SqlLiteral.new('?'), 212 | arel_table[Arel::Nodes::SqlLiteral.new(attribute_hash_column)], 213 | Arel::Nodes::SqlLiteral.new(element) 214 | ) 215 | ), value 216 | ) 217 | end 218 | 219 | def self.squint_jsonb_element_missing(column_name_segments, reln) 220 | element = column_name_segments.pop 221 | attribute_hash_column = column_name_segments.join('->'.freeze) 222 | # Query generated is equals default or attribute present is null or equals false 223 | # * Is null happens when the the whole column is null 224 | # * equals false is when the column has jsonb data, but the key doesn't exist 225 | # ("posts"."storext_attributes"->>'is_awesome' = 'false' OR 226 | # (("posts"."storext_attributes" ? 'is_awesome') IS NULL OR 227 | # ("posts"."storext_attributes" ? 'is_awesome') = FALSE) 228 | # ) 229 | Arel::Nodes::Grouping.new( 230 | reln.or( 231 | Arel::Nodes::Grouping.new( 232 | squint_jsonb_element_equality(element, attribute_hash_column, nil).or( 233 | squint_jsonb_element_equality(element, attribute_hash_column, Arel::Nodes::False.new) 234 | ) 235 | ) 236 | ) 237 | ) 238 | end 239 | end 240 | end 241 | -------------------------------------------------------------------------------- /lib/squint/version.rb: -------------------------------------------------------------------------------- 1 | module Squint 2 | VERSION = "2.0.0".freeze 3 | end 4 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |
6 |
7 | Search PostgreSQL jsonb
and hstore
columns.
8 |
175 |
176 |
177 |
178 |
179 |
184 | A simple online proctoring service that allows you to take exams or certification tests at home. 185 |
186 | 187 | -------------------------------------------------------------------------------- /squint.gemspec: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift File.expand_path("../lib", __FILE__) 2 | 3 | # Maintain your gem's version: 4 | require "squint/version" 5 | 6 | # Describe your gem and declare its dependencies: 7 | Gem::Specification.new do |s| 8 | s.name = "squint" 9 | s.version = Squint::VERSION 10 | s.authors = ["David H. Wilkins", "Justin Licata"] 11 | s.email = ["dwilkins@proctoru.com", "jlicata@proctoru.com"] 12 | s.homepage = "https://github.com/ProctorU/squint" 13 | s.summary = "Search PostgreSQL jsonb and hstore columns" 14 | s.description = "Use rails semantics to search keys and values inside " \ 15 | "PostgreSQL jsonb, json and hstore columns. Compatible " \ 16 | "with StoreXT attributes." 17 | s.license = "MIT" 18 | 19 | s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", 20 | "Rakefile", "readme.md", ".all-contributorsrc"] 21 | s.test_files = Dir["test/**/*"] 22 | 23 | s.add_dependency "rails", ">= 5.1.6.2" 24 | s.add_dependency "pg" 25 | 26 | s.add_development_dependency 'appraisal' 27 | end 28 | -------------------------------------------------------------------------------- /test/dummy/Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require File.expand_path('../config/application', __FILE__) 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /test/dummy/app/assets/config/manifest.js: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/dummy/app/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProctorU/squint/74ec8e1db6eaeca03ee76f5093ed50ebe1674a87/test/dummy/app/models/.keep -------------------------------------------------------------------------------- /test/dummy/app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProctorU/squint/74ec8e1db6eaeca03ee76f5093ed50ebe1674a87/test/dummy/app/models/concerns/.keep -------------------------------------------------------------------------------- /test/dummy/app/models/post.rb: -------------------------------------------------------------------------------- 1 | class Post < ActiveRecord::Base 2 | include Storext.model 3 | include Squint 4 | 5 | store_attribute :storext_jsonb_attributes, :jsonb_zip_code, String, default: '90210' 6 | store_attribute :storext_jsonb_attributes, :jsonb_friend_count, Integer, default: 0 7 | store_attribute :storext_jsonb_attributes, :jsonb_is_awesome, Integer, default: false 8 | store_attribute :storext_jsonb_attributes, :jsonb_is_present, Integer, default: nil 9 | 10 | store_attribute :storext_hstore_attributes, :hstore_zip_code, String, default: '90210' 11 | store_attribute :storext_hstore_attributes, :hstore_friend_count, Integer, default: 0 12 | store_attribute :storext_hstore_attributes, :hstore_is_awesome, Integer, default: false 13 | store_attribute :storext_hstore_attributes, :hstore_is_present, Integer, default: nil 14 | 15 | store_attribute :settings, :zip_code, String, default: '90210' 16 | end 17 | -------------------------------------------------------------------------------- /test/dummy/app/models/user.rb: -------------------------------------------------------------------------------- 1 | class User < ActiveRecord::Base 2 | include Storext.model 3 | include Squint 4 | 5 | store_attribute :settings, :zip_code, String, default: '90210' 6 | end 7 | -------------------------------------------------------------------------------- /test/dummy/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Rails.application 5 | -------------------------------------------------------------------------------- /test/dummy/config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | require 'rails/all' 4 | 5 | Bundler.require(*Rails.groups) 6 | require "squint" 7 | 8 | module Dummy 9 | class Application < Rails::Application 10 | # Settings in config/environments/* take precedence over those specified here. 11 | # Application configuration should go into files in config/initializers 12 | # -- all .rb files in that directory are automatically loaded. 13 | 14 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 15 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 16 | # config.time_zone = 'Central Time (US & Canada)' 17 | 18 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 19 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 20 | # config.i18n.default_locale = :de 21 | 22 | # Do not swallow errors in after_commit/after_rollback callbacks. 23 | if ActiveRecord::VERSION::STRING < '5' 24 | config.active_record.raise_in_transactional_callbacks = true 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /test/dummy/config/boot.rb: -------------------------------------------------------------------------------- 1 | # Set up gems listed in the Gemfile. 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) 3 | 4 | require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) 5 | $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) 6 | -------------------------------------------------------------------------------- /test/dummy/config/database.yml: -------------------------------------------------------------------------------- 1 | # local 2 | default: &default 3 | adapter: postgresql 4 | encoding: unicode 5 | pool: 5 6 | 7 | development: 8 | <<: *default 9 | database: squint_development 10 | 11 | test: 12 | <<: *default 13 | database: squint_test 14 | 15 | -------------------------------------------------------------------------------- /test/dummy/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /test/dummy/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Do not eager load code on boot. This avoids loading your whole application 11 | # just for the purpose of running a single test. If you are using a tool that 12 | # preloads Rails for running tests, you may have to set it to true. 13 | config.eager_load = false 14 | 15 | # Configure static file server for tests with Cache-Control for performance. 16 | if ActiveRecord::VERSION::STRING < '5' 17 | config.serve_static_files = true 18 | config.static_cache_control = 'public, max-age=3600' 19 | elsif ActiveRecord::VERSION::STRING > '5' 20 | config.public_file_server.enabled = true 21 | config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' } 22 | end 23 | 24 | # Show full error reports and disable caching. 25 | config.consider_all_requests_local = true 26 | config.action_controller.perform_caching = false 27 | 28 | # Raise exceptions instead of rendering exception templates. 29 | config.action_dispatch.show_exceptions = false 30 | 31 | # Disable request forgery protection in test environment. 32 | config.action_controller.allow_forgery_protection = false 33 | 34 | # Tell Action Mailer not to deliver emails to the real world. 35 | # The :test delivery method accumulates sent emails in the 36 | # ActionMailer::Base.deliveries array. 37 | config.action_mailer.delivery_method = :test 38 | 39 | # Randomize the order test cases are executed. 40 | config.active_support.test_order = :random 41 | 42 | # Print deprecation notices to the stderr. 43 | config.active_support.deprecation = :stderr 44 | 45 | # Raises error for missing translations 46 | # config.action_view.raise_on_missing_translations = true 47 | end 48 | -------------------------------------------------------------------------------- /test/dummy/db/migrate/20170512185941_create_posts.rb: -------------------------------------------------------------------------------- 1 | class CreatePosts < ActiveRecord::Migration 2 | def change 3 | enable_extension "hstore" 4 | create_table :posts do |t| 5 | t.string :title 6 | t.string :body 7 | t.jsonb :request_info 8 | t.hstore :properties 9 | t.jsonb :storext_jsonb_attributes 10 | t.hstore :storext_hstore_attributes 11 | 12 | t.timestamps null: false 13 | t.index :request_info, using: 'GIN' 14 | t.index :properties, using: 'GIN' 15 | t.index :storext_jsonb_attributes, using: 'GIN' 16 | t.index :storext_hstore_attributes, using: 'GIN' 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /test/dummy/db/migrate/20200318185942_create_users.rb: -------------------------------------------------------------------------------- 1 | class CreateUsers < ActiveRecord::Migration 2 | def change 3 | create_table :users do |t| 4 | t.hstore :settings 5 | 6 | t.timestamps null: false 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /test/dummy/db/migrate/20200318185943_add_settings_to_posts.rb: -------------------------------------------------------------------------------- 1 | class AddSettingsToPosts < ActiveRecord::Migration 2 | def change 3 | change_table :posts do |t| 4 | t.jsonb :settings 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /test/dummy/db/schema.rb: -------------------------------------------------------------------------------- 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 | # Note that this schema.rb definition is the authoritative source for your 6 | # database schema. If you need to create the application database on another 7 | # system, you should be using db:schema:load, not running all the migrations 8 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 9 | # you'll amass, the slower it'll run and the greater likelihood for issues). 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema.define(version: 20200318185943) do 14 | 15 | # These are extensions that must be enabled in order to support this database 16 | enable_extension "plpgsql" 17 | enable_extension "hstore" 18 | 19 | create_table "posts", force: :cascade do |t| 20 | t.string "title" 21 | t.string "body" 22 | t.jsonb "request_info" 23 | t.hstore "properties" 24 | t.jsonb "storext_jsonb_attributes" 25 | t.hstore "storext_hstore_attributes" 26 | t.datetime "created_at", null: false 27 | t.datetime "updated_at", null: false 28 | t.jsonb "settings" 29 | t.index ["properties"], name: "index_posts_on_properties", using: :gin 30 | t.index ["request_info"], name: "index_posts_on_request_info", using: :gin 31 | t.index ["storext_hstore_attributes"], name: "index_posts_on_storext_hstore_attributes", using: :gin 32 | t.index ["storext_jsonb_attributes"], name: "index_posts_on_storext_jsonb_attributes", using: :gin 33 | end 34 | 35 | create_table "users", force: :cascade do |t| 36 | t.hstore "settings" 37 | t.datetime "created_at", null: false 38 | t.datetime "updated_at", null: false 39 | end 40 | 41 | end 42 | -------------------------------------------------------------------------------- /test/dummy/log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProctorU/squint/74ec8e1db6eaeca03ee76f5093ed50ebe1674a87/test/dummy/log/.keep -------------------------------------------------------------------------------- /test/dummy/test/fixtures/posts.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | title: Post One Title 5 | body: Post One Body 6 | request_info: { referer: "http://example.com/one" } 7 | properties: { referer: "http://example.com/one" } 8 | 9 | two: 10 | title: Post Two Title 11 | body: Post Two Body 12 | request_info: { referer: "http://example.com/two" } 13 | properties: { referer: "http://example.com/two" } 14 | 15 | three: 16 | title: Post Three Title 17 | body: Post Three Body 18 | 19 | with_storext: 20 | title: With Storext title 21 | body: With Storext title 22 | request_info: { referer: "http://example.com/random" } 23 | properties: { referer: "http://example.com/random" } 24 | storext_jsonb_attributes: { jsonb_zip_code: '35124' } 25 | storext_hstore_attributes: { hstore_zip_code: '35124' } 26 | 27 | with_storext_friends: 28 | title: With Storext friends title 29 | body: With Storext friends title 30 | request_info: { referer: "http://example.com/random" } 31 | properties: { referer: "http://example.com/random" } 32 | storext_jsonb_attributes: { jsonb_zip_code: '36081', jsonb_friend_count: 10 } 33 | storext_hstore_attributes: { hstore_zip_code: '36081', hstore_friend_count: 10 } 34 | 35 | with_storext_is_awesome_default: 36 | title: With Storext is awesome title 37 | body: With Storext is awesome title 38 | request_info: { referer: "http://example.com/random" } 39 | properties: { referer: "http://example.com/random" } 40 | storext_jsonb_attributes: { jsonb_zip_code: '36085', jsonb_friend_count: 11, jsonb_is_awesome: false } 41 | storext_hstore_attributes: { hstore_zip_code: '36085', hstore_friend_count: 11, hstore_is_awesome: false } 42 | 43 | with_storext_is_awesome_not_default: 44 | title: With Storext is aweesome not default title 45 | body: With Storext is awesome not default body 46 | request_info: { referer: "http://example.com/random" } 47 | properties: { referer: "http://example.com/random" } 48 | storext_jsonb_attributes: { jsonb_zip_code: '36085', jsonb_friend_count: 11, jsonb_is_awesome: true } 49 | storext_hstore_attributes: { hstore_zip_code: '36085', hstore_friend_count: 11, hstore_is_awesome: true } 50 | 51 | with_storext_is_present_default: 52 | title: With Storext is present default title 53 | body: With Storext is present default body 54 | request_info: { referer: "http://example.com/random" } 55 | properties: { referer: "http://example.com/random" } 56 | storext_jsonb_attributes: { jsonb_zip_code: '36085', jsonb_friend_count: 11, jsonb_is_present: nil } 57 | storext_hstore_attributes: { hstore_zip_code: '36085', hstore_friend_count: 11, hstore_is_present: nil } 58 | 59 | with_storext_is_present_not_default: 60 | title: With Storext is present not default title 61 | body: With Storext is present not default body 62 | request_info: { referer: "http://example.com/random" } 63 | properties: { referer: "http://example.com/random" } 64 | storext_jsonb_attributes: { jsonb_zip_code: '36085', jsonb_friend_count: 11, jsonb_is_present: "Heck Yeah" } 65 | storext_hstore_attributes: { hstore_zip_code: '36085', hstore_friend_count: 11, hstore_is_present: "Heck Yeah" } 66 | -------------------------------------------------------------------------------- /test/dummy/user.rb: -------------------------------------------------------------------------------- 1 | class User < ActiveRecord::Base 2 | include Storext.model 3 | include Squint 4 | 5 | store_attribute :settings, :zip_code, String, default: '90210' 6 | end 7 | -------------------------------------------------------------------------------- /test/squint_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class SquintTest < ActiveSupport::TestCase 4 | 5 | # Tests that should pass for both jsonb and hstore properties 6 | %i[request_info properties].each do |prop_name| 7 | test "generates SQL for #{prop_name}" do 8 | sql_string = Post.where(prop_name => { referer: "http://example.com/one" }).to_sql 9 | assert_match(/\"posts\".\"#{prop_name}\"-[>]{1,2}\'referer\'/, sql_string) 10 | end 11 | 12 | test "finds records for #{prop_name} populated" do 13 | reln = Post.where(prop_name => { referer: "http://example.com/one" }) 14 | assert_equal 1, reln.count 15 | end 16 | 17 | test "finds records for #{prop_name} populated with array" do 18 | reln = Post.where( 19 | prop_name => { referer: ["http://example.com/one", "http://example.com/two"] } 20 | ) 21 | assert_equal 2, reln.count, reln.to_sql 22 | end 23 | end 24 | 25 | %i[request_info properties].each do |prop_name| 26 | test "finds records for #{prop_name} populated with array including nil" do 27 | reln = Post.where(prop_name => { referer: ["http://example.com/one", nil] }) 28 | assert_equal 2, reln.count, reln.to_sql 29 | end 30 | 31 | test "finds records for #{prop_name} with nil" do 32 | reln = Post.where(prop_name => { referer: nil }) 33 | assert_equal 1, reln.count, reln.to_sql 34 | end 35 | 36 | test "finds records for #{prop_name} missing element that doesn't exist with nil" do 37 | reln = Post.where(prop_name => { not_there: nil }) 38 | assert_equal Post.all.count, reln.count, reln.to_sql 39 | end 40 | 41 | test "Doesn't find records for #{prop_name} missing element that doesn't exist populated" do 42 | reln = Post.where(prop_name => { not_there: "any value will do" }) 43 | assert_equal 0, reln.count, reln.to_sql 44 | end 45 | end 46 | 47 | [ 48 | [:storext_jsonb_attributes, 'jsonb'], 49 | # [:storext_hstore_attributes, 'hstore'] 50 | ].each do |prop_name, prefix| 51 | test "detects present #{prop_name}" do 52 | reln = Post.where(prop_name => { "#{prefix}_zip_code" => '35124' }) 53 | # puts reln.to_sql 54 | assert_equal 1, reln.count, reln.to_sql 55 | end 56 | 57 | test "#{prop_name} is composeable in one where" do 58 | # get the first matching post 59 | posts = Post.where(prop_name => { "#{prefix}_zip_code" => '90210' }) 60 | # compose with previous query with the id of first post 61 | reln = Post.where(prop_name => { "#{prefix}_zip_code" => '90210' }, id: posts.first.id) 62 | # puts reln.to_sql 63 | assert_operator posts.count, :>, 1 64 | assert_equal 1, reln.count, reln.to_sql 65 | end 66 | 67 | test "#{prop_name} is composeable in multiple wheres" do 68 | # get the first matching post 69 | posts = Post.where(prop_name => { "#{prefix}_zip_code" => '90210' }) 70 | # compose with previous query with the id of first post 71 | reln = Post.where(prop_name => { "#{prefix}_zip_code" => '90210' }).where(id: posts.first.id) 72 | # puts reln.to_sql 73 | assert posts.count > 1 74 | assert_equal 1, reln.count, reln.to_sql 75 | end 76 | end 77 | 78 | [[:storext_jsonb_attributes, 'jsonb'], 79 | [:storext_hstore_attributes, 'hstore']].each do |prop_name, prefix| 80 | 81 | test "detects default #{prop_name}" do 82 | reln = Post.where(prop_name => { "#{prefix}_zip_code" => '90210' }) 83 | # puts reln.to_sql 84 | assert_equal Post.all.count - 6, reln.count, reln.to_sql 85 | end 86 | 87 | test "detects present integer #{prop_name}" do 88 | reln = Post.where(prop_name => { "#{prefix}_friend_count" => 10 }) 89 | # puts reln.to_sql 90 | assert_equal 1, reln.count, reln.to_sql 91 | end 92 | 93 | test "detects default integer #{prop_name}" do 94 | reln = Post.where(prop_name => { "#{prefix}_friend_count" => 0 }) 95 | # puts reln.to_sql 96 | assert_equal Post.all.count - 5, reln.count, reln.to_sql 97 | end 98 | 99 | test "detects default Falseclass #{prop_name}" do 100 | reln = Post.where(prop_name => { "#{prefix}_is_awesome" => false }) 101 | # puts reln.to_sql 102 | assert_equal Post.all.count - 1, reln.count, reln.to_sql 103 | end 104 | end 105 | 106 | test "handles string parameters" do 107 | reln = Post.where(storext_jsonb_attributes: { "jsonb_friend_count" => 11 }). 108 | where("posts.title = ?", 'With Storext is aweesome not default title') 109 | assert_nothing_raised do 110 | assert_equal 1, reln.count 111 | end 112 | end 113 | 114 | test "handles multiple non-hash parameters" do 115 | reln = Post.where(storext_jsonb_attributes: { "jsonb_friend_count" => 11 }). 116 | where("posts.id between ? and ?", 117 | posts(:with_storext_is_awesome_not_default).id, 118 | posts(:with_storext_is_awesome_not_default).id + 1) 119 | assert_nothing_raised do 120 | assert_equal 1, reln.count 121 | end 122 | end 123 | 124 | # 125 | # Make sure that build_where isn't passed more than 2 parameters 126 | # There was a bug... 127 | # 128 | test 'with find by lotsa things' do 129 | assert_nothing_raised do 130 | Post.find_by(id: 1, title: 'sumpthin', 131 | body: 'sumpthin else', 132 | created_at: '2015-01-01') 133 | end 134 | end 135 | 136 | test 'HASH_DATA_COLUMNS is not shared between models' do 137 | assert_equal('hstore', User::HASH_DATA_COLUMNS[:settings]) 138 | assert_equal('jsonb' , Post::HASH_DATA_COLUMNS[:settings]) 139 | end 140 | end 141 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | # Configure Rails Environment 2 | ENV["RAILS_ENV"] = "test" 3 | 4 | require File.expand_path("../../test/dummy/config/environment.rb", __FILE__) 5 | ActiveRecord::Migrator.migrations_paths = 6 | [File.expand_path("../../test/dummy/db/migrate", __FILE__)] 7 | require "rails/test_help" 8 | 9 | require 'minitest/focus' 10 | # Filter out Minitest backtrace while allowing backtrace from other libraries 11 | # to be shown. 12 | Minitest.backtrace_filter = Minitest::BacktraceFilter.new 13 | 14 | # Load support files 15 | Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } 16 | 17 | # Load fixtures from the engine 18 | if ActiveSupport::TestCase.respond_to?(:fixture_path=) 19 | ActiveSupport::TestCase.fixture_path = File.expand_path("../dummy/test/fixtures", __FILE__) 20 | ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path 21 | ActiveSupport::TestCase.fixtures :all 22 | end 23 | 24 | class ActiveSupport::TestCase 25 | fixtures :all 26 | # 'cuz I want to be able to login to the db and see things 27 | # and there aren't many tests here anyway, so speed isn't a problem 28 | if ActiveRecord::VERSION::STRING < '5' 29 | self.use_transactional_fixtures = false 30 | elsif ActiveRecord::VERSION::STRING > '5' 31 | self.use_transactional_tests = false 32 | end 33 | end 34 | --------------------------------------------------------------------------------