Skip to content

Commit

Permalink
Adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Elad Meidar committed Nov 11, 2009
1 parent 584ad9d commit 07f5d43
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 5 deletions.
1 change: 0 additions & 1 deletion lib/indexer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Indexer


def self.sortalize(array)
Marshal.load(Marshal.dump(array)).each do |element|
element.sort! if element.is_a?(Array)
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/app/models/address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Address < ActiveRecord::Base
belongs_to :addressable, :polymorphic => true
belongs_to :user
belongs_to :company
end
10 changes: 10 additions & 0 deletions test/fixtures/app/models/company.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Company < ActiveRecord::Base

belongs_to :owner, :foreign_key => 'owner_id', :class_name => 'User'

has_one :address, :as => :addressable

has_many :users

has_and_belongs_to_many :freelancers
end
3 changes: 3 additions & 0 deletions test/fixtures/app/models/freelancer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Freelancer < ActiveRecord::Base
has_and_belongs_to_many :companies
end
7 changes: 7 additions & 0 deletions test/fixtures/app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class User < ActiveRecord::Base
belongs_to :company

has_one :company, :foreign_key => 'owner_id'
has_one :address, :as => :addressable

end
28 changes: 28 additions & 0 deletions test/fixtures/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
ActiveRecord::Schema.define do
create_table "users", :force => true do |t|
t.column "company_id", :integer
t.column "name", :text
t.column "email", :text
end

create_table "companies", :force => true do |t|
t.column "name", :text
t.column "owned_id", :integer
end

create_table "addresses", :force => true do |t|
t.column "addressable_type", :string
t.column "addressable_id", :integer
t.column "address", :text
end

create_table "freelancers", :force => true do |t|
t.column "name", :string
t.column "price_per_hour", :integer
end

create_table "companies_freelancers", :force => true do |t|
t.column "freelancer_id", :integer
t.column "company_id", :integer
end
end
6 changes: 3 additions & 3 deletions test/rails_indexes_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'test_helper'

class RailsIndexesTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true

test "fail dammit" do
assert_equal 1,4
end
end
22 changes: 21 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
require 'rubygems'
require 'activerecord'
require 'active_record/fixtures'
require 'active_support'
require 'active_support/test_case'
require 'active_support/test_case'
require 'action_controller'

require 'indexer'

ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:database => ":memory:"
)

load 'test/fixtures/schema.rb'

# Load models
Dir['test/fixtures/app/models/**/*.rb'].each { |f| require f }

# load controllers
Dir['test/fixtures/app/controllers/**/*.rb'].each { |f| require f }

puts "Done!"

0 comments on commit 07f5d43

Please sign in to comment.