-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathtest_helper.rb
More file actions
89 lines (74 loc) · 2.1 KB
/
Copy pathtest_helper.rb
File metadata and controls
89 lines (74 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require "disposable"
require "minitest/autorun"
# require "representable/debug"
# require "pp"
require "declarative/testing"
# Helper method to normalize hash inspect format for cross-Ruby version compatibility
# Ruby 3.4 changed from {:key => value} to {key: value} in inspect output
def normalize_inspect(inspect_string)
inspect_string
.gsub(/" => /, '"=>') # Remove spaces around => for string keys: "key" => value → "key"=>value
.gsub(/([{,\[]\s*)(\w+): /, '\1:\2=>') # Convert symbol keys: {key: value} → {:key=>value} (only after {, [, or ,)
end
require "disposable/twin/coercion"
DRY_TYPES_CONSTANT = Disposable::Twin::Coercion::DRY_TYPES_CONSTANT
DRY_TYPES_INT_CONSTANT = Disposable::Twin::Coercion::DRY_TYPES_VERSION < Gem::Version.new("0.13.0") ? 'Int' : 'Integer'
class Track
def initialize(options={})
@title = options[:title]
end
attr_reader :title
end
# require 'active_record'
# require 'database_cleaner'
# DatabaseCleaner.strategy = :truncation
require 'active_record'
class Artist < ActiveRecord::Base
has_many :albums
end
class Song < ActiveRecord::Base
belongs_to :artist
end
class Album < ActiveRecord::Base
has_many :songs
belongs_to :artist
end
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:database => ":memory:"
)
ActiveRecord::Schema.define do
create_table :artists do |table|
table.column :name, :string
table.timestamps null: false
end
create_table :songs do |table|
table.column :title, :string
table.column :artist_id, :integer
table.column :album_id, :integer
table.timestamps null: false
end
create_table :albums do |table|
table.column :name, :string
table.column :artist_id, :integer
table.timestamps null: false
end
end
module Disposable
module Comparable
def attributes(source)
source.instance_variable_get(:@fields)
end
def ==(other)
self.class == other.class and attributes(self) == attributes(other)
end
end
module Saveable
def save
@saved = true
end
def saved?
defined?(@saved) ? @saved : nil
end
end
end