Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove duplicate find_rubygems methods

  • Loading branch information...
commit 72fdbe144a25dafb4b117768ce44327572c0a2a2 1 parent 8348cfd
@sferik sferik authored
View
16 app/controllers/api/v1/owners_controller.rb
@@ -34,18 +34,12 @@ def destroy
end
end
- protected
+protected
- def find_rubygem
- unless @rubygem = Rubygem.find_by_name(params[:rubygem_id])
- render :text => 'This gem could not be found.', :status => :not_found
- end
- end
-
- def verify_gem_ownership
- unless current_user.rubygems.find_by_name(params[:rubygem_id])
- render :text => 'You do not have permission to manage this gem.', :status => :unauthorized
- end
+ def verify_gem_ownership
+ unless current_user.rubygems.find_by_name(params[:rubygem_id])
+ render :text => 'You do not have permission to manage this gem.', :status => :unauthorized
end
+ end
end
View
4 app/controllers/api/v1/rubygems_controller.rb
@@ -3,8 +3,8 @@ class Api::V1::RubygemsController < Api::BaseController
before_filter :authenticate_with_api_key, :only => [:index, :create, :yank, :unyank]
before_filter :verify_authenticated_user, :only => [:index, :create, :yank, :unyank]
- before_filter :find_gem, :only => [:show]
- before_filter :find_gem_by_name, :only => [:yank, :unyank]
+ before_filter :find_rubygem, :only => [:show]
+ before_filter :find_rubygem_by_name, :only => [:yank, :unyank]
before_filter :validate_gem_and_version, :only => [:yank, :unyank]
respond_to :json, :xml, :yaml, :on => [:index, :show, :latest, :just_updated]
View
26 app/controllers/api/v1/web_hooks_controller.rb
@@ -1,10 +1,8 @@
class Api::V1::WebHooksController < Api::BaseController
skip_before_filter :verify_authenticity_token
-
before_filter :authenticate_with_api_key
before_filter :verify_authenticated_user
- before_filter :find_gem_by_name, :except => :index
-
+ before_filter :find_rubygem_by_name, :except => :index
respond_to :json, :xml, :yaml, :only => :index
def index
@@ -13,26 +11,19 @@ def index
def create
webhook = current_user.web_hooks.build(:url => @url, :rubygem => @rubygem)
-
if webhook.save
- render :text => webhook.success_message,
- :status => :created
+ render(:text => webhook.success_message, :status => :created)
else
- render :text => webhook.errors.full_messages,
- :status => :conflict
+ render(:text => webhook.errors.full_messages, :status => :conflict)
end
end
def remove
- webhook = current_user.web_hooks.find_by_rubygem_id_and_url(
- @rubygem.try(:id),
- @url)
-
+ webhook = current_user.web_hooks.find_by_rubygem_id_and_url(@rubygem.try(:id), @url)
if webhook.try(:destroy)
- render :text => webhook.removed_message
+ render(:text => webhook.removed_message)
else
- render :text => "No such webhook exists under your account.",
- :status => :not_found
+ render(:text => "No such webhook exists under your account.", :status => :not_found)
end
end
@@ -40,10 +31,7 @@ def fire
webhook = current_user.web_hooks.new(:url => @url)
@rubygem = Rubygem.find_by_name("gemcutter") unless @rubygem
- if webhook.fire(request.host_with_port,
- @rubygem,
- @rubygem.versions.most_recent,
- false)
+ if webhook.fire(request.host_with_port, @rubygem, @rubygem.versions.most_recent, false)
render :text => webhook.deployed_message(@rubygem)
else
render :text => webhook.failed_message(@rubygem), :status => :bad_request
View
8 app/controllers/application_controller.rb
@@ -3,11 +3,11 @@ class ApplicationController < ActionController::Base
include SimpleSSLRequirement
helper :announcements
-
protect_from_forgery :only => [:create, :update, :destroy]
-
ssl_required :if => :signed_in?
+protected
+
def authenticate_with_api_key
api_key = request.headers["Authorization"] || params[:api_key]
self.current_user = User.find_by_api_key(api_key)
@@ -19,7 +19,7 @@ def verify_authenticated_user
end
end
- def find_gem
+ def find_rubygem
@rubygem = Rubygem.find_by_name(params[:rubygem_id] || params[:id])
if @rubygem.blank?
respond_to do |format|
@@ -33,7 +33,7 @@ def find_gem
end
end
- def find_gem_by_name
+ def find_rubygem_by_name
@url = params[:url]
@gem_name = params[:gem_name]
@rubygem = Rubygem.find_by_name(@gem_name)
View
17 app/controllers/rubygems_controller.rb
@@ -1,6 +1,6 @@
class RubygemsController < ApplicationController
before_filter :redirect_to_root, :only => [:edit, :update], :unless => :signed_in?
- before_filter :find_gem, :only => [:edit, :update, :show]
+ before_filter :find_rubygem, :only => [:edit, :update, :show]
before_filter :load_gem, :only => [:edit, :update]
def index
@@ -33,13 +33,14 @@ def update
end
end
- protected
- def load_gem
- if !@rubygem.owned_by?(current_user)
- flash[:warning] = "You do not have permission to edit this gem."
- redirect_to root_url
- end
+protected
- @linkset = @rubygem.linkset
+ def load_gem
+ if !@rubygem.owned_by?(current_user)
+ flash[:warning] = "You do not have permission to edit this gem."
+ redirect_to root_url
end
+
+ @linkset = @rubygem.linkset
+ end
end
View
2  app/controllers/stats_controller.rb
@@ -1,5 +1,5 @@
class StatsController < ApplicationController
- before_filter :find_gem, :only => :show
+ before_filter :find_rubygem, :only => :show
before_filter :ensure_hosted, :only => :show
def index
View
25 app/controllers/subscriptions_controller.rb
@@ -1,29 +1,24 @@
class SubscriptionsController < ApplicationController
-
- before_filter :find_gem
+ before_filter :find_rubygem
def create
- subscription = @gem.subscriptions.build(:user => current_user)
+ subscription = @rubygem.subscriptions.build(:user => current_user)
render_toggle_or_unacceptable(subscription.try(:save))
end
def destroy
- subscription = @gem.subscriptions.find_by_user_id(current_user.try(:id))
+ subscription = @rubygem.subscriptions.find_by_user_id(current_user.try(:id))
render_toggle_or_unacceptable(subscription.try(:destroy))
end
- protected
-
- def find_gem
- @gem = Rubygem.find_by_name(params[:rubygem_id])
- end
+protected
- def render_toggle_or_unacceptable(success)
- if success
- render(:update) { |page| page['.toggler'].toggle }
- else
- render :text => '', :status => :forbidden
- end
+ def render_toggle_or_unacceptable(success)
+ if success
+ render(:update) { |page| page['.toggler'].toggle }
+ else
+ render :text => '', :status => :forbidden
end
+ end
end
View
2  app/controllers/versions_controller.rb
@@ -1,5 +1,5 @@
class VersionsController < ApplicationController
- before_filter :find_gem
+ before_filter :find_rubygem
def index
@versions = @rubygem.versions.by_position
View
36 test/functional/subscriptions_controller_test.rb
@@ -10,12 +10,12 @@ class SubscriptionsControllerTest < ActionController::TestCase
context "On POST to create for a gem that the user is not subscribed to" do
setup do
- @gem = Factory(:rubygem)
- Factory(:version, :rubygem => @gem)
- post :create, :rubygem_id => @gem.to_param
+ @rubygem = Factory(:rubygem)
+ Factory(:version, :rubygem => @rubygem)
+ post :create, :rubygem_id => @rubygem.to_param
end
- should assign_to(:gem) { @gem }
+ should assign_to(:rubygem) { @rubygem }
should respond_with :success
should "toggle the subscribe link" do
assert_match /\("\.toggler"\)\.toggle\(\)/, @response.body
@@ -24,36 +24,36 @@ class SubscriptionsControllerTest < ActionController::TestCase
context "On POST to create for a gem that the user is subscribed to" do
setup do
- @gem = Factory(:rubygem)
- Factory(:version, :rubygem => @gem)
- Factory(:subscription, :rubygem => @gem, :user => @user)
- post :create, :rubygem_id => @gem.to_param
+ @rubygem = Factory(:rubygem)
+ Factory(:version, :rubygem => @rubygem)
+ Factory(:subscription, :rubygem => @rubygem, :user => @user)
+ post :create, :rubygem_id => @rubygem.to_param
end
- should assign_to(:gem) { @gem }
+ should assign_to(:rubygem) { @rubygem }
should respond_with :forbidden
end
context "On DELETE to destroy for a gem that the user is not subscribed to" do
setup do
- @gem = Factory(:rubygem)
- Factory(:version, :rubygem => @gem)
- delete :destroy, :rubygem_id => @gem.to_param
+ @rubygem = Factory(:rubygem)
+ Factory(:version, :rubygem => @rubygem)
+ delete :destroy, :rubygem_id => @rubygem.to_param
end
- should assign_to(:gem) { @gem }
+ should assign_to(:rubygem) { @rubygem }
should respond_with :forbidden
end
context "On DELETE to destroy for a gem that the user is subscribed to" do
setup do
- @gem = Factory(:rubygem)
- Factory(:version, :rubygem => @gem)
- Factory(:subscription, :rubygem => @gem, :user => @user)
- delete :destroy, :rubygem_id => @gem.to_param
+ @rubygem = Factory(:rubygem)
+ Factory(:version, :rubygem => @rubygem)
+ Factory(:subscription, :rubygem => @rubygem, :user => @user)
+ delete :destroy, :rubygem_id => @rubygem.to_param
end
- should assign_to(:gem) { @gem }
+ should assign_to(:rubygem) { @rubygem }
should respond_with :success
should "toggle the subscribe link" do
assert_match /\("\.toggler"\)\.toggle\(\)/, @response.body
Please sign in to comment.
Something went wrong with that request. Please try again.