Skip to content
This repository

Fix #401 api collision #402

Merged
merged 1 commit into from about 2 years ago

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 February 15, 2012
Christopher Meiklejohn cmeiklejohn closed this February 15, 2012
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

Showing 1 unique commit by 1 author.

Feb 14, 2012
Mark McSpadden Move latest and just_update api endpoint from rubygems controller to …
…new activites controller
4e51e5a
This page is out of date. Refresh to see the latest.
14  app/controllers/api/v1/activities_controller.rb
... ...
@@ -0,0 +1,14 @@
  1
+class Api::V1::ActivitiesController < Api::BaseController
  2
+  respond_to :json, :xml, :yaml, :on => [:latest, :just_updated]
  3
+
  4
+  def latest
  5
+    @rubygems = Rubygem.latest(50)
  6
+    respond_with(@rubygems, :yamlish => true)
  7
+  end
  8
+
  9
+  def just_updated
  10
+    @rubygems = Version.just_updated(50).map(&:rubygem)
  11
+    respond_with(@rubygems, :yamlish => true)
  12
+  end
  13
+
  14
+end
10  app/controllers/api/v1/rubygems_controller.rb
@@ -46,16 +46,6 @@ def unyank
46 46
     end
47 47
   end
48 48
 
49  
-  def latest
50  
-    @rubygems = Rubygem.latest(50)
51  
-    respond_with(@rubygems, :yamlish => true)
52  
-  end
53  
-
54  
-  def just_updated
55  
-    @rubygems = Version.just_updated(50).map(&:rubygem)
56  
-    respond_with(@rubygems, :yamlish => true)
57  
-  end
58  
-
59 49
   private
60 50
 
61 51
   def validate_gem_and_version
11  config/routes.rb
@@ -39,15 +39,20 @@
39 39
       resources :rubygems, :path => 'gems', :only => [:create, :show, :index], :id => Patterns::LAZY_ROUTE_PATTERN, :format => /json|xml|yaml/ do
40 40
         collection do
41 41
           delete :yank
42  
-          put :unyank
43  
-          get :latest
44  
-          get :just_updated
  42
+          put :unyank          
45 43
         end
46 44
         constraints :rubygem_id => Patterns::ROUTE_PATTERN do
47 45
           resource :owners, :only => [:show, :create, :destroy]
48 46
         end
49 47
       end
50 48
 
  49
+      resource :activity, :only => [], :format => /json|xml|yaml/ do
  50
+        collection do
  51
+          get :latest
  52
+          get :just_updated
  53
+        end
  54
+      end
  55
+
51 56
       resource :search, :only => :show
52 57
 
53 58
       resources :web_hooks, :only => [:create, :index] do
86  test/functional/api/v1/activities_controller_test.rb
... ...
@@ -0,0 +1,86 @@
  1
+require 'test_helper'
  2
+
  3
+class Api::V1::ActivitiesControllerTest < ActionController::TestCase
  4
+
  5
+  def should_return_latest_gems(gems)
  6
+    assert_equal 2, gems.length
  7
+    gems.each {|g| assert g.is_a?(Hash) }
  8
+    assert_equal @rubygem_2.attributes['name'], gems[0]['name']
  9
+    assert_equal @rubygem_3.attributes['name'], gems[1]['name']
  10
+  end
  11
+
  12
+  def should_return_just_updated_gems(gems)
  13
+    assert_equal 3, gems.length
  14
+    gems.each {|g| assert g.is_a?(Hash) }
  15
+    assert_equal @rubygem_1.attributes['name'], gems[0]['name']
  16
+    assert_equal @rubygem_2.attributes['name'], gems[1]['name']
  17
+    assert_equal @rubygem_3.attributes['name'], gems[2]['name']
  18
+  end
  19
+
  20
+  context "No signed in-user" do
  21
+    context "On GET to latest" do
  22
+      setup do
  23
+        @rubygem_1 = Factory(:rubygem)
  24
+        @version_1 = Factory(:version, :rubygem => @rubygem_1)
  25
+        @version_2 = Factory(:version, :rubygem => @rubygem_1)
  26
+
  27
+        @rubygem_2 = Factory(:rubygem)
  28
+        @version_3 = Factory(:version, :rubygem => @rubygem_2)
  29
+
  30
+        @rubygem_3 = Factory(:rubygem)
  31
+        @version_4 = Factory(:version, :rubygem => @rubygem_3)
  32
+
  33
+        stub(Rubygem).latest(50){ [@rubygem_2, @rubygem_3] }
  34
+      end
  35
+
  36
+      should "return correct JSON for latest gems" do
  37
+        get :latest, :format => :json
  38
+        should_return_latest_gems MultiJson.decode(@response.body)
  39
+      end
  40
+
  41
+      should "return correct YAML for latest gems" do
  42
+        get :latest, :format => :yaml
  43
+        should_return_latest_gems YAML.load(@response.body)
  44
+      end
  45
+
  46
