diff --git a/app/models/project_statistic.rb b/app/models/project_statistic.rb index 49ab6e890..c529f4635 100644 --- a/app/models/project_statistic.rb +++ b/app/models/project_statistic.rb @@ -5,6 +5,4 @@ class ProjectStatistic < ActiveRecord::Base validates :arch, :project, :average_build_time, :build_count, presence: true validates :project_id, uniqueness: { scope: :arch_id } - - # attr_accessible :average_build_time, :build_count end diff --git a/app/policies/group_policy.rb b/app/policies/group_policy.rb index 966b4f9f2..434c9bdb0 100644 --- a/app/policies/group_policy.rb +++ b/app/policies/group_policy.rb @@ -36,7 +36,9 @@ class GroupPolicy < ApplicationPolicy # # Returns Array 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 class Scope < Scope diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 19e2ae953..1ab2890d9 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -1,28 +1,14 @@ require 'spec_helper' describe Group do - before(:each) do - stub_symlink_methods - @group = FactoryGirl.create(:group) + let(:group) { FactoryGirl.build(: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 - 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 diff --git a/spec/models/key_pair_spec.rb b/spec/models/key_pair_spec.rb index a4ff7eacc..319d59697 100644 --- a/spec/models/key_pair_spec.rb +++ b/spec/models/key_pair_spec.rb @@ -1,51 +1,46 @@ require 'spec_helper' describe KeyPair do - before(:all) { FactoryGirl.create(:key_pair) } - it { should belong_to(:repository) } it { should belong_to(:user)} - it { should ensure_length_of(:public).is_at_most(10000) } - it { should ensure_length_of(:secret).is_at_most(10000) } - - - it { should_not allow_mass_assignment_of(:user) } - it { should_not allow_mass_assignment_of(:key_id) } + it { should validate_length_of(:public).is_at_most(10000) } + it { should validate_length_of(:secret).is_at_most(10000) } describe 'check_keys validation' do 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 subject.public = 'test' - subject.valid? - subject.errors[:public].should =~ [I18n.t('activerecord.errors.key_pair.wrong_key')] + expect(subject).to_not be_valid + expect(subject.errors[:public]).to contain_exactly I18n.t('activerecord.errors.key_pair.wrong_key') end it 'checks error when wrong secret key' do subject.secret = 'test' - subject.valid? - subject.errors[:secret].should =~ [I18n.t('activerecord.errors.key_pair.wrong_key')] + expect(subject).to_not be_valid + expect(subject.errors[:secret]).to contain_exactly I18n.t('activerecord.errors.key_pair.wrong_key') end it 'checks error when public key contains secret key' do subject.public = subject.secret - subject.valid? - subject.errors[:public].should =~ [I18n.t('activerecord.errors.key_pair.wrong_public_key')] + expect(subject).to_not be_valid + expect(subject.errors[:public]).to contain_exactly I18n.t('activerecord.errors.key_pair.wrong_public_key') end it 'checks error when secret key contains public key' do subject.secret = subject.public - subject.valid? - subject.errors[:secret].should =~ [I18n.t('activerecord.errors.key_pair.wrong_secret_key')] + expect(subject).to_not be_valid + expect(subject.errors[:secret]).to contain_exactly I18n.t('activerecord.errors.key_pair.wrong_secret_key') end it 'checks error when different fingerprint of keys' do file = File.open(Rails.root.join('spec', 'support', 'fixtures', 'pubring.pass.gpg'), "rb") subject.public = file.read file.close - subject.valid? - subject.errors[:secret].should =~ [I18n.t('activerecord.errors.key_pair.wrong_keys')] + expect(subject).to_not be_valid + expect(subject.errors[:secret]).to contain_exactly I18n.t('activerecord.errors.key_pair.wrong_keys') end it 'checks error when secret key contains passphrase' do @@ -56,17 +51,14 @@ describe KeyPair do subject.secret = file.read file.close - subject.valid? - subject.errors[:secret].should =~ [I18n.t('activerecord.errors.key_pair.key_has_passphrase')] + expect(subject).to_not be_valid + expect(subject.errors[:secret]).to contain_exactly I18n.t('activerecord.errors.key_pair.key_has_passphrase') end end after(:all) do - Platform.delete_all - User.delete_all - Product.delete_all FileUtils.rm_rf(APP_CONFIG['root_path']) end end diff --git a/spec/models/mass_build_spec.rb b/spec/models/mass_build_spec.rb index 6c3433c6d..482ef7943 100644 --- a/spec/models/mass_build_spec.rb +++ b/spec/models/mass_build_spec.rb @@ -4,9 +4,10 @@ describe MassBuild do before { stub_symlink_methods } context 'ensures that validations and associations exist' do + let(:mass_build) { FactoryGirl.build(:mass_build) } it 'is valid given valid attributes' do - FactoryGirl.create(:mass_build).should be_truthy + expect(mass_build).to be_valid end 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(: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 it 'ensures that projects_list contains unique projects' do @@ -35,19 +34,17 @@ describe MassBuild do ab ) 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/) expect(list.count).to eq 2 - list.should include('at', 'ab') + expect(list).to include('at', 'ab') end it '#generate_list' do mb = FactoryGirl.build(:mass_build) bl = double(:build_list) - # allow(service).to receive(:already_pulled?).with(post.identifier).and_return(true) - # allow(BuildList).to receive(:find_each).and_yield(bl) - BuildList.stub_chain(:select, :where, :joins, :find_each).and_yield(bl) + allow(BuildList).to receive_message_chain(:select, :where, :joins, :find_each).and_yield(bl) expect(bl).to receive(:id) expect(bl).to receive(:project_name) expect(bl).to receive(:arch_name) diff --git a/spec/models/platform_spec.rb b/spec/models/platform_spec.rb index a9f552687..fa66e2a30 100644 --- a/spec/models/platform_spec.rb +++ b/spec/models/platform_spec.rb @@ -39,39 +39,34 @@ describe Platform do it { should have_readonly_attribute(:parent_platform_id) } it { should have_readonly_attribute(:platform_type) } - it { should_not allow_mass_assignment_of(:repositories) } - 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)} + it { should_not allow_value("How do you do...\nmy_platform").for(:name) } end it 'ensures that folder of platform will be removed after destroy' do platform = FactoryGirl.create :platform FileUtils.mkdir_p platform.path platform.destroy - Dir.exists?(platform.path).should be_falsy + expect(Dir.exists?(platform.path)).to be_falsy end it 'ensures that owner of personal platform can not be changed' do platform = FactoryGirl.create :personal_platform owner = platform.owner platform.owner = FactoryGirl.create :user - platform.save.should be_falsy + expect(platform.save).to be_falsy end it 'ensures that owner of platform of group can not be changed' do group = FactoryGirl.create :group platform = FactoryGirl.create :personal_platform, owner: group platform.owner = FactoryGirl.create :user - platform.save.should be_falsy + expect(platform.save).to be_falsy end it 'ensures that owner of main platform can be changed' do platform = FactoryGirl.create :platform platform.owner = FactoryGirl.create :user - platform.save.should be_truthy + expect(platform.save).to be_truthy end end diff --git a/spec/models/product_build_list_spec.rb b/spec/models/product_build_list_spec.rb index 63ad93dfc..b53c0f100 100644 --- a/spec/models/product_build_list_spec.rb +++ b/spec/models/product_build_list_spec.rb @@ -32,10 +32,6 @@ describe ProductBuildList do it { is_expected.to_not allow_value(555).for(:status) } 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 describe '#abf_worker_srcpath' do diff --git a/spec/models/product_spec.rb b/spec/models/product_spec.rb index 14d998bd5..a59d37889 100644 --- a/spec/models/product_spec.rb +++ b/spec/models/product_spec.rb @@ -22,14 +22,10 @@ describe Product do it { should validate_uniqueness_of(:name).scoped_to(:platform_id) } end - it { should ensure_length_of(:main_script).is_at_most(255) } - it { should ensure_length_of(:params).is_at_most(255) } + it { should validate_length_of(:main_script).is_at_most(255) } + it { should validate_length_of(:params).is_at_most(255) } 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 diff --git a/spec/models/project_statistic_spec.rb b/spec/models/project_statistic_spec.rb index fca55d974..a7fd9dd60 100644 --- a/spec/models/project_statistic_spec.rb +++ b/spec/models/project_statistic_spec.rb @@ -11,9 +11,6 @@ describe ProjectStatistic do it { should validate_presence_of(:average_build_time) } 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 FactoryGirl.create(:project_statistic) should validate_uniqueness_of(:project_id).scoped_to(:arch_id) diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 22e5bbdb0..f25a55dd9 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -30,10 +30,6 @@ describe Repository do it { should have_readonly_attribute(:name) } 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 context '#sync_lock_file_exists?, #add_sync_lock_file, #remove_sync_lock_file, #add_repo_lock_file, #remove_repo_lock_file' do diff --git a/spec/models/token_spec.rb b/spec/models/token_spec.rb index 3c57364b0..6f1ddf31f 100644 --- a/spec/models/token_spec.rb +++ b/spec/models/token_spec.rb @@ -14,11 +14,6 @@ describe Token do it { should validate_presence_of(:subject_id) } 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 token = FactoryGirl.create(:platform_token) token.authentication_token = platform_token.authentication_token