diff options
author | Marius Balteanu <marius.balteanu@zitec.com> | 2024-11-23 11:17:54 +0000 |
---|---|---|
committer | Marius Balteanu <marius.balteanu@zitec.com> | 2024-11-23 11:17:54 +0000 |
commit | db0ac01d3d3177bb0c9b03d0a9e2ec120f701921 (patch) | |
tree | 0aea8ec326310432590dd2c5736bfd1fece18769 | |
parent | 7579df28c0e3c15155547d47f2ac01e817a299d3 (diff) | |
download | redmine-db0ac01d3d3177bb0c9b03d0a9e2ec120f701921.tar.gz redmine-db0ac01d3d3177bb0c9b03d0a9e2ec120f701921.zip |
Fixes project query scope that does not take into account limit and offset options (#41791).
git-svn-id: https://svn.redmine.org/redmine/trunk@23300 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/project_query.rb | 4 | ||||
-rw-r--r-- | test/unit/project_query_test.rb | 14 |
2 files changed, 17 insertions, 1 deletions
diff --git a/app/models/project_query.rb b/app/models/project_query.rb index 6defbcc83..726721bd8 100644 --- a/app/models/project_query.rb +++ b/app/models/project_query.rb @@ -156,7 +156,9 @@ class ProjectQuery < Query order_option << "#{Project.table_name}.lft ASC" scope = base_scope. order(order_option). - joins(joins_for_order_statement(order_option.join(','))) + joins(joins_for_order_statement(order_option.join(','))). + limit(options[:limit]). + offset(options[:offset]) if has_custom_field_column? scope = scope.preload(:custom_values) diff --git a/test/unit/project_query_test.rb b/test/unit/project_query_test.rb index 360bc08b7..156949ea8 100644 --- a/test/unit/project_query_test.rb +++ b/test/unit/project_query_test.rb @@ -162,4 +162,18 @@ class ProjectQueryTest < ActiveSupport::TestCase assert_not_nil last_activitiy_date assert_equal Redmine::Activity::Fetcher.new(User.current).events(nil, nil, :project => Project.find(1)).first.updated_on, last_activitiy_date end + + def test_results_scope_with_offset_and_limit + q = ProjectQuery.new + + ((q.results_scope.count / 2) + 1).times do |i| + limit = 2 + offset = i * 2 + + scope_without = q.results_scope.offset(offset).limit(limit).ids + scope_with = q.results_scope(:offset => offset, :limit => limit).ids + + assert_equal scope_without, scope_with + end + end end |