Merge pull request #781 from warpc/777-group_owner

[refs #777] Big test fix, refactoring tests.
This commit is contained in:
Vladimir Sharshov 2012-12-20 06:03:38 -08:00
commit 7f2bf385fd
26 changed files with 348 additions and 361 deletions

View File

@ -12,10 +12,8 @@ class ActivityFeedObserver < ActiveRecord::Observer
) )
when 'Issue' when 'Issue'
recipients = record.collect_recipient_ids record.collect_recipients.each do |recipient|
recipients.each do |recipient_id| UserMailer.new_issue_notification(record, recipient).deliver if recipient.notifier.can_notify && recipient.notifier.new_issue
recipient = User.find(recipient_id)
UserMailer.new_issue_notification(record, recipient).deliver if User.find(recipient).notifier.can_notify && User.find(recipient).notifier.new_issue
ActivityFeed.create( ActivityFeed.create(
:user => recipient, :user => recipient,
:kind => 'new_issue_notification', :kind => 'new_issue_notification',
@ -94,9 +92,9 @@ class ActivityFeedObserver < ActiveRecord::Observer
options.merge!({:user_id => first_commiter.id, :user_name => first_commiter.name}) if first_commiter options.merge!({:user_id => first_commiter.id, :user_name => first_commiter.name}) if first_commiter
end end
record.project.owner_and_admin_ids.each do |recipient| record.project.admins.each do |recipient|
ActivityFeed.create!( ActivityFeed.create!(
:user => User.find(recipient), :user => recipient,
:kind => kind, :kind => kind,
:data => options :data => options
) )
@ -106,9 +104,9 @@ class ActivityFeedObserver < ActiveRecord::Observer
actor = User.find_by_uname! record[:actor_name] actor = User.find_by_uname! record[:actor_name]
project = Project.find record[:project_id] project = Project.find record[:project_id]
project.owner_and_admin_ids.each do |recipient| project.admins.each do |recipient|
ActivityFeed.create!( ActivityFeed.create!(
:user => User.find(recipient),#record.user, :user => recipient,
:kind => 'wiki_new_commit_notification', :kind => 'wiki_new_commit_notification',
:data => {:user_id => actor.id, :user_name => actor.name, :user_email => actor.email, :project_id => project.id, :data => {:user_id => actor.id, :user_name => actor.name, :user_email => actor.email, :project_id => project.id,
:project_name => project.name, :commit_sha => record[:commit_sha], :project_owner => project.owner.uname} :project_name => project.name, :commit_sha => record[:commit_sha], :project_owner => project.owner.uname}
@ -134,9 +132,9 @@ class ActivityFeedObserver < ActiveRecord::Observer
if [BuildList::BUILD_PUBLISHED, BuildServer::SUCCESS, BuildServer::BUILD_ERROR, BuildServer::PLATFORM_NOT_FOUND, if [BuildList::BUILD_PUBLISHED, BuildServer::SUCCESS, BuildServer::BUILD_ERROR, BuildServer::PLATFORM_NOT_FOUND,
BuildServer::PROJECT_NOT_FOUND, BuildServer::PROJECT_VERSION_NOT_FOUND, BuildList::FAILED_PUBLISH].include? record.status or BuildServer::PROJECT_NOT_FOUND, BuildServer::PROJECT_VERSION_NOT_FOUND, BuildList::FAILED_PUBLISH].include? record.status or
(record.status == BuildList::BUILD_PENDING && record.bs_id_changed?) (record.status == BuildList::BUILD_PENDING && record.bs_id_changed?)
record.project.owner_and_admin_ids.each do |recipient| record.project.admins.each do |recipient|
ActivityFeed.create( ActivityFeed.create(
:user => User.find(recipient), :user => recipient,
:kind => 'build_list_notification', :kind => 'build_list_notification',
:data => {:task_num => record.bs_id, :build_list_id => record.id, :status => record.status, :updated_at => record.updated_at, :data => {:task_num => record.bs_id, :build_list_id => record.id, :status => record.status, :updated_at => record.updated_at,
:project_id => record.project_id, :project_name => record.project.name, :project_owner => record.project.owner.uname, :project_id => record.project_id, :project_name => record.project.name, :project_owner => record.project.owner.uname,

View File

@ -139,9 +139,8 @@ class Comment < ActiveRecord::Base
if issue_comment? if issue_comment?
commentable.subscribes.create(:user => user) if !commentable.subscribes.exists?(:user_id => user.id) commentable.subscribes.create(:user => user) if !commentable.subscribes.exists?(:user_id => user.id)
elsif commit_comment? elsif commit_comment?
recipients = project.relations.by_role('admin').where(:actor_type => 'User').map &:actor # admins recipients = project.admins
recipients << user << User.where(:email => commentable.committer.email).first # commentor and committer recipients << user << User.where(:email => commentable.try(:committer).try(:email)).first # commentor and committer
recipients << project.owner if project.owner_type == 'User' # project owner
recipients.compact.uniq.each do |user| recipients.compact.uniq.each do |user|
options = {:project_id => project.id, :subscribeable_id => commentable_id, :subscribeable_type => commentable.class.name, :user_id => user.id} options = {:project_id => project.id, :subscribeable_id => commentable_id, :subscribeable_type => commentable.class.name, :user_id => user.id}
Subscribe.subscribe_to_commit(options) if Subscribe.subscribed_to_commit?(project, user, commentable) Subscribe.subscribe_to_commit(options) if Subscribe.subscribed_to_commit?(project, user, commentable)

View File

@ -62,11 +62,9 @@ class Issue < ActiveRecord::Base
self.status = 'open' self.status = 'open'
end end
def collect_recipient_ids def collect_recipients
recipients = self.project.relations.by_role('admin').where(:actor_type => 'User').map { |rel| rel.read_attribute(:actor_id) } recipients = self.project.admins
recipients = recipients | [self.assignee_id] if self.assignee_id recipients = recipients | [self.assignee] if self.assignee
recipients = recipients | [self.project.owner_id] if self.project.owner_type == 'User'
recipients recipients
end end
@ -78,10 +76,9 @@ class Issue < ActiveRecord::Base
end end
def subscribe_users def subscribe_users
recipients = collect_recipient_ids collect_recipients.each do |recipient|
recipients.each do |recipient_id| if recipient.notifier.new_comment && !self.subscribes.exists?(:user_id => recipient.id)
if User.find(recipient_id).notifier.new_comment && !self.subscribes.exists?(:user_id => recipient_id) ss = self.subscribes.create(:user_id => recipient.id)
ss = self.subscribes.create(:user_id => recipient_id)
end end
end end
end end
@ -94,5 +91,4 @@ class Issue < ActiveRecord::Base
end end
end end
end end
end end

View File

@ -103,10 +103,14 @@ class Project < ActiveRecord::Base
@platforms ||= repositories.map(&:platform).uniq @platforms ||= repositories.map(&:platform).uniq
end end
def owner_and_admin_ids def admins
recipients = self.relations.by_role('admin').where(:actor_type => 'User').map { |rel| rel.read_attribute(:actor_id) } admins = self.collaborators.where("relations.role = 'admin'")
recipients = recipients | [self.owner_id] if self.owner_type == 'User' grs = self.groups.where("relations.role = 'admin'")
recipients if self.owner.is_a? Group
grs = grs.where("relations.actor_id != ?", self.owner.id)
admins = admins | owner.members.where("relations.role = 'admin'")
end
admins = admins | grs.map(&:members).flatten # member of the admin group is admin
end end
def public? def public?

View File

@ -17,8 +17,8 @@ ActiveRecord::Schema.define(:version => 20121214145009) do
t.integer "user_id", :null => false t.integer "user_id", :null => false
t.string "kind" t.string "kind"
t.text "data" t.text "data"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
end end
create_table "advisories", :force => true do |t| create_table "advisories", :force => true do |t|
@ -53,8 +53,8 @@ ActiveRecord::Schema.define(:version => 20121214145009) do
create_table "arches", :force => true do |t| create_table "arches", :force => true do |t|
t.string "name", :null => false t.string "name", :null => false
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
end end
add_index "arches", ["name"], :name => "index_arches_on_name", :unique => true add_index "arches", ["name"], :name => "index_arches_on_name", :unique => true
@ -63,8 +63,8 @@ ActiveRecord::Schema.define(:version => 20121214145009) do
t.integer "user_id" t.integer "user_id"
t.string "provider" t.string "provider"
t.string "uid" t.string "uid"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
end end
add_index "authentications", ["provider", "uid"], :name => "index_authentications_on_provider_and_uid", :unique => true add_index "authentications", ["provider", "uid"], :name => "index_authentications_on_provider_and_uid", :unique => true
@ -75,8 +75,8 @@ ActiveRecord::Schema.define(:version => 20121214145009) do
t.integer "level" t.integer "level"
t.integer "status" t.integer "status"
t.integer "build_list_id" t.integer "build_list_id"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.string "version" t.string "version"
end end
@ -110,8 +110,8 @@ ActiveRecord::Schema.define(:version => 20121214145009) do
t.integer "project_id" t.integer "project_id"
t.integer "arch_id" t.integer "arch_id"
t.datetime "notified_at" t.datetime "notified_at"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.boolean "is_circle", :default => false t.boolean "is_circle", :default => false
t.text "additional_repos" t.text "additional_repos"
t.string "name" t.string "name"
@ -145,8 +145,8 @@ ActiveRecord::Schema.define(:version => 20121214145009) do
t.string "commentable_type" t.string "commentable_type"
t.integer "user_id" t.integer "user_id"
t.text "body" t.text "body"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.decimal "commentable_id", :precision => 50, :scale => 0 t.decimal "commentable_id", :precision => 50, :scale => 0
t.integer "project_id" t.integer "project_id"
t.text "data" t.text "data"
@ -164,8 +164,8 @@ ActiveRecord::Schema.define(:version => 20121214145009) do
t.string "controller" t.string "controller"
t.string "action" t.string "action"
t.text "message" t.text "message"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
end end
create_table "flash_notifies", :force => true do |t| create_table "flash_notifies", :force => true do |t|
@ -179,8 +179,8 @@ ActiveRecord::Schema.define(:version => 20121214145009) do
create_table "groups", :force => true do |t| create_table "groups", :force => true do |t|
t.integer "owner_id" t.integer "owner_id"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.string "uname" t.string "uname"
t.integer "own_projects_count", :default => 0, :null => false t.integer "own_projects_count", :default => 0, :null => false
t.text "description" t.text "description"
@ -197,8 +197,8 @@ ActiveRecord::Schema.define(:version => 20121214145009) do
t.string "title" t.string "title"
t.text "body" t.text "body"
t.string "status", :default => "open" t.string "status", :default => "open"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.integer "user_id" t.integer "user_id"
t.datetime "closed_at" t.datetime "closed_at"
t.integer "closed_by" t.integer "closed_by"
@ -260,14 +260,14 @@ ActiveRecord::Schema.define(:version => 20121214145009) do
t.string "description" t.string "description"
t.string "name", :null => false t.string "name", :null => false
t.integer "parent_platform_id" t.integer "parent_platform_id"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.boolean "released", :default => false, :null => false t.boolean "released", :default => false, :null => false
t.integer "owner_id" t.integer "owner_id"
t.string "owner_type" t.string "owner_type"
t.string "visibility", :default => "open", :null => false t.string "visibility", :default => "open", :null => false
t.string "platform_type", :default => "main", :null => false t.string "platform_type", :default => "main", :null => false
t.string "distrib_type", :null => false t.string "distrib_type"
end end
add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false
@ -276,16 +276,16 @@ ActiveRecord::Schema.define(:version => 20121214145009) do
t.integer "platform_id" t.integer "platform_id"
t.string "login" t.string "login"
t.string "password" t.string "password"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.integer "user_id" t.integer "user_id"
end end
create_table "product_build_lists", :force => true do |t| create_table "product_build_lists", :force => true do |t|
t.integer "product_id" t.integer "product_id"
t.integer "status", :default => 2, :null => false t.integer "status", :default => 3, :null => false
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.integer "project_id" t.integer "project_id"
t.string "project_version" t.string "project_version"
t.string "commit_hash" t.string "commit_hash"
@ -302,8 +302,8 @@ ActiveRecord::Schema.define(:version => 20121214145009) do
create_table "products", :force => true do |t| create_table "products", :force => true do |t|
t.string "name", :null => false t.string "name", :null => false
t.integer "platform_id", :null => false t.integer "platform_id", :null => false
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.text "description" t.text "description"
t.integer "project_id" t.integer "project_id"
t.string "params" t.string "params"
@ -316,8 +316,8 @@ ActiveRecord::Schema.define(:version => 20121214145009) do
t.string "name" t.string "name"
t.string "version" t.string "version"
t.datetime "file_mtime" t.datetime "file_mtime"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.integer "platform_id" t.integer "platform_id"
end end
@ -326,27 +326,27 @@ ActiveRecord::Schema.define(:version => 20121214145009) do
create_table "project_to_repositories", :force => true do |t| create_table "project_to_repositories", :force => true do |t|
t.integer "project_id" t.integer "project_id"
t.integer "repository_id" t.integer "repository_id"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
end end
add_index "project_to_repositories", ["repository_id", "project_id"], :name => "index_project_to_repositories_on_repository_id_and_project_id", :unique => true add_index "project_to_repositories", ["repository_id", "project_id"], :name => "index_project_to_repositories_on_repository_id_and_project_id", :unique => true
create_table "projects", :force => true do |t| create_table "projects", :force => true do |t|
t.string "name" t.string "name"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.integer "owner_id" t.integer "owner_id"
t.string "owner_type" t.string "owner_type"
t.string "visibility", :default => "open" t.string "visibility", :default => "open"
t.text "description" t.text "description"
t.string "ancestry" t.string "ancestry"
t.boolean "has_issues", :default => true t.boolean "has_issues", :default => true
t.boolean "has_wiki", :default => false
t.string "srpm_file_name" t.string "srpm_file_name"
t.string "srpm_content_type"
t.integer "srpm_file_size" t.integer "srpm_file_size"
t.datetime "srpm_updated_at" t.datetime "srpm_updated_at"
t.string "srpm_content_type"
t.boolean "has_wiki", :default => false
t.string "default_branch", :default => "master" t.string "default_branch", :default => "master"
t.boolean "is_package", :default => true, :null => false t.boolean "is_package", :default => true, :null => false
t.integer "average_build_time", :default => 0, :null => false t.integer "average_build_time", :default => 0, :null => false
@ -376,8 +376,8 @@ ActiveRecord::Schema.define(:version => 20121214145009) do
t.string "token" t.string "token"
t.boolean "approved", :default => false t.boolean "approved", :default => false
t.boolean "rejected", :default => false t.boolean "rejected", :default => false
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.string "interest" t.string "interest"
t.text "more" t.text "more"
t.string "language" t.string "language"
@ -391,16 +391,16 @@ ActiveRecord::Schema.define(:version => 20121214145009) do
t.string "actor_type" t.string "actor_type"
t.integer "target_id" t.integer "target_id"
t.string "target_type" t.string "target_type"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.string "role" t.string "role"
end end
create_table "repositories", :force => true do |t| create_table "repositories", :force => true do |t|
t.string "description", :null => false t.string "description", :null => false
t.integer "platform_id", :null => false t.integer "platform_id", :null => false
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.string "name", :null => false t.string "name", :null => false
t.boolean "publish_without_qa", :default => true t.boolean "publish_without_qa", :default => true
end end
@ -414,8 +414,8 @@ ActiveRecord::Schema.define(:version => 20121214145009) do
t.boolean "new_comment_reply", :default => true t.boolean "new_comment_reply", :default => true
t.boolean "new_issue", :default => true t.boolean "new_issue", :default => true
t.boolean "issue_assign", :default => true t.boolean "issue_assign", :default => true
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.boolean "new_comment_commit_owner", :default => true t.boolean "new_comment_commit_owner", :default => true
t.boolean "new_comment_commit_repo_owner", :default => true t.boolean "new_comment_commit_repo_owner", :default => true
t.boolean "new_comment_commit_commentor", :default => true t.boolean "new_comment_commit_commentor", :default => true
@ -426,8 +426,8 @@ ActiveRecord::Schema.define(:version => 20121214145009) do
create_table "subscribes", :force => true do |t| create_table "subscribes", :force => true do |t|
t.string "subscribeable_type" t.string "subscribeable_type"
t.integer "user_id" t.integer "user_id"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.boolean "status", :default => true t.boolean "status", :default => true
t.integer "project_id" t.integer "project_id"
t.decimal "subscribeable_id", :precision => 50, :scale => 0 t.decimal "subscribeable_id", :precision => 50, :scale => 0
@ -436,17 +436,20 @@ ActiveRecord::Schema.define(:version => 20121214145009) do
create_table "users", :force => true do |t| create_table "users", :force => true do |t|
t.string "name" t.string "name"
t.string "email", :default => "", :null => false t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false t.string "encrypted_password", :default => "", :null => false
t.string "reset_password_token" t.string "reset_password_token"
t.datetime "reset_password_sent_at" t.datetime "reset_password_sent_at"
t.datetime "remember_created_at" t.datetime "remember_created_at"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.text "ssh_key" t.text "ssh_key"
t.string "uname" t.string "uname"
t.string "role" t.string "role"
t.string "language", :default => "en" t.string "language", :default => "en"
t.integer "own_projects_count", :default => 0, :null => false t.integer "own_projects_count", :default => 0, :null => false
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.text "professional_experience" t.text "professional_experience"
t.string "site" t.string "site"
t.string "company" t.string "company"
@ -458,9 +461,6 @@ ActiveRecord::Schema.define(:version => 20121214145009) do
t.integer "failed_attempts", :default => 0 t.integer "failed_attempts", :default => 0
t.string "unlock_token" t.string "unlock_token"
t.datetime "locked_at" t.datetime "locked_at"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "authentication_token" t.string "authentication_token"
t.integer "build_priority", :default => 50 t.integer "build_priority", :default => 50
end end

View File

@ -1,6 +1,10 @@
# -*- encoding : utf-8 -*- # -*- encoding : utf-8 -*-
require 'spec_helper' require 'spec_helper'
def incorrect_action_message
'Incorrect action for current build list'
end
shared_examples_for 'show build list via api' do shared_examples_for 'show build list via api' do
it 'should be able to perform show action' do it 'should be able to perform show action' do
get :show, @show_params get :show, @show_params
@ -127,7 +131,7 @@ describe Api::V1::BuildListsController do
it "should return correct json error message" do it "should return correct json error message" do
@build_list.update_column(:status, BuildServer::PROJECT_NOT_FOUND) @build_list.update_column(:status, BuildServer::PROJECT_NOT_FOUND)
do_cancel do_cancel
response.body.should == {:is_canceled => false, :url => api_v1_build_list_path(@build_list, :format => :json), :message => I18n.t('layout.build_lists.cancel_fail')}.to_json response.body.should == {:is_canceled => false, :url => api_v1_build_list_path(@build_list, :format => :json), :message => incorrect_action_message}.to_json
end end
it "should not cancel build list" do it "should not cancel build list" do
@ -183,7 +187,7 @@ describe Api::V1::BuildListsController do
end end
it "should return correct json error message" do it "should return correct json error message" do
response.body.should == {:is_published => false, :url => api_v1_build_list_path(@build_list, :format => :json), :message => I18n.t('layout.build_lists.publish_fail')}.to_json response.body.should == {:is_published => false, :url => api_v1_build_list_path(@build_list, :format => :json), :message => incorrect_action_message}.to_json
end end
it "should not cancel build list" do it "should not cancel build list" do
@ -243,7 +247,7 @@ describe Api::V1::BuildListsController do
end end
it "should return correct json error message" do it "should return correct json error message" do
response.body.should == {:is_reject_published => false, :url => api_v1_build_list_path(@build_list, :format => :json), :message => I18n.t('layout.build_lists.reject_publish_fail')}.to_json response.body.should == {:is_reject_published => false, :url => api_v1_build_list_path(@build_list, :format => :json), :message => incorrect_action_message}.to_json
end end
it "should not cancel build list" do it "should not cancel build list" do
@ -391,7 +395,7 @@ describe Api::V1::BuildListsController do
@build_list2 = FactoryGirl.create(:build_list_core) @build_list2 = FactoryGirl.create(:build_list_core)
@build_list2.project.update_column(:visibility, 'hidden') @build_list2.project.update_column(:visibility, 'hidden')
project = FactoryGirl.create(:project, :visibility => 'hidden', :owner => @user) project = FactoryGirl.create(:project_with_commit, :visibility => 'hidden', :owner => @user)
@build_list3 = FactoryGirl.create(:build_list_core, :project => project) @build_list3 = FactoryGirl.create(:build_list_core, :project => project)
@build_list4 = FactoryGirl.create(:build_list_core) @build_list4 = FactoryGirl.create(:build_list_core)

View File

@ -11,7 +11,7 @@ end
shared_examples_for 'not able search with api' do shared_examples_for 'not able search with api' do
it 'should not be able to search' do it 'should not be able to search' do
get :index, :format => :json get :index, :format => :json
response.should redirect_to(controller.current_user ? forbidden_path : new_user_session_path) response.code.should eq('401')
end end
end end

View File

@ -2,6 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe AutocompletesController do describe AutocompletesController do
before {stub_symlink_methods}
context 'for user' do context 'for user' do
before do before do

View File

@ -8,7 +8,7 @@ describe Groups::MembersController do
@user = @group.owner @user = @group.owner
set_session_for @user set_session_for @user
@another_user = FactoryGirl.create(:user) @another_user = FactoryGirl.create(:user)
@add_params = {:group_id => @group, :user_id => @another_user.uname} @add_params = {:group_id => @group, :user_uname => @another_user.uname}
@remove_params = {:group_id => @group, :user_remove => {"#{@group.owner.id}"=>["1"]}} @remove_params = {:group_id => @group, :user_remove => {"#{@group.owner.id}"=>["1"]}}
@update_params = {:group_id => @group, :user => {"#{@group.owner.id}"=>'reader'}} @update_params = {:group_id => @group, :user => {"#{@group.owner.id}"=>'reader'}}
end end

View File

@ -24,8 +24,10 @@ shared_examples_for 'product build list admin' do
end end
it 'should be able to perform cancel action' do it 'should be able to perform cancel action' do
url = platform_product_product_build_list_path(@product.platform, @product, @pbl)
@request.env['HTTP_REFERER'] = url
put :cancel, valid_attributes_for_show put :cancel, valid_attributes_for_show
response.should redirect_to(platform_product_product_build_list_path(@product.platform, @product, @pbl)) response.should redirect_to(url)
end end
it 'should be able to perform show action' do it 'should be able to perform show action' do
@ -131,7 +133,7 @@ describe Platforms::ProductBuildListsController do
before(:each) do before(:each) do
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
set_session_for(@user) set_session_for(@user)
@pbl.product.platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') @product.platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
end end
it_should_behave_like 'product build list admin' it_should_behave_like 'product build list admin'

View File

@ -32,7 +32,7 @@ describe Platforms::ProductsController do
@project = FactoryGirl.create(:project) @project = FactoryGirl.create(:project)
params = {:platform_id => @platform.id, :src_project => @project.name_with_owner} params = {:platform_id => @platform.id, :src_project => @project.name_with_owner}
@create_params = params.merge({:product => {:name => 'pro'}}) @create_params = params.merge({:product => {:name => 'pro', :time_living => 150}})
@update_params = params.merge({:product => {:name => 'pro2'}}) @update_params = params.merge({:product => {:name => 'pro2'}})
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)

View File

@ -44,13 +44,13 @@ describe Projects::BuildListsController do
it 'should save correct commit_hash for branch based build' do it 'should save correct commit_hash for branch based build' do
post :create, {:owner_name => @project.owner.uname, :project_name => @project.name}.merge(@create_params).deep_merge(:build_list => {:project_version => "latest_master"}) post :create, {:owner_name => @project.owner.uname, :project_name => @project.name}.merge(@create_params).deep_merge(:build_list => {:project_version => "latest_master"})
@project.build_lists.last.commit_hash.should == @project.repo.commits('master').last.id @project.build_lists.last.commit_hash.should == @project.repo.commits('master').first.id
end end
it 'should save correct commit_hash for tag based build' do it 'should save correct commit_hash for tag based build' do
system("cd #{@project.repo.path} && git tag 4.7.5.3") # TODO REDO through grit system("cd #{@project.repo.path} && git tag 4.7.5.3") # TODO REDO through grit
post :create, {:owner_name => @project.owner.uname, :project_name => @project.name}.merge(@create_params).deep_merge(:build_list => {:project_version => "4.7.5.3"}) post :create, {:owner_name => @project.owner.uname, :project_name => @project.name}.merge(@create_params).deep_merge(:build_list => {:project_version => "4.7.5.3"})
@project.build_lists.last.commit_hash.should == @project.repo.commits('4.7.5.3').last.id @project.build_lists.last.commit_hash.should == @project.repo.commits('4.7.5.3').first.id
end end
it 'should not be able to create with wrong project version' do it 'should not be able to create with wrong project version' do
@ -129,7 +129,7 @@ describe Projects::BuildListsController do
@build_list2 = FactoryGirl.create(:build_list_core) @build_list2 = FactoryGirl.create(:build_list_core)
@build_list2.project.update_column(:visibility, 'hidden') @build_list2.project.update_column(:visibility, 'hidden')
project = FactoryGirl.create(:project, :visibility => 'hidden', :owner => @user) project = FactoryGirl.create(:project_with_commit, :visibility => 'hidden', :owner => @user)
@build_list3 = FactoryGirl.create(:build_list_core, :project => project) @build_list3 = FactoryGirl.create(:build_list_core, :project => project)
@build_list4 = FactoryGirl.create(:build_list_core) @build_list4 = FactoryGirl.create(:build_list_core)
@ -217,7 +217,7 @@ describe Projects::BuildListsController do
@build_list2 = FactoryGirl.create(:build_list_core) @build_list2 = FactoryGirl.create(:build_list_core)
@build_list2.project.update_column(:visibility, 'hidden') @build_list2.project.update_column(:visibility, 'hidden')
project = FactoryGirl.create(:project, :visibility => 'hidden', :owner => @user) project = FactoryGirl.create(:project_with_commit, :visibility => 'hidden', :owner => @user)
@build_list3 = FactoryGirl.create(:build_list_core, :project => project) @build_list3 = FactoryGirl.create(:build_list_core, :project => project)
@build_list4 = FactoryGirl.create(:build_list_core) @build_list4 = FactoryGirl.create(:build_list_core)
@ -346,7 +346,6 @@ describe Projects::BuildListsController do
describe 'publish_build' do describe 'publish_build' do
before { before {
test_git_commit(build_list.project)
build_list.update_column(:commit_hash, build_list.project.repo.commits('master').last.id) build_list.update_column(:commit_hash, build_list.project.repo.commits('master').last.id)
build_list.update_column(:status, BuildList::BUILD_PUBLISH) build_list.update_column(:status, BuildList::BUILD_PUBLISH)
build_list_package build_list_package
@ -508,4 +507,5 @@ describe Projects::BuildListsController do
it { lambda{ do_get }.should change(build_list, :updated_at) } it { lambda{ do_get }.should change(build_list, :updated_at) }
end end
end end
after(:all) {clean_projects_dir}
end end

View File

@ -1,94 +1,22 @@
# -*- encoding : utf-8 -*- # -*- encoding : utf-8 -*-
require 'spec_helper' require 'spec_helper'
def create_comment user
FactoryGirl.create(:comment, :user => user, :commentable => @commit, :project => @project)
end
shared_examples_for 'user with create comment rights for commits' do
it 'should be able to perform create action' do
post :create, @create_params
response.should redirect_to(commit_path(@project, @commit.id)+"#comment#{Comment.last.id}")
end
it 'should create subscribe 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 for commits' do
it 'should be able to perform update action' do
put :update, {:id => @own_comment.id}.merge(@update_params)
response.status.should == 200
end
it 'should update subscribe body' 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 for commits' do
it 'should be able to perform update action' do
put :update, {:id => @stranger_comment.id}.merge(@update_params)
response.status.should == 200
end
it 'should update comment title' do
put :update, {:id => @stranger_comment.id}.merge(@update_params)
@stranger_comment.reload.body.should == 'updated'
end
end
shared_examples_for 'user without update stranger comment rights for commits' do
it 'should not be able to perform update action' do
put :update, {:id => @stranger_comment.id}.merge(@update_params)
response.should redirect_to(forbidden_path)
end
it 'should not update comment title' do
put :update, {:id => @stranger_comment.id}.merge(@update_params)
@stranger_comment.reload.body.should_not == 'updated'
end
end
shared_examples_for 'user without destroy comment rights for commits' do
it 'should not be able to perform destroy action' do
delete :destroy, :id => @stranger_comment.id, :commit_id => @commit.id, :owner_name => @project.owner.uname, :project_name => @project.name
response.should redirect_to(forbidden_path)
end
it 'should not reduce comments count' do
lambda{ delete :destroy, :id => @stranger_comment.id, :commit_id => @commit.id, :owner_name => @project.owner.uname, :project_name => @project.name }.should change{ Comment.count }.by(0)
end
end
shared_examples_for 'user with destroy comment rights for commits' do
it 'should be able to perform destroy action' do
delete :destroy, :id => @stranger_comment.id, :commit_id => @commit.id, :owner_name => @project.owner.uname, :project_name => @project.name
response.should redirect_to(commit_path(@project, @commit.id))
end
it 'should reduce comments count' do
lambda{ delete :destroy, :id => @stranger_comment.id, :commit_id => @commit.id, :owner_name => @project.owner.uname, :project_name => @project.name }.should change{ Comment.count }.by(-1)
end
end
describe Projects::CommentsController do describe Projects::CommentsController do
before(:each) do before(:each) do
stub_symlink_methods stub_symlink_methods
@project = FactoryGirl.create(:project) @project = FactoryGirl.create(:project_with_commit)
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.repo.path}) # maybe FIXME ?
@commit = @project.repo.commits.first @commit = @project.repo.commits.first
@create_params = {:comment => {:body => 'I am a comment!'}, :owner_name => @project.owner.uname, :project_name => @project.name, :commit_id => @commit.id} @create_params = {:comment => {:body => 'I am a comment!'}, :owner_name => @project.owner.uname, :project_name => @project.name, :commit_id => @commit.id}
@update_params = {:comment => {:body => 'updated'}, :owner_name => @project.owner.uname, :project_name => @project.name, :commit_id => @commit.id} @update_params = {:comment => {:body => 'updated'}, :owner_name => @project.owner.uname, :project_name => @project.name, :commit_id => @commit.id}
any_instance_of(Project, :versions => ['v1.0', 'v2.0']) any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
@stranger_comment = create_comment FactoryGirl.create(:user) @comment = FactoryGirl.create(:comment, :commentable => @commit, :project => @project)
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
@own_comment = create_comment @user @own_comment = FactoryGirl.create(:comment, :commentable => @commit, :user => @user, :project => @project)
set_session_for(@user) set_session_for(@user)
@path = {:owner_name => @project.owner.uname, :project_name => @project.name, :commit_id => @commit.id}
@return_path = commit_path(@project, @commit.id)
end end
context 'for project admin user' do context 'for project admin user' do
@ -96,25 +24,22 @@ describe Projects::CommentsController do
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
end end
it_should_behave_like 'user with create comment rights for commits' it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user with update stranger comment rights for commits' it_should_behave_like 'user with update stranger comment ability'
it_should_behave_like 'user with update own comment rights for commits' it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user with destroy comment rights for commits' it_should_behave_like 'user with destroy comment ability'
#it_should_behave_like 'user with destroy rights' #it_should_behave_like 'user with destroy ability'
end end
context 'for project owner user' do context 'for project owner user' do
before(:each) do before(:each) do
@user.destroy set_session_for(@project.owner)
@user = @project.owner
set_session_for(@user)
@own_comment = create_comment @user
end end
it_should_behave_like 'user with create comment rights for commits' it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user with update stranger comment rights for commits' it_should_behave_like 'user with update stranger comment ability'
it_should_behave_like 'user with update own comment rights for commits' it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user with destroy comment rights for commits' it_should_behave_like 'user with destroy comment ability'
end end
context 'for project reader user' do context 'for project reader user' do
@ -122,10 +47,10 @@ describe Projects::CommentsController do
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader') @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
end end
it_should_behave_like 'user with create comment rights for commits' it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user without update stranger comment rights for commits' it_should_behave_like 'user without update stranger comment ability'
it_should_behave_like 'user with update own comment rights for commits' it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user without destroy comment rights for commits' it_should_behave_like 'user without destroy comment ability'
end end
context 'for project writer user' do context 'for project writer user' do
@ -133,9 +58,9 @@ describe Projects::CommentsController do
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'writer') @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'writer')
end end
it_should_behave_like 'user with create comment rights for commits' it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user without update stranger comment rights for commits' it_should_behave_like 'user without update stranger comment ability'
it_should_behave_like 'user with update own comment rights for commits' it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user without destroy comment rights for commits' it_should_behave_like 'user without destroy comment ability'
end end
end end

View File

@ -6,7 +6,7 @@ shared_context "comments controller" do
stub_symlink_methods stub_symlink_methods
@project = FactoryGirl.create(:project) @project = FactoryGirl.create(:project)
@issue = FactoryGirl.create(:issue, :project_id => @project.id, :user => FactoryGirl.create(:user)) @issue = FactoryGirl.create(:issue, :project_id => @project.id)
@comment = FactoryGirl.create(:comment, :commentable => @issue, :project_id => @project.id) @comment = FactoryGirl.create(:comment, :commentable => @issue, :project_id => @project.id)
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
@ -14,82 +14,14 @@ shared_context "comments controller" do
set_session_for(@user) set_session_for(@user)
@address = {:owner_name => @project.owner.uname, :project_name => @project.name, :issue_id => @issue.serial_id} @path = {:owner_name => @project.owner.uname, :project_name => @project.name, :issue_id => @issue.serial_id}
@create_params = {:comment => {:body => 'I am a comment!'}}.merge(@address) @return_path = project_issue_path(@project, @issue)
@update_params = {:comment => {:body => 'updated'}}.merge(@address) @create_params = {:comment => {:body => 'I am a comment!'}}.merge(@path)
@update_params = {:comment => {:body => 'updated'}}.merge(@path)
end end
end end
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)+"#comment#{Comment.last.id}")
end
it 'should create comment in the database' 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.status.should == 200
end
it 'should update comment body' 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.status.should == 200
end
it 'should update comment body' 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 comment body' 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}.merge(@address)
response.should redirect_to(forbidden_path)
end
it 'should not delete comment from database' do
lambda{ delete :destroy, {:id => @comment.id}.merge(@address)}.should change{ Issue.count }.by(0)
end
end
shared_examples_for 'user with destroy comment rights' do
it 'should be able to perform destroy action' do
delete :destroy, {:id => @comment.id}.merge(@address)
response.should redirect_to([@project, @issue])
end
it 'should delete comment from database' do
lambda{ delete :destroy, {:id => @comment.id}.merge(@address)}.should change{ Comment.count }.by(-1)
end
end
describe Projects::CommentsController do describe Projects::CommentsController do
include_context "comments controller" include_context "comments controller"
@ -99,10 +31,10 @@ describe Projects::CommentsController do
@user.save @user.save
end end
it_should_behave_like 'user with create comment rights' it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user with update stranger comment rights' it_should_behave_like 'user with update stranger comment ability'
it_should_behave_like 'user with update own comment rights' it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user with destroy comment rights' it_should_behave_like 'user with destroy comment ability'
end end
context 'for project admin user' do context 'for project admin user' do
@ -110,10 +42,10 @@ describe Projects::CommentsController do
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin') @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
end end
it_should_behave_like 'user with create comment rights' it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user with update stranger comment rights' it_should_behave_like 'user with update stranger comment ability'
it_should_behave_like 'user with update own comment rights' it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user with destroy comment rights' it_should_behave_like 'user with destroy comment ability'
end end
context 'for project owner user' do context 'for project owner user' do
@ -121,10 +53,10 @@ describe Projects::CommentsController do
set_session_for(@project.owner) # owner should be user set_session_for(@project.owner) # owner should be user
end end
it_should_behave_like 'user with create comment rights' it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user with update stranger comment rights' it_should_behave_like 'user with update stranger comment ability'
it_should_behave_like 'user with update own comment rights' it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user with destroy comment rights' it_should_behave_like 'user with destroy comment ability'
end end
context 'for project reader user' do context 'for project reader user' do
@ -132,10 +64,10 @@ describe Projects::CommentsController do
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader') @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
end end
it_should_behave_like 'user with create comment rights' it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user without update stranger comment rights' it_should_behave_like 'user without update stranger comment ability'
it_should_behave_like 'user with update own comment rights' it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user without destroy comment rights' it_should_behave_like 'user without destroy comment ability'
end end
context 'for project writer user' do context 'for project writer user' do
@ -143,9 +75,9 @@ describe Projects::CommentsController do
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'writer') @project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'writer')
end end
it_should_behave_like 'user with create comment rights' it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user without update stranger comment rights' it_should_behave_like 'user without update stranger comment ability'
it_should_behave_like 'user with update own comment rights' it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user without destroy comment rights' it_should_behave_like 'user without destroy comment ability'
end end
end end

View File

@ -3,10 +3,6 @@ require 'spec_helper'
describe Projects::Git::TreesController do describe Projects::Git::TreesController do
def fill_project
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.repo.path}) # maybe FIXME ?
end
before(:each) do before(:each) do
stub_symlink_methods stub_symlink_methods
@ -19,13 +15,13 @@ describe Projects::Git::TreesController do
context 'for guest' do context 'for guest' do
it 'should be able to perform archive action with anonymous acccess', :anonymous_access => true do it 'should be able to perform archive action with anonymous acccess', :anonymous_access => true do
fill_project fill_project @project
get :archive, @params.merge(:format => 'tar.gz') get :archive, @params.merge(:format => 'tar.gz')
response.should be_success response.should be_success
end end
it 'should not be able to perform archive action without anonymous acccess', :anonymous_access => false do it 'should not be able to perform archive action without anonymous acccess', :anonymous_access => false do
fill_project fill_project @project
get :archive, @params.merge(:format => 'tar.gz') get :archive, @params.merge(:format => 'tar.gz')
response.code.should == '401' response.code.should == '401'
end end
@ -39,25 +35,27 @@ describe Projects::Git::TreesController do
end end
it 'should not be able to injection code with format' do it 'should not be able to injection code with format' do
fill_project @project
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
set_session_for(@user) set_session_for(@user)
fill_project
expect { get :archive, @params.merge(:format => "tar.gz master > /dev/null; echo 'I am hacker!';\#") }.to raise_error(ActionController::RoutingError) expect { get :archive, @params.merge(:format => "tar.gz master > /dev/null; echo 'I am hacker!';\#") }.to raise_error(ActionController::RoutingError)
end end
it 'should not be able to injection code with treeish' do it 'should not be able to injection code with treeish' do
fill_project @project
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
set_session_for(@user) set_session_for(@user)
fill_project
expect { get :archive, @params.merge(:treeish => "master > /dev/null; echo 'I am hacker!';\#") }.to raise_error(ActionController::RoutingError) expect { get :archive, @params.merge(:treeish => "master > /dev/null; echo 'I am hacker!';\#") }.to raise_error(ActionController::RoutingError)
end end
it 'should be able to perform archive action' do it 'should be able to perform archive action' do
fill_project @project
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
set_session_for(@user) set_session_for(@user)
fill_project
get :archive, @params.merge(:format => 'tar.gz') get :archive, @params.merge(:format => 'tar.gz')
response.should be_success response.should be_success
end end
end end
after(:all) {clean_projects_dir}
end end

