Commit e9e9a61c authored by jplang's avatar jplang

Time entry queries should be copied and deleted too.

git-svn-id: https://svn.redmine.org/redmine/trunk@16320 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 0f2633d5
......@@ -40,7 +40,7 @@ class Project < ActiveRecord::Base
has_many :versions, :dependent => :destroy
belongs_to :default_version, :class_name => 'Version'
has_many :time_entries, :dependent => :destroy
has_many :queries, :class_name => 'IssueQuery', :dependent => :delete_all
has_many :queries, :dependent => :delete_all
has_many :documents, :dependent => :destroy
has_many :news, lambda {includes(:author)}, :dependent => :destroy
has_many :issue_categories, lambda {order("#{IssueCategory.table_name}.name")}, :dependent => :delete_all
......@@ -1055,12 +1055,12 @@ class Project < ActiveRecord::Base
# Copies queries from +project+
def copy_queries(project)
project.queries.each do |query|
new_query = IssueQuery.new
new_query = query.class.new
new_query.attributes = query.attributes.dup.except("id", "project_id", "sort_criteria", "user_id", "type")
new_query.sort_criteria = query.sort_criteria if query.sort_criteria
new_query.project = self
new_query.user_id = query.user_id
new_query.role_ids = query.role_ids if query.visibility == IssueQuery::VISIBILITY_ROLES
new_query.role_ids = query.role_ids if query.visibility == ::Query::VISIBILITY_ROLES
self.queries << new_query
end
end
......
......@@ -162,4 +162,24 @@ queries_009:
---
- - priority
- desc
queries_010:
id: 10
type: TimeEntryQuery
project_id: 1
visibility: 2
name: My spent time
filters: |
---
user_id:
:values:
- "me"
:operator: =
user_id: 1
column_names:
group_by:
sort_criteria: |
---
- - spent_on
- desc
......@@ -235,17 +235,28 @@ class ProjectCopyTest < ActiveSupport::TestCase
assert_equal [1, 2], member.role_ids.sort
end
test "#copy should copy project specific queries" do
assert @project.valid?
assert @project.queries.empty?
assert @project.copy(@source_project)
def test_copy_should_copy_project_specific_issue_queries
source = Project.generate!
target = Project.new(:name => 'Copy Test', :identifier => 'copy-test')
IssueQuery.generate!(:project => source, :user => User.find(2))
assert target.copy(source)
assert_equal @source_project.queries.size, @project.queries.size
@project.queries.each do |query|
assert query
assert_equal @project, query.project
end
assert_equal @source_project.queries.map(&:user_id).sort, @project.queries.map(&:user_id).sort
assert_equal 1, target.queries.size
query = target.queries.first
assert_kind_of IssueQuery, query
assert_equal 2, query.user_id
end
def test_copy_should_copy_project_specific_time_entry_queries
source = Project.generate!
target = Project.new(:name => 'Copy Test', :identifier => 'copy-test')
TimeEntryQuery.generate!(:project => source, :user => User.find(2))
assert target.copy(source)
assert_equal 1, target.queries.size
query = target.queries.first
assert_kind_of TimeEntryQuery, query
assert_equal 2, query.user_id
end
def test_copy_should_copy_queries_roles_visibility
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment