From 9a22ac63eca587d5efd56d626b7579236734cda0 Mon Sep 17 00:00:00 2001 From: Andrew8xx8 Date: Tue, 12 Feb 2013 10:54:56 +0400 Subject: [PATCH 1/2] Dynamic values must be in blocks if FG --- spec/factories.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/factories.rb b/spec/factories.rb index 0e0c04f9..ae9066cb 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -123,7 +123,7 @@ FactoryGirl.define do factory :event do factory :closed_issue_event do project - action Event::Closed + action { Event::Closed } target factory: :closed_issue author factory: :user end From b5db541338314b01423d79fb9155e8c4ddc5d494 Mon Sep 17 00:00:00 2001 From: Andrew8xx8 Date: Tue, 12 Feb 2013 11:16:45 +0400 Subject: [PATCH 2/2] All scopes must be in lambdas --- app/models/concerns/issuable.rb | 6 +++--- app/models/event.rb | 4 ++-- app/models/milestone.rb | 4 ++-- app/models/namespace.rb | 2 +- app/models/note.rb | 4 ++-- app/models/project.rb | 2 +- app/models/snippet.rb | 6 +++--- app/models/user.rb | 8 ++++---- app/models/users_project.rb | 8 ++++---- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 8872cf59..645b35ec 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -19,12 +19,12 @@ module Issuable validates :title, presence: true, length: { within: 0..255 } validates :closed, inclusion: { in: [true, false] } - scope :opened, where(closed: false) - scope :closed, where(closed: true) + scope :opened, -> { where(closed: false) } + scope :closed, -> { where(closed: true) } scope :of_group, ->(group) { where(project_id: group.project_ids) } scope :of_user_team, ->(team) { where(project_id: team.project_ids, assignee_id: team.member_ids) } scope :assigned, ->(u) { where(assignee_id: u.id)} - scope :recent, order("created_at DESC") + scope :recent, -> { order("created_at DESC") } delegate :name, :email, diff --git a/app/models/event.rb b/app/models/event.rb index d0ba6154..97b1e330 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -42,8 +42,8 @@ class Event < ActiveRecord::Base serialize :data # Scopes - scope :recent, order("created_at DESC") - scope :code_push, where(action: Pushed) + scope :recent, -> { order("created_at DESC") } + scope :code_push, -> { where(action: Pushed) } scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent } class << self diff --git a/app/models/milestone.rb b/app/models/milestone.rb index 8b4c895d..457fe18f 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -20,8 +20,8 @@ class Milestone < ActiveRecord::Base has_many :issues has_many :merge_requests - scope :active, where(closed: false) - scope :closed, where(closed: true) + scope :active, -> { where(closed: false) } + scope :closed, -> { where(closed: true) } validates :title, presence: true validates :project, presence: true diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 547d383d..4e157839 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -29,7 +29,7 @@ class Namespace < ActiveRecord::Base after_update :move_dir after_destroy :rm_dir - scope :root, where('type IS NULL') + scope :root, -> { where('type IS NULL') } def self.search query where("name LIKE :query OR path LIKE :query", query: "%#{query}%") diff --git a/app/models/note.rb b/app/models/note.rb index ded126b4..97f6bf6e 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -43,8 +43,8 @@ class Note < ActiveRecord::Base # Scopes scope :for_commit_id, ->(commit_id) { where(noteable_type: "Commit", commit_id: commit_id) } - scope :inline, where("line_code IS NOT NULL") - scope :not_inline, where("line_code IS NULL") + scope :inline, -> { where("line_code IS NOT NULL") } + scope :not_inline, -> { where("line_code IS NULL") } scope :common, ->{ where(noteable_type: ["", nil]) } scope :fresh, ->{ order("created_at ASC, id ASC") } diff --git a/app/models/project.rb b/app/models/project.rb index 8c747743..c1e04899 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -91,7 +91,7 @@ class Project < ActiveRecord::Base scope :sorted_by_activity, ->() { order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC") } scope :personal, ->(user) { where(namespace_id: user.namespace_id) } scope :joined, ->(user) { where("namespace_id != ?", user.namespace_id) } - scope :public, where(public: true) + scope :public, -> { where(public: true) } class << self def abandoned diff --git a/app/models/snippet.rb b/app/models/snippet.rb index 806d346c..c4ee35e0 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -31,9 +31,9 @@ class Snippet < ActiveRecord::Base validates :content, presence: true # Scopes - scope :fresh, order("created_at DESC") - scope :non_expired, where(["expires_at IS NULL OR expires_at > ?", Time.current]) - scope :expired, where(["expires_at IS NOT NULL AND expires_at < ?", Time.current]) + scope :fresh, -> { order("created_at DESC") } + scope :non_expired, -> { where(["expires_at IS NULL OR expires_at > ?", Time.current]) } + scope :expired, -> { where(["expires_at IS NOT NULL AND expires_at < ?", Time.current]) } def self.content_types [ diff --git a/app/models/user.rb b/app/models/user.rb index 5b0df09a..8c1a8b42 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -87,10 +87,10 @@ class User < ActiveRecord::Base delegate :path, to: :namespace, allow_nil: true, prefix: true # Scopes - scope :admins, where(admin: true) - scope :blocked, where(blocked: true) - scope :active, where(blocked: false) - scope :alphabetically, order('name ASC') + scope :admins, -> { where(admin: true) } + scope :blocked, -> { where(blocked: true) } + scope :active, -> { where(blocked: false) } + scope :alphabetically, -> { order('name ASC') } scope :in_team, ->(team){ where(id: team.member_ids) } scope :not_in_team, ->(team){ where('users.id NOT IN (:ids)', ids: team.member_ids) } scope :potential_team_members, ->(team) { team.members.any? ? active.not_in_team(team) : active } diff --git a/app/models/users_project.rb b/app/models/users_project.rb index dd8ceb9d..486aaa69 100644 --- a/app/models/users_project.rb +++ b/app/models/users_project.rb @@ -32,10 +32,10 @@ class UsersProject < ActiveRecord::Base delegate :name, :username, :email, to: :user, prefix: true - scope :guests, where(project_access: GUEST) - scope :reporters, where(project_access: REPORTER) - scope :developers, where(project_access: DEVELOPER) - scope :masters, where(project_access: MASTER) + scope :guests, -> { where(project_access: GUEST) } + scope :reporters, -> { where(project_access: REPORTER) } + scope :developers, -> { where(project_access: DEVELOPER) } + scope :masters, -> { where(project_access: MASTER) } scope :in_project, ->(project) { where(project_id: project.id) } scope :in_projects, ->(projects) { where(project_id: project_ids) }