Commit b5db541338314b01423d79fb9155e8c4ddc5d494

Authored by Andrew8xx8
1 parent 9a22ac63

All scopes must be in lambdas

app/models/concerns/issuable.rb
@@ -19,12 +19,12 @@ module Issuable @@ -19,12 +19,12 @@ module Issuable
19 validates :title, presence: true, length: { within: 0..255 } 19 validates :title, presence: true, length: { within: 0..255 }
20 validates :closed, inclusion: { in: [true, false] } 20 validates :closed, inclusion: { in: [true, false] }
21 21
22 - scope :opened, where(closed: false)  
23 - scope :closed, where(closed: true) 22 + scope :opened, -> { where(closed: false) }
  23 + scope :closed, -> { where(closed: true) }
24 scope :of_group, ->(group) { where(project_id: group.project_ids) } 24 scope :of_group, ->(group) { where(project_id: group.project_ids) }
25 scope :of_user_team, ->(team) { where(project_id: team.project_ids, assignee_id: team.member_ids) } 25 scope :of_user_team, ->(team) { where(project_id: team.project_ids, assignee_id: team.member_ids) }
26 scope :assigned, ->(u) { where(assignee_id: u.id)} 26 scope :assigned, ->(u) { where(assignee_id: u.id)}
27 - scope :recent, order("created_at DESC") 27 + scope :recent, -> { order("created_at DESC") }
28 28
29 delegate :name, 29 delegate :name,
30 :email, 30 :email,
app/models/event.rb
@@ -42,8 +42,8 @@ class Event < ActiveRecord::Base @@ -42,8 +42,8 @@ class Event < ActiveRecord::Base
42 serialize :data 42 serialize :data
43 43
44 # Scopes 44 # Scopes
45 - scope :recent, order("created_at DESC")  
46 - scope :code_push, where(action: Pushed) 45 + scope :recent, -> { order("created_at DESC") }
  46 + scope :code_push, -> { where(action: Pushed) }
47 scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent } 47 scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent }
48 48
49 class << self 49 class << self
app/models/milestone.rb
@@ -20,8 +20,8 @@ class Milestone &lt; ActiveRecord::Base @@ -20,8 +20,8 @@ class Milestone &lt; ActiveRecord::Base
20 has_many :issues 20 has_many :issues
21 has_many :merge_requests 21 has_many :merge_requests
22 22
23 - scope :active, where(closed: false)  
24 - scope :closed, where(closed: true) 23 + scope :active, -> { where(closed: false) }
  24 + scope :closed, -> { where(closed: true) }
25 25
26 validates :title, presence: true 26 validates :title, presence: true
27 validates :project, presence: true 27 validates :project, presence: true
app/models/namespace.rb
@@ -29,7 +29,7 @@ class Namespace &lt; ActiveRecord::Base @@ -29,7 +29,7 @@ class Namespace &lt; ActiveRecord::Base
29 after_update :move_dir 29 after_update :move_dir
30 after_destroy :rm_dir 30 after_destroy :rm_dir
31 31
32 - scope :root, where('type IS NULL') 32 + scope :root, -> { where('type IS NULL') }
33 33
34 def self.search query 34 def self.search query
35 where("name LIKE :query OR path LIKE :query", query: "%#{query}%") 35 where("name LIKE :query OR path LIKE :query", query: "%#{query}%")
app/models/note.rb
@@ -43,8 +43,8 @@ class Note &lt; ActiveRecord::Base @@ -43,8 +43,8 @@ class Note &lt; ActiveRecord::Base
43 43
44 # Scopes 44 # Scopes
45 scope :for_commit_id, ->(commit_id) { where(noteable_type: "Commit", commit_id: commit_id) } 45 scope :for_commit_id, ->(commit_id) { where(noteable_type: "Commit", commit_id: commit_id) }
46 - scope :inline, where("line_code IS NOT NULL")  
47 - scope :not_inline, where("line_code IS NULL") 46 + scope :inline, -> { where("line_code IS NOT NULL") }
  47 + scope :not_inline, -> { where("line_code IS NULL") }
