Permalink
Browse files

Merge remote-tracking branch 'gnarg/master' into size

Conflicts:
	app/models/pusher.rb
	db/schema.rb
	features/push.feature
	test/unit/pusher_test.rb
  • Loading branch information...
2 parents d9a9283 + ebbc2b6 commit d49ea76a5c3b3412d7f29485b3b2b4b056434e03 @evanphx evanphx committed Jul 12, 2013
View
@@ -1,5 +1,5 @@
class Pusher
- attr_reader :user, :spec, :message, :code, :rubygem, :body, :version, :version_id
+ attr_reader :user, :spec, :message, :code, :rubygem, :body, :version, :version_id, :size
attr_accessor :bundler_api_url
def initialize(user, body, host_with_port=nil)
@@ -53,6 +53,7 @@ def pull_spec
def find
@rubygem = Rubygem.find_or_initialize_by_name(spec.name.to_s)
@version = @rubygem.find_or_initialize_version_from_spec(spec)
+ @version.size ||= size
if @version.new_record?
true
@@ -109,6 +110,7 @@ def notify(message, code)
def update
rubygem.update_attributes_from_gem_specification!(version, spec)
rubygem.create_ownership(user) unless version.new_record?
+ @size = body.size if body
true
rescue ActiveRecord::RecordInvalid, ActiveRecord::Rollback
false
View
@@ -139,6 +139,10 @@ def yanked?
!indexed
end
+ def size
+ read_attribute(:size) || 'N/A'
+ end
+
def info
[ description, summary, "This rubygem does not have a description or summary." ].detect(&:present?)
end
@@ -4,6 +4,7 @@
<% if version.platformed? %>
<span class="platform"><%= version.platform %></span>
<% end %>
+ <span class="size">(<%= number_to_human_size(version.size) %>)</span>
<% if version.yanked? -%>
<span class="yanked"><%= t '.yanked' %></span>
<% end -%>
@@ -0,0 +1,9 @@
+class AddSizeToVersion < ActiveRecord::Migration
+ def self.up
+ add_column :versions, :size, :integer
+ end
+
+ def self.down
+ remove_column :versions, :size
+ end
+end
View
@@ -12,7 +12,6 @@
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20121124000000) do
-
create_table "announcements", :force => true do |t|
t.text "body"
t.datetime "created_at", :null => false
@@ -145,6 +144,7 @@
t.boolean "latest"
t.string "full_name"
t.string "licenses"
+ t.integer "size"
end
add_index "versions", ["built_at"], :name => "index_versions_on_built_at"
View
@@ -13,6 +13,7 @@ Feature: Push Gems
And I visit the gem page for "RGem"
Then I should see "RGem"
And I should see "1.2.3"
+ And I should see "(3 KB)"
And I should see "John Doe"
And I should see "The best gem"
And I should see "MIT"
View
@@ -18,7 +18,7 @@ namespace :gemcutter do
puts "Processing #{path}"
cutter = Pusher.new(nil, File.open(path))
- cutter.pull_spec and cutter.find and cutter.save
+ cutter.pull_spec and cutter.size_gem and cutter.find and cutter.save
end
end
end
@@ -749,7 +749,7 @@ table {
text-decoration: underline;
}
-.main .info .meta .versions .platform {
+.main .info .meta .versions .platform .size {
color: #B0A58C;
font-size: 0.85em;
margin-left: 4px;
@@ -0,0 +1,28 @@
+#!/usr/bin/env ruby
+
+ENV['RAILS_ENV'] ||= 'production'
+require_relative '../config/environment'
+
+def fog
+ $fog || Fog::Storage.new(:provider => 'Local',
+ :local_root => Pusher.server_path('gems'))
+end
+
+Version.find_in_batches do |versions|
+ versions.each do |version|
+ print "sizing #{version.full_name}: "
+ file = fog.directories.get($rubygems_config[:s3_bucket] + '/gems') \
+ .files.get("#{version.full_name}.gem")
+ if file
+ begin
+ size = file.content_length.bytes
+ version.update_attribute(:size, size)
+ print "succeeded (#{size})\n"
+ rescue => e
+ print "failed - #{e.message}"
+ end
+ else
+ print "failed - file not found"
+ end
+ end
+end
View
@@ -82,6 +82,7 @@
platform "ruby"
licenses "MIT"
rubygem
+ size 1024
end
factory :version_history do
View
@@ -127,19 +127,31 @@ class PusherTest < ActiveSupport::TestCase
assert_equal false, params["prerelease"]
end
- context "finding rubygem" do
- should "initialize new gem if one does not exist" do
+ context "initialize new gem with find if one does not exist" do
+ setup do
spec = "spec"
stub(spec).name { "some name" }
stub(spec).version { "1.3.3.7" }
stub(spec).original_platform { "ruby" }
stub(@cutter).spec { spec }
+ stub(@cutter).size { 5 }
@cutter.find
+ end
- assert_not_nil @cutter.rubygem
- assert_not_nil @cutter.version
+ should "set rubygem" do
+ assert_equal 'some name', @cutter.rubygem.name
end
+ should "set version" do
+ assert_equal '1.3.3.7', @cutter.version.number
+ end
+
+ should "set gem version size" do
+ assert_equal 5, @cutter.version.size
+ end
+ end
+
+ context "finding an existing gem" do
should "bring up existing gem with matching spec" do
@rubygem = create(:rubygem)
spec = "spec"
@@ -188,5 +200,32 @@ class PusherTest < ActiveSupport::TestCase
end
end
end
+
+ context "successfully saving a gemcutter" do
+ setup do
+ @rubygem = create(:rubygem)
+ stub(@cutter).rubygem { @rubygem }
+ create(:version, :rubygem => @rubygem, :number => '0.1.1')
+ stub(@cutter).version { @rubygem.versions[0] }
+ stub(@rubygem).update_attributes_from_gem_specification!
+ any_instance_of(Indexer) {|i| stub(i).write_gem }
+ @cutter.save
+ end
+
+ should "update rubygem attributes" do
+ assert_received(@rubygem) do |rubygem|
+ rubygem.update_attributes_from_gem_specification!(@cutter.version,
+ @cutter.spec)
+ end
+ end
+
+ should "set gem file size" do
+ assert_equal @gem.size, @cutter.size
+ end
+
+ should "set success code" do
+ assert_equal 200, @cutter.code
+ end
+ end
end
end
@@ -295,6 +295,11 @@ class VersionTest < ActiveSupport::TestCase
assert_equal "This rubygem does not have a description or summary.", @version.info
end
+ should "give 'N/A' for size when size not available" do
+ @version.size = nil
+ assert_equal 'N/A', @version.size
+ end
+
context "when yanked" do
setup do
@version.yank!

0 comments on commit d49ea76

Please sign in to comment.