summaryrefslogtreecommitdiff
path: root/help
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2013-11-06 10:55:25 +0100
committerAzul <azul@leap.se>2013-11-06 10:55:25 +0100
commitebc60f3aba1ca08e454ba5e91f49905df2e5fa13 (patch)
tree48eeab39861be9d9f2993e316cf0118071b917a0 /help
parentd620fd42925f1d3d29a66bb61a75bed8c2bdaf8f (diff)
Ticket.destroy_all_from(user) - remove all tickets created by a user
We'll use this to clean up after user destruction
Diffstat (limited to 'help')
-rw-r--r--help/app/models/ticket.rb7
-rw-r--r--help/test/factories.rb4
-rw-r--r--help/test/unit/ticket_test.rb6
3 files changed, 17 insertions, 0 deletions
diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb
index 8066d0d..74f2050 100644
--- a/help/app/models/ticket.rb
+++ b/help/app/models/ticket.rb
@@ -24,6 +24,7 @@ class Ticket < CouchRest::Model::Base
design do
view :by_updated_at
view :by_created_at
+ view :by_created_by
view :by_is_open_and_created_at
view :by_is_open_and_updated_at
@@ -40,6 +41,12 @@ class Ticket < CouchRest::Model::Base
@selection.tickets
end
+ def self.destroy_all_from(user)
+ self.by_created_by.key(user.id).each do |ticket|
+ ticket.destroy
+ end
+ end
+
def is_creator_validated?
!!created_by
end
diff --git a/help/test/factories.rb b/help/test/factories.rb
index 5368ce6..bce3af1 100644
--- a/help/test/factories.rb
+++ b/help/test/factories.rb
@@ -9,6 +9,10 @@ FactoryGirl.define do
{ "0" => { "body" => Faker::Lorem.sentences.join(" ") } }
end
end
+
+ factory :ticket_with_creator do
+ created_by { FactoryGirl.create(:user).id }
+ end
end
end
diff --git a/help/test/unit/ticket_test.rb b/help/test/unit/ticket_test.rb
index 04832d9..6c29d11 100644
--- a/help/test/unit/ticket_test.rb
+++ b/help/test/unit/ticket_test.rb
@@ -39,6 +39,12 @@ class TicketTest < ActiveSupport::TestCase
assert @sample.is_creator_validated?
end
+ test "destroy all tickets from a user" do
+ t = FactoryGirl.create :ticket_with_creator
+ u = t.created_by_user
+ Ticket.destroy_all_from(u)
+ assert_equal nil, Ticket.find(t.id)
+ end
=begin
# TODO: do once have current_user stuff in order
test "code if & only if not creator-validated" do