From 3ad56638b7c6b328beb50555f6960ef6c1692b25 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Sat, 5 Apr 2014 22:37:27 +0400 Subject: [PATCH] Added specs for MassBuild --- app/models/mass_build.rb | 14 +++++------- spec/models/mass_build_spec.rb | 40 +++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index 653ff9c60..998d2faea 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -104,12 +104,10 @@ class MassBuild < ActiveRecord::Base where( status: status, mass_build_id: self.id - ).joins(:project, :arch).find_in_batches(batch_size: 100) do |build_lists| - build_lists.each do |build_list| - report << "ID: #{build_list.id}; " - report << "PROJECT_NAME: #{build_list.project_name}; " - report << "ARCH: #{build_list.arch_name}\n" - end + ).joins(:project, :arch).find_each(batch_size: 100) do |build_list| + report << "ID: #{build_list.id}; " + report << "PROJECT_NAME: #{build_list.project_name}; " + report << "ARCH: #{build_list.arch_name}\n" end report end @@ -117,8 +115,8 @@ class MassBuild < ActiveRecord::Base def publish(user, *statuses) builds = build_lists.where(status: statuses) builds.update_all(publisher_id: user.id) - builds.order(:id).find_in_batches(batch_size: 50) do |bls| - bls.each{ |bl| bl.can_publish? && bl.has_new_packages? && bl.now_publish } + builds.find_each(batch_size: 50) do |bl| + bl.now_publish if bl.can_publish? && bl.has_new_packages? end end diff --git a/spec/models/mass_build_spec.rb b/spec/models/mass_build_spec.rb index 510fc4a5e..171c1a174 100644 --- a/spec/models/mass_build_spec.rb +++ b/spec/models/mass_build_spec.rb @@ -33,9 +33,47 @@ describe MassBuild do at ab ) - mass_build = FactoryGirl.create(:mass_build, projects_list: projects_list) + mass_build = FactoryGirl.build(:mass_build, projects_list: projects_list) + mass_build.should be_valid list = mass_build.projects_list.split(/[\r]*\n/) list.should have(2).items list.should 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) + expect(bl).to receive(:id) + expect(bl).to receive(:project_name) + expect(bl).to receive(:arch_name) + mb.send(:generate_list, 0) + end + + it '#publish' do + mb = FactoryGirl.build(:mass_build) + user = double(:user, id: 123) + + bl1 = double(:build_list, can_publish?: true, has_new_packages?: true) + bl2 = double(:build_list, can_publish?: true, has_new_packages?: false) + bl3 = double(:build_list, can_publish?: false, has_new_packages?: true) + bl4 = double(:build_list, can_publish?: false, has_new_packages?: false) + + finder = double(:finder) + allow(mb).to receive(:build_lists).and_return(finder) + allow(finder).to receive(:where).and_return(finder) + allow(finder).to receive(:find_each).and_yield(bl1).and_yield(bl2).and_yield(bl3).and_yield(bl4) + + expect(finder).to receive(:update_all).with(publisher_id: user.id) + expect(bl1).to receive(:now_publish) + expect(bl2).to_not receive(:now_publish) + expect(bl3).to_not receive(:now_publish) + expect(bl4).to_not receive(:now_publish) + + mb.send(:publish, user, []) + end + end