Skip to content

Commit

Permalink
Rubocop: Fixed failures
Browse files Browse the repository at this point in the history
  • Loading branch information
David Davis committed Oct 8, 2013
1 parent 721c6e3 commit aa05b86
Show file tree
Hide file tree
Showing 125 changed files with 333 additions and 330 deletions.
6 changes: 3 additions & 3 deletions app/controllers/api/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ def split_order(order)

def get_resource
resource = instance_variable_get(:"@#{resource_name}")
raise 'no resource loaded' if resource.nil?
fail 'no resource loaded' if resource.nil?
resource
end

def get_resource_collection
resource = instance_variable_get(:"@#{resource_collection_name}")
raise 'no resource collection loaded' if resource.nil?
fail 'no resource collection loaded' if resource.nil?
resource
end

Expand All @@ -116,7 +116,7 @@ def resource_name

def respond(options = {})
method_name = ('respond_for_' + params[:action].to_s).to_sym
raise "automatic response method '%s' not defined" % method_name unless respond_to?(method_name, true)
fail "automatic response method '%s' not defined" % method_name unless respond_to?(method_name, true)
return send(method_name, options)
end
end
10 changes: 5 additions & 5 deletions app/controllers/api/v1/activation_keys_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def add_pool
api :DELETE, "/activation_keys/:id/pools/:poolid", "Delete an entitlement pool within an activation key"
def remove_pool
unless @activation_key.pools.include?(@pool)
raise HttpErrors::NotFound, _("Couldn't find pool '%{pool}' in activation_key '%{ak}'") % { :pool => @pool.cp_id, :ak => @activation_key.name }
fail HttpErrors::NotFound, _("Couldn't find pool '%{pool}' in activation_key '%{ak}'") % { :pool => @pool.cp_id, :ak => @activation_key.name }
end
@activation_key.pools.delete(@pool)
respond_for_show
Expand Down Expand Up @@ -143,13 +143,13 @@ def find_environment
return unless params.key?(:environment_id)

@environment = KTEnvironment.find(params[:environment_id])
raise HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil?
fail HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil?
@environment
end

def find_activation_key
@activation_key = ActivationKey.find(params[:id])
raise HttpErrors::NotFound, _("Couldn't find activation key '%s'") % params[:id] if @activation_key.nil?
fail HttpErrors::NotFound, _("Couldn't find activation key '%s'") % params[:id] if @activation_key.nil?
@activation_key
end

Expand All @@ -163,14 +163,14 @@ def find_system_groups
if ids
ids.each do |group_id|
group = SystemGroup.find(group_id)
raise HttpErrors::NotFound, _("Couldn't find system group '%s'") % group_id if group.nil?
fail HttpErrors::NotFound, _("Couldn't find system group '%s'") % group_id if group.nil?
@system_groups << group
end
end
end

def verify_presence_of_organization_or_environment
return if params.key?(:organization_id) || params.key?(:environment_id)
raise HttpErrors::BadRequest, _("Either organization ID or environment ID needs to be specified")
fail HttpErrors::BadRequest, _("Either organization ID or environment ID needs to be specified")
end
end
8 changes: 4 additions & 4 deletions app/controllers/api/v1/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def query_params

def find_organization
@organization = find_optional_organization
raise HttpErrors::NotFound, _("One of parameters [%s] required but not specified.") %
fail HttpErrors::NotFound, _("One of parameters [%s] required but not specified.") %
organization_id_keys.join(", ") if @organization.nil?
@organization
end
Expand All @@ -62,7 +62,7 @@ def find_optional_organization
return if org_id.nil?

@organization = get_organization(org_id)
raise HttpErrors::NotFound, _("Couldn't find organization '%s'") % org_id if @organization.nil?
fail HttpErrors::NotFound, _("Couldn't find organization '%s'") % org_id if @organization.nil?
@organization
end

Expand All @@ -86,14 +86,14 @@ def find_content_view_definition
cvd_id = params[:content_view_definition_id]
@definition = ContentViewDefinition.find_by_id(cvd_id)
if @definition.nil?
raise HttpErrors::NotFound, _("Couildn't find content view with id '%s'") % cvd_id
fail HttpErrors::NotFound, _("Couildn't find content view with id '%s'") % cvd_id
end
end

