From ac4e7842df5d5fef98354145e226f8a861a3e934 Mon Sep 17 00:00:00 2001 From: Josh Langholtz Date: Mon, 20 Jun 2016 18:30:21 -0400 Subject: [PATCH 1/5] Initial rubocop set-up --- .rubocop.yml | 4 + .rubocop_todo.yml | 304 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 308 insertions(+) create mode 100644 .rubocop.yml create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..c98d207 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,4 @@ +AllCops: + DisplayCopNames: true + ExtraDetails: true + TargetRubyVersion: 2.3 diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..f4de04a --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,304 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2016-06-20 18:21:19 -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: 3 +# Cop supports --auto-correct. +# Configuration parameters: AlignWith, SupportedStyles. +# SupportedStyles: either, start_of_block, start_of_line +Lint/BlockAlignment: + Exclude: + - 'app/controllers/application_controller.rb' + - 'spec/controllers/observations_controller_spec.rb' + +# Offense count: 2 +Lint/ParenthesesAsGroupedExpression: + Exclude: + - 'spec/controllers/invitations_controller_spec.rb' + - 'spec/controllers/observations_controller_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowUnusedKeywordArguments. +Lint/UnusedBlockArgument: + Exclude: + - 'app/controllers/application_controller.rb' + +# Offense count: 1 +Lint/UselessAssignment: + Exclude: + - 'spec/controllers/observations_controller_spec.rb' + +# Offense count: 1 +Metrics/AbcSize: + Max: 16 + +# Offense count: 110 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes. +# URISchemes: http, https +Metrics/LineLength: + Max: 180 + +# Offense count: 2 +# Configuration parameters: CountComments. +Metrics/MethodLength: + Max: 17 + +# Offense count: 1 +# Cop supports --auto-correct. +Style/BlockComments: + Exclude: + - 'spec/spec_helper.rb' + +# Offense count: 16 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods. +# SupportedStyles: line_count_based, semantic, braces_for_chaining +# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object +# FunctionalMethods: let, let!, subject, watch +# IgnoredMethods: lambda, proc, it +Style/BlockDelimiters: + Exclude: + - 'spec/controllers/invitations_controller_spec.rb' + - 'spec/controllers/observations_controller_spec.rb' + - 'spec/controllers/users_controller_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: braces, no_braces, context_dependent +Style/BracesAroundHashParameters: + Exclude: + - 'db/migrate/20160617180935_create_observations.rb' + +# Offense count: 1 +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: nested, compact +Style/ClassAndModuleChildren: + Exclude: + - 'app/controllers/users/invitations_controller.rb' + +# Offense count: 17 +Style/Documentation: + Enabled: false + +# Offense count: 3 +# Cop supports --auto-correct. +Style/EmptyLines: + Exclude: + - 'app/controllers/users_controller.rb' + - 'db/migrate/20160617174555_devise_create_users.rb' + - 'spec/views/observations/edit.html.erb_spec.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Style/EmptyLinesAroundAccessModifier: + Exclude: + - 'app/controllers/observations_controller.rb' + - 'app/controllers/users/invitations_controller.rb' + - 'app/controllers/users_controller.rb' + +# Offense count: 13 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: empty_lines, no_empty_lines +Style/EmptyLinesAroundBlockBody: + Exclude: + - 'db/schema.rb' + - 'spec/controllers/invitations_controller_spec.rb' + - 'spec/controllers/observations_controller_spec.rb' + - 'spec/controllers/users_controller_spec.rb' + - 'spec/controllers/welcome_controller_spec.rb' + - 'spec/models/user_spec.rb' + - 'spec/routing/observations_routing_spec.rb' + - 'spec/views/observations/edit.html.erb_spec.rb' + - 'spec/views/observations/new.html.erb_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/EmptyLinesAroundMethodBody: + Exclude: + - 'app/controllers/users_controller.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. +Style/ExtraSpacing: + Exclude: + - 'db/schema.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. +# SupportedStyles: consistent, special_for_inner_method_call, special_for_inner_method_call_in_parentheses +Style/FirstParameterIndentation: + Exclude: + - 'spec/views/observations/edit.html.erb_spec.rb' + - 'spec/views/observations/new.html.erb_spec.rb' + - 'spec/views/observations/show.html.erb_spec.rb' + +# Offense count: 1 +# Configuration parameters: MinBodyLength. +Style/GuardClause: + Exclude: + - 'app/models/ability.rb' + +# Offense count: 53 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues. +# SupportedStyles: ruby19, ruby19_no_mixed_keys, hash_rockets +Style/HashSyntax: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: MaxLineLength. +Style/IfUnlessModifier: + Exclude: + - 'app/models/ability.rb' + - 'config/initializers/rollbar.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: SupportedStyles, IndentationWidth. +# SupportedStyles: special_inside_parentheses, consistent, align_brackets +Style/IndentArray: + EnforcedStyle: consistent + +# Offense count: 26 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: normal, rails +Style/IndentationConsistency: + Exclude: + - 'app/controllers/observations_controller.rb' + - 'spec/controllers/observations_controller_spec.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: Width. +Style/IndentationWidth: + Exclude: + - 'app/controllers/observations_controller.rb' + - 'spec/controllers/observations_controller_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/MutableConstant: + Exclude: + - 'app/models/user.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/NumericLiterals: + MinDigits: 15 + +# Offense count: 3 +# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist. +# NamePrefix: is_, has_, have_ +# NamePrefixBlacklist: is_, has_, have_ +# NameWhitelist: is_a? +Style/PredicateName: + Exclude: + - 'spec/**/*' + - 'app/models/user.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Style/RedundantSelf: + Exclude: + - 'app/models/user.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. +# SupportedStyles: slashes, percent_r, mixed +Style/RegexpLiteral: + Exclude: + - 'app/models/observation.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/SpaceAfterColon: + Exclude: + - 'spec/controllers/observations_controller_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment. +Style/SpaceAroundOperators: + Exclude: + - 'Gemfile' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. +# SupportedStyles: space, no_space +Style/SpaceInsideBlockBraces: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +Style/SpaceInsideBrackets: + Exclude: + - 'config/environments/production.rb' + +# Offense count: 36 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles. +# SupportedStyles: space, no_space +Style/SpaceInsideHashLiteralBraces: + Enabled: false + +# Offense count: 257 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiterals: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: IgnoredMethods. +# IgnoredMethods: respond_to, define_method +Style/SymbolProc: + Exclude: + - 'db/seeds.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: final_newline, final_blank_line +Style/TrailingBlankLines: + Exclude: + - 'db/seeds.rb' + - 'spec/views/observations/show.html.erb_spec.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles. +# SupportedStyles: comma, consistent_comma, no_comma +Style/TrailingCommaInLiteral: + Exclude: + - 'config/environments/development.rb' + - 'config/environments/production.rb' + - 'config/environments/test.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/TrailingWhitespace: + Exclude: + - 'app/controllers/observations_controller.rb' + - 'spec/models/observation_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: SupportedStyles, WordRegex. +# SupportedStyles: percent, brackets +Style/WordArray: + EnforcedStyle: percent + MinSize: -Infinity From 5a51251ec0615d2f95db385dcefd5cca7d828c6d Mon Sep 17 00:00:00 2001 From: Josh Langholtz Date: Mon, 20 Jun 2016 18:50:47 -0400 Subject: [PATCH 2/5] Autocorrect rubocop violations --- .rubocop.yml | 5 + .rubocop_todo.yml | 248 +----------------- Gemfile | 2 +- app/controllers/application_controller.rb | 8 +- app/controllers/observations_controller.rb | 25 +- .../users/invitations_controller.rb | 1 + app/controllers/users_controller.rb | 5 +- app/models/ability.rb | 4 +- app/models/observation.rb | 2 +- app/models/user.rb | 8 +- config/application.rb | 18 +- config/environments/development.rb | 2 +- config/environments/production.rb | 6 +- config/environments/test.rb | 2 +- config/initializers/rollbar.rb | 4 +- config/puma.rb | 6 +- config/routes.rb | 4 +- .../20160617174555_devise_create_users.rb | 9 +- .../20160617180935_create_observations.rb | 4 +- db/seeds.rb | 8 +- .../invitations_controller_spec.rb | 33 ++- .../observations_controller_spec.rb | 168 ++++++------ spec/controllers/users_controller_spec.rb | 54 ++-- spec/controllers/welcome_controller_spec.rb | 1 - spec/models/ability_spec.rb | 6 +- spec/models/observation_spec.rb | 13 +- spec/models/user_spec.rb | 26 +- spec/rails_helper.rb | 4 +- spec/requests/observations_spec.rb | 12 +- spec/routing/observations_routing_spec.rb | 38 ++- spec/spec_helper.rb | 96 ++++--- spec/views/observations/edit.html.erb_spec.rb | 24 +- .../views/observations/index.html.erb_spec.rb | 44 ++-- spec/views/observations/new.html.erb_spec.rb | 23 +- spec/views/observations/show.html.erb_spec.rb | 13 +- 35 files changed, 334 insertions(+), 592 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index c98d207..288dbb0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,9 @@ AllCops: + Exclude: + - 'db/schema.rb' DisplayCopNames: true ExtraDetails: true TargetRubyVersion: 2.3 + +Style/FrozenStringLiteralComment: + Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f4de04a..f23b051 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,33 +1,17 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2016-06-20 18:21:19 -0400 using RuboCop version 0.40.0. +# on 2016-06-20 18:52:30 -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: 3 -# Cop supports --auto-correct. -# Configuration parameters: AlignWith, SupportedStyles. -# SupportedStyles: either, start_of_block, start_of_line -Lint/BlockAlignment: - Exclude: - - 'app/controllers/application_controller.rb' - - 'spec/controllers/observations_controller_spec.rb' - # Offense count: 2 Lint/ParenthesesAsGroupedExpression: Exclude: - 'spec/controllers/invitations_controller_spec.rb' - 'spec/controllers/observations_controller_spec.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowUnusedKeywordArguments. -Lint/UnusedBlockArgument: - Exclude: - - 'app/controllers/application_controller.rb' - # Offense count: 1 Lint/UselessAssignment: Exclude: @@ -37,44 +21,17 @@ Lint/UselessAssignment: Metrics/AbcSize: Max: 16 -# Offense count: 110 +# Offense count: 102 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes. # URISchemes: http, https Metrics/LineLength: - Max: 180 + Max: 184 # Offense count: 2 # Configuration parameters: CountComments. Metrics/MethodLength: Max: 17 -# Offense count: 1 -# Cop supports --auto-correct. -Style/BlockComments: - Exclude: - - 'spec/spec_helper.rb' - -# Offense count: 16 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods. -# SupportedStyles: line_count_based, semantic, braces_for_chaining -# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object -# FunctionalMethods: let, let!, subject, watch -# IgnoredMethods: lambda, proc, it -Style/BlockDelimiters: - Exclude: - - 'spec/controllers/invitations_controller_spec.rb' - - 'spec/controllers/observations_controller_spec.rb' - - 'spec/controllers/users_controller_spec.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: braces, no_braces, context_dependent -Style/BracesAroundHashParameters: - Exclude: - - 'db/migrate/20160617180935_create_observations.rb' - # Offense count: 1 # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: nested, compact @@ -86,117 +43,6 @@ Style/ClassAndModuleChildren: Style/Documentation: Enabled: false -# Offense count: 3 -# Cop supports --auto-correct. -Style/EmptyLines: - Exclude: - - 'app/controllers/users_controller.rb' - - 'db/migrate/20160617174555_devise_create_users.rb' - - 'spec/views/observations/edit.html.erb_spec.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -Style/EmptyLinesAroundAccessModifier: - Exclude: - - 'app/controllers/observations_controller.rb' - - 'app/controllers/users/invitations_controller.rb' - - 'app/controllers/users_controller.rb' - -# Offense count: 13 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: empty_lines, no_empty_lines -Style/EmptyLinesAroundBlockBody: - Exclude: - - 'db/schema.rb' - - 'spec/controllers/invitations_controller_spec.rb' - - 'spec/controllers/observations_controller_spec.rb' - - 'spec/controllers/users_controller_spec.rb' - - 'spec/controllers/welcome_controller_spec.rb' - - 'spec/models/user_spec.rb' - - 'spec/routing/observations_routing_spec.rb' - - 'spec/views/observations/edit.html.erb_spec.rb' - - 'spec/views/observations/new.html.erb_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/EmptyLinesAroundMethodBody: - Exclude: - - 'app/controllers/users_controller.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. -Style/ExtraSpacing: - Exclude: - - 'db/schema.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. -# SupportedStyles: consistent, special_for_inner_method_call, special_for_inner_method_call_in_parentheses -Style/FirstParameterIndentation: - Exclude: - - 'spec/views/observations/edit.html.erb_spec.rb' - - 'spec/views/observations/new.html.erb_spec.rb' - - 'spec/views/observations/show.html.erb_spec.rb' - -# Offense count: 1 -# Configuration parameters: MinBodyLength. -Style/GuardClause: - Exclude: - - 'app/models/ability.rb' - -# Offense count: 53 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues. -# SupportedStyles: ruby19, ruby19_no_mixed_keys, hash_rockets -Style/HashSyntax: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: MaxLineLength. -Style/IfUnlessModifier: - Exclude: - - 'app/models/ability.rb' - - 'config/initializers/rollbar.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: SupportedStyles, IndentationWidth. -# SupportedStyles: special_inside_parentheses, consistent, align_brackets -Style/IndentArray: - EnforcedStyle: consistent - -# Offense count: 26 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: normal, rails -Style/IndentationConsistency: - Exclude: - - 'app/controllers/observations_controller.rb' - - 'spec/controllers/observations_controller_spec.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: Width. -Style/IndentationWidth: - Exclude: - - 'app/controllers/observations_controller.rb' - - 'spec/controllers/observations_controller_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/MutableConstant: - Exclude: - - 'app/models/user.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/NumericLiterals: - MinDigits: 15 - # Offense count: 3 # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist. # NamePrefix: is_, has_, have_ @@ -207,12 +53,6 @@ Style/PredicateName: - 'spec/**/*' - 'app/models/user.rb' -# Offense count: 3 -# Cop supports --auto-correct. -Style/RedundantSelf: - Exclude: - - 'app/models/user.rb' - # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. @@ -220,85 +60,3 @@ Style/RedundantSelf: Style/RegexpLiteral: Exclude: - 'app/models/observation.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/SpaceAfterColon: - Exclude: - - 'spec/controllers/observations_controller_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment. -Style/SpaceAroundOperators: - Exclude: - - 'Gemfile' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. -# SupportedStyles: space, no_space -Style/SpaceInsideBlockBraces: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -Style/SpaceInsideBrackets: - Exclude: - - 'config/environments/production.rb' - -# Offense count: 36 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles. -# SupportedStyles: space, no_space -Style/SpaceInsideHashLiteralBraces: - Enabled: false - -# Offense count: 257 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline. -# SupportedStyles: single_quotes, double_quotes -Style/StringLiterals: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: IgnoredMethods. -# IgnoredMethods: respond_to, define_method -Style/SymbolProc: - Exclude: - - 'db/seeds.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: final_newline, final_blank_line -Style/TrailingBlankLines: - Exclude: - - 'db/seeds.rb' - - 'spec/views/observations/show.html.erb_spec.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles. -# SupportedStyles: comma, consistent_comma, no_comma -Style/TrailingCommaInLiteral: - Exclude: - - 'config/environments/development.rb' - - 'config/environments/production.rb' - - 'config/environments/test.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/TrailingWhitespace: - Exclude: - - 'app/controllers/observations_controller.rb' - - 'spec/models/observation_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: SupportedStyles, WordRegex. -# SupportedStyles: percent, brackets -Style/WordArray: - EnforcedStyle: percent - MinSize: -Infinity diff --git a/Gemfile b/Gemfile index 449f4c9..a44f3e5 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4c68dc5..b809d60 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/observations_controller.rb b/app/controllers/observations_controller.rb index 77b63e8..e338c81 100644 --- a/app/controllers/observations_controller.rb +++ b/app/controllers/observations_controller.rb @@ -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 diff --git a/app/controllers/users/invitations_controller.rb b/app/controllers/users/invitations_controller.rb index f353d0b..5515ef6 100644 --- a/app/controllers/users/invitations_controller.rb +++ b/app/controllers/users/invitations_controller.rb @@ -3,6 +3,7 @@ class Users::InvitationsController < Devise::InvitationsController before_action :check_authorization private + def configure_permitted_parameters devise_parameter_sanitizer.permit(:invite, keys: [:role]) end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f911462..96ab3ce 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,7 +1,6 @@ class UsersController < ApplicationController load_and_authorize_resource - def index @title = 'All Users' @users = User.all @@ -9,7 +8,7 @@ def index def guests @title = 'Pending Approval' - @users = User.where("role" => "guest") + @users = User.where('role' => 'guest') render 'index' end @@ -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 diff --git a/app/models/ability.rb b/app/models/ability.rb index ce01217..fbc28f7 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -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.is_admin? end end diff --git a/app/models/observation.rb b/app/models/observation.rb index 113d945..19dce3b 100644 --- a/app/models/observation.rb +++ b/app/models/observation.rb @@ -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: /\Aimage\/.*\Z/ end diff --git a/app/models/user.rb b/app/models/user.rb index 9d4c84b..ea36816 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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" + role == 'admin' end def is_researcher? - self.role == "researcher" + role == 'researcher' end def is_scientist? - self.role == "scientist" + role == 'scientist' end end diff --git a/config/application.rb b/config/application.rb index 51afc3e..854b907 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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 diff --git a/config/environments/development.rb b/config/environments/development.rb index 4a6c1dd..c306abc 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -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 diff --git a/config/environments/production.rb b/config/environments/production.rb index ac0c1cc..9f03711 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -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 @@ -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) @@ -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 diff --git a/config/environments/test.rb b/config/environments/test.rb index 9482646..627382d 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -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 diff --git a/config/initializers/rollbar.rb b/config/initializers/rollbar.rb index 6b0265c..a90be5e 100644 --- a/config/initializers/rollbar.rb +++ b/config/initializers/rollbar.rb @@ -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`, diff --git a/config/puma.rb b/config/puma.rb index c7f311f..786af49 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 1a4ff1b..45d71b6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20160617174555_devise_create_users.rb b/db/migrate/20160617174555_devise_create_users.rb index f942b33..bc17255 100644 --- a/db/migrate/20160617174555_devise_create_users.rb +++ b/db/migrate/20160617174555_devise_create_users.rb @@ -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 @@ -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 diff --git a/db/migrate/20160617180935_create_observations.rb b/db/migrate/20160617180935_create_observations.rb index 1b1c37c..e7e960b 100644 --- a/db/migrate/20160617180935_create_observations.rb +++ b/db/migrate/20160617180935_create_observations.rb @@ -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 diff --git a/db/seeds.rb b/db/seeds.rb index 3f03534..3cc094d 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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) \ No newline at end of file +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) diff --git a/spec/controllers/invitations_controller_spec.rb b/spec/controllers/invitations_controller_spec.rb index 45b7a38..78bdf95 100644 --- a/spec/controllers/invitations_controller_spec.rb +++ b/spec/controllers/invitations_controller_spec.rb @@ -1,34 +1,33 @@ require 'rails_helper' RSpec.describe Users::InvitationsController, type: :controller do - describe "GET #new" do - - context "improper authorization" do - it "redirects to login page" do - @request.env["devise.mapping"] = Devise.mappings[:user] + describe 'GET #new' do + context 'improper authorization' do + it 'redirects to login page' do + @request.env['devise.mapping'] = Devise.mappings[:user] get :new expect(response).to redirect_to(new_user_session_path) end end end - context "proper authorization" do - let (:admin_params) { + context 'proper authorization' do + let (:admin_params) do { - email: "admin@gmail.com", - name: "Mr Admin", - role: "admin", - password: "password", - password_confirmation: "password" + email: 'admin@gmail.com', + name: 'Mr Admin', + role: 'admin', + password: 'password', + password_confirmation: 'password' } - } + end - let(:admin) { + let(:admin) do User.create!(admin_params) - } + end - it "loads invitation form" do - @request.env["devise.mapping"] = Devise.mappings[:user] + it 'loads invitation form' do + @request.env['devise.mapping'] = Devise.mappings[:user] sign_in admin get :new expect(response.status).to eq(200) diff --git a/spec/controllers/observations_controller_spec.rb b/spec/controllers/observations_controller_spec.rb index f1223bc..d2f9e7e 100644 --- a/spec/controllers/observations_controller_spec.rb +++ b/spec/controllers/observations_controller_spec.rb @@ -19,21 +19,20 @@ # that an instance is receiving a specific message. RSpec.describe ObservationsController, type: :controller do - # This should return the minimal set of attributes required to create a valid # Observation. As you add validations to Observation, be sure to # adjust the attributes here as well. - let(:valid_attributes) { + let(:valid_attributes) do { - sighted_at:DateTime.new(2016, 5, 10, 10, 30, 0, '-5'), + sighted_at: DateTime.new(2016, 5, 10, 10, 30, 0, '-5'), location: 'Near my moms house', latitude: 38.918167, longitude: -78.194445, num_bands: 1 } - } + end - let(:invalid_attributes) { + let(:invalid_attributes) do { sighted_at: DateTime.new(2016, 5, 10, 10, 30, 0, '-5'), location: 'Near my moms house', @@ -41,96 +40,96 @@ longitude: -78.194445, num_bands: 3 } - } + end - let (:admin_params) { + let (:admin_params) do { - email: "admin@gmail.com", - name: "Mr Admin", - role: "admin", - password: "password", - password_confirmation: "password" + email: 'admin@gmail.com', + name: 'Mr Admin', + role: 'admin', + password: 'password', + password_confirmation: 'password' } - } + end - let(:admin) { + let(:admin) do User.create!(admin_params) - } + end # This should return the minimal set of values that should be in the session # in order to pass any filters (e.g. authentication) defined in # ObservationsController. Be sure to keep this updated too. let(:valid_session) { {} } - describe "GET #index" do - it "assigns all observations as @observations" do - @request.env["devise.mapping"] = Devise.mappings[:user] + describe 'GET #index' do + it 'assigns all observations as @observations' do + @request.env['devise.mapping'] = Devise.mappings[:user] sign_in admin observation = Observation.create! valid_attributes - get :index, params: {}, session: valid_session - expect(assigns(:observations)).to eq(Observation.all) + get :index, params: {}, session: valid_session + expect(assigns(:observations)).to eq(Observation.all) end end - describe "GET #show" do - it "assigns the requested observation as @observation" do + describe 'GET #show' do + it 'assigns the requested observation as @observation' do observation = Observation.create! valid_attributes - get :show, params: {id: observation.to_param}, session: valid_session - expect(assigns(:observation)).to eq(observation) + get :show, params: { id: observation.to_param }, session: valid_session + expect(assigns(:observation)).to eq(observation) end end - describe "GET #new" do - it "assigns a new observation as @observation" do - get :new, params: {}, session: valid_session - expect(assigns(:observation)).to be_a_new(Observation) + describe 'GET #new' do + it 'assigns a new observation as @observation' do + get :new, params: {}, session: valid_session + expect(assigns(:observation)).to be_a_new(Observation) end end - describe "GET #edit" do - it "assigns the requested observation as @observation" do + describe 'GET #edit' do + it 'assigns the requested observation as @observation' do observation = Observation.create! valid_attributes - get :edit, params: {id: observation.to_param}, session: valid_session - expect(assigns(:observation)).to eq(observation) + get :edit, params: { id: observation.to_param }, session: valid_session + expect(assigns(:observation)).to eq(observation) end end - describe "POST #create" do - context "with valid params" do - it "creates a new Observation" do - expect { - post :create, params: {observation: valid_attributes}, session: valid_session - }.to change(Observation, :count).by(1) + describe 'POST #create' do + context 'with valid params' do + it 'creates a new Observation' do + expect do + post :create, params: { observation: valid_attributes }, session: valid_session + end.to change(Observation, :count).by(1) end - it "assigns a newly created observation as @observation" do - post :create, params: {observation: valid_attributes}, session: valid_session - expect(assigns(:observation)).to be_a(Observation) + it 'assigns a newly created observation as @observation' do + post :create, params: { observation: valid_attributes }, session: valid_session + expect(assigns(:observation)).to be_a(Observation) expect(assigns(:observation)).to be_persisted end - it "redirects to the created observation" do - post :create, params: {observation: valid_attributes}, session: valid_session - expect(response).to redirect_to(Observation.last) + it 'redirects to the created observation' do + post :create, params: { observation: valid_attributes }, session: valid_session + expect(response).to redirect_to(Observation.last) end end - context "with invalid params" do - it "assigns a newly created but unsaved observation as @observation" do - post :create, params: {observation: invalid_attributes}, session: valid_session - expect(assigns(:observation)).to be_a_new(Observation) + context 'with invalid params' do + it 'assigns a newly created but unsaved observation as @observation' do + post :create, params: { observation: invalid_attributes }, session: valid_session + expect(assigns(:observation)).to be_a_new(Observation) end it "re-renders the 'new' template" do - post :create, params: {observation: invalid_attributes}, session: valid_session - expect(response).to render_template("new") + post :create, params: { observation: invalid_attributes }, session: valid_session + expect(response).to render_template('new') end end end - describe "PUT #update" do - context "with valid params" do - let(:new_attributes) { + describe 'PUT #update' do + context 'with valid params' do + let(:new_attributes) do { sighted_at: DateTime.new(2016, 5, 10, 10, 30, 0, '-5'), location: 'Near my dads house', @@ -138,9 +137,9 @@ longitude: -78.194445, num_bands: 1 } - } + end - let(:valid_attributes) { + let(:valid_attributes) do { sighted_at: DateTime.new(2016, 5, 10, 10, 30, 0, '-5'), location: 'Near my moms house', @@ -148,62 +147,61 @@ longitude: -78.194445, num_bands: 1 } - } + end let(:valid_session) { {} } - it "updates the requested observation" do + it 'updates the requested observation' do observation = Observation.create! valid_attributes - put :update, params: {id: observation.to_param, observation: new_attributes}, session: valid_session - observation.reload - expect(observation.location).to eql('Near my dads house') - expect(observation.sighted_at.utc.to_i).to eql(DateTime.new(2016, 5, 10, 10, 30, 0, '-5').to_i) - expect(observation.latitude).to eql(38.918167) - expect(observation.longitude).to eql(-78.194445) - expect(observation.num_bands).to eql(1) + put :update, params: { id: observation.to_param, observation: new_attributes }, session: valid_session + observation.reload + expect(observation.location).to eql('Near my dads house') + expect(observation.sighted_at.utc.to_i).to eql(DateTime.new(2016, 5, 10, 10, 30, 0, '-5').to_i) + expect(observation.latitude).to eql(38.918167) + expect(observation.longitude).to eql(-78.194445) + expect(observation.num_bands).to eql(1) end - it "assigns the requested observation as @observation" do + it 'assigns the requested observation as @observation' do observation = Observation.create! valid_attributes - put :update, params: {id: observation.to_param, observation: valid_attributes}, session: valid_session - expect(assigns(:observation)).to eq(observation) + put :update, params: { id: observation.to_param, observation: valid_attributes }, session: valid_session + expect(assigns(:observation)).to eq(observation) end - it "redirects to the observation" do + it 'redirects to the observation' do observation = Observation.create! valid_attributes - put :update, params: {id: observation.to_param, observation: valid_attributes}, session: valid_session - expect(response).to redirect_to(observation) + put :update, params: { id: observation.to_param, observation: valid_attributes }, session: valid_session + expect(response).to redirect_to(observation) end end - context "with invalid params" do - it "assigns the observation as @observation" do + context 'with invalid params' do + it 'assigns the observation as @observation' do observation = Observation.create! valid_attributes - put :update, params: {id: observation.to_param, observation: invalid_attributes}, session: valid_session - expect(assigns(:observation)).to eq(observation) + put :update, params: { id: observation.to_param, observation: invalid_attributes }, session: valid_session + expect(assigns(:observation)).to eq(observation) end it "re-renders the 'edit' template" do observation = Observation.create! valid_attributes - put :update, params: {id: observation.to_param, observation: invalid_attributes}, session: valid_session - expect(response).to render_template("edit") + put :update, params: { id: observation.to_param, observation: invalid_attributes }, session: valid_session + expect(response).to render_template('edit') end end end - describe "DELETE #destroy" do - it "destroys the requested observation" do + describe 'DELETE #destroy' do + it 'destroys the requested observation' do observation = Observation.create! valid_attributes - expect { - delete :destroy, params: {id: observation.to_param}, session: valid_session - }.to change(Observation, :count).by(-1) + expect do + delete :destroy, params: { id: observation.to_param }, session: valid_session + end.to change(Observation, :count).by(-1) end - it "redirects to the observations list" do + it 'redirects to the observations list' do observation = Observation.create! valid_attributes - delete :destroy, params: {id: observation.to_param}, session: valid_session - expect(response).to redirect_to(observations_url) + delete :destroy, params: { id: observation.to_param }, session: valid_session + expect(response).to redirect_to(observations_url) end end - end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 985d8ce..50ce6c8 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -1,53 +1,51 @@ require 'rails_helper' RSpec.describe UsersController, type: :controller do - - describe "Admin users should GET index access" do - let(:admin_params) { + describe 'Admin users should GET index access' do + let(:admin_params) do { - email: "admin@gmail.com", - name: "Mr Admin", - role: "admin", - password: "password", - password_confirmation: "password" + email: 'admin@gmail.com', + name: 'Mr Admin', + role: 'admin', + password: 'password', + password_confirmation: 'password' } - } + end - let(:admin) { + let(:admin) do User.create!(admin_params) - } + end - before { + before do allow(controller).to receive(:current_user).and_return(admin) - } + end - it "admin users have access to user index" do + it 'admin users have access to user index' do get :index, params: {} expect(response.status).to eq(200) end end - describe "NonAdmin users should not GET index access" do - - let(:nonadmin_params) { + describe 'NonAdmin users should not GET index access' do + let(:nonadmin_params) do { - email: "nonadmin@gmail.com", - name: "Mr User", - role: "scientist", - password: "password", - password_confirmation: "password" + email: 'nonadmin@gmail.com', + name: 'Mr User', + role: 'scientist', + password: 'password', + password_confirmation: 'password' } - } + end - let(:nonadmin) { + let(:nonadmin) do User.create!(nonadmin_params) - } + end - before { + before do allow(controller).to receive(:current_user).and_return(nonadmin) - } + end - it "nonadmin users should not have access to user index" do + it 'nonadmin users should not have access to user index' do get :index, params: {} expect(response.status).to eq(302) end diff --git a/spec/controllers/welcome_controller_spec.rb b/spec/controllers/welcome_controller_spec.rb index 332a230..e560f50 100644 --- a/spec/controllers/welcome_controller_spec.rb +++ b/spec/controllers/welcome_controller_spec.rb @@ -1,5 +1,4 @@ require 'rails_helper' RSpec.describe WelcomeController, type: :controller do - end diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index df7b32b..69f7756 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -2,13 +2,13 @@ require 'cancan/matchers' RSpec.describe Ability, type: :model do - it "can manage users when admin" do - user = User.new :role => "admin" + it 'can manage users when admin' do + user = User.new role: 'admin' ability = Ability.new(user) expect(ability).to be_able_to(:manage, User.new) end - it "cannot manage user when not admin" do + it 'cannot manage user when not admin' do user = User.new ability = Ability.new(user) expect(ability).not_to be_able_to(:manage, User.new) diff --git a/spec/models/observation_spec.rb b/spec/models/observation_spec.rb index 06c0c72..a719726 100644 --- a/spec/models/observation_spec.rb +++ b/spec/models/observation_spec.rb @@ -1,10 +1,9 @@ require 'rails_helper' RSpec.describe Observation, type: :model do - - it "can be valid" do + it 'can be valid' do observation = Observation.new( - location: "Location", + location: 'Location', latitude: 10.99, longitude: 11.99, num_bands: 0 @@ -12,9 +11,9 @@ expect(observation).to be_valid end - it "should have num bands greater than 0" do + it 'should have num bands greater than 0' do observation = Observation.new( - location: "Location", + location: 'Location', latitude: 10.99, longitude: 11.99, num_bands: -1 @@ -22,9 +21,9 @@ expect(observation).to_not be_valid end - it "should have num bands less than 3" do + it 'should have num bands less than 3' do observation = Observation.new( - location: "Location", + location: 'Location', latitude: 10.99, longitude: 11.99, num_bands: 3 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 707d039..b514154 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,27 +1,25 @@ require 'rails_helper' RSpec.describe User, type: :model do - - it "can be valid" do + it 'can be valid' do user = User.new( - email: "spacejame@gmail.com", - name: "Michael Jordan", - role: "admin", - password: "password", - password_confirmation: "password" + email: 'spacejame@gmail.com', + name: 'Michael Jordan', + role: 'admin', + password: 'password', + password_confirmation: 'password' ) expect(user).to be_valid end - it "can be an admin" do + it 'can be an admin' do user = User.new( - email: "spacejame@gmail.com", - name: "Michael Jordan", - role: "admin", - password: "password", - password_confirmation: "password" + email: 'spacejame@gmail.com', + name: 'Michael Jordan', + role: 'admin', + password: 'password', + password_confirmation: 'password' ) expect(user.is_admin?).to be(true) end - end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 95d8675..d7ccfa2 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -2,7 +2,7 @@ ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) # Prevent database truncation if the environment is production -abort("The Rails environment is running in production mode!") if Rails.env.production? +abort('The Rails environment is running in production mode!') if Rails.env.production? require 'spec_helper' require 'rspec/rails' # Add additional requires below this line. Rails is not loaded until this point! @@ -29,7 +29,7 @@ RSpec.configure do |config| # configure devise rspec helpers - config.include Devise::TestHelpers, :type => :controller + config.include Devise::TestHelpers, type: :controller # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" diff --git a/spec/requests/observations_spec.rb b/spec/requests/observations_spec.rb index 7e0be64..c85b37c 100644 --- a/spec/requests/observations_spec.rb +++ b/spec/requests/observations_spec.rb @@ -1,16 +1,16 @@ require 'rails_helper' -RSpec.describe "Observations", type: :request do - describe "GET /observations" do - it "can get list" do +RSpec.describe 'Observations', type: :request do + describe 'GET /observations' do + it 'can get list' do get observations_path expect(response).to have_http_status(200) end end - describe "POST /observations" do - it "should create observation" do - post "/observations", params: {observation: {sighted_at: DateTime.new(2016, 5, 10, 10, 30, 0, '-5'), location: "somewhere", latitude: 40.00, longitude: -78.00, num_bands: 1}} + describe 'POST /observations' do + it 'should create observation' do + post '/observations', params: { observation: { sighted_at: DateTime.new(2016, 5, 10, 10, 30, 0, '-5'), location: 'somewhere', latitude: 40.00, longitude: -78.00, num_bands: 1 } } expect(response.code).to eql('302') expect(response).to redirect_to(assigns(:observation)) end diff --git a/spec/routing/observations_routing_spec.rb b/spec/routing/observations_routing_spec.rb index 868aa7d..719899b 100644 --- a/spec/routing/observations_routing_spec.rb +++ b/spec/routing/observations_routing_spec.rb @@ -1,39 +1,37 @@ -require "rails_helper" +require 'rails_helper' RSpec.describe ObservationsController, type: :routing do - describe "routing" do - - it "routes to #index" do - expect(:get => "/observations").to route_to("observations#index") + describe 'routing' do + it 'routes to #index' do + expect(get: '/observations').to route_to('observations#index') end - it "routes to #new" do - expect(:get => "/observations/new").to route_to("observations#new") + it 'routes to #new' do + expect(get: '/observations/new').to route_to('observations#new') end - it "routes to #show" do - expect(:get => "/observations/1").to route_to("observations#show", :id => "1") + it 'routes to #show' do + expect(get: '/observations/1').to route_to('observations#show', id: '1') end - it "routes to #edit" do - expect(:get => "/observations/1/edit").to route_to("observations#edit", :id => "1") + it 'routes to #edit' do + expect(get: '/observations/1/edit').to route_to('observations#edit', id: '1') end - it "routes to #create" do - expect(:post => "/observations").to route_to("observations#create") + it 'routes to #create' do + expect(post: '/observations').to route_to('observations#create') end - it "routes to #update via PUT" do - expect(:put => "/observations/1").to route_to("observations#update", :id => "1") + it 'routes to #update via PUT' do + expect(put: '/observations/1').to route_to('observations#update', id: '1') end - it "routes to #update via PATCH" do - expect(:patch => "/observations/1").to route_to("observations#update", :id => "1") + it 'routes to #update via PATCH' do + expect(patch: '/observations/1').to route_to('observations#update', id: '1') end - it "routes to #destroy" do - expect(:delete => "/observations/1").to route_to("observations#destroy", :id => "1") + it 'routes to #destroy' do + expect(delete: '/observations/1').to route_to('observations#destroy', id: '1') end - end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8f698be..ef76a62 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -47,53 +47,51 @@ # triggering implicit auto-inclusion in groups with matching metadata. config.shared_context_metadata_behavior = :apply_to_host_groups -# The settings below are suggested to provide a good initial experience -# with RSpec, but feel free to customize to your heart's content. -=begin - # This allows you to limit a spec run to individual examples or groups - # you care about by tagging them with `:focus` metadata. When nothing - # is tagged with `:focus`, all examples get run. RSpec also provides - # aliases for `it`, `describe`, and `context` that include `:focus` - # metadata: `fit`, `fdescribe` and `fcontext`, respectively. - config.filter_run_when_matching :focus - - # Allows RSpec to persist some state between runs in order to support - # the `--only-failures` and `--next-failure` CLI options. We recommend - # you configure your source control system to ignore this file. - config.example_status_persistence_file_path = "spec/examples.txt" - - # Limits the available syntax to the non-monkey patched syntax that is - # recommended. For more details, see: - # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ - # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ - # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode - config.disable_monkey_patching! - - # Many RSpec users commonly either run the entire suite or an individual - # file, and it's useful to allow more verbose output when running an - # individual spec file. - if config.files_to_run.one? - # Use the documentation formatter for detailed output, - # unless a formatter has already been configured - # (e.g. via a command-line flag). - config.default_formatter = 'doc' - end - - # Print the 10 slowest examples and example groups at the - # end of the spec run, to help surface which specs are running - # particularly slow. - config.profile_examples = 10 - - # Run specs in random order to surface order dependencies. If you find an - # order dependency and want to debug it, you can fix the order by providing - # the seed, which is printed after each run. - # --seed 1234 - config.order = :random - - # Seed global randomization in this process using the `--seed` CLI option. - # Setting this allows you to use `--seed` to deterministically reproduce - # test failures related to randomization by passing the same `--seed` value - # as the one that triggered the failure. - Kernel.srand config.seed -=end + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + # # This allows you to limit a spec run to individual examples or groups + # # you care about by tagging them with `:focus` metadata. When nothing + # # is tagged with `:focus`, all examples get run. RSpec also provides + # # aliases for `it`, `describe`, and `context` that include `:focus` + # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + # config.filter_run_when_matching :focus + # + # # Allows RSpec to persist some state between runs in order to support + # # the `--only-failures` and `--next-failure` CLI options. We recommend + # # you configure your source control system to ignore this file. + # config.example_status_persistence_file_path = "spec/examples.txt" + # + # # Limits the available syntax to the non-monkey patched syntax that is + # # recommended. For more details, see: + # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + # config.disable_monkey_patching! + # + # # Many RSpec users commonly either run the entire suite or an individual + # # file, and it's useful to allow more verbose output when running an + # # individual spec file. + # if config.files_to_run.one? + # # Use the documentation formatter for detailed output, + # # unless a formatter has already been configured + # # (e.g. via a command-line flag). + # config.default_formatter = 'doc' + # end + # + # # Print the 10 slowest examples and example groups at the + # # end of the spec run, to help surface which specs are running + # # particularly slow. + # config.profile_examples = 10 + # + # # Run specs in random order to surface order dependencies. If you find an + # # order dependency and want to debug it, you can fix the order by providing + # # the seed, which is printed after each run. + # # --seed 1234 + # config.order = :random + # + # # Seed global randomization in this process using the `--seed` CLI option. + # # Setting this allows you to use `--seed` to deterministically reproduce + # # test failures related to randomization by passing the same `--seed` value + # # as the one that triggered the failure. + # Kernel.srand config.seed end diff --git a/spec/views/observations/edit.html.erb_spec.rb b/spec/views/observations/edit.html.erb_spec.rb index bc54392..a4e5ce7 100644 --- a/spec/views/observations/edit.html.erb_spec.rb +++ b/spec/views/observations/edit.html.erb_spec.rb @@ -1,31 +1,29 @@ require 'rails_helper' -RSpec.describe "observations/edit", type: :view do +RSpec.describe 'observations/edit', type: :view do before(:each) do @observation = assign(:observation, Observation.create!( - :location => "MyString", - :latitude => "9.99", - :longitude => "9.99", - :num_bands => 1 + location: 'MyString', + latitude: '9.99', + longitude: '9.99', + num_bands: 1 )) end - it "renders the edit observation form" do + it 'renders the edit observation form' do render - assert_select "form[action=?][method=?]", observation_path(@observation), "post" do + assert_select 'form[action=?][method=?]', observation_path(@observation), 'post' do + assert_select 'input#observation_location[name=?]', 'observation[location]' - assert_select "input#observation_location[name=?]", "observation[location]" + assert_select 'input#observation_latitude[name=?]', 'observation[latitude]' - assert_select "input#observation_latitude[name=?]", "observation[latitude]" + assert_select 'input#observation_longitude[name=?]', 'observation[longitude]' - assert_select "input#observation_longitude[name=?]", "observation[longitude]" - - assert_select "input#observation_num_bands[name=?]", "observation[num_bands]" + assert_select 'input#observation_num_bands[name=?]', 'observation[num_bands]' end end - it 'creates a div due to google maps' do render # TODO: fix this test diff --git a/spec/views/observations/index.html.erb_spec.rb b/spec/views/observations/index.html.erb_spec.rb index 5c7c45a..8480142 100644 --- a/spec/views/observations/index.html.erb_spec.rb +++ b/spec/views/observations/index.html.erb_spec.rb @@ -1,32 +1,32 @@ require 'rails_helper' -RSpec.describe "observations/index", type: :view do +RSpec.describe 'observations/index', type: :view do before(:each) do assign(:observations, [ - Observation.create!( - :location => "Location", - :sighted_at => DateTime.new(2016, 5, 10, 10, 30, 0, '-5'), - :latitude => 10.99, - :longitude => 11.99, - :num_bands => 0 - ), - Observation.create!( - :location => "here", - :sighted_at => DateTime.new(2014, 5, 10, 10, 40, 0, '-5'), - :latitude => 12.99, - :longitude => 13.99, - :num_bands => 1 - ) - ]) + Observation.create!( + location: 'Location', + sighted_at: DateTime.new(2016, 5, 10, 10, 30, 0, '-5'), + latitude: 10.99, + longitude: 11.99, + num_bands: 0 + ), + Observation.create!( + location: 'here', + sighted_at: DateTime.new(2014, 5, 10, 10, 40, 0, '-5'), + latitude: 12.99, + longitude: 13.99, + num_bands: 1 + ) + ]) end - it "renders a list of observations" do + it 'renders a list of observations' do render - assert_select "tr>td.sighted_at_date", :text => "2016-05-10", :count => 1 - assert_select "tr>td.sighted_at_time", :text => "15:30", :count => 1 - assert_select "tr>td.longitude", :text => "11.99".to_s, :count => 1 - assert_select "tr>td.latitude", :text => "10.99".to_s, :count => 1 - assert_select "tr>td.num_bands", :text => "1".to_s, :count => 1 + assert_select 'tr>td.sighted_at_date', text: '2016-05-10', count: 1 + assert_select 'tr>td.sighted_at_time', text: '15:30', count: 1 + assert_select 'tr>td.longitude', text: '11.99'.to_s, count: 1 + assert_select 'tr>td.latitude', text: '10.99'.to_s, count: 1 + assert_select 'tr>td.num_bands', text: '1'.to_s, count: 1 end it 'creates a div due to google maps' do diff --git a/spec/views/observations/new.html.erb_spec.rb b/spec/views/observations/new.html.erb_spec.rb index ebbf044..a0644c8 100644 --- a/spec/views/observations/new.html.erb_spec.rb +++ b/spec/views/observations/new.html.erb_spec.rb @@ -1,27 +1,26 @@ require 'rails_helper' -RSpec.describe "observations/new", type: :view do +RSpec.describe 'observations/new', type: :view do before(:each) do assign(:observation, Observation.new( - :location => "MyString", - :latitude => "9.99", - :longitude => "9.99", - :num_bands => 1 + location: 'MyString', + latitude: '9.99', + longitude: '9.99', + num_bands: 1 )) end - it "renders new observation form" do + it 'renders new observation form' do render - assert_select "form[action=?][method=?]", observations_path, "post" do + assert_select 'form[action=?][method=?]', observations_path, 'post' do + assert_select 'input#observation_location[name=?]', 'observation[location]' - assert_select "input#observation_location[name=?]", "observation[location]" + assert_select 'input#observation_latitude[name=?]', 'observation[latitude]' - assert_select "input#observation_latitude[name=?]", "observation[latitude]" + assert_select 'input#observation_longitude[name=?]', 'observation[longitude]' - assert_select "input#observation_longitude[name=?]", "observation[longitude]" - - assert_select "input#observation_num_bands[name=?]", "observation[num_bands]" + assert_select 'input#observation_num_bands[name=?]', 'observation[num_bands]' end end end diff --git a/spec/views/observations/show.html.erb_spec.rb b/spec/views/observations/show.html.erb_spec.rb index 8f357b8..46e22fe 100644 --- a/spec/views/observations/show.html.erb_spec.rb +++ b/spec/views/observations/show.html.erb_spec.rb @@ -1,16 +1,16 @@ require 'rails_helper' -RSpec.describe "observations/show", type: :view do +RSpec.describe 'observations/show', type: :view do before(:each) do @observation = assign(:observation, Observation.create!( - :location => "Location", - :latitude => "9.99", - :longitude => "9.99", - :num_bands => 2 + location: 'Location', + latitude: '9.99', + longitude: '9.99', + num_bands: 2 )) end - it "renders attributes in

