summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-09-13 12:58:14 +0200
committerhukl <contact@smyck.org>2009-09-13 12:58:14 +0200
commit34b4e764ab8b00fa24c9ffead40494acd4c9da6b (patch)
tree21caf1f7fae0dafccd999c38bff4f8ddff734958
parentcaebe56799887c348ab0da380940c93eb15e8d87 (diff)
added :dependent => :destroy to asset model so related assets get deleted as the asset they're referencing is deleted.
Closes #25
-rw-r--r--app/models/asset.rb1
-rw-r--r--test/unit/asset_test.rb21
2 files changed, 19 insertions, 3 deletions
diff --git a/app/models/asset.rb b/app/models/asset.rb
index 41823e7..5bfea76 100644
--- a/app/models/asset.rb
+++ b/app/models/asset.rb
@@ -1,5 +1,6 @@
1class Asset < ActiveRecord::Base 1class Asset < ActiveRecord::Base
2 2
3 has_many :related_assets, :dependent => :destroy
3 has_many :pages, :through => :related_assets 4 has_many :pages, :through => :related_assets
4 5
5 has_attached_file( 6 has_attached_file(
diff --git a/test/unit/asset_test.rb b/test/unit/asset_test.rb
index 58aba76..a1041e4 100644
--- a/test/unit/asset_test.rb
+++ b/test/unit/asset_test.rb
@@ -1,8 +1,23 @@
1require 'test_helper' 1require 'test_helper'
2 2
3class AssetTest < ActiveSupport::TestCase 3class AssetTest < ActiveSupport::TestCase
4 # Replace this with your real tests. 4
5 test "the truth" do 5 test "related assets get destroyed when assets get destroyed" do
6 assert true 6 Asset.delete_all
7 RelatedAsset.delete_all
8
9 assert asset = Asset.create
10 assert node = Node.root.children.create( :slug => "asset" )
11 assert_equal [], node.draft.assets
12
13 draft = node.draft
14 draft.assets << asset
15 assert_equal 1, draft.assets.length
16
17 asset.destroy
18 draft.reload
19 assert_equal 0, draft.assets.length
20 assert_equal 0, RelatedAsset.count
7 end 21 end
22
8end 23end