Skip to content

Commit

Permalink
Remove fixture integration
Browse files Browse the repository at this point in the history
With the progress we've made via the top-level model grouping I don't think we need to have this backwards compatibility.
  • Loading branch information
kaspth committed Sep 7, 2023
1 parent 7b5bc58 commit 8e9b6c9
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 19 deletions.
10 changes: 4 additions & 6 deletions lib/oaken.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions test/fixtures/yaml_records.yml

This file was deleted.

5 changes: 0 additions & 5 deletions test/oaken_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8e9b6c9

Please sign in to comment.