This commit is contained in:
amartynov 2015-12-03 12:22:59 +03:00
commit 41b4fa8373
6 changed files with 31 additions and 16 deletions

View File

@ -13,7 +13,6 @@ gem "chef", ">=12"
gem "mongo" gem "mongo"
gem "bson_ext" gem "bson_ext"
gem "multi_json", "1.7.8" gem "multi_json", "1.7.8"
# gem "rufus-scheduler", "2.0.24"
gem "sidekiq", "3.2.6" gem "sidekiq", "3.2.6"
gem 'wisper' gem 'wisper'
gem 'rake', '10.2.0' gem 'rake', '10.2.0'
@ -31,6 +30,7 @@ group :test do
gem 'rspec', '~>3.3' gem 'rspec', '~>3.3'
gem 'factory_girl', '~>4.5' gem 'factory_girl', '~>4.5'
gem 'activesupport' gem 'activesupport'
gem 'rspec_junit_formatter'
end end
group :devepoment do group :devepoment do

View File

@ -350,6 +350,7 @@ DEPENDENCIES
rack-accept-media-types rack-accept-media-types
rake (= 10.2.0) rake (= 10.2.0)
rspec (~> 3.3) rspec (~> 3.3)
rspec_junit_formatter
sidekiq (= 3.2.6) sidekiq (= 3.2.6)
sinatra (= 1.4.5) sinatra (= 1.4.5)
sinatra-contrib sinatra-contrib
@ -357,6 +358,3 @@ DEPENDENCIES
test-unit test-unit
thin (~> 1.5.1) thin (~> 1.5.1)
wisper wisper
BUNDLED WITH
1.10.5

View File

@ -175,7 +175,7 @@ module Devops
# Deletes project servers # Deletes project servers
# #
# * *Request* # * *Request*
# - method : PATCH # - method : DELETE
# - headers : # - headers :
# - Accept: application/json # - Accept: application/json
# - Content-Type: application/json # - Content-Type: application/json

View File

@ -1,6 +1,10 @@
require_relative "devops_error" require_relative "devops_error"
class InvalidRecord < ::Devops::Exception::DevopsError class InvalidRecord < ::Devops::Exception::DevopsError
# message could be a String or a hash like
# {
# error_data: [{:key=>:provider, :message=>"Value can not be undefined"}]
# }
def initialize msg def initialize msg
if msg.is_a?(String) if msg.is_a?(String)
super(msg) super(msg)
@ -9,6 +13,17 @@ class InvalidRecord < ::Devops::Exception::DevopsError
end end
end end
def message
if @object
messages = @object[:error_data].map do |error_item|
"#{error_item[:key]}: #{error_item[:message]}"
end
"Following errors occured: \n#{messages.join('\n')}"
else
super
end
end
def http_status def http_status
400 400
end end

View File

@ -16,7 +16,7 @@ RSpec.describe Devops::Model::Image, type: :model do
describe 'validation' do describe 'validation' do
include_examples 'field type validation', :id, :not_nil, :non_empty_string, :field_validator include_examples 'field type validation', :id, :not_nil, :non_empty_string, :field_validator
include_examples 'field type validation', :remote_user, :not_nil, :non_empty_string, :only_word_symbols, :field_validator include_examples 'field type validation', :remote_user, :not_nil, :non_empty_string, :field_validator
include_examples 'field type validation', :name, :not_nil, :non_empty_string, :field_validator include_examples 'field type validation', :name, :not_nil, :non_empty_string, :field_validator
include_examples 'field type validation', :bootstrap_template, :maybe_nil, :non_empty_string, :only_word_symbols, :field_validator include_examples 'field type validation', :bootstrap_template, :maybe_nil, :non_empty_string, :only_word_symbols, :field_validator
@ -36,6 +36,12 @@ RSpec.describe Devops::Model::Image, type: :model do
it 'bootstrap_template should be included in available bootstrap templates' do it 'bootstrap_template should be included in available bootstrap templates' do
expect(build(:image, bootstrap_template: 'wrong')).not_to be_valid expect(build(:image, bootstrap_template: 'wrong')).not_to be_valid
end end
it 'remote_user should contain only a-zA-Z0-9_-.' do
expect(build(:image, remote_user: 'aA0-.')).to be_valid
expect(build(:image, remote_user: 'name/')).not_to be_valid
expect(build(:image, remote_user: 'name!')).not_to be_valid
end
end end
it '#to_hash_without_id returns provider, name, remote_user and bootstrap_template' do it '#to_hash_without_id returns provider, name, remote_user and bootstrap_template' do

View File

@ -4,20 +4,16 @@ RSpec.describe Devops::Model::Report, type: :model do
let(:report) { build(:report) } let(:report) { build(:report) }
describe '#initialize' do describe '#initialize' do
let(:given_moment) { Time.new(2007,11,1,15,25,0, "+01:00") }
it 'converts created_at to localtime' do it 'converts created_at to localtime' do
now = Time.now.utc converted = build(:report, created_at: given_moment).created_at
expect(now.zone).to eq 'UTC' expect(converted).to eq given_moment.localtime
expect(
build(:report, created_at: now).created_at.zone
).not_to eq 'UTC'
end end
it 'converts updated_at to localtime' do it 'converts updated_at to localtime' do
now = Time.now.utc converted = build(:report, updated_at: given_moment).updated_at
expect(now.zone).to eq 'UTC' expect(converted).to eq given_moment.localtime
expect(
build(:report, updated_at: now).updated_at.zone
).not_to eq 'UTC'
end end
end end