diff --git a/test/acts_as_archival_test.rb b/test/acts_as_archival_test.rb index f002e6f..087445d 100644 --- a/test/acts_as_archival_test.rb +++ b/test/acts_as_archival_test.rb @@ -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") diff --git a/test/associations_test.rb b/test/associations_test.rb new file mode 100644 index 0000000..89721bc --- /dev/null +++ b/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 diff --git a/test/fixtures/archival.rb b/test/fixtures/archival.rb index 192780a..2d90ec2 100644 --- a/test/fixtures/archival.rb +++ b/test/fixtures/archival.rb @@ -3,4 +3,6 @@ # archived_at - datetime class Archival < ActiveRecord::Base acts_as_archival + + has_many :kids, :dependent => :destroy end diff --git a/test/fixtures/kid.rb b/test/fixtures/kid.rb new file mode 100644 index 0000000..45c1724 --- /dev/null +++ b/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 diff --git a/test/schema.rb b/test/schema.rb index 40c0267..e9759b9 100644 --- a/test/schema.rb +++ b/test/schema.rb @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index cfd2c44..c3db954 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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