Merge branch 'master' into 385-change-name-for-git-archives

This commit is contained in:
Vokhmin Alexey V 2012-09-20 14:53:29 +04:00
commit 805521c486
7 changed files with 172 additions and 119 deletions

View File

@ -127,6 +127,10 @@ class BuildList < ActiveRecord::Base
after_transition :on => :published, :do => [:set_version_and_tag, :actualize_packages]
after_transition :on => [:published, :fail_publish, :build_error], :do => :notify_users
after_transition :on => :build_success, :do => :notify_users,
:unless => lambda { |build_list| build_list.auto_publish? }
event :place_build do
transition :waiting_for_response => :build_pending, :if => lambda { |build_list|
build_list.add_to_queue == BuildServer::SUCCESS
@ -290,6 +294,22 @@ class BuildList < ActiveRecord::Base
protected
def notify_users
unless mass_build_id
users = []
if project # find associated users
users = project.all_members.
select{ |user| user.notifier.can_notify? && user.notifier.new_associated_build? }
end
if user.notifier.can_notify? && user.notifier.new_build?
users = users | [user]
end
users.each do |user|
UserMailer.build_list_notification(self, user).deliver
end
end
end # notify_users
def delete_container
if can_cancel?
BuildServer.delete_build_list bs_id

View File

@ -1,7 +1,4 @@
class BuildListObserver < ActiveRecord::Observer
PUBLICATION_STATUSES = [BuildList::BUILD_PUBLISHED, BuildList::FAILED_PUBLISH]
STATUSES = [BuildServer::BUILD_ERROR, BuildServer::SUCCESS] + PUBLICATION_STATUSES
observe :build_list
def before_update(record)
@ -18,28 +15,7 @@ class BuildListObserver < ActiveRecord::Observer
record.project.update_attributes({ :average_build_time => new_av_time, :build_count => build_count + 1 }, :without_protection => true)
end
end
BuildListObserver.notify_users(record)
end
end # before_update
private
def self.notify_users(build_list)
if !build_list.mass_build_id &&
( (build_list.auto_publish? && PUBLICATION_STATUSES.include?(build_list.status)) ||
(!build_list.auto_publish? && STATUSES.include?(build_list.status)) )
users = []
if build_list.project # find associated users
users = build_list.project.all_members.
select{ |user| user.notifier.can_notify? && user.notifier.new_associated_build? }
end
if build_list.user.notifier.can_notify? && build_list.user.notifier.new_build?
users = users | [build_list.user]
end
users.each do |user|
UserMailer.build_list_notification(build_list, user).deliver
end
end
end # notify_users
end

View File

@ -1,7 +1,7 @@
%p== Hello, #{@register_request.name || @register_request.email}.
%p
You have been invited to project ABF. Please click on the following link for registration:
= link_to 'link', new_user_registration_url(:invitation_token => @register_request.token)
You have been invited to project ABF. Please click on the following
= link_to 'link for registration', new_user_registration_url(:invitation_token => @register_request.token)
%p== Support team «ROSA Build System»

View File

@ -1,7 +1,7 @@
%p== Здравствуйте, #{@register_request.name || @register_request.email}.
%p
Вы приглашены в проект ABF. Чтобы зарегистрироваться перейдите по
= link_to 'ссылке', new_user_registration_url(:invitation_token => @register_request.token)
Вы приглашены в проект ABF. Пожалуйста, перейдите по
= link_to 'ссылке для регистрации', new_user_registration_url(:invitation_token => @register_request.token)
%p== Команда поддержки «ROSA Build System»

View File

@ -40,7 +40,7 @@ namespace :add_branch do
open(source).readlines.each do |name|
name.chomp!; name.strip!
print "Fork branch for '#{name}'... "
if p = Project.find_by_name_and_owner_type_and_owner_id(name, owner.class.to_s, owner.id)
if p = Project.find_by_owner_and_name(owner.uname, name)
# Rake::Task['add_branch:fork_branch'].execute(:path => p.path, :src_branch => src_branch, :dst_branch => dst_branch)
system "bundle exec rake add_branch:fork_branch[#{p.path},#{src_branch},#{dst_branch}] -s RAILS_ENV=#{Rails.env} > /dev/null 2>&1"
print 'Ok!'

View File

@ -1,94 +1,5 @@
require 'spec_helper'
describe BuildListObserver do
context "notify users" do
let!(:user) { FactoryGirl.create(:user) }
let!(:build_list) { FactoryGirl.create(:build_list, :user => user, :auto_publish => false) }
before(:all) { ActionMailer::Base.deliveries = [] }
before { build_list.update_attribute(:status, BuildServer::BUILD_STARTED) }
after { ActionMailer::Base.deliveries = [] }
shared_examples_for 'build list notifications by email' do
it "gets notification by email when status - Build complete" do
build_list.update_attribute(:status, BuildServer::SUCCESS)
should have(1).item
end
it "gets notification by email when status - Build published" do
build_list.update_attribute(:status, BuildList::BUILD_PUBLISHED)
should have(1).item
end
it "gets notification by email when auto_publish and status - Build published" do
build_list.update_attributes(:auto_publish => true, :status => BuildList::BUILD_PUBLISHED)
should have(1).item
end
it "doesn't get notification by email when auto_publish and status - Build complete" do
build_list.update_attributes(:auto_publish => true, :status => BuildServer::SUCCESS)
should have(:no).items
end
it "doesn't get notification by email when mass build" do
build_list.update_attributes(:mass_build_id => 1, :status => BuildList::BUILD_PUBLISHED)
should have(:no).items
end
it "doesn't get notification by email when notification by email has been disabled" do
notifier.update_attribute(:can_notify, false)
build_list.update_attribute(:status, BuildServer::SUCCESS)
should have(:no).items
end
end
subject { ActionMailer::Base.deliveries }
context "user created build task" do
let!(:notifier) { user.notifier }
before do
notifier.update_attribute(:new_associated_build, false)
build_list.project.owner.notifier.update_attribute(:can_notify, false)
end
it_should_behave_like 'build list notifications by email'
it "doesn't get notification by email when 'build list' notifications has been disabled" do
notifier.update_attribute(:new_build, false)
build_list.update_attribute(:status, BuildServer::SUCCESS)
should have(:no).items
end
it "doesn't get notification by email when 'build list' notifications - enabled, email notifications - disabled" do
notifier.update_attributes(:can_notify => false, :new_build => true)
build_list.update_attribute(:status, BuildServer::SUCCESS)
should have(:no).items
end
end
context "build task has been created and associated user" do
let!(:notifier) { build_list.project.owner.notifier }
before do
notifier.update_attribute(:new_build, false)
user.notifier.update_attribute(:can_notify, false)
end
it_should_behave_like 'build list notifications by email'
it "doesn't get notification by email when 'associated build list' notifications has been disabled" do
notifier.update_attribute(:new_associated_build, false)
build_list.update_attribute(:status, BuildServer::SUCCESS)
should have(:no).items
end
it "doesn't get notification by email when 'associated build list' notifications - enabled, email notifications - disabled" do
notifier.update_attributes(:can_notify => false, :new_associated_build => true)
build_list.update_attribute(:status, BuildServer::SUCCESS)
should have(:no).items
end
end
end # notify users
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -0,0 +1,146 @@
# -*- encoding : utf-8 -*-
require 'spec_helper'
describe BuildList do
context "#notify_users" do
before { stub_symlink_methods }
let!(:user) { FactoryGirl.create(:user) }
let!(:build_list) { FactoryGirl.create(:build_list_core,
:user => user,
:auto_publish => false) }
let!(:build_list_package) { FactoryGirl.create(:build_list_package,
:build_list => build_list,
:project => build_list.project) }
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
after { ActionMailer::Base.deliveries = [] }
shared_examples_for 'build list notifications by email' do
it "gets notification by email when status - Build complete" do
build_list.build_success
should have(1).item
end
it "gets notification by email when status - Build error" do
build_list.build_error
should have(1).item
end
it "gets notification by email when auto_publish and status - Build error" do
build_list.update_attributes(:auto_publish => true)
build_list.build_error
should have(1).item
end
it "gets notification by email when status - Failed publish" do
build_list.update_attributes(:status => BuildList::BUILD_PUBLISH)
build_list.fail_publish
should have(1).item
end
it "gets notification by email when auto_publish and status - Failed publish" do
build_list.update_attributes(:auto_publish => true, :status => BuildList::BUILD_PUBLISH)
build_list.fail_publish
should have(1).item
end
it "gets notification by email when status - Build published" do
build_list.update_attributes(:status => BuildList::BUILD_PUBLISH)
build_list.published
should have(1).item
end
it "gets notification by email when auto_publish and status - Build published" do
build_list.update_attributes(:auto_publish => true, :status => BuildList::BUILD_PUBLISH)
build_list.published
should have(1).item
end
it "doesn't get notification by email when auto_publish and status - Build complete" do
build_list.update_attributes(:auto_publish => true)
build_list.build_success
should have(:no).items
end
it "doesn't get notification by email when mass build" do
build_list.update_attributes(:mass_build_id => 1, :status => BuildList::BUILD_PUBLISH)
build_list.published
should have(:no).items
end
it "doesn't get notification by email when notification by email has been disabled" do
notifier.update_attributes(:can_notify => false)
build_list.build_success
should have(:no).items
end
end
subject { ActionMailer::Base.deliveries }
context "user created build task" do
let!(:notifier) { user.notifier }
before do
notifier.update_attributes(:new_associated_build => false)
build_list.project.owner.notifier.update_attributes(:can_notify => false)
end
it_should_behave_like 'build list notifications by email'
it "doesn't get notification by email when 'build list' notifications has been disabled" do
notifier.update_attributes(:new_build => false)
build_list.build_success
should have(:no).items
end
it "doesn't get notification by email when 'build list' notifications - enabled, email notifications - disabled" do
notifier.update_attributes(:can_notify => false, :new_build => true)
build_list.build_success
should have(:no).items
end
end
context "build task has been created and associated user" do
let!(:notifier) { build_list.project.owner.notifier }
before do
notifier.update_attributes(:new_build => false)
user.notifier.update_attributes(:can_notify => false)
end
it_should_behave_like 'build list notifications by email'
it "doesn't get notification by email when 'associated build list' notifications has been disabled" do
notifier.update_attributes(:new_associated_build => false)
build_list.build_success
should have(:no).items
end
it "doesn't get notification by email when 'associated build list' notifications - enabled, email notifications - disabled" do
notifier.update_attributes(:can_notify => false, :new_associated_build => true)
build_list.build_success
should have(:no).items
end
end
it "doesn't get 2 notification by email when user associated to project and created task" do
bl = FactoryGirl.create(:build_list_core,
:user => user,
:auto_publish => true,
:project => FactoryGirl.create(:project, :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
should have(1).item
end
end # notify_users
end