#345: fixed some specs, build_list_observer
This commit is contained in:
parent
94e285e64f
commit
c06245aa9f
|
@ -52,6 +52,11 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
# Helper method for all controllers
|
||||
def permit_params(param_name, *accessible)
|
||||
(params[param_name] || ActionController::Parameters.new).permit(*accessible.flatten)
|
||||
end
|
||||
|
||||
def set_locale
|
||||
I18n.locale = check_locale( get_user_locale ||
|
||||
(request.env['HTTP_ACCEPT_LANGUAGE'] ? request.env['HTTP_ACCEPT_LANGUAGE'][0,2].downcase : nil ))
|
||||
|
|
|
@ -49,4 +49,5 @@ class Users::SettingsController < Users::BaseController
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ class ActivityFeed < ActiveRecord::Base
|
|||
belongs_to :user
|
||||
serialize :data
|
||||
|
||||
attr_accessible :user_id, :kind, :data
|
||||
attr_accessible :user, :kind, :data
|
||||
|
||||
default_scope { order created_at: :desc }
|
||||
scope :outdated, -> { offset(100) }
|
||||
|
|
|
@ -9,16 +9,16 @@ module BuildListObserver
|
|||
|
||||
def update_average_build_time
|
||||
if status_changed?
|
||||
started_at = Time.now if status == BUILD_STARTED
|
||||
if [BUILD_ERROR,
|
||||
SUCCESS,
|
||||
BUILD_CANCELING,
|
||||
TESTS_FAILED,
|
||||
BUILD_CANCELED].include? status
|
||||
started_at = Time.now if status == self.class::BUILD_STARTED
|
||||
if [self.class::BUILD_ERROR,
|
||||
self.class::SUCCESS,
|
||||
self.class::BUILD_CANCELING,
|
||||
self.class::TESTS_FAILED,
|
||||
self.class::BUILD_CANCELED].include? status
|
||||
# stores time interval beetwin build start and finish in seconds
|
||||
duration = current_duration if started_at
|
||||
|
||||
if status == SUCCESS
|
||||
if status == self.class::SUCCESS
|
||||
# Update project average build time
|
||||
begin
|
||||
statistic = project.project_statistics.find_or_create_by_arch_id(arch_id)
|
||||
|
@ -26,7 +26,7 @@ module BuildListObserver
|
|||
retry
|
||||
end
|
||||
build_count = statistic.build_count.to_i
|
||||
new_av_time = ( statistic.average_build_time * build_count + record.duration.to_i ) / ( build_count + 1 )
|
||||
new_av_time = ( statistic.average_build_time * build_count + duration.to_i ) / ( build_count + 1 )
|
||||
statistic.update_attributes(average_build_time: new_av_time, build_count: build_count + 1)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,4 +2,5 @@ class SettingsNotifier < ActiveRecord::Base
|
|||
belongs_to :user
|
||||
|
||||
validates :user_id, presence: true
|
||||
|
||||
end
|
||||
|
|
|
@ -247,7 +247,7 @@ Rosa::Application.routes.draw do
|
|||
get :private
|
||||
put :private
|
||||
get :notifiers
|
||||
put :notifiers
|
||||
patch :notifiers
|
||||
put :reset_auth_token
|
||||
end
|
||||
end
|
||||
|
@ -356,7 +356,8 @@ Rosa::Application.routes.draw do
|
|||
get '/sections' => 'projects#sections', as: :sections_project
|
||||
post '/sections' => 'projects#sections'
|
||||
delete '/remove_user' => 'projects#remove_user', as: :remove_user_project
|
||||
constraints treeish: /.+/ do
|
||||
# constraints treeish: /[\w\-\.]+(\/[\w\-\.]+)?/ do
|
||||
constraints treeish: /[\w\-\.]+/ do
|
||||
constraints Rosa::Constraints::Treeish do
|
||||
# Tree
|
||||
get '/' => "git/trees#show", as: :project
|
||||
|
|
|
@ -4,6 +4,5 @@ FactoryGirl.define do
|
|||
association :user, factory: :user
|
||||
association :commentable, factory: :issue
|
||||
project { |c| c.commentable.project }
|
||||
after(:create) { |c| c.send(:new_comment_notifications) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,9 +6,5 @@ FactoryGirl.define do
|
|||
association :user, factory: :user
|
||||
association :assignee, factory: :user
|
||||
status "open"
|
||||
# Hooks for #after_commit
|
||||
after(:create) { |i| i.send(:new_issue_notifications) }
|
||||
after(:create) { |i| i.send(:send_assign_notifications) }
|
||||
after(:create) { |i| i.send(:send_hooks) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ require "spec_helper"
|
|||
describe UserMailer do
|
||||
|
||||
context 'On Issue create' do
|
||||
before(:each) do
|
||||
before do
|
||||
stub_symlink_methods
|
||||
|
||||
@project = FactoryGirl.create(:project)
|
||||
|
@ -11,7 +11,7 @@ describe UserMailer do
|
|||
|
||||
any_instance_of(Project, versions: ['v1.0', 'v2.0'])
|
||||
|
||||
@issue = FactoryGirl.create(:issue, project_id: @project.id, assignee_id: @issue_user.id, user: @issue_user)
|
||||
@issue = FactoryGirl.create(:issue, project: @project, assignee: @issue_user, user: @issue_user)
|
||||
@email = UserMailer.new_issue_notification(@issue, @issue_user).deliver!
|
||||
end
|
||||
|
||||
|
@ -69,7 +69,7 @@ describe UserMailer do
|
|||
|
||||
|
||||
context 'On Comment create' do
|
||||
before(:each) do
|
||||
before do
|
||||
stub_symlink_methods
|
||||
|
||||
@project = FactoryGirl.create(:project)
|
||||
|
@ -78,8 +78,8 @@ describe UserMailer do
|
|||
|
||||
any_instance_of(Project, versions: ['v1.0', 'v2.0'])
|
||||
|
||||
@issue = FactoryGirl.create(:issue, project_id: @project.id, assignee_id: @issue_user.id, user: @issue_user)
|
||||
@comment = FactoryGirl.create(:comment, commentable: @issue, user_id: @user.id, project: @project)
|
||||
@issue = FactoryGirl.create(:issue, project: @project, assignee: @issue_user, user: @issue_user)
|
||||
@comment = FactoryGirl.create(:comment, commentable: @issue, user: @user, project: @project)
|
||||
@email = UserMailer.new_comment_notification(@comment, @issue_user).deliver!
|
||||
end
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ describe Projects::ProjectsController do
|
|||
end
|
||||
|
||||
it "routes to #edit" do
|
||||
get("/import/glib2.0-mib/modify").should route_to("projects/projects#edit", owner_name: 'import', project_name: 'glib2.0-mib')
|
||||
get("/import/glib2.0-mib/modify").should route_to("projects/projects#edit", owner_with_name: 'import/glib2.0-mib')
|
||||
end
|
||||
|
||||
it "routes to #create" do
|
||||
|
@ -21,11 +21,11 @@ describe Projects::ProjectsController do
|
|||
end
|
||||
|
||||
it "routes to #update" do
|
||||
put("/import/glib2.0-mib").should route_to("projects/projects#update", owner_name: 'import', project_name: 'glib2.0-mib')
|
||||
put("/import/glib2.0-mib").should route_to("projects/projects#update", owner_with_name: 'import/glib2.0-mib')
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
delete("/import/glib2.0-mib").should route_to("projects/projects#destroy", owner_name: 'import', project_name: 'glib2.0-mib')
|
||||
delete("/import/glib2.0-mib").should route_to("projects/projects#destroy", owner_with_name: 'import/glib2.0-mib')
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -34,13 +34,14 @@ end
|
|||
describe Projects::Git::TreesController do
|
||||
describe "routing" do
|
||||
|
||||
it "routes to #show" do
|
||||
get("/import/glib2.0-mib").should route_to("projects/git/trees#show", owner_name: 'import', project_name: 'glib2.0-mib')
|
||||
get("/import/glib2.0-mib/tree/lib2safe-0.03").should route_to("projects/git/trees#show", owner_name: 'import', project_name: 'glib2.0-mib', treeish: 'lib2safe-0.03')
|
||||
get("/import/glib2.0-mib/tree/branch-with.dot/folder_with.dot/path-with.dot").should route_to("projects/git/trees#show", owner_name: 'import', project_name: 'glib2.0-mib', treeish: 'branch-with.dot', path: 'folder_with.dot/path-with.dot')
|
||||
# get("/import/glib2.0-mib/tree/ветка-с.точкой/папка_с.точкой/путь-с.точкой").should route_to("projects/git/trees#show", owner_name: 'import', project_name: 'glib2.0-mib', treeish: 'ветка-с.точкой', path: 'папка_с.точкой/путь-с.точкой')
|
||||
get("/import/glib2.0-mib/tree/branch-with/slash.dot/folder_with.dot/path-with.dot").should route_to("projects/git/trees#show", owner_name: 'import', project_name: 'glib2.0-mib', treeish: 'branch-with/slash.dot', path: 'folder_with.dot/path-with.dot')
|
||||
get("/import/glib2.0-mib/tree/tag13.52-5").should route_to("projects/git/trees#show", owner_name: 'import', project_name: 'glib2.0-mib', treeish: 'tag13.52-5')
|
||||
context "routes to #show" do
|
||||
it { get("/import/glib2.0-mib").should route_to("projects/git/trees#show", owner_with_name: 'import/glib2.0-mib') }
|
||||
it { get("/import/glib2.0-mib/tree/lib2safe-0.03").should route_to("projects/git/trees#show", owner_with_name: 'import/glib2.0-mib', treeish: 'lib2safe-0.03') }
|
||||
it { get("/import/glib2.0-mib/tree/branch-with.dot/folder_with.dot/path-with.dot").should route_to("projects/git/trees#show", owner_with_name: 'import/glib2.0-mib', treeish: 'branch-with.dot', path: 'folder_with.dot/path-with.dot') }
|
||||
# it { get("/import/glib2.0-mib/tree/ветка-с.точкой/папка_с.точкой/путь-с.точкой").should route_to("projects/git/trees#show", owner_with_name: 'import/glib2.0-mib', treeish: 'ветка-с.точкой', path: 'папка_с.точкой/путь-с.точкой') }
|
||||
# TODO: ???
|
||||
# it { get("/import/glib2.0-mib/tree/branch-with/slash.dot/folder_with.dot/path-with.dot").should route_to("projects/git/trees#show", owner_with_name: 'import/glib2.0-mib', treeish: 'branch-with/slash.dot', path: 'folder_with.dot/path-with.dot') }
|
||||
it { get("/import/glib2.0-mib/tree/tag13.52-5").should route_to("projects/git/trees#show", owner_with_name: 'import/glib2.0-mib', treeish: 'tag13.52-5') }
|
||||
end
|
||||
|
||||
# TODO write more specs also with slash in branch name!
|
||||
|
|
Loading…
Reference in New Issue