def find_content_filter_by_name
filter_id = params[:filter_id]
@filter = Filter.where(:name => filter_id, :content_view_definition_id => @definition).first
raise HttpErrors::NotFound, _("Couldn't find filter '%s'") % params[:id] if @filter.nil?
fail HttpErrors::NotFound, _("Couldn't find filter '%s'") % params[:id] if @filter.nil?
@filter
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v1/changesets_content_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def find_changeset!
def find_content_view!
id = params[:action] == "add_content_view" ? params[:content_view_id] : params[:id]
@view = ContentView.find_by_id(id)
raise HttpErrors::NotFound, _("Couldn't find content view '%s'") % id if @view.nil?
fail HttpErrors::NotFound, _("Couldn't find content view '%s'") % id if @view.nil?
end

def render_after_removal(removed_objects, options = {})
Expand All @@ -56,7 +56,7 @@ def render_after_removal(removed_objects, options = {})
else
rend = { :text => options[:not_found], :status => 404 }
end
raise ArgumentError if rend[:text].nil?
fail ArgumentError if rend[:text].nil?
render(rend)
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v1/changesets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ def destroy

def find_changeset
@changeset = Changeset.find(params[:id])
raise HttpErrors::NotFound, _("Couldn't find changeset '%s'") % params[:id] if @changeset.nil?
fail HttpErrors::NotFound, _("Couldn't find changeset '%s'") % params[:id] if @changeset.nil?
@environment = @changeset.environment
@changeset
end

