Skip to content

Instantly share code, notes, and snippets.

@intrip
Last active April 12, 2021 12:59
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 intrip/25665e7b9e759cb021c951ea4d25f28b to your computer and use it in GitHub Desktop.
Save intrip/25665e7b9e759cb021c951ea4d25f28b 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" }
# Activate the gem you are reporting the issue against.
gem "activerecord", "~> 6.1"
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 :countries, force: true do |t|
end
create_table :cities, force: true do |t|
t.references :country
t.string :language
end
end
class Country < ActiveRecord::Base
has_many :cities, dependent: :destroy
accepts_nested_attributes_for :cities
end
class City < ActiveRecord::Base
belongs_to :country
validates :language , uniqueness: true
end
class T < Minitest::Test
def test_case
country = Country.new(cities:[City.new(language: 'en-US'), City.new(language: 'en-US')])
assert_equal false, country.save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment