Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix #401 api collision #402

Merged
merged 1 commit into from

3 participants

Mark McSpadden Christopher Meiklejohn Nick Quaranto
Mark McSpadden

Corresponding guides PR - rubygems/guides#24

Christopher Meiklejohn
Collaborator

Looks good.

Christopher Meiklejohn cmeiklejohn merged commit 7eaf560 into from
Christopher Meiklejohn
Collaborator

One the build passes on travis, I'll deploy to staging. @qrush @sferik do we need to post a blog entry about this change?

Nick Quaranto
Owner

I'd post to the gemcutter google group, I can post to twitter about it. Most likely not a huge deal given it's a really new API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 15, 2012
  1. Mark McSpadden
This page is out of date. Refresh to see the latest.
14 app/controllers/api/v1/activities_controller.rb
View
@@ -0,0 +1,14 @@
+class Api::V1::ActivitiesController < Api::BaseController
+ respond_to :json, :xml, :yaml, :on => [:latest, :just_updated]
+
+ def latest
+ @rubygems = Rubygem.latest(50)
+ respond_with(@rubygems, :yamlish => true)
+ end
+
+ def just_updated
+ @rubygems = Version.just_updated(50).map(&:rubygem)
+ respond_with(@rubygems, :yamlish => true)
+ end
+
+end
10 app/controllers/api/v1/rubygems_controller.rb
View
@@ -46,16 +46,6 @@ def unyank
end
end
- def latest
- @rubygems = Rubygem.latest(50)
- respond_with(@rubygems, :yamlish => true)
- end
-
- def just_updated
- @rubygems = Version.just_updated(50).map(&:rubygem)
- respond_with(@rubygems, :yamlish => true)
- end
-
private
def validate_gem_and_version
11 config/routes.rb
View
@@ -39,15 +39,20 @@
resources :rubygems, :path => 'gems', :only => [:create, :show, :index], :id => Patterns::LAZY_ROUTE_PATTERN, :format => /json|xml|yaml/ do
collection do
delete :yank
- put :unyank
- get :latest
- get :just_updated
+ put :unyank
end
constraints :rubygem_id => Patterns::ROUTE_PATTERN do
resource :owners, :only => [:show, :create, :destroy]
end
end
+ resource :activity, :only => [], :format => /json|xml|yaml/ do
+ collection do
+ get :latest
+ get :just_updated
+ end
+ end
+
resource :search, :only => :show
resources :web_hooks, :only => [:create, :index] do
86 test/functional/api/v1/activities_controller_test.rb
View
@@ -0,0 +1,86 @@
+require 'test_helper'
+
+class Api::V1::ActivitiesControllerTest < ActionController::TestCase
+
+ def should_return_latest_gems(gems)
+ assert_equal 2, gems.length
+ gems.each {|g| assert g.is_a?(Hash) }
+ assert_equal @rubygem_2.attributes['name'], gems[0]['name']
+ assert_equal @rubygem_3.attributes['name'], gems[1]['name']
+ end
+
+ def should_return_just_updated_gems(gems)
+ assert_equal 3, gems.length
+ gems.each {|g| assert g.is_a?(Hash) }
+ assert_equal @rubygem_1.attributes['name'], gems[0]['name']
+ assert_equal @rubygem_2.attributes['name'], gems[1]['name']
+ assert_equal @rubygem_3.attributes['name'], gems[2]['name']
+ end
+
+ context "No signed in-user" do
+ context "On GET to latest" do
+ setup do
+ @rubygem_1 = Factory(:rubygem)
+ @version_1 = Factory(:version, :rubygem => @rubygem_1)
+ @version_2 = Factory(:version, :rubygem => @rubygem_1)
+
+ @rubygem_2 = Factory(:rubygem)
+ @version_3 = Factory(:version, :rubygem => @rubygem_2)
+
+ @rubygem_3 = Factory(:rubygem)
+ @version_4 = Factory(:version, :rubygem => @rubygem_3)
+
+ stub(Rubygem).latest(50){ [@rubygem_2, @rubygem_3] }
+ end
+
+ should "return correct JSON for latest gems" do
+ get :latest, :format => :json
+ should_return_latest_gems MultiJson.decode(@response.body)
+ end
+
+ should "return correct YAML for latest gems" do
+ get :latest, :format => :yaml
+ should_return_latest_gems YAML.load(@response.body)
+ end
+
+ should "return correct XML for latest gems" do
+ get :latest, :format => :xml
+ gems = Hash.from_xml(Nokogiri.parse(@response.body).to_xml)['rubygems']
+ should_return_latest_gems(gems)
+ end
+ end
+
+ context "On GET to just_updated" do
+ setup do
+ @rubygem_1 = Factory(:rubygem)
+ @version_1 = Factory(:version, :rubygem => @rubygem_1)
+ @version_2 = Factory(:version, :rubygem => @rubygem_1)
+
+ @rubygem_2 = Factory(:rubygem)
+ @version_3 = Factory(:version, :rubygem => @rubygem_2)
+
+ @rubygem_3 = Factory(:rubygem)
+ @version_4 = Factory(:version, :rubygem => @rubygem_3)
+
+ stub(Version).just_updated(50){ [@version_2, @version_3, @version_4] }
+ end
+
+ should "return correct JSON for just_updated gems" do
+ get :just_updated, :format => :json
+ should_return_just_updated_gems MultiJson.decode(@response.body)
+ end
+
+ should "return correct YAML for just_updated gems" do
+ get :just_updated, :format => :yaml
+ should_return_just_updated_gems YAML.load(@response.body)
+ end
+
+ should "return correct XML for just_updated gems" do
+ get :just_updated, :format => :xml
+ gems = Hash.from_xml(Nokogiri.parse(@response.body).to_xml)['rubygems']
+ should_return_just_updated_gems(gems)
+ end
+ end
+
+ end
+end
64 test/functional/api/v1/rubygems_controller_test.rb
View
@@ -393,69 +393,5 @@ def should_return_just_updated_gems(gems)
end
end
- context "On GET to latest" do
- setup do
- @rubygem_1 = Factory(:rubygem)
- @version_1 = Factory(:version, :rubygem => @rubygem_1)
- @version_2 = Factory(:version, :rubygem => @rubygem_1)
-
- @rubygem_2 = Factory(:rubygem)
- @version_3 = Factory(:version, :rubygem => @rubygem_2)
-
- @rubygem_3 = Factory(:rubygem)
- @version_4 = Factory(:version, :rubygem => @rubygem_3)
-
- stub(Rubygem).latest(50){ [@rubygem_2, @rubygem_3] }
- end
-
- should "return correct JSON for latest gems" do
- get :latest, :format => :json
- should_return_latest_gems MultiJson.decode(@response.body)
- end
-
- should "return correct YAML for latest gems" do
- get :latest, :format => :yaml
- should_return_latest_gems YAML.load(@response.body)
- end
-
- should "return correct XML for latest gems" do
- get :latest, :format => :xml
- gems = Hash.from_xml(Nokogiri.parse(@response.body).to_xml)['rubygems']
- should_return_latest_gems(gems)
- end
- end
-
- context "On GET to just_updated" do
- setup do
- @rubygem_1 = Factory(:rubygem)
- @version_1 = Factory(:version, :rubygem => @rubygem_1)
- @version_2 = Factory(:version, :rubygem => @rubygem_1)
-
- @rubygem_2 = Factory(:rubygem)
- @version_3 = Factory(:version, :rubygem => @rubygem_2)
-
- @rubygem_3 = Factory(:rubygem)
- @version_4 = Factory(:version, :rubygem => @rubygem_3)
-
- stub(Version).just_updated(50){ [@version_2, @version_3, @version_4] }
- end
-
- should "return correct JSON for just_updated gems" do
- get :just_updated, :format => :json
- should_return_just_updated_gems MultiJson.decode(@response.body)
- end
-
- should "return correct YAML for just_updated gems" do
- get :just_updated, :format => :yaml
- should_return_just_updated_gems YAML.load(@response.body)
- end
-
- should "return correct XML for just_updated gems" do
- get :just_updated, :format => :xml
- gems = Hash.from_xml(Nokogiri.parse(@response.body).to_xml)['rubygems']
- should_return_just_updated_gems(gems)
- end
- end
-
end
end
Something went wrong with that request. Please try again.