simple RuboCop style fixes
This commit is contained in:
parent
3f313c134d
commit
38fcfcd4e5
@ -1,3 +1,9 @@
|
||||
Documentation:
|
||||
Enabled: false
|
||||
Metrics/LineLength:
|
||||
Enabled: false
|
||||
Style/RedundantSelf:
|
||||
Enabled: false
|
||||
AllCops:
|
||||
RunRailsCops: true
|
||||
Include:
|
||||
|
||||
8
Gemfile
8
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
|
||||
|
||||
3
Rakefile
3
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__)
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -37,6 +37,7 @@ class PlayersController < ApplicationController
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_player
|
||||
@player = Player.find(params[:id])
|
||||
end
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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,
|
||||
request_specs: false,
|
||||
routing_specs: false,
|
||||
controller_specs: false,
|
||||
request_specs: false
|
||||
g.fixture_replacement :factory_girl, dir: "spec/factories"
|
||||
controller_specs: false
|
||||
g.fixture_replacement :factory_girl, dir: 'spec/factories'
|
||||
end
|
||||
|
||||
# Settings in config/environments/* take precedence over those specified here.
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
# Be sure to restart your server when you modify this file.
|
||||
|
||||
Rails.application.config.action_dispatch.cookies_serializer = :json
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
FactoryGirl.define do
|
||||
factory :game do
|
||||
title "Test Game"
|
||||
title 'Test Game'
|
||||
status nil
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
FactoryGirl.define do
|
||||
factory :player do
|
||||
game nil
|
||||
user nil
|
||||
user nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
FactoryGirl.define do
|
||||
factory :play do
|
||||
game nil
|
||||
player nil
|
||||
player nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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,13 +38,14 @@ 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
|
||||
@ -58,7 +58,7 @@ 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
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
RSpec.configure do |config|
|
||||
config.include Devise::TestHelpers, :type => :controller
|
||||
config.include Devise::TestHelpers, type: :controller
|
||||
end
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user