Skip to content

Commit

Permalink
Refine test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
nragaz committed May 25, 2010
1 parent e1e25f9 commit 0057506
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 53 deletions.
10 changes: 10 additions & 0 deletions test/active_record_test.rb
@@ -0,0 +1,10 @@
require 'test_helper'

class ActiveRecordTest < ActiveSupport::TestCase
load_schema

test "create user without exception" do
assert_nothing_raised { User.new(:name => 'John Doe') }
end

end
9 changes: 9 additions & 0 deletions test/active_resource_test.rb
@@ -0,0 +1,9 @@
require 'test_helper'

class ActiveResourceTest < ActiveSupport::TestCase
load_schema

test "create user resource without exception" do
assert_nothing_raised { Api::User.new(:name => 'John Doe') }
end
end
Empty file added test/avatars/.gitignore
Empty file.
File renamed without changes.
File renamed without changes.
31 changes: 0 additions & 31 deletions test/encoded_attachment_test.rb

This file was deleted.

65 changes: 43 additions & 22 deletions test/test_helper.rb
Expand Up @@ -11,30 +11,51 @@

require (File.dirname(__FILE__) + '/../init.rb')

def load_schema
config = YAML::load(IO.read(File.dirname(__FILE__) + '/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
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
end

module Api
class User < ActiveResource::Base
self.site = "http://localhost:3000"

has_encoded_attachment :avatar

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 'sqlite3'
'sqlite3'
require 'rubygems'
require 'sqlite'
'sqlite'
rescue MissingSourceFile
begin
require 'sqlite3'
'sqlite3'
rescue MissingSourceFile
end
end
end

if db_adapter.nil?
raise "No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3."
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__) + "/schema.rb")
end
ActiveRecord::Base.establish_connection(config[db_adapter])
load(File.dirname(__FILE__) + "/config/schema.rb")
end
end

0 comments on commit 0057506

Please sign in to comment.