From aa8eac7c2a6ec5cdffcabecc5a7de12492928868 Mon Sep 17 00:00:00 2001 From: Alex Coles Date: Mon, 29 Jun 2015 18:27:33 +0200 Subject: [PATCH 1/5] Bump Rails dependency to latest 4.1.x Signed-off-by: Alex Coles --- openproject-my_project_page.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openproject-my_project_page.gemspec b/openproject-my_project_page.gemspec index d084052c76..db8cb83e5d 100644 --- a/openproject-my_project_page.gemspec +++ b/openproject-my_project_page.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |s| s.files = Dir["{app,config,db,lib}/**/*", "README.md"] s.test_files = Dir["spec/**/*"] - s.add_dependency 'rails', '~> 4.0.13' + s.add_dependency 'rails', '~> 4.1.11' s.add_development_dependency "factory_girl_rails", "~> 4.0" From c31caa5ebad1d17c31cb5e51e62ac2132f286533 Mon Sep 17 00:00:00 2001 From: Alex Coles Date: Sat, 29 Aug 2015 12:44:21 +0200 Subject: [PATCH 2/5] Migrate obsolete AR finder/query methods Signed-off-by: Alex Coles --- .../my_projects_overviews_controller.rb | 38 ++++++++++--------- .../selected_widgets_steps.rb | 2 +- spec/models/my_projects_overview_spec.rb | 2 +- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/app/controllers/my_projects_overviews_controller.rb b/app/controllers/my_projects_overviews_controller.rb index f4e044d909..f1de8e6205 100644 --- a/app/controllers/my_projects_overviews_controller.rb +++ b/app/controllers/my_projects_overviews_controller.rb @@ -161,14 +161,13 @@ class MyProjectsOverviewsController < ApplicationController :object_callback def childprojects - @childprojects ||= project.children.visible.all + @childprojects ||= project.children.visible end def recent_news - @news ||= project.news.all :limit => 5, - :include => [ :author, :project ], - :order => "#{News.table_name}.created_on DESC" - + @news ||= project.news.limit(5) + .includes([:author, :project]) + .order("#{News.table_name}.created_on DESC") end def types @@ -176,24 +175,27 @@ class MyProjectsOverviewsController < ApplicationController end def open_work_packages_by_type - @open_work_packages_by_tracker ||= WorkPackage.visible.count(:group => :type, - :include => [:project, :status, :type], - :conditions => ["(#{subproject_condition}) AND #{Status.table_name}.is_closed=?", false]) + @open_work_packages_by_tracker ||= WorkPackage.visible + .group(:type) + .includes([:project, :status, :type]) + .where(["(#{subproject_condition}) AND #{Status.table_name}.is_closed=?", false]) + .count end def total_work_packages_by_type - @total_work_packages_by_tracker ||= WorkPackage.visible.count(:group => :type, - :include => [:project, :status, :type], - :conditions => subproject_condition) - + @total_work_packages_by_tracker ||= WorkPackage.visible + .group(:type) + .includes([:project, :status, :type]) + .where(subproject_condition) + .count end def assigned_work_packages - @assigned_issues ||= WorkPackage.visible.open.find(:all, - :conditions => { :assigned_to_id => User.current.id }, - :limit => 10, - :include => [ :status, :project, :type, :priority ], - :order => "#{IssuePriority.table_name}.position DESC, #{WorkPackage.table_name}.updated_on DESC") + @assigned_issues ||= WorkPackage.visible.open + .where(assigned_to: User.current.id) + .limit(10) + .includes([:status, :project, :type, :priority]) + .order("#{IssuePriority.table_name}.position DESC, #{WorkPackage.table_name}.updated_on DESC") end def users_by_role(limit = 100) @@ -278,7 +280,7 @@ class MyProjectsOverviewsController < ApplicationController end def overview - @overview ||= MyProjectsOverview.find_or_create_by_project_id(project.id) + @overview ||= MyProjectsOverview.find_or_create_by(project_id: project.id) end def attachments diff --git a/features/step_definitions/selected_widgets_steps.rb b/features/step_definitions/selected_widgets_steps.rb index 3cac54b04a..ec394e03c9 100644 --- a/features/step_definitions/selected_widgets_steps.rb +++ b/features/step_definitions/selected_widgets_steps.rb @@ -20,7 +20,7 @@ Given /^the following widgets are selected for the overview page of the "(.+)" project:$/ do |project_name, table| project = Project.find_by_name(project_name) - page = MyProjectsOverview.find_or_create_by_project_id(project.id) + page = MyProjectsOverview.find_or_create_by(project_id: project.id) blocks = ({ "top" => "", "left" => "", "right" => "", "hidden" => "" }).merge(table.rows_hash) diff --git a/spec/models/my_projects_overview_spec.rb b/spec/models/my_projects_overview_spec.rb index 1fa02bb6d2..6b6731e3b5 100644 --- a/spec/models/my_projects_overview_spec.rb +++ b/spec/models/my_projects_overview_spec.rb @@ -24,7 +24,7 @@ describe MyProjectsOverview, :type => :model do before do @enabled_module_names = %w[activity work_package_tracking news wiki] FactoryGirl.create(:project, :enabled_module_names => @enabled_module_names) - @project = Project.find(:first) + @project = Project.first @overview = MyProjectsOverview.create(:project_id => @project.id) end From 1a4635b8cb7108e7e84f2d10d80c15d7d15b4bda Mon Sep 17 00:00:00 2001 From: Alex Coles Date: Sun, 30 Aug 2015 10:18:35 +0200 Subject: [PATCH 3/5] Migrate obsolete AR finder/query methods in views Signed-off-by: Alex Coles --- .../blocks/_spent_time.html.erb | 8 ++++---- .../blocks/_work_packages_assigned_to_me.html.erb | 12 ++++++------ .../blocks/_work_packages_reported_by_me.html.erb | 12 ++++++------ .../blocks/_work_packages_responsible_for.html.erb | 12 ++++++------ 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/app/views/my_projects_overviews/blocks/_spent_time.html.erb b/app/views/my_projects_overviews/blocks/_spent_time.html.erb index caef89ee74..24f96f2cbc 100644 --- a/app/views/my_projects_overviews/blocks/_spent_time.html.erb +++ b/app/views/my_projects_overviews/blocks/_spent_time.html.erb @@ -26,10 +26,10 @@ See doc/COPYRIGHT.md for more details. <% end %> <% - entries = TimeEntry.find(:all, - :conditions => ["#{TimeEntry.table_name}.user_id = ? AND #{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", @user.id, Date.today - 6, Date.today], - :include => [:activity, :project, {:work_package => [:type, :status]}], - :order => "#{TimeEntry.table_name}.spent_on DESC, #{Project.table_name}.name ASC, #{Type.table_name}.position ASC, #{WorkPackage.table_name}.id ASC") + entries = TimeEntry + .where(["#{TimeEntry.table_name}.user_id = ? AND #{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", @user.id, Date.today - 6, Date.today]) + .includes([:activity, :project, {:work_package => [:type, :status]}]) + .order("#{TimeEntry.table_name}.spent_on DESC, #{Project.table_name}.name ASC, #{Type.table_name}.position ASC, #{WorkPackage.table_name}.id ASC") entries_by_day = entries.group_by(&:spent_on) %> diff --git a/app/views/my_projects_overviews/blocks/_work_packages_assigned_to_me.html.erb b/app/views/my_projects_overviews/blocks/_work_packages_assigned_to_me.html.erb index 3755a84ede..d5e5c24e89 100644 --- a/app/views/my_projects_overviews/blocks/_work_packages_assigned_to_me.html.erb +++ b/app/views/my_projects_overviews/blocks/_work_packages_assigned_to_me.html.erb @@ -19,17 +19,17 @@ See doc/COPYRIGHT.md for more details. ++#%> -

