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 characters
# frozen_string_literal: true | |
RSpec.describe FactoryBot do | |
shared_examples_for 'valid definition' do | |
it 'is valid' do | |
is_expected.to be_valid, (-> { factory.errors.full_messages.join("\n") }) | |
end | |
end | |
FactoryBot.factories.map(&:name).each do |factory_name| |
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 characters
# frozen_string_literal: true | |
RSpec.describe 'ActiveRecord i18n' do | |
let(:table_names) { ActiveRecord::Base.connection.tables } | |
let(:models) do | |
table_names.map do |table_name| | |
table_to_model(table_name) | |
rescue NameError | |
nil |
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 characters
# frozen_string_literal: true | |
RSpec.describe 'rake db:seed' do | |
it 'works fine' do | |
expect { load('db/seeds.rb') }.to_not raise_error | |
end | |
end |
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 characters
# frozen_string_literal: true | |
RSpec.describe 'ActiveRecord duplicated indexes' do | |
let(:connection) do | |
ActiveRecord::Base.connection | |
end | |
it 'is not found' do | |
tables = connection.tables | |
duplicated_indexes = {} |
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 characters
# frozen_string_literal: true | |
RSpec.describe 'ActiveRecord foreign key' do | |
let(:connection) { ActiveRecord::Base.connection } | |
let(:tables) { connection.tables } | |
def foreign_key_exists?(reflection, foreign_keys) | |
to_table_name = reflection.klass.table_name | |
reflection.foreign_key |
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 characters
# frozen_string_literal: true | |
RSpec.describe 'ActiveRecord associations' do | |
let(:connection) { ActiveRecord::Base.connection } | |
let(:table_names) { connection.tables } | |
let(:models) { table_names.map { table_to_model(_1) } } | |
# テスト対象から除外する関連を定義 | |
let(:ignored_reflections) do | |
# { table_names => [association_name, ...] } |
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 characters
https://github.com/kufu/activerecord-bitemporal/pull/70/files#diff-77aac43b146505859dd74b1fd3e151c0e94174f5abc85475fe1dfba10a5c64bfL330 | |
git clone https://github.com/kufu/activerecord-bitemporal | |
hub checkout https://github.com/kufu/activerecord-bitemporal/pull/70 | |
# L330をObjectに戻す | |
vi lib/activerecord-bitemporal/bitemporal.rb | |
rbenv local 3.0.0 | |
bundle i --path .bundle |
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 characters
# 指定したレコードの関連の探索処理 | |
# | |
# @example | |
# depth_query = ActiveRecordDepthQuery.new(employee, [attendance: :attendance_records]) | |
# depth_query.each do |relation| | |
# relation.to_a #=> 1度目は従業員に紐づくAttendanceの一覧、2度目はAttendanceRecordの一覧が返ってくる | |
# end | |
class ActiveRecordDepthQuery | |
include Enumerable |
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 characters
# frozen_string_literal: true | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
gem "rails", '~> 6.1.0' |
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 characters
# frozen_string_literal: true | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
gem "rails", '~> 6.0.0' |