#794: merge master into branch

This commit is contained in:
Vokhmin Alexey V 2012-12-20 19:33:14 +04:00
commit a09699fc03
31 changed files with 362 additions and 367 deletions

View File

@ -12,10 +12,8 @@ class ActivityFeedObserver < ActiveRecord::Observer
)
when 'Issue'
recipients = record.collect_recipient_ids
recipients.each do |recipient_id|
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
record.collect_recipients.each do |recipient|
UserMailer.new_issue_notification(record, recipient).deliver if recipient.notifier.can_notify && recipient.notifier.new_issue
ActivityFeed.create(
:user => recipient,
: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
end
record.project.owner_and_admin_ids.each do |recipient|
record.project.admins.each do |recipient|
ActivityFeed.create!(
:user => User.find(recipient),
:user => recipient,
:kind => kind,
:data => options
)
@ -106,9 +104,9 @@ class ActivityFeedObserver < ActiveRecord::Observer
actor = User.find_by_uname! record[:actor_name]
project = Project.find record[:project_id]
project.owner_and_admin_ids.each do |recipient|
project.admins.each do |recipient|
ActivityFeed.create!(
:user => User.find(recipient),#record.user,
:user => recipient,
:kind => 'wiki_new_commit_notification',
: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}
@ -134,9 +132,9 @@ class ActivityFeedObserver < ActiveRecord::Observer
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
(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(
:user => User.find(recipient),
:user => recipient,
:kind => 'build_list_notification',
: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,

View File

@ -139,9 +139,8 @@ 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(: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 = project.admins
recipients << user << User.where(:email => commentable.try(:committer).try(:email)).first # commentor and committer
recipients.compact.uniq.each do |user|
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)

View File

@ -62,11 +62,9 @@ class Issue < ActiveRecord::Base
self.status = 'open'
end
def collect_recipient_ids
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'
def collect_recipients
recipients = self.project.admins
recipients = recipients | [self.assignee] if self.assignee
recipients
end
@ -78,10 +76,9 @@ class Issue < ActiveRecord::Base
end
def subscribe_users
recipients = collect_recipient_ids
recipients.each do |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)
collect_recipients.each do |recipient|
if recipient.notifier.new_comment && !self.subscribes.exists?(:user_id => recipient.id)
ss = self.subscribes.create(:user_id => recipient.id)
end
end
end
@ -94,5 +91,4 @@ class Issue < ActiveRecord::Base
end
end
end
end

View File

@ -103,10 +103,14 @@ class Project < ActiveRecord::Base
@platforms ||= repositories.map(&:platform).uniq
end
def owner_and_admin_ids
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
def admins
admins = self.collaborators.where("relations.role = 'admin'")
grs = self.groups.where("relations.role = 'admin'")
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
def public?
@ -120,7 +124,8 @@ class Project < ActiveRecord::Base
def git_project_address auth_user
host ||= EventLog.current_controller.request.host_with_port rescue ::Rosa::Application.config.action_mailer.default_url_options[:host]
protocol = APP_CONFIG['mailer_https_url'] ? "https" : "http" rescue "http"
opts = {:host => host, :protocol => protocol, :user => auth_user.authentication_token, :password => ''}
opts = {:host => host, :protocol => protocol}
opts.merge!({:user => auth_user.authentication_token, :password => ''}) unless self.public?
Rails.application.routes.url_helpers.project_url(self.owner.uname, self.name, opts) + ".git"
#path #share by NFS
end

View File

@ -13,7 +13,7 @@
%tr
- sha1 = item['sha1']
- filename = item['file_name']
- url = "#{APP_CONFIG['file_store_url']}/#{sha1}"
- url = "#{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{sha1}"
- url << '.log?show=true' if filename =~ /.*\.(log|txt)$/
%td= link_to filename, url
%td= sha1

View File

@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# argv[0] user token; argv[1] url to file-store
require 'json'
require 'rest-client'
@ -9,8 +10,7 @@ old_sources = if File.exist? abf_yml
[]
end
#MAX_SIZE = 2 * 1024 * 1024 # 2.megabytes
url = "#{APP_CONFIG['file_store_url']}.json"
#url = 'http://localhost:3001/api/v1/file_stores.json'
url = "#{ARGF.argv[1]}/api/v1"
rclient = RestClient::Resource.new(url, :user => ARGF.argv[0]) # user auth token
Dir.glob("*.{bz2,rar,gz,tar,tbz2,tgz,zip,Z,7z,xz,lzma}").uniq.sort.each do |file|
@ -18,7 +18,7 @@ Dir.glob("*.{bz2,rar,gz,tar,tbz2,tgz,zip,Z,7z,xz,lzma}").uniq.sort.each do |file
#next if File.size(file) < MAX_SIZE
sha1 = Digest::SHA1.file(file).hexdigest
resp = JSON(RestClient.get url, :params => {:hash => sha1})
resp = JSON(RestClient.get "#{url}/file_stores", :params => {:hash => sha1})
if resp[0].respond_to?('[]') && resp[0]['file_name'] && resp[0]['sha1_hash']
# file already exists at file-store
new_sources << " \"#{file}\": #{sha1}"
@ -26,7 +26,7 @@ Dir.glob("*.{bz2,rar,gz,tar,tbz2,tgz,zip,Z,7z,xz,lzma}").uniq.sort.each do |file
puts " file \"#{file}\" already exists in the file-store"
elsif resp == []
# try to put file at file-store
resp = JSON `curl --user #{ARGF.argv[0]}: -POST -F "file_store[file]=@#{file}" http://file-store.rosalinux.ru/api/v1/upload`
resp = JSON `curl --user #{ARGF.argv[0]}: -POST -F "file_store[file]=@#{file}" #{url}/upload`
unless resp['sha1_hash'].nil?
new_sources << " \"#{file}\": #{sha1}"
FileUtils.rm_rf file

View File

@ -6,6 +6,7 @@ git_path=$2
git_branch=$3
script=$4
token=$5
file_store_url=$6
name=$(rpm -q --qf '[%{Name}]' -p $srpm_path)
version=$(rpm -q --qf '[%{Version}-%{Release}]' -p $srpm_path)
tmp_dir=/tmp/$name-$version-$RANDOM
@ -32,7 +33,7 @@ cpio -idv < srpm.cpio
rm -f srpm.cpio
# Remove archives
$script $token
$script $token $file_store_url
# Commit and push changes
git add -A .

View File

@ -17,8 +17,8 @@ ActiveRecord::Schema.define(:version => 20121219122905) do
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 "advisories", :force => true do |t|
@ -53,8 +53,8 @@ ActiveRecord::Schema.define(:version => 20121219122905) do
create_table "arches", :force => true do |t|
t.string "name", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "arches", ["name"], :name => "index_arches_on_name", :unique => true
@ -63,8 +63,8 @@ ActiveRecord::Schema.define(:version => 20121219122905) do
t.integer "user_id"
t.string "provider"
t.string "uid"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "authentications", ["provider", "uid"], :name => "index_authentications_on_provider_and_uid", :unique => true
@ -75,8 +75,8 @@ ActiveRecord::Schema.define(:version => 20121219122905) do
t.integer "level"
t.integer "status"
t.integer "build_list_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "version"
end
@ -110,8 +110,8 @@ ActiveRecord::Schema.define(:version => 20121219122905) do
t.integer "project_id"
t.integer "arch_id"
t.datetime "notified_at"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "is_circle", :default => false
t.text "additional_repos"
t.string "name"
@ -145,8 +145,8 @@ ActiveRecord::Schema.define(:version => 20121219122905) do
t.string "commentable_type"
t.integer "user_id"
t.text "body"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.decimal "commentable_id", :precision => 50, :scale => 0
t.integer "project_id"
t.text "data"
@ -164,8 +164,8 @@ ActiveRecord::Schema.define(:version => 20121219122905) do
t.string "controller"
t.string "action"
t.text "message"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "flash_notifies", :force => true do |t|
@ -179,8 +179,8 @@ ActiveRecord::Schema.define(:version => 20121219122905) do
create_table "groups", :force => true do |t|
t.integer "owner_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "uname"
t.integer "own_projects_count", :default => 0, :null => false
t.text "description"
@ -197,8 +197,8 @@ ActiveRecord::Schema.define(:version => 20121219122905) do
t.string "title"
t.text "body"
t.string "status", :default => "open"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "user_id"
t.datetime "closed_at"
t.integer "closed_by"
@ -272,14 +272,14 @@ ActiveRecord::Schema.define(:version => 20121219122905) do
t.string "description"
t.string "name", :null => false
t.integer "parent_platform_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "released", :default => false, :null => false
t.integer "owner_id"
t.string "owner_type"
t.string "visibility", :default => "open", :null => false
t.string "platform_type", :default => "main", :null => false
t.string "distrib_type", :null => false
t.string "distrib_type"
end
add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false
@ -288,16 +288,16 @@ ActiveRecord::Schema.define(:version => 20121219122905) do
t.integer "platform_id"
t.string "login"
t.string "password"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "user_id"
end
create_table "product_build_lists", :force => true do |t|
t.integer "product_id"
t.integer "status", :default => 2, :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "status", :default => 3, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "project_id"
t.string "project_version"
t.string "commit_hash"
@ -314,8 +314,8 @@ ActiveRecord::Schema.define(:version => 20121219122905) do
create_table "products", :force => true do |t|
t.string "name", :null => false
t.integer "platform_id", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.text "description"
t.integer "project_id"
t.string "params"
@ -328,8 +328,8 @@ ActiveRecord::Schema.define(:version => 20121219122905) do
t.string "name"
t.string "version"
t.datetime "file_mtime"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "platform_id"
end
@ -338,27 +338,27 @@ ActiveRecord::Schema.define(:version => 20121219122905) do
create_table "project_to_repositories", :force => true do |t|
t.integer "project_id"
t.integer "repository_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
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|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "owner_id"
t.string "owner_type"
t.string "visibility", :default => "open"
t.text "description"
t.string "ancestry"
t.boolean "has_issues", :default => true
t.boolean "has_wiki", :default => false
t.string "srpm_file_name"
t.string "srpm_content_type"
t.integer "srpm_file_size"
t.datetime "srpm_updated_at"
t.string "srpm_content_type"
t.boolean "has_wiki", :default => false
t.string "default_branch", :default => "master"
t.boolean "is_package", :default => true, :null => false
t.integer "average_build_time", :default => 0, :null => false
@ -388,8 +388,8 @@ ActiveRecord::Schema.define(:version => 20121219122905) do
t.string "token"
t.boolean "approved", :default => false
t.boolean "rejected", :default => false
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "interest"
t.text "more"
t.string "language"
@ -403,16 +403,16 @@ ActiveRecord::Schema.define(:version => 20121219122905) do
t.string "actor_type"
t.integer "target_id"
t.string "target_type"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "role"
end
create_table "repositories", :force => true do |t|
t.string "description", :null => false
t.integer "platform_id", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "name", :null => false
t.boolean "publish_without_qa", :default => true
end
@ -426,8 +426,8 @@ ActiveRecord::Schema.define(:version => 20121219122905) do
t.boolean "new_comment_reply", :default => true
t.boolean "new_issue", :default => true
t.boolean "issue_assign", :default => true
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "new_comment_commit_owner", :default => true
t.boolean "new_comment_commit_repo_owner", :default => true
t.boolean "new_comment_commit_commentor", :default => true
@ -438,8 +438,8 @@ ActiveRecord::Schema.define(:version => 20121219122905) do
create_table "subscribes", :force => true do |t|
t.string "subscribeable_type"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "status", :default => true
t.integer "project_id"
t.decimal "subscribeable_id", :precision => 50, :scale => 0
@ -447,18 +447,21 @@ ActiveRecord::Schema.define(:version => 20121219122905) 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 "email", :default => "", :null => false
t.string "encrypted_password", :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.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.text "ssh_key"
t.string "uname"
t.string "role"
t.string "language", :default => "en"
t.integer "own_projects_count", :default => 0, :null => false
t.string "language", :default => "en"
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.string "site"
t.string "company"
@ -467,14 +470,11 @@ ActiveRecord::Schema.define(:version => 20121219122905) do
t.string "avatar_content_type"
t.integer "avatar_file_size"
t.datetime "avatar_updated_at"
t.integer "failed_attempts", :default => 0
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"
t.integer "build_priority", :default => 50
t.integer "build_priority", :default => 50
end
add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token"

View File

@ -53,7 +53,7 @@ module AbfWorker
select{ |r| r['file_name'] !~ /.*\.log$/ }.first
sha1 = container ? container['sha1'] : nil
if sha1
bl.container_path = "#{APP_CONFIG['file_store_url']}/#{sha1}"
bl.container_path = "#{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{sha1}"
bl.save!
end
update_results(bl, options)

View File

@ -93,7 +93,8 @@ module Modules
def import_srpm(srpm_path = srpm.path, branch_name = 'import')
token = User.find_by_uname('rosa_system').authentication_token
system("#{Rails.root.join('bin', 'import_srpm.sh')} #{srpm_path} #{path} #{branch_name} #{Rails.root.join('bin', 'file-store.rb')} #{token} >> /dev/null 2>&1")
opts = [srpm_path, path, branch_name, Rails.root.join('bin', 'file-store.rb'), token, APP_CONFIG['file_store_url']].join(' ')
system("#{Rails.root.join('bin', 'import_srpm.sh')} #{opts} >> /dev/null 2>&1")
end
protected

View File

@ -1,6 +1,10 @@
# -*- encoding : utf-8 -*-
require 'spec_helper'
def incorrect_action_message
'Incorrect action for current build list'
end
shared_examples_for 'show build list via api' do
it 'should be able to perform show action' do
get :show, @show_params
@ -127,7 +131,7 @@ describe Api::V1::BuildListsController do
it "should return correct json error message" do
@build_list.update_column(:status, BuildServer::PROJECT_NOT_FOUND)
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
it "should not cancel build list" do
@ -183,7 +187,7 @@ describe Api::V1::BuildListsController do
end
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
it "should not cancel build list" do
@ -243,7 +247,7 @@ describe Api::V1::BuildListsController do
end
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
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.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_list4 = FactoryGirl.create(:build_list_core)

View File

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

View File

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

View File

@ -8,7 +8,7 @@ describe Groups::MembersController do
@user = @group.owner
set_session_for @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"]}}
@update_params = {:group_id => @group, :user => {"#{@group.owner.id}"=>'reader'}}
end

View File

@ -24,8 +24,10 @@ shared_examples_for 'product build list admin' do
end
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
response.should redirect_to(platform_product_product_build_list_path(@product.platform, @product, @pbl))
response.should redirect_to(url)
end
it 'should be able to perform show action' do
@ -99,7 +101,7 @@ describe Platforms::ProductBuildListsController do
def valid_attributes_for_destroy
{:id => @pbl.id, :product_id => @pbl.product.id, :platform_id => @pbl.product.platform.id }
end
def valid_attributes_for_show
valid_attributes_for_destroy
end
@ -121,7 +123,7 @@ describe Platforms::ProductBuildListsController do
context 'for user' do
before(:each) { set_session_for FactoryGirl.create(:user) }
it_should_behave_like 'product build list user'
it_should_behave_like 'product build list user without admin rights'
@ -131,7 +133,7 @@ describe Platforms::ProductBuildListsController do
before(:each) do
@user = FactoryGirl.create(: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
it_should_behave_like 'product build list admin'
@ -143,14 +145,14 @@ describe Platforms::ProductBuildListsController do
it_should_behave_like 'product build list admin'
it_should_behave_like 'product build list user'
end
end
context 'callbacks' do
let(:pbl) { FactoryGirl.create(:product_build_list) }
before(:each) do
mock(controller).authenticate_product_builder! {true}
end

View File

@ -23,21 +23,21 @@ shared_examples_for 'admin user' do
end
describe Platforms::ProductsController do
before(:each) do
stub_symlink_methods
before(:each) do
stub_symlink_methods
@another_user = FactoryGirl.create(:user)
@platform = FactoryGirl.create(:platform)
@product = FactoryGirl.create(:product, :platform => @platform)
@project = FactoryGirl.create(:project)
@another_user = FactoryGirl.create(:user)
@platform = FactoryGirl.create(:platform)
@product = FactoryGirl.create(:product, :platform => @platform)
@project = FactoryGirl.create(:project)
params = {:platform_id => @platform.id, :src_project => @project.name_with_owner}
@create_params = params.merge({:product => {:name => 'pro'}})
@update_params = params.merge({:product => {:name => 'pro2'}})
params = {:platform_id => @platform.id, :src_project => @project.name_with_owner}
@create_params = params.merge({:product => {:name => 'pro', :time_living => 150}})
@update_params = params.merge({:product => {:name => 'pro2'}})
@user = FactoryGirl.create(:user)
set_session_for(@user)
end
@user = FactoryGirl.create(:user)
set_session_for(@user)
end
context 'for guest' do
before(:each) do

View File

@ -44,13 +44,13 @@ describe Projects::BuildListsController 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"})
@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
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
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
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.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_list4 = FactoryGirl.create(:build_list_core)
@ -217,7 +217,7 @@ describe Projects::BuildListsController do
@build_list2 = FactoryGirl.create(:build_list_core)
@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_list4 = FactoryGirl.create(:build_list_core)
@ -346,7 +346,6 @@ describe Projects::BuildListsController do
describe 'publish_build' do
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(:status, BuildList::BUILD_PUBLISH)
build_list_package
@ -508,4 +507,5 @@ describe Projects::BuildListsController do
it { lambda{ do_get }.should change(build_list, :updated_at) }
end
end
after(:all) {clean_projects_dir}
end

View File

@ -1,94 +1,22 @@
# -*- encoding : utf-8 -*-
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
before(:each) do
stub_symlink_methods
@project = FactoryGirl.create(:project)
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.repo.path}) # maybe FIXME ?
@project = FactoryGirl.create(:project_with_commit)
@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}
@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'])
@stranger_comment = create_comment FactoryGirl.create(:user)
@comment = FactoryGirl.create(:comment, :commentable => @commit, :project => @project)
@user = FactoryGirl.create(:user)
@own_comment = create_comment @user
@own_comment = FactoryGirl.create(:comment, :commentable => @commit, :user => @user, :project => @project)
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
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')
end
it_should_behave_like 'user with create comment rights for commits'
it_should_behave_like 'user with update stranger comment rights for commits'
it_should_behave_like 'user with update own comment rights for commits'
it_should_behave_like 'user with destroy comment rights for commits'
#it_should_behave_like 'user with destroy rights'
it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user with update stranger comment ability'
it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user with destroy comment ability'
#it_should_behave_like 'user with destroy ability'
end
context 'for project owner user' do
before(:each) do
@user.destroy
@user = @project.owner
set_session_for(@user)
@own_comment = create_comment @user
set_session_for(@project.owner)
end
it_should_behave_like 'user with create comment rights for commits'
it_should_behave_like 'user with update stranger comment rights for commits'
it_should_behave_like 'user with update own comment rights for commits'
it_should_behave_like 'user with destroy comment rights for commits'
it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user with update stranger comment ability'
it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user with destroy comment ability'
end
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')
end
it_should_behave_like 'user with create comment rights for commits'
it_should_behave_like 'user without update stranger comment rights for commits'
it_should_behave_like 'user with update own comment rights for commits'
it_should_behave_like 'user without destroy comment rights for commits'
it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user without update stranger comment ability'
it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user without destroy comment ability'
end
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')
end
it_should_behave_like 'user with create comment rights for commits'
it_should_behave_like 'user without update stranger comment rights for commits'
it_should_behave_like 'user with update own comment rights for commits'
it_should_behave_like 'user without destroy comment rights for commits'
it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user without update stranger comment ability'
it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user without destroy comment ability'
end
end

