From 99d7a2baa0f65f44c34b398e540d7b92c9ddff15 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 10 Sep 2013 20:09:48 +0400 Subject: [PATCH] #298: added extra specs for #has_new_packages? --- app/models/build_list.rb | 4 ++- spec/models/build_list_spec.rb | 55 +++++++++++++++++++++++++++------- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 0d9f607fa..b07a1918b 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -293,7 +293,9 @@ class BuildList < ActiveRecord::Base return true if nsp.release.to_i > sp.release.to_i else nsp_version.each_with_index do |nv, index| - return true if nv > sp_version[index].to_i + ov = sp_version[index].to_i + return true if nv > ov + return false if nv < ov end end end diff --git a/spec/models/build_list_spec.rb b/spec/models/build_list_spec.rb index bc9736b53..9401fc9c7 100644 --- a/spec/models/build_list_spec.rb +++ b/spec/models/build_list_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' describe BuildList do + before { stub_symlink_methods } context 'validates that repository contains project' do it 'when repository contains project' do @@ -16,7 +17,6 @@ describe BuildList do end context "#notify_users" do - before { stub_symlink_methods } let!(:user) { FactoryGirl.create(:user) } let!(:build_list) { FactoryGirl.create(:build_list, :user => user, @@ -155,13 +155,14 @@ describe BuildList do end # notify_users - context '#can_auto_publish?' do - before { stub_symlink_methods } + context '#has_new_packages?' do let!(:build_list) { FactoryGirl.create( :build_list, :status => BuildList::SUCCESS, :auto_publish => true) } let!(:build_list_package) { FactoryGirl.create( :build_list_package, :build_list => build_list, + :version => '3.1.12', + :release => 6, :platform => build_list.save_to_platform, :project => build_list.project) } let!(:published_build_list) { FactoryGirl.create( :build_list, @@ -173,25 +174,57 @@ describe BuildList do :build_list => published_build_list, :platform => published_build_list.save_to_platform, :actual => true, + :version => '3.1.12', + :release => 6, :project => published_build_list.project) } it 'ensures that return false if version of packages are same' do - build_list.can_auto_publish?.should be_false + build_list.has_new_packages?.should be_false end - it 'ensures that return false if version of published package >' do - published_build_list_package.update_attributes(:version => '3.1.13') - build_list.can_auto_publish?.should be_false + context 'ensures that return false if version of published package >' do + + it 'published: 3.1.13, new: 3.1.12' do + published_build_list_package.update_attributes(:version => '3.1.13') + build_list.has_new_packages?.should be_false + end + + it 'published: 3.1.12, new: 3.0.999' do + build_list_package.update_attributes(:version => '3.0.999') + build_list.has_new_packages?.should be_false + end + + it 'published: 3.0.rc1, new: 3.0.0' do + published_build_list_package.update_attributes(:version => '3.0.rc1') + build_list_package.update_attributes(:version => '3.0.0') + build_list.has_new_packages?.should be_false + end + end - it 'ensures that return true if version of published package <' do - published_build_list_package.update_attributes(:version => '3.1.11') - build_list.can_auto_publish?.should be_true + context 'ensures that return true if version of published package <' do + + it 'published: 3.1.11, new: 3.1.12' do + published_build_list_package.update_attributes(:version => '3.1.11') + build_list.has_new_packages?.should be_true + end + + it 'published: 3.0.999, new: 3.1.12' do + published_build_list_package.update_attributes(:version => '3.0.999') + build_list.has_new_packages?.should be_true + end + + it 'published: 3.0.0, new: 3.0.rc1' do + published_build_list_package.update_attributes(:version => '3.0.0') + build_list_package.update_attributes(:version => '3.0.rc1') + build_list.has_new_packages?.should be_true + end + end it 'ensures that return true if release of published package <' do published_build_list_package.update_attributes(:release => 5) - build_list.can_auto_publish?.should be_true + build_list.has_new_packages?.should be_true end end