-
Notifications
You must be signed in to change notification settings - Fork 9
/
test_helper.rb
73 lines (59 loc) · 1.98 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/unit'
require 'logger'
require 'bundler'
Bundler.setup
Bundler.require
Paperclip.configure
Paperclip::Railtie.insert
class User < ActiveRecord::Base
has_attached_file :avatar,
:path => File.dirname(__FILE__) + "/avatars/:id_partition/:attachment/:style.:extension",
:url => "/users/:id.:extension"
encode_attachment_in_xml :avatar
has_attached_file :avatar_remote,
:path => File.dirname(__FILE__) + "/avatars/:id_partition/:attachment/:style.:extension",
:url => "/users/:id.:extension"
encode_attachment_in_xml :avatar_remote, :send_urls => true, :root_url => "http://localhost/"
end
module Api
class User < ActiveResource::Base
self.site = "http://localhost/"
has_encoded_attachment :avatar
has_encoded_attachment :avatar_remote
schema do
string "name"
end
end
end
class ActiveSupport::TestCase
def self.load_schema
config = YAML::load(IO.read(File.dirname(__FILE__) + '/config/database.yml'))
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/log/debug.log")
db_adapter = ENV['DB']
# no db passed, try one of these fine config-free DBs before bombing.
db_adapter ||=
begin
require 'rubygems'
require 'sqlite'
'sqlite'
rescue MissingSourceFile
begin
require 'sqlite3'
'sqlite3'
rescue MissingSourceFile
end
end
if db_adapter.nil?
raise "No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3."
end
ActiveRecord::Base.establish_connection(config[db_adapter])
load(File.dirname(__FILE__) + "/config/schema.rb")
end
def self.user_with_encoded_files
User.encode_attachment_in_xml :avatar
end
def self.user_urls
User.encode_attachment_in_xml :avatar, :send_urls => true, :root_url => "http://localhost/"
end
end