Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move bug report templates into ransack repository and run templates at CI #1191

Merged
merged 5 commits into from
Jan 22, 2021
Merged

Move bug report templates into ransack repository and run templates at CI #1191

merged 5 commits into from
Jan 22, 2021

Conversation

yahonda
Copy link
Contributor

@yahonda yahonda commented Dec 28, 2020

This pull request moves bug report templates into ransack repository and run templates at CI.

This file is located at https://gist.github.com/jonatack/63048bc5062a84ba9e09
Co-authored-by: jonatack <jonnyatack@gmail.com>
This file is located at https://gist.github.com/jonatack/5df41a0edb53b7bad989
Co-authored-by: jonatack <jonnyatack@gmail.com>
- Ransack does not Rails master branch aka 6.2.0.alpha yet
- polyamorous is now part of ransack
- sqlite3 adapter default boolean changed from `'t'/'f'` to `1/0`
Refer rails/rails@52e050e
- Apply RuboCop auto correct
Copy link
Contributor

@deivid-rodriguez deivid-rodriguez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit weird to me that the templates crate a Gemfile on the fly instead of using bundler/inline or using a real persisted Gemfile. But this PR only moves them inside the repo without touching them, which is a good move in itself 👍

@yahonda
Copy link
Contributor Author

yahonda commented Dec 31, 2020

Thanks for the review. Let me try require "bundler/inline" .

@yahonda
Copy link
Contributor Author

yahonda commented Jan 1, 2021

Using "require 'bundler/inline'" gets "`instantiate_object_mapper': Unsupported adapter (RuntimeError)".

def self.instantiate_object_mapper
if defined?(::ActiveRecord::Base)
ActiveRecordAdapter.new
elsif defined?(::Mongoid)
MongoidAdapter.new
else
raise "Unsupported adapter"
end
end

I expected ::ActiveRecord::Base is defined by gem 'rails', github: 'rails/rails', branch: '6-1-stable' but actually it is not.
Please advise.

$ ruby -v
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
$ bundler -v
Bundler version 2.2.3
$ more bug_report_templates/test-ransacker-arel-present-predicate.rb
# test-ransacker-arel-present-predicate.rb

# Run it in your console with: `ruby test-ransacker-arel-present-predicate.rb`

require 'bundler/inline'

gemfile(true) do
  source 'https://rubygems.org'

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  # Rails master
  gem 'rails', github: 'rails/rails', branch: '6-1-stable'

  # Rails last release
  # gem 'rails'

  gem 'sqlite3'
  gem 'ransack', github: 'activerecord-hackery/ransack'
end

require 'active_record'
require 'minitest/autorun'
require 'logger'
require 'ransack'

# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)

# Display versions.
message = "Running test case with Ruby #{RUBY_VERSION}, Active Record #{
  ::ActiveRecord::VERSION::STRING}, Arel #{Arel::VERSION} and #{
  ::ActiveRecord::Base.connection.adapter_name}"
line = '=' * message.length
puts line, message, line

ActiveRecord::Schema.define do
  create_table :projects, force: true do |t|
    t.string :name
    t.string :number
  end
end

class Project < ActiveRecord::Base
  ransacker :name do
    Arel.sql('projects.name')
  end

  ransacker :number do |parent|
    parent.table[:number]
  end
end

class BugTest < Minitest::Test
  def test_ransackers
    sql = Project.ransack({ number_present: 1 }).result.to_sql
    puts sql
    assert_equal "SELECT \"projects\".* FROM \"projects\" WHERE (\"projects\".\"number\" IS NOT NULL AND \"projects\".\"number\" != '')", sql

    sql = Project.ransack({ name_present: 1 }).result.to_sql
    puts sql
    assert_equal "SELECT \"projects\".* FROM \"projects\" WHERE (projects.name IS NOT NULL AND projects.name != '')", sql
  end
