#472: Update specs

This commit is contained in:
Vokhmin Alexey V 2015-05-26 02:03:38 +03:00
parent ae572b96d8
commit c14a33d0be
11 changed files with 41 additions and 91 deletions

View File

@ -5,6 +5,4 @@ class ProjectStatistic < ActiveRecord::Base
validates :arch, :project, :average_build_time, :build_count, presence: true validates :arch, :project, :average_build_time, :build_count, presence: true
validates :project_id, uniqueness: { scope: :arch_id } validates :project_id, uniqueness: { scope: :arch_id }
# attr_accessible :average_build_time, :build_count
end end

View File

@ -36,7 +36,9 @@ class GroupPolicy < ApplicationPolicy
# #
# Returns Array # Returns Array
def permitted_attributes def permitted_attributes
%i(uname description delete_avatar default_branch) pa = %i(description delete_avatar default_branch)
pa << :uname if record.new_record?
pa
end end
class Scope < Scope class Scope < Scope

View File

@ -1,28 +1,14 @@
require 'spec_helper' require 'spec_helper'
describe Group do describe Group do
before(:each) do let(:group) { FactoryGirl.build(:group) }
stub_symlink_methods
@group = FactoryGirl.create(:group) before { stub_symlink_methods }
it { should_not allow_value("How do you do...\nmy_group").for(:uname) }
it 'is valid given valid attributes' do
expect(group).to be_valid
end end
context 'with mass assignment' do
before(:each) do
@user = FactoryGirl.create(:user)
@another_user = FactoryGirl.create(:user)
end
it 'should not be able to update uname' do
@group.should_not allow_mass_assignment_of uname: 'new_uname'
end
it 'should not be able to update owner' do
@group.should_not allow_mass_assignment_of owner_type: 'User', owner_id: @another_user.id
end
end
it 'uname validation' do
g = FactoryGirl.build(:group, uname: "How do you do...\nmy_group")
expect(g.valid?).to be_falsy
end
end end

View File

@ -1,51 +1,46 @@
require 'spec_helper' require 'spec_helper'
describe KeyPair do describe KeyPair do
before(:all) { FactoryGirl.create(:key_pair) }
it { should belong_to(:repository) } it { should belong_to(:repository) }
it { should belong_to(:user)} it { should belong_to(:user)}
it { should ensure_length_of(:public).is_at_most(10000) } it { should validate_length_of(:public).is_at_most(10000) }
it { should ensure_length_of(:secret).is_at_most(10000) } it { should validate_length_of(:secret).is_at_most(10000) }
it { should_not allow_mass_assignment_of(:user) }
it { should_not allow_mass_assignment_of(:key_id) }
describe 'check_keys validation' do describe 'check_keys validation' do
subject { FactoryGirl.build(:key_pair) } subject { FactoryGirl.build(:key_pair) }
it { subject.valid?.should be_truthy } it { expect(subject).to be_valid }
it 'checks error when wrong public key' do it 'checks error when wrong public key' do
subject.public = 'test' subject.public = 'test'
subject.valid? expect(subject).to_not be_valid
subject.errors[:public].should =~ [I18n.t('activerecord.errors.key_pair.wrong_key')] expect(subject.errors[:public]).to contain_exactly I18n.t('activerecord.errors.key_pair.wrong_key')
end end
it 'checks error when wrong secret key' do it 'checks error when wrong secret key' do
subject.secret = 'test' subject.secret = 'test'
subject.valid? expect(subject).to_not be_valid
subject.errors[:secret].should =~ [I18n.t('activerecord.errors.key_pair.wrong_key')] expect(subject.errors[:secret]).to contain_exactly I18n.t('activerecord.errors.key_pair.wrong_key')
end end
it 'checks error when public key contains secret key' do it 'checks error when public key contains secret key' do
subject.public = subject.secret subject.public = subject.secret
subject.valid? expect(subject).to_not be_valid
subject.errors[:public].should =~ [I18n.t('activerecord.errors.key_pair.wrong_public_key')] expect(subject.errors[:public]).to contain_exactly I18n.t('activerecord.errors.key_pair.wrong_public_key')
end end
it 'checks error when secret key contains public key' do it 'checks error when secret key contains public key' do
subject.secret = subject.public subject.secret = subject.public
subject.valid? expect(subject).to_not be_valid
subject.errors[:secret].should =~ [I18n.t('activerecord.errors.key_pair.wrong_secret_key')] expect(subject.errors[:secret]).to contain_exactly I18n.t('activerecord.errors.key_pair.wrong_secret_key')
end end
it 'checks error when different fingerprint of keys' do it 'checks error when different fingerprint of keys' do
file = File.open(Rails.root.join('spec', 'support', 'fixtures', 'pubring.pass.gpg'), "rb") file = File.open(Rails.root.join('spec', 'support', 'fixtures', 'pubring.pass.gpg'), "rb")
subject.public = file.read subject.public = file.read
file.close file.close
subject.valid? expect(subject).to_not be_valid
subject.errors[:secret].should =~ [I18n.t('activerecord.errors.key_pair.wrong_keys')] expect(subject.errors[:secret]).to contain_exactly I18n.t('activerecord.errors.key_pair.wrong_keys')
end end
it 'checks error when secret key contains passphrase' do it 'checks error when secret key contains passphrase' do
@ -56,17 +51,14 @@ describe KeyPair do
subject.secret = file.read subject.secret = file.read
file.close file.close
subject.valid? expect(subject).to_not be_valid
subject.errors[:secret].should =~ [I18n.t('activerecord.errors.key_pair.key_has_passphrase')] expect(subject.errors[:secret]).to contain_exactly I18n.t('activerecord.errors.key_pair.key_has_passphrase')
end end
end end
after(:all) do after(:all) do
Platform.delete_all
User.delete_all
Product.delete_all
FileUtils.rm_rf(APP_CONFIG['root_path']) FileUtils.rm_rf(APP_CONFIG['root_path'])
end end
end end

View File

@ -4,9 +4,10 @@ describe MassBuild do
before { stub_symlink_methods } before { stub_symlink_methods }
context 'ensures that validations and associations exist' do context 'ensures that validations and associations exist' do
let(:mass_build) { FactoryGirl.build(:mass_build) }
it 'is valid given valid attributes' do it 'is valid given valid attributes' do
FactoryGirl.create(:mass_build).should be_truthy expect(mass_build).to be_valid
end end
it { should belong_to(:build_for_platform) } it { should belong_to(:build_for_platform) }
@ -21,12 +22,10 @@ describe MassBuild do
it { should validate_presence_of(:name)} it { should validate_presence_of(:name)}
it { should validate_presence_of(:projects_list)} it { should validate_presence_of(:projects_list)}
it { should ensure_length_of(:projects_list).is_at_most(500_000) } it { should validate_length_of(:projects_list).is_at_most(500_000) }
it { should ensure_length_of(:description).is_at_most(255) } it { should validate_length_of(:description).is_at_most(255) }
it { should_not allow_mass_assignment_of(:name) }
it { should_not allow_mass_assignment_of(:arch_names) }
end end
it 'ensures that projects_list contains unique projects' do it 'ensures that projects_list contains unique projects' do
@ -35,19 +34,17 @@ describe MassBuild do
ab ab
) )
mass_build = FactoryGirl.build(:mass_build, projects_list: projects_list) mass_build = FactoryGirl.build(:mass_build, projects_list: projects_list)
mass_build.should be_valid expect(mass_build).to be_valid
list = mass_build.projects_list.split(/[\r]*\n/) list = mass_build.projects_list.split(/[\r]*\n/)
expect(list.count).to eq 2 expect(list.count).to eq 2
list.should include('at', 'ab') expect(list).to include('at', 'ab')
end end
it '#generate_list' do it '#generate_list' do
mb = FactoryGirl.build(:mass_build) mb = FactoryGirl.build(:mass_build)
bl = double(:build_list) bl = double(:build_list)
# allow(service).to receive(:already_pulled?).with(post.identifier).and_return(true) allow(BuildList).to receive_message_chain(:select, :where, :joins, :find_each).and_yield(bl)
# allow(BuildList).to receive(:find_each).and_yield(bl)
BuildList.stub_chain(:select, :where, :joins, :find_each).and_yield(bl)
expect(bl).to receive(:id) expect(bl).to receive(:id)
expect(bl).to receive(:project_name) expect(bl).to receive(:project_name)
expect(bl).to receive(:arch_name) expect(bl).to receive(:arch_name)

View File

@ -39,39 +39,34 @@ describe Platform do
it { should have_readonly_attribute(:parent_platform_id) } it { should have_readonly_attribute(:parent_platform_id) }
it { should have_readonly_attribute(:platform_type) } it { should have_readonly_attribute(:platform_type) }
it { should_not allow_mass_assignment_of(:repositories) } it { should_not allow_value("How do you do...\nmy_platform").for(:name) }
it { should_not allow_mass_assignment_of(:products) }
it { should_not allow_mass_assignment_of(:members) }
it { should_not allow_mass_assignment_of(:parent) }
it {should_not allow_value("How do you do...\nmy_platform").for(:name)}
end end
it 'ensures that folder of platform will be removed after destroy' do it 'ensures that folder of platform will be removed after destroy' do
platform = FactoryGirl.create :platform platform = FactoryGirl.create :platform
FileUtils.mkdir_p platform.path FileUtils.mkdir_p platform.path
platform.destroy platform.destroy
Dir.exists?(platform.path).should be_falsy expect(Dir.exists?(platform.path)).to be_falsy
end end
it 'ensures that owner of personal platform can not be changed' do it 'ensures that owner of personal platform can not be changed' do
platform = FactoryGirl.create :personal_platform platform = FactoryGirl.create :personal_platform
owner = platform.owner owner = platform.owner
platform.owner = FactoryGirl.create :user platform.owner = FactoryGirl.create :user
platform.save.should be_falsy expect(platform.save).to be_falsy
end end
it 'ensures that owner of platform of group can not be changed' do it 'ensures that owner of platform of group can not be changed' do
group = FactoryGirl.create :group group = FactoryGirl.create :group
platform = FactoryGirl.create :personal_platform, owner: group platform = FactoryGirl.create :personal_platform, owner: group
platform.owner = FactoryGirl.create :user platform.owner = FactoryGirl.create :user
platform.save.should be_falsy expect(platform.save).to be_falsy
end end
it 'ensures that owner of main platform can be changed' do it 'ensures that owner of main platform can be changed' do
platform = FactoryGirl.create :platform platform = FactoryGirl.create :platform
platform.owner = FactoryGirl.create :user platform.owner = FactoryGirl.create :user
platform.save.should be_truthy expect(platform.save).to be_truthy
end end
end end

View File

@ -32,10 +32,6 @@ describe ProductBuildList do
it { is_expected.to_not allow_value(555).for(:status) } it { is_expected.to_not allow_value(555).for(:status) }
it { is_expected.to have_readonly_attribute(:product_id) } it { is_expected.to have_readonly_attribute(:product_id) }
#it { should_not allow_mass_assignment_of(:product_id) }
it { is_expected.to allow_mass_assignment_of(:status) }
it { is_expected.to allow_mass_assignment_of(:base_url) }
end end
describe '#abf_worker_srcpath' do describe '#abf_worker_srcpath' do

View File

@ -22,14 +22,10 @@ describe Product do
it { should validate_uniqueness_of(:name).scoped_to(:platform_id) } it { should validate_uniqueness_of(:name).scoped_to(:platform_id) }
end end
it { should ensure_length_of(:main_script).is_at_most(255) } it { should validate_length_of(:main_script).is_at_most(255) }
it { should ensure_length_of(:params).is_at_most(255) } it { should validate_length_of(:params).is_at_most(255) }
it { should have_readonly_attribute(:platform_id) } it { should have_readonly_attribute(:platform_id) }
it { should_not allow_mass_assignment_of(:platform) }
#it { should_not allow_mass_assignment_of(:platform_id) }
it { should_not allow_mass_assignment_of(:product_build_lists) }
end end

View File

@ -11,9 +11,6 @@ describe ProjectStatistic do
it { should validate_presence_of(:average_build_time) } it { should validate_presence_of(:average_build_time) }
it { should validate_presence_of(:build_count) } it { should validate_presence_of(:build_count) }
it { should_not allow_mass_assignment_of(:project_id) }
it { should_not allow_mass_assignment_of(:arch_id) }
it 'uniqueness of project_id and arch_id' do it 'uniqueness of project_id and arch_id' do
FactoryGirl.create(:project_statistic) FactoryGirl.create(:project_statistic)
should validate_uniqueness_of(:project_id).scoped_to(:arch_id) should validate_uniqueness_of(:project_id).scoped_to(:arch_id)

View File

@ -30,10 +30,6 @@ describe Repository do
it { should have_readonly_attribute(:name) } it { should have_readonly_attribute(:name) }
it { should have_readonly_attribute(:platform_id) } it { should have_readonly_attribute(:platform_id) }
it { should_not allow_mass_assignment_of(:platform) }
it { should_not allow_mass_assignment_of(:platform_id) }
end end
context '#sync_lock_file_exists?, #add_sync_lock_file, #remove_sync_lock_file, #add_repo_lock_file, #remove_repo_lock_file' do context '#sync_lock_file_exists?, #add_sync_lock_file, #remove_sync_lock_file, #add_repo_lock_file, #remove_repo_lock_file' do

View File

@ -14,11 +14,6 @@ describe Token do
it { should validate_presence_of(:subject_id) } it { should validate_presence_of(:subject_id) }
it { should validate_presence_of(:subject_type) } it { should validate_presence_of(:subject_type) }
it { should_not allow_mass_assignment_of(:authentication_token) }
it { should_not allow_mass_assignment_of(:creator_id) }
it { should_not allow_mass_assignment_of(:subject_id) }
it { should_not allow_mass_assignment_of(:subject_type) }
it 'ensures that authentication_token unique' do it 'ensures that authentication_token unique' do
token = FactoryGirl.create(:platform_token) token = FactoryGirl.create(:platform_token)
token.authentication_token = platform_token.authentication_token token.authentication_token = platform_token.authentication_token