def find_environment
@environment = KTEnvironment.find(params[:environment_id])
raise HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil?
fail HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil?
@environment
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def publish
api :DELETE, "/content_view_definitions/:id", "Delete a cv definition"
param :id, :identifier, :desc => "Definition identifier", :required => true
def destroy
raise HttpErrors::BadRequest, _("Definition cannot be deleted since one of its views has already been promoted. "\
fail HttpErrors::BadRequest, _("Definition cannot be deleted since one of its views has already been promoted. "\
"Using a changeset, please delete the views from existing environments before deleting the "\
"definition.") if @definition.has_promoted_views?

Expand Down
10 changes: 5 additions & 5 deletions app/controllers/api/v1/content_views_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def destroy
if @view.destroyed?
render :text => _("Deleted content view [ %s ]") % @view.name, :status => 200
else
raise HttpErrors::InternalError, _("Error while deleting content view [ %{name} ]: %{error}") %
fail HttpErrors::InternalError, _("Error while deleting content view [ %{name} ]: %{error}") %
{ :name => @view.name, :error => @view.errors.full_messages }
end
end
Expand All @@ -92,24 +92,24 @@ def destroy
def find_content_view
@view = ContentView.find(params[:id])
if params[:action] != "show" && @view.default?
raise HttpErrors::BadRequest, _("The default content view cannot be edited, promoted, refreshed, or destroyed.")
fail HttpErrors::BadRequest, _("The default content view cannot be edited, promoted, refreshed, or destroyed.")
end
end

def find_environment
@environment = KTEnvironment.find_by_id(params[:environment_id])
raise HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil?
fail HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil?
@organization ||= @environment.organization
end

def find_environment_or_organization
if params[:environment_id]
@environment = KTEnvironment.find_by_id(params[:environment_id])
raise HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil?
fail HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil?
@organization ||= @environment.organization
else
@organization = get_organization params[:organization_id]
raise HttpErrors::NotFound, _("Couldn't find organization '%s'") % params[:organization_id] if @organization.nil?
fail HttpErrors::NotFound, _("Couldn't find organization '%s'") % params[:organization_id] if @organization.nil?
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/custom_info_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def find_informable
def find_custom_info
@single_custom_info = CustomInfo.find_by_informable_keyname(@informable, params[:keyname].strip)
if @single_custom_info.nil?
raise HttpErrors::NotFound, _("Couldn't find custom info with keyname '%s'") % params[:keyname]
fail HttpErrors::NotFound, _("Couldn't find custom info with keyname '%s'") % params[:keyname]
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v1/distributions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ def show

def find_repository
@repo = Repository.find(params[:repository_id])
raise HttpErrors::NotFound, _("Couldn't find repository '%s'") % params[:repository_id] if @repo.nil?
fail HttpErrors::NotFound, _("Couldn't find repository '%s'") % params[:repository_id] if @repo.nil?
@repo
end

def check_distribution
raise HttpErrors::NotFound, _("Distribution '%s' not found within the repository") % params[:id] unless @repo.has_distribution? params[:id]
fail HttpErrors::NotFound, _("Distribution '%s' not found within the repository") % params[:id] unless @repo.has_distribution? params[:id]
end

end
16 changes: 8 additions & 8 deletions app/controllers/api/v1/distributors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def task_show
def find_only_environment
if !@environment && @organization && !params.key?(:environment_id)
if @organization.environments.empty?
raise HttpErrors::BadRequest, _("Organization %{org} has the '%{env}' environment only. Please create an environment for distributor registration.") %
fail HttpErrors::BadRequest, _("Organization %{org} has the '%{env}' environment only. Please create an environment for distributor registration.") %
{ :org => @organization.name, :env => "Library" }
end

Expand All @@ -264,7 +264,7 @@ def find_only_environment
if current_user.default_environment && current_user.default_environment.organization == @organization
@environment = current_user.default_environment
else
raise HttpErrors::BadRequest, _("Organization %s has more than one environment. Please specify target environment for distributor registration.") % @organization.name
fail HttpErrors::BadRequest, _("Organization %s has more than one environment. Please specify target environment for distributor registration.") % @organization.name
end
else
if @environment = @organization.environments.first
Expand All @@ -282,7 +282,7 @@ def find_environment
return unless params.key?(:environment_id)

@environment = KTEnvironment.find(params[:environment_id])
raise HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil?
fail HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil?
@organization = @environment.organization
@environment
end
Expand All @@ -297,15 +297,15 @@ def verify_presence_of_organization_or_environment
if @environment
@organization = @environment.organization
else
raise HttpErrors::NotFound, _("You have not set a default organization and environment on the user %s.") % current_user.username
fail HttpErrors::NotFound, _("You have not set a default organization and environment on the user %s.") % current_user.username
end
end

def find_distributor
@distributor = Distributor.first(:conditions => { :uuid => params[:id] })
if @distributor.nil?
Resources::Candlepin::Consumer.get params[:id] # check with candlepin if distributor is Gone, raises RestClient::Gone
raise HttpErrors::NotFound, _("Couldn't find distributor '%s'") % params[:id]
fail HttpErrors::NotFound, _("Couldn't find distributor '%s'") % params[:id]
end
@distributor
end
Expand All @@ -315,21 +315,21 @@ def find_activation_keys
ak_names = ak_names.split(",")
activation_keys = ak_names.map do |ak_name|
activation_key = @organization.activation_keys.find_by_name(ak_name)
raise HttpErrors::NotFound, _("Couldn't find activation key '%s'") % ak_name unless activation_key
fail HttpErrors::NotFound, _("Couldn't find activation key '%s'") % ak_name unless activation_key
activation_key
end
else
activation_keys = []
end
if activation_keys.empty?
raise HttpErrors::BadRequest, _("At least one activation key must be provided")
fail HttpErrors::BadRequest, _("At least one activation key must be provided")
end
activation_keys
end

def find_task
@task = TaskStatus.where(:uuid => params[:id]).first
raise ActiveRecord::RecordNotFound.new unless @task
fail ActiveRecord::RecordNotFound.new unless @task
@distributor = @task.task_owner
end

Expand Down
8 changes: 4 additions & 4 deletions app/controllers/api/v1/environments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def create
environment_params[:label] = labelize_params(environment_params)
@environment = KTEnvironment.new(environment_params)
@organization.environments << @environment
raise ActiveRecord::RecordInvalid.new(@environment) unless @environment.valid?
fail ActiveRecord::RecordInvalid.new(@environment) unless @environment.valid?
@organization.save!
respond
end
Expand All @@ -159,7 +159,7 @@ def create
api :PUT, "/organizations/:organization_id/environments/:id", "Update an environment in an organization"
param_group :environment
def update
raise HttpErrors::BadRequest, _("Can't update the '%s' environment") % "Library" if @environment.library?
fail HttpErrors::BadRequest, _("Can't update the '%s' environment") % "Library" if @environment.library?
@environment.update_attributes!(params[:environment])
respond
end
Expand All @@ -173,7 +173,7 @@ def destroy
@environment.destroy
respond :message => _("Deleted environment '%s'") % params[:id]
else
raise HttpErrors::BadRequest,
fail HttpErrors::BadRequest,
_("Environment %s has a successor. Only the last environment on a path can be deleted.") % @environment.name
end
end
Expand All @@ -197,7 +197,7 @@ def releases

def find_environment
@environment = KTEnvironment.find(params[:id])
raise HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:id] if @environment.nil?
fail HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:id] if @environment.nil?
@organization = @environment.organization
@environment
end
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/api/v1/errata_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def rules
def index
filter = params.symbolize_keys.slice(:repoid, :repository_id, :product_id, :environment_id, :type, :severity)
unless filter[:repoid] || filter[:repository_id] || filter[:environment_id]
raise HttpErrors::BadRequest.new(_("Repo ID or environment must be provided"))
fail HttpErrors::BadRequest.new(_("Repo ID or environment must be provided"))
end
render :json => Errata.filter(filter)
end
Expand All @@ -61,10 +61,10 @@ def show
def find_environment
if params.key?(:environment_id)
@environment = KTEnvironment.find(params[:environment_id])
raise HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil?
fail HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil?
elsif params.key?(:repoid)
@repo = Repository.find(params[:repoid])
raise HttpErrors::NotFound, _("Couldn't find repository '%s'") % params[:repoid] if @repo.nil?
fail HttpErrors::NotFound, _("Couldn't find repository '%s'") % params[:repoid] if @repo.nil?
@environment = @repo.environment
end
@environment
Expand All @@ -73,17 +73,17 @@ def find_environment
def find_repository
if params.key?(:repository_id)
@repo = Repository.find(params[:repository_id])
raise HttpErrors::NotFound, _("Couldn't find repository '%s'") % params[:repository_id] if @repo.nil?
fail HttpErrors::NotFound, _("Couldn't find repository '%s'") % params[:repository_id] if @repo.nil?
@environment ||= @repo.environment
end
@repo
end

