From 0478ec0a4da77c03e12e69b7c010f9f91a450f13 Mon Sep 17 00:00:00 2001 From: David Singleton Date: Fri, 26 Feb 2016 12:30:11 +0000 Subject: [PATCH] Fix basic ruby violations --- Gemfile | 4 ++-- app/controllers/application_controller.rb | 2 +- app/controllers/components_controller.rb | 1 - app/controllers/fixtures_controller.rb | 9 ++++----- app/models/component.rb | 4 ++-- bin/rails | 2 +- config.ru | 2 +- config/environments/test.rb | 2 +- config/initializers/cookies_serializer.rb | 2 +- config/routes.rb | 1 - test/controllers/about_controller_test.rb | 1 - test/controllers/components_controller_test.rb | 1 - test/controllers/fixtures_controller_test.rb | 3 +-- test/controllers/welcome_controller_test.rb | 1 - 14 files changed, 14 insertions(+), 21 deletions(-) diff --git a/Gemfile b/Gemfile index 4e4406d..4809b40 100644 --- a/Gemfile +++ b/Gemfile @@ -12,12 +12,12 @@ gem 'uglifier', '>= 1.3.0' gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. -gem 'sdoc', '~> 0.4.0', group: :doc +gem 'sdoc', '~> 0.4.0', group: :doc gem 'kramdown', '1.5' if ENV['SLIMMER_DEV'] - gem 'slimmer', :path => '../slimmer' + gem 'slimmer', path: '../slimmer' else gem 'slimmer', '9.1.0' end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b129feb..986469c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -7,8 +7,8 @@ class ApplicationController < ActionController::Base before_filter :set_custom_slimmer_headers - private + def set_custom_slimmer_headers set_slimmer_headers(report_a_problem: 'false') end diff --git a/app/controllers/components_controller.rb b/app/controllers/components_controller.rb index caa6db9..fa82763 100644 --- a/app/controllers/components_controller.rb +++ b/app/controllers/components_controller.rb @@ -1,7 +1,6 @@ require 'component' class ComponentsController < ApplicationController - def show @component = Component.get(params[:id]) end diff --git a/app/controllers/fixtures_controller.rb b/app/controllers/fixtures_controller.rb index ac9bbd2..8ad2596 100644 --- a/app/controllers/fixtures_controller.rb +++ b/app/controllers/fixtures_controller.rb @@ -1,11 +1,10 @@ require 'component' class FixturesController < ApplicationController - def show - @fixture = component.fixtures.select {|f| + @fixture = component.fixtures.find {|f| f.id == params[:id] - }.first + } end def index @@ -13,9 +12,9 @@ def index end def preview - @fixture = component.fixtures.select {|f| + @fixture = component.fixtures.find {|f| f.id == params[:fixture_id] - }.first + } render layout: 'preview' end diff --git a/app/models/component.rb b/app/models/component.rb index 565d5d3..7d2518d 100644 --- a/app/models/component.rb +++ b/app/models/component.rb @@ -1,6 +1,6 @@ Component = Struct.new(:id, :name, :description, :body, :fixtures) do def self.get(id) - all.select { |component| component.id == id }.first + all.find { |component| component.id == id } end def self.all @@ -28,7 +28,7 @@ def self.fetch_component_doc begin JSON.parse( RestClient.get(component_doc_url).body, - {symbolize_names: true} + symbolize_names: true ) rescue RestClient::BadGateway => e raise "#{e} from #{Plek.current.find('static')} - is static running?" diff --git a/bin/rails b/bin/rails index 7feb6a3..4d608ed 100755 --- a/bin/rails +++ b/bin/rails @@ -3,6 +3,6 @@ begin load File.expand_path("../spring", __FILE__) rescue LoadError end -APP_PATH = File.expand_path('../../config/application', __FILE__) +APP_PATH = File.expand_path('../../config/application', __FILE__) require_relative '../config/boot' require 'rails/commands' diff --git a/config.ru b/config.ru index 5bc2a61..bd83b25 100644 --- a/config.ru +++ b/config.ru @@ -1,4 +1,4 @@ # This file is used by Rack-based servers to start the application. -require ::File.expand_path('../config/environment', __FILE__) +require ::File.expand_path('../config/environment', __FILE__) run Rails.application diff --git a/config/environments/test.rb b/config/environments/test.rb index 70c5193..b3ffacd 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -13,7 +13,7 @@ config.eager_load = false # Configure static asset server for tests with Cache-Control for performance. - config.serve_static_files = true + config.serve_static_files = true config.static_cache_control = 'public, max-age=3600' # Show full error reports and disable caching. diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb index 7a06a89..7f70458 100644 --- a/config/initializers/cookies_serializer.rb +++ b/config/initializers/cookies_serializer.rb @@ -1,3 +1,3 @@ # Be sure to restart your server when you modify this file. -Rails.application.config.action_dispatch.cookies_serializer = :json \ No newline at end of file +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/config/routes.rb b/config/routes.rb index 342d079..bf95ea5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,4 @@ Rails.application.routes.draw do - get 'about' => 'about#index' resources :components, only: [:index, :show] do diff --git a/test/controllers/about_controller_test.rb b/test/controllers/about_controller_test.rb index 78a4985..634130d 100644 --- a/test/controllers/about_controller_test.rb +++ b/test/controllers/about_controller_test.rb @@ -5,5 +5,4 @@ class AboutControllerTest < ActionController::TestCase get :index assert_response :success end - end diff --git a/test/controllers/components_controller_test.rb b/test/controllers/components_controller_test.rb index 7d44a19..71b0ae4 100644 --- a/test/controllers/components_controller_test.rb +++ b/test/controllers/components_controller_test.rb @@ -10,5 +10,4 @@ class ComponentsControllerTest < ActionController::TestCase get :show, id: 'title' assert_response :success end - end diff --git a/test/controllers/fixtures_controller_test.rb b/test/controllers/fixtures_controller_test.rb index da10970..c940f5b 100644 --- a/test/controllers/fixtures_controller_test.rb +++ b/test/controllers/fixtures_controller_test.rb @@ -7,8 +7,7 @@ class FixturesControllerTest < ActionController::TestCase end test "should get show" do - get :show, {component_id: 'title', id: 'default'} + get :show, component_id: 'title', id: 'default' assert_response :success end - end diff --git a/test/controllers/welcome_controller_test.rb b/test/controllers/welcome_controller_test.rb index dff8e9d..e4d5aba 100644 --- a/test/controllers/welcome_controller_test.rb +++ b/test/controllers/welcome_controller_test.rb @@ -5,5 +5,4 @@ class WelcomeControllerTest < ActionController::TestCase get :index assert_response :success end - end