Last active
July 6, 2016 21:34
-
-
Save marcalc/cc2f5b018498e6c44e12df0523dc3b9d to your computer and use it in GitHub Desktop.
Revisions
-
marcalc revised this gist
Jul 6, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -51,7 +51,7 @@ class Role < ActiveRecord::Base end class User < ActiveRecord::Base has_many :user_roles has_many :roles, through: :user_roles, validate: false end -
marcalc created this gist
Jul 6, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,71 @@ 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, validate: false 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