<%=l(:label_work_packages_assigned_to_me)%> (<%= WorkPackage.visible.open.count(:conditions => {:assigned_to_id => User.current.id, :project_id => @project.id})%>)

+

<%=l(:label_work_packages_assigned_to_me)%> (<%= WorkPackage.visible.open.where(assigned_to_id: User.current.id, project_id: @project.id).count %>)

<% if defined? block_name_id %> <%= content_for block_name_id %> <% end %> -<% assigned_work_packages = WorkPackage.visible.open.find(:all, - :conditions => {:assigned_to_id => User.current.id, :project_id => @project.id}, - :limit => 10, - :include => [ :status, :project, :type, :priority ], - :order => "#{IssuePriority.table_name}.position DESC, #{WorkPackage.table_name}.updated_at DESC") %> +<% assigned_work_packages = WorkPackage.visible.open + .where(assigned_to_id: User.current.id, project_id: @project.id) + .limit(10) + .includes([:status, :project, :type, :priority]) + .order("#{IssuePriority.table_name}.position DESC, #{WorkPackage.table_name}.updated_at DESC") %> <%= render :partial => 'work_packages/list_simple', :locals => { :work_packages => assigned_work_packages } %> <% if assigned_work_packages.length > 0 %>

diff --git a/app/views/my_projects_overviews/blocks/_work_packages_reported_by_me.html.erb b/app/views/my_projects_overviews/blocks/_work_packages_reported_by_me.html.erb index d16d614540..5ed02c6750 100644 --- a/app/views/my_projects_overviews/blocks/_work_packages_reported_by_me.html.erb +++ b/app/views/my_projects_overviews/blocks/_work_packages_reported_by_me.html.erb @@ -19,17 +19,17 @@ See doc/COPYRIGHT.md for more details. ++#%> -

<%=l(:label_work_package_view_all_reported_by_me)%> (<%= WorkPackage.visible.count(:conditions => { :author_id => User.current.id, :project_id => @project.id }) %>)

+

<%=l(:label_work_package_view_all_reported_by_me)%> (<%= WorkPackage.visible.where(author_id: User.current.id, project_id: @project.id).count %>)

<% if defined? block_name_id %> <%= content_for block_name_id %> <% end %> -<% reported_work_packages = WorkPackage.visible.find(:all, - :conditions => { :author_id => User.current.id, :project_id => @project.id }, - :limit => 10, - :include => [ :status, :project, :type ], - :order => "#{WorkPackage.table_name}.updated_at DESC") %> +<% reported_work_packages = WorkPackage.visible + .where(author_id: User.current.id, project_id: @project.id) + .limit(10) + .includes([:status, :project, :type]) + .order("#{WorkPackage.table_name}.updated_at DESC") %> <%= render :partial => 'work_packages/list_simple', :locals => { :work_packages => reported_work_packages } %> <% if reported_work_packages.length > 0 %>

diff --git a/app/views/my_projects_overviews/blocks/_work_packages_responsible_for.html.erb b/app/views/my_projects_overviews/blocks/_work_packages_responsible_for.html.erb index 68eaae8b18..4eba5775f1 100644 --- a/app/views/my_projects_overviews/blocks/_work_packages_responsible_for.html.erb +++ b/app/views/my_projects_overviews/blocks/_work_packages_responsible_for.html.erb @@ -19,17 +19,17 @@ See doc/COPYRIGHT.md for more details. ++#%> -

<%=l(:label_work_packages_responsible_for)%> (<%= WorkPackage.visible.open.count(:conditions => {:responsible_id => User.current.id, :project_id => @project.id})%>)

+

<%=l(:label_work_packages_responsible_for)%> (<%= WorkPackage.visible.open.where(responsible_id: User.current.id, project_id: @project.id).count %>)

<% if defined? block_name_id %> <%= content_for block_name_id %> <% end %> -<% responsible_work_packages = WorkPackage.visible.open.find(:all, - :conditions => {:responsible_id => User.current.id, :project_id => @project.id}, - :limit => 10, - :include => [ :status, :project, :type, :priority ], - :order => "#{IssuePriority.table_name}.position DESC, #{WorkPackage.table_name}.updated_at DESC") %> +<% responsible_work_packages = WorkPackage.visible.open + .where(responsible_id: User.current.id, project_id: @project.id) + .limit(10) + .includes([:status, :project, :type, :priority]) + .order("#{IssuePriority.table_name}.position DESC, #{WorkPackage.table_name}.updated_at DESC") %> <%= render :partial => 'work_packages/list_simple', :locals => { :work_packages => responsible_work_packages } %> <% if responsible_work_packages.length > 0 %>

From 477bcd8c78cc62c35f8ad04abc3eaece6f10a0da Mon Sep 17 00:00:00 2001 From: Jens Ulferts Date: Wed, 2 Sep 2015 12:04:52 +0200 Subject: [PATCH 4/5] remove code duplication --- .../my_projects_overviews_controller.rb | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/controllers/my_projects_overviews_controller.rb b/app/controllers/my_projects_overviews_controller.rb index f1de8e6205..9c9a8ecd4e 100644 --- a/app/controllers/my_projects_overviews_controller.rb +++ b/app/controllers/my_projects_overviews_controller.rb @@ -175,19 +175,21 @@ class MyProjectsOverviewsController < ApplicationController end def open_work_packages_by_type - @open_work_packages_by_tracker ||= WorkPackage.visible - .group(:type) - .includes([:project, :status, :type]) - .where(["(#{subproject_condition}) AND #{Status.table_name}.is_closed=?", false]) + @open_work_packages_by_tracker ||= work_packages_by_type + .where(statuses: { is_closed: false }) .count end def total_work_packages_by_type - @total_work_packages_by_tracker ||= WorkPackage.visible - .group(:type) - .includes([:project, :status, :type]) - .where(subproject_condition) - .count + @total_work_packages_by_tracker ||= work_packages_by_type.count + end + + def work_packages_by_type + WorkPackage + .visible + .group(:type) + .includes([:project, :status, :type]) + .where(subproject_condition) end def assigned_work_packages From 98fd8828c3c66761effe39f05b43be245ab44128 Mon Sep 17 00:00:00 2001 From: Jens Ulferts Date: Wed, 2 Sep 2015 13:00:56 +0200 Subject: [PATCH 5/5] code styling --- app/controllers/my_projects_overviews_controller.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/my_projects_overviews_controller.rb b/app/controllers/my_projects_overviews_controller.rb index 9c9a8ecd4e..bc346fb2a4 100644 --- a/app/controllers/my_projects_overviews_controller.rb +++ b/app/controllers/my_projects_overviews_controller.rb @@ -165,9 +165,11 @@ class MyProjectsOverviewsController < ApplicationController end def recent_news - @news ||= project.news.limit(5) + @news ||= project + .news .includes([:author, :project]) .order("#{News.table_name}.created_on DESC") + .limit(5) end def types @@ -193,11 +195,14 @@ class MyProjectsOverviewsController < ApplicationController end def assigned_work_packages - @assigned_issues ||= WorkPackage.visible.open + @assigned_issues ||= WorkPackage + .visible + .open .where(assigned_to: User.current.id) .limit(10) .includes([:status, :project, :type, :priority]) - .order("#{IssuePriority.table_name}.position DESC, #{WorkPackage.table_name}.updated_on DESC") + .order("#{IssuePriority.table_name}.position DESC, + #{WorkPackage.table_name}.updated_on DESC") end def users_by_role(limit = 100)