From de093d7065aa19e46a2b18555af9968e7e5ba5ae Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Thu, 26 Apr 2012 05:38:33 +0400 Subject: [PATCH] [issue #425] Changed object to actor in Relation and to eventable in EventLog --- app/controllers/members_controller.rb | 12 +++---- app/controllers/platforms_controller.rb | 8 ++--- app/helpers/projects_helper.rb | 2 +- app/models/ability.rb | 30 ++++++++--------- app/models/collaborator.rb | 12 +++---- app/models/comment.rb | 2 +- app/models/event_log.rb | 4 +-- app/models/event_log_observer.rb | 8 ++--- app/models/group.rb | 12 +++---- app/models/issue.rb | 2 +- app/models/platform.rb | 8 ++--- app/models/project.rb | 6 ++-- app/models/relation.rb | 14 ++++---- app/models/user.rb | 4 +-- app/views/collaborators/edit.html.haml | 4 +-- app/views/event_logs/_description.html.haml | 8 ++--- app/views/members/edit.html.haml | 2 +- config/initializers/notifications.rb | 10 +++--- ...4830_change_object_to_actor_in_relation.rb | 15 +++++++++ ...change_object_to_eventable_in_event_log.rb | 17 ++++++++++ db/schema.rb | 32 +++++++++---------- lib/modules/models/acts_like_member.rb | 4 +-- lib/modules/models/owner.rb | 2 +- .../build_lists_controller_spec.rb | 14 ++++---- .../collaborators_controller_spec.rb | 12 +++---- .../comments_controller_for_commit_spec.rb | 6 ++-- spec/controllers/comments_controller_spec.rb | 6 ++-- spec/controllers/groups_controller_spec.rb | 6 ++-- spec/controllers/issues_controller_spec.rb | 8 ++--- spec/controllers/members_controller_spec.rb | 4 +-- spec/controllers/platforms_controller_spec.rb | 4 +-- .../product_build_lists_controller_spec.rb | 2 +- spec/controllers/products_controller_spec.rb | 2 +- spec/controllers/projects_controller_spec.rb | 8 ++--- .../repositories_controller_spec.rb | 2 +- .../controllers/subscribes_controller_spec.rb | 2 +- spec/models/cancan_spec.rb | 12 +++---- spec/models/comment_for_commit_spec.rb | 2 +- spec/models/comment_spec.rb | 4 +-- spec/models/group_spec.rb | 6 ++-- 40 files changed, 175 insertions(+), 143 deletions(-) create mode 100644 db/migrate/20120425174830_change_object_to_actor_in_relation.rb create mode 100644 db/migrate/20120425190938_change_object_to_eventable_in_event_log.rb diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 9d9f8ce1f..d31b35a50 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -33,10 +33,10 @@ class MembersController < ApplicationController params['user'].keys.each { |user_id| role = params['user'][user_id] - if relation = parent.objects.find_by_object_id_and_object_type(user_id, 'User') + if relation = parent.actors.where(:actor_id => user_id, :actor_type => 'User') #find_by_actor_id_and_actor_type(user_id, 'User') relation.update_attribute(:role, role) else - relation = parent.objects.build(:object_id => user_id, :object_type => 'User', :role => role) + relation = parent.actors.build(:actor_id => user_id, :actor_type => 'User', :role => role) relation.save! end } if params['user'] @@ -53,7 +53,7 @@ class MembersController < ApplicationController def remove if params[:id] u = User.find(params[:id]) - Relation.by_object(u).by_target(parent)[0].destroy + Relation.by_actor(u).by_target(parent)[0].destroy redirect_to groups_path else @@ -65,7 +65,7 @@ class MembersController < ApplicationController all_user_ids.each do |user_id| u = User.find(user_id) - Relation.by_object(u).by_target(parent).each {|r| r.destroy} + Relation.by_actor(u).by_target(parent).each {|r| r.destroy} end redirect_to edit_group_members_path(parent) @@ -75,8 +75,8 @@ class MembersController < ApplicationController def add if params['user_id'] and !params['user_id'].empty? @user = User.find_by_uname(params['user_id']) - unless parent.objects.exists? :object_id => @user.id, :object_type => 'User' - relation = parent.objects.build(:object_id => @user.id, :object_type => 'User', :role => params[:role]) + unless parent.actors.exists? :actor_id => @user.id, :actor_type => 'User' + relation = parent.actors.build(:actor_id => @user.id, :actor_type => 'User', :role => params[:role]) if relation.save flash[:notice] = t("flash.members.successfully_added") else diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index 360b7a280..7ef625831 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -95,14 +95,14 @@ class PlatformsController < ApplicationController def remove_members all_user_ids = params['user_remove'].inject([]) {|a, (k, v)| a << k if v.first == '1'; a} all_user_ids.each do |uid| - Relation.by_target(@platform).where(:object_id => uid, :object_type => 'User').each{|r| r.destroy} + Relation.by_target(@platform).where(:actor_id => uid, :actor_type => 'User').each{|r| r.destroy} end redirect_to members_platform_path(@platform) end def remove_member u = User.find(params[:member_id]) - Relation.by_object(u).by_target(@platform).each{|r| r.destroy} + Relation.by_actor(u).by_target(@platform).each{|r| r.destroy} redirect_to members_platform_path(@platform) end @@ -110,11 +110,11 @@ class PlatformsController < ApplicationController def add_member if params[:member_id].present? member = User.find(params[:member_id]) - if @platform.relations.exists?(:object_id => member.id, :object_type => member.class.to_s) or @platform.owner == member + if @platform.relations.exists?(:actor_id => member.id, :actor_type => member.class.to_s) or @platform.owner == member flash[:warning] = t('flash.platform.members.already_added', :name => member.uname) else rel = @platform.relations.build(:role => 'admin') - rel.object = member + rel.actor = member if rel.save flash[:notice] = t('flash.platform.members.successfully_added', :name => member.uname) else diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 653b5fa9b..40ddb89a2 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -28,7 +28,7 @@ module ProjectsHelper end def alone_member?(project) - Relation.by_target(project).by_object(current_user).size > 0 + Relation.by_target(project).by_actor(current_user).size > 0 end def participant_path(participant) diff --git a/app/models/ability.rb b/app/models/ability.rb index 4002c3a68..9eace670a 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -46,7 +46,7 @@ class Ability can [:read, :create, :autocomplete_group_uname], Group can [:update, :manage_members], Group do |group| - group.objects.exists?(:object_type => 'User', :object_id => user.id, :role => 'admin') # or group.owner_id = user.id + group.actors.exists?(:actor_type => 'User', :actor_id => user.id, :role => 'admin') # or group.owner_id = user.id end can :destroy, Group, :owner_id => user.id @@ -60,7 +60,7 @@ class Ability can(:fork, Project) {|project| can? :read, project} can(:fork_to_group, Project) {|project| project.owner_type == 'Group' and can? :update, project.owner} can(:destroy, Project) {|project| owner? project} - can(:destroy, Project) {|project| project.owner_type == 'Group' and project.owner.objects.exists?(:object_type => 'User', :object_id => user.id, :role => 'admin')} + can(:destroy, Project) {|project| project.owner_type == 'Group' and project.owner.actors.exists?(:actor_type => 'User', :actor_id => user.id, :role => 'admin')} can :remove_user, Project can [:read, :owned], BuildList, :user_id => user.id @@ -143,28 +143,28 @@ class Ability parent ||= table ["#{table}.#{key} IN ( SELECT target_id FROM relations WHERE relations.target_type = ? AND - (relations.object_type = 'User' AND relations.object_id = ? OR - relations.object_type = 'Group' AND relations.object_id IN (?)))", parent.classify, @user, @user.group_ids] + (relations.actor_type = 'User' AND relations.actor_id = ? OR + relations.actor_type = 'Group' AND relations.actor_id IN (?)))", parent.classify, @user, @user.group_ids] end - def relation_exists_for(object, roles) - object.relations.exists?(:object_id => @user.id, :object_type => 'User', :role => roles) or - object.relations.exists?(:object_id => @user.group_ids, :object_type => 'Group', :role => roles) + def relation_exists_for(target, roles) + target.relations.exists?(:actor_id => @user.id, :actor_type => 'User', :role => roles) or + target.relations.exists?(:actor_id => @user.group_ids, :actor_type => 'Group', :role => roles) end - def local_reader?(object) - relation_exists_for(object, %w{reader writer admin}) or owner?(object) + def local_reader?(target) + relation_exists_for(target, %w{reader writer admin}) or owner?(target) end - def local_writer?(object) - relation_exists_for(object, %w{writer admin}) or owner?(object) + def local_writer?(target) + relation_exists_for(target, %w{writer admin}) or owner?(target) end - def local_admin?(object) - relation_exists_for(object, 'admin') or owner?(object) + def local_admin?(target) + relation_exists_for(target, 'admin') or owner?(target) end - def owner?(object) - object.owner == @user or @user.own_groups.include?(object.owner) + def owner?(target) + target.owner == @user or @user.own_groups.include?(target.owner) end end diff --git a/app/models/collaborator.rb b/app/models/collaborator.rb index e8b31bfc7..c0b0e35af 100644 --- a/app/models/collaborator.rb +++ b/app/models/collaborator.rb @@ -17,7 +17,7 @@ class Collaborator def find_by_project(project) res = [] project.relations.each do |r| - res << from_relation(r) unless project.owner_id == r.object_id and project.owner_type == r.object_type + res << from_relation(r) unless project.owner_id == r.actor_id and project.owner_type == r.actor_type end return res end @@ -64,7 +64,7 @@ class Collaborator def relation=(model) @relation = model - @actor = @relation.object + @actor = @relation.actor @project = @relation.target end @@ -134,15 +134,15 @@ class Collaborator end def relation - return @relation if @relation.present? and @relation.object == @actor and @relation.target == @project + return @relation if @relation.present? and @relation.actor == @actor and @relation.target == @project if @actor.present? and @project.present? - @relation = Relation.by_object(@actor).by_target(@project).limit(1).first - @relation ||= Relation.new(:object_id => @actor.id, :object_type => @actor.class.to_s, + @relation = Relation.by_actor(@actor).by_target(@project).limit(1).first + @relation ||= Relation.new(:actor_id => @actor.id, :actor_type => @actor.class.to_s, :target_id => @project.id, :target_type => 'Project') else @relation = Relation.new - @relation.object = @actor + @relation.actor = @actor @relation.target = @project end @relation diff --git a/app/models/comment.rb b/app/models/comment.rb index 241cde404..e5c22c36f 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -61,7 +61,7 @@ class Comment < ActiveRecord::Base if issue_comment? commentable.subscribes.create(:user => user) if !commentable.subscribes.exists?(:user_id => user.id) elsif commit_comment? - recipients = project.relations.by_role('admin').where(:object_type => 'User').map &:object # admins + recipients = project.relations.by_role('admin').where(:actor_type => 'User').map &:actor # admins recipients << user << User.where(:email => commentable.committer.email).first # commentor and committer recipients << project.owner if project.owner_type == 'User' # project owner recipients.compact.uniq.each do |user| diff --git a/app/models/event_log.rb b/app/models/event_log.rb index ca3607a82..b2a1322fd 100644 --- a/app/models/event_log.rb +++ b/app/models/event_log.rb @@ -1,7 +1,7 @@ # -*- encoding : utf-8 -*- class EventLog < ActiveRecord::Base belongs_to :user - belongs_to :object, :polymorphic => true + belongs_to :eventable, :polymorphic => true # self.per_page = 1 @@ -10,7 +10,7 @@ class EventLog < ActiveRecord::Base before_create do self.user_name = user.try(:uname) || 'guest' - self.object_name ||= object.name if object.respond_to?(:name) + self.eventable_name ||= eventable.name if eventable.respond_to?(:name) end # after_create { self.class.current_controller = nil } diff --git a/app/models/event_log_observer.rb b/app/models/event_log_observer.rb index 1518ef9fd..1a6c1437c 100644 --- a/app/models/event_log_observer.rb +++ b/app/models/event_log_observer.rb @@ -3,24 +3,24 @@ class EventLogObserver < ActiveRecord::Observer observe :user, :private_user, :platform, :repository, :project, :product, :build_list, :product_build_list def after_create(record) - ActiveSupport::Notifications.instrument("event_log.observer", :object => record) + ActiveSupport::Notifications.instrument("event_log.observer", :eventable => record) end def before_update(record) case record.class.to_s when 'BuildList' if record.status_changed? and [BuildList::BUILD_CANCELED, BuildList::BUILD_PUBLISHED].include?(record.status) - ActiveSupport::Notifications.instrument("event_log.observer", :object => record) + ActiveSupport::Notifications.instrument("event_log.observer", :eventable => record) end when 'Platform' if record.visibility_changed? - ActiveSupport::Notifications.instrument "event_log.observer", :object => record, + ActiveSupport::Notifications.instrument "event_log.observer", :eventable => record, :message => I18n.t("activerecord.attributes.platform.visibility_types.#{record.visibility}") end end end def after_destroy(record) - ActiveSupport::Notifications.instrument("event_log.observer", :object => record) + ActiveSupport::Notifications.instrument("event_log.observer", :eventable => record) end end diff --git a/app/models/group.rb b/app/models/group.rb index 393069884..0f34d2c6c 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -2,12 +2,12 @@ class Group < ActiveRecord::Base belongs_to :owner, :class_name => 'User' - has_many :relations, :as => :object, :dependent => :destroy - has_many :objects, :as => :target, :class_name => 'Relation' - has_many :targets, :as => :object, :class_name => 'Relation' + has_many :relations, :as => :actor, :dependent => :destroy + has_many :actors, :as => :target, :class_name => 'Relation' + has_many :targets, :as => :actor, :class_name => 'Relation' - has_many :members, :through => :objects, :source => :object, :source_type => 'User', :autosave => true - has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true + has_many :members, :through => :actors, :source => :actor, :source_type => 'User', :autosave => true + has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true has_many :own_projects, :as => :owner, :class_name => 'Project', :dependent => :destroy has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy @@ -18,7 +18,7 @@ class Group < ActiveRecord::Base scope :opened, where('1=1') scope :by_owner, lambda {|owner| where(:owner_id => owner.id)} - scope :by_admin, lambda {|admin| joins(:objects).where(:'relations.role' => 'admin', :'relations.object_id' => admin.id, :'relations.object_type' => 'User')} + scope :by_admin, lambda {|admin| joins(:actors).where(:'relations.role' => 'admin', :'relations.actor_id' => admin.id, :'relations.actor_type' => 'User')} include Modules::Models::ActsLikeMember diff --git a/app/models/issue.rb b/app/models/issue.rb index 11f6d9849..628970e35 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -54,7 +54,7 @@ class Issue < ActiveRecord::Base end def collect_recipient_ids - recipients = self.project.relations.by_role('admin').where(:object_type => 'User').map { |rel| rel.read_attribute(:object_id) } + recipients = self.project.relations.by_role('admin').where(:actor_type => 'User').map { |rel| rel.read_attribute(:actor_id) } recipients = recipients | [self.assignee_id] if self.assignee_id recipients = recipients | [self.project.owner_id] if self.project.owner_type == 'User' diff --git a/app/models/platform.rb b/app/models/platform.rb index 85d799606..8c86044bc 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -10,8 +10,8 @@ class Platform < ActiveRecord::Base has_many :products, :dependent => :destroy has_many :relations, :as => :target, :dependent => :destroy - has_many :objects, :as => :target, :class_name => 'Relation', :dependent => :destroy - has_many :members, :through => :objects, :source => :object, :source_type => 'User' + has_many :actors, :as => :target, :class_name => 'Relation', :dependent => :destroy + has_many :members, :through => :actors, :source => :actor, :source_type => 'User' validates :description, :presence => true validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES} @@ -148,8 +148,8 @@ class Platform < ActiveRecord::Base def update_owner_relation if owner_id_was != owner_id - r = relations.where(:object_id => owner_id_was, :object_type => owner_type_was)[0] - r.update_attributes(:object_id => owner_id, :object_type => owner_type) + r = relations.where(:actor_id => owner_id_was, :actor_type => owner_type_was)[0] + r.update_attributes(:actor_id => owner_id, :actor_type => owner_type) end end diff --git a/app/models/project.rb b/app/models/project.rb index a4308160b..5049446a0 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -13,8 +13,8 @@ class Project < ActiveRecord::Base has_many :repositories, :through => :project_to_repositories has_many :relations, :as => :target, :dependent => :destroy - has_many :collaborators, :through => :relations, :source => :object, :source_type => 'User' - has_many :groups, :through => :relations, :source => :object, :source_type => 'Group' + has_many :collaborators, :through => :relations, :source => :actor, :source_type => 'User' + has_many :groups, :through => :relations, :source => :actor, :source_type => 'Group' has_many :labels validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false}, :presence => true, :format => {:with => /^[a-zA-Z0-9_\-\+\.]+$/} @@ -206,7 +206,7 @@ class Project < ActiveRecord::Base end def owner_and_admin_ids - recipients = self.relations.by_role('admin').where(:object_type => 'User').map { |rel| rel.read_attribute(:object_id) } + recipients = self.relations.by_role('admin').where(:actor_type => 'User').map { |rel| rel.read_attribute(:actor_id) } recipients = recipients | [self.owner_id] if self.owner_type == 'User' recipients end diff --git a/app/models/relation.rb b/app/models/relation.rb index 9b2494f5c..5e5e5bb5e 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -1,22 +1,22 @@ # -*- encoding : utf-8 -*- class Relation < ActiveRecord::Base belongs_to :target, :polymorphic => true - belongs_to :object, :polymorphic => true + belongs_to :actor, :polymorphic => true 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? } +# validate { errors.add(:actor, :taken) if Relation.where(:actor_type => self.actor_type, :actor_id => self.actor_id).present? } before_validation :add_default_role - scope :by_user_through_groups, lambda {|u| where("object_type = 'User' AND object_id = ? OR object_type = 'Group' AND object_id IN (?)", u.id, u.group_ids)} - scope :by_object, lambda {|obj| {:conditions => ['object_id = ? AND object_type = ?', obj.id, obj.class.to_s]}} + scope :by_user_through_groups, lambda {|u| where("actor_type = 'User' AND actor_id = ? OR actor_type = 'Group' AND actor_id IN (?)", u.id, u.group_ids)} + scope :by_actor, lambda {|obj| {:conditions => ['actor_id = ? AND actor_type = ?', obj.id, obj.class.to_s]}} scope :by_target, lambda {|tar| {:conditions => ['target_id = ? AND target_type = ?', tar.id, tar.class.to_s]}} scope :by_role, lambda {|role| {:conditions => ['role = ?', role]}} - def self.create_with_role(object, target, role) - r = new - r.object = object + def self.create_with_role(actor, target, role) + r = self.new + r.actor = actor r.target = target r.role = role r.save diff --git a/app/models/user.rb b/app/models/user.rb index 5803ef8f2..8ddbbaad7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -24,8 +24,8 @@ class User < ActiveRecord::Base has_many :subscribes, :foreign_key => :user_id, :dependent => :destroy has_many :comments, :dependent => :destroy - has_many :relations, :as => :object, :dependent => :destroy - has_many :targets, :as => :object, :class_name => 'Relation', :dependent => :destroy + has_many :relations, :as => :actor, :dependent => :destroy + has_many :targets, :as => :actor, :class_name => 'Relation', :dependent => :destroy has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true has_many :groups, :through => :targets, :source => :target, :source_type => 'Group', :autosave => true diff --git a/app/views/collaborators/edit.html.haml b/app/views/collaborators/edit.html.haml index 5bec1f005..70f620314 100644 --- a/app/views/collaborators/edit.html.haml +++ b/app/views/collaborators/edit.html.haml @@ -39,7 +39,7 @@ - Relation::ROLES.each_with_index do |role, i| %td .radio - = radio_button_tag "user[#{user.id}]", role, ((@project.relations.exists? :object_id => user.id, :object_type => 'User', :role => role) ? :checked : nil), :class => 'niceRadio' + = radio_button_tag "user[#{user.id}]", role, ((@project.relations.exists? :actor_id => user.id, :actor_type => 'User', :role => role) ? :checked : nil), :class => 'niceRadio' .forradio= t("layout.collaborators.role_names.#{ role }") = link_to_function t("layout.delete_selected"), "deleteAdminMember();", :class => 'button' = link_to_function t("layout.save"), "saveAdminMember();", :class => 'button right_floated' @@ -84,7 +84,7 @@ - Relation::ROLES.each_with_index do |role, i| %td .radio - = radio_button_tag "group[#{group.id}]", role, ((@project.relations.exists? :object_id => group.id, :object_type => 'Group', :role => role) ? :checked : nil), :class => 'niceRadio' + = radio_button_tag "group[#{group.id}]", role, ((@project.relations.exists? :actor_id => group.id, :actor_type => 'Group', :role => role) ? :checked : nil), :class => 'niceRadio' .forradio= t("layout.collaborators.role_names.#{ role }") = link_to_function t("layout.delete_selected"), "deleteAdminGroup();", :class => 'button' = link_to_function t("layout.save"), "saveAdminGroup();", :class => 'button right_floated' diff --git a/app/views/event_logs/_description.html.haml b/app/views/event_logs/_description.html.haml index eb6f9d25f..5f8359787 100644 --- a/app/views/event_logs/_description.html.haml +++ b/app/views/event_logs/_description.html.haml @@ -1,8 +1,8 @@ = surround '[', ']' do = I18n.t "event_log.controllers.#{el.controller.underscore}", :default => el.controller = I18n.t "event_log.actions.#{el.controller.underscore}.#{el.action}", :default => :"event_log.actions.#{el.action}" -- if el.object_id.present? and el.object_type.present? - = I18n.t "activerecord.models.#{el.object_type.underscore}" - = el.object_name - = "(id##{el.object_id})" # link_to "id##{el.object_id}", el.object +- if el.eventable_id.present? and el.eventable_type.present? + = I18n.t "activerecord.models.#{el.eventable_type.underscore}" + = el.eventable_name + = "(id##{el.eventable_id})" # link_to "id##{el.eventable_id}", el.eventable = el.message diff --git a/app/views/members/edit.html.haml b/app/views/members/edit.html.haml index 81648bbaa..db09dab07 100644 --- a/app/views/members/edit.html.haml +++ b/app/views/members/edit.html.haml @@ -23,7 +23,7 @@ - Relation::ROLES.each_with_index do |role, i| %td .radio - = radio_button_tag "user[#{user.id}]", role, ((parent.objects.exists? :object_id => user.id, :object_type => 'User', :role => role) ? :checked : nil), :class => 'niceRadio' + = radio_button_tag "user[#{user.id}]", role, ((parent.actors.exists? :actor_id => user.id, :actor_type => 'User', :role => role) ? :checked : nil), :class => 'niceRadio' .forradio= t("layout.collaborators.role_names.#{ role }") = link_to_function t("layout.delete"), "deleteAdminMember();", :class => 'button' .both diff --git a/config/initializers/notifications.rb b/config/initializers/notifications.rb index 75d0ebba1..0988fe186 100644 --- a/config/initializers/notifications.rb +++ b/config/initializers/notifications.rb @@ -1,6 +1,6 @@ # -*- encoding : utf-8 -*- Warden::Manager.after_authentication do |user,auth,opts| # after_set_user, :except => fetch - ActiveSupport::Notifications.instrument("event_log.observer", :object => user) + ActiveSupport::Notifications.instrument("event_log.observer", :eventable => user) end Warden::Manager.before_failure do |env, opts| @@ -10,14 +10,14 @@ Warden::Manager.before_failure do |env, opts| end Warden::Manager.before_logout do |user,auth,opts| - ActiveSupport::Notifications.instrument("event_log.observer", :object => user) + ActiveSupport::Notifications.instrument("event_log.observer", :eventable => user) end ActiveSupport::Notifications.subscribe "event_log.observer" do |name, start, finish, id, payload| if c = EventLog.current_controller - object = payload[:object] - message = payload[:message].presence; message ||= object.event_log_message if object.respond_to?(:event_log_message) + eventable = payload[:eventable] + message = payload[:message].presence; message ||= eventable.event_log_message if eventable.respond_to?(:event_log_message) EventLog.create_with_current_controller :kind => (payload[:kind].presence || 'info'), :message => message, - :object => object, :object_name => payload[:object_name].presence + :eventable => eventable, :eventable_name => payload[:eventable_name].presence end end diff --git a/db/migrate/20120425174830_change_object_to_actor_in_relation.rb b/db/migrate/20120425174830_change_object_to_actor_in_relation.rb new file mode 100644 index 000000000..68343b17f --- /dev/null +++ b/db/migrate/20120425174830_change_object_to_actor_in_relation.rb @@ -0,0 +1,15 @@ +class ChangeObjectToActorInRelation < ActiveRecord::Migration + def up + change_table :relations do |t| + t.rename :object_id, :actor_id + t.rename :object_type, :actor_type + end + end + + def down + change_table :relations do |t| + t.rename :actor_id, :object_id + t.rename :actor_type, :object_type + end + end +end diff --git a/db/migrate/20120425190938_change_object_to_eventable_in_event_log.rb b/db/migrate/20120425190938_change_object_to_eventable_in_event_log.rb new file mode 100644 index 000000000..0bc01a01f --- /dev/null +++ b/db/migrate/20120425190938_change_object_to_eventable_in_event_log.rb @@ -0,0 +1,17 @@ +class ChangeObjectToEventableInEventLog < ActiveRecord::Migration + def up + change_table :event_logs do |t| + t.rename :object_id, :eventable_id + t.rename :object_type, :eventable_type + t.rename :object_name, :eventable_name + end + end + + def down + change_table :event_logs do |t| + t.rename :eventable_id, :object_id + t.rename :eventable_type, :object_type + t.rename :eventable_name, :object_name + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 0b20e0d3a..0773d879d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,14 +11,14 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120418100619) do +ActiveRecord::Schema.define(:version => 20120425190938) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false t.string "kind" t.text "data" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "arches", :force => true do |t| @@ -112,9 +112,9 @@ ActiveRecord::Schema.define(:version => 20120418100619) do create_table "event_logs", :force => true do |t| t.integer "user_id" t.string "user_name" - t.integer "object_id" - t.string "object_type" - t.string "object_name" + t.integer "eventable_id" + t.string "eventable_type" + t.string "eventable_name" t.string "ip" t.string "kind" t.string "protocol" @@ -262,24 +262,25 @@ ActiveRecord::Schema.define(:version => 20120418100619) do t.integer "build_count", :default => 0, :null => false end + add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false + create_table "register_requests", :force => true do |t| t.string "name" t.string "email" t.string "token" t.boolean "approved", :default => false t.boolean "rejected", :default => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "interest" t.text "more" end add_index "register_requests", ["email"], :name => "index_register_requests_on_email", :unique => true, :case_sensitive => false - add_index "register_requests", ["token"], :name => "index_register_requests_on_token", :unique => true, :case_sensitive => false create_table "relations", :force => true do |t| - t.integer "object_id" - t.string "object_type" + t.integer "actor_id" + t.string "actor_type" t.integer "target_id" t.string "target_type" t.datetime "created_at" @@ -323,19 +324,15 @@ ActiveRecord::Schema.define(:version => 20120418100619) do t.string "name" t.string "email", :default => "", :null => false t.string "encrypted_password", :limit => 128, :default => "", :null => false - t.string "password_salt", :default => "", :null => false t.string "reset_password_token" + t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.datetime "created_at" t.datetime "updated_at" t.string "uname" t.string "role" t.string "language", :default => "en" - t.string "confirmation_token" - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" t.integer "own_projects_count", :default => 0, :null => false - t.datetime "reset_password_sent_at" t.text "professional_experience" t.string "site" t.string "company" @@ -347,6 +344,9 @@ ActiveRecord::Schema.define(:version => 20120418100619) do t.integer "failed_attempts", :default => 0 t.string "unlock_token" t.datetime "locked_at" + t.string "confirmation_token" + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" t.string "authentication_token" end diff --git a/lib/modules/models/acts_like_member.rb b/lib/modules/models/acts_like_member.rb index 0db4dd577..a8de53425 100644 --- a/lib/modules/models/acts_like_member.rb +++ b/lib/modules/models/acts_like_member.rb @@ -8,10 +8,10 @@ module Modules scope :not_member_of, lambda { |item| where(" #{klass.table_name}.id NOT IN ( - SELECT relations.object_id + SELECT relations.actor_id FROM relations WHERE ( - relations.object_type = '#{klass.to_s}' + relations.actor_type = '#{klass.to_s}' AND relations.target_type = '#{item.class.to_s}' AND relations.target_id = #{item.id} ) diff --git a/lib/modules/models/owner.rb b/lib/modules/models/owner.rb index 06ca7fa9b..b92a067be 100644 --- a/lib/modules/models/owner.rb +++ b/lib/modules/models/owner.rb @@ -5,7 +5,7 @@ module Modules extend ActiveSupport::Concern included do - after_create lambda { relations.create :object_id => owner.id, :object_type => owner.class.to_s, :role => 'admin' } + after_create lambda { relations.create :actor_id => owner.id, :actor_type => owner.class.to_s, :role => 'admin' } end module ClassMethods diff --git a/spec/controllers/build_lists_controller_spec.rb b/spec/controllers/build_lists_controller_spec.rb index 899c064d2..b42eb08d0 100644 --- a/spec/controllers/build_lists_controller_spec.rb +++ b/spec/controllers/build_lists_controller_spec.rb @@ -103,7 +103,7 @@ describe BuildListsController do @owner_user = @project.owner @member_user = FactoryGirl.create(:user) rel = @project.relations.build(:role => 'reader') - rel.object = @member_user + rel.actor = @member_user rel.save @user = FactoryGirl.create(:user) set_session_for(@user) @@ -116,7 +116,7 @@ describe BuildListsController do @build_list2 = FactoryGirl.create(:build_list_core, :project => FactoryGirl.create(:project, :visibility => 'hidden')) @build_list3 = FactoryGirl.create(:build_list_core, :project => FactoryGirl.create(:project, :owner => @user, :visibility => 'hidden')) @build_list4 = FactoryGirl.create(:build_list_core, :project => FactoryGirl.create(:project, :visibility => 'hidden')) - @build_list4.project.relations.create :role => 'reader', :object_id => @user.id, :object_type => 'User' + @build_list4.project.relations.create :role => 'reader', :actor_id => @user.id, :actor_type => 'User' end it 'should be able to perform index action' do @@ -177,17 +177,17 @@ describe BuildListsController do before(:each) do @owner_group = FactoryGirl.create(:group) @owner_user = FactoryGirl.create(:user) - @owner_group.objects.create :role => 'reader', :object_id => @owner_user.id, :object_type => 'User' + @owner_group.actors.create :role => 'reader', :actor_id => @owner_user.id, :actor_type => 'User' @member_group = FactoryGirl.create(:group) @member_user = FactoryGirl.create(:user) - @member_group.objects.create :role => 'reader', :object_id => @member_user.id, :object_type => 'User' + @member_group.actors.create :role => 'reader', :actor_id => @member_user.id, :actor_type => 'User' @group = FactoryGirl.create(:group) @user = FactoryGirl.create(:user) - @group.objects.create :role => 'reader', :object_id => @user.id, :object_type => 'User' + @group.actors.create :role => 'reader', :actor_id => @user.id, :actor_type => 'User' @project = FactoryGirl.create(:project, :owner => @owner_group) - @project.relations.create :role => 'reader', :object_id => @member_group.id, :object_type => 'Group' + @project.relations.create :role => 'reader', :actor_id => @member_group.id, :actor_type => 'Group' @build_list = FactoryGirl.create(:build_list_core, :project => @project) @@ -201,7 +201,7 @@ describe BuildListsController do @build_list2 = FactoryGirl.create(:build_list_core, :project => FactoryGirl.create(:project, :visibility => 'hidden')) @build_list3 = FactoryGirl.create(:build_list_core, :project => FactoryGirl.create(:project, :owner => @group, :visibility => 'hidden')) @build_list4 = FactoryGirl.create(:build_list_core, :project => FactoryGirl.create(:project, :visibility => 'hidden')) - @build_list4.project.relations.create :role => 'reader', :object_id => @group.id, :object_type => 'Group' + @build_list4.project.relations.create :role => 'reader', :actor_id => @group.id, :actor_type => 'Group' end it 'should be able to perform index action' do diff --git a/spec/controllers/collaborators_controller_spec.rb b/spec/controllers/collaborators_controller_spec.rb index b8781ba28..bee7f4187 100644 --- a/spec/controllers/collaborators_controller_spec.rb +++ b/spec/controllers/collaborators_controller_spec.rb @@ -31,12 +31,12 @@ shared_examples_for 'project admin user' do it 'should add new collaborator with reader role' do post :create, @create_params.merge(:collaborator => @user_params) - @project.relations.exists?(:object_type => 'User', :object_id => @another_user.id, :role => 'reader').should be_true + @project.relations.exists?(:actor_type => 'User', :actor_id => @another_user.id, :role => 'reader').should be_true end it 'should add new group with reader role' do post :create, @create_params.merge(:collaborator => @group_params) - @project.relations.exists?(:object_type => 'Group', :object_id => @group.id, :role => 'reader').should be_true + @project.relations.exists?(:actor_type => 'Group', :actor_id => @group.id, :role => 'reader').should be_true end it 'should be able to set reader role for any user' do @@ -102,7 +102,7 @@ describe CollaboratorsController do # @user.relations set_session_for(@user) @group = FactoryGirl.create(:group) - @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') + @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') create_params end @@ -117,7 +117,7 @@ describe CollaboratorsController do @group = FactoryGirl.create(:group) @project.update_attribute(:owner, @user) - @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') + @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') create_params end @@ -129,7 +129,7 @@ describe CollaboratorsController do before(:each) do @user = FactoryGirl.create(:user) set_session_for(@user) - @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') + @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader') end it_should_behave_like 'user with no rights for this project' @@ -139,7 +139,7 @@ describe CollaboratorsController do before(:each) do @user = FactoryGirl.create(:user) set_session_for(@user) - @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer') + @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'writer') end it_should_behave_like 'user with no rights for this project' diff --git a/spec/controllers/comments_controller_for_commit_spec.rb b/spec/controllers/comments_controller_for_commit_spec.rb index d0be49110..6f646eae7 100644 --- a/spec/controllers/comments_controller_for_commit_spec.rb +++ b/spec/controllers/comments_controller_for_commit_spec.rb @@ -93,7 +93,7 @@ describe CommentsController do context 'for project admin user' do before(:each) do - @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') + @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') end it_should_behave_like 'user with create comment rights for commits' @@ -119,7 +119,7 @@ describe CommentsController do context 'for project reader user' do before(:each) do - @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') + @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader') end it_should_behave_like 'user with create comment rights for commits' @@ -130,7 +130,7 @@ describe CommentsController do context 'for project writer user' do before(:each) do - @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer') + @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'writer') end it_should_behave_like 'user with create comment rights for commits' diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index d6c7c71d3..01b3c468f 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -90,7 +90,7 @@ describe CommentsController do context 'for project admin user' do before(:each) do - @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') + @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') end it_should_behave_like 'user with create comment rights' @@ -112,7 +112,7 @@ describe CommentsController do context 'for project reader user' do before(:each) do - @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') + @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader') end it_should_behave_like 'user with create comment rights' @@ -123,7 +123,7 @@ describe CommentsController do context 'for project writer user' do before(:each) do - @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer') + @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'writer') end it_should_behave_like 'user with create comment rights' diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index cafbaee12..68db4bbf4 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -117,7 +117,7 @@ describe GroupsController do before(:each) do @user = FactoryGirl.create(:user) set_session_for(@user) - @group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'admin') + @group.actors.create(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') end it_should_behave_like 'update_member_relation' @@ -130,7 +130,7 @@ describe GroupsController do @user = FactoryGirl.create(:user) set_session_for(@user) @group.update_attribute(:owner, @user) - @group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'admin') + @group.actors.create(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') end it_should_behave_like 'update_member_relation' @@ -141,7 +141,7 @@ describe GroupsController do before(:each) do @user = FactoryGirl.create(:user) set_session_for(@user) - @group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'reader') + @group.actors.create(:actor_type => 'User', :actor_id => @user.id, :role => 'reader') end it_should_behave_like 'no group user' diff --git a/spec/controllers/issues_controller_spec.rb b/spec/controllers/issues_controller_spec.rb index 2816ccd1e..9a52e8fe6 100644 --- a/spec/controllers/issues_controller_spec.rb +++ b/spec/controllers/issues_controller_spec.rb @@ -115,7 +115,7 @@ describe IssuesController do before(:each) do @user = FactoryGirl.create(:user) set_session_for(@user) - @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') + @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') end it_should_behave_like 'issue user with project reader rights' @@ -130,7 +130,7 @@ describe IssuesController do @user = FactoryGirl.create(:user) set_session_for(@user) @project.update_attribute(:owner, @user) - @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') + @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') end it_should_behave_like 'issue user with project reader rights' @@ -144,7 +144,7 @@ describe IssuesController do before(:each) do @user = FactoryGirl.create(:user) set_session_for(@user) - @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') + @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader') end it_should_behave_like 'issue user with project reader rights' @@ -166,7 +166,7 @@ describe IssuesController do before(:each) do @user = FactoryGirl.create(:user) set_session_for(@user) - @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer') + @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'writer') end it_should_behave_like 'issue user with project reader rights' diff --git a/spec/controllers/members_controller_spec.rb b/spec/controllers/members_controller_spec.rb index 9ed19484e..9389bb281 100644 --- a/spec/controllers/members_controller_spec.rb +++ b/spec/controllers/members_controller_spec.rb @@ -15,12 +15,12 @@ describe MembersController do it 'should add member to group' do post :add, @add_params response.should redirect_to(edit_group_members_path(@group)) - Relation.by_target(@group).by_object(@another_user).count.should eql(1) + Relation.by_target(@group).by_actor(@another_user).count.should eql(1) end it 'should add reader member to group' do post :add, @add_params - Relation.by_target(@group).by_object(@another_user).first.role.should eql('reader') + Relation.by_target(@group).by_actor(@another_user).first.role.should eql('reader') end end end diff --git a/spec/controllers/platforms_controller_spec.rb b/spec/controllers/platforms_controller_spec.rb index 62136e9ae..c915f1477 100644 --- a/spec/controllers/platforms_controller_spec.rb +++ b/spec/controllers/platforms_controller_spec.rb @@ -105,7 +105,7 @@ describe PlatformsController do @user = FactoryGirl.create(:user) set_session_for(@user) @platform.update_attribute(:owner, @user) - @platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') + @platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') end it_should_behave_like 'user without create rights' @@ -127,7 +127,7 @@ describe PlatformsController do before(:each) do @user = FactoryGirl.create(:user) set_session_for(@user) - @platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') + @platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader') end it_should_behave_like 'platform index viewer' diff --git a/spec/controllers/product_build_lists_controller_spec.rb b/spec/controllers/product_build_lists_controller_spec.rb index e5ed367f0..f8192bc59 100644 --- a/spec/controllers/product_build_lists_controller_spec.rb +++ b/spec/controllers/product_build_lists_controller_spec.rb @@ -92,7 +92,7 @@ describe ProductBuildListsController do before(:each) do @user = FactoryGirl.create(:user) set_session_for(@user) - @pbl.product.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') + @pbl.product.platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') end it_should_behave_like 'admin' diff --git a/spec/controllers/products_controller_spec.rb b/spec/controllers/products_controller_spec.rb index 03dcbeaa9..4b8a63c69 100644 --- a/spec/controllers/products_controller_spec.rb +++ b/spec/controllers/products_controller_spec.rb @@ -64,7 +64,7 @@ describe ProductsController do before(:each) do @user = FactoryGirl.create(:user) set_session_for(@user) - @platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') + @platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') end it_should_behave_like 'admin user' diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index eceef48a5..95bfc5cf5 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -48,7 +48,7 @@ describe ProjectsController do @user = FactoryGirl.create(:user) set_session_for(@user) @project.update_attribute(:owner, @user) - @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') + @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') end it_should_behave_like 'projects user with admin rights' @@ -74,7 +74,7 @@ describe ProjectsController do before(:each) do @user = FactoryGirl.create(:user) set_session_for(@user) - @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') + @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader') end it_should_behave_like 'projects user with reader rights' @@ -84,7 +84,7 @@ describe ProjectsController do before(:each) do @user = FactoryGirl.create(:user) set_session_for(@user) - @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer') + @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'writer') end it_should_behave_like 'projects user with reader rights' @@ -103,7 +103,7 @@ describe ProjectsController do it 'should be able to fork project to group' do group = FactoryGirl.create(:group) - group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'admin') + group.actors.create(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') post :fork, :id => @project.id, :group => group.id response.should redirect_to(project_path(group.projects.first.id)) end diff --git a/spec/controllers/repositories_controller_spec.rb b/spec/controllers/repositories_controller_spec.rb index 47109cf0b..b42625942 100644 --- a/spec/controllers/repositories_controller_spec.rb +++ b/spec/controllers/repositories_controller_spec.rb @@ -108,7 +108,7 @@ describe RepositoriesController do @user = FactoryGirl.create(:user) set_session_for(@user) @repository.platform.update_attribute(:owner, @user) - @repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') + @repository.platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') end it_should_behave_like 'platform admin user' diff --git a/spec/controllers/subscribes_controller_spec.rb b/spec/controllers/subscribes_controller_spec.rb index c1b4c3f02..b443b2893 100644 --- a/spec/controllers/subscribes_controller_spec.rb +++ b/spec/controllers/subscribes_controller_spec.rb @@ -66,7 +66,7 @@ describe SubscribesController do before(:each) do @user = FactoryGirl.create(:admin) set_session_for(@user) - @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') + @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') @destroy_params = @destroy_params.merge({:id => @user.id}) end diff --git a/spec/models/cancan_spec.rb b/spec/models/cancan_spec.rb index c1bb336c6..71a228613 100644 --- a/spec/models/cancan_spec.rb +++ b/spec/models/cancan_spec.rb @@ -147,7 +147,7 @@ describe CanCan do context 'with read rights' do before(:each) do - @project.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'reader') + @project.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'reader') end it 'should be able to read project' do @@ -165,7 +165,7 @@ describe CanCan do context 'with writer rights' do before(:each) do - @project.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'writer') + @project.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'writer') end [:read, :create, :new].each do |action| @@ -184,7 +184,7 @@ describe CanCan do context 'with admin rights' do before(:each) do - @project.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'admin') + @project.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'admin') end [:read, :update].each do |action| @@ -258,7 +258,7 @@ describe CanCan do context 'with read rights' do before(:each) do - @platform.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'reader') + @platform.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'reader') end it "should be able to read platform" do @@ -286,7 +286,7 @@ describe CanCan do context 'with read rights' do before(:each) do - @repository.platform.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'reader') + @repository.platform.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'reader') end it "should be able to read repository" do @@ -298,7 +298,7 @@ describe CanCan do context 'build list relations' do before(:each) do @project = FactoryGirl.create(:project) - @project.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'writer') + @project.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'writer') @build_list = FactoryGirl.create(:build_list, :project => @project) end diff --git a/spec/models/comment_for_commit_spec.rb b/spec/models/comment_for_commit_spec.rb index 3f4234648..c8bcc0afd 100644 --- a/spec/models/comment_for_commit_spec.rb +++ b/spec/models/comment_for_commit_spec.rb @@ -61,7 +61,7 @@ describe Comment do set_comments_data_for_commit @admin = FactoryGirl.create(:user) @ability = Ability.new(@admin) - @project.relations.create!(:object_type => 'User', :object_id => @admin.id, :role => 'admin') + @project.relations.create!(:actor_type => 'User', :actor_id => @admin.id, :role => 'admin') ActionMailer::Base.deliveries = [] end diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index e9d9e105c..16caf891b 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -56,7 +56,7 @@ describe Comment do set_commentable_data - @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') + @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') end it 'should create comment' do @@ -85,7 +85,7 @@ describe Comment do set_commentable_data @project.update_attribute(:owner, @user) - @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') + @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') end it 'should create comment' do diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 0252fb69c..e45a47994 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -34,7 +34,7 @@ describe Group do before(:each) do @user = FactoryGirl.create(:user) @another_user = FactoryGirl.create(:user) - @group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'admin') + @group.actors.create(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') @ability = Ability.new(@user) end @@ -63,7 +63,7 @@ describe Group do before(:each) do @user = FactoryGirl.create(:user) @group.update_attribute(:owner, @user) - @group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'admin') + @group.actors.create(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') @ability = Ability.new(@user) end @@ -77,7 +77,7 @@ describe Group do context 'for group reader and writer user' do before(:each) do @user = FactoryGirl.create(:user) - @group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'reader') + @group.actors.create(:actor_type => 'User', :actor_id => @user.id, :role => 'reader') @ability = Ability.new(@user) end