Merge pull request #9 from warpc/groups_repositories_fixes
Fixed bug with duplicate relations and removed unnecessary routes and views part in users and groups, close #4
This commit is contained in:
commit
dc95df1073
|
@ -26,7 +26,7 @@ class GroupsController < ApplicationController
|
|||
|
||||
def show
|
||||
@platforms = @group.platforms.paginate(:page => params[:platform_page], :per_page => 10)
|
||||
@repositories = @group.repositories.paginate(:page => params[:repository_page], :per_page => 10)
|
||||
# @repositories = @group.repositories.paginate(:page => params[:repository_page], :per_page => 10)
|
||||
@projects = @group.projects.paginate(:page => params[:project_page], :per_page => 10)
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ class UsersController < ApplicationController
|
|||
def show
|
||||
@groups = @user.groups.uniq
|
||||
@platforms = @user.platforms.paginate(:page => params[:platform_page], :per_page => 10)
|
||||
@repositories = @user.repositories.paginate(:page => params[:repository_page], :per_page => 10)
|
||||
# @repositories = @user.repositories.paginate(:page => params[:repository_page], :per_page => 10)
|
||||
@projects = @user.projects.paginate(:page => params[:project_page], :per_page => 10)
|
||||
end
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ class Group < ActiveRecord::Base
|
|||
after_create :add_owner_to_members
|
||||
|
||||
include Modules::Models::PersonalRepository
|
||||
include Modules::Models::Owner
|
||||
# include Modules::Models::Owner
|
||||
|
||||
protected
|
||||
def add_owner_to_members
|
||||
|
|
|
@ -5,6 +5,7 @@ class Relation < ActiveRecord::Base
|
|||
ROLES = %w[reader writer admin]
|
||||
validates :role, :inclusion => {:in => ROLES}
|
||||
|
||||
# validate { errors.add(:object, :taken) if Relation.where(:object_type => self.object_type, :object_id => self.object_id).present? }
|
||||
before_validation :add_default_role
|
||||
|
||||
scope :by_object, lambda {|obj| {:conditions => ['object_id = ? AND object_type = ?', obj.id, obj.class.to_s]}}
|
||||
|
|
|
@ -62,9 +62,11 @@ class Repository < ActiveRecord::Base
|
|||
|
||||
def add_admin_relations
|
||||
platform.relations.where(:role => 'admin').each do |rel|
|
||||
r = relations.build(:role => 'admin', :object_type => rel.object_type)
|
||||
r.object_id = rel.object_id
|
||||
r.save
|
||||
if !relations.exists?(:role => 'admin', :object_type => rel.object_type, :object_id => rel.object_id) && rel.object != owner
|
||||
r = relations.build(:role => 'admin', :object_type => rel.object_type)
|
||||
r.object_id = rel.object_id
|
||||
r.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
.actions
|
||||
= will_paginate @platforms, :param_name => :platform_page
|
||||
|
||||
.block
|
||||
-#.block
|
||||
.secondary-navigation
|
||||
%ul.wat-cf
|
||||
%li.first.active= link_to t("layout.repositories.list"), repositories_path
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
.actions
|
||||
= will_paginate @platforms, :param_name => :platform_page
|
||||
|
||||
.block
|
||||
-#.block
|
||||
.secondary-navigation
|
||||
%ul.wat-cf
|
||||
%li.first.active= link_to t("layout.repositories.list"), repositories_path
|
||||
|
|
|
@ -124,7 +124,7 @@ Rosa::Application.routes.draw do
|
|||
|
||||
resources :projects, :only => [:new, :create, :index]
|
||||
|
||||
resources :repositories, :only => [:new, :create]
|
||||
# resources :repositories, :only => [:new, :create]
|
||||
end
|
||||
|
||||
match '/catalogs', :to => 'categories#platforms', :as => :catalogs
|
||||
|
|
|
@ -1,5 +1,21 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Repository do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
|
||||
context 'when create with same owner that platform' do
|
||||
before (:each) do
|
||||
@platform = Factory(:platform)
|
||||
@params = {:name => 'tst_platform', :description => 'test platform'}
|
||||
end
|
||||
|
||||
it 'it should increase Relations.count by 1' do
|
||||
rep = Repository.new(@params)
|
||||
rep.platform = @platform
|
||||
rep.owner = @platform.owner
|
||||
rep.save!
|
||||
Relation.by_object(rep.owner).by_target(rep).count.should eql(1)
|
||||
# (@platform.owner.repositories.where(:platform_id => @platform.id).count == 1).should be_true
|
||||
end
|
||||
end
|
||||
#pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue