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

Style updates #67

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions .hound.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ruby:
config_file: .rubocop.yml
11 changes: 11 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
inherit_from: .rubocop_todo.yml

AllCops:
Exclude:
- 'db/schema.rb'
DisplayCopNames: true
ExtraDetails: true
TargetRubyVersion: 2.3

Style/FrozenStringLiteralComment:
Enabled: false
26 changes: 26 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-06-20 19:08:22 -0400 using RuboCop version 0.40.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
Metrics/AbcSize:
Max: 16

# Offense count: 102
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
# URISchemes: http, https
Metrics/LineLength:
Max: 184

# Offense count: 2
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 17

# Offense count: 17
Style/Documentation:
Enabled: false
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ gem 'jbuilder', '~> 2.0'
gem 'rollbar'
gem 'pry'
gem 'aws-sdk', '~> 2.3'
gem 'paperclip', :git=> 'https://github.com/thoughtbot/paperclip', :ref => '523bd46c768226893f23889079a7aa9c73b57d68'
gem 'paperclip', git: 'https://github.com/thoughtbot/paperclip', ref: '523bd46c768226893f23889079a7aa9c73b57d68'
gem 'dotenv-rails'
gem 'gmaps4rails'

Expand Down
8 changes: 4 additions & 4 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ class ApplicationController < ActionController::Base
protect_from_forgery with: :exception, prepend: true
before_action :configure_permitted_parameters, if: :devise_controller?

rescue_from CanCan::AccessDenied do |exception|
respond_to do |format|
format.html { redirect_to root_path, :alert => "Unauthorized"}
end
rescue_from CanCan::AccessDenied do |_exception|
respond_to do |format|
format.html { redirect_to root_path, alert: 'Unauthorized' }
end
end
before_action :configure_permitted_parameters, if: :devise_controller?

protected
Expand Down
25 changes: 13 additions & 12 deletions app/controllers/observations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,21 @@ def destroy

def gmaps_hash
@hash = Gmaps4rails.build_markers(@observations) do |observation, marker|
marker.lat observation.latitude
marker.lng observation.longitude
marker.infowindow observation.location
end
marker.lat observation.latitude
marker.lng observation.longitude
marker.infowindow observation.location
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_observation
@observation = Observation.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def observation_params
params.require(:observation).permit(:sighted_at, :location, :latitude, :longitude, :num_bands, :photo)
end
# Use callbacks to share common setup or constraints between actions.
def set_observation
@observation = Observation.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def observation_params
params.require(:observation).permit(:sighted_at, :location, :latitude, :longitude, :num_bands, :photo)
end
end
21 changes: 12 additions & 9 deletions app/controllers/users/invitations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
class Users::InvitationsController < Devise::InvitationsController
before_action :configure_permitted_parameters, if: :devise_controller?
before_action :check_authorization
module Users
class InvitationsController < Devise::InvitationsController
before_action :configure_permitted_parameters, if: :devise_controller?
before_action :check_authorization

private
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:invite, keys: [:role])
end
private

def configure_permitted_parameters
devise_parameter_sanitizer.permit(:invite, keys: [:role])
end

def check_authorization
can? :invite, User
def check_authorization
can? :invite, User
end
end
end
5 changes: 2 additions & 3 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
class UsersController < ApplicationController
load_and_authorize_resource


def index
@title = 'All Users'
@users = User.all
end

def guests
@title = 'Pending Approval'
@users = User.where("role" => "guest")
@users = User.where('role' => 'guest')
render 'index'
end

Expand All @@ -25,10 +24,10 @@ def edit
def update
@user = User.find(params[:id])
redirect_to users_path, alert: 'Success!' if @user.update_attributes(user_params)

end

private

def user_params
params.require(:user).permit(:email, :name, :phone, :role)
end
Expand Down
4 changes: 1 addition & 3 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ class Ability

def initialize(user)
user ||= User.new
if user.is_admin?
can :manage, :all
end
can :manage, :all if user.admin?
end
end
2 changes: 1 addition & 1 deletion app/models/observation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class Observation < ApplicationRecord
medium: '300x300>'
}

validates_attachment_content_type :photo, :content_type => /\Aimage\/.*\Z/
validates_attachment_content_type :photo, content_type: %r{\Aimage/.*\Z}
end
14 changes: 7 additions & 7 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ class User < ApplicationRecord
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :invitable, :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
ROLES = ['admin', 'researcher', 'scientist']
ROLES = %w(admin researcher scientist).freeze

def is_admin?
self.role == "admin"
def admin?
role == 'admin'
end

def is_researcher?
self.role == "researcher"
def researcher?
role == 'researcher'
end

