diff --git a/Gemfile b/Gemfile index 75a43a941..7f01fde4b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,8 @@ #ruby=1.9.3 source 'https://rubygems.org' -source 'https://jamjam:blueberryjam@www.jamkazam.com/gems/' +unless ENV["LOCAL_DEV"] == "1" + source 'https://jamjam:blueberryjam@www.jamkazam.com/gems/' +end # Look for $WORKSPACE, otherwise use "workspace" as dev path. workspace = ENV["WORKSPACE"] || "~/workspace" diff --git a/lib/jam_ruby/models/artifact_update.rb b/lib/jam_ruby/models/artifact_update.rb index 9367b25c3..d224f6120 100644 --- a/lib/jam_ruby/models/artifact_update.rb +++ b/lib/jam_ruby/models/artifact_update.rb @@ -7,12 +7,25 @@ module JamRuby self.primary_key = 'id' attr_accessible :version, :uri, :sha1, :environment, :product + + # ORDER MATTERS HERE- before_save for this method must be declared before mount_uploader: https://github.com/jnicklas/carrierwave/wiki/Known-Issues + before_save :update_uri_attributes mount_uploader :uri, ArtifactUploader validate :version, :presence => true validate :uri, :presence => true - validate :sha1, :presence => false - validate :environment, presence => true + validate :sha1, :presence => true + validate :size, :presence => true + validate :environment, :presence => true validate :product, :inclusion => {:in => PRODUCTS} + + private + + def update_uri_attributes + if uri.present? && uri_changed? + self.size = uri.file.size + self.sha1 = Digest::MD5.hexdigest(File.read(uri.current_path)) + end + end end end diff --git a/spec/jam_ruby/models/artifact_update_spec.rb b/spec/jam_ruby/models/artifact_update_spec.rb index c4ed36193..24075e310 100644 --- a/spec/jam_ruby/models/artifact_update_spec.rb +++ b/spec/jam_ruby/models/artifact_update_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'digest/md5' describe ArtifactUpdate do @@ -23,15 +24,14 @@ describe ArtifactUpdate do artifact.product = 'JamClient/Win32' artifact.version = '0.1.1' artifact.uri = File.open(ARTIFACT_FILE) - artifact.sha1 = 'blahablahblah' - artifact.save! artifact.environment.should == "public" artifact.product.should == "JamClient/Win32" artifact.version.should == "0.1.1" File.basename(artifact.uri.path).should == ARTIFACT_FILE - artifact.sha1.should == "blahablahblah" + artifact.sha1.should == Digest::MD5.hexdigest(File.read(ARTIFACT_FILE)) + artifact.size.should == File.size(ARTIFACT_FILE) found = ArtifactUpdate.find_by_product_and_version('JamClient/Win32', '0.1.1') artifact.should == found