View File

@ -6,7 +6,7 @@ shared_context "comments controller" do
stub_symlink_methods
@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)
@user = FactoryGirl.create(:user)
@ -14,82 +14,14 @@ shared_context "comments controller" do
set_session_for(@user)
@address = {:owner_name => @project.owner.uname, :project_name => @project.name, :issue_id => @issue.serial_id}
@create_params = {:comment => {:body => 'I am a comment!'}}.merge(@address)
@update_params = {:comment => {:body => 'updated'}}.merge(@address)
@path = {:owner_name => @project.owner.uname, :project_name => @project.name, :issue_id => @issue.serial_id}
@return_path = project_issue_path(@project, @issue)
@create_params = {:comment => {:body => 'I am a comment!'}}.merge(@path)
@update_params = {:comment => {:body => 'updated'}}.merge(@path)
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
include_context "comments controller"
@ -99,10 +31,10 @@ describe Projects::CommentsController do
@user.save
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 with destroy comment rights'
it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user with update stranger comment ability'
it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user with destroy comment ability'
end
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')
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 with destroy comment rights'
it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user with update stranger comment ability'
it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user with destroy comment ability'
end
context 'for project owner user' do
@ -121,10 +53,10 @@ describe Projects::CommentsController do
set_session_for(@project.owner) # owner should be 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 with destroy comment rights'
it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user with update stranger comment ability'
it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user with destroy comment ability'
end
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')
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'
it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user without update stranger comment ability'
it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user without destroy comment ability'
end
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')
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'
it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user without update stranger comment ability'
it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user without destroy comment ability'
end
end