def is_scientist?
self.role == "scientist"
def scientist?
role == 'scientist'
end
end
18 changes: 9 additions & 9 deletions config/application.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require_relative 'boot'

require "rails"
require 'rails'
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"
require 'active_model/railtie'
require 'active_job/railtie'
require 'active_record/railtie'
require 'action_controller/railtie'
require 'action_mailer/railtie'
require 'action_view/railtie'
require 'action_cable/engine'
require 'sprockets/railtie'
# require "rails/test_unit/railtie"

# Require the gems listed in Gemfile, including any gems
Expand Down
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
bucket: ENV.fetch('S3_BUCKET_NAME'),
access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
s3_region: ENV.fetch('AWS_REGION'),
s3_region: ENV.fetch('AWS_REGION')
}
}
end
6 changes: 3 additions & 3 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
config.log_level = :debug

# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]
config.log_tags = [:request_id]

# Use a different cache store in production.
# config.cache_store = :mem_cache_store
Expand Down Expand Up @@ -91,7 +91,7 @@
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

if ENV["RAILS_LOG_TO_STDOUT"].present?
if ENV['RAILS_LOG_TO_STDOUT'].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
Expand All @@ -106,7 +106,7 @@
bucket: ENV.fetch('S3_BUCKET_NAME'),
access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
s3_region: ENV.fetch('AWS_REGION'),
s3_region: ENV.fetch('AWS_REGION')
}
}
end
2 changes: 1 addition & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
bucket: ENV.fetch('S3_BUCKET_NAME'),
access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
s3_region: ENV.fetch('AWS_REGION'),
s3_region: ENV.fetch('AWS_REGION')
}
}
end
4 changes: 1 addition & 3 deletions config/initializers/rollbar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
config.access_token = ENV['ROLLBAR_ACCESS_TOKEN']

# Here we'll disable in 'test':
if Rails.env.test?
config.enabled = false
end
config.enabled = false if Rails.env.test?

# By default, Rollbar will try to call the `current_user` controller method
# to fetch the logged-in user object, and then call that object's `id`,
Expand Down
6 changes: 3 additions & 3 deletions config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum, this matches the default thread size of Active Record.
#
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }.to_i
threads threads_count, threads_count

# Specifies the `port` that Puma will listen on to receive requests, default is 3000.
#
port ENV.fetch("PORT") { 3000 }
port ENV.fetch('PORT') { 3000 }

# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }
environment ENV.fetch('RAILS_ENV') { 'development' }

# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked webserver processes. If using threads and workers together
Expand Down
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Rails.application.routes.draw do
root 'welcome#index'
resources :observations
devise_for :users, :controllers => { :invitations => 'users/invitations' }
scope "/admin" do
devise_for :users, controllers: { invitations: 'users/invitations' }
scope '/admin' do
resources :users
get 'guests', to: 'users#guests'
end
Expand Down
9 changes: 4 additions & 5 deletions db/migrate/20160617174555_devise_create_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ class DeviseCreateUsers < ActiveRecord::Migration[5.0]
def change
create_table :users do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
t.string :name, null: false, default: ""
t.string :phone, null: false, default: ""
t.string :email, null: false, default: ''
t.string :encrypted_password, null: false, default: ''
t.string :name, null: false, default: ''
t.string :phone, null: false, default: ''

## Recoverable
t.string :reset_password_token
Expand All @@ -32,7 +32,6 @@ def change
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at


t.timestamps null: false
end

Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20160617180935_create_observations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class CreateObservations < ActiveRecord::Migration[5.0]
def change
create_table :observations do |t|
t.datetime :sighted_at
t.string :location, {precision: 10, scale: 6}
t.decimal :latitude, {precision: 10, scale: 6}
t.string :location, precision: 10, scale: 6
t.decimal :latitude, precision: 10, scale: 6
t.decimal :longitude
t.integer :num_bands

Expand Down
8 changes: 4 additions & 4 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
puts "Adding a Whole bunch of Observations"
puts 'Adding a Whole bunch of Observations'

Observation.all.each {|o| o.delete}
Observation.all.each(&:delete)

Observation.create(sighted_at: DateTime.now, location: "Burke Lake Park, Fairfax Station, VA", latitude: 38, longitude: -77, num_bands: 1)
Observation.create(sighted_at: DateTime.now, location: "someplace cool", latitude: 37, longitude: -78, num_bands: 1)
Observation.create(sighted_at: DateTime.now, location: 'Burke Lake Park, Fairfax Station, VA', latitude: 38, longitude: -77, num_bands: 1)
Observation.create(sighted_at: DateTime.now, location: 'someplace cool', latitude: 37, longitude: -78, num_bands: 1)
Loading