Commit 4546c7109ce46b5607bd1c5362bd50881ced6983

Authored by Dmitriy Zaporozhets
2 parents 52cd655f 4496a747

Merge branch 'Undev-feature/refactoring_scopes_pr'

app/controllers/admin/users_controller.rb
@@ -14,7 +14,7 @@ class Admin::UsersController < Admin::ApplicationController @@ -14,7 +14,7 @@ class Admin::UsersController < Admin::ApplicationController
14 @not_in_projects = @not_in_projects.without_user(admin_user) if admin_user.authorized_projects.present? 14 @not_in_projects = @not_in_projects.without_user(admin_user) if admin_user.authorized_projects.present?
15 15
16 # Projects he already own or joined 16 # Projects he already own or joined
17 - @projects = admin_user.authorized_projects.where('projects.id in (?)', admin_user.authorized_projects.map(&:id)) 17 + @projects = admin_user.authorized_projects
18 end 18 end
19 19
20 def team_update 20 def team_update
app/helpers/application_helper.rb
@@ -151,9 +151,8 @@ module ApplicationHelper @@ -151,9 +151,8 @@ module ApplicationHelper
151 end 151 end
152 152
153 def project_last_activity project 153 def project_last_activity project
154 - activity = project.last_activity  
155 - if activity && activity.created_at  
156 - time_ago_in_words(activity.created_at) + " ago" 154 + if project.last_activity_at
  155 + time_ago_in_words(project.last_activity_at) + " ago"
157 else 156 else
158 "Never" 157 "Never"
159 end 158 end
app/models/group.rb
@@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
13 # 13 #
14 14
15 class Group < Namespace 15 class Group < Namespace
  16 +
