Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #401 api collision #402

Merged
merged 1 commit into from
Feb 15, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/controllers/api/v1/activities_controller.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 0 additions & 10 deletions app/controllers/api/v1/rubygems_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
86 changes: 86 additions & 0 deletions test/functional/api/v1/activities_controller_test.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 0 additions & 64 deletions test/functional/api/v1/rubygems_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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