forked from ryanb/complex-form-examples
-
Notifications
You must be signed in to change notification settings - Fork 28
/
test_helper.rb
73 lines (57 loc) · 1.59 KB
/
test_helper.rb
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
require 'rubygems'
require 'test/spec'
require 'mocha'
require 'activerecord'
$: << File.expand_path('../../lib', __FILE__)
require 'nested_params'
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
ActiveRecord::Migration.verbose = false
# ActiveRecord::Base.logger = Logger.new($stdout)
# ActiveRecord::Base.logger.level = Logger::DEBUG
def setup_db
ActiveRecord::Schema.define(:version => 1) do
create_table :members do |t|
t.column :email, :string
t.column :address, :string
end
create_table :visitors do |t|
t.column :email, :string
t.column :address, :string
end
create_table :artists do |t|
t.integer :member_id
t.integer :visitor_id
t.string :name
end
create_table :avatars do |t|
t.integer :member_id
t.integer :visitor_id
t.string :name
end
end
end
def teardown_db
ActiveRecord::Base.connection.tables.each do |table|
ActiveRecord::Base.connection.drop_table(table)
end
end
class Member < ActiveRecord::Base
extend NestedParams
has_one :artist, :nested_params => true
extend AutosaveAssociation
has_one :avatar, :autosave => true
end
class Visitor < ActiveRecord::Base
extend NestedParams
has_many :artists, :nested_params => true, :destroy_missing => true, :reject_empty => true
extend AutosaveAssociation
has_many :avatars, :autosave => true
end
class Artist < ActiveRecord::Base
belongs_to :member
validates_presence_of :name
end
class Avatar < ActiveRecord::Base
belongs_to :member
validates_presence_of :name
end