diff --git a/app/assets/javascripts/user/application.js.erb b/app/assets/javascripts/user/application.js.erb index 7589c2a5..fab51939 100644 --- a/app/assets/javascripts/user/application.js.erb +++ b/app/assets/javascripts/user/application.js.erb @@ -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{ diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 484a2f45..e6bd94b3 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -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,8 +28,10 @@ module Admin def test_login if Rails.env.test? and user = User.find_by_email(params[:email]) sign_in user + render layout: false + else + render nothing: true end - render nothing: true end # GET /users/new diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index caaf3e66..49522182 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/templates/user/_join_request.mustache b/app/templates/user/_join_request.mustache index a85e4d59..29bbf187 100644 --- a/app/templates/user/_join_request.mustache +++ b/app/templates/user/_join_request.mustache @@ -7,7 +7,7 @@
{{message}}
diff --git a/app/views/admin/users/test_login.html.slim b/app/views/admin/users/test_login.html.slim new file mode 100644 index 00000000..cf10fb94 --- /dev/null +++ b/app/views/admin/users/test_login.html.slim @@ -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}" diff --git a/app/views/layouts/phone.html.slim b/app/views/layouts/phone.html.slim index 0709122f..8878bc9e 100644 --- a/app/views/layouts/phone.html.slim +++ b/app/views/layouts/phone.html.slim @@ -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 }, diff --git a/app/views/user/join_occupied_table.html.slim b/app/views/user/join_occupied_table.html.slim index b3a9d8d6..50826241 100644 --- a/app/views/user/join_occupied_table.html.slim +++ b/app/views/user/join_occupied_table.html.slim @@ -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()' diff --git a/spec/acceptance/users/join_an_occupied_table.feature b/spec/acceptance/users/join_an_occupied_table.feature new file mode 100644 index 00000000..a51f459c --- /dev/null +++ b/spec/acceptance/users/join_an_occupied_table.feature @@ -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 diff --git a/spec/acceptance_steps/list_steps.rb b/spec/acceptance_steps/global_list_steps.rb similarity index 57% rename from spec/acceptance_steps/list_steps.rb rename to spec/acceptance_steps/global_list_steps.rb index 63a81fd3..49d38f74 100644 --- a/spec/acceptance_steps/list_steps.rb +++ b/spec/acceptance_steps/global_list_steps.rb @@ -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 diff --git a/spec/acceptance_steps/global_table_steps.rb b/spec/acceptance_steps/global_table_steps.rb index ab8d87ee..5ea19b40 100644 --- a/spec/acceptance_steps/global_table_steps.rb +++ b/spec/acceptance_steps/global_table_steps.rb @@ -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 diff --git a/spec/acceptance_steps/global_user_steps.rb b/spec/acceptance_steps/global_user_steps.rb index 84584e07..7a51c6ba 100644 --- a/spec/acceptance_steps/global_user_steps.rb +++ b/spec/acceptance_steps/global_user_steps.rb @@ -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 diff --git a/spec/acceptance_steps/users/authentication_steps.rb b/spec/acceptance_steps/users/authentication_steps.rb index 3e6795be..c7d1768d 100644 --- a/spec/acceptance_steps/users/authentication_steps.rb +++ b/spec/acceptance_steps/users/authentication_steps.rb @@ -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 diff --git a/spec/acceptance_steps/users/join_request_steps.rb b/spec/acceptance_steps/users/join_request_steps.rb new file mode 100644 index 00000000..b40654ed --- /dev/null +++ b/spec/acceptance_steps/users/join_request_steps.rb @@ -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 diff --git a/spec/acceptance_steps/users/order_products_steps.rb b/spec/acceptance_steps/users/order_products_steps.rb index ae63459d..9b1671aa 100644 --- a/spec/acceptance_steps/users/order_products_steps.rb +++ b/spec/acceptance_steps/users/order_products_steps.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9a352d18..24d7a62e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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