View File

@ -3,10 +3,6 @@ require 'spec_helper'
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
stub_symlink_methods
@ -19,13 +15,13 @@ describe Projects::Git::TreesController do
context 'for guest' 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')
response.should be_success
end
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')
response.code.should == '401'
end
@ -39,25 +35,27 @@ describe Projects::Git::TreesController do
end
it 'should not be able to injection code with format' do
fill_project @project
@user = FactoryGirl.create(: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)
end
it 'should not be able to injection code with treeish' do
fill_project @project
@user = FactoryGirl.create(: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)
end
it 'should be able to perform archive action' do
fill_project @project
@user = FactoryGirl.create(:user)
set_session_for(@user)
fill_project
get :archive, @params.merge(:format => 'tar.gz')
response.should be_success
end
end
after(:all) {clean_projects_dir}
end

View File

@ -7,8 +7,7 @@ shared_context "pull request controller" do
FileUtils.rm_rf(APP_CONFIG['root_path'])
stub_symlink_methods
@project = FactoryGirl.create(:project)
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.path})
@project = FactoryGirl.create(:project_with_commit)
@pull = @project.pull_requests.new :issue_attributes => {:title => 'test', :body => 'testing'}
@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
it "should create pull request to the parent project" do
@parent = FactoryGirl.create(:project)
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@parent.path})
@parent = FactoryGirl.create(:project_with_commit)
@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).

