From 38fcfcd4e58c943e5d71d0a585ab7e1a95a02b6e Mon Sep 17 00:00:00 2001 From: "Jesse C. Fisher" Date: Tue, 4 Aug 2015 17:26:09 -0700 Subject: [PATCH] simple RuboCop style fixes --- .rubocop.yml | 6 ++ Gemfile | 8 +- Rakefile | 3 +- app/controllers/games_controller.rb | 12 +-- app/controllers/players_controller.rb | 13 +-- app/controllers/users_controller.rb | 9 +- app/models/game.rb | 9 +- app/models/play.rb | 6 +- app/models/player.rb | 4 +- app/models/user.rb | 2 +- app/policies/user_policy.rb | 3 +- app/services/create_admin_service.rb | 10 +- config/application.rb | 15 ++- config/deploy.rb | 2 - config/environments/development.rb | 7 +- config/environments/production.rb | 22 +++-- config/environments/test.rb | 2 +- config/initializers/cookies_serializer.rb | 3 +- config/initializers/devise.rb | 4 +- .../devise_permitted_parameters.rb | 1 - config/initializers/pundit.rb | 3 +- config/initializers/upmin.rb | 5 +- spec/factories/games.rb | 2 +- spec/factories/players.rb | 3 +- spec/factories/plays.rb | 3 +- spec/factories/users.rb | 5 +- spec/features/plays_spec.rb | 29 +++--- spec/features/users/sign_in_spec.rb | 11 ++- spec/features/users/sign_out_spec.rb | 4 - spec/features/users/user_delete_spec.rb | 8 +- spec/features/users/user_edit_spec.rb | 13 ++- spec/features/users/user_index_spec.rb | 2 - spec/features/users/user_quick_play_spec.rb | 6 +- spec/features/users/user_show_spec.rb | 6 +- spec/features/visitors/about_page_spec.rb | 4 +- spec/features/visitors/home_page_spec.rb | 4 +- spec/features/visitors/navigation_spec.rb | 2 - spec/features/visitors/quick_play_spec.rb | 6 +- spec/features/visitors/sign_up_spec.rb | 7 +- spec/models/game_spec.rb | 11 +-- spec/models/play_spec.rb | 2 +- spec/models/player_card_spec.rb | 2 +- spec/models/player_spec.rb | 2 +- spec/models/user_spec.rb | 4 +- spec/policies/user_policy_spec.rb | 19 ++-- spec/rails_helper.rb | 6 +- spec/spec_helper.rb | 99 ++++++++++--------- spec/support/database_cleaner.rb | 2 +- spec/support/devise.rb | 2 +- spec/support/helpers/session_helpers.rb | 2 +- 50 files changed, 191 insertions(+), 224 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 5d303f03..5ada3173 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,9 @@ +Documentation: + Enabled: false +Metrics/LineLength: + Enabled: false +Style/RedundantSelf: + Enabled: false AllCops: RunRailsCops: true Include: diff --git a/Gemfile b/Gemfile index 1e48de4d..aeffd869 100644 --- a/Gemfile +++ b/Gemfile @@ -33,12 +33,12 @@ group :development do gem 'guard-rails' gem 'guard-rspec' gem 'html2haml' - gem 'hub', :require=>nil + gem 'hub', require: nil gem 'quiet_assets' gem 'rails_layout' - gem 'rb-fchange', :require=>false - gem 'rb-fsevent', :require=>false - gem 'rb-inotify', :require=>false + gem 'rb-fchange', require: false + gem 'rb-fsevent', require: false + gem 'rb-inotify', require: false gem 'spring-commands-rspec' end group :development, :test do diff --git a/Rakefile b/Rakefile index ba6b733d..ce4aec20 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,6 @@ # Add your own tasks in files placed in lib/tasks ending in .rake, -# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. +# for example lib/tasks/capistrano.rake, +# and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index d8eac172..0ad12ef9 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -21,8 +21,8 @@ class GamesController < ApplicationController end def play_hand - # TODO validate player's turn, current_user == @game.current_player.user - # TODO move this logic out of controller maybe to model(s) + # TODO: validate player's turn, current_user == @game.current_player.user + # TODO: move this logic out of controller maybe to model(s) @cards_to_play = @game.current_player.player_cards.find(params[:player_card_ids]) # Instantiate the play @@ -35,7 +35,7 @@ class GamesController < ApplicationController card.save end - # TODO add current_hand logic + # TODO: add current_hand logic # @hand > @game.hand_to_beat redirect_to @game end @@ -64,7 +64,7 @@ class GamesController < ApplicationController def join @game = Game.find(params[:game_id]) @game.add_player_from_user(current_user) - flash[:notice] = "Successfully joined game..." + flash[:notice] = 'Successfully joined game...' redirect_to(@game) end @@ -74,13 +74,13 @@ class GamesController < ApplicationController begin @game.start rescue StandardError => e - @game.errors.messages.each do |key,msg| + @game.errors.messages.each do |key, msg| flash[key] = msg.join end redirect_to(@game) return end - flash[:notice] = "Game started." + flash[:notice] = 'Game started.' redirect_to(@game) end diff --git a/app/controllers/players_controller.rb b/app/controllers/players_controller.rb index 56195a65..76fe5a52 100644 --- a/app/controllers/players_controller.rb +++ b/app/controllers/players_controller.rb @@ -37,11 +37,12 @@ class PlayersController < ApplicationController end private - def set_player - @player = Player.find(params[:id]) - end - def player_params - params.require(:player).permit(:game_id, :user_id) - end + def set_player + @player = Player.find(params[:id]) + end + + def player_params + params.require(:player).permit(:game_id, :user_id) + end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 244d8782..d333cb4e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,5 @@ class UsersController < ApplicationController - before_filter :authenticate_user! + before_action :authenticate_user! after_action :verify_authorized def index @@ -16,9 +16,9 @@ class UsersController < ApplicationController @user = User.find(params[:id]) authorize @user if @user.update_attributes(secure_params) - redirect_to users_path, :notice => "User updated." + redirect_to users_path, notice: 'User updated.' else - redirect_to users_path, :alert => "Unable to update user." + redirect_to users_path, alert: 'Unable to update user.' end end @@ -26,7 +26,7 @@ class UsersController < ApplicationController user = User.find(params[:id]) authorize user user.destroy - redirect_to users_path, :notice => "User deleted." + redirect_to users_path, notice: 'User deleted.' end private @@ -34,5 +34,4 @@ class UsersController < ApplicationController def secure_params params.require(:user).permit(:role) end - end diff --git a/app/models/game.rb b/app/models/game.rb index 8f5bddc0..844aebf2 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -20,7 +20,7 @@ class Game < ActiveRecord::Base d.cards.shuffle! # Deal the cards players.each do |player| - 13.times do + 13.times do card = d.cards.shift player.player_cards.new(card.instance_values) end @@ -29,7 +29,7 @@ class Game < ActiveRecord::Base # Set status to first turn # Player with the lowest card - self.status = "First Play at: " + self.lowest_card.player.user.email + self.status = 'First Play at: ' + self.lowest_card.player.user.email self.control_player_id = self.lowest_card.player.id save end @@ -42,9 +42,9 @@ class Game < ActiveRecord::Base @player_count = players.count errors[:players] = 'Must be at least 2 players.' if @player_count < 2 errors[:players] = 'Must be less than 5 players.' if @player_count > 4 - errors[:status] = 'Game already started...' if self.status != nil + errors[:status] = 'Game already started...' if self.status.nil? == false errors[:player_cards] = 'Cards already dealt...' unless player_cards.empty? - raise StandardError, errors if errors.count > 0 + fail StandardError, errors if errors.count > 0 return true end @@ -90,5 +90,4 @@ class Game < ActiveRecord::Base def control_user self.players.find(self.control_player_id).user end - end diff --git a/app/models/play.rb b/app/models/play.rb index ad847dd1..bf411952 100644 --- a/app/models/play.rb +++ b/app/models/play.rb @@ -1,5 +1,5 @@ class Play < ActiveRecord::Base - belongs_to :game, :foreign_key => "game_id" - belongs_to :player, :foreign_key => "player_id" - has_many :player_cards, :foreign_key => "play_id" + belongs_to :game, foreign_key: 'game_id' + belongs_to :player, foreign_key: 'player_id' + has_many :player_cards, foreign_key: 'play_id' end diff --git a/app/models/player.rb b/app/models/player.rb index 05c41c22..dbf735ef 100644 --- a/app/models/player.rb +++ b/app/models/player.rb @@ -6,6 +6,6 @@ class Player < ActiveRecord::Base has_many :player_cards has_many :plays - validates_presence_of :user_id - validates_presence_of :game_id + validates :user_id, presence: true + validates :game_id, presence: true end diff --git a/app/models/user.rb b/app/models/user.rb index a213d45d..2f13e49f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,6 @@ class User < ActiveRecord::Base enum role: [:user, :vip, :admin] - after_initialize :set_default_role, :if => :new_record? + after_initialize :set_default_role, if: :new_record? def set_default_role self.role ||= :user diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb index 2889a10a..7223dace 100644 --- a/app/policies/user_policy.rb +++ b/app/policies/user_policy.rb @@ -11,7 +11,7 @@ class UserPolicy end def show? - @current_user.admin? or @current_user == @user + @current_user.admin? || @current_user == @user end def update? @@ -22,5 +22,4 @@ class UserPolicy return false if @current_user == @user @current_user.admin? end - end diff --git a/app/services/create_admin_service.rb b/app/services/create_admin_service.rb index 9078b31c..633e9af4 100644 --- a/app/services/create_admin_service.rb +++ b/app/services/create_admin_service.rb @@ -1,10 +1,10 @@ class CreateAdminService def call user = User.find_or_create_by!(email: Rails.application.secrets.admin_email) do |user| - user.password = Rails.application.secrets.admin_password - user.password_confirmation = Rails.application.secrets.admin_password - user.confirm! - user.admin! - end + user.password = Rails.application.secrets.admin_password + user.password_confirmation = Rails.application.secrets.admin_password + user.confirm! + user.admin! + end end end diff --git a/config/application.rb b/config/application.rb index 02b87d36..0e793e1a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -8,16 +8,15 @@ Bundler.require(*Rails.groups) module ThirteenTienLen class Application < Rails::Application - config.generators do |g| g.test_framework :rspec, - fixtures: true, - view_specs: false, - helper_specs: false, - routing_specs: false, - controller_specs: false, - request_specs: false - g.fixture_replacement :factory_girl, dir: "spec/factories" + fixtures: true, + view_specs: false, + helper_specs: false, + request_specs: false, + routing_specs: false, + controller_specs: false + g.fixture_replacement :factory_girl, dir: 'spec/factories' end # Settings in config/environments/* take precedence over those specified here. diff --git a/config/deploy.rb b/config/deploy.rb index a1b6fd1a..21f6eed2 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -17,7 +17,6 @@ set :repo_url, 'git@example.com:me/my_repo.git' # set :keep_releases, 5 namespace :deploy do - desc 'Restart application' task :restart do on roles(:app), in: :sequence, wait: 5 do @@ -36,5 +35,4 @@ namespace :deploy do end after :finishing, 'deploy:cleanup' - end diff --git a/config/environments/development.rb b/config/environments/development.rb index df9854ec..84d058ae 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -28,22 +28,21 @@ Rails.application.configure do config.assets.debug = true config.action_mailer.smtp_settings = { - address: "smtp.gmail.com", + address: 'smtp.gmail.com', port: 587, domain: Rails.application.secrets.domain_name, - authentication: "plain", + authentication: 'plain', enable_starttls_auto: true, user_name: Rails.application.secrets.email_provider_username, password: Rails.application.secrets.email_provider_password } # ActionMailer Config - config.action_mailer.default_url_options = { :host => 'localhost:3000' } + config.action_mailer.default_url_options = { host: 'localhost:3000' } config.action_mailer.delivery_method = :smtp config.action_mailer.raise_delivery_errors = true # Send email in development mode? config.action_mailer.perform_deliveries = true - # Adds additional error checking when serving assets at runtime. # Checks for improperly declared sprockets dependencies. # Raises helpful error messages. diff --git a/config/environments/production.rb b/config/environments/production.rb index a0420884..4ae81535 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,5 +1,6 @@ Rails.application.configure do - # Settings specified here will take precedence over those in config/application.rb. + # Settings specified here + # will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.cache_classes = true @@ -16,7 +17,8 @@ Rails.application.configure do # Enable Rack::Cache to put a simple HTTP cache in front of your application # Add `rack-cache` to your Gemfile before enabling this. - # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. + # For large-scale production use, consider using a caching reverse proxy + # like nginx, varnish or squid. # config.action_dispatch.rack_cache = true # Disable Rails's static asset server (Apache or nginx will already do this). @@ -32,13 +34,15 @@ Rails.application.configure do # Generate digests for assets URLs. config.assets.digest = true - # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + # `config.assets.precompile` and `config.assets.version` have moved + # to config/initializers/assets.rb # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx - # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # Force all access to the app over SSL, use Strict-Transport-Security, + # and use secure cookies. # config.force_ssl = true # Set to :debug to see everything in the log. @@ -57,7 +61,8 @@ Rails.application.configure do # config.action_controller.asset_host = "http://assets.example.com" # Ignore bad email addresses and do not raise email delivery errors. - # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # Set this to true and configure the email server for + # immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false # Enable locale fallbacks for I18n (makes lookups for any locale fall back to @@ -68,21 +73,20 @@ Rails.application.configure do config.active_support.deprecation = :notify config.action_mailer.smtp_settings = { - address: "smtp.gmail.com", + address: 'smtp.gmail.com', port: 587, domain: Rails.application.secrets.domain_name, - authentication: "plain", + authentication: 'plain', enable_starttls_auto: true, user_name: Rails.application.secrets.email_provider_username, password: Rails.application.secrets.email_provider_password } # ActionMailer Config - config.action_mailer.default_url_options = { :host => Rails.application.secrets.domain_name } + config.action_mailer.default_url_options = { host: Rails.application.secrets.domain_name } config.action_mailer.delivery_method = :smtp config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = false - # Disable automatic flushing of the log to improve performance. # config.autoflush_log = false diff --git a/config/environments/test.rb b/config/environments/test.rb index f17418ab..936ce6cc 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -30,7 +30,7 @@ Rails.application.configure do # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test - config.action_mailer.default_url_options = { :host => Rails.application.secrets.domain_name } + config.action_mailer.default_url_options = { host: Rails.application.secrets.domain_name } # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb index 7a06a89f..573e5792 100644 --- a/config/initializers/cookies_serializer.rb +++ b/config/initializers/cookies_serializer.rb @@ -1,3 +1,4 @@ # 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/initializers/devise.rb b/config/initializers/devise.rb index 786edede..fd050096 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -41,12 +41,12 @@ Devise.setup do |config| # Configure which authentication keys should be case-insensitive. # These keys will be downcased upon creating or modifying a user and when used # to authenticate or find a user. Default is :email. - config.case_insensitive_keys = [ :email ] + config.case_insensitive_keys = [:email] # Configure which authentication keys should have whitespace stripped. # These keys will have whitespace before and after removed upon creating or # modifying a user and when used to authenticate or find a user. Default is :email. - config.strip_whitespace_keys = [ :email ] + config.strip_whitespace_keys = [:email] # Tell if authentication through request.params is enabled. True by default. # It can be set to an array that will enable params authentication only for the diff --git a/config/initializers/devise_permitted_parameters.rb b/config/initializers/devise_permitted_parameters.rb index 3ab6ae33..d18292eb 100644 --- a/config/initializers/devise_permitted_parameters.rb +++ b/config/initializers/devise_permitted_parameters.rb @@ -11,7 +11,6 @@ module DevisePermittedParameters devise_parameter_sanitizer.for(:sign_up) << :name devise_parameter_sanitizer.for(:account_update) << :name end - end DeviseController.send :include, DevisePermittedParameters diff --git a/config/initializers/pundit.rb b/config/initializers/pundit.rb index f574e12f..bee953ca 100644 --- a/config/initializers/pundit.rb +++ b/config/initializers/pundit.rb @@ -13,10 +13,9 @@ module PunditHelper private def user_not_authorized - flash[:alert] = "Access denied." + flash[:alert] = 'Access denied.' redirect_to (request.referrer || root_path) end - end ApplicationController.send :include, PunditHelper diff --git a/config/initializers/upmin.rb b/config/initializers/upmin.rb index 11275940..8b9757cb 100644 --- a/config/initializers/upmin.rb +++ b/config/initializers/upmin.rb @@ -14,12 +14,11 @@ module AdminOnly def admin_only unless current_user.admin? - redirect_to :back, :alert => "Access denied." + redirect_to :back, alert: 'Access denied.' end rescue ActionController::RedirectBackError - redirect_to '/', :alert => "Access denied." + redirect_to '/', alert: 'Access denied.' end - end Upmin::ApplicationController.send :include, AdminOnly diff --git a/spec/factories/games.rb b/spec/factories/games.rb index 3c947445..d52ec992 100644 --- a/spec/factories/games.rb +++ b/spec/factories/games.rb @@ -1,6 +1,6 @@ FactoryGirl.define do factory :game do - title "Test Game" + title 'Test Game' status nil end end diff --git a/spec/factories/players.rb b/spec/factories/players.rb index 714788b4..358f02c0 100644 --- a/spec/factories/players.rb +++ b/spec/factories/players.rb @@ -1,7 +1,6 @@ FactoryGirl.define do factory :player do game nil -user nil + user nil end - end diff --git a/spec/factories/plays.rb b/spec/factories/plays.rb index f8723682..e640c483 100644 --- a/spec/factories/plays.rb +++ b/spec/factories/plays.rb @@ -1,7 +1,6 @@ FactoryGirl.define do factory :play do game nil -player nil + player nil end - end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 8c1b90d6..dafea8b8 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -1,13 +1,12 @@ FactoryGirl.define do factory :user do confirmed_at Time.now - name "Test User" + name 'Test User' sequence(:email) { |n| "test#{n}@example.com" } - password "please123" + password 'please123' trait :admin do role 'admin' end - end end diff --git a/spec/features/plays_spec.rb b/spec/features/plays_spec.rb index b754561c..5c1adbb9 100644 --- a/spec/features/plays_spec.rb +++ b/spec/features/plays_spec.rb @@ -2,8 +2,7 @@ require 'rails_helper' include Warden::Test::Helpers Warden.test_mode! -feature "Play a hand", :type => :feature do - +feature 'Play a hand', type: :feature do after(:each) do Warden.test_reset! end @@ -13,20 +12,20 @@ feature "Play a hand", :type => :feature do # When I play a hand containing the lowest card # Then I see a successful play message scenario 'first play contains lowest card' do - # TODO extract game setup to a factory + # TODO: extract game setup to a factory game = FactoryGirl.create :game user1 = FactoryGirl.create :user user2 = FactoryGirl.create :user game.add_player_from_user user1 game.add_player_from_user user2 game.start - login_as(game.current_player.user, :scope => :user) + login_as(game.current_player.user, scope: :user) visit game_path game # Click the lowest card checkbox @card_to_play = game.lowest_card check @card_to_play.to_s - click_button "Play Hand" - expect(page).to have_content("Played " + game.lowest_card.to_s) + click_button 'Play Hand' + expect(page).to have_content('Played ' + game.lowest_card.to_s) # create game with players # current_player plays hand containing lowest card # expect successful play message @@ -39,17 +38,18 @@ feature "Play a hand", :type => :feature do game.add_player_from_user user1 game.add_player_from_user user2 game.start - login_as(game.current_player.user, :scope => :user) + login_as(game.current_player.user, scope: :user) visit game_path game # Click the lowest card checkbox @card_to_play = game.current_player.player_cards.order(:value).last check @card_to_play.to_s - click_button "Play Hand" - expect(page).to have_content("First hand must contain the lowest card: #{game.lowest_card.to_s}") + click_button 'Play Hand' + expect(page).to have_content + "First hand must contain the lowest card: #{game.lowest_card.to_s}" # current_player plays hand not containing lowest card # expect unsuccessful play message hand MUST contain lowest card end - + # Scenario: Player can play a valid hand on their turn # Given I am the active player # When I play a valid hand @@ -58,9 +58,9 @@ feature "Play a hand", :type => :feature do # create game with players # current_player plays a valid hand # expect successful play message - pending "to be implemented" + skip 'to be implemented' end - + # Scenario: Player can not play an invalid hand on their turn # Given I am the active player # When I play an invalid hand @@ -69,7 +69,7 @@ feature "Play a hand", :type => :feature do # create game with players # current_player plays an invalid hand # expect invalid hand message - pending "to be implemented" + skip 'to be implemented' end # Scenario: Player can not play a hand when it is not their turn @@ -80,7 +80,6 @@ feature "Play a hand", :type => :feature do # create game with players # not_current_player plays a valid hand # expect unsuccessful play message - pending "to be implemented" + skip 'to be implemented' end - end diff --git a/spec/features/users/sign_in_spec.rb b/spec/features/users/sign_in_spec.rb index 57d4d933..7e50113a 100644 --- a/spec/features/users/sign_in_spec.rb +++ b/spec/features/users/sign_in_spec.rb @@ -3,14 +3,14 @@ # I want to sign in # So I can visit protected areas of the site feature 'Sign in', :devise do - # Scenario: User cannot sign in if not registered # Given I do not exist as a user # When I sign in with valid credentials # Then I see an invalid credentials message scenario 'user cannot sign in if not registered' do signin('test@example.com', 'please123') - expect(page).to have_content I18n.t 'devise.failure.not_found_in_database', authentication_keys: 'email' + expect(page).to have_content + I18n.t 'devise.failure.not_found_in_database', authentication_keys: 'email' end # Scenario: User can sign in with valid credentials @@ -32,7 +32,8 @@ feature 'Sign in', :devise do scenario 'user cannot sign in with wrong email' do user = FactoryGirl.create(:user) signin('invalid@email.com', user.password) - expect(page).to have_content I18n.t 'devise.failure.not_found_in_database', authentication_keys: 'email' + expect(page).to have_content + I18n.t 'devise.failure.not_found_in_database', authentication_keys: 'email' end # Scenario: User cannot sign in with wrong password @@ -43,7 +44,7 @@ feature 'Sign in', :devise do scenario 'user cannot sign in with wrong password' do user = FactoryGirl.create(:user) signin(user.email, 'invalidpass') - expect(page).to have_content I18n.t 'devise.failure.invalid', authentication_keys: 'email' + expect(page).to have_content + I18n.t 'devise.failure.invalid', authentication_keys: 'email' end - end diff --git a/spec/features/users/sign_out_spec.rb b/spec/features/users/sign_out_spec.rb index 3f906b98..2c401e71 100644 --- a/spec/features/users/sign_out_spec.rb +++ b/spec/features/users/sign_out_spec.rb @@ -3,7 +3,6 @@ # I want to sign out # So I can protect my account from unauthorized access feature 'Sign out', :devise do - # Scenario: User signs out successfully # Given I am signed in # When I sign out @@ -15,7 +14,4 @@ feature 'Sign out', :devise do click_link 'Sign out' expect(page).to have_content I18n.t 'devise.sessions.signed_out' end - end - - diff --git a/spec/features/users/user_delete_spec.rb b/spec/features/users/user_delete_spec.rb index 7cd1c97f..443b7537 100644 --- a/spec/features/users/user_delete_spec.rb +++ b/spec/features/users/user_delete_spec.rb @@ -6,7 +6,6 @@ Warden.test_mode! # I want to delete my user profile # So I can close my account feature 'User delete', :devise, :js do - after(:each) do Warden.test_reset! end @@ -18,15 +17,10 @@ feature 'User delete', :devise, :js do scenario 'user can delete own account' do skip 'skip a slow test' user = FactoryGirl.create(:user) - login_as(user, :scope => :user) + login_as(user, scope: :user) visit edit_user_registration_path(user) click_button 'Cancel my account' page.driver.browser.switch_to.alert.accept expect(page).to have_content I18n.t 'devise.registrations.destroyed' end - end - - - - diff --git a/spec/features/users/user_edit_spec.rb b/spec/features/users/user_edit_spec.rb index f4acd383..096d534e 100644 --- a/spec/features/users/user_edit_spec.rb +++ b/spec/features/users/user_edit_spec.rb @@ -6,7 +6,6 @@ Warden.test_mode! # I want to edit my user profile # So I can change my email address feature 'User edit', :devise do - after(:each) do Warden.test_reset! end @@ -17,12 +16,13 @@ feature 'User edit', :devise do # Then I see an account updated message scenario 'user changes email address' do user = FactoryGirl.create(:user) - login_as(user, :scope => :user) + login_as(user, scope: :user) visit edit_user_registration_path(user) - fill_in 'Email', :with => 'newemail@example.com' - fill_in 'Current password', :with => user.password + fill_in 'Email', with: 'newemail@example.com' + fill_in 'Current password', with: user.password click_button 'Update' - txts = [I18n.t( 'devise.registrations.updated'), I18n.t( 'devise.registrations.update_needs_confirmation')] + txts = [I18n.t('devise.registrations.updated'), + I18n.t('devise.registrations.update_needs_confirmation')] expect(page).to have_content(/.*#{txts[0]}.*|.*#{txts[1]}.*/) end @@ -33,10 +33,9 @@ feature 'User edit', :devise do scenario "user cannot cannot edit another user's profile", :me do me = FactoryGirl.create(:user) other = FactoryGirl.create(:user, email: 'other@example.com') - login_as(me, :scope => :user) + login_as(me, scope: :user) visit edit_user_registration_path(other) expect(page).to have_content 'Edit User' expect(page).to have_field('Email', with: me.email) end - end diff --git a/spec/features/users/user_index_spec.rb b/spec/features/users/user_index_spec.rb index d786db61..851b92a1 100644 --- a/spec/features/users/user_index_spec.rb +++ b/spec/features/users/user_index_spec.rb @@ -6,7 +6,6 @@ Warden.test_mode! # I want to see a list of users # So I can see who has registered feature 'User index page', :devise do - after(:each) do Warden.test_reset! end @@ -21,5 +20,4 @@ feature 'User index page', :devise do visit users_path expect(page).to have_content user.email end - end diff --git a/spec/features/users/user_quick_play_spec.rb b/spec/features/users/user_quick_play_spec.rb index cc90f952..6b02520c 100644 --- a/spec/features/users/user_quick_play_spec.rb +++ b/spec/features/users/user_quick_play_spec.rb @@ -6,18 +6,16 @@ Warden.test_mode! # I want to play a quick game # So I can have fun as fast as possible feature 'Quick play', :devise do - # Scenario: User can join a game using the quick play link # Given I am signed in # When I click the Quick Play link # Then I join a game scenario 'user can join a quick play game' do - pending("#EXPECT USER TO JOIN FIRST OPEN QUICK PLAY GAME") + pending('#EXPECT USER TO JOIN FIRST OPEN QUICK PLAY GAME') user = FactoryGirl.create(:user) signin(user.email, user.password) click_link 'Quick Play' - #EXPECT VISITOR TO JOIN FIRST OPEN QUICK PLAY TABLE + # EXPECT VISITOR TO JOIN FIRST OPEN QUICK PLAY TABLE expect(fail) end - end diff --git a/spec/features/users/user_show_spec.rb b/spec/features/users/user_show_spec.rb index aeee7d69..e829dc23 100644 --- a/spec/features/users/user_show_spec.rb +++ b/spec/features/users/user_show_spec.rb @@ -6,7 +6,6 @@ Warden.test_mode! # I want to visit my user profile page # So I can see my personal account data feature 'User profile page', :devise do - after(:each) do Warden.test_reset! end @@ -17,7 +16,7 @@ feature 'User profile page', :devise do # Then I see my own email address scenario 'user sees own profile' do user = FactoryGirl.create(:user) - login_as(user, :scope => :user) + login_as(user, scope: :user) visit user_path(user) expect(page).to have_content 'User' expect(page).to have_content user.email @@ -30,10 +29,9 @@ feature 'User profile page', :devise do scenario "user cannot see another user's profile" do me = FactoryGirl.create(:user) other = FactoryGirl.create(:user, email: 'other@example.com') - login_as(me, :scope => :user) + login_as(me, scope: :user) Capybara.current_session.driver.header 'Referer', root_path visit user_path(other) expect(page).to have_content 'Access denied.' end - end diff --git a/spec/features/visitors/about_page_spec.rb b/spec/features/visitors/about_page_spec.rb index d94b56d2..ab53d6b1 100644 --- a/spec/features/visitors/about_page_spec.rb +++ b/spec/features/visitors/about_page_spec.rb @@ -3,14 +3,12 @@ # I want to visit an 'about' page # So I can learn more about the website feature 'About page' do - # Scenario: Visit the 'about' page # Given I am a visitor # When I visit the 'about' page - # Then I see "About the Website" + # Then I see 'About the Website' scenario 'Visit the about page' do visit 'pages/about' expect(page).to have_content 'About the Website' end - end diff --git a/spec/features/visitors/home_page_spec.rb b/spec/features/visitors/home_page_spec.rb index 8afa3658..4ac018e5 100644 --- a/spec/features/visitors/home_page_spec.rb +++ b/spec/features/visitors/home_page_spec.rb @@ -3,14 +3,12 @@ # I want to visit a home page # So I can learn more about the website feature 'Home page' do - # Scenario: Visit the home page # Given I am a visitor # When I visit the home page - # Then I see "Welcome" + # Then I see 'Welcome' scenario 'visit the home page' do visit root_path expect(page).to have_content 'Welcome' end - end diff --git a/spec/features/visitors/navigation_spec.rb b/spec/features/visitors/navigation_spec.rb index 73041e86..b6d61a73 100644 --- a/spec/features/visitors/navigation_spec.rb +++ b/spec/features/visitors/navigation_spec.rb @@ -3,7 +3,6 @@ # I want to see navigation links # So I can find home, sign in, or sign up feature 'Navigation links', :devise do - # Scenario: View navigation links # Given I am a visitor # When I visit the home page @@ -13,5 +12,4 @@ feature 'Navigation links', :devise do expect(page).to have_content 'Sign in' expect(page).to have_content 'Sign up' end - end diff --git a/spec/features/visitors/quick_play_spec.rb b/spec/features/visitors/quick_play_spec.rb index 1389235b..71599f5e 100644 --- a/spec/features/visitors/quick_play_spec.rb +++ b/spec/features/visitors/quick_play_spec.rb @@ -3,17 +3,15 @@ # I want to play a game # So I can have fun without signing up feature 'Quick play', :devise do - # Scenario: Visitor can join a game using the quick play link # Given I am not signed in # When I click the Quick Play link # Then I join a game scenario 'visitor can join a quick play game' do - pending("#EXPECT VISITOR TO JOIN FIRST OPEN QUICK PLAY GAME") + pending('#EXPECT VISITOR TO JOIN FIRST OPEN QUICK PLAY GAME') visit root_path click_link 'Quick Play' - #EXPECT VISITOR TO JOIN FIRST OPEN QUICK PLAY TABLE + # EXPECT VISITOR TO JOIN FIRST OPEN QUICK PLAY TABLE expect(fail) end - end diff --git a/spec/features/visitors/sign_up_spec.rb b/spec/features/visitors/sign_up_spec.rb index fc50163b..06f4132f 100644 --- a/spec/features/visitors/sign_up_spec.rb +++ b/spec/features/visitors/sign_up_spec.rb @@ -3,14 +3,14 @@ # I want to sign up # So I can visit protected areas of the site feature 'Sign Up', :devise do - # Scenario: Visitor can sign up with valid email address and password # Given I am not signed in # When I sign up with a valid email address and password # Then I see a successful sign up message scenario 'visitor can sign up with valid email address and password' do sign_up_with('test@example.com', 'please123', 'please123') - txts = [I18n.t( 'devise.registrations.signed_up'), I18n.t( 'devise.registrations.signed_up_but_unconfirmed')] + txts = [I18n.t('devise.registrations.signed_up'), + I18n.t('devise.registrations.signed_up_but_unconfirmed')] expect(page).to have_content(/.*#{txts[0]}.*|.*#{txts[1]}.*/) end @@ -38,7 +38,7 @@ feature 'Sign Up', :devise do # Then I see a 'too short password' message scenario 'visitor cannot sign up with a short password' do sign_up_with('test@example.com', 'please', 'please') - expect(page).to have_content "Password is too short" + expect(page).to have_content 'Password is too short' end # Scenario: Visitor cannot sign up without password confirmation @@ -58,5 +58,4 @@ feature 'Sign Up', :devise do sign_up_with('test@example.com', 'please123', 'mismatch') expect(page).to have_content "Password confirmation doesn't match" end - end diff --git a/spec/models/game_spec.rb b/spec/models/game_spec.rb index cec409e4..acf55366 100644 --- a/spec/models/game_spec.rb +++ b/spec/models/game_spec.rb @@ -28,7 +28,7 @@ RSpec.describe Game, type: :model do context 'when there are less than 2 players' do it 'is not startable with too few players' do - expect{@game.validate_startable}.to raise_error StandardError + expect { @game.validate_startable }.to raise_error StandardError expect(@game.players.size).to eq(0) expect(@game.startable?).to eq(false) expect(@game.errors[:players]) @@ -43,7 +43,7 @@ RSpec.describe Game, type: :model do @player.save end @game.players.new(user_id: User.last.id) - expect{@game.validate_startable}.to raise_error StandardError + expect { @game.validate_startable }.to raise_error StandardError expect(@game.startable?).to eq(false) expect(@game.errors[:players]) .to include 'Must be less than 5 players.' @@ -51,11 +51,4 @@ RSpec.describe Game, type: :model do end end end - - #when the game starts - #the player with the lowest card goes first - - #it 'Can not be started if game is invalid' do - #expect(@game.start).to raise_error - #end end diff --git a/spec/models/play_spec.rb b/spec/models/play_spec.rb index cfd8f782..b42be7f8 100644 --- a/spec/models/play_spec.rb +++ b/spec/models/play_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Play, :type => :model do +RSpec.describe Play, type: :model do before(:each) do @game = FactoryGirl.create(:game) @user1 = FactoryGirl.create(:user) diff --git a/spec/models/player_card_spec.rb b/spec/models/player_card_spec.rb index 40e6573e..f3229dff 100644 --- a/spec/models/player_card_spec.rb +++ b/spec/models/player_card_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' -RSpec.describe PlayerCard, :type => :model do +RSpec.describe PlayerCard, type: :model do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/models/player_spec.rb b/spec/models/player_spec.rb index b5778bca..9aa96a29 100644 --- a/spec/models/player_spec.rb +++ b/spec/models/player_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' -RSpec.describe Player, :type => :model do +RSpec.describe Player, type: :model do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 9b176188..cd787a6a 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,13 +1,11 @@ describe User do - before(:each) { @user = User.new(email: 'user@example.com') } subject { @user } it { should respond_to(:email) } - it "#email returns a string" do + it '#email returns a string' do expect(@user.email).to match 'user@example.com' end - end diff --git a/spec/policies/user_policy_spec.rb b/spec/policies/user_policy_spec.rb index 37579cce..b2621c2a 100644 --- a/spec/policies/user_policy_spec.rb +++ b/spec/policies/user_policy_spec.rb @@ -6,42 +6,41 @@ describe UserPolicy do let (:admin) { FactoryGirl.build_stubbed :user, :admin } permissions :index? do - it "denies access if not an admin" do + it 'denies access if not an admin' do expect(UserPolicy).not_to permit(current_user) end - it "allows access for an admin" do + it 'allows access for an admin' do expect(UserPolicy).to permit(admin) end end permissions :show? do - it "prevents other users from seeing your profile" do + it 'prevents other users from seeing your profile' do expect(subject).not_to permit(current_user, other_user) end - it "allows you to see your own profile" do + it 'allows you to see your own profile' do expect(subject).to permit(current_user, current_user) end - it "allows an admin to see any profile" do + it 'allows an admin to see any profile' do expect(subject).to permit(admin) end end permissions :update? do - it "prevents updates if not an admin" do + it 'prevents updates if not an admin' do expect(subject).not_to permit(current_user) end - it "allows an admin to make updates" do + it 'allows an admin to make updates' do expect(subject).to permit(admin) end end permissions :destroy? do - it "prevents deleting yourself" do + it 'prevents deleting yourself' do expect(subject).not_to permit(current_user, current_user) end - it "allows an admin to delete any user" do + it 'allows an admin to delete any user' do expect(subject).to permit(admin, other_user) end end - end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 4d3565c3..d93c9ee7 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,7 +1,7 @@ # This file is copied to spec/ when you run 'rails generate rspec:install' -ENV["RAILS_ENV"] ||= 'test' +ENV['RAILS_ENV'] ||= 'test' require 'spec_helper' -require File.expand_path("../../config/environment", __FILE__) +require File.expand_path('../../config/environment', __FILE__) require 'rspec/rails' # Add additional requires below this line. Rails is not loaded until this point! @@ -18,7 +18,7 @@ require 'rspec/rails' # directory. Alternatively, in the individual `*_spec.rb` files, manually # require only the support files necessary. # -Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } +Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } # Checks for pending migrations before tests are run. # If you are not using ActiveRecord, you can remove this line. diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 275ba496..936f2a72 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,14 +1,16 @@ -# This file was generated by the `rails generate rspec:install` command. Conventionally, all -# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. -# The generated `.rspec` file contains `--require spec_helper` which will cause this -# file to always be loaded, without a need to explicitly require it in any files. -# +# This file was generated by the `rails generate rspec:install` command. +# Conventionally, all specs live under a `spec` directory, which +# RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly +# require it in any files. # Given that it is always loaded, you are encouraged to keep this file as # light-weight as possible. Requiring heavyweight dependencies from this file # will add to the boot time of your test suite on EVERY test run, even for an # individual file that may not need all of that loaded. Instead, consider making # a separate helper file that requires the additional dependencies and performs -# the additional setup, and require it from the spec files that actually need it. +# the additional setup, and require it from the spec files +# that actually need it. # # The `.rspec` file also contains a few flags that are not defaults but that # users commonly want. @@ -40,46 +42,47 @@ RSpec.configure do |config| # The settings below are suggested to provide a good initial experience # with RSpec, but feel free to customize to your heart's content. -=begin - # These two settings work together to allow 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. - config.filter_run :focus - config.run_all_when_everything_filtered = true - - # Limits the available syntax to the non-monkey patched syntax that is recommended. - # For more details, see: - # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax - # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ - # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching - 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 +#=begin +# # These two settings work together to allow 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. +# config.filter_run :focus +# config.run_all_when_everything_filtered = true +# +# # Limits the available syntax +# # to the non-monkey patched syntax that is recommended. +# # For more details, see: +# # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax +# # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ +# # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching +# 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 end diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb index a9758d43..ac38e31b 100644 --- a/spec/support/database_cleaner.rb +++ b/spec/support/database_cleaner.rb @@ -7,7 +7,7 @@ RSpec.configure do |config| DatabaseCleaner.strategy = :transaction end - config.before(:each, :js => true) do + config.before(:each, js: true) do DatabaseCleaner.strategy = :truncation end diff --git a/spec/support/devise.rb b/spec/support/devise.rb index 3552bea5..79998955 100644 --- a/spec/support/devise.rb +++ b/spec/support/devise.rb @@ -1,3 +1,3 @@ RSpec.configure do |config| - config.include Devise::TestHelpers, :type => :controller + config.include Devise::TestHelpers, type: :controller end diff --git a/spec/support/helpers/session_helpers.rb b/spec/support/helpers/session_helpers.rb index 88e2dec6..1f6a3298 100644 --- a/spec/support/helpers/session_helpers.rb +++ b/spec/support/helpers/session_helpers.rb @@ -4,7 +4,7 @@ module Features visit new_user_registration_path fill_in 'Email', with: email fill_in 'Password', with: password - fill_in 'Password confirmation', :with => confirmation + fill_in 'Password confirmation', with: confirmation click_button 'Sign up' end