simple RuboCop style fixes

This commit is contained in:
Jesse C. Fisher 2015-08-04 17:26:09 -07:00
parent 3f313c134d
commit 38fcfcd4e5
50 changed files with 191 additions and 224 deletions

View File

@ -1,3 +1,9 @@
Documentation:
Enabled: false
Metrics/LineLength:
Enabled: false
Style/RedundantSelf:
Enabled: false
AllCops: AllCops:
RunRailsCops: true RunRailsCops: true
Include: Include:

View File

@ -33,12 +33,12 @@ group :development do
gem 'guard-rails' gem 'guard-rails'
gem 'guard-rspec' gem 'guard-rspec'
gem 'html2haml' gem 'html2haml'
gem 'hub', :require=>nil gem 'hub', require: nil
gem 'quiet_assets' gem 'quiet_assets'
gem 'rails_layout' gem 'rails_layout'
gem 'rb-fchange', :require=>false gem 'rb-fchange', require: false
gem 'rb-fsevent', :require=>false gem 'rb-fsevent', require: false
gem 'rb-inotify', :require=>false gem 'rb-inotify', require: false
gem 'spring-commands-rspec' gem 'spring-commands-rspec'
end end
group :development, :test do group :development, :test do

View File

@ -1,5 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake, # 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__) require File.expand_path('../config/application', __FILE__)

View File

@ -21,8 +21,8 @@ class GamesController < ApplicationController
end end
def play_hand def play_hand
# TODO validate player's turn, current_user == @game.current_player.user # TODO: validate player's turn, current_user == @game.current_player.user
# TODO move this logic out of controller maybe to model(s) # TODO: move this logic out of controller maybe to model(s)
@cards_to_play = @game.current_player.player_cards.find(params[:player_card_ids]) @cards_to_play = @game.current_player.player_cards.find(params[:player_card_ids])
# Instantiate the play # Instantiate the play
@ -35,7 +35,7 @@ class GamesController < ApplicationController
card.save card.save
end end
# TODO add current_hand logic # TODO: add current_hand logic
# @hand > @game.hand_to_beat # @hand > @game.hand_to_beat
redirect_to @game redirect_to @game
end end
@ -64,7 +64,7 @@ class GamesController < ApplicationController
def join def join
@game = Game.find(params[:game_id]) @game = Game.find(params[:game_id])
@game.add_player_from_user(current_user) @game.add_player_from_user(current_user)
flash[:notice] = "Successfully joined game..." flash[:notice] = 'Successfully joined game...'
redirect_to(@game) redirect_to(@game)
end end
@ -74,13 +74,13 @@ class GamesController < ApplicationController
begin begin
@game.start @game.start
rescue StandardError => e rescue StandardError => e
@game.errors.messages.each do |key,msg| @game.errors.messages.each do |key, msg|
flash[key] = msg.join flash[key] = msg.join
end end
redirect_to(@game) redirect_to(@game)
return return
end end
flash[:notice] = "Game started." flash[:notice] = 'Game started.'
redirect_to(@game) redirect_to(@game)
end end

View File

@ -37,11 +37,12 @@ class PlayersController < ApplicationController
end end
private private
def set_player
@player = Player.find(params[:id])
end
def player_params def set_player
params.require(:player).permit(:game_id, :user_id) @player = Player.find(params[:id])
end end
def player_params
params.require(:player).permit(:game_id, :user_id)
end
end end

View File

@ -1,5 +1,5 @@
class UsersController < ApplicationController class UsersController < ApplicationController
before_filter :authenticate_user! before_action :authenticate_user!
after_action :verify_authorized after_action :verify_authorized
def index def index
@ -16,9 +16,9 @@ class UsersController < ApplicationController
@user = User.find(params[:id]) @user = User.find(params[:id])
authorize @user authorize @user
if @user.update_attributes(secure_params) if @user.update_attributes(secure_params)
redirect_to users_path, :notice => "User updated." redirect_to users_path, notice: 'User updated.'
else else
redirect_to users_path, :alert => "Unable to update user." redirect_to users_path, alert: 'Unable to update user.'
end end
end end
@ -26,7 +26,7 @@ class UsersController < ApplicationController
user = User.find(params[:id]) user = User.find(params[:id])
authorize user authorize user
user.destroy user.destroy
redirect_to users_path, :notice => "User deleted." redirect_to users_path, notice: 'User deleted.'
end end
private private
@ -34,5 +34,4 @@ class UsersController < ApplicationController
def secure_params def secure_params
params.require(:user).permit(:role) params.require(:user).permit(:role)
end end
end end

View File

