Don't like to add extra models/tables/fixtures, use existing those
This commit is contained in:
parent
1508246851
commit
d240f6238c
|
@ -35,7 +35,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def timestamp_column_names
|
||||
ModelMetadata.new(@association.through_reflection.klass).timestamp_column_names
|
||||
@association.through_reflection.klass.all_timestamp_attributes_in_model
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -19,8 +19,6 @@ require "models/developer"
|
|||
require "models/dog"
|
||||
require "models/doubloon"
|
||||
require "models/joke"
|
||||
require "models/loot"
|
||||
require "models/loot_parrot"
|
||||
require "models/matey"
|
||||
require "models/other_dog"
|
||||
require "models/parrot"
|
||||
|
@ -1103,8 +1101,7 @@ class FoxyFixturesTest < ActiveRecord::TestCase
|
|||
# Set to false to blow away fixtures cache and ensure our fixtures are loaded
|
||||
self.use_transactional_tests = false
|
||||
fixtures :parrots, :parrots_pirates, :pirates, :treasures, :mateys, :ships, :computers,
|
||||
:developers, :"admin/accounts", :"admin/users", :live_parrots, :dead_parrots, :books,
|
||||
:loots
|
||||
:developers, :"admin/accounts", :"admin/users", :live_parrots, :dead_parrots, :books
|
||||
|
||||
if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
|
||||
require "models/uuid_parent"
|
||||
|
@ -1193,11 +1190,15 @@ class FoxyFixturesTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_supports_timestamps_in_join_tables
|
||||
assert_not_nil parrots(:looter).created_at
|
||||
assert_not_nil loots(:bounty).created_at
|
||||
assert_equal loots(:bounty), parrots(:looter).loots.first
|
||||
assert_equal loots(:bounty), parrots(:looter).loot_parrots.first.loot
|
||||
assert_not_nil parrots(:looter).loot_parrots.first.created_at
|
||||
assert_not_nil developers(:david).created_at
|
||||
assert_not_nil computers(:laptop).created_at
|
||||
|
||||
klass = Class.new(ActiveRecord::Base) do
|
||||
self.table_name = "computers_developers"
|
||||
end
|
||||
|
||||
computers_developers = klass.find_by(developer_id: developers(:david), computer_id: computers(:laptop))
|
||||
assert_not_nil computers_developers.created_at
|
||||
end
|
||||
|
||||
def test_supports_inline_habtm
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
bounty:
|
||||
value: 123.45
|
|
@ -25,9 +25,6 @@ polly:
|
|||
treasures: sapphire, ruby
|
||||
<<: *DEAD_PARROT
|
||||
|
||||
looter:
|
||||
loots: bounty
|
||||
|
||||
DEFAULTS: &DEFAULTS
|
||||
treasures: sapphire, ruby
|
||||
parrot_sti_class: LiveParrot
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Loot < ActiveRecord::Base
|
||||
has_many :loot_parrots, class_name: "LootParrot"
|
||||
has_many :parrots, through: :loot_parrots
|
||||
end
|
|
@ -1,6 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class LootParrot < ActiveRecord::Base
|
||||
belongs_to :parrot
|
||||
belongs_to :loot
|
||||
end
|
|
@ -5,8 +5,7 @@ class Parrot < ActiveRecord::Base
|
|||
|
||||
has_and_belongs_to_many :pirates
|
||||
has_and_belongs_to_many :treasures
|
||||
has_many :loot_parrots, class_name: "LootParrot"
|
||||
has_many :loots, through: :loot_parrots
|
||||
has_many :loots, as: :looter, class_name: "Treasure"
|
||||
alias_attribute :title, :name
|
||||
|
||||
validates_presence_of :name
|
||||
|
|
|
@ -267,11 +267,13 @@ ActiveRecord::Schema.define do
|
|||
t.integer :developer, null: false
|
||||
t.integer :extendedWarranty, null: false
|
||||
t.integer :timezone
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :computers_developers, id: false, force: true do |t|
|
||||
t.references :computer
|
||||
t.references :developer
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :contracts, force: true do |t|
|
||||
|
@ -562,17 +564,6 @@ ActiveRecord::Schema.define do
|
|||
t.timestamps null: true
|
||||
end
|
||||
|
||||
create_table :loots, force: true do |t|
|
||||
t.float :value
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :loot_parrots, force: true do |t|
|
||||
t.references :loot, null: false
|
||||
t.references :parrot, null: false
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :magazines, force: true do |t|
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue