Commit b5db541338314b01423d79fb9155e8c4ddc5d494
1 parent
9a22ac63
Exists in
master
and in
4 other branches
All scopes must be in lambdas
Showing
9 changed files
with
22 additions
and
22 deletions
Show diff stats
app/models/concerns/issuable.rb
... | ... | @@ -19,12 +19,12 @@ module Issuable |
19 | 19 | validates :title, presence: true, length: { within: 0..255 } |
20 | 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 | 24 | scope :of_group, ->(group) { where(project_id: group.project_ids) } |
25 | 25 | scope :of_user_team, ->(team) { where(project_id: team.project_ids, assignee_id: team.member_ids) } |
26 | 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 | 29 | delegate :name, |
30 | 30 | :email, | ... | ... |
app/models/event.rb
... | ... | @@ -42,8 +42,8 @@ class Event < ActiveRecord::Base |
42 | 42 | serialize :data |
43 | 43 | |
44 | 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 | 47 | scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent } |
48 | 48 | |
49 | 49 | class << self | ... | ... |
app/models/milestone.rb
... | ... | @@ -20,8 +20,8 @@ class Milestone < ActiveRecord::Base |
20 | 20 | has_many :issues |
21 | 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 | 26 | validates :title, presence: true |
27 | 27 | validates :project, presence: true | ... | ... |
app/models/namespace.rb
... | ... | @@ -29,7 +29,7 @@ class Namespace < ActiveRecord::Base |
29 | 29 | after_update :move_dir |
30 | 30 | after_destroy :rm_dir |
31 | 31 | |
32 | - scope :root, where('type IS NULL') | |
32 | + scope :root, -> { where('type IS NULL') } | |
33 | 33 | |
34 | 34 | def self.search query |
35 | 35 | where("name LIKE :query OR path LIKE :query", query: "%#{query}%") | ... | ... |
app/models/note.rb
... | ... | @@ -43,8 +43,8 @@ class Note < ActiveRecord::Base |
43 | 43 | |
44 | 44 | # Scopes |
45 | 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 | 49 | scope :common, ->{ where(noteable_type: ["", nil]) } |
50 | 50 | scope :fresh, ->{ order("created_at ASC, id ASC") } | ... | ... |
app/models/project.rb
... | ... | @@ -91,7 +91,7 @@ class Project < ActiveRecord::Base |
91 | 91 | scope :sorted_by_activity, ->() { order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC") } |
92 | 92 | scope :personal, ->(user) { where(namespace_id: user.namespace_id) } |
93 | 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 | 96 | class << self |
97 | 97 | def abandoned | ... | ... |
app/models/snippet.rb
... | ... | @@ -31,9 +31,9 @@ class Snippet < ActiveRecord::Base |
31 | 31 | validates :content, presence: true |
32 | 32 | |
33 | 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 | 38 | def self.content_types |
39 | 39 | [ | ... | ... |
app/models/user.rb
... | ... | @@ -87,10 +87,10 @@ class User < ActiveRecord::Base |
87 | 87 | delegate :path, to: :namespace, allow_nil: true, prefix: true |
88 | 88 | |
89 | 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 | 94 | scope :in_team, ->(team){ where(id: team.member_ids) } |
95 | 95 | scope :not_in_team, ->(team){ where('users.id NOT IN (:ids)', ids: team.member_ids) } |
96 | 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 < ActiveRecord::Base |
32 | 32 | |
33 | 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 | 40 | scope :in_project, ->(project) { where(project_id: project.id) } |
41 | 41 | scope :in_projects, ->(projects) { where(project_id: project_ids) } | ... | ... |