Skip to content

Commit

Permalink
start working on associations tests refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
janxious committed Mar 3, 2012
1 parent 735b360 commit 38623e4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
10 changes: 0 additions & 10 deletions test/acts_as_archival_test.rb
Expand Up @@ -16,16 +16,6 @@ def setup
@readonly_archived.readonly!
end

test "archive archives 'has_' associated archival objects that are dependent destroy" do
assert @hole.class.is_archival?
assert @hole.muskrats.first.class.is_archival?

@hole.archive

assert @hole.reload.archived?
assert @hole.muskrats(true).first.archived?
end

test "archive does not archive 'has_' associated archival objects that are not dependent destroy" do
@hole.squirrels.create(:name => "Rocky")

Expand Down
12 changes: 12 additions & 0 deletions test/associations_test.rb
@@ -0,0 +1,12 @@
require_relative "test_helper"

class ActsAsArchivalTest < ActiveSupport::TestCase
test "archive archives 'has_' associated archival objects that are dependent destroy" do
archival = Archival.create!
child = archival.kids.create!
archival.archive

assert archival.reload.archived?
assert child.reload.archived?
end
end
2 changes: 2 additions & 0 deletions test/fixtures/archival.rb
Expand Up @@ -3,4 +3,6 @@
# archived_at - datetime
class Archival < ActiveRecord::Base
acts_as_archival

has_many :kids, :dependent => :destroy
end
9 changes: 9 additions & 0 deletions test/fixtures/kid.rb
@@ -0,0 +1,9 @@
# name - string
# archival_id - integer
# archive_number - string
# archived_at - datetime
class Kid < ActiveRecord::Base
acts_as_archival

belongs_to :archival
end
7 changes: 7 additions & 0 deletions test/schema.rb
Expand Up @@ -6,6 +6,13 @@
t.column :archived_at, :datetime
end

create_table :kids, :force => true do |t|
t.column :name, :string
t.column :archival_id, :integer
t.column :archive_number, :string
t.column :archived_at, :datetime
end

create_table :plains, :force => true do |t|
t.column :name, :string
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Expand Up @@ -19,7 +19,7 @@
ActiveRecord::Base.establish_connection(dbconfig)
load(schema_file) if File.exist?(schema_file)

%w(archival plain hole mole muskrat squirrel kitty puppy ship rat orange flea snake beaver tick ixodidae).each do |test_class_file|
%w(archival kid plain hole mole muskrat squirrel kitty puppy ship rat orange flea snake beaver tick ixodidae).each do |test_class_file|
require_relative "fixtures/#{test_class_file}"
end

Expand Down

0 comments on commit 38623e4

Please sign in to comment.