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 "bson_ext"
gem "multi_json", "1.7.8"
# gem "rufus-scheduler", "2.0.24"
gem "sidekiq", "3.2.6"
gem 'wisper'
gem 'rake', '10.2.0'
@ -31,6 +30,7 @@ group :test do
gem 'rspec', '~>3.3'
gem 'factory_girl', '~>4.5'
gem 'activesupport'
gem 'rspec_junit_formatter'
end
group :devepoment do

View File

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

View File

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

View File

@ -1,6 +1,10 @@
require_relative "devops_error"
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
if msg.is_a?(String)
super(msg)
@ -9,6 +13,17 @@ class InvalidRecord < ::Devops::Exception::DevopsError
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
400
end

View File

@ -16,7 +16,7 @@ RSpec.describe Devops::Model::Image, type: :model do
describe 'validation' do
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', :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
expect(build(:image, bootstrap_template: 'wrong')).not_to be_valid
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
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) }
describe '#initialize' do
let(:given_moment) { Time.new(2007,11,1,15,25,0, "+01:00") }
it 'converts created_at to localtime' do
now = Time.now.utc
expect(now.zone).to eq 'UTC'
expect(
build(:report, created_at: now).created_at.zone
).not_to eq 'UTC'
converted = build(:report, created_at: given_moment).created_at
expect(converted).to eq given_moment.localtime
end
it 'converts updated_at to localtime' do
now = Time.now.utc
expect(now.zone).to eq 'UTC'
expect(
build(:report, updated_at: now).updated_at.zone
).not_to eq 'UTC'
converted = build(:report, updated_at: given_moment).updated_at
expect(converted).to eq given_moment.localtime
end
end