View File

@ -7,8 +7,7 @@ shared_context "pull request controller" do
FileUtils.rm_rf(APP_CONFIG['root_path']) FileUtils.rm_rf(APP_CONFIG['root_path'])
stub_symlink_methods stub_symlink_methods
@project = FactoryGirl.create(:project) @project = FactoryGirl.create(:project_with_commit)
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.path})
@pull = @project.pull_requests.new :issue_attributes => {:title => 'test', :body => 'testing'} @pull = @project.pull_requests.new :issue_attributes => {:title => 'test', :body => 'testing'}
@pull.issue.user, @pull.issue.project = @project.owner, @pull.to_project @pull.issue.user, @pull.issue.project = @project.owner, @pull.to_project
@ -84,8 +83,7 @@ shared_examples_for 'pull request user with project reader rights' do
end end
it "should create pull request to the parent project" do it "should create pull request to the parent project" do
@parent = FactoryGirl.create(:project) @parent = FactoryGirl.create(:project_with_commit)
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@parent.path})
@project.update_attributes({:parent_id => @parent}, :without_protection => true) @project.update_attributes({:parent_id => @parent}, :without_protection => true)
lambda{ post :create, @create_params.merge({:to_project => @parent.name_with_owner}) }.should change{ PullRequest.joins(:issue). lambda{ post :create, @create_params.merge({:to_project => @parent.name_with_owner}) }.should change{ PullRequest.joins(:issue).

View File

@ -4,7 +4,7 @@ FactoryGirl.define do
association :user association :user
#association :project #association :project
association :save_to_platform, :factory => :platform_with_repos association :save_to_platform, :factory => :platform_with_repos
project { |bl| FactoryGirl.create(:project, :repositories => [bl.save_to_platform.repositories.first]) } project { |bl| FactoryGirl.create(:project_with_commit, :repositories => [bl.save_to_platform.repositories.first]) }
association :arch association :arch
build_for_platform {|bl| bl.save_to_platform} build_for_platform {|bl| bl.save_to_platform}
save_to_repository {|bl| bl.save_to_platform.repositories.first} save_to_repository {|bl| bl.save_to_platform.repositories.first}
@ -12,8 +12,7 @@ FactoryGirl.define do
update_type 'security' update_type 'security'
include_repos {|bl| bl.save_to_platform.repositories.map(&:id)} include_repos {|bl| bl.save_to_platform.repositories.map(&:id)}
project_version 'latest_master' project_version 'latest_master'
time_living 150 commit_hash {|bl| Grit::Repo.new(bl.project.path).commits.first.id}
after(:build) {|bl| test_git_commit bl.project }
end end
factory :build_list_core, :parent => :build_list do factory :build_list_core, :parent => :build_list do
@ -21,7 +20,7 @@ FactoryGirl.define do
end end
factory :build_list_by_group_project, :parent => :build_list_core do factory :build_list_by_group_project, :parent => :build_list_core do
project { |bl| FactoryGirl.create(:group_project, :repositories => [bl.save_to_platform.repositories.first]) } project { |bl| FactoryGirl.create(:group_project_with_commit, :repositories => [bl.save_to_platform.repositories.first]) }
end end
factory :build_list_package, :class => BuildList::Package do factory :build_list_package, :class => BuildList::Package do

View File

@ -3,11 +3,7 @@ FactoryGirl.define do
factory :product do factory :product do
name { FactoryGirl.generate(:string) } name { FactoryGirl.generate(:string) }
association :platform, :factory => :platform association :platform, :factory => :platform
association :project, :factory => :project association :project, :factory => :project_with_commit
before(:create) { |p|
p.project.repo.index.add('test', 'TEST')
p.project.repo.index.commit('Test commit')
}
time_living 150 time_living 150
end end
end end

View File

@ -9,4 +9,12 @@ FactoryGirl.define do
factory :group_project, :parent => :project do factory :group_project, :parent => :project do
association :owner, :factory => :group association :owner, :factory => :group
end end
factory :project_with_commit, :parent => :project do
after(:build) {|project| fill_project project}
end
factory :group_project_with_commit, :parent => :group_project do
after(:build) {|project| fill_project project}
end
end end

View File

@ -16,7 +16,6 @@ describe BuildList do
before(:all) { ActionMailer::Base.deliveries = [] } before(:all) { ActionMailer::Base.deliveries = [] }
before do before do
test_git_commit(build_list.project)
build_list.update_attributes(:commit_hash => build_list.project.repo.commits('master').last.id, build_list.update_attributes(:commit_hash => build_list.project.repo.commits('master').last.id,
:status => BuildServer::BUILD_STARTED,) :status => BuildServer::BUILD_STARTED,)
end end
@ -132,9 +131,8 @@ describe BuildList do
bl = FactoryGirl.create(:build_list_core, bl = FactoryGirl.create(:build_list_core,
:user => user, :user => user,
:auto_publish => true, :auto_publish => true,
:project => FactoryGirl.create(:project, :owner => user)) :project => FactoryGirl.create(:project_with_commit, :owner => user))
FactoryGirl.create(:build_list_package, :build_list => bl, :project => bl.project) FactoryGirl.create(:build_list_package, :build_list => bl, :project => bl.project)
test_git_commit(bl.project)
bl.update_attributes(:commit_hash => bl.project.repo.commits('master').last.id, bl.update_attributes(:commit_hash => bl.project.repo.commits('master').last.id,
:status => BuildList::BUILD_PUBLISH) :status => BuildList::BUILD_PUBLISH)
bl.published bl.published

View File

@ -137,7 +137,7 @@ describe CanCan do
context 'as project collaborator' do context 'as project collaborator' do
before(:each) do before(:each) do
@project = FactoryGirl.create(:project) @project = FactoryGirl.create(:project_with_commit)
@issue = FactoryGirl.create(:issue, :project_id => @project.id) @issue = FactoryGirl.create(:issue, :project_id => @project.id)
end end
@ -205,11 +205,8 @@ describe CanCan do
context 'with owner rights' do context 'with owner rights' do
before(:each) do before(:each) do
@project.owner = @user @project = FactoryGirl.create(:project_with_commit, :owner => @user)
@project.save @issue = FactoryGirl.create(:issue, :project_id => @project.id)
@project.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'admin')
@issue.project.reload
end end
[:read, :update, :destroy].each do |action| [:read, :update, :destroy].each do |action|

View File

@ -9,8 +9,7 @@ end
def set_comments_data_for_commit def set_comments_data_for_commit
@ability = Ability.new(@user) @ability = Ability.new(@user)
@project = FactoryGirl.create(:project, :owner => @user) @project = FactoryGirl.create(:project_with_commit, :owner => @user)
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.repo.path}) # maybe FIXME ?
@commit = @project.repo.commits.first @commit = @project.repo.commits.first
@comment = create_comment(@user) @comment = create_comment(@user)