" do + it 'renders attributes in

' do render expect(rendered).to match(/Location/) expect(rendered).to match(/9.99/) @@ -24,4 +24,3 @@ # assert_select "div.gm-style" end end - From 1d8d097a38a164842123801e00c05daf65f54d52 Mon Sep 17 00:00:00 2001 From: Josh Langholtz Date: Mon, 20 Jun 2016 19:18:36 -0400 Subject: [PATCH 3/5] Resolve remaining style violations --- .rubocop.yml | 2 + .rubocop_todo.yml | 38 +------------------ .../users/invitations_controller.rb | 20 +++++----- app/models/ability.rb | 2 +- app/models/observation.rb | 2 +- app/models/user.rb | 6 +-- .../invitations_controller_spec.rb | 2 +- .../observations_controller_spec.rb | 4 +- spec/models/user_spec.rb | 2 +- 9 files changed, 23 insertions(+), 55 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 288dbb0..5ab8989 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,5 @@ +inherit_from: .rubocop_todo.yml + AllCops: Exclude: - 'db/schema.rb' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f23b051..54338a3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,22 +1,11 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2016-06-20 18:52:30 -0400 using RuboCop version 0.40.0. +# 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: 2 -Lint/ParenthesesAsGroupedExpression: - Exclude: - - 'spec/controllers/invitations_controller_spec.rb' - - 'spec/controllers/observations_controller_spec.rb' - -# Offense count: 1 -Lint/UselessAssignment: - Exclude: - - 'spec/controllers/observations_controller_spec.rb' - # Offense count: 1 Metrics/AbcSize: Max: 16 @@ -32,31 +21,6 @@ Metrics/LineLength: Metrics/MethodLength: Max: 17 -# Offense count: 1 -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: nested, compact -Style/ClassAndModuleChildren: - Exclude: - - 'app/controllers/users/invitations_controller.rb' - # Offense count: 17 Style/Documentation: Enabled: false - -# Offense count: 3 -# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist. -# NamePrefix: is_, has_, have_ -# NamePrefixBlacklist: is_, has_, have_ -# NameWhitelist: is_a? -Style/PredicateName: - Exclude: - - 'spec/**/*' - - 'app/models/user.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. -# SupportedStyles: slashes, percent_r, mixed -Style/RegexpLiteral: - Exclude: - - 'app/models/observation.rb' diff --git a/app/controllers/users/invitations_controller.rb b/app/controllers/users/invitations_controller.rb index 5515ef6..04d8d62 100644 --- a/app/controllers/users/invitations_controller.rb +++ b/app/controllers/users/invitations_controller.rb @@ -1,14 +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 + private - def configure_permitted_parameters - devise_parameter_sanitizer.permit(:invite, keys: [:role]) - end + 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 diff --git a/app/models/ability.rb b/app/models/ability.rb index fbc28f7..5b91ec9 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -3,6 +3,6 @@ class Ability def initialize(user) user ||= User.new - can :manage, :all if user.is_admin? + can :manage, :all if user.admin? end end diff --git a/app/models/observation.rb b/app/models/observation.rb index 19dce3b..b57f807 100644 --- a/app/models/observation.rb +++ b/app/models/observation.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index ea36816..804a01e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,15 +5,15 @@ class User < ApplicationRecord :recoverable, :rememberable, :trackable, :validatable ROLES = %w(admin researcher scientist).freeze - def is_admin? + def admin? role == 'admin' end - def is_researcher? + def researcher? role == 'researcher' end - def is_scientist? + def scientist? role == 'scientist' end end diff --git a/spec/controllers/invitations_controller_spec.rb b/spec/controllers/invitations_controller_spec.rb index 78bdf95..378a88d 100644 --- a/spec/controllers/invitations_controller_spec.rb +++ b/spec/controllers/invitations_controller_spec.rb @@ -12,7 +12,7 @@ end context 'proper authorization' do - let (:admin_params) do + let(:admin_params) do { email: 'admin@gmail.com', name: 'Mr Admin', diff --git a/spec/controllers/observations_controller_spec.rb b/spec/controllers/observations_controller_spec.rb index d2f9e7e..1a66f2e 100644 --- a/spec/controllers/observations_controller_spec.rb +++ b/spec/controllers/observations_controller_spec.rb @@ -42,7 +42,7 @@ } end - let (:admin_params) do + let(:admin_params) do { email: 'admin@gmail.com', name: 'Mr Admin', @@ -65,7 +65,7 @@ it 'assigns all observations as @observations' do @request.env['devise.mapping'] = Devise.mappings[:user] sign_in admin - observation = Observation.create! valid_attributes + Observation.create! valid_attributes get :index, params: {}, session: valid_session expect(assigns(:observations)).to eq(Observation.all) end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index b514154..65cd8ee 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -20,6 +20,6 @@ password: 'password', password_confirmation: 'password' ) - expect(user.is_admin?).to be(true) + expect(user).to be_admin end end From 3a44f46c98476c4e134e0e5d14cc0d267d37754d Mon Sep 17 00:00:00 2001 From: Josh Langholtz Date: Mon, 20 Jun 2016 19:41:56 -0400 Subject: [PATCH 4/5] Add Hound CI configuration file --- .hound.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .hound.yml diff --git a/.hound.yml b/.hound.yml new file mode 100644 index 0000000..5d0ff60 --- /dev/null +++ b/.hound.yml @@ -0,0 +1,2 @@ +ruby: + config_file: .rubocop.yml From d5ce5df2d14f9a6ad5876587135534e577d01edb Mon Sep 17 00:00:00 2001 From: Josh Langholtz Date: Mon, 20 Jun 2016 21:18:57 -0400 Subject: [PATCH 5/5] Enable Rails cops --- .rubocop.yml | 6 ++++++ app/models/observation.rb | 2 +- db/seeds.rb | 6 +++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 5ab8989..332bcc3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -7,5 +7,11 @@ AllCops: ExtraDetails: true TargetRubyVersion: 2.3 +Rails: + Enabled: true + Style/FrozenStringLiteralComment: Enabled: false + +Style/StringLiterals: + EnforcedStyle: single_quotes diff --git a/app/models/observation.rb b/app/models/observation.rb index b57f807..a19c6d3 100644 --- a/app/models/observation.rb +++ b/app/models/observation.rb @@ -1,5 +1,5 @@ class Observation < ApplicationRecord - validates_inclusion_of :num_bands, in: 0..2 + validates :num_bands, inclusion: 0..2 has_attached_file :photo, styles: { thumb: '100x100>', diff --git a/db/seeds.rb b/db/seeds.rb index 3cc094d..c30ac88 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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' +Rails.logger.info 'Adding a Whole bunch of Observations' 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.current, location: 'Burke Lake Park, Fairfax Station, VA', latitude: 38, longitude: -77, num_bands: 1) +Observation.create(sighted_at: DateTime.current, location: 'someplace cool', latitude: 37, longitude: -78, num_bands: 1)