From a1a70b562bbbc20afbc2a2e020baa4623e462137 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 17 Jun 2015 00:00:57 +0300 Subject: [PATCH] Fixed: ActiveRecord::SerializationTypeMismatch --- app/models/build_list/package.rb | 11 ++++++----- spec/models/build_list/package_spec.rb | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/models/build_list/package.rb b/app/models/build_list/package.rb index b55c5ffd3..cafa2fdb9 100644 --- a/app/models/build_list/package.rb +++ b/app/models/build_list/package.rb @@ -24,7 +24,6 @@ class BuildList::Package < ActiveRecord::Base scope :like_name, ->(name) { where("#{table_name}.name ILIKE ?", "%#{name}%") if name.present? } before_create :set_epoch - before_create :normalize_dependent_packages def assignee project.maintainer @@ -47,12 +46,14 @@ class BuildList::Package < ActiveRecord::Base end end - protected - - def normalize_dependent_packages - self.dependent_packages = dependent_packages.to_s.split(/\s/).select(&:present?) + # Public: Set dependent_packages. + def dependent_packages=(v) + v = v.to_s.split(/\s/).select(&:present?) if v.is_a?(String) + write_attribute :dependent_packages, v end + protected + def set_epoch self.epoch = nil if epoch.blank? || epoch == 0 end diff --git a/spec/models/build_list/package_spec.rb b/spec/models/build_list/package_spec.rb index fe71fa974..06aed9199 100644 --- a/spec/models/build_list/package_spec.rb +++ b/spec/models/build_list/package_spec.rb @@ -4,17 +4,18 @@ describe BuildList::Package do before { stub_symlink_methods } it 'is valid' do - FactoryGirl.create(:build_list_package).should be_persisted + expect(FactoryGirl.create(:build_list_package)).to be_persisted end - context '#set_epoch' do + + describe '#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 + expect(package.epoch).to be_nil end end @@ -22,9 +23,16 @@ describe BuildList::Package do it "ensures that valid epoch has been setted" do package.epoch = '55' package.save - package.epoch.should == 55 + expect(package.epoch).to eq 55 end end + describe '#dependent_packages=' do + it 'sets a packages' do + package = FactoryGirl.build(:build_list_package, dependent_packages: 'x y z') + expect(package).to be_valid + expect(package.dependent_packages).to eq %w(x y z) + end + end end