From 8e9b6c9ccc5e2d8218489a28c307a892dceeca3a Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Thu, 7 Sep 2023 16:26:36 +0200 Subject: [PATCH] Remove fixture integration With the progress we've made via the top-level model grouping I don't think we need to have this backwards compatibility. --- lib/oaken.rb | 10 ++++------ test/fixtures/yaml_records.yml | 3 --- test/oaken_test.rb | 5 ----- test/test_helper.rb | 5 ----- 4 files changed, 4 insertions(+), 19 deletions(-) delete mode 100644 test/fixtures/yaml_records.yml diff --git a/lib/oaken.rb b/lib/oaken.rb index 495b325..32a51e3 100644 --- a/lib/oaken.rb +++ b/lib/oaken.rb @@ -69,26 +69,24 @@ def update(id, **attributes) class Stored::ActiveRecord < Stored::Abstract def find(id) - @type.find identify id + @type.find id.hash end def update(id, **attributes) attributes = super - if record = @type.find_by(id: identify(id)) + if record = @type.find_by(id: id.hash) record.tap { _1.update!(**attributes) } else - @type.create!(id: identify(id), **attributes) + @type.create!(id: id.hash, **attributes) end end def upsert(id, **attributes) attributes = super @type.new(attributes).validate! - @type.upsert({ id: identify(id), **attributes }) + @type.upsert({ id: id.hash, **attributes }) end - - private def identify(id) = ::ActiveRecord::FixtureSet.identify(id, @type.type_for_attribute(@type.primary_key).type) end module Data diff --git a/test/fixtures/yaml_records.yml b/test/fixtures/yaml_records.yml deleted file mode 100644 index f0b3ff6..0000000 --- a/test/fixtures/yaml_records.yml +++ /dev/null @@ -1,3 +0,0 @@ -first: - name: "YAML" - account: business diff --git a/test/oaken_test.rb b/test/oaken_test.rb index 4ce128e..fa0c858 100644 --- a/test/oaken_test.rb +++ b/test/oaken_test.rb @@ -24,11 +24,6 @@ def test_helper_methods end end - def test_fixture_yml_compatibility - assert_equal "YAML", YamlRecord.first.name - assert_equal accounts.business, YamlRecord.first.account - end - def test_accessing_fixture assert_equal "Kasper", users.kasper.name assert_equal "Coworker", users.coworker.name diff --git a/test/test_helper.rb b/test/test_helper.rb index eea2412..e278971 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -58,11 +58,6 @@ def self.root() = __dir__ # Needed for the sqlite3 tasks. t.integer :price_cents, null: false t.timestamps end - - create_table :yaml_records, force: true do |t| - t.integer :account_id, null: false - t.string :name, null: false - end end class Account < ActiveRecord::Base