48 48
49 scope :common, ->{ where(noteable_type: ["", nil]) } 49 scope :common, ->{ where(noteable_type: ["", nil]) }
50 scope :fresh, ->{ order("created_at ASC, id ASC") } 50 scope :fresh, ->{ order("created_at ASC, id ASC") }
app/models/project.rb
@@ -91,7 +91,7 @@ class Project &lt; ActiveRecord::Base @@ -91,7 +91,7 @@ class Project &lt; ActiveRecord::Base
91 scope :sorted_by_activity, ->() { order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC") } 91 scope :sorted_by_activity, ->() { order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC") }
92 scope :personal, ->(user) { where(namespace_id: user.namespace_id) } 92 scope :personal, ->(user) { where(namespace_id: user.namespace_id) }
93 scope :joined, ->(user) { where("namespace_id != ?", user.namespace_id) } 93 scope :joined, ->(user) { where("namespace_id != ?", user.namespace_id) }
94 - scope :public, where(public: true) 94 + scope :public, -> { where(public: true) }
95 95
96 class << self 96 class << self
97 def abandoned 97 def abandoned
app/models/snippet.rb
@@ -31,9 +31,9 @@ class Snippet &lt; ActiveRecord::Base @@ -31,9 +31,9 @@ class Snippet &lt; ActiveRecord::Base
31 validates :content, presence: true 31 validates :content, presence: true
32 32
33 # Scopes 33 # Scopes
34 - scope :fresh, order("created_at DESC")  
35 - scope :non_expired, where(["expires_at IS NULL OR expires_at > ?", Time.current])  
36 - scope :expired, where(["expires_at IS NOT NULL AND expires_at < ?", Time.current]) 34 + scope :fresh, -> { order("created_at DESC") }
  35 + scope :non_expired, -> { where(["expires_at IS NULL OR expires_at > ?", Time.current]) }
  36 + scope :expired, -> { where(["expires_at IS NOT NULL AND expires_at < ?", Time.current]) }
37 37
38 def self.content_types 38 def self.content_types
39 [ 39 [
app/models/user.rb
@@ -87,10 +87,10 @@ class User &lt; ActiveRecord::Base @@ -87,10 +87,10 @@ class User &lt; ActiveRecord::Base
87 delegate :path, to: :namespace, allow_nil: true, prefix: true 87 delegate :path, to: :namespace, allow_nil: true, prefix: true
88 88
89 # Scopes 89 # Scopes
90 - scope :admins, where(admin: true)  
91 - scope :blocked, where(blocked: true)  
92 - scope :active, where(blocked: false)  
93 - scope :alphabetically, order('name ASC') 90 + scope :admins, -> { where(admin: true) }
  91 + scope :blocked, -> { where(blocked: true) }
  92 + scope :active, -> { where(blocked: false) }
  93 + scope :alphabetically, -> { order('name ASC') }
94 scope :in_team, ->(team){ where(id: team.member_ids) } 94 scope :in_team, ->(team){ where(id: team.member_ids) }
95 scope :not_in_team, ->(team){ where('users.id NOT IN (:ids)', ids: team.member_ids) } 95 scope :not_in_team, ->(team){ where('users.id NOT IN (:ids)', ids: team.member_ids) }
96 scope :potential_team_members, ->(team) { team.members.any? ? active.not_in_team(team) : active } 96 scope :potential_team_members, ->(team) { team.members.any? ? active.not_in_team(team) : active }
app/models/users_project.rb
@@ -32,10 +32,10 @@ class UsersProject &lt; ActiveRecord::Base @@ -32,10 +32,10 @@ class UsersProject &lt; ActiveRecord::Base
32 32
33 delegate :name, :username, :email, to: :user, prefix: true 33 delegate :name, :username, :email, to: :user, prefix: true
34 34
35 - scope :guests, where(project_access: GUEST)  
36 - scope :reporters, where(project_access: REPORTER)  
37 - scope :developers, where(project_access: DEVELOPER)  
38 - scope :masters, where(project_access: MASTER) 35 + scope :guests, -> { where(project_access: GUEST) }
  36 + scope :reporters, -> { where(project_access: REPORTER) }
  37 + scope :developers, -> { where(project_access: DEVELOPER) }
  38 + scope :masters, -> { where(project_access: MASTER) }
39 39
40 scope :in_project, ->(project) { where(project_id: project.id) } 40 scope :in_project, ->(project) { where(project_id: project.id) }
41 scope :in_projects, ->(projects) { where(project_id: project_ids) } 41 scope :in_projects, ->(projects) { where(project_id: project_ids) }