+      should "return correct XML for latest gems" do
  47
+        get :latest, :format => :xml
  48
+        gems = Hash.from_xml(Nokogiri.parse(@response.body).to_xml)['rubygems']
  49
+        should_return_latest_gems(gems)
  50
+      end
  51
+    end
  52
+
  53
+    context "On GET to just_updated" do
  54
+      setup do
  55
+        @rubygem_1 = Factory(:rubygem)
  56
+        @version_1 = Factory(:version, :rubygem => @rubygem_1)
  57
+        @version_2 = Factory(:version, :rubygem => @rubygem_1)
  58
+
  59
+        @rubygem_2 = Factory(:rubygem)
  60
+        @version_3 = Factory(:version, :rubygem => @rubygem_2)
  61
+
  62
+        @rubygem_3 = Factory(:rubygem)
  63
+        @version_4 = Factory(:version, :rubygem => @rubygem_3)
  64
+
  65
+        stub(Version).just_updated(50){ [@version_2, @version_3, @version_4] }
  66
+      end
  67
+
  68
+      should "return correct JSON for just_updated gems" do
  69
+        get :just_updated, :format => :json
  70
+        should_return_just_updated_gems MultiJson.decode(@response.body)
  71
+      end
  72
+
  73
+      should "return correct YAML for just_updated gems" do
  74
+        get :just_updated, :format => :yaml
  75
+        should_return_just_updated_gems YAML.load(@response.body)
  76
+      end
  77
+
  78
+      should "return correct XML for just_updated gems" do
  79
+        get :just_updated, :format => :xml
  80
+        gems = Hash.from_xml(Nokogiri.parse(@response.body).to_xml)['rubygems']
  81
+        should_return_just_updated_gems(gems)
  82
+      end
  83
+    end
  84
+
  85
+  end
  86
+end
64  test/functional/api/v1/rubygems_controller_test.rb
@@ -393,69 +393,5 @@ def should_return_just_updated_gems(gems)
393 393
       end
394 394
     end
395 395
 
396  
-    context "On GET to latest" do
397  
-      setup do
398  
-        @rubygem_1 = Factory(:rubygem)
399  
-        @version_1 = Factory(:version, :rubygem => @rubygem_1)
400  
-        @version_2 = Factory(:version, :rubygem => @rubygem_1)
401  
-
402  
-        @rubygem_2 = Factory(:rubygem)
403  
-        @version_3 = Factory(:version, :rubygem => @rubygem_2)
404  
-
405  
-        @rubygem_3 = Factory(:rubygem)
406  
-        @version_4 = Factory(:version, :rubygem => @rubygem_3)
407  
-
408  
-        stub(Rubygem).latest(50){ [@rubygem_2, @rubygem_3] }
409  
-      end
410  
-
411  
-      should "return correct JSON for latest gems" do
412  
-        get :latest, :format => :json
413  
-        should_return_latest_gems MultiJson.decode(@response.body)
414  
-      end
415  
-
416  
-      should "return correct YAML for latest gems" do
417  
-        get :latest, :format => :yaml
418  
-        should_return_latest_gems YAML.load(@response.body)
419  
-      end
420  
-
421  
-      should "return correct XML for latest gems" do
422  
-        get :latest, :format => :xml
423  
-        gems = Hash.from_xml(Nokogiri.parse(@response.body).to_xml)['rubygems']
424  
-        should_return_latest_gems(gems)
425  
-      end
426  
-    end
427  
-
428  
-    context "On GET to just_updated" do
429  
-      setup do
430  
-        @rubygem_1 = Factory(:rubygem)
431  
-        @version_1 = Factory(:version, :rubygem => @rubygem_1)
432  
-        @version_2 = Factory(:version, :rubygem => @rubygem_1)
433  
-
434  
-        @rubygem_2 = Factory(:rubygem)
435  
-        @version_3 = Factory(:version, :rubygem => @rubygem_2)
436  
-
437  
-        @rubygem_3 = Factory(:rubygem)
438  
-        @version_4 = Factory(:version, :rubygem => @rubygem_3)
439  
-
440  
-        stub(Version).just_updated(50){ [@version_2, @version_3, @version_4] }
441  
-      end
442  
-
443  
-      should "return correct JSON for just_updated gems" do
444  
-        get :just_updated, :format => :json
445  
-        should_return_just_updated_gems MultiJson.decode(@response.body)
446  
-      end
447  
-
448  
-      should "return correct YAML for just_updated gems" do
449  
-        get :just_updated, :format => :yaml
450  
-        should_return_just_updated_gems YAML.load(@response.body)
451  
-      end
452  
-
453  
-      should "return correct XML for just_updated gems" do
454  
-        get :just_updated, :format => :xml
455  
-        gems = Hash.from_xml(Nokogiri.parse(@response.body).to_xml)['rubygems']
456  
-        should_return_just_updated_gems(gems)
457  
-      end
458  
-    end
459  
-
460 396
   end
461 397
 end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.