From 0415603a49772ae816f3c16d7e68883d2e08fc8c Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Thu, 13 Aug 2015 15:08:04 +0200 Subject: [PATCH] Green specs for ember 1.13 --- Gemfile | 2 +- Gemfile.lock | 8 +++++++- app/assets/javascripts/user/app/app.js.coffee | 1 + .../modifications/controller_modifications.js.coffee | 4 +++- spec/acceptance/users/sign_up_with_facebook.feature | 2 ++ spec/acceptance_steps/suppliers/section_view_steps.rb | 3 +-- spec/support/ember_helpers.rb | 11 ++++++----- 7 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index 0d1a638d..f900fcc3 100644 --- a/Gemfile +++ b/Gemfile @@ -30,7 +30,7 @@ group :assets do #gem 'capistrano-local-precompile', require: false # See https://github.com/sstephenson/execjs#readme for more supported runtimes - #gem 'therubyracer', platforms: :ruby + gem 'therubyracer', platforms: :ruby gem 'uglifier', '>= 1.0.3' diff --git a/Gemfile.lock b/Gemfile.lock index 31d4414a..043ec1fd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -187,7 +187,7 @@ GEM ember-source (>= 1.8.0) jquery-rails (>= 1.0.17) railties (>= 3.1) - ember-source (1.13.7) + ember-source (1.13.8) ember-validations-rails (1.0.0) railties erubis (2.7.0) @@ -252,6 +252,7 @@ GEM addressable (~> 2.3) letter_opener (1.4.1) launchy (~> 2.2) + libv8 (3.16.14.11) loofah (2.0.2) nokogiri (>= 1.5.9) mail (2.6.3) @@ -336,6 +337,7 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.4.2) + ref (2.0.0) responders (2.1.0) railties (>= 4.2.0, < 5) rest-client (1.8.0) @@ -419,6 +421,9 @@ GEM temple (0.7.6) test_squad (0.0.1) rails + therubyracer (0.12.2) + libv8 (~> 3.16.14.0) + ref thor (0.19.1) thread_safe (0.3.5) tilt (1.4.1) @@ -518,6 +523,7 @@ DEPENDENCIES spring-commands-rspec sucker_punch test_squad + therubyracer turnip uglifier (>= 1.0.3) web-console (~> 2.0.0) diff --git a/app/assets/javascripts/user/app/app.js.coffee b/app/assets/javascripts/user/app/app.js.coffee index 7e78a59b..d3b1a1ed 100644 --- a/app/assets/javascripts/user/app/app.js.coffee +++ b/app/assets/javascripts/user/app/app.js.coffee @@ -27,6 +27,7 @@ Ember.Application.initializer application.register('global:variables', Globals, {singleton: true}) application.inject('controller', 'globals', 'global:variables') application.inject('component', 'globals', 'global:variables') + application.inject('route', 'globals', 'global:variables') @App = Ember.Application.create LOG_TRANSITIONS: true diff --git a/app/assets/javascripts/user/app/modifications/controller_modifications.js.coffee b/app/assets/javascripts/user/app/modifications/controller_modifications.js.coffee index 27dbe8e3..b378194a 100644 --- a/app/assets/javascripts/user/app/modifications/controller_modifications.js.coffee +++ b/app/assets/javascripts/user/app/modifications/controller_modifications.js.coffee @@ -2,8 +2,10 @@ ControllerExtensions = Ember.Mixin.create needs: ['application'] ajaxError: (callback)-> handler = (emberError)=> + emberError = emberError.errors[0] if emberError.errors and emberError.errors.length console.log "Error: status #{emberError.status}" - if emberError.status is 401 + status = parseInt(emberError.status) + if status is 401 App.__container__.lookup('route:application').unauthorized() else callback.call(@, emberError) diff --git a/spec/acceptance/users/sign_up_with_facebook.feature b/spec/acceptance/users/sign_up_with_facebook.feature index 30d5f194..0f12e13b 100644 --- a/spec/acceptance/users/sign_up_with_facebook.feature +++ b/spec/acceptance/users/sign_up_with_facebook.feature @@ -16,6 +16,7 @@ Feature: Sign up as user using facebook Given there is a confirmed and open supplier And there is a facebook user And the user has an active order + And there is no user information stored in the local storage #When I visit the user obtain token path When the user is on the homepage Then the user is redirected to the sign in page @@ -38,6 +39,7 @@ Feature: Sign up as user using facebook Given there is a confirmed and open supplier And there is a instagram user And the user has an active order + And there is no user information stored in the local storage #When I visit the user obtain token path When the user is on the homepage Then the user is redirected to the sign in page diff --git a/spec/acceptance_steps/suppliers/section_view_steps.rb b/spec/acceptance_steps/suppliers/section_view_steps.rb index d3fd6390..fbab147b 100644 --- a/spec/acceptance_steps/suppliers/section_view_steps.rb +++ b/spec/acceptance_steps/suppliers/section_view_steps.rb @@ -30,8 +30,7 @@ step "the section table should not be marked as in need of help" do end step 'the table should be marked as occupied and having an active order' do - classes = find(".section-table-#{@table.id}")['class'].split(/\s+/) - expect(classes & %w[occupied active_order]).to eq %w[occupied active_order] + assert_element_class ".section-table-#{@table.id}", %w[occupied active_order] end step "I click on section table as a supplier" do diff --git a/spec/support/ember_helpers.rb b/spec/support/ember_helpers.rb index 676bb12e..c2c50882 100644 --- a/spec/support/ember_helpers.rb +++ b/spec/support/ember_helpers.rb @@ -15,16 +15,17 @@ module SpecEmberHelpers JSON.parse(h) end - def assert_element_class(selector, class_name) + def assert_element_class(selector, expected_class_names) find selector # capybara wait for element time = 0 - classes = page.evaluate_script("$('#{selector}').attr('class')") - while !classes.include?(class_name) and time < 10 + expected_class_names = Array.wrap(expected_class_names).sort + found_classes = page.evaluate_script("$('#{selector}').attr('class')").to_s.split(/\s+/).sort + while (found_classes & expected_class_names) != expected_class_names and time < 10 sleep 0.1 - classes = page.evaluate_script("$('#{selector}').attr('class')") + found_classes = page.evaluate_script("$('#{selector}').attr('class')").to_s.split(/\s+/).sort time += 1 end - classes.should include class_name + (found_classes & expected_class_names).sort.should eq expected_class_names end # expect_that_eventually selector: '.supplier-orders-placed-count-number', has_text: "10"