@ -20,7 +20,7 @@ class Game < ActiveRecord::Base
d.cards.shuffle! d.cards.shuffle!
# Deal the cards # Deal the cards
players.each do |player| players.each do |player|
13.times do 13.times do
card = d.cards.shift card = d.cards.shift
player.player_cards.new(card.instance_values) player.player_cards.new(card.instance_values)
end end
@ -29,7 +29,7 @@ class Game < ActiveRecord::Base
# Set status to first turn # Set status to first turn
# Player with the lowest card # 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 self.control_player_id = self.lowest_card.player.id
save save
end end
@ -42,9 +42,9 @@ class Game < ActiveRecord::Base
@player_count = players.count @player_count = players.count
errors[:players] = 'Must be at least 2 players.' if @player_count < 2 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[: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? 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 return true
end end
@ -90,5 +90,4 @@ class Game < ActiveRecord::Base
def control_user def control_user
self.players.find(self.control_player_id).user self.players.find(self.control_player_id).user
end end
end end

View File

@ -1,5 +1,5 @@
class Play < ActiveRecord::Base class Play < ActiveRecord::Base
belongs_to :game, :foreign_key => "game_id" belongs_to :game, foreign_key: 'game_id'
belongs_to :player, :foreign_key => "player_id" belongs_to :player, foreign_key: 'player_id'
has_many :player_cards, :foreign_key => "play_id" has_many :player_cards, foreign_key: 'play_id'
end end

View File

@ -6,6 +6,6 @@ class Player < ActiveRecord::Base
has_many :player_cards has_many :player_cards
has_many :plays has_many :plays
validates_presence_of :user_id validates :user_id, presence: true
validates_presence_of :game_id validates :game_id, presence: true
end end

View File

@ -1,6 +1,6 @@
class User < ActiveRecord::Base class User < ActiveRecord::Base
enum role: [:user, :vip, :admin] 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 def set_default_role
self.role ||= :user self.role ||= :user

View File

@ -11,7 +11,7 @@ class UserPolicy
end end
def show? def show?
@current_user.admin? or @current_user == @user @current_user.admin? || @current_user == @user
end end
def update? def update?
@ -22,5 +22,4 @@ class UserPolicy
return false if @current_user == @user return false if @current_user == @user
@current_user.admin? @current_user.admin?
end end
end end

View File

@ -1,10 +1,10 @@
class CreateAdminService class CreateAdminService
def call def call
user = User.find_or_create_by!(email: Rails.application.secrets.admin_email) do |user| user = User.find_or_create_by!(email: Rails.application.secrets.admin_email) do |user|
user.password = Rails.application.secrets.admin_password user.password = Rails.application.secrets.admin_password
user.password_confirmation = Rails.application.secrets.admin_password user.password_confirmation = Rails.application.secrets.admin_password
user.confirm! user.confirm!
user.admin! user.admin!
end end
end end
end end

View File

@ -8,16 +8,15 @@ Bundler.require(*Rails.groups)
module ThirteenTienLen module ThirteenTienLen
class Application < Rails::Application class Application < Rails::Application
config.generators do |g| config.generators do |g|
g.test_framework :rspec, g.test_framework :rspec,
fixtures: true, fixtures: true,
view_specs: false, view_specs: false,
helper_specs: false, helper_specs: false,
routing_specs: false, request_specs: false,
controller_specs: false, routing_specs: false,
request_specs: false controller_specs: false
g.fixture_replacement :factory_girl, dir: "spec/factories" g.fixture_replacement :factory_girl, dir: 'spec/factories'
end end
# Settings in config/environments/* take precedence over those specified here. # Settings in config/environments/* take precedence over those specified here.

View File

@ -17,7 +17,6 @@ set :repo_url, 'git@example.com:me/my_repo.git'
# set :keep_releases, 5 # set :keep_releases, 5
namespace :deploy do namespace :deploy do
desc 'Restart application' desc 'Restart application'
task :restart do task :restart do
on roles(:app), in: :sequence, wait: 5 do on roles(:app), in: :sequence, wait: 5 do
@ -36,5 +35,4 @@ namespace :deploy do
end end
after :finishing, 'deploy:cleanup' after :finishing, 'deploy:cleanup'
end end

View File

@ -28,22 +28,21 @@ Rails.application.configure do
config.assets.debug = true config.assets.debug = true
config.action_mailer.smtp_settings = { config.action_mailer.smtp_settings = {
address: "smtp.gmail.com", address: 'smtp.gmail.com',
port: 587, port: 587,
domain: Rails.application.secrets.domain_name, domain: Rails.application.secrets.domain_name,
authentication: "plain", authentication: 'plain',
enable_starttls_auto: true, enable_starttls_auto: true,
user_name: Rails.application.secrets.email_provider_username, user_name: Rails.application.secrets.email_provider_username,
password: Rails.application.secrets.email_provider_password password: Rails.application.secrets.email_provider_password
} }
# ActionMailer Config # 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.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = true config.action_mailer.raise_delivery_errors = true
# Send email in development mode? # Send email in development mode?
config.action_mailer.perform_deliveries = true config.action_mailer.perform_deliveries = true
# Adds additional error checking when serving assets at runtime. # Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies. # Checks for improperly declared sprockets dependencies.
# Raises helpful error messages. # Raises helpful error messages.

View File

@ -1,5 +1,6 @@
Rails.application.configure do 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. # Code is not reloaded between requests.
config.cache_classes = true 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 # Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this. # 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 # config.action_dispatch.rack_cache = true
# Disable Rails's static asset server (Apache or nginx will already do this). # 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. # Generate digests for assets URLs.
config.assets.digest = true 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. # 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-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx # 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 # config.force_ssl = true
# Set to :debug to see everything in the log. # 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" # config.action_controller.asset_host = "http://assets.example.com"
# Ignore bad email addresses and do not raise email delivery errors. # 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 # config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to # 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.active_support.deprecation = :notify
config.action_mailer.smtp_settings = { config.action_mailer.smtp_settings = {
address: "smtp.gmail.com", address: 'smtp.gmail.com',
port: 587, port: 587,
domain: Rails.application.secrets.domain_name, domain: Rails.application.secrets.domain_name,
authentication: "plain", authentication: 'plain',
enable_starttls_auto: true, enable_starttls_auto: true,
user_name: Rails.application.secrets.email_provider_username, user_name: Rails.application.secrets.email_provider_username,
password: Rails.application.secrets.email_provider_password password: Rails.application.secrets.email_provider_password
} }
# ActionMailer Config # 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.delivery_method = :smtp
config.action_mailer.perform_deliveries = true config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false config.action_mailer.raise_delivery_errors = false
# Disable automatic flushing of the log to improve performance. # Disable automatic flushing of the log to improve performance.
# config.autoflush_log = false # config.autoflush_log = false

View File

@ -30,7 +30,7 @@ Rails.application.configure do
# The :test delivery method accumulates sent emails in the # The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array. # ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test 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. # Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr config.active_support.deprecation = :stderr

View File

@ -1,3 +1,4 @@
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
Rails.application.config.action_dispatch.cookies_serializer = :json Rails.application.config.action_dispatch.cookies_serializer = :json

View File

@ -41,12 +41,12 @@ Devise.setup do |config|
# Configure which authentication keys should be case-insensitive. # Configure which authentication keys should be case-insensitive.
# These keys will be downcased upon creating or modifying a user and when used # These keys will be downcased upon creating or modifying a user and when used
# to authenticate or find a user. Default is :email. # 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. # Configure which authentication keys should have whitespace stripped.
# These keys will have whitespace before and after removed upon creating or # 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. # 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. # 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 # It can be set to an array that will enable params authentication only for the

View File

@ -11,7 +11,6 @@ module DevisePermittedParameters
devise_parameter_sanitizer.for(:sign_up) << :name devise_parameter_sanitizer.for(:sign_up) << :name
devise_parameter_sanitizer.for(:account_update) << :name devise_parameter_sanitizer.for(:account_update) << :name
end end
end end
DeviseController.send :include, DevisePermittedParameters DeviseController.send :include, DevisePermittedParameters

View File

@ -13,10 +13,9 @@ module PunditHelper
private private
def user_not_authorized def user_not_authorized
flash[:alert] = "Access denied." flash[:alert] = 'Access denied.'
redirect_to (request.referrer || root_path) redirect_to (request.referrer || root_path)
end end
end end
ApplicationController.send :include, PunditHelper ApplicationController.send :include, PunditHelper

View File

@ -14,12 +14,11 @@ module AdminOnly
def admin_only def admin_only
unless current_user.admin? unless current_user.admin?
redirect_to :back, :alert => "Access denied." redirect_to :back, alert: 'Access denied.'
end end
rescue ActionController::RedirectBackError rescue ActionController::RedirectBackError
redirect_to '/', :alert => "Access denied." redirect_to '/', alert: 'Access denied.'
end end
end end
Upmin::ApplicationController.send :include, AdminOnly Upmin::ApplicationController.send :include, AdminOnly

View File

@ -1,6 +1,6 @@
FactoryGirl.define do FactoryGirl.define do
factory :game do factory :game do
title "Test Game" title 'Test Game'
status nil status nil
end end
end end

View File

@ -1,7 +1,6 @@
FactoryGirl.define do FactoryGirl.define do
factory :player do factory :player do
game nil game nil
user nil user nil
end end
end end

View File

@ -1,7 +1,6 @@
FactoryGirl.define do FactoryGirl.define do
factory :play do factory :play do
game nil game nil
player nil player nil
end end
end end

View File

@ -1,13 +1,12 @@
FactoryGirl.define do FactoryGirl.define do
factory :user do factory :user do
confirmed_at Time.now confirmed_at Time.now
name "Test User" name 'Test User'
sequence(:email) { |n| "test#{n}@example.com" } sequence(:email) { |n| "test#{n}@example.com" }
password "please123" password 'please123'
trait :admin do trait :admin do
role 'admin' role 'admin'
end end
end end
end end

View File

@ -2,8 +2,7 @@ require 'rails_helper'
include Warden::Test::Helpers include Warden::Test::Helpers
Warden.test_mode! Warden.test_mode!
feature "Play a hand", :type => :feature do feature 'Play a hand', type: :feature do
after(:each) do after(:each) do
Warden.test_reset! Warden.test_reset!
end end
@ -13,20 +12,20 @@ feature "Play a hand", :type => :feature do
# When I play a hand containing the lowest card # When I play a hand containing the lowest card
# Then I see a successful play message # Then I see a successful play message
scenario 'first play contains lowest card' do 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 game = FactoryGirl.create :game
user1 = FactoryGirl.create :user user1 = FactoryGirl.create :user
user2 = FactoryGirl.create :user user2 = FactoryGirl.create :user
game.add_player_from_user user1 game.add_player_from_user user1
game.add_player_from_user user2 game.add_player_from_user user2
game.start game.start
login_as(game.current_player.user, :scope => :user) login_as(game.current_player.user, scope: :user)
visit game_path game visit game_path game
# Click the lowest card checkbox # Click the lowest card checkbox
@card_to_play = game.lowest_card @card_to_play = game.lowest_card
check @card_to_play.to_s check @card_to_play.to_s
click_button "Play Hand" click_button 'Play Hand'
expect(page).to have_content("Played " + game.lowest_card.to_s) expect(page).to have_content('Played ' + game.lowest_card.to_s)
# create game with players # create game with players
# current_player plays hand containing lowest card # current_player plays hand containing lowest card
# expect successful play message # 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 user1
game.add_player_from_user user2 game.add_player_from_user user2
game.start game.start
login_as(game.current_player.user, :scope => :user) login_as(game.current_player.user, scope: :user)
visit game_path game visit game_path game
# Click the lowest card checkbox # Click the lowest card checkbox
@card_to_play = game.current_player.player_cards.order(:value).last @card_to_play = game.current_player.player_cards.order(:value).last
check @card_to_play.to_s check @card_to_play.to_s
click_button "Play Hand" click_button 'Play Hand'
expect(page).to have_content("First hand must contain the lowest card: #{game.lowest_card.to_s}") 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 # current_player plays hand not containing lowest card
# expect unsuccessful play message hand MUST contain lowest card # expect unsuccessful play message hand MUST contain lowest card
end end
# Scenario: Player can play a valid hand on their turn # Scenario: Player can play a valid hand on their turn
# Given I am the active player # Given I am the active player
# When I play a valid hand # When I play a valid hand
@ -58,9 +58,9 @@ feature "Play a hand", :type => :feature do
# create game with players # create game with players
# current_player plays a valid hand # current_player plays a valid hand
# expect successful play message # expect successful play message
pending "to be implemented" skip 'to be implemented'
end end
# Scenario: Player can not play an invalid hand on their turn # Scenario: Player can not play an invalid hand on their turn
# Given I am the active player # Given I am the active player
# When I play an invalid hand # When I play an invalid hand
@ -69,7 +69,7 @@ feature "Play a hand", :type => :feature do
# create game with players # create game with players
# current_player plays an invalid hand # current_player plays an invalid hand
# expect invalid hand message # expect invalid hand message
pending "to be implemented" skip 'to be implemented'
end end
# Scenario: Player can not play a hand when it is not their turn # 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 # create game with players
# not_current_player plays a valid hand # not_current_player plays a valid hand
# expect unsuccessful play message # expect unsuccessful play message
pending "to be implemented" skip 'to be implemented'
end end
end end

View File

@ -3,14 +3,14 @@
# I want to sign in # I want to sign in
# So I can visit protected areas of the site # So I can visit protected areas of the site
feature 'Sign in', :devise do feature 'Sign in', :devise do
# Scenario: User cannot sign in if not registered # Scenario: User cannot sign in if not registered
# Given I do not exist as a user # Given I do not exist as a user
# When I sign in with valid credentials # When I sign in with valid credentials
# Then I see an invalid credentials message # Then I see an invalid credentials message
scenario 'user cannot sign in if not registered' do scenario 'user cannot sign in if not registered' do
signin('test@example.com', 'please123') 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 end
# Scenario: User can sign in with valid credentials # 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 scenario 'user cannot sign in with wrong email' do
user = FactoryGirl.create(:user) user = FactoryGirl.create(:user)
signin('invalid@email.com', user.password) 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 end
# Scenario: User cannot sign in with wrong password # 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 scenario 'user cannot sign in with wrong password' do
user = FactoryGirl.create(:user) user = FactoryGirl.create(:user)
signin(user.email, 'invalidpass') 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
end end

View File

@ -3,7 +3,6 @@
# I want to sign out # I want to sign out
# So I can protect my account from unauthorized access # So I can protect my account from unauthorized access
feature 'Sign out', :devise do feature 'Sign out', :devise do
# Scenario: User signs out successfully # Scenario: User signs out successfully
# Given I am signed in # Given I am signed in
# When I sign out # When I sign out
@ -15,7 +14,4 @@ feature 'Sign out', :devise do
click_link 'Sign out' click_link 'Sign out'
expect(page).to have_content I18n.t 'devise.sessions.signed_out' expect(page).to have_content I18n.t 'devise.sessions.signed_out'
end end
end end

View File

@ -6,7 +6,6 @@ Warden.test_mode!
# I want to delete my user profile # I want to delete my user profile
# So I can close my account # So I can close my account
feature 'User delete', :devise, :js do feature 'User delete', :devise, :js do
after(:each) do after(:each) do
Warden.test_reset! Warden.test_reset!
end end
@ -18,15 +17,10 @@ feature 'User delete', :devise, :js do
scenario 'user can delete own account' do scenario 'user can delete own account' do
skip 'skip a slow test' skip 'skip a slow test'
user = FactoryGirl.create(:user) user = FactoryGirl.create(:user)
login_as(user, :scope => :user) login_as(user, scope: :user)
visit edit_user_registration_path(user) visit edit_user_registration_path(user)
click_button 'Cancel my account' click_button 'Cancel my account'
page.driver.browser.switch_to.alert.accept page.driver.browser.switch_to.alert.accept
expect(page).to have_content I18n.t 'devise.registrations.destroyed' expect(page).to have_content I18n.t 'devise.registrations.destroyed'
end end
end end

View File

@ -6,7 +6,6 @@ Warden.test_mode!
# I want to edit my user profile # I want to edit my user profile
# So I can change my email address # So I can change my email address
feature 'User edit', :devise do feature 'User edit', :devise do
after(:each) do after(:each) do
Warden.test_reset! Warden.test_reset!
end end
@ -17,12 +16,13 @@ feature 'User edit', :devise do
# Then I see an account updated message # Then I see an account updated message
scenario 'user changes email address' do scenario 'user changes email address' do
user = FactoryGirl.create(:user) user = FactoryGirl.create(:user)
login_as(user, :scope => :user) login_as(user, scope: :user)
visit edit_user_registration_path(user) visit edit_user_registration_path(user)
fill_in 'Email', :with => 'newemail@example.com' fill_in 'Email', with: 'newemail@example.com'
fill_in 'Current password', :with => user.password fill_in 'Current password', with: user.password
click_button 'Update' 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]}.*/) expect(page).to have_content(/.*#{txts[0]}.*|.*#{txts[1]}.*/)
end end
@ -33,10 +33,9 @@ feature 'User edit', :devise do
scenario "user cannot cannot edit another user's profile", :me do scenario "user cannot cannot edit another user's profile", :me do
me = FactoryGirl.create(:user) me = FactoryGirl.create(:user)
other = FactoryGirl.create(:user, email: 'other@example.com') other = FactoryGirl.create(:user, email: 'other@example.com')
login_as(me, :scope => :user) login_as(me, scope: :user)
visit edit_user_registration_path(other) visit edit_user_registration_path(other)
expect(page).to have_content 'Edit User' expect(page).to have_content 'Edit User'
expect(page).to have_field('Email', with: me.email) expect(page).to have_field('Email', with: me.email)
end end
end end

View File

@ -6,7 +6,6 @@ Warden.test_mode!
# I want to see a list of users # I want to see a list of users
# So I can see who has registered # So I can see who has registered
feature 'User index page', :devise do feature 'User index page', :devise do
after(:each) do after(:each) do
Warden.test_reset! Warden.test_reset!
end end
@ -21,5 +20,4 @@ feature 'User index page', :devise do
visit users_path visit users_path
expect(page).to have_content user.email expect(page).to have_content user.email
end end
end end

View File

@ -6,18 +6,16 @@ Warden.test_mode!
# I want to play a quick game # I want to play a quick game
# So I can have fun as fast as possible # So I can have fun as fast as possible
feature 'Quick play', :devise do feature 'Quick play', :devise do
# Scenario: User can join a game using the quick play link # Scenario: User can join a game using the quick play link
# Given I am signed in # Given I am signed in
# When I click the Quick Play link # When I click the Quick Play link
# Then I join a game # Then I join a game
scenario 'user can join a quick play game' do 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) user = FactoryGirl.create(:user)
signin(user.email, user.password) signin(user.email, user.password)
click_link 'Quick Play' click_link 'Quick Play'
#EXPECT VISITOR TO JOIN FIRST OPEN QUICK PLAY TABLE # EXPECT VISITOR TO JOIN FIRST OPEN QUICK PLAY TABLE
expect(fail) expect(fail)
end end
end end

View File

@ -6,7 +6,6 @@ Warden.test_mode!
# I want to visit my user profile page # I want to visit my user profile page
# So I can see my personal account data # So I can see my personal account data
feature 'User profile page', :devise do feature 'User profile page', :devise do
after(:each) do after(:each) do
Warden.test_reset! Warden.test_reset!
end end
@ -17,7 +16,7 @@ feature 'User profile page', :devise do
# Then I see my own email address # Then I see my own email address
scenario 'user sees own profile' do scenario 'user sees own profile' do
user = FactoryGirl.create(:user) user = FactoryGirl.create(:user)
login_as(user, :scope => :user) login_as(user, scope: :user)
visit user_path(user) visit user_path(user)
expect(page).to have_content 'User' expect(page).to have_content 'User'
expect(page).to have_content user.email 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 scenario "user cannot see another user's profile" do
me = FactoryGirl.create(:user) me = FactoryGirl.create(:user)
other = FactoryGirl.create(:user, email: 'other@example.com') 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 Capybara.current_session.driver.header 'Referer', root_path
visit user_path(other) visit user_path(other)
expect(page).to have_content 'Access denied.' expect(page).to have_content 'Access denied.'
end end
end end

View File

@ -3,14 +3,12 @@
# I want to visit an 'about' page # I want to visit an 'about' page
# So I can learn more about the website # So I can learn more about the website
feature 'About page' do feature 'About page' do
# Scenario: Visit the 'about' page # Scenario: Visit the 'about' page
# Given I am a visitor # Given I am a visitor
# When I visit the 'about' page # When I visit the 'about' page
# Then I see "About the Website" # Then I see 'About the Website'
scenario 'Visit the about page' do scenario 'Visit the about page' do
visit 'pages/about' visit 'pages/about'
expect(page).to have_content 'About the Website' expect(page).to have_content 'About the Website'
end end
end end

