[refs #54] Add comments specs and factory. Remove unused code. Add one delay and fix some links.
This commit is contained in:
parent
49ec1ebe98
commit
635e2b7977
|
@ -88,16 +88,8 @@ class Ability
|
|||
cannot :manage, Issue, :project => {:has_issues => false} # switch off issues
|
||||
|
||||
can(:create, Comment) {|comment| can? :read, comment.commentable.project}
|
||||
can(:update, Comment) {|comment| can? :update, comment.user_id == user.id or local_admin?(comment.commentable.project)}
|
||||
can(:update, Comment) {|comment| comment.user_id == user.id or local_admin?(comment.commentable.project)}
|
||||
cannot :manage, Comment, :commentable => {:project => {:has_issues => false}} # switch off issues
|
||||
|
||||
can :create, Subscribe do |subscribe|
|
||||
!subscribe.subscribeable.subscribes.exists?(:user_id => user.id)
|
||||
end
|
||||
can :destroy, Subscribe do |subscribe|
|
||||
subscribe.subscribeable.subscribes.exists?(:user_id => user.id) && user.id == subscribe.user_id
|
||||
end
|
||||
#can [:create, :delete], Subscribe
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -106,6 +98,13 @@ class Ability
|
|||
cannot :destroy, Repository, :platform => {:platform_type => 'personal'}
|
||||
cannot :fork, Project, :owner_id => user.id, :owner_type => user.class.to_s
|
||||
cannot :destroy, Issue
|
||||
|
||||
can :create, Subscribe do |subscribe|
|
||||
!subscribe.subscribeable.subscribes.exists?(:user_id => user.id)
|
||||
end
|
||||
can :destroy, Subscribe do |subscribe|
|
||||
subscribe.subscribeable.subscribes.exists?(:user_id => user.id) && user.id == subscribe.user_id
|
||||
end
|
||||
end
|
||||
|
||||
# TODO group_ids ??
|
||||
|
|
|
@ -9,14 +9,12 @@ class Comment < ActiveRecord::Base
|
|||
protected
|
||||
|
||||
def deliver_new_comment_notification
|
||||
#UserMailer.new_comment_notification(self, self.commentable.user).deliver
|
||||
#UserMailer.new_comment_notification(self, self.commentable.project.owner).deliver
|
||||
recipients = self.commentable.project.relations.by_role('admin').where(:object_type => 'User').map { |rel| rel.read_attribute(:object_id) }
|
||||
recipients = recipients | [self.commentable.user_id]
|
||||
recipients = recipients | [self.commentable.project.owner_id] if self.commentable.project.owner_type == 'User'
|
||||
recipients.each do |recipient_id|
|
||||
recipient = User.find(recipient_id)
|
||||
UserMailer.new_comment_notification(self, recipient).deliver
|
||||
UserMailer.delay.new_comment_notification(self, recipient)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,12 +33,6 @@ class Issue < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def deliver_new_issue_notification
|
||||
#UserMailer.new_issue_notification(self, self.project.owner).deliver
|
||||
#self.project.relations.by_role('admin').each do |rel|
|
||||
# admin = User.find(rel.object_id)
|
||||
# UserMailer.new_issue_notification(self, admin).deliver
|
||||
#end
|
||||
|
||||
recipients = collect_recipient_ids
|
||||
recipients.each do |recipient_id|
|
||||
recipient = User.find(recipient_id)
|
||||
|
@ -47,7 +41,6 @@ class Issue < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def deliver_issue_assign_notification
|
||||
#UserMailer.delay.issue_assign_notification(self, self.user).deliver if self.user_id_was != self.user_id
|
||||
UserMailer.delay.issue_assign_notification(self, self.user) if self.user_id_was != self.user_id
|
||||
end
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
= link_to t('layout.issues.subscribe_btn'), project_issue_subscribes_path(@project, @issue), :method => :post
|
||||
|
||||
%a{ :name => "comments" }
|
||||
.block#block-lists
|
||||
.block#block-list
|
||||
.content
|
||||
%h2.title
|
||||
= t("layout.issues.comments_header")
|
||||
|
@ -44,8 +44,8 @@
|
|||
= comment.body
|
||||
%br
|
||||
%br
|
||||
= link_to t("layout.edit"), edit_project_issue_comment_path(@project, @issue, comment) if can? :update, comment
|
||||
= link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), project_issue_comment_path(@project, @issue, comment), :method => "delete", :class => "button", :confirm => t("layout.comments.confirm_delete") if can? :delete, comment
|
||||
= link_to t("layout.edit"), edit_project_issue_comment_path(@project, @issue.id, comment) if can? :update, comment
|
||||
= link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), project_issue_comment_path(@project, @issue.id, comment), :method => "delete", :class => "button", :confirm => t("layout.comments.confirm_delete") if can? :delete, comment
|
||||
|
||||
.block
|
||||
.content
|
||||
|
|
11
db/schema.rb
11
db/schema.rb
|
@ -245,6 +245,7 @@ ActiveRecord::Schema.define(:version => 20111226141947) do
|
|||
t.string "object_type"
|
||||
t.integer "target_id"
|
||||
t.string "target_type"
|
||||
t.integer "role_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "role"
|
||||
|
@ -281,16 +282,16 @@ ActiveRecord::Schema.define(:version => 20111226141947) do
|
|||
|
||||
create_table "users", :force => true do |t|
|
||||
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 "email", :default => "", :null => false
|
||||
t.string "encrypted_password", :limit => 128, :default => "", :null => false
|
||||
t.string "reset_password_token"
|
||||
t.string "remember_token"
|
||||
t.datetime "reset_password_sent_at"
|
||||
t.datetime "remember_created_at"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.text "ssh_key"
|
||||
t.string "uname"
|
||||
t.text "ssh_key"
|
||||
t.integer "role_id"
|
||||
t.string "role"
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,148 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe CommentsController do
|
||||
shared_examples_for 'user with create comment rights' do
|
||||
it 'should be able to perform create action' do
|
||||
post :create, @create_params
|
||||
response.should redirect_to(project_issue_path(@project, @issue))
|
||||
end
|
||||
|
||||
it 'should create issue object into db' do
|
||||
lambda{ post :create, @create_params }.should change{ Comment.count }.by(1)
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for 'user with update own comment rights' do
|
||||
it 'should be able to perform update action' do
|
||||
put :update, {:id => @own_comment.id}.merge(@update_params)
|
||||
response.should redirect_to([@project, @issue])
|
||||
end
|
||||
|
||||
it 'should update issue title' do
|
||||
put :update, {:id => @own_comment.id}.merge(@update_params)
|
||||
@own_comment.reload.body.should == 'updated'
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for 'user with update stranger comment rights' do
|
||||
it 'should be able to perform update action' do
|
||||
put :update, {:id => @comment.id}.merge(@update_params)
|
||||
response.should redirect_to([@project, @issue])
|
||||
end
|
||||
|
||||
it 'should update issue title' do
|
||||
put :update, {:id => @comment.id}.merge(@update_params)
|
||||
@comment.reload.body.should == 'updated'
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for 'user without update stranger comment rights' do
|
||||
it 'should not be able to perform update action' do
|
||||
put :update, {:id => @comment.id}.merge(@update_params)
|
||||
response.should redirect_to(forbidden_path)
|
||||
end
|
||||
|
||||
it 'should not update issue title' do
|
||||
put :update, {:id => @comment.id}.merge(@update_params)
|
||||
@comment.reload.body.should_not == 'updated'
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for 'user without destroy comment rights' do
|
||||
it 'should not be able to perform destroy action' do
|
||||
delete :destroy, :id => @comment.id, :issue_id => @issue.id, :project_id => @project.id
|
||||
response.should redirect_to(forbidden_path)
|
||||
end
|
||||
|
||||
it 'should not reduce comments count' do
|
||||
lambda{ delete :destroy, :id => @comment.id, :issue_id => @issue.id, :project_id => @project.id }.should change{ Issue.count }.by(0)
|
||||
end
|
||||
end
|
||||
|
||||
#shared_examples_for 'user with destroy rights' do
|
||||
# it 'should be able to perform destroy action' do
|
||||
# delete :destroy, :id => @comment.id, :issue_id => @issue.id, :project_id => @project.id
|
||||
# response.should redirect_to([@project, @issue])
|
||||
# end
|
||||
#
|
||||
# it 'should reduce comments count' do
|
||||
# lambda{ delete :destroy, :id => @comment.id, :issue_id => @issue.id, :project_id => @project.id }.should change{ Comment.count }.by(-1)
|
||||
# end
|
||||
#end
|
||||
|
||||
describe CommentsController do
|
||||
before(:each) do
|
||||
stub_rsync_methods
|
||||
|
||||
@project = Factory(:project)
|
||||
@issue = Factory(:issue, :project_id => @project.id)
|
||||
@comment = Factory(:comment, :commentable => @issue)
|
||||
|
||||
@create_params = {:comment => {:body => 'I am a comment!'}, :project_id => @project.id, :issue_id => @issue.id}
|
||||
@update_params = {:comment => {:body => 'updated'}, :project_id => @project.id, :issue_id => @issue.id}
|
||||
|
||||
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
||||
|
||||
@request.env['HTTP_REFERER'] = project_issue_path(@project, @issue)
|
||||
end
|
||||
|
||||
context 'for project admin user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
set_session_for(@user)
|
||||
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
||||
|
||||
@own_comment = Factory(:comment, :commentable => @issue, :user => @user)
|
||||
end
|
||||
|
||||
it_should_behave_like 'user with create comment rights'
|
||||
it_should_behave_like 'user with update stranger comment rights'
|
||||
it_should_behave_like 'user with update own comment rights'
|
||||
it_should_behave_like 'user without destroy comment rights'
|
||||
end
|
||||
|
||||
context 'for project owner user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
set_session_for(@user)
|
||||
@project.update_attribute(:owner, @user)
|
||||
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
||||
|
||||
@own_comment = Factory(:comment, :commentable => @issue, :user => @user)
|
||||
end
|
||||
|
||||
it_should_behave_like 'user with create comment rights'
|
||||
it_should_behave_like 'user with update stranger comment rights'
|
||||
it_should_behave_like 'user with update own comment rights'
|
||||
it_should_behave_like 'user without destroy comment rights'
|
||||
end
|
||||
|
||||
context 'for project reader user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
set_session_for(@user)
|
||||
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
|
||||
|
||||
@own_comment = Factory(:comment, :commentable => @issue, :user => @user)
|
||||
end
|
||||
|
||||
it_should_behave_like 'user with create comment rights'
|
||||
it_should_behave_like 'user without update stranger comment rights'
|
||||
it_should_behave_like 'user with update own comment rights'
|
||||
it_should_behave_like 'user without destroy comment rights'
|
||||
end
|
||||
|
||||
context 'for project writer user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
set_session_for(@user)
|
||||
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer')
|
||||
|
||||
@own_comment = Factory(:comment, :commentable => @issue, :user => @user)
|
||||
end
|
||||
|
||||
it_should_behave_like 'user with create comment rights'
|
||||
it_should_behave_like 'user without update stranger comment rights'
|
||||
it_should_behave_like 'user with update own comment rights'
|
||||
it_should_behave_like 'user without destroy comment rights'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -78,8 +78,6 @@ describe IssuesController do
|
|||
|
||||
@project = Factory(:project)
|
||||
@issue_user = Factory(:user)
|
||||
@create_params = {:project => {:name => 'pro'}}
|
||||
@update_params = {:project => {:name => 'pro2'}}
|
||||
|
||||
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# Read about factories at http://github.com/thoughtbot/factory_girl
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :comment do
|
||||
end
|
||||
end
|
||||
Factory.define(:comment) do |p|
|
||||
p.body { Factory.next(:string) }
|
||||
p.association :user, :factory => :user
|
||||
p.association :commentable, :factory => :issue
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
Factory.define(:issue) do |p|
|
||||
p.title { Factory.next(:string) }
|
||||
p.body { Factory.next(:string) }
|
||||
p.association :project, :factory => :project
|
||||
p.association :user, :factory => :user
|
||||
p.status "open"
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue