diff --git a/app/models/build_list/package.rb b/app/models/build_list/package.rb index ba3700d11..caffcfd03 100644 --- a/app/models/build_list/package.rb +++ b/app/models/build_list/package.rb @@ -5,8 +5,7 @@ class BuildList::Package < ActiveRecord::Base belongs_to :project belongs_to :platform - attr_accessor :epoch - attr_accessible :fullname, :name, :release, :version, :sha1 + attr_accessible :fullname, :name, :release, :version, :sha1, :epoch validates :build_list_id, :project_id, :platform_id, :fullname, :package_type, :name, :release, :version, @@ -23,6 +22,8 @@ class BuildList::Package < ActiveRecord::Base scope :by_package_type, lambda {|type| where(:package_type => type) } scope :like_name, lambda {|name| where("#{table_name}.name ILIKE ?", "%#{name}%") if name.present?} + before_create :set_epoch + def assignee project.maintainer end @@ -38,11 +39,15 @@ class BuildList::Package < ActiveRecord::Base protected + def set_epoch + self.epoch = nil if epoch.blank? || epoch == 0 + end + # String representation in the form "e:v-r" # @return [String] # @note The epoch is included always. As 0 if not present def to_vre_epoch_zero - evr = epoch.present? ? "#{epoch.to_i}:#{version}" : "0:#{version}" + evr = epoch.present? ? "#{epoch}:#{version}" : "0:#{version}" evr << "-#{release}" if release.present? evr end diff --git a/db/migrate/20130912113545_add_epoch_to_build_list_package.rb b/db/migrate/20130912113545_add_epoch_to_build_list_package.rb new file mode 100644 index 000000000..cb17ac841 --- /dev/null +++ b/db/migrate/20130912113545_add_epoch_to_build_list_package.rb @@ -0,0 +1,5 @@ +class AddEpochToBuildListPackage < ActiveRecord::Migration + def change + add_column :build_list_packages, :epoch, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 2e0a0ed69..6a3be7999 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130829161042) do +ActiveRecord::Schema.define(:version => 20130912113545) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -95,6 +95,7 @@ ActiveRecord::Schema.define(:version => 20130829161042) do t.datetime "updated_at", :null => false t.boolean "actual", :default => false t.string "sha1" + t.integer "epoch" end add_index "build_list_packages", ["actual", "platform_id"], :name => "index_build_list_packages_on_actual_and_platform_id" diff --git a/spec/models/build_list/package_spec.rb b/spec/models/build_list/package_spec.rb new file mode 100644 index 000000000..3ed6e1c8c --- /dev/null +++ b/spec/models/build_list/package_spec.rb @@ -0,0 +1,31 @@ +# -*- encoding : utf-8 -*- +require 'spec_helper' + +describe BuildList::Package do + before { stub_symlink_methods } + + it 'is valid' do + FactoryGirl.create(:build_list_package).should be_persisted + end + + context '#set_epoch' do + let(:package) { FactoryGirl.build(:build_list_package) } + + ['', '(none)'].each do |epoch| + it "ensures that epoch is set to nil when epoch is '#{epoch}'" do + package.epoch = epoch + package.save + package.epoch.should be_nil + end + + end + + it "ensures that valid epoch has been setted" do + package.epoch = '55' + package.save + package.epoch.should == 55 + end + + end + +end