Skip to content

Commit

Permalink
[#1251] Delete ResourceViews when purging their Resource
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorbaptista committed May 7, 2014
1 parent 7a101cb commit 6b50e02
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
@@ -0,0 +1,10 @@
def upgrade(migrate_engine):
migrate_engine.execute('''
ALTER TABLE resource_view
DROP CONSTRAINT resource_view_resource_id_fkey;
ALTER TABLE resource_view
ADD CONSTRAINT resource_view_resource_id_fkey
FOREIGN KEY (resource_id) REFERENCES resource(id)
ON UPDATE CASCADE ON DELETE CASCADE;
''')
9 changes: 9 additions & 0 deletions ckan/new_tests/model/test_resource_view.py
Expand Up @@ -49,3 +49,12 @@ def test_delete_view_type_doesnt_commit(self):

result = ResourceView.get_count_not_in_view_types(['image'])
assert_equals(result, [('webpage', 1)])

def test_purging_resource_removes_its_resource_views(self):
resource_view_dict = factories.ResourceView()
resource = model.Resource.get(resource_view_dict['resource_id'])

resource.purge()
model.repo.commit_and_remove()

assert_equals(ResourceView.get(resource_view_dict['id']), None)

0 comments on commit 6b50e02

Please sign in to comment.