Skip to content

Instantly share code, notes, and snippets.

@klyonrad
Last active August 18, 2020 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klyonrad/87eb3f34f9c3e3b66fdd73f86cf04ccc to your computer and use it in GitHub Desktop.
Save klyonrad/87eb3f34f9c3e3b66fdd73f86cf04ccc to your computer and use it in GitHub Desktop.
Bug report for ransack with attribute name open
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
gem "rails", '~> 5.2'
# Activate the gem you are reporting the issue against.
gem "sqlite3"
gem 'hamlit'
gem 'discard' # loading/requiring ransack fails without this. No idea why.
gem 'draper', '3.1.0'
gem 'ransack'
end
require "active_record"
require "rack/test"
require "action_controller/railtie"
class TestApp < Rails::Application
config.root = __dir__
# config.hosts << "example.org"
config.session_store :cookie_store, key: "cookie_store_key"
secrets.secret_key_base = "secret_key_base"
config.logger = Logger.new($stdout)
Rails.logger = config.logger
routes.draw do
resources :comments
end
end
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :comments, force: true do |t|
t.string :open, default: 'false'
t.string :author_name
end
end
class Comment < ActiveRecord::Base
include Draper::Decoratable
end
class CommentDecorator < Draper::Decorator
delegate_all
end
class CommentsController < ActionController::Base
include Rails.application.routes.url_helpers
include Draper::DecoratesAssigned # grrr not working
# decorates_assigned :comment
def index
render plain: "Home"
end
def edit
@comment = Comment.find(params[:id]).decorate
template = <<ERB
<%= form_for(@comment) do |f| %>
<%= f.text_field :open %>
<% end %>
ERB
render inline: template, layout: false
end
end
require "minitest/autorun"
class BugTest < Minitest::Test
include Rack::Test::Methods
def test_smoke
get "/comments"
assert last_response.ok?
end
def test_returns_success
comment = Comment.create!(open: 'true')
get "/comments/#{comment.id}/edit"
assert last_response.ok?
end
private
def app
Rails.application
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment