diff --git a/app/models/project.rb b/app/models/project.rb index 463829229b5..09fdc07fb25 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -86,13 +86,13 @@ class Project < ActiveRecord::Base validate :check_limit, :repo_name # Scopes - scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.authorized_projects.map(&:id) ) } - scope :without_team, ->(team) { team.projects.present? ? where("id NOT IN (:ids)", ids: team.projects.map(&:id)) : scoped } - scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) } - scope :in_team, ->(team) { where("id IN (:ids)", ids: team.projects.map(&:id)) } + scope :without_user, ->(user) { where("projects.id NOT IN (:ids)", ids: user.authorized_projects.map(&:id) ) } + scope :without_team, ->(team) { team.projects.present? ? where("projects.id NOT IN (:ids)", ids: team.projects.map(&:id)) : scoped } + scope :not_in_group, ->(group) { where("projects.id NOT IN (:ids)", ids: group.project_ids ) } + scope :in_team, ->(team) { where("projects.id IN (:ids)", ids: team.projects.map(&:id)) } scope :in_namespace, ->(namespace) { where(namespace_id: namespace.id) } scope :in_group_namespace, -> { joins(:group) } - scope :sorted_by_activity, -> { order("last_activity_at DESC") } + scope :sorted_by_activity, -> { order("projects.last_activity_at DESC") } scope :personal, ->(user) { where(namespace_id: user.namespace_id) } scope :joined, ->(user) { where("namespace_id != ?", user.namespace_id) } scope :public_only, -> { where(public: true) } @@ -190,7 +190,7 @@ class Project < ActiveRecord::Base end def last_activity_date - last_activity_at + last_activity_at || updated_at end def project_id diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index cbc7f278c2a..bfd7645b33f 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -108,8 +108,8 @@ describe Project do describe 'last_activity_date' do it 'returns the creation date of the project\'s last event if present' do - project.stub(last_event: last_event) - project.last_activity_date.should == last_event.created_at + last_activity_event = create(:event, project: project) + project.last_activity_date.to_s(:db).should == last_event.created_at.to_s(:db) end it 'returns the project\'s last update date if it has no events' do