Browse files

Moving the show view over

  • Loading branch information...
1 parent 0554452 commit 76873866fb5278379e3a81e1d907e815f66a5224 @qrush qrush committed May 30, 2009
View
5 Rakefile
@@ -10,9 +10,10 @@ desc "Run all tests and features"
task :default => [:test, :features]
desc "Clean out files that aren't needed."
-task :clean do
+task :clean => :environment do
system("git clean -dfx server/; git checkout server/")
- Rake::Task["db:reset"].execute
+ Rubygem.delete_all
+ Version.delete_all
end
desc "Get the gem server up and running"
View
5 app/controllers/rubygems_controller.rb
@@ -3,4 +3,9 @@ class RubygemsController < ApplicationController
def index
@gems = Rubygem.all
end
+
+ def show
+ @gem = Rubygem.find_by_name(params[:id])
+ @current_version = @gem.versions.first
+ end
end
View
1 app/models/version.rb
@@ -1,4 +1,5 @@
class Version < ActiveRecord::Base
belongs_to :rubygem
+ default_scope :order => 'created_at DESC'
end
View
36 app/views/rubygems/show.html.haml
@@ -0,0 +1,36 @@
+-@title = @gem.name
+-@subtitle = @current_version.number
+-@page_title = "#{@gem} &raquo; #{page_title}"
+.grid_8
+ .block.red
+ %h3 Description
+ %p= @current_version.description
+ .block.green
+ %h3 Install
+ %pre= "gem install #{@gem}"
+ .block.red.versions
+ -if @gem.versions.size > 1
+ %h3 Versions
+ %p
+ -@gem.versions.each do |version|
+ %a{:href => "/"}
+ %span.version= version.number
+ %span.date= version.created_at.to_date.to_formatted_s(:long)
+.grid_4
+ .block.red
+ %h3 Authors
+ %p= @current_version.authors
+ .block.red
+ %h3 Downloads
+ %p= @current_version.downloads
+ .block.red
+ %h3 Last Update
+ %p= @current_version.created_at.to_date.to_formatted_s(:long)
+ .block.red.links
+ %h3 Links
+ %p
+ %a{:href => "/"} Homepage
+ %a{:href => "/"} Docs
+ %a{:href => "/"} Code
+ %a{:href => "/"} Mailing List
+ %a{:href => "/"} Bug Tracker
View
45 apps/site/views/gem.haml
@@ -1,45 +0,0 @@
--@title = @gem.name
--@subtitle = @gem.version
--@page_title = "#{@gem.name} &raquo; #{page_title}"
-.grid_8
- .block.red
- %h3 Description
- %p= @gem.description || @gem.summary
- .block.green
- %h3 Install
- %pre= "gem install #{@gem.name}"
- .block.red.versions
- %h3 Versions
- %p
- %a{:href => "/"}
- %span.version 0.0.3
- %span.date January 12, 2005
- %a{:href => "/"}
- %span.version 0.0.2
- %span.date January 11, 2005
- %a{:href => "/"}
- %span.version 0.0.1
- %span.date January 4, 2005
-.grid_4
- -unless @gem.authors.empty?
- .block.red
- -if @gem.authors.size == 1
- %h3 Author
- -else
- %h3 Authors
- -@gem.authors.each do |author|
- %p= author
- .block.red
- %h3 Downloads
- %p 23,000
- .block.red
- %h3 Last Update
- %p= @gem.date.strftime("%B %e, %Y")
- .block.red.links
- %h3 Links
- %p
- %a{:href => "/"} Homepage
- %a{:href => "/"} Docs
- %a{:href => "/"} Code
- %a{:href => "/"} Mailing List
- %a{:href => "/"} Bug Tracker
View
45 test/functional/rubygems_controller_test.rb
@@ -17,5 +17,50 @@ class RubygemsControllerTest < ActionController::TestCase
end
end
end
+
+ context "On GET to show" do
+ setup do
+ @gem = Factory(:rubygem)
+ @current_version = @gem.versions.first
+ get :show, :id => @gem.to_param
+ end
+
+ should_respond_with :success
+ should_render_template :show
+ should_assign_to :gem
+ should_assign_to :current_version
+ should "render info about the gem" do
+ assert_contain @gem.name
+ assert_contain @current_version.description
+ assert_contain @current_version.number
+ assert_contain @current_version.created_at.to_date.to_formatted_s(:long)
+ assert_not_contain "Versions"
+ end
+ end
+
+ context "On GET to show with a gem that has multiple versions" do
+ setup do
+ @gem = Factory(:rubygem)
+ @version = Factory(:version, :number => "1.0.0", :rubygem => @gem)
+ @gem.reload
+ @current_version = @gem.versions.first
+ get :show, :id => @gem.to_param
+ end
+
+ should_respond_with :success
+ should_render_template :show
+ should_assign_to :gem
+ should_assign_to :current_version
+ should "render info about the gem" do
+ assert_contain @gem.name
+ assert_contain @current_version.description
+ assert_contain @current_version.number
+ assert_contain @current_version.created_at.to_date.to_formatted_s(:long)
+
+ assert_contain "Versions"
+ assert_contain @gem.versions.last.number
+ assert_contain @gem.versions.last.created_at.to_date.to_formatted_s(:long)
+ end
+ end
end

0 comments on commit 7687386

Please sign in to comment.