16 def add_users_to_project_teams(user_ids, project_access) 17 def add_users_to_project_teams(user_ids, project_access)
17 UsersProject.add_users_into_projects( 18 UsersProject.add_users_into_projects(
18 projects.map(&:id), 19 projects.map(&:id),
app/models/issue.rb
@@ -25,19 +25,9 @@ class Issue &lt; ActiveRecord::Base @@ -25,19 +25,9 @@ class Issue &lt; ActiveRecord::Base
25 25
26 acts_as_taggable_on :labels 26 acts_as_taggable_on :labels
27 27
28 - class << self  
29 - def cared(user)  
30 - where('assignee_id = :user', user: user.id)  
31 - end  
32 -  
33 - def authored(user)  
34 - where('author_id = :user', user: user.id)  
35 - end  
36 -  
37 - def open_for(user)  
38 - opened.assigned(user)  
39 - end  
40 - end 28 + scope :cared, ->(user) { where(assignee_id: user) }
  29 + scope :authored, ->(user) { where(author_id: user) }
  30 + scope :open_for, ->(user) { opened.assigned(user) }
41 31
42 state_machine :state, initial: :opened do 32 state_machine :state, initial: :opened do
43 event :close do 33 event :close do
app/models/key.rb
@@ -23,7 +23,7 @@ class Key &lt; ActiveRecord::Base @@ -23,7 +23,7 @@ class Key &lt; ActiveRecord::Base
23 before_validation :strip_white_space 23 before_validation :strip_white_space
24 24
25 validates :title, presence: true, length: { within: 0..255 } 25 validates :title, presence: true, length: { within: 0..255 }
26 - validates :key, presence: true, length: { within: 0..5000 }, format: { :with => /ssh-.{3} / }, uniqueness: true 26 + validates :key, presence: true, length: { within: 0..5000 }, format: { with: /ssh-.{3} / }, uniqueness: true
27 validate :fingerprintable_key 27 validate :fingerprintable_key
28 28
29 delegate :name, :email, to: :user, prefix: true 29 delegate :name, :email, to: :user, prefix: true
@@ -48,7 +48,7 @@ class Key &lt; ActiveRecord::Base @@ -48,7 +48,7 @@ class Key &lt; ActiveRecord::Base
48 end 48 end
49 49
50 def is_deploy_key 50 def is_deploy_key
51 - !!project_id 51 + project.present?
52 end 52 end
53 53
54 # projects that has this key 54 # projects that has this key
app/models/milestone.rb
@@ -19,6 +19,7 @@ class Milestone &lt; ActiveRecord::Base @@ -19,6 +19,7 @@ class Milestone &lt; ActiveRecord::Base
19 belongs_to :project 19 belongs_to :project
20 has_many :issues 20 has_many :issues
21 has_many :merge_requests 21 has_many :merge_requests
  22 + has_many :participants, through: :issues, source: :assignee
22 23
23 scope :active, -> { with_state(:active) } 24 scope :active, -> { with_state(:active) }
24 scope :closed, -> { with_state(:closed) } 25 scope :closed, -> { with_state(:closed) }
@@ -48,10 +49,6 @@ class Milestone &lt; ActiveRecord::Base @@ -48,10 +49,6 @@ class Milestone &lt; ActiveRecord::Base
48 end 49 end
49 end 50 end
50 51
51 - def participants  
52 - User.where(id: issues.pluck(:assignee_id))  
53 - end  
54 -  
55 def open_items_count 52 def open_items_count
56 self.issues.opened.count + self.merge_requests.opened.count 53 self.issues.opened.count + self.merge_requests.opened.count
57 end 54 end
app/models/project.rb
@@ -30,7 +30,7 @@ class Project &lt; ActiveRecord::Base @@ -30,7 +30,7 @@ class Project &lt; ActiveRecord::Base
30 30
31 attr_accessible :name, :path, :description, :default_branch, :issues_tracker, 31 attr_accessible :name, :path, :description, :default_branch, :issues_tracker,
32 :issues_enabled, :wall_enabled, :merge_requests_enabled, :snippets_enabled, :issues_tracker_id, 32 :issues_enabled, :wall_enabled, :merge_requests_enabled, :snippets_enabled, :issues_tracker_id,
33 - :wiki_enabled, :public, :import_url, as: [:default, :admin] 33 + :wiki_enabled, :public, :import_url, :last_activity_at, as: [:default, :admin]
34 34
35 attr_accessible :namespace_id, :creator_id, as: :admin 35 attr_accessible :namespace_id, :creator_id, as: :admin
36 36
@@ -87,17 +87,18 @@ class Project &lt; ActiveRecord::Base @@ -87,17 +87,18 @@ class Project &lt; ActiveRecord::Base
87 validate :check_limit, :repo_name 87 validate :check_limit, :repo_name
88 88
89 # Scopes 89 # Scopes
90 - scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.authorized_projects.map(&:id) ) }  
91 - scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) }  
92 - scope :without_team, ->(team) { team.projects.present? ? where("id NOT IN (:ids)", ids: team.projects.map(&:id)) : scoped }  
93 - scope :in_team, ->(team) { where("id IN (:ids)", ids: team.projects.map(&:id)) } 90 + scope :without_user, ->(user) { where("projects.id NOT IN (:ids)", ids: user.authorized_projects.map(&:id) ) }
  91 + scope :without_team, ->(team) { team.projects.present? ? where("projects.id NOT IN (:ids)", ids: team.projects.map(&:id)) : scoped }
  92 + scope :not_in_group, ->(group) { where("projects.id NOT IN (:ids)", ids: group.project_ids ) }
  93 + scope :in_team, ->(team) { where("projects.id IN (:ids)", ids: team.projects.map(&:id)) }
