Commit 85e039049cba5ac1bf92e6cbba2ea1236d6892f7

Authored by Andrey Kumanyaev
1 parent 734d6fcd

Fix tests

app/models/project.rb
@@ -86,13 +86,13 @@ class Project < ActiveRecord::Base @@ -86,13 +86,13 @@ class Project < ActiveRecord::Base
86 validate :check_limit, :repo_name 86 validate :check_limit, :repo_name
87 87
88 # Scopes 88 # Scopes
89 - scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.authorized_projects.map(&:id) ) }  
90 - scope :without_team, ->(team) { team.projects.present? ? where("id NOT IN (:ids)", ids: team.projects.map(&:id)) : scoped }  
91 - scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) }  
92 - scope :in_team, ->(team) { where("id IN (:ids)", ids: team.projects.map(&:id)) } 89 + scope :without_user, ->(user) { where("projects.id NOT IN (:ids)", ids: user.authorized_projects.map(&:id) ) }
  90 + scope :without_team, ->(team) { team.projects.present? ? where("projects.id NOT IN (:ids)", ids: team.projects.map(&:id)) : scoped }
  91 + scope :not_in_group, ->(group) { where("projects.id NOT IN (:ids)", ids: group.project_ids ) }
  92 + scope :in_team, ->(team) { where("projects.id IN (:ids)", ids: team.projects.map(&:id)) }
93 scope :in_namespace, ->(namespace) { where(namespace_id: namespace.id) } 93 scope :in_namespace, ->(namespace) { where(namespace_id: namespace.id) }
94 scope :in_group_namespace, -> { joins(:group) } 94 scope :in_group_namespace, -> { joins(:group) }
95 - scope :sorted_by_activity, -> { order("last_activity_at DESC") } 95 + scope :sorted_by_activity, -> { order("projects.last_activity_at DESC") }
96 scope :personal, ->(user) { where(namespace_id: user.namespace_id) } 96 scope :personal, ->(user) { where(namespace_id: user.namespace_id) }
97 scope :joined, ->(user) { where("namespace_id != ?", user.namespace_id) } 97 scope :joined, ->(user) { where("namespace_id != ?", user.namespace_id) }
98 scope :public_only, -> { where(public: true) } 98 scope :public_only, -> { where(public: true) }
@@ -190,7 +190,7 @@ class Project < ActiveRecord::Base @@ -190,7 +190,7 @@ class Project < ActiveRecord::Base
190 end 190 end
191 191
192 def last_activity_date 192 def last_activity_date
193 - last_activity_at 193 + last_activity_at || updated_at
194 end 194 end
195 195
196 def project_id 196 def project_id
spec/models/project_spec.rb
@@ -108,8 +108,8 @@ describe Project do @@ -108,8 +108,8 @@ describe Project do
108 108
109 describe 'last_activity_date' do 109 describe 'last_activity_date' do
110 it 'returns the creation date of the project\'s last event if present' do 110 it 'returns the creation date of the project\'s last event if present' do
111 - project.stub(last_event: last_event)  
112 - project.last_activity_date.should == last_event.created_at 111 + last_activity_event = create(:event, project: project)
  112 + project.last_activity_date.to_s(:db).should == last_event.created_at.to_s(:db)
113 end 113 end
114 114
115 it 'returns the project\'s last update date if it has no events' do 115 it 'returns the project\'s last update date if it has no events' do