View File

@ -3,14 +3,12 @@
# I want to visit a home page # I want to visit a home page
# So I can learn more about the website # So I can learn more about the website
feature 'Home page' do feature 'Home page' do
# Scenario: Visit the home page # Scenario: Visit the home page
# Given I am a visitor # Given I am a visitor
# When I visit the home page # When I visit the home page
# Then I see "Welcome" # Then I see 'Welcome'
scenario 'visit the home page' do scenario 'visit the home page' do
visit root_path visit root_path
expect(page).to have_content 'Welcome' expect(page).to have_content 'Welcome'
end end
end end

View File

@ -3,7 +3,6 @@
# I want to see navigation links # I want to see navigation links
# So I can find home, sign in, or sign up # So I can find home, sign in, or sign up
feature 'Navigation links', :devise do feature 'Navigation links', :devise do
# Scenario: View navigation links # Scenario: View navigation links
# Given I am a visitor # Given I am a visitor
# When I visit the home page # 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 in'
expect(page).to have_content 'Sign up' expect(page).to have_content 'Sign up'
end end
end end

View File

@ -3,17 +3,15 @@
# I want to play a game # I want to play a game
# So I can have fun without signing up # So I can have fun without signing up
feature 'Quick play', :devise do feature 'Quick play', :devise do
# Scenario: Visitor can join a game using the quick play link # Scenario: Visitor can join a game using the quick play link
# Given I am not signed in # Given I am not signed in
# When I click the Quick Play link # When I click the Quick Play link
# Then I join a game # Then I join a game
scenario 'visitor can join a quick play game' do 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 visit root_path
click_link 'Quick Play' click_link 'Quick Play'
#EXPECT VISITOR TO JOIN FIRST OPEN QUICK PLAY TABLE # EXPECT VISITOR TO JOIN FIRST OPEN QUICK PLAY TABLE
expect(fail) expect(fail)
end end
end end