94 scope :in_namespace, ->(namespace) { where(namespace_id: namespace.id) } 94 scope :in_namespace, ->(namespace) { where(namespace_id: namespace.id) }
95 - scope :sorted_by_activity, ->() { order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC") } 95 + scope :in_group_namespace, -> { joins(:group) }
  96 + scope :sorted_by_activity, -> { order("projects.last_activity_at DESC") }
96 scope :personal, ->(user) { where(namespace_id: user.namespace_id) } 97 scope :personal, ->(user) { where(namespace_id: user.namespace_id) }
97 scope :joined, ->(user) { where("namespace_id != ?", user.namespace_id) } 98 scope :joined, ->(user) { where("namespace_id != ?", user.namespace_id) }
98 scope :public_only, -> { where(public: true) } 99 scope :public_only, -> { where(public: true) }
99 100
100 - enumerize :issues_tracker, :in => (Gitlab.config.issues_tracker.keys).append(:gitlab), :default => :gitlab 101 + enumerize :issues_tracker, in: (Gitlab.config.issues_tracker.keys).append(:gitlab), default: :gitlab
101 102
102 class << self 103 class << self
103 def abandoned 104 def abandoned
@@ -190,7 +191,7 @@ class Project &lt; ActiveRecord::Base @@ -190,7 +191,7 @@ class Project &lt; ActiveRecord::Base
190 end 191 end
191 192
192 def last_activity_date 193 def last_activity_date
193 - last_event.try(:created_at) || updated_at 194 + last_activity_at || updated_at
194 end 195 end
195 196
196 def project_id 197 def project_id
app/models/user.rb
@@ -59,11 +59,10 @@ class User &lt; ActiveRecord::Base @@ -59,11 +59,10 @@ class User &lt; ActiveRecord::Base
59 # 59 #
60 60
61 # Namespace for personal projects 61 # Namespace for personal projects
62 - has_one :namespace,  
63 - dependent: :destroy,  
64 - foreign_key: :owner_id,  
65 - class_name: "Namespace",  
66 - conditions: 'type IS NULL' 62 + has_one :namespace, dependent: :destroy, foreign_key: :owner_id, class_name: "Namespace", conditions: 'type IS NULL'
  63 +
  64 + # Namespaces (owned groups and own namespace)
  65 + has_many :namespaces, foreign_key: :owner_id
67 66
68 # Profile 67 # Profile
69 has_many :keys, dependent: :destroy 68 has_many :keys, dependent: :destroy
@@ -72,15 +71,11 @@ class User &lt; ActiveRecord::Base @@ -72,15 +71,11 @@ class User &lt; ActiveRecord::Base
72 has_many :groups, class_name: "Group", foreign_key: :owner_id 71 has_many :groups, class_name: "Group", foreign_key: :owner_id
73 72
74 # Teams 73 # Teams
75 - has_many :own_teams,  
76 - class_name: "UserTeam",  
77 - foreign_key: :owner_id,  
78 - dependent: :destroy  
79 -  
80 - has_many :user_team_user_relationships, dependent: :destroy  
81 - has_many :user_teams, through: :user_team_user_relationships 74 + has_many :own_teams, dependent: :destroy, class_name: "UserTeam", foreign_key: :owner_id
  75 + has_many :user_team_user_relationships, dependent: :destroy
  76 + has_many :user_teams, through: :user_team_user_relationships
82 has_many :user_team_project_relationships, through: :user_teams 77 has_many :user_team_project_relationships, through: :user_teams
83 - has_many :team_projects, through: :user_team_project_relationships 78 + has_many :team_projects, through: :user_team_project_relationships
84 79
85 # Projects 80 # Projects
86 has_many :users_projects, dependent: :destroy 81 has_many :users_projects, dependent: :destroy
@@ -88,14 +83,14 @@ class User &lt; ActiveRecord::Base @@ -88,14 +83,14 @@ class User &lt; ActiveRecord::Base
88 has_many :notes, dependent: :destroy, foreign_key: :author_id 83 has_many :notes, dependent: :destroy, foreign_key: :author_id
89 has_many :merge_requests, dependent: :destroy, foreign_key: :author_id 84 has_many :merge_requests, dependent: :destroy, foreign_key: :author_id
90 has_many :events, dependent: :destroy, foreign_key: :author_id, class_name: "Event" 85 has_many :events, dependent: :destroy, foreign_key: :author_id, class_name: "Event"
  86 + has_many :recent_events, foreign_key: :author_id, class_name: "Event", order: "id DESC"
91 has_many :assigned_issues, dependent: :destroy, foreign_key: :assignee_id, class_name: "Issue" 87 has_many :assigned_issues, dependent: :destroy, foreign_key: :assignee_id, class_name: "Issue"
92 has_many :assigned_merge_requests, dependent: :destroy, foreign_key: :assignee_id, class_name: "MergeRequest" 88 has_many :assigned_merge_requests, dependent: :destroy, foreign_key: :assignee_id, class_name: "MergeRequest"
93 - has_many :projects, through: :users_projects  
94 89
95 - has_many :recent_events,  
96 - class_name: "Event",  
97 - foreign_key: :author_id,  
98 - order: "id DESC" 90 + has_many :personal_projects, through: :namespace, source: :projects
  91 + has_many :projects, through: :users_projects
  92 + has_many :own_projects, foreign_key: :creator_id
  93 + has_many :owned_projects, through: :namespaces, source: :projects
99 94
100 # 95 #
101 # Validations 96 # Validations
@@ -109,9 +104,7 @@ class User &lt; ActiveRecord::Base @@ -109,9 +104,7 @@ class User &lt; ActiveRecord::Base
109 format: { with: Gitlab::Regex.username_regex, 104 format: { with: Gitlab::Regex.username_regex,
110 message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" } 105 message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
111 106
112 - validates :notification_level,  
113 - inclusion: { in: Notification.notification_levels },  
114 - presence: true 107 + validates :notification_level, inclusion: { in: Notification.notification_levels }, presence: true
115 108
116 validate :namespace_uniq, if: ->(user) { user.username_changed? } 109 validate :namespace_uniq, if: ->(user) { user.username_changed? }
117 110
@@ -145,6 +138,9 @@ class User &lt; ActiveRecord::Base @@ -145,6 +138,9 @@ class User &lt; ActiveRecord::Base
145 scope :alphabetically, -> { order('name ASC') } 138 scope :alphabetically, -> { order('name ASC') }
146 scope :in_team, ->(team){ where(id: team.member_ids) } 139 scope :in_team, ->(team){ where(id: team.member_ids) }
147 scope :not_in_team, ->(team){ where('users.id NOT IN (:ids)', ids: team.member_ids) } 140 scope :not_in_team, ->(team){ where('users.id NOT IN (:ids)', ids: team.member_ids) }
  141 + scope :not_in_project, ->(project) { project.users.present? ? where("id not in (:ids)", ids: project.users.map(&:id) ) : scoped }
  142 + scope :without_projects, -> { where('id NOT IN (SELECT DISTINCT(user_id) FROM users_projects)') }
  143 +
148 scope :potential_team_members, ->(team) { team.members.any? ? active.not_in_team(team) : active } 144 scope :potential_team_members, ->(team) { team.members.any? ? active.not_in_team(team) : active }
149 145
150 # 146 #
@@ -171,18 +167,6 @@ class User &lt; ActiveRecord::Base @@ -171,18 +167,6 @@ class User &lt; ActiveRecord::Base
171 end 167 end
172 end 168 end
173 169
174 - def not_in_project(project)  
175 - if project.users.present?  
176 - where("id not in (:ids)", ids: project.users.map(&:id) )  
177 - else  
178 - scoped  
179 - end  
180 - end  
181 -  
182 - def without_projects  
183 - where('id NOT IN (SELECT DISTINCT(user_id) FROM users_projects)')  
184 - end  
185 -  
186 def create_from_omniauth(auth, ldap = false) 170 def create_from_omniauth(auth, ldap = false)
187 gitlab_auth.create_from_omniauth(auth, ldap) 171 gitlab_auth.create_from_omniauth(auth, ldap)
188 end 172 end
@@ -229,56 +213,36 @@ class User &lt; ActiveRecord::Base @@ -229,56 +213,36 @@ class User &lt; ActiveRecord::Base
229 end 213 end
230 end 214 end
231 215
232 - # Namespaces user has access to  
233 - def namespaces  
234 - namespaces = []  
235 -  
236 - # Add user account namespace  
237 - namespaces << self.namespace if self.namespace  
238 -  
239 - # Add groups you can manage  
240 - namespaces += groups.all  
241 -  
242 - namespaces  
243 - end  
244 -  
245 # Groups where user is an owner 216 # Groups where user is an owner
246 def owned_groups 217 def owned_groups
247 groups 218 groups
248 end 219 end
249 220
  221 + def owned_teams
  222 + own_teams
  223 + end
  224 +
250 # Groups user has access to 225 # Groups user has access to
251 def authorized_groups 226 def authorized_groups
252 - @authorized_groups ||= begin  
253 - groups = Group.where(id: self.authorized_projects.pluck(:namespace_id)).all  
254 - groups = groups + self.groups  
255 - groups.uniq  
256 - end 227 + @group_ids ||= (groups.pluck(:id) + authorized_projects.pluck(:namespace_id))
  228 + Group.where(id: @group_ids)
257 end 229 end
258 230
259 231
260 # Projects user has access to 232 # Projects user has access to
261 def authorized_projects 233 def authorized_projects
262 - project_ids = users_projects.pluck(:project_id)  
263 - project_ids = project_ids | owned_projects.pluck(:id)  
264 - Project.where(id: project_ids) 234 + @project_ids ||= (owned_projects.pluck(:id) + projects.pluck(:id)).uniq
  235 + Project.where(id: @project_ids)
265 end 236 end
266 237
267 - # Projects in user namespace  
268 - def personal_projects  
269 - Project.personal(self)  
270 - end  
271 -  
272 - # Projects where user is an owner  
273 - def owned_projects  
274 - Project.where("(projects.namespace_id IN (:namespaces)) OR  
275 - (projects.namespace_id IS NULL AND projects.creator_id = :user_id)",  
276 - namespaces: namespaces.map(&:id), user_id: self.id) 238 + def authorized_teams
  239 + @team_ids ||= (user_teams.pluck(:id) + own_teams.pluck(:id)).uniq
  240 + UserTeam.where(id: @team_ids)
277 end 241 end
278 242
279 # Team membership in authorized projects 243 # Team membership in authorized projects
280 def tm_in_authorized_projects 244 def tm_in_authorized_projects
281 - UsersProject.where(project_id: authorized_projects.map(&:id), user_id: self.id) 245 + UsersProject.where(project_id: authorized_projects.map(&:id), user_id: self.id)
282 end 246 end
283 247
284 def is_admin? 248 def is_admin?
@@ -348,28 +312,13 @@ class User &lt; ActiveRecord::Base @@ -348,28 +312,13 @@ class User &lt; ActiveRecord::Base
348 end 312 end
349 313
350 def several_namespaces? 314 def several_namespaces?
351 - namespaces.size > 1 315 + namespaces.many?
352 end 316 end
353 317
354 def namespace_id 318 def namespace_id
355 namespace.try :id 319 namespace.try :id
356 end 320 end
357 321
358 - def authorized_teams  
359 - @authorized_teams ||= begin  
360 - ids = []  
361 - ids << UserTeam.with_member(self).pluck('user_teams.id')  
362 - ids << UserTeam.created_by(self).pluck('user_teams.id')  
363 - ids.flatten  
364 -  
365 - UserTeam.where(id: ids)  
366 - end  
367 - end  
368 -  
369 - def owned_teams  
370 - UserTeam.where(owner_id: self.id)  
371 - end  
372 -  
373 def name_with_username 322 def name_with_username
374 "#{name} (#{username})" 323 "#{name} (#{username})"
375 end 324 end
app/observers/project_activity_cache_observer.rb 0 → 100644
@@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
  1 +class ProjectActivityCacheObserver < BaseObserver
  2 + observe :event
  3 +
  4 + def after_create(event)
  5 + event.project.update_attribute(:last_activity_at, event.created_at) if event.project
  6 + end
  7 +end
  8 +
config/application.rb
@@ -24,6 +24,7 @@ module Gitlab @@ -24,6 +24,7 @@ module Gitlab
24 24
25 # Activate observers that should always be running. 25 # Activate observers that should always be running.
26 config.active_record.observers = :activity_observer, 26 config.active_record.observers = :activity_observer,
  27 + :project_activity_cache_observer,
27 :issue_observer, 28 :issue_observer,
28 :key_observer, 29 :key_observer,
29 :merge_request_observer, 30 :merge_request_observer,
db/migrate/20130403003950_add_last_activity_column_into_project.rb 0 → 100644
@@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
  1 +class AddLastActivityColumnIntoProject < ActiveRecord::Migration
  2 + def up
  3 + add_column :projects, :last_activity_at, :datetime
  4 + add_index :projects, :last_activity_at
  5 +
  6 + Project.find_each do |project|
  7 + last_activity_date = if project.last_activity
  8 + project.last_activity.created_at
  9 + else
  10 + project.updated_at
  11 + end
  12 +
  13 + project.update_attribute(:last_activity_at, last_activity_date)
  14 + end
  15 + end
  16 +
  17 + def down
  18 + remove_index :projects, :last_activity_at
  19 + remove_column :projects, :last_activity_at
  20 + end
  21 +end
@@ -37,8 +37,8 @@ ActiveRecord::Schema.define(:version =&gt; 20130404164628) do @@ -37,8 +37,8 @@ ActiveRecord::Schema.define(:version =&gt; 20130404164628) do
37 t.integer "assignee_id" 37 t.integer "assignee_id"
38 t.integer "author_id" 38 t.integer "author_id"
39 t.integer "project_id" 39 t.integer "project_id"
40 - t.datetime "created_at", :null => false  
41 - t.datetime "updated_at", :null => false 40 + t.datetime "created_at"
  41 + t.datetime "updated_at"
42 t.integer "position", :default => 0 42 t.integer "position", :default => 0
43 t.string "branch_name" 43 t.string "branch_name"
44 t.text "description" 44 t.text "description"
@@ -55,8 +55,8 @@ ActiveRecord::Schema.define(:version =&gt; 20130404164628) do @@ -55,8 +55,8 @@ ActiveRecord::Schema.define(:version =&gt; 20130404164628) do
55 55
56 create_table "keys", :force => true do |t| 56 create_table "keys", :force => true do |t|
57 t.integer "user_id" 57 t.integer "user_id"
58 - t.datetime "created_at", :null => false  
59 - t.datetime "updated_at", :null => false 58 + t.datetime "created_at"
  59 + t.datetime "updated_at"
60 t.text "key" 60 t.text "key"
61 t.string "title" 61 t.string "title"
62 t.string "identifier" 62 t.string "identifier"
@@ -74,8 +74,8 @@ ActiveRecord::Schema.define(:version =&gt; 20130404164628) do @@ -74,8 +74,8 @@ ActiveRecord::Schema.define(:version =&gt; 20130404164628) do
74 t.integer "author_id" 74 t.integer "author_id"
75 t.integer "assignee_id" 75 t.integer "assignee_id"
76 t.string "title" 76 t.string "title"
77 - t.datetime "created_at", :null => false  
78 - t.datetime "updated_at", :null => false 77 + t.datetime "created_at"
  78 + t.datetime "updated_at"
79 t.text "st_commits", :limit => 2147483647 79 t.text "st_commits", :limit => 2147483647
80 t.text "st_diffs", :limit => 2147483647 80 t.text "st_diffs", :limit => 2147483647
81 t.integer "milestone_id" 81 t.integer "milestone_id"
@@ -124,8 +124,8 @@ ActiveRecord::Schema.define(:version =&gt; 20130404164628) do @@ -124,8 +124,8 @@ ActiveRecord::Schema.define(:version =&gt; 20130404164628) do
124 t.text "note" 124 t.text "note"
125 t.string "noteable_type" 125 t.string "noteable_type"
126 t.integer "author_id" 126 t.integer "author_id"
127 - t.datetime "created_at", :null => false  
128 - t.datetime "updated_at", :null => false 127 + t.datetime "created_at"
  128 + t.datetime "updated_at"
129 t.integer "project_id" 129 t.integer "project_id"
130 t.string "attachment" 130 t.string "attachment"
131 t.string "line_code" 131 t.string "line_code"
@@ -143,8 +143,8 @@ ActiveRecord::Schema.define(:version =&gt; 20130404164628) do @@ -143,8 +143,8 @@ ActiveRecord::Schema.define(:version =&gt; 20130404164628) do
143 t.string "name" 143 t.string "name"
144 t.string "path" 144 t.string "path"
145 t.text "description" 145 t.text "description"
146 - t.datetime "created_at", :null => false  
147 - t.datetime "updated_at", :null => false 146 + t.datetime "created_at"
  147 + t.datetime "updated_at"
148 t.integer "creator_id" 148 t.integer "creator_id"
149 t.string "default_branch" 149 t.string "default_branch"
150 t.boolean "issues_enabled", :default => true, :null => false 150 t.boolean "issues_enabled", :default => true, :null => false
@@ -188,8 +188,8 @@ ActiveRecord::Schema.define(:version =&gt; 20130404164628) do @@ -188,8 +188,8 @@ ActiveRecord::Schema.define(:version =&gt; 20130404164628) do
188 t.text "content" 188 t.text "content"
189 t.integer "author_id", :null => false 189 t.integer "author_id", :null => false
190 t.integer "project_id", :null => false 190 t.integer "project_id", :null => false
191 - t.datetime "created_at", :null => false  
192 - t.datetime "updated_at", :null => false 191 + t.datetime "created_at"
  192 + t.datetime "updated_at"
193 t.string "file_name" 193 t.string "file_name"
194 t.datetime "expires_at" 194 t.datetime "expires_at"
195 end 195 end
@@ -208,9 +208,6 @@ ActiveRecord::Schema.define(:version =&gt; 20130404164628) do @@ -208,9 +208,6 @@ ActiveRecord::Schema.define(:version =&gt; 20130404164628) do
208 t.datetime "created_at" 208 t.datetime "created_at"
209 end 209 end
210 210
211 - add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"  
212 - add_index "taggings", ["taggable_id", "taggable_type", "context"], :name => "index_taggings_on_taggable_id_and_taggable_type_and_context"  
213 -  
214 create_table "tags", :force => true do |t| 211 create_table "tags", :force => true do |t|
215 t.string "name" 212 t.string "name"
216 end 213 end
@@ -242,42 +239,41 @@ ActiveRecord::Schema.define(:version =&gt; 20130404164628) do @@ -242,42 +239,41 @@ ActiveRecord::Schema.define(:version =&gt; 20130404164628) do
242 end 239 end
243 240
244 create_table "users", :force => true do |t| 241 create_table "users", :force => true do |t|
245 - t.string "email", :default => "", :null => false  
246 - t.string "encrypted_password", :default => "", :null => false 242 + t.string "email", :default => "", :null => false
  243 + t.string "encrypted_password", :limit => 128, :default => "", :null => false
247 t.string "reset_password_token" 244 t.string "reset_password_token"
248 t.datetime "reset_password_sent_at" 245 t.datetime "reset_password_sent_at"
249 t.datetime "remember_created_at" 246 t.datetime "remember_created_at"
250 - t.integer "sign_in_count", :default => 0 247 + t.integer "sign_in_count", :default => 0
251 t.datetime "current_sign_in_at" 248 t.datetime "current_sign_in_at"
252 t.datetime "last_sign_in_at" 249 t.datetime "last_sign_in_at"
253 t.string "current_sign_in_ip" 250 t.string "current_sign_in_ip"
254 t.string "last_sign_in_ip" 251 t.string "last_sign_in_ip"
255 - t.datetime "created_at", :null => false  
256 - t.datetime "updated_at", :null => false 252 + t.datetime "created_at"
  253 + t.datetime "updated_at"
257 t.string "name" 254 t.string "name"
258 - t.boolean "admin", :default => false, :null => false  
259 - t.integer "projects_limit", :default => 10  
260 - t.string "skype", :default => "", :null => false  
261 - t.string "linkedin", :default => "", :null => false  
262 - t.string "twitter", :default => "", :null => false 255 + t.boolean "admin", :default => false, :null => false
  256 + t.integer "projects_limit", :default => 10
  257 + t.string "skype", :default => "", :null => false
  258 + t.string "linkedin", :default => "", :null => false
  259 + t.string "twitter", :default => "", :null => false
263 t.string "authentication_token" 260 t.string "authentication_token"
264 - t.integer "theme_id", :default => 1, :null => false 261 + t.integer "theme_id", :default => 1, :null => false
265 t.string "bio" 262 t.string "bio"
266 - t.integer "failed_attempts", :default => 0 263 + t.integer "failed_attempts", :default => 0
267 t.datetime "locked_at" 264 t.datetime "locked_at"
268 t.string "extern_uid" 265 t.string "extern_uid"
269 t.string "provider" 266 t.string "provider"
270 t.string "username" 267 t.string "username"
271 - t.boolean "can_create_group", :default => true, :null => false  
272 - t.boolean "can_create_team", :default => true, :null => false 268 + t.boolean "can_create_group", :default => true, :null => false
  269 + t.boolean "can_create_team", :default => true, :null => false
273 t.string "state" 270 t.string "state"
274 - t.integer "color_scheme_id", :default => 1, :null => false  
275 - t.integer "notification_level", :default => 1, :null => false 271 + t.integer "color_scheme_id", :default => 1, :null => false
  272 + t.integer "notification_level", :default => 1, :null => false
276 end 273 end
277 274
278 add_index "users", ["admin"], :name => "index_users_on_admin" 275 add_index "users", ["admin"], :name => "index_users_on_admin"
279 add_index "users", ["email"], :name => "index_users_on_email", :unique => true 276 add_index "users", ["email"], :name => "index_users_on_email", :unique => true
280 - add_index "users", ["extern_uid", "provider"], :name => "index_users_on_extern_uid_and_provider", :unique => true  
281 add_index "users", ["name"], :name => "index_users_on_name" 277 add_index "users", ["name"], :name => "index_users_on_name"
282 add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true 278 add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
283 add_index "users", ["username"], :name => "index_users_on_username" 279 add_index "users", ["username"], :name => "index_users_on_username"
@@ -285,8 +281,8 @@ ActiveRecord::Schema.define(:version =&gt; 20130404164628) do @@ -285,8 +281,8 @@ ActiveRecord::Schema.define(:version =&gt; 20130404164628) do
285 create_table "users_projects", :force => true do |t| 281 create_table "users_projects", :force => true do |t|
286 t.integer "user_id", :null => false 282 t.integer "user_id", :null => false
287 t.integer "project_id", :null => false 283 t.integer "project_id", :null => false
288 - t.datetime "created_at", :null => false  
289 - t.datetime "updated_at", :null => false 284 + t.datetime "created_at"
  285 + t.datetime "updated_at"
290 t.integer "project_access", :default => 0, :null => false 286 t.integer "project_access", :default => 0, :null => false
291 t.integer "notification_level", :default => 3, :null => false 287 t.integer "notification_level", :default => 3, :null => false
292 end 288 end
@@ -298,8 +294,8 @@ ActiveRecord::Schema.define(:version =&gt; 20130404164628) do @@ -298,8 +294,8 @@ ActiveRecord::Schema.define(:version =&gt; 20130404164628) do
298 create_table "web_hooks", :force => true do |t| 294 create_table "web_hooks", :force => true do |t|
299 t.string "url" 295 t.string "url"
300 t.integer "project_id" 296 t.integer "project_id"
301 - t.datetime "created_at", :null => false  
302 - t.datetime "updated_at", :null => false 297 + t.datetime "created_at"
  298 + t.datetime "updated_at"
303 t.string "type", :default => "ProjectHook" 299 t.string "type", :default => "ProjectHook"
304 t.integer "service_id" 300 t.integer "service_id"
305 end 301 end
spec/models/project_spec.rb
@@ -109,8 +109,8 @@ describe Project do @@ -109,8 +109,8 @@ describe Project do
109 109
110 describe 'last_activity_date' do 110 describe 'last_activity_date' do
111 it 'returns the creation date of the project\'s last event if present' do 111 it 'returns the creation date of the project\'s last event if present' do
112 - project.stub(last_event: last_event)  
113 - project.last_activity_date.should == last_event.created_at 112 + last_activity_event = create(:event, project: project)
  113 + project.last_activity_date.to_s(:db).should == last_event.created_at.to_s(:db)
114 end 114 end
115 115
116 it 'returns the project\'s last update date if it has no events' do 116 it 'returns the project\'s last update date if it has no events' do