Better user specs for joining tables
This commit is contained in:
@@ -154,7 +154,8 @@ String.prototype.capitalize = function() {
|
||||
function t(path, vars){
|
||||
vars || (vars = {});
|
||||
var parts = path.split('.');
|
||||
var accessor = '$translations.'+$locale+'["' + parts.join('"]["')+ '"]';
|
||||
var locale = Qstorage.getItem('locale') || 'en';
|
||||
var accessor = '$translations.'+locale+'["' + parts.join('"]["')+ '"]';
|
||||
var result;
|
||||
try{
|
||||
result = eval(accessor);
|
||||
@@ -175,7 +176,6 @@ $.ajaxSetup({
|
||||
}
|
||||
});
|
||||
$(function(){
|
||||
$locale = Qstorage.getItem('locale') || 'en';
|
||||
if(Qstorage.getItem('message')){
|
||||
var container = $('.alert-success');
|
||||
var msg_finder = Qstorage.getItem('message');
|
||||
@@ -186,7 +186,7 @@ $(function(){
|
||||
}
|
||||
if(Qstorage.getItem('list_closed')){
|
||||
var container = $('.alert-error');
|
||||
container.find('div').text($translations[$locale]['messages']['the_list_has_been_closed']);
|
||||
container.find('div').text(t('messages.the_list_has_been_closed'));
|
||||
container.show();
|
||||
Qstorage.removeItem('list_closed');
|
||||
}
|
||||
@@ -194,7 +194,6 @@ $(function(){
|
||||
});
|
||||
function setLocale(locale){
|
||||
Qstorage.setItem('locale', locale);
|
||||
$locale = locale;
|
||||
setTranslations();
|
||||
}
|
||||
function Qupdate(selector){
|
||||
@@ -202,8 +201,9 @@ function Qupdate(selector){
|
||||
}
|
||||
function setTranslations(selector){
|
||||
var list = $('#top-navigation-list');
|
||||
var locale = Qstorage.getItem('locale');
|
||||
list.find('.locale').show();
|
||||
list.find('.locale-'+$locale).hide();
|
||||
list.find('.locale-'+locale).hide();
|
||||
if(selector){
|
||||
$(selector).find('[data-t]').each(function(){$(this).text(t($(this).attr('data-t')))})
|
||||
}else{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
module Admin
|
||||
class UsersController < Admin::ApplicationController
|
||||
skip_before_filter :authenticate_administrator!, only: :test_login
|
||||
skip_before_filter :set_locale, only: :test_login
|
||||
# GET /users
|
||||
# GET /users.json
|
||||
def index
|
||||
@@ -27,9 +28,11 @@ module Admin
|
||||
def test_login
|
||||
if Rails.env.test? and user = User.find_by_email(params[:email])
|
||||
sign_in user
|
||||
end
|
||||
render layout: false
|
||||
else
|
||||
render nothing: true
|
||||
end
|
||||
end
|
||||
|
||||
# GET /users/new
|
||||
# GET /users/new.json
|
||||
|
||||
@@ -24,7 +24,7 @@ private
|
||||
end
|
||||
|
||||
def set_locale
|
||||
I18n.locale = (params[:locale].presence || Rails.configuration.i18n.default_locale).to_sym
|
||||
I18n.locale = (params[:locale].presence || I18n.default_locale).to_sym
|
||||
end
|
||||
|
||||
def layout_by_resource
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<p>{{message}}</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="#" class="btn" onclick="Quser.reject_join_request('{{requester_id}}')" data-dismiss="modal" aria-hidden="true">{{reject}}</a>
|
||||
<a href="#" class="btn btn-primary" onclick="Quser.approve_join_request('{{requester_id}}')" data-dismiss="modal" aria-hidden="true">{{approve}}</a>
|
||||
<a href="#" class="btn reject-join-request-button" onclick="Quser.reject_join_request('{{requester_id}}')" data-dismiss="modal" aria-hidden="true">{{reject}}</a>
|
||||
<a href="#" class="btn btn-primary approve-join-request-button" onclick="Quser.approve_join_request('{{requester_id}}')" data-dismiss="modal" aria-hidden="true">{{approve}}</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
doctype html
|
||||
html
|
||||
head
|
||||
javascript:
|
||||
localStorage.setItem('auth_token', '#{current_user.authentication_token}');
|
||||
localStorage.setItem('user_id', '#{current_user.id}');
|
||||
localStorage.setItem('locale', '#{I18n.default_locale}');
|
||||
|
||||
|
||||
body
|
||||
p Test login page
|
||||
p= "Signed in as: #{current_user.email}"
|
||||
@@ -21,7 +21,6 @@ html lang="en"
|
||||
var QMobile, Qwaiter, Quser;
|
||||
var data_host = 'http://data.qwaiter.com';
|
||||
var event_host = '#{event_host}';
|
||||
var $locale = 'en';
|
||||
var $asset_path = '##assets_path##';
|
||||
var Qstorage = localStorage;
|
||||
- else
|
||||
@@ -29,7 +28,6 @@ html lang="en"
|
||||
var QMobile, Qwaiter, Quser;
|
||||
var data_host = 'http://data.qwaiter.com';
|
||||
var event_host = '#{event_host}';
|
||||
var $locale = 'en';
|
||||
var $asset_path = '/assets/';
|
||||
var Qstorage = localStorage;
|
||||
#{user_dynamic_data_host}
|
||||
@@ -48,8 +46,6 @@ html lang="en"
|
||||
root_url: function(){return '/user'},
|
||||
goHome: function(){ redirect_to('user_root')},
|
||||
connection_problem: function(){alert('There is a problem connecting to the server')},
|
||||
locale: function(){ return $locale || ($locale = 'en')},
|
||||
setLocale: function(locale){$locale = locale; return locale},
|
||||
token: function(){return this.auth_token},
|
||||
setUserId: function(id){ this.stored_user_id = id},
|
||||
user_id: function(){return this.stored_user_id },
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
.form-actions
|
||||
= link_to t('user.join_occupied_table.back'), user_root_path, class: :btn, data: {t: 'join_request.requestor.go_back'}
|
||||
'
|
||||
button.btn.btn-primary onclick="Quser.show_table_products()" data-t='join_request.requestor.show_the_products'= t('user.join_occupied_table.show_the_products')
|
||||
button.btn.btn-primary.show-menu-button onclick="Quser.show_table_products()" data-t='join_request.requestor.show_the_products'= t('user.join_occupied_table.show_the_products')
|
||||
'
|
||||
button.btn.btn-warning onClick="Quser.join_occupied_table()" data-t='join_request.requestor.join_this_table'= t('user.join_occupied_table.join_this_table')
|
||||
button.btn.btn-warning.join-table-button onClick="Quser.join_occupied_table()" data-t='join_request.requestor.join_this_table'= t('user.join_occupied_table.join_this_table')
|
||||
#join-occupied-table-progress-container
|
||||
- onload_javascript 'Quser.watch_events()'
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
Feature: Joining an occupied table
|
||||
|
||||
@javascript
|
||||
Scenario: Happy flow
|
||||
Given There is an open supplier with a menu
|
||||
And there is a signed in user with an active order
|
||||
And I am on the user homepage
|
||||
When another user scans the QR code on the table
|
||||
And the other user clicks the join table button
|
||||
Then the other user should see a join table waiting message
|
||||
And the original user should see a join request message
|
||||
When the original user approves the other user's join request
|
||||
Then the original user should not see the join request anymore
|
||||
And the other user should be added to the active list
|
||||
And the other user should be redirected to the user menu page
|
||||
|
||||
@javascript
|
||||
Scenario: Original user rejects the join request
|
||||
Given There is an open supplier with a menu
|
||||
And there is a signed in user with an active order
|
||||
And I am on the user homepage
|
||||
When another user scans the QR code on the table
|
||||
And the other user clicks the join table button
|
||||
Then the other user should see a join table waiting message
|
||||
And the original user should see a join request message
|
||||
When the original user rejects the other user's join request
|
||||
Then the original user should not see the join request anymore
|
||||
And the other user should not be added to the active list
|
||||
And the other user should see a join reject message
|
||||
|
||||
#@javascript
|
||||
#Scenario: The other user just wants to see the table menu
|
||||
#Given There is an open supplier with a menu
|
||||
#And there is a signed in user with an active order
|
||||
#And I am on the user homepage
|
||||
#When another user scans the QR code on the table
|
||||
#And the other user clicks the show me the menu button
|
||||
@@ -7,6 +7,13 @@ step "the list is marked as in need of payment" do
|
||||
@list.needs_payment!
|
||||
end
|
||||
|
||||
step "the user has an active list" do
|
||||
@list = create :list, supplier: @supplier, table: @table, user_ids: [@user.id]
|
||||
@user.reload
|
||||
@user.active_list_id = @list.id
|
||||
@user.save
|
||||
end
|
||||
|
||||
step "the list should be marked as closed" do
|
||||
@list.reload
|
||||
@list.state.should == 'closed'
|
||||
@@ -22,3 +29,17 @@ end
|
||||
step "I am signed in as a user" do
|
||||
step "I visit the user obtain token path"
|
||||
end
|
||||
|
||||
step "the other user should be added to the active list" do
|
||||
@other_user.reload
|
||||
@list.reload
|
||||
@other_user.active_list_id.should == @list.id
|
||||
@list.user_ids.should =~ [@user.id, @other_user.id]
|
||||
end
|
||||
|
||||
step "the other user should not be added to the active list" do
|
||||
@other_user.reload
|
||||
@list.reload
|
||||
@other_user.active_list_id.should be_nil
|
||||
@list.user_ids.should == [@user.id]
|
||||
end
|
||||
@@ -3,7 +3,20 @@ step "the user scans a table QR code" do
|
||||
page.execute_script "Quser.actions_for_table({table_id: '#{@table.id}'})"
|
||||
end
|
||||
|
||||
step "another user scans the QR code on the table" do
|
||||
step 'there is another signed in user user'
|
||||
visit user_root_path
|
||||
page.execute_script "Quser.actions_for_table({table_id: '#{@table.id}'})"
|
||||
end
|
||||
|
||||
|
||||
step 'there is a table' do
|
||||
step 'there is a section'
|
||||
@table ||= create :table, section: @section, supplier: @supplier
|
||||
end
|
||||
|
||||
step "the other user should see a join table waiting message" do
|
||||
#waiting_text = I18n.t('') #TODO: make better user client translation system, similar to supplier
|
||||
waiting_text = page.evaluate_script(%|t('join_request.requestor.waiting_for_confirmation')|)
|
||||
page.should have_content waiting_text
|
||||
end
|
||||
|
||||
@@ -10,3 +10,16 @@ step "the user should be redirected to the archived list path" do
|
||||
route_should_be 'user#history_list'
|
||||
page.should have_selector ".order-row-#{@order.id}"
|
||||
end
|
||||
|
||||
step 'there is another user' do
|
||||
@other_user ||= create :user
|
||||
end
|
||||
|
||||
step "the other user clicks the join table button" do
|
||||
find('.join-table-button').click
|
||||
end
|
||||
|
||||
step "the other user should be redirected to the user menu page" do
|
||||
Capybara.session_name = :other_user
|
||||
route_should_be 'user#list_products'
|
||||
end
|
||||
|
||||
@@ -23,6 +23,12 @@ step "I should be signed in as a user through facebook" do
|
||||
step "the newly created user info should be stored in the local storage"
|
||||
end
|
||||
|
||||
step 'there is another signed in user user' do
|
||||
Capybara.session_name = :other_user
|
||||
step 'there is another user'
|
||||
visit test_login_admin_users_path(email: @other_user.email)
|
||||
end
|
||||
|
||||
step "I should be redirected to the user home" do
|
||||
page.current_path.should == user_root_path
|
||||
end
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
step "the original user should see a join request message" do
|
||||
Capybara.session_name = :default
|
||||
request_text = page.evaluate_script(%|t('join_request.body', {email: '#{@other_user.email}'})|)
|
||||
request_text.should be_present
|
||||
page.should have_content request_text
|
||||
end
|
||||
|
||||
step "the original user should not see the join request anymore" do
|
||||
Capybara.session_name = :default
|
||||
request_text = page.evaluate_script(%|t('join_request.body', {email: '#{@other_user.email}'})|)
|
||||
request_text.should be_present
|
||||
page.should_not have_content request_text
|
||||
end
|
||||
|
||||
step "the original user approves the other user's join request" do
|
||||
find('.approve-join-request-button').click
|
||||
end
|
||||
|
||||
step "the original user rejects the other user's join request" do
|
||||
find('.reject-join-request-button').click
|
||||
end
|
||||
|
||||
step "the other user should see a join reject message" do
|
||||
Capybara.session_name = :other_user
|
||||
reject_text = I18n.t('messages.join_request_rejected')
|
||||
reject_text.should be_present
|
||||
reject_text.should_not include 'translation'
|
||||
page.should have_content reject_text
|
||||
end
|
||||
@@ -15,3 +15,15 @@ step "the user clicks on the user order button" do
|
||||
find('#active-order-table .btn-primary').click
|
||||
sleep 1
|
||||
end
|
||||
|
||||
step "the user has an active order" do
|
||||
step 'there is a section'
|
||||
step 'there is a table'
|
||||
step 'the user has an active list'
|
||||
|
||||
end
|
||||
|
||||
step "there is a signed in user with an active order" do
|
||||
step "I am signed in as a user"
|
||||
step "the user has an active order"
|
||||
end
|
||||
|
||||
+2
-1
@@ -12,7 +12,7 @@ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
||||
#Dir[Rails.root.join("spec/factories/**/*.rb")].each {|f| require f }
|
||||
Dir.glob("spec/acceptance_steps/**/*steps.rb") { |f| load f, true }
|
||||
|
||||
I18n.locale = Rails.configuration.i18n.default_locale
|
||||
I18n.locale =I18n.default_locale
|
||||
Devise.stretches = 1
|
||||
Capybara.javascript_driver = :webkit
|
||||
#Capybara.default_driver = :selenium
|
||||
@@ -113,6 +113,7 @@ RSpec.configure do |config|
|
||||
|
||||
config.before :each, type: :feature do
|
||||
#Supplier.any_instance.stub send_confirmation_instructions: true
|
||||
Capybara.session_name = :default
|
||||
end
|
||||
|
||||
# If true, the base class of anonymous controllers will be inferred
|
||||
|
||||
Reference in New Issue
Block a user