View File

@ -3,14 +3,14 @@
# I want to sign up # I want to sign up
# So I can visit protected areas of the site # So I can visit protected areas of the site
feature 'Sign Up', :devise do feature 'Sign Up', :devise do
# Scenario: Visitor can sign up with valid email address and password # Scenario: Visitor can sign up with valid email address and password
# Given I am not signed in # Given I am not signed in
# When I sign up with a valid email address and password # When I sign up with a valid email address and password
# Then I see a successful sign up message # Then I see a successful sign up message
scenario 'visitor can sign up with valid email address and password' do scenario 'visitor can sign up with valid email address and password' do
sign_up_with('test@example.com', 'please123', 'please123') 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]}.*/) expect(page).to have_content(/.*#{txts[0]}.*|.*#{txts[1]}.*/)
end end
@ -38,7 +38,7 @@ feature 'Sign Up', :devise do
# Then I see a 'too short password' message # Then I see a 'too short password' message
scenario 'visitor cannot sign up with a short password' do scenario 'visitor cannot sign up with a short password' do
sign_up_with('test@example.com', 'please', 'please') 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 end
# Scenario: Visitor cannot sign up without password confirmation # 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') sign_up_with('test@example.com', 'please123', 'mismatch')
expect(page).to have_content "Password confirmation doesn't match" expect(page).to have_content "Password confirmation doesn't match"
end end
end end

View File

@ -28,7 +28,7 @@ RSpec.describe Game, type: :model do
context 'when there are less than 2 players' do context 'when there are less than 2 players' do
it 'is not startable with too few 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.players.size).to eq(0)
expect(@game.startable?).to eq(false) expect(@game.startable?).to eq(false)
expect(@game.errors[:players]) expect(@game.errors[:players])
@ -43,7 +43,7 @@ RSpec.describe Game, type: :model do
@player.save @player.save
end end
@game.players.new(user_id: User.last.id) @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.startable?).to eq(false)
expect(@game.errors[:players]) expect(@game.errors[:players])
.to include 'Must be less than 5 players.' .to include 'Must be less than 5 players.'
@ -51,11 +51,4 @@ RSpec.describe Game, type: :model do
end end
end 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 end

