refactor and move to selenium

This commit is contained in:
2015-01-21 18:23:47 +01:00
parent c688f0353b
commit 9a8c364d38
24 changed files with 174 additions and 116 deletions
+2
View File
@@ -37,3 +37,5 @@ chromedriver.log
/old_cap /old_cap
gem_graph.png gem_graph.png
erl_crash.dump erl_crash.dump
/db/*.couch
/db/*_design
+27 -28
View File
@@ -1,28 +1,27 @@
FROM rails:onbuild FROM ruby:2.2.0
#FROM bterkuile/ruby-base
# # throw errors if Gemfile has been modified since Gemfile.lock
#MAINTAINER Benjamin ter Kuile <bterkuile@gmail.com> RUN bundle config --global frozen 1
#
## Add 'web' user which will run the application RUN mkdir -p /usr/src/app/vendor
#RUN adduser web --home /home/web --shell /bin/bash --disabled-password --gecos ""
# WORKDIR /usr/src/app
## Separate Gemfile ADD so that `bundle install` can be cached more effectively
#ADD Gemfile /var/www/ # Test
#ADD Gemfile.lock /var/www/ RUN apt-get update && apt-get install -y qt5-default libqt5webkit5-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
#RUN chown -R web:web /var/www &&\ # Standard
# mkdir -p /var/bundle &&\ RUN apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/*
# chown -R web:web /var/bundle RUN apt-get update && apt-get install -y mysql-client postgresql-client sqlite3 --no-install-recommends && rm -rf /var/lib/apt/lists/*
#RUN su -c "cd /var/www && bundle install --deployment --without development test assets --path /var/bundle" -s /bin/bash -l web # Specific
# RUN apt-get update && apt-get install -y dos2unix --no-install-recommends && rm -rf /var/lib/apt/lists/*
## Add application source
#ADD . /var/www COPY Gemfile /usr/src/app/
#RUN chown -R web:web /var/www COPY Gemfile.lock /usr/src/app/
# #COPY vendor/cache /usr/src/app/vendor/cache
#USER web #RUN bundle install --local
# RUN bundle install
#WORKDIR /var/www
# COPY . /usr/src/app
##VOLUME ['/Users/bterkuile/companytools/development/rails/mozo_bar/public/system:/var/www/public/system']
#EXPOSE 3000 EXPOSE 3000
# CMD ["rails", "server", '-b', '0.0.0.0']
#CMD ["bundle", "exec", "foreman", "start"]
+2 -1
View File
@@ -104,7 +104,8 @@ group :test do
# gem 'database_cleaner' # gem 'database_cleaner'
# gem 'capybara' #, '2.0.3' # gem 'capybara' #, '2.0.3'
#gem 'selenium-webdriver' #gem 'selenium-webdriver'
gem 'capybara-webkit' #, '~>0.14.2' # version 1.1.0 does not yet compile in mavericks #gem 'capybara-webkit' #, '~>0.14.2' # version 1.1.0 does not yet compile in mavericks
gem 'selenium-webdriver'
gem 'capybara-screenshot' gem 'capybara-screenshot'
gem 'turnip' gem 'turnip'
gem 'rspec-its' gem 'rspec-its'
+11 -4
View File
@@ -142,9 +142,8 @@ GEM
capybara (>= 1.0, < 3) capybara (>= 1.0, < 3)
colored colored
launchy launchy
capybara-webkit (1.3.1) childprocess (0.5.5)
capybara (>= 2.0.2, < 2.5.0) ffi (~> 1.0, >= 1.0.11)
json
climate_control (0.0.3) climate_control (0.0.3)
activesupport (>= 3.0) activesupport (>= 3.0)
cocaine (0.5.5) cocaine (0.5.5)
@@ -222,6 +221,7 @@ GEM
faye-websocket (0.9.2) faye-websocket (0.9.2)
eventmachine (>= 0.12.0) eventmachine (>= 0.12.0)
websocket-driver (>= 0.5.1) websocket-driver (>= 0.5.1)
ffi (1.9.6)
font-awesome-rails (4.2.0.0) font-awesome-rails (4.2.0.0)
railties (>= 3.2, < 5.0) railties (>= 3.2, < 5.0)
foundation-rails (5.5.0.0) foundation-rails (5.5.0.0)
@@ -369,6 +369,7 @@ GEM
rspec-support (~> 3.1.0) rspec-support (~> 3.1.0)
rspec-support (3.1.2) rspec-support (3.1.2)
ruby-progressbar (1.7.1) ruby-progressbar (1.7.1)
rubyzip (1.1.6)
safe_yaml (1.0.4) safe_yaml (1.0.4)
sass (3.3.14) sass (3.3.14)
sass-rails (5.0.0.beta1) sass-rails (5.0.0.beta1)
@@ -376,6 +377,11 @@ GEM
sass (~> 3.2) sass (~> 3.2)
sprockets (~> 2.12) sprockets (~> 2.12)
sprockets-rails (>= 2.0, < 4.0) sprockets-rails (>= 2.0, < 4.0)
selenium-webdriver (2.44.0)
childprocess (~> 0.5)
multi_json (~> 1.0)
rubyzip (~> 1.0)
websocket (~> 1.0)
simplecov (0.9.1) simplecov (0.9.1)
docile (~> 1.1.0) docile (~> 1.1.0)
multi_json (~> 1.0) multi_json (~> 1.0)
@@ -431,6 +437,7 @@ GEM
webmock (1.20.4) webmock (1.20.4)
addressable (>= 2.3.6) addressable (>= 2.3.6)
crack (>= 0.3.2) crack (>= 0.3.2)
websocket (1.2.1)
websocket-driver (0.5.1) websocket-driver (0.5.1)
websocket-extensions (>= 0.1.0) websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.1) websocket-extensions (0.1.1)
@@ -450,7 +457,6 @@ DEPENDENCIES
capistrano-rails (~> 1.1) capistrano-rails (~> 1.1)
capistrano-rvm (~> 0.1) capistrano-rvm (~> 0.1)
capybara-screenshot capybara-screenshot
capybara-webkit
cmtool! cmtool!
coffee-rails coffee-rails
couch_potato! couch_potato!
@@ -484,6 +490,7 @@ DEPENDENCIES
rspec-its rspec-its
rspec-rails rspec-rails
sass-rails (= 5.0.0.beta1) sass-rails (= 5.0.0.beta1)
selenium-webdriver
simplecov simplecov
simply_stored! simply_stored!
slim-rails slim-rails
@@ -0,0 +1,9 @@
App.MenuProductCategoriesComponent = Ember.Component.extend
orderProducts: false
timestamp: 0 # invalidation param
active_product_categories: (->
list = @get('product_categories')
).property('product_categories.@each', 'timestamp')
actions:
toggleProductCategory: (product_category) -> product_category.toggleProperty('collapsed')
@@ -0,0 +1,14 @@
App.MenuProductComponent = Ember.Component.extend
tagName: 'li'
classNameBindings: ['specific_id']
specific_id: (-> "order-product-#{@get('product.id')}").property('product.id')
orderProducts: false
target: -> @get('parentView.targetObject')
actions:
addProduct: (product)->
if existing = @target().store.all('product_order').find((po)-> po.get('product') == product and not po.get('order'))
existing.increment()
else
@target().store.createRecord 'product_order', product: product, price: product.get('price')
showProductDescription: (product)->
@target().modal 'product_info', model: product, title: product.get('name')
@@ -108,6 +108,8 @@ App.ApplicationController = Ember.Controller.extend
if error_list = @store.all('list').findBy('id', 'current') if error_list = @store.all('list').findBy('id', 'current')
error_list.eraseRecord() error_list.eraseRecord()
@set 'list', null @set 'list', null
@redirect_to 'index' switch @currentRouteName
when 'table' then # nothing
else @redirect_to 'index'
@store.find('list', 'current').then(success, error) @store.find('list', 'current').then(success, error)
@@ -17,15 +17,6 @@ App.TableController = Ember.ObjectController.extend
if @get('model.occupied') then true else false # no point in joining tables that are not occupied if @get('model.occupied') then true else false # no point in joining tables that are not occupied
).property('controllers.application.list.id', 'supplier.can_take_orders', 'model.occupied', 'model.id', 'controllers.application.list.table.id') ).property('controllers.application.list.id', 'supplier.can_take_orders', 'model.occupied', 'model.id', 'controllers.application.list.table.id')
actions: actions:
addProduct: (product)->
if existing = @store.all('product_order').find((po)-> po.get('product') == product and not po.get('order'))
existing.increment()
else
@store.createRecord 'product_order', product: product, price: product.get('price')
joinOccupiedTable: -> joinOccupiedTable: ->
Ember.$.post("#{$data_host}/user/join_occupied_table.json", table_id: @get('model.id')) Ember.$.post("#{$data_host}/user/join_occupied_table.json", table_id: @get('model.id'))
@set 'controllers.application.join_request_sent', true # keeps the button deactivated @set 'controllers.application.join_request_sent', true # keeps the button deactivated
toggleProductCategory: (product_category)->
product_category.set 'collapsed', not product_category.get('collapsed')
showProductDescription: (product)->
@modal 'product_info', model: product, title: product.get('name')
@@ -3,7 +3,7 @@ ControllerExtensions = Ember.Mixin.create
ajaxError: (callback)-> ajaxError: (callback)->
handler = (emberError)=> handler = (emberError)=>
console.log "Error: status #{emberError.status}" console.log "Error: status #{emberError.status}"
if emberError.status == 401 if emberError.status is 401
App.__container__.lookup('route:application').unauthorized() App.__container__.lookup('route:application').unauthorized()
else else
callback.call(@, emberError) callback.call(@, emberError)
@@ -0,0 +1,15 @@
each product_category in active_product_categories
.product-category-container
if orderProducts
h4 OderProducts
if product_category.products
h4.product_category-title{action "toggleProductCategory" product_category}
if product_category.collapsed
span.icon.collapsed
else
span.icon
= product_category.name
unless product_category.collapsed
ul.product_category-products
each product in product_category.products
= menu-product product=product orderProducts=orderProducts
@@ -0,0 +1,12 @@
if product.description
button.show-product-description{action "showProductDescription" product}
span
else
span.no-product-description
if orderProducts
a{action "addProduct" product}= product.name
button.add-product-to-list{action "addProduct" product}
span
else
span= product.name
span.product-price.currency=currency product.price
@@ -12,41 +12,7 @@
else else
button.join-table-button{action "joinOccupiedTable"}=t 'join_request.requestor.join_this_table' button.join-table-button{action "joinOccupiedTable"}=t 'join_request.requestor.join_this_table'
if tableCanTakeOrders if tableCanTakeOrders
.large-6.columns .large-6.columns= menu-product-categories product_categories=supplier.product_categories orderProducts=true
each product_category in supplier.product_categories
.product-category-container
if product_category.products
h4.product_category-title{action "toggleProductCategory" product_category}
if product_category.collapsed
span.icon.collapsed
else
span.icon
= product_category.name
unless product_category.collapsed
ul.product_category-products
each product in product_category.products
li class="order-product-#{unbound product.id}"
if product.description
button.show-product-description{action "showProductDescription" product}
span
else
span.no-product-description
a{action "addProduct" product}= product.name
button.add-product-to-list{action "addProduct" product}
span
span.product-price.currency=currency product.price
.large-6.columns= render 'product_orders' .large-6.columns= render 'product_orders'
else else
.large12 .large12= menu-product-categories product_categories=supplier.product_categories orderProducts=false
each product_category in supplier.product_categories
if product_category.products
.product_category-container
h4.product-category-title= product_category.name
ul.product_category-products
each product in product_category.products
li class="order-product-#{unbound product.id}"
if product.description
button.show-product-description{action "showProductDescription" product}
span
span= product.name
span.right.currency=currency product.price
@@ -1,6 +1,8 @@
module Admin module Admin
class SuppliersController < Admin::ApplicationController class SuppliersController < Admin::ApplicationController
before_filter :set_relation_options, only: [:new, :edit, :create, :update] before_filter :set_relation_options, only: [:new, :edit, :create, :update]
skip_before_filter :authenticate_administrator!, only: :test_login
skip_before_filter :set_locale, only: :test_login
# GET /suppliers # GET /suppliers
# GET /suppliers.json # GET /suppliers.json
def index def index
@@ -12,6 +14,13 @@ module Admin
end end
end end
def test_login
if Rails.env.test? and supplier = Supplier.find_by_email(params[:email])
sign_in supplier
end
render nothing: true
end
# GET /suppliers/1 # GET /suppliers/1
# GET /suppliers/1.json # GET /suppliers/1.json
def show def show
+2
View File
@@ -50,6 +50,8 @@ class InMemoryQCounter
def reload_stats! def reload_stats!
require 'yaml' require 'yaml'
require 'couchrest' require 'couchrest'
require 'pry'
binding.pry
couch_settings_path = File.join(ENV['MOZO_PATH'], 'config/couchdb.yml') couch_settings_path = File.join(ENV['MOZO_PATH'], 'config/couchdb.yml')
puts "Couch settings path: #{couch_settings_path}" puts "Couch settings path: #{couch_settings_path}"
puts "Environment: #{environment.inspect}" puts "Environment: #{environment.inspect}"
+5 -1
View File
@@ -9,7 +9,11 @@ Qwaiter::Application.routes.draw do
get :test_login get :test_login
end end
end end
resources :suppliers resources :suppliers do
collection do
get :test_login
end
end
resources :tables resources :tables
resources :orders resources :orders
resources :sections resources :sections
+6 -3
View File
@@ -1,9 +1,12 @@
db: db:
image: bterkuile/couchdb image: bterkuile/couchdb
volumes: volumes:
- .db:/usr/local/var/lib/couchdb - db:/usr/local/var/lib/couchdb
expose: expose:
- 5984 - 5984
net: host
counters:
image: ruby:2.2
web: web:
build: . build: .
#command: bundle exec unicorn -p 3000 -c ./config/unicorn.rb #command: bundle exec unicorn -p 3000 -c ./config/unicorn.rb
@@ -12,5 +15,5 @@ web:
- .:/usr/src/app - .:/usr/src/app
ports: ports:
- "3000:3000" - "3000:3000"
links: #links:
- db # #- db
+10 -4
View File
@@ -54,6 +54,7 @@ Feature: Supplier main board
Given there is an active list and order Given there is an active list and order
And there is another section with table And there is another section with table
And I am signed in as supplier And I am signed in as supplier
When I visit the supplier root path
And a new order on a table in another section is created And a new order on a table in another section is created
Then I should see the list and the new list Then I should see the list and the new list
And I should see the order and the new order And I should see the order and the new order
@@ -69,7 +70,8 @@ Feature: Supplier main board
Scenario: Selecting a specific section and jumping towards section view Scenario: Selecting a specific section and jumping towards section view
Given there is an active list and order Given there is an active list and order
And I am signed in as supplier And I am signed in as supplier
When I select the section in the supplier dashboard When I visit the supplier root path
And I select the section in the supplier dashboard
And I click on the section main board section jumper And I click on the section main board section jumper
Then I should be redirected to the supplier section view Then I should be redirected to the supplier section view
@@ -78,6 +80,7 @@ Feature: Supplier main board
Given there is an active list and order Given there is an active list and order
And there is another section with table And there is another section with table
And I am signed in as supplier And I am signed in as supplier
When I visit the supplier root path
# wait until page is fully loaded, could be a pure ruby command inside a within :selector statement since the browser will wait for the selector to be present and then the lists are loaded # wait until page is fully loaded, could be a pure ruby command inside a within :selector statement since the browser will wait for the selector to be present and then the lists are loaded
And I wait 4 seconds And I wait 4 seconds
When the active list changes to another table in another section When the active list changes to another table in another section
@@ -89,7 +92,8 @@ Feature: Supplier main board
Scenario: Remove an order Scenario: Remove an order
Given there is an active list and order Given there is an active list and order
And I am signed in as supplier And I am signed in as supplier
When the supplier marks the order as wrong in the main board view When I visit the supplier root path
And the supplier marks the order as wrong in the main board view
Then the supplier main board order should not be visible anymore Then the supplier main board order should not be visible anymore
And the supplier main board list total should be updated And the supplier main board list total should be updated
And the supplier placed orders counter should be reduced And the supplier placed orders counter should be reduced
@@ -98,7 +102,8 @@ Feature: Supplier main board
Scenario: Closing list with active orders updates supplier counters Scenario: Closing list with active orders updates supplier counters
Given there is an active list and order Given there is an active list and order
And I am signed in as supplier And I am signed in as supplier
When I click on the close list button in the supplier dashboard When I visit the supplier root path
And I click on the close list button in the supplier dashboard
And confirm the supplier close list modal And confirm the supplier close list modal
Then the supplier placed orders counter should be reduced Then the supplier placed orders counter should be reduced
@@ -107,7 +112,8 @@ Feature: Supplier main board
Given there is an active list and order Given there is an active list and order
And there is another section with table And there is another section with table
And I am signed in as supplier And I am signed in as supplier
When a new order on a table in another section is created When I visit the supplier root path
And a new order on a table in another section is created
Then I should see the list and the new list Then I should see the list and the new list
And I should see the order and the new order And I should see the order and the new order
When I select the section in the supplier dashboard When I select the section in the supplier dashboard
@@ -5,8 +5,8 @@ Feature: Adding product category
Given there is a confirmed and open supplier Given there is a confirmed and open supplier
And I am signed in as supplier And I am signed in as supplier
#And there are 2 supplier products #And there are 2 supplier products
And the supplier visits the menu page When the supplier visits the menu page
When the supplier clicks on the new product category button And the supplier clicks on the new product category button
And the supplier fills in the new product category form selecting not available on tuesdays And the supplier fills in the new product category form selecting not available on tuesdays
And the supplier submits the product category form And the supplier submits the product category form
Then then new product category with proper properties should have been created Then then new product category with proper properties should have been created
@@ -1,6 +1,8 @@
step "I am signed in as supplier" do step "I am signed in as supplier" do
step 'visit the supplier sign in path'
find('#supplier_email').set @supplier.email visit test_login_admin_suppliers_path(email: @supplier.email)
find('#supplier_password').set @supplier_password #step 'visit the supplier sign in path'
click_on 'Inloggen' #find('#supplier_email').set @supplier.email
#find('#supplier_password').set @supplier_password
#click_on 'Inloggen'
end end
@@ -1,29 +1,27 @@
step "the section table should be positioned in the section" do step "the section table should be positioned in the section" do
table = page.find(".section-table-#{@table.id}") page.find(".section-table-#{@table.id}") # wait for table presence
left = table['style'].to_s.match(/left:(\d+)/)
left.should be_present left = page.evaluate_script("$('.section-table-#{@table.id}').position().left")
left[1].to_i.should > 10 left.to_i.should > 0
top = table['style'].to_s.match(/top:(\d+)/)
top.should be_present top = page.evaluate_script("$('.section-table-#{@table.id}').position().top")
top[1].to_i.should > 10 top.to_i.should > 0
end end
step "the section table should be marked as having an active order" do step "the section table should be marked as having an active order" do
table = page.find(".section-table-#{@table.id}") assert_element_class ".section-table-#{@table.id}", 'active_order'
table['class'].should include 'active_order'
end end
step "the section table should still be marked as having an active order" do step "the section table should still be marked as having an active order" do
step "the section table should be marked as having an active order" step "the section table should be marked as having an active order"
end end
step "the section table should be marked as occupied" do step "the section table should be marked as occupied" do
table = page.find(".section-table-#{@table.id}") assert_element_class ".section-table-#{@table.id}", 'occupied'
table['class'].should include 'occupied'
end end
step "the section table should be marked as in need of help" do step "the section table should be marked as in need of help" do
table = page.find(".section-table-#{@table.id}") assert_element_class ".section-table-#{@table.id}", 'needs_help'
table['class'].should include 'needs_help'
end end
step "the section table should not be marked as in need of help" do step "the section table should not be marked as in need of help" do
@@ -97,9 +95,9 @@ step "I click the supplier section normal mode button" do
end end
step "I fill in the supplier edit section form with new values" do step "I fill in the supplier edit section form with new values" do
find('.section-edit-title-field').set 'RenamedSection' js_set_field '.section-edit-title-field', 'RenamedSection'
find('.section-edit-width-field').set '40' js_set_field '.section-edit-width-field', 40
find('.section-edit-height-field').set '52.7' js_set_field '.section-edit-height-field', 52.7
end end
step "the last section tab header should have the newly filled in name" do step "the last section tab header should have the newly filled in name" do
@@ -66,6 +66,7 @@ step "the user order :product_name should be in the order list with price" do |p
concerning_product = Product.find_by_name(product_name) concerning_product = Product.find_by_name(product_name)
#ember_order = ember_store['product_orders'].find{|po| po['product_id'] == concerning_product.id} #ember_order = ember_store['product_orders'].find{|po| po['product_id'] == concerning_product.id}
#ember_order = ember_find('product_order', concerning_product.id) #ember_order = ember_find('product_order', concerning_product.id)
sleep 0.1
ember_order = ember_all('product_order').find{|po| po['product_id'] == concerning_product.id } ember_order = ember_all('product_order').find{|po| po['product_id'] == concerning_product.id }
quantity = ember_order['quantity'] quantity = ember_order['quantity']
order_price = quantity * concerning_product.price order_price = quantity * concerning_product.price
+2 -1
View File
@@ -19,7 +19,8 @@ Dir.glob("spec/acceptance_steps/**/*steps.rb") { |f| load f, true }
I18n.locale =I18n.default_locale I18n.locale =I18n.default_locale
Devise.stretches = 1 Devise.stretches = 1
Capybara.javascript_driver = :webkit #Capybara.javascript_driver = :webkit
Capybara.javascript_driver = :selenium
Capybara.default_wait_time = 4 # ember needs more time than the default of 2 Capybara.default_wait_time = 4 # ember needs more time than the default of 2
Capybara::Screenshot.webkit_options = { width: 1024, height: 768 } Capybara::Screenshot.webkit_options = { width: 1024, height: 768 }
WebMock.disable_net_connect!(allow_localhost: true) WebMock.disable_net_connect!(allow_localhost: true)
+18 -5
View File
@@ -15,18 +15,31 @@ module SpecEmberHelpers
JSON.parse(h) JSON.parse(h)
end end
def assert_element_class(selector, class_name)
find selector # capybara wait for element
time = 0
classes = page.evaluate_script("$('#{selector}').attr('class')")
while !classes.include?(class_name) and time < 10
sleep 0.1
classes = page.evaluate_script("$('#{selector}').attr('class')")
time += 1
end
classes.should include class_name
end
def js_set_field(selector, value)
page.execute_script("$('#{selector}').val('#{value}').trigger('change')")
end
def ember_find(typeKey, id) def ember_find(typeKey, id)
h = page.evaluate_script <<-SCRIPT h = page.evaluate_script <<-SCRIPT
$s = App.__container__.lookup('store:main'); App.__container__.lookup('store:main').all('#{typeKey}').findBy('id', '#{id}').serialize()
record = $s.all('#{typeKey}').findBy('id', '#{id}');
record ? record.serialize() : null
SCRIPT SCRIPT
end end
def ember_all(typeKey) def ember_all(typeKey)
h = page.evaluate_script <<-SCRIPT h = page.evaluate_script <<-SCRIPT
$s = App.__container__.lookup('store:main'); App.__container__.lookup('store:main').all('#{typeKey}').invoke('serialize')
$s.all('#{typeKey}').invoke('serialize')
SCRIPT SCRIPT
end end
+1
View File
@@ -4,6 +4,7 @@ Release
Supplier Supplier
-------- --------
- facebook icons in list????
- Settings saved feedback, according to commented spec, maybe with redirect - Settings saved feedback, according to commented spec, maybe with redirect
- english emails - english emails
- form action button looks (Roos) - form action button looks (Roos)