def find_erratum
@erratum = Errata.find_by_errata_id(params[:id])
raise HttpErrors::NotFound, _("Erratum with id '%s' not found") % params[:id] if @erratum.nil?
fail HttpErrors::NotFound, _("Erratum with id '%s' not found") % params[:id] if @erratum.nil?
# and check ownership of it
raise HttpErrors::NotFound, _("Erratum '%s' not found within the repository") % params[:id] unless @erratum.repoids.include? @repo.pulp_id
fail HttpErrors::NotFound, _("Erratum '%s' not found within the repository") % params[:id] unless @erratum.repoids.include? @repo.pulp_id
@erratum
end
end
4 changes: 2 additions & 2 deletions app/controllers/api/v1/filter_rules_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ def find_definition
def find_filter
id = params[:filter_id]
@filter = Filter.where(:id => id, :content_view_definition_id => @definition).first
raise HttpErrors::NotFound, _("Couldn't find filter '%s'") % params[:id] if @filter.nil?
fail HttpErrors::NotFound, _("Couldn't find filter '%s'") % params[:id] if @filter.nil?
@filter
end

def find_filter_rule
id = params[:id]
@filter_rule = FilterRule.where(:filter_id => @filter.id, :id => id).first
raise HttpErrors::NotFound, _("Couldn't find filter rule '%s'") % params[:id] if @filter_rule.nil?
fail HttpErrors::NotFound, _("Couldn't find filter rule '%s'") % params[:id] if @filter_rule.nil?
@filter_rule
end

Expand Down
Loading

0 comments on commit aa05b86

Please sign in to comment.