View File

@ -1,6 +1,6 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe Play, :type => :model do RSpec.describe Play, type: :model do
before(:each) do before(:each) do
@game = FactoryGirl.create(:game) @game = FactoryGirl.create(:game)
@user1 = FactoryGirl.create(:user) @user1 = FactoryGirl.create(:user)

View File

@ -1,5 +1,5 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe PlayerCard, :type => :model do RSpec.describe PlayerCard, type: :model do
pending "add some examples to (or delete) #{__FILE__}" pending "add some examples to (or delete) #{__FILE__}"
end end

View File

@ -1,5 +1,5 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe Player, :type => :model do RSpec.describe Player, type: :model do
pending "add some examples to (or delete) #{__FILE__}" pending "add some examples to (or delete) #{__FILE__}"
end end

View File

@ -1,13 +1,11 @@
describe User do describe User do
before(:each) { @user = User.new(email: 'user@example.com') } before(:each) { @user = User.new(email: 'user@example.com') }
subject { @user } subject { @user }
it { should respond_to(:email) } 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' expect(@user.email).to match 'user@example.com'
end end
end end

View File

@ -6,42 +6,41 @@ describe UserPolicy do
let (:admin) { FactoryGirl.build_stubbed :user, :admin } let (:admin) { FactoryGirl.build_stubbed :user, :admin }
permissions :index? do 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) expect(UserPolicy).not_to permit(current_user)
end end
it "allows access for an admin" do it 'allows access for an admin' do
expect(UserPolicy).to permit(admin) expect(UserPolicy).to permit(admin)
end end
end end
permissions :show? do 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) expect(subject).not_to permit(current_user, other_user)
end 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) expect(subject).to permit(current_user, current_user)
end end
it "allows an admin to see any profile" do it 'allows an admin to see any profile' do
expect(subject).to permit(admin) expect(subject).to permit(admin)
end end
end end
permissions :update? do 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) expect(subject).not_to permit(current_user)
end end
it "allows an admin to make updates" do it 'allows an admin to make updates' do
expect(subject).to permit(admin) expect(subject).to permit(admin)
end end
end end
permissions :destroy? do permissions :destroy? do
it "prevents deleting yourself" do it 'prevents deleting yourself' do
expect(subject).not_to permit(current_user, current_user) expect(subject).not_to permit(current_user, current_user)
end 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) expect(subject).to permit(admin, other_user)
end end
end end
end end

