Skip to content

Instantly share code, notes, and snippets.

@utilum
Last active April 26, 2018 18:03
Show Gist options
  • Save utilum/a1800fd431ae8d560d34c255020f95fa to your computer and use it in GitHub Desktop.
Save utilum/a1800fd431ae8d560d34c255020f95fa to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails"
gem "sqlite3"
end
require "active_record"
require "minitest/autorun"
require "logger"
# 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 :posts, force: true do |t|
t.string :column
t.string :ignored
end
end
class Post < ActiveRecord::Base
self.ignored_columns = [:ignored]
end
class BugTest < Minitest::Test
def test_ignored
assert_equal ['ignored'], Post.ignored_columns
end
def test_attributes
assert_raises ActiveModel::UnknownAttributeError,
post = Post.create!(column: 'value', ignored: 'another value')
expected_attributes = {
'id' => post.id,
'column' => 'value',
'ignored' => 'another value',
}
assert_equal 3, post.attributes.size
assert_equal expected_attributes, post.attributes
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment