spec_helper.rb
2.05 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
89
90
91
92
93
94
95
96
97
98
require 'debugger'
require 'database_cleaner'
require 'rubygems'
require "active_record"
require 'active_support'
require 'sqlite3'
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'rails'))
require "init"
require "rails/railtie"
module Rails
def self.env
@_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development")
end
end
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
# ActiveRecord::Base.configurations = true
# ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.verbose = false
ActiveRecord::Schema.define do
create_table "users", :force => true do |t|
t.column "name", :text
t.column "account_id", :integer
end
create_table "people", :force => true do |t|
t.column "name", :text
end
create_table "accounts", :force => true do |t|
t.column "name", :text
end
create_table "products", :force => true do |t|
t.column "name", :text
t.column "account_id", :integer
end
require_relative '../lib/generators/has_magic_fields/install/templates/migration'
AddHasMagicFieldsTables.new.change
end
RSpec.configure do |config|
config.before(:all) do
class Account < ActiveRecord::Base
include HasMagicFields::Extend
has_many :users
has_magic_fields
end
class Person < ActiveRecord::Base
include HasMagicFields::Extend
has_magic_fields
end
class User < ActiveRecord::Base
include HasMagicFields::Extend
belongs_to :account
has_magic_fields :through => :account
end
class Product < ActiveRecord::Base
include HasMagicFields::Extend
belongs_to :account
has_magic_fields :through => :account
end
end
config.after(:all) do
end
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.around(:each) do |example|
DatabaseCleaner.cleaning do
example.run
end
end
end