View File

@ -1,6 +1,83 @@
# -*- encoding : utf-8 -*- # -*- encoding : utf-8 -*-
require 'spec_helper' require 'spec_helper'
describe Issue do def set_data
pending "add some examples to (or delete) #{__FILE__}" @user = FactoryGirl.create(:user)
@stranger = FactoryGirl.create(:user)
end
def create_issue issue_owner
ActionMailer::Base.deliveries = []
@issue = FactoryGirl.create(:issue, :project_id => @project.id,
:user => issue_owner, :assignee => nil)
end
describe Issue do
before do
stub_symlink_methods
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
end
context 'for project admin user' do
before(:each) do
set_data
@project = FactoryGirl.create(:project, :owner => @user)
create_issue(@stranger)
end
it 'should send an e-mail' do
ActionMailer::Base.deliveries.count.should == 1
ActionMailer::Base.deliveries.last.to.include?(@user.email).should == true
end
end
context 'for member-group' do
before(:each) do
set_data
@project = FactoryGirl.create(:project, :owner => @user)
@group = FactoryGirl.create(:group)
reader = FactoryGirl.create :user
@group.actors.create(:actor_type => 'User', :actor_id => reader.id, :role => 'reader')
end
it 'should send an e-mail to all members of the admin group' do
@project.relations.create!(:actor_type => 'Group', :actor_id => @group.id, :role => 'admin')
create_issue(@stranger)
ActionMailer::Base.deliveries.count.should == 3 # 1 owner + 2 group member. enough?
end
it 'should not send an e-mail to members of the reader group' do
@project.relations.create!(:actor_type => 'Group', :actor_id => @group.id, :role => 'reader')
create_issue(@stranger)
ActionMailer::Base.deliveries.count.should == 1 # 1 project owner
end
end
context 'Group project' do
before(:each) do
set_data
@group = FactoryGirl.create(:group, :owner => @user)
@project = FactoryGirl.create(:project, :owner => @group)
end
context 'for admin of the group' do
it 'should send an e-mail' do
create_issue(@stranger)
ActionMailer::Base.deliveries.count.should == 1
ActionMailer::Base.deliveries.last.to.include?(@user.email).should == true
end
end
context 'for reader of the group' do
it 'should not send an e-mail' do
reader = FactoryGirl.create :user
@group.actors.create(:actor_type => 'User', :actor_id => reader.id, :role => 'reader')
create_issue(@stranger)
ActionMailer::Base.deliveries.count.should == 1
end
end
end
end end