end
$ ruby bug_report_templates/test-ransacker-arel-present-predicate.rb
Fetching https://github.com/rails/rails.git
Fetching https://github.com/activerecord-hackery/ransack.git
Fetching gem metadata from https://rubygems.org/......
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/............
Resolving dependencies...
Using rake 13.0.3
Using minitest 5.14.2
Using zeitwerk 2.4.2
Using builder 3.2.4
Using erubi 1.10.0
Using mini_portile2 2.4.0
Using crass 1.0.6
Using rack 2.2.3
Using sqlite3 1.4.2
Using nio4r 2.5.4
Using rack-test 1.1.0
Using mimemagic 0.3.5
Using bundler 2.2.3
Using method_source 1.0.0
Using thor 1.0.1
Using concurrent-ruby 1.1.7
Using nokogiri 1.10.10
Using i18n 1.8.5
Using tzinfo 2.0.4
Using sprockets 4.0.2
Using websocket-extensions 0.1.5
Using activesupport 6.1.0 from https://github.com/rails/rails.git (at 6-1-stable@91fe488)
Using mini_mime 1.0.2
Using rails-dom-testing 2.0.3
Using websocket-driver 0.7.3
Using globalid 0.4.2
Using marcel 0.3.3
Using activejob 6.1.0 from https://github.com/rails/rails.git (at 6-1-stable@91fe488)
Using activemodel 6.1.0 from https://github.com/rails/rails.git (at 6-1-stable@91fe488)
Using mail 2.7.1
Using activerecord 6.1.0 from https://github.com/rails/rails.git (at 6-1-stable@91fe488)
Using loofah 2.8.0
Using ransack 2.4.1 from https://github.com/activerecord-hackery/ransack.git (at master@9d336ce)
Using rails-html-sanitizer 1.3.0
Using actionview 6.1.0 from https://github.com/rails/rails.git (at 6-1-stable@91fe488)
Using actionpack 6.1.0 from https://github.com/rails/rails.git (at 6-1-stable@91fe488)
Using actioncable 6.1.0 from https://github.com/rails/rails.git (at 6-1-stable@91fe488)
Using activestorage 6.1.0 from https://github.com/rails/rails.git (at 6-1-stable@91fe488)
Using actionmailer 6.1.0 from https://github.com/rails/rails.git (at 6-1-stable@91fe488)
Using railties 6.1.0 from https://github.com/rails/rails.git (at 6-1-stable@91fe488)
Using actionmailbox 6.1.0 from https://github.com/rails/rails.git (at 6-1-stable@91fe488)
Using sprockets-rails 3.2.2
Using actiontext 6.1.0 from https://github.com/rails/rails.git (at 6-1-stable@91fe488)
Using rails 6.1.0 from https://github.com/rails/rails.git (at 6-1-stable@91fe488)
/home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:69:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'ransack'. (Bundler::GemRequireError)
Gem Load Error is: Unsupported adapter
Backtrace for gem load error is:
/home/yahonda/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/bundler/gems/ransack-9d336ced99d9/lib/ransack/adapters.rb:14:in `instantiate_object_mapper'
/home/yahonda/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/bundler/gems/ransack-9d336ced99d9/lib/ransack/adapters.rb:5:in `object_mapper'
/home/yahonda/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/bundler/gems/ransack-9d336ced99d9/lib/ransack.rb:6:in `<top (required)>'
/home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:66:in `require'
/home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:66:in `block (2 levels) in require'
/home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:61:in `each'
/home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:61:in `block in require'
/home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:50:in `each'
/home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:50:in `require'
/home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/inline.rb:70:in `block in gemfile'
/home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/settings.rb:115:in `temporary'
/home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/inline.rb:54:in `gemfile'
bug_report_templates/test-ransacker-arel-present-predicate.rb:7:in `<main>'
Bundler Error Backtrace:
	from /home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:65:in `block (2 levels) in require'
	from /home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:61:in `each'
	from /home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:61:in `block in require'
	from /home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:50:in `each'
	from /home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:50:in `require'
	from /home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/inline.rb:70:in `block in gemfile'
	from /home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/settings.rb:115:in `temporary'
	from /home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/inline.rb:54:in `gemfile'
	from bug_report_templates/test-ransacker-arel-present-predicate.rb:7:in `<main>'
/home/yahonda/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/bundler/gems/ransack-9d336ced99d9/lib/ransack/adapters.rb:14:in `instantiate_object_mapper': Unsupported adapter (RuntimeError)
	from /home/yahonda/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/bundler/gems/ransack-9d336ced99d9/lib/ransack/adapters.rb:5:in `object_mapper'
	from /home/yahonda/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/bundler/gems/ransack-9d336ced99d9/lib/ransack.rb:6:in `<top (required)>'
	from /home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:66:in `require'
	from /home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:66:in `block (2 levels) in require'
	from /home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:61:in `each'
	from /home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:61:in `block in require'
	from /home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:50:in `each'
	from /home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/runtime.rb:50:in `require'
	from /home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/inline.rb:70:in `block in gemfile'
	from /home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/settings.rb:115:in `temporary'
	from /home/yahonda/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/inline.rb:54:in `gemfile'
	from bug_report_templates/test-ransacker-arel-present-predicate.rb:7:in `<main>'
$

@scarroll32
Copy link
Member

Thanks for your contribution @yahonda !

@scarroll32 scarroll32 merged commit 06421f7 into activerecord-hackery:master Jan 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants