[logaling-commit] logaling/logaling-server [github-project-related-to-user] Extract scope for Membership

Zurück zum Archiv-Index

SHIMADA Koji null+****@clear*****
Tue Sep 25 08:30:45 JST 2012


SHIMADA Koji	2012-09-25 08:30:45 +0900 (Tue, 25 Sep 2012)

  New Revision: 7cc802a9ba1a69296487e43dabac9a011f6ccdbe
  https://github.com/logaling/logaling-server/commit/7cc802a9ba1a69296487e43dabac9a011f6ccdbe

  Log:
    Extract scope for Membership

  Modified files:
    app/models/github_project_membership.rb
    app/models/membership.rb

  Modified: app/models/github_project_membership.rb (+1 -1)
===================================================================
--- app/models/github_project_membership.rb    2012-09-25 01:27:09 +0900 (8fbb847)
+++ app/models/github_project_membership.rb    2012-09-25 08:30:45 +0900 (78631eb)
@@ -34,7 +34,7 @@ class GithubProjectMembership
   end
 
   def user_must_not_belongs_to_github_project_yet
-    unless Membership.where(user_id: user_id).joins(:github_project).merge(GithubProject.where(owner: project_owner, name: project_name)).empty?
+    unless Membership.for(project_owner, project_name).of(user_id).empty?
       errors.add :project_name, "は既に登録されています"
     end
   end

  Modified: app/models/membership.rb (+8 -0)
===================================================================
--- app/models/membership.rb    2012-09-25 01:27:09 +0900 (2234ee8)
+++ app/models/membership.rb    2012-09-25 08:30:45 +0900 (4f9dfba)
@@ -4,4 +4,12 @@ class Membership < ActiveRecord::Base
   accepts_nested_attributes_for :github_project
 
   validates_uniqueness_of :user_id, scope: :github_project_id
+
+  scope :of, lambda {|user|
+    where(user_id: user)
+  }
+
+  scope :for, lambda {|project_owner, project_name|
+    joins(:github_project).merge(GithubProject.where(owner: project_owner, name: project_name))
+  }
 end
-------------- next part --------------
An HTML attachment was scrubbed...
Download 



More information about the logaling-commit mailing list
Zurück zum Archiv-Index