View File

@ -1,7 +1,7 @@
# This file is copied to spec/ when you run 'rails generate rspec:install' # 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 'spec_helper'
require File.expand_path("../../config/environment", __FILE__) require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails' require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point! # 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 # directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary. # 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. # Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line. # If you are not using ActiveRecord, you can remove this line.

View File

@ -1,14 +1,16 @@
# This file was generated by the `rails generate rspec:install` command. Conventionally, all # This file was generated by the `rails generate rspec:install` command.
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # Conventionally, all specs live under a `spec` directory, which
# The generated `.rspec` file contains `--require spec_helper` which will cause this # RSpec adds to the `$LOAD_PATH`.
# file to always be loaded, without a need to explicitly require it in any files. # 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 # Given that it is always loaded, you are encouraged to keep this file as
# light-weight as possible. Requiring heavyweight dependencies from this file # 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 # 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 # individual file that may not need all of that loaded. Instead, consider making
# a separate helper file that requires the additional dependencies and performs # 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 # The `.rspec` file also contains a few flags that are not defaults but that
# users commonly want. # users commonly want.
@ -40,46 +42,47 @@ RSpec.configure do |config|
# The settings below are suggested to provide a good initial experience # The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content. # with RSpec, but feel free to customize to your heart's content.
=begin #=begin
# These two settings work together to allow you to limit a spec run # # 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 # # to individual examples or groups you care about by tagging them with
# `:focus` metadata. When nothing is tagged with `:focus`, all examples # # `:focus` metadata. When nothing is tagged with `:focus`, all examples
# get run. # # get run.
config.filter_run :focus # config.filter_run :focus
config.run_all_when_everything_filtered = true # config.run_all_when_everything_filtered = true
#
# Limits the available syntax to the non-monkey patched syntax that is recommended. # # Limits the available syntax
# For more details, see: # # to the non-monkey patched syntax that is recommended.
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax # # For more details, see:
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ # # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching # # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
config.disable_monkey_patching! # # - 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 # # Many RSpec users commonly either run the entire suite or an individual
# individual spec file. # # file, and it's useful to allow more verbose output when running an
if config.files_to_run.one? # # individual spec file.
# Use the documentation formatter for detailed output, # if config.files_to_run.one?
# unless a formatter has already been configured # # Use the documentation formatter for detailed output,
# (e.g. via a command-line flag). # # unless a formatter has already been configured
config.default_formatter = 'doc' # # (e.g. via a command-line flag).
end # 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 # # Print the 10 slowest examples and example groups at the
# particularly slow. # # end of the spec run, to help surface which specs are running
config.profile_examples = 10 # # 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 # # Run specs in random order to surface order dependencies. If you find an
# the seed, which is printed after each run. # # order dependency and want to debug it, you can fix the order by providing
# --seed 1234 # # the seed, which is printed after each run.
config.order = :random # # --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 # # Seed global randomization in this process using the `--seed` CLI option.
# test failures related to randomization by passing the same `--seed` value # # Setting this allows you to use `--seed` to deterministically reproduce
# as the one that triggered the failure. # # test failures related to randomization by passing the same `--seed` value
Kernel.srand config.seed # # as the one that triggered the failure.
=end # Kernel.srand config.seed
#=end
end end

View File

@ -7,7 +7,7 @@ RSpec.configure do |config|
DatabaseCleaner.strategy = :transaction DatabaseCleaner.strategy = :transaction
end end
config.before(:each, :js => true) do config.before(:each, js: true) do
DatabaseCleaner.strategy = :truncation DatabaseCleaner.strategy = :truncation
end end

View File

@ -1,3 +1,3 @@
RSpec.configure do |config| RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller config.include Devise::TestHelpers, type: :controller
end end

View File

@ -4,7 +4,7 @@ module Features
visit new_user_registration_path visit new_user_registration_path
fill_in 'Email', with: email fill_in 'Email', with: email
fill_in 'Password', with: password fill_in 'Password', with: password
fill_in 'Password confirmation', :with => confirmation fill_in 'Password confirmation', with: confirmation
click_button 'Sign up' click_button 'Sign up'
end end