View File

@ -4,14 +4,12 @@ require 'spec_helper'
def set_data_for_pull def set_data_for_pull
@ability = Ability.new(@user) @ability = Ability.new(@user)
@project = FactoryGirl.create(:project, :owner => @user) @project = FactoryGirl.create(:project_with_commit, :owner => @user)
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.path})
@clone_path = File.join(APP_CONFIG['root_path'], 'repo_clone', @project.id.to_s) @clone_path = File.join(APP_CONFIG['root_path'], 'repo_clone', @project.id.to_s)
FileUtils.mkdir_p(@clone_path) FileUtils.mkdir_p(@clone_path)
@other_project = FactoryGirl.create(:project, :owner => @user) @other_project = FactoryGirl.create(:project_with_commit, :owner => @user)
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@other_project.path})
any_instance_of(Project, :versions => ['v1.0', 'v2.0']) any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
end end

View File

@ -52,14 +52,16 @@ def stub_key_pairs_calls
stub(BuildServer).rm_repository_key { 0 } stub(BuildServer).rm_repository_key { 0 }
end end
def test_git_commit(project)
project.repo.index.add('test', 'TEST')
project.repo.index.commit('Test commit')
end
Resque.inline = true Resque.inline = true
# Add testing root_path # Add testing root_path
%x(rm -Rf #{Rails.root}/tmp/test_root) %x(rm -Rf #{APP_CONFIG['git_path']})
%x(mkdir -p #{Rails.root}/tmp/test_root) %x(mkdir -p #{APP_CONFIG['git_path']})
APP_CONFIG['root_path'] = "#{Rails.root}/tmp/test_root"
def fill_project project
%x(mkdir -p #{project.path} && cp -Rf #{Rails.root}/spec/tests.git/* #{project.path}) # maybe FIXME ?
end
def clean_projects_dir
FileUtils.rm_rf "#{APP_CONFIG['git_path']}"
end

View File

@ -36,10 +36,66 @@ shared_examples_for 'user without destroy stranger comment ability (for model)'
end end
end end
shared_examples_for 'by default settings' do shared_examples_for 'user with create comment ability' do
it 'should send an e-mail' do it 'should be able to perform create action' do
comment = create_comment(@stranger) post :create, @create_params
ActionMailer::Base.deliveries.count.should == 1 response.should redirect_to(@return_path+"#comment#{Comment.last.id}")
ActionMailer::Base.deliveries.last.to.include?(@user.email).should == true end
it 'should create comment in the database' do
lambda{ post :create, @create_params }.should change{ Comment.count }.by(1)
end
end
shared_examples_for 'user with update own comment ability' do
it 'should be able to perform update action' do
put :update, {:id => @own_comment.id}.merge(@update_params)
response.status.should == 200
end
it 'should update subscribe body' 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 ability' do
it 'should be able to perform update action' do
put :update, {:id => @comment.id}.merge(@update_params)
response.status.should == 200
end
it 'should update comment body' do
put :update, {:id => @comment.id}.merge(@update_params)
@comment.reload.body.should == 'updated'
end
end
shared_examples_for 'user without update stranger comment ability' 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 comment body' do
put :update, {:id => @comment.id}.merge(@update_params)
@comment.reload.body.should_not == 'updated'
end
end
shared_examples_for 'user with destroy comment ability' do
it 'should be able to perform destroy action' do
delete :destroy, {:id => @comment.id}.merge(@path)
response.should redirect_to(@return_path)
end
it 'should delete comment from database' do
lambda{ delete :destroy, {:id => @comment.id}.merge(@path)}.should change{ Comment.count }.by(-1)
end
end
shared_examples_for 'user without destroy comment ability' do
it 'should not be able to perform destroy action' do
delete :destroy, {:id => @comment.id}.merge(@path)
response.should redirect_to(forbidden_path)
end
it 'should not delete comment from database' do
lambda{ delete :destroy, {:id => @comment.id}.merge(@path)}.should change{ Issue.count }.by(0)
end end
end end