From e736586129a110f4dcada8afe70b420c17286a4b Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 7 Apr 2015 23:44:39 +0300 Subject: [PATCH] #465: Update specs --- app/models/build_list.rb | 10 +++++----- app/models/concerns/feed/issue.rb | 2 +- spec/jobs/dependent_packages_job_spec.rb | 19 ++++++++----------- spec/models/issue_spec.rb | 5 +++-- spec/models/product_build_list_spec.rb | 10 ---------- 5 files changed, 17 insertions(+), 29 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 0b914be79..ba8e85ac3 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -724,17 +724,17 @@ class BuildList < ActiveRecord::Base save end - def current_ability - @current_ability ||= Ability.new(user) - end + # def current_ability + # @current_ability ||= Ability.new(user) + # end def prepare_extra_repositories if save_to_platform && save_to_platform.main? self.extra_repositories = nil else - self.extra_repositories = Repository.joins(:platform). + self.extra_repositories = PlatformPolicy::Scope.new(user, Repository.joins(:platform)).show. where(id: extra_repositories, platforms: {platform_type: 'personal'}). - accessible_by(current_ability, :read).pluck('repositories.id') + pluck('repositories.id') end end diff --git a/app/models/concerns/feed/issue.rb b/app/models/concerns/feed/issue.rb index 5801ba22f..8a814b2e8 100644 --- a/app/models/concerns/feed/issue.rb +++ b/app/models/concerns/feed/issue.rb @@ -59,7 +59,7 @@ module Feed::Issue ) end # dont remove outdated issues link - ::Comment.create_link_on_issues_from_item(self) if previous_changes['title'].present? || previous_changes['body'].present? + ::Comment.create_link_on_issues_from_item(self) if title_changed? || body_changed? end def send_hooks(action = :create) diff --git a/spec/jobs/dependent_packages_job_spec.rb b/spec/jobs/dependent_packages_job_spec.rb index eed039cdc..2966539da 100644 --- a/spec/jobs/dependent_packages_job_spec.rb +++ b/spec/jobs/dependent_packages_job_spec.rb @@ -4,7 +4,6 @@ describe BuildLists::DependentPackagesJob do let(:build_list) { FactoryGirl.build(:build_list, id: 123) } let(:user) { build_list.user } let(:project) { build_list.project } - let(:ability) { double(:ability) } let(:project_ids) { [build_list.project_id] } let(:arch_ids) { [build_list.arch_id] } let(:options) { { @@ -18,14 +17,12 @@ describe BuildLists::DependentPackagesJob do before do stub_symlink_methods allow(BuildList).to receive(:find).with(123).and_return(build_list) - # BuildList::Package.stub_chain(:joins, :where, :reorder, :uniq, :pluck).and_return([project.id]) - Project.stub_chain(:where, :to_a).and_return([project]) - Arch.stub_chain(:where, :to_a).and_return([build_list.arch]) + allow(Project).to receive_message_chain(:where, :to_a).and_return([project]) + allow(Arch).to receive_message_chain(:where, :to_a).and_return([build_list.arch]) - allow(Ability).to receive(:new).and_return(ability) - allow(ability).to receive(:can?).with(:show, build_list).and_return(true) - allow(ability).to receive(:can?).with(:write, project).and_return(true) - allow(ability).to receive(:can?).with(:create, anything).and_return(true) + allow_any_instance_of(BuildListPolicy).to receive(:show?).and_return(true) + allow_any_instance_of(ProjectPolicy).to receive(:write?).and_return(true) + allow_any_instance_of(BuildListPolicy).to receive(:create?).and_return(true) end subject { BuildLists::DependentPackagesJob } @@ -43,21 +40,21 @@ describe BuildLists::DependentPackagesJob do end it 'ensures that do nothing if user has no access for show of build_list' do - allow(ability).to receive(:can?).with(:show, build_list).and_return(false) + allow_any_instance_of(BuildListPolicy).to receive(:show?).and_return(false) expect do subject.perform build_list.id, user.id, project_ids, arch_ids, options end.to change(BuildList, :count).by(0) end it 'ensures that do nothing if user has no access for write of project' do - allow(ability).to receive(:can?).with(:write, project).and_return(false) + allow_any_instance_of(ProjectPolicy).to receive(:write?).and_return(false) expect do subject.perform build_list.id, user.id, project_ids, arch_ids, options end.to change(BuildList, :count).by(0) end it 'ensures that do nothing if user has no access for create of build_list' do - allow(ability).to receive(:can?).with(:create, anything).and_return(false) + allow_any_instance_of(BuildListPolicy).to receive(:create?).and_return(false) expect do subject.perform build_list.id, user.id, project_ids, arch_ids, options end.to change(BuildList, :count).by(0) diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 40ea8396c..71135d163 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -53,8 +53,8 @@ describe Issue do it 'should create automatic comment after updating another issue body' do create_issue(@user) another_issue = FactoryGirl.create(:issue, project: @project) + another_issue = Issue.find another_issue.id another_issue.update_attribute(:title, "[##{@issue.serial_id}]") - another_issue.send(:send_assign_notifications) Comment.where(automatic: true, commentable_type: 'Issue', created_from_issue_id: another_issue.id).count.should == 1 @@ -63,8 +63,9 @@ describe Issue do it 'should send email message to new assignee' do create_issue(@user) ActionMailer::Base.deliveries = [] + @issue = Issue.find @issue.id @issue.update_attribute :assignee_id, @user.id - @issue.send(:send_assign_notifications, :update) + ActionMailer::Base.deliveries.count.should == 1 end end diff --git a/spec/models/product_build_list_spec.rb b/spec/models/product_build_list_spec.rb index c1fd50fd5..6014d66e0 100644 --- a/spec/models/product_build_list_spec.rb +++ b/spec/models/product_build_list_spec.rb @@ -35,14 +35,4 @@ describe ProductBuildList do it { is_expected.to allow_mass_assignment_of(:status) } it { is_expected.to allow_mass_assignment_of(:base_url) } end - - # see app/ability.rb - # can :read, ProductBuildList#, product: {platform: {visibility: 'open'}} # double nested hash don't work - it 'should generate correct sql to get product build lists' do - FactoryGirl.create(:arch, name: 'x86_64') - FactoryGirl.create(:product_build_list) - user = FactoryGirl.create(:user) - ability = Ability.new user - expect(ProductBuildList.accessible_by(ability).count).to eq 1 - end end