Skip to content

Instantly share code, notes, and snippets.

@marcalc
Last active July 6, 2016 21:34
Show Gist options
  • Save marcalc/cc2f5b018498e6c44e12df0523dc3b9d to your computer and use it in GitHub Desktop.
Save marcalc/cc2f5b018498e6c44e12df0523dc3b9d to your computer and use it in GitHub Desktop.
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'
# Activate the gem you are reporting the issue against.
gem 'minitest'
gem 'activerecord', '3.2.22'
gem 'sqlite3'
end
require 'active_record'
require 'minitest/autorun'
require 'logger'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
# 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 "roles", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "user_roles", force: :cascade do |t|
t.integer "user_id"
t.integer "role_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "users", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end
class Role < ActiveRecord::Base
validates_presence_of :name
end
class User < ActiveRecord::Base
has_many :user_roles
has_many :roles, through: :user_roles, validate: false
end
class UserRole < ActiveRecord::Base
belongs_to :user
belongs_to :role
end
class BugTest < Minitest::Test
def test_association_stuff
Role.new(name: nil).save(validate: false) # deliberately creating an invalid nameless role
u = User.create!(role_ids: ["1"]) # OK
u.update_attributes(role_ids: nil) # OK
u.update_attributes(role_ids: ["1"]) # OK
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment