forked from collectiveidea/audited
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_helper.rb
75 lines (62 loc) · 1.94 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
74
75
ENV["RAILS_ENV"] = "test"
$:.unshift(File.dirname(__FILE__) + '/../lib')
require 'rubygems'
require 'multi_rails_init'
require 'active_record'
require 'active_record/version'
require 'active_record/fixtures'
require 'action_controller'
require 'action_controller/test_process'
require 'action_view'
require 'test/unit'
require 'shoulda'
gem 'jnunemaker-matchy'
require 'matchy'
require File.dirname(__FILE__) + '/../init.rb'
config = YAML::load(IO.read(File.dirname(__FILE__) + '/db/database.yml'))
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite3mem'])
ActiveRecord::Migration.verbose = false
load(File.dirname(__FILE__) + "/db/schema.rb")
class User < ActiveRecord::Base
acts_as_audited :except => :password
attr_protected :logins
def name=(val)
write_attribute(:name, CGI.escapeHTML(val))
end
end
class Company < ActiveRecord::Base
acts_as_audited
end
class OnUpdateDestroy < ActiveRecord::Base
set_table_name 'companies'
acts_as_audited :on => [:update, :destroy]
end
class OnCreateDestroy < ActiveRecord::Base
set_table_name 'companies'
acts_as_audited :on => [:create, :destroy]
end
class OnCreateDestroyExceptName < ActiveRecord::Base
set_table_name 'companies'
acts_as_audited :except => :name, :on => [:create, :destroy]
end
class OnCreateUpdate < ActiveRecord::Base
set_table_name 'companies'
acts_as_audited :on => [:create, :update]
end
class Test::Unit::TestCase
# def change(receiver=nil, message=nil, &block)
# ChangeExpectation.new(self, receiver, message, &block)
# end
def create_user(attrs = {})
User.create({:name => 'Brandon', :username => 'brandon', :password => 'password'}.merge(attrs))
end
def create_versions(n = 2)
returning User.create(:name => 'Foobar 1') do |u|
(n - 1).times do |i|
u.update_attribute :name, "Foobar #{i + 2}"
end
u.reload
end
end
end