View File

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

View File

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

View File

@ -9,4 +9,12 @@ FactoryGirl.define do
factory :group_project, :parent => :project do
association :owner, :factory => :group
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

View File

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

View File

@ -32,7 +32,7 @@ describe CanCan do
before(:each) do
admin_create
end
it 'should manage all' do
#(@ability.can? :manage, :all).should be_true
@ability.should be_able_to(:manage, :all)
@ -93,7 +93,7 @@ describe CanCan do
@ability.should be_able_to(:read, model_name)
end
end
it "shoud be able to show user profile" do
@ability.should be_able_to(:show, User)
end
@ -123,21 +123,21 @@ describe CanCan do
context "private users relations" do
before(:each) do
@private_user = FactoryGirl.create(:private_user)
@private_user.platform.owner = @user
@private_user.platform.save
end
[:read, :create].each do |action|
it "should be able to #{ action } PrivateUser" do
@ability.should be_able_to(action, @private_user)
@ability.should be_able_to(action, @private_user)
end
end
end
context 'as project collaborator' do
before(:each) do
@project = FactoryGirl.create(:project)
@project = FactoryGirl.create(:project_with_commit)
@issue = FactoryGirl.create(:issue, :project_id => @project.id)
end
@ -205,11 +205,8 @@ describe CanCan do
context 'with owner rights' do
before(:each) do
@project.owner = @user
@project.save
@project.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'admin')
@issue.project.reload
@project = FactoryGirl.create(:project_with_commit, :owner => @user)
@issue = FactoryGirl.create(:issue, :project_id => @project.id)
end
[:read, :update, :destroy].each do |action|

View File

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

View File

@ -1,6 +1,83 @@
# -*- encoding : utf-8 -*-
require 'spec_helper'
describe Issue do
pending "add some examples to (or delete) #{__FILE__}"
def set_data
@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

View File

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

View File

@ -52,11 +52,6 @@ def stub_key_pairs_calls
stub(BuildServer).rm_repository_key { 0 }
end
def test_git_commit(project)
project.repo.index.add('test', 'TEST')
project.repo.index.commit('Test commit')
end
Resque.inline = true
def init_test_root
@ -71,3 +66,15 @@ end
init_test_root
APP_CONFIG['root_path'] = "#{Rails.root}/tmp/test_root"
# Add testing root_path
%x(rm -Rf #{APP_CONFIG['git_path']})
%x(mkdir -p #{APP_CONFIG['git_path']})
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
shared_examples_for 'by default settings' do
it 'should send an e-mail' do
comment = create_comment(@stranger)
ActionMailer::Base.deliveries.count.should == 1
ActionMailer::Base.deliveries.last.to.include?(@user.email).should == true
shared_examples_for 'user with create comment ability' do
it 'should be able to perform create action' do
post :create, @create_params
response.should redirect_to(@return_path+"#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 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