Add soft_token to players
This commit is contained in:
parent
bd1d2bb55d
commit
5032c602c0
@ -64,7 +64,7 @@ class Game < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def add_player_from_user(user)
|
||||
return false unless can_accomodate(user)
|
||||
return false unless self.joinable?(user)
|
||||
new_player = self.players.create(user: user, soft_token: user.soft_token)
|
||||
end
|
||||
|
||||
@ -73,7 +73,7 @@ class Game < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def already_has?(user)
|
||||
users.include?(user)
|
||||
self.players.pluck(:user_id, :soft_token).flatten.compact.to_set.intersect? ([user.id, user.soft_token].to_set)
|
||||
end
|
||||
|
||||
def full?
|
||||
@ -88,7 +88,7 @@ class Game < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def joinable? user
|
||||
!self.users.include?(user) && !self.full?
|
||||
!self.already_has?(user) && !self.full?
|
||||
end
|
||||
|
||||
def next_player_id
|
||||
|
||||
@ -7,8 +7,8 @@ class Player < ActiveRecord::Base
|
||||
has_many :plays
|
||||
|
||||
#TODO: soft_user will not have a user_id
|
||||
validates :user_id, presence: true
|
||||
validates :game_id, presence: true
|
||||
validates :user, presence: true
|
||||
validates :game, presence: true
|
||||
|
||||
def inventory
|
||||
player_cards.where(play_id: nil).order(:value)
|
||||
|
||||
30
app/views/users/registrations/new.html.erb
Normal file
30
app/views/users/registrations/new.html.erb
Normal file
@ -0,0 +1,30 @@
|
||||
<h2>Sign up</h2>
|
||||
|
||||
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
|
||||
<%= devise_error_messages! %>
|
||||
|
||||
<div class="field">
|
||||
<%= f.hidden_field :soft_token, value: current_user.soft_token %>
|
||||
<%= f.label :email %><br />
|
||||
<%= f.email_field :email, autofocus: true %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :password %>
|
||||
<% if @minimum_password_length %>
|
||||
<em>(<%= @minimum_password_length %> characters minimum)</em>
|
||||
<% end %><br />
|
||||
<%= f.password_field :password, autocomplete: "off" %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :password_confirmation %><br />
|
||||
<%= f.password_field :password_confirmation, autocomplete: "off" %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= f.submit "Sign up" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= render "devise/shared/links" %>
|
||||
51
spec/features/users/user_join_game_spec.rb
Normal file
51
spec/features/users/user_join_game_spec.rb
Normal file
@ -0,0 +1,51 @@
|
||||
require 'rails_helper'
|
||||
include Warden::Test::Helpers
|
||||
Warden.test_mode!
|
||||
|
||||
feature 'Join a game', type: :feature, js: true do
|
||||
# before(:each) do
|
||||
# @game = setup_game
|
||||
# @game.reload
|
||||
# @player = @game.controlling_player
|
||||
# signin(@player.user.email,'please123')
|
||||
# #login_as(@player.user, scope: :user)
|
||||
# visit game_path @game
|
||||
# end
|
||||
|
||||
after(:each) do
|
||||
Warden.test_reset!
|
||||
end
|
||||
|
||||
# Scenario: The user joins a game
|
||||
# Given: A joinable game and I am a signed in user
|
||||
# When I click the join game button
|
||||
# Then I see myself in the game
|
||||
scenario 'user can join a game' do
|
||||
@game = FactoryGirl.create :game
|
||||
@user = FactoryGirl.create :user
|
||||
login_as(@user, scope: :user)
|
||||
visit game_path @game
|
||||
click_button "Join"
|
||||
#TODO: Fix this asynchronous race condition
|
||||
visit current_path
|
||||
expect(page).to have_content @user.email
|
||||
end
|
||||
|
||||
# Scenario: The user is unable to join a game if they are already joined
|
||||
# Given: A game I am currently in that is otherwise joinable
|
||||
# When I visit the game path
|
||||
# Then I do not see a Join button
|
||||
scenario 'user can not join a game twice' do
|
||||
@game = FactoryGirl.create :game
|
||||
@user = FactoryGirl.create :user
|
||||
login_as(@user, scope: :user)
|
||||
visit game_path @game
|
||||
click_button "Join"
|
||||
#TODO: Fix this asynchronous race condition
|
||||
visit current_path
|
||||
expect(page).to_not have_content "Join"
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
@ -14,6 +14,30 @@ feature 'Sign Up', :devise do
|
||||
expect(page).to have_content(/.*#{txts[0]}.*|.*#{txts[1]}.*/)
|
||||
end
|
||||
|
||||
# Scenario: Visitor joins a game and then signs up
|
||||
# Given I am not signed in
|
||||
# When I join a game and then sign up
|
||||
# Then I should see myself in that game
|
||||
scenario 'visitor joins a game and then signs up', js: true do
|
||||
visit new_game_path
|
||||
fill_in 'game_title', with: 'Test Game'
|
||||
click_button 'Create Game'
|
||||
click_button 'Join'
|
||||
sign_up_with('test@example.com', 'please123', 'please123')
|
||||
visit games_path
|
||||
click_link 'Test Game'
|
||||
expect(page).to have_content('test@example.com')
|
||||
end
|
||||
|
||||
# # Scenario: Visitor joins a game and then signs in
|
||||
# # Given I am not signed in
|
||||
# # When I join a game and then sign in
|
||||
# # Then I should see myself in that game
|
||||
# scenario 'visitor joins a game and then signs in' do
|
||||
# sign_up_with('test@example.com', 'please123', 'mismatch')
|
||||
# expect(page).to have_content "Password confirmation doesn't match"
|
||||
# end
|
||||
|
||||
# Scenario: Visitor cannot sign up with invalid email address
|
||||
# Given I am not signed in
|
||||
# When I sign up with an invalid email address
|
||||
|
||||
@ -3,7 +3,7 @@ module Features
|
||||
def sign_up_with(email, password, confirmation)
|
||||
visit new_user_registration_path
|
||||
fill_in 'Email', with: email
|
||||
fill_in 'Password', with: password
|
||||
fill_in 'Password', with: password, match: :prefer_exact
|
||||
fill_in 'Password confirmation', with: confirmation
|
||||
click_button 'Sign up'
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user