Bundle update & restructure tests (RSpec 3)
This commit is contained in:
parent
7b2bcedb16
commit
aa7a2a31ae
14 changed files with 412 additions and 413 deletions
3
Gemfile
3
Gemfile
|
@ -103,8 +103,9 @@ group :test do
|
||||||
gem 'database_cleaner'
|
gem 'database_cleaner'
|
||||||
gem 'connection_pool'
|
gem 'connection_pool'
|
||||||
# need to include rspec components before i18n-spec or rake fails in test environment
|
# need to include rspec components before i18n-spec or rake fails in test environment
|
||||||
gem 'rspec-core', '~> 2.99' # almost ready for RSpec 3
|
gem 'rspec-core', '~> 3.2'
|
||||||
gem 'rspec-rerun'
|
gem 'rspec-rerun'
|
||||||
|
gem 'rspec-legacy_formatters'
|
||||||
gem 'i18n-spec'
|
gem 'i18n-spec'
|
||||||
# code coverage
|
# code coverage
|
||||||
gem 'simplecov', require: false
|
gem 'simplecov', require: false
|
||||||
|
|
46
Gemfile.lock
46
Gemfile.lock
|
@ -337,27 +337,32 @@ GEM
|
||||||
nokogiri
|
nokogiri
|
||||||
rubyzip
|
rubyzip
|
||||||
spreadsheet (> 0.6.4)
|
spreadsheet (> 0.6.4)
|
||||||
rspec (2.99.0)
|
rspec (3.2.0)
|
||||||
rspec-core (~> 2.99.0)
|
rspec-core (~> 3.2.0)
|
||||||
rspec-expectations (~> 2.99.0)
|
rspec-expectations (~> 3.2.0)
|
||||||
rspec-mocks (~> 2.99.0)
|
rspec-mocks (~> 3.2.0)
|
||||||
rspec-collection_matchers (1.1.2)
|
rspec-core (3.2.3)
|
||||||
rspec-expectations (>= 2.99.0.beta1)
|
rspec-support (~> 3.2.0)
|
||||||
rspec-core (2.99.2)
|
rspec-expectations (3.2.1)
|
||||||
rspec-expectations (2.99.2)
|
diff-lcs (>= 1.2.0, < 2.0)
|
||||||
diff-lcs (>= 1.1.3, < 2.0)
|
rspec-support (~> 3.2.0)
|
||||||
rspec-mocks (2.99.3)
|
rspec-legacy_formatters (1.0.0)
|
||||||
rspec-rails (2.99.0)
|
rspec-core (>= 3.0.0.beta2)
|
||||||
actionpack (>= 3.0)
|
rspec-support (>= 3.0.0.beta2)
|
||||||
activemodel (>= 3.0)
|
rspec-mocks (3.2.1)
|
||||||
activesupport (>= 3.0)
|
diff-lcs (>= 1.2.0, < 2.0)
|
||||||
railties (>= 3.0)
|
rspec-support (~> 3.2.0)
|
||||||
rspec-collection_matchers
|
rspec-rails (3.2.1)
|
||||||
rspec-core (~> 2.99.0)
|
actionpack (>= 3.0, < 4.3)
|
||||||
rspec-expectations (~> 2.99.0)
|
activesupport (>= 3.0, < 4.3)
|
||||||
rspec-mocks (~> 2.99.0)
|
railties (>= 3.0, < 4.3)
|
||||||
|
rspec-core (~> 3.2.0)
|
||||||
|
rspec-expectations (~> 3.2.0)
|
||||||
|
rspec-mocks (~> 3.2.0)
|
||||||
|
rspec-support (~> 3.2.0)
|
||||||
rspec-rerun (0.3.0)
|
rspec-rerun (0.3.0)
|
||||||
rspec
|
rspec
|
||||||
|
rspec-support (3.2.2)
|
||||||
ruby-ole (1.2.11.8)
|
ruby-ole (1.2.11.8)
|
||||||
ruby-prof (0.15.6)
|
ruby-prof (0.15.6)
|
||||||
ruby-units (1.4.5)
|
ruby-units (1.4.5)
|
||||||
|
@ -518,7 +523,8 @@ DEPENDENCIES
|
||||||
recurring_select
|
recurring_select
|
||||||
resque
|
resque
|
||||||
roo (~> 1.13.2)
|
roo (~> 1.13.2)
|
||||||
rspec-core (~> 2.99)
|
rspec-core (~> 3.2)
|
||||||
|
rspec-legacy_formatters
|
||||||
rspec-rails
|
rspec-rails
|
||||||
rspec-rerun
|
rspec-rerun
|
||||||
ruby-prof
|
ruby-prof
|
||||||
|
|
|
@ -15,12 +15,7 @@ class LoginController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
if (user = User.find_by_email(params[:user][:email]))
|
if (user = User.find_by_email(params[:user][:email]))
|
||||||
user.reset_password_token = user.new_random_password(16)
|
user.request_password_reset!
|
||||||
user.reset_password_expires = Time.now.advance(:days => 2)
|
|
||||||
if user.save
|
|
||||||
Mailer.reset_password(user).deliver_now
|
|
||||||
logger.debug("Sent password reset email to #{user.email}.")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
redirect_to login_url, :notice => I18n.t('login.controller.reset_password.notice')
|
redirect_to login_url, :notice => I18n.t('login.controller.reset_password.notice')
|
||||||
end
|
end
|
||||||
|
|
|
@ -119,7 +119,21 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
r
|
r
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Generates password reset token and sends email
|
||||||
|
# @return [Boolean] Whether it succeeded or not
|
||||||
|
def request_password_reset!
|
||||||
|
self.reset_password_token = new_random_password(16)
|
||||||
|
self.reset_password_expires = Time.now.advance(days: 2)
|
||||||
|
if save!
|
||||||
|
Mailer.reset_password(self).deliver_now
|
||||||
|
logger.debug("Sent password reset email to #{email}.")
|
||||||
|
true
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Checks the admin role
|
# Checks the admin role
|
||||||
def role_admin?
|
def role_admin?
|
||||||
groups.detect {|group| group.role_admin?}
|
groups.detect {|group| group.role_admin?}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
require_relative '../spec_helper'
|
require_relative '../spec_helper'
|
||||||
|
|
||||||
describe ArticlesController, :type => :feature do
|
feature ArticlesController do
|
||||||
let(:user) { create :user, groups:[create(:workgroup, role_article_meta: true)] }
|
let(:user) { create :user, groups:[create(:workgroup, role_article_meta: true)] }
|
||||||
let (:supplier) { create :supplier }
|
let (:supplier) { create :supplier }
|
||||||
let!(:article_category) { create :article_category }
|
let!(:article_category) { create :article_category }
|
||||||
before { login user }
|
before { login user }
|
||||||
|
|
||||||
describe ":index", :type => :feature, :js => true do
|
describe ':index', js: true do
|
||||||
before { visit supplier_articles_path(supplier) }
|
before { visit supplier_articles_path(supplier_id: supplier.id) }
|
||||||
|
|
||||||
it 'can visit supplier articles path' do
|
it 'can visit supplier articles path' do
|
||||||
expect(page).to have_content(supplier.name)
|
expect(page).to have_content(supplier.name)
|
||||||
|
@ -35,11 +35,11 @@ describe ArticlesController, :type => :feature do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ":upload", :type => :feature, :js => true do
|
describe ':upload' do
|
||||||
let(:filename) { 'foodsoft_file_02.csv' }
|
let(:filename) { 'foodsoft_file_02.csv' }
|
||||||
let(:file) { Rails.root.join("spec/fixtures/#{filename}") }
|
let(:file) { Rails.root.join("spec/fixtures/#{filename}") }
|
||||||
before do
|
before do
|
||||||
visit upload_supplier_articles_path(supplier)
|
visit upload_supplier_articles_path(supplier_id: supplier.id)
|
||||||
attach_file 'articles_file', file
|
attach_file 'articles_file', file
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require_relative '../spec_helper'
|
require_relative '../spec_helper'
|
||||||
|
|
||||||
describe 'settling an order', :type => :feature do
|
feature 'settling an order', js: true do
|
||||||
let(:admin) { create :user, groups:[create(:workgroup, role_finance: true)] }
|
let(:admin) { create :user, groups:[create(:workgroup, role_finance: true)] }
|
||||||
let(:user) { create :user, groups:[create(:ordergroup)] }
|
let(:user) { create :user, groups:[create(:ordergroup)] }
|
||||||
let(:supplier) { create :supplier }
|
let(:supplier) { create :supplier }
|
||||||
|
@ -27,158 +27,154 @@ describe 'settling an order', :type => :feature do
|
||||||
expect(goa2.result).to eq(1)
|
expect(goa2.result).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe :type => :feature, :js => true do
|
before { login admin }
|
||||||
before { login admin }
|
before { visit new_finance_order_path(order_id: order.id) }
|
||||||
before { visit new_finance_order_path(order_id: order.id) }
|
|
||||||
|
|
||||||
it 'has product ordered visible' do
|
|
||||||
expect(page).to have_content(article.name)
|
|
||||||
expect(page).to have_selector("#order_article_#{oa.id}")
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'shows order result' do
|
|
||||||
click_link article.name
|
|
||||||
expect(page).to have_selector("#group_order_articles_#{oa.id}")
|
|
||||||
within("#group_order_articles_#{oa.id}") do
|
|
||||||
# make sure these ordergroup names are in the list for this product
|
|
||||||
expect(page).to have_content(go1.ordergroup.name)
|
|
||||||
expect(page).to have_content(go2.ordergroup.name)
|
|
||||||
# and that their order results match what we expect
|
|
||||||
expect(page).to have_selector("#r_#{goa1.id}")
|
|
||||||
expect(find("#r_#{goa1.id}").value.to_f).to eq(3)
|
|
||||||
expect(page).to have_selector("#r_#{goa2.id}")
|
|
||||||
expect(find("#r_#{goa2.id}").value.to_f).to eq(1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'keeps ordered quantities when article is deleted from resulting order' do
|
|
||||||
within("#order_article_#{oa.id}") do
|
|
||||||
click_link I18n.t('ui.delete')
|
|
||||||
page.driver.browser.switch_to.alert.accept
|
|
||||||
end
|
|
||||||
expect(page).to_not have_selector("#order_article_#{oa.id}")
|
|
||||||
expect(OrderArticle.exists?(oa.id)).to be true
|
|
||||||
oa.reload
|
|
||||||
expect(oa.quantity).to eq(4)
|
|
||||||
expect(oa.tolerance).to eq(0)
|
|
||||||
expect(oa.units_to_order).to eq(0)
|
|
||||||
expect(goa1.reload.result).to eq(0)
|
|
||||||
expect(goa2.reload.result).to eq(0)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'deletes an OrderArticle with no GroupOrderArticles' do
|
|
||||||
goa1.destroy
|
|
||||||
goa2.destroy
|
|
||||||
within("#order_article_#{oa.id}") do
|
|
||||||
click_link I18n.t('ui.delete')
|
|
||||||
page.driver.browser.switch_to.alert.accept
|
|
||||||
end
|
|
||||||
expect(page).to_not have_selector("#order_article_#{oa.id}")
|
|
||||||
expect(OrderArticle.exists?(oa.id)).to be false
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'keeps ordered quantities when GroupOrderArticle is deleted from resulting order' do
|
|
||||||
click_link article.name
|
|
||||||
expect(page).to have_selector("#group_order_article_#{goa1.id}")
|
|
||||||
within("#group_order_article_#{goa1.id}") do
|
|
||||||
click_link I18n.t('ui.delete')
|
|
||||||
end
|
|
||||||
expect(page).to_not have_selector("#group_order_article_#{goa1.id}")
|
|
||||||
expect(OrderArticle.exists?(oa.id)).to be true
|
|
||||||
expect(GroupOrderArticle.exists?(goa1.id)).to be true
|
|
||||||
goa1.reload
|
|
||||||
expect(goa1.result).to eq(0)
|
|
||||||
expect(goa1.quantity).to eq(3)
|
|
||||||
expect(goa1.tolerance).to eq(0)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'deletes a GroupOrderArticle with no ordered amounts' do
|
|
||||||
goa1.update_attributes({:quantity => 0, :tolerance => 0})
|
|
||||||
click_link article.name
|
|
||||||
expect(page).to have_selector("#group_order_article_#{goa1.id}")
|
|
||||||
within("#group_order_article_#{goa1.id}") do
|
|
||||||
click_link I18n.t('ui.delete')
|
|
||||||
end
|
|
||||||
expect(page).to_not have_selector("#group_order_article_#{goa1.id}")
|
|
||||||
expect(OrderArticle.exists?(oa.id)).to be true
|
|
||||||
expect(GroupOrderArticle.exists?(goa1.id)).to be false
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'keeps product when amount is set to zero' do
|
|
||||||
within("#order_article_#{oa.id}") do
|
|
||||||
click_link I18n.t('ui.edit')
|
|
||||||
end
|
|
||||||
within("#edit_order_article_#{oa.id}") do
|
|
||||||
fill_in :order_article_units_to_order, :with => 0
|
|
||||||
find('input[type="submit"]').click
|
|
||||||
end
|
|
||||||
sleep 0.5 # workaround "javascript error" "e is null"
|
|
||||||
expect(page).to have_selector("#order_article_#{oa.id}")
|
|
||||||
# make sure it still works after reloading
|
|
||||||
visit new_finance_order_path(order_id: order.id)
|
|
||||||
expect(page).to have_selector("#order_article_#{oa.id}")
|
|
||||||
expect(OrderArticle.exists?(oa.id)).to be true
|
|
||||||
oa.reload
|
|
||||||
expect(oa.units_to_order).to eq(0)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'can add an ordergroup to an order article' do
|
|
||||||
user # need to reference user before "new article" dialog is loaded
|
|
||||||
click_link article.name
|
|
||||||
within("#group_order_articles_#{oa.id}") do
|
|
||||||
click_link I18n.t('finance.balancing.group_order_articles.add_group')
|
|
||||||
end
|
|
||||||
expect(page).to have_selector('form#new_group_order_article')
|
|
||||||
within('#new_group_order_article') do
|
|
||||||
select user.ordergroup.name, :from => 'group_order_article_ordergroup_id'
|
|
||||||
fill_in 'group_order_article_result', :with => 8
|
|
||||||
find('input[type="submit"]').click
|
|
||||||
end
|
|
||||||
expect(page).to_not have_selector('form#new_group_order_article')
|
|
||||||
expect(page).to have_content(user.ordergroup.name)
|
|
||||||
goa = GroupOrderArticle.last
|
|
||||||
expect(goa).to_not be_nil
|
|
||||||
expect(goa.result).to eq 8
|
|
||||||
expect(page).to have_selector("#group_order_article_#{goa.id}")
|
|
||||||
expect(find("#r_#{goa.id}").value.to_f).to eq 8
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'can modify an ordergroup result' do
|
|
||||||
click_link article.name
|
|
||||||
within("#group_order_articles_#{oa.id}") do
|
|
||||||
fill_in "r_#{goa1.id}", :with => 5
|
|
||||||
# leave input box and wait a bit so that update is sent using ajax
|
|
||||||
find("#r_#{goa1.id}").native.send_keys :tab
|
|
||||||
sleep 1
|
|
||||||
end
|
|
||||||
expect(goa1.reload.result).to eq 5
|
|
||||||
expect(find("#group_order_articles_#{oa.id} tfoot td:nth-child(3)").text.to_f).to eq 6
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'can modify an ordergroup result using the + button' do
|
|
||||||
click_link article.name
|
|
||||||
within("#group_order_article_#{goa1.id}") do
|
|
||||||
4.times { find('button[data-increment]').click }
|
|
||||||
sleep 1
|
|
||||||
end
|
|
||||||
expect(goa1.reload.result).to eq 7
|
|
||||||
expect(find("#group_order_articles_#{oa.id} tfoot td:nth-child(3)").text.to_f).to eq 8
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'can add an article' do
|
|
||||||
new_article = create :article, supplier: supplier
|
|
||||||
expect(page).to_not have_content(new_article.name)
|
|
||||||
click_link I18n.t('finance.balancing.edit_results_by_articles.add_article')
|
|
||||||
expect(page).to have_selector('form#new_order_article')
|
|
||||||
within('#new_order_article') do
|
|
||||||
select new_article.name, :from => 'order_article_article_id'
|
|
||||||
find('input[type="submit"]').click
|
|
||||||
end
|
|
||||||
expect(page).to_not have_selector('form#new_order_article')
|
|
||||||
expect(page).to have_content(new_article.name)
|
|
||||||
expect(order.order_articles.where(article_id: new_article.id)).to_not be nil
|
|
||||||
end
|
|
||||||
|
|
||||||
|
it 'has product ordered visible' do
|
||||||
|
expect(page).to have_content(article.name)
|
||||||
|
expect(page).to have_selector("#order_article_#{oa.id}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'shows order result' do
|
||||||
|
click_link article.name
|
||||||
|
expect(page).to have_selector("#group_order_articles_#{oa.id}")
|
||||||
|
within("#group_order_articles_#{oa.id}") do
|
||||||
|
# make sure these ordergroup names are in the list for this product
|
||||||
|
expect(page).to have_content(go1.ordergroup.name)
|
||||||
|
expect(page).to have_content(go2.ordergroup.name)
|
||||||
|
# and that their order results match what we expect
|
||||||
|
expect(page).to have_selector("#r_#{goa1.id}")
|
||||||
|
expect(find("#r_#{goa1.id}").value.to_f).to eq(3)
|
||||||
|
expect(page).to have_selector("#r_#{goa2.id}")
|
||||||
|
expect(find("#r_#{goa2.id}").value.to_f).to eq(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'keeps ordered quantities when article is deleted from resulting order' do
|
||||||
|
within("#order_article_#{oa.id}") do
|
||||||
|
click_link I18n.t('ui.delete')
|
||||||
|
page.driver.browser.switch_to.alert.accept
|
||||||
|
end
|
||||||
|
expect(page).to_not have_selector("#order_article_#{oa.id}")
|
||||||
|
expect(OrderArticle.exists?(oa.id)).to be true
|
||||||
|
oa.reload
|
||||||
|
expect(oa.quantity).to eq(4)
|
||||||
|
expect(oa.tolerance).to eq(0)
|
||||||
|
expect(oa.units_to_order).to eq(0)
|
||||||
|
expect(goa1.reload.result).to eq(0)
|
||||||
|
expect(goa2.reload.result).to eq(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'deletes an OrderArticle with no GroupOrderArticles' do
|
||||||
|
goa1.destroy
|
||||||
|
goa2.destroy
|
||||||
|
within("#order_article_#{oa.id}") do
|
||||||
|
click_link I18n.t('ui.delete')
|
||||||
|
page.driver.browser.switch_to.alert.accept
|
||||||
|
end
|
||||||
|
expect(page).to_not have_selector("#order_article_#{oa.id}")
|
||||||
|
expect(OrderArticle.exists?(oa.id)).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'keeps ordered quantities when GroupOrderArticle is deleted from resulting order' do
|
||||||
|
click_link article.name
|
||||||
|
expect(page).to have_selector("#group_order_article_#{goa1.id}")
|
||||||
|
within("#group_order_article_#{goa1.id}") do
|
||||||
|
click_link I18n.t('ui.delete')
|
||||||
|
end
|
||||||
|
expect(page).to_not have_selector("#group_order_article_#{goa1.id}")
|
||||||
|
expect(OrderArticle.exists?(oa.id)).to be true
|
||||||
|
expect(GroupOrderArticle.exists?(goa1.id)).to be true
|
||||||
|
goa1.reload
|
||||||
|
expect(goa1.result).to eq(0)
|
||||||
|
expect(goa1.quantity).to eq(3)
|
||||||
|
expect(goa1.tolerance).to eq(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'deletes a GroupOrderArticle with no ordered amounts' do
|
||||||
|
goa1.update_attributes({:quantity => 0, :tolerance => 0})
|
||||||
|
click_link article.name
|
||||||
|
expect(page).to have_selector("#group_order_article_#{goa1.id}")
|
||||||
|
within("#group_order_article_#{goa1.id}") do
|
||||||
|
click_link I18n.t('ui.delete')
|
||||||
|
end
|
||||||
|
expect(page).to_not have_selector("#group_order_article_#{goa1.id}")
|
||||||
|
expect(OrderArticle.exists?(oa.id)).to be true
|
||||||
|
expect(GroupOrderArticle.exists?(goa1.id)).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'keeps product when amount is set to zero' do
|
||||||
|
within("#order_article_#{oa.id}") do
|
||||||
|
click_link I18n.t('ui.edit')
|
||||||
|
end
|
||||||
|
within("#edit_order_article_#{oa.id}") do
|
||||||
|
fill_in :order_article_units_to_order, :with => 0
|
||||||
|
find('input[type="submit"]').click
|
||||||
|
end
|
||||||
|
sleep 0.5 # workaround "javascript error" "e is null"
|
||||||
|
expect(page).to have_selector("#order_article_#{oa.id}")
|
||||||
|
# make sure it still works after reloading
|
||||||
|
visit new_finance_order_path(order_id: order.id)
|
||||||
|
expect(page).to have_selector("#order_article_#{oa.id}")
|
||||||
|
expect(OrderArticle.exists?(oa.id)).to be true
|
||||||
|
oa.reload
|
||||||
|
expect(oa.units_to_order).to eq(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'can add an ordergroup to an order article' do
|
||||||
|
user # need to reference user before "new article" dialog is loaded
|
||||||
|
click_link article.name
|
||||||
|
within("#group_order_articles_#{oa.id}") do
|
||||||
|
click_link I18n.t('finance.balancing.group_order_articles.add_group')
|
||||||
|
end
|
||||||
|
expect(page).to have_selector('form#new_group_order_article')
|
||||||
|
within('#new_group_order_article') do
|
||||||
|
select user.ordergroup.name, :from => 'group_order_article_ordergroup_id'
|
||||||
|
fill_in 'group_order_article_result', :with => 8
|
||||||
|
find('input[type="submit"]').click
|
||||||
|
end
|
||||||
|
expect(page).to_not have_selector('form#new_group_order_article')
|
||||||
|
expect(page).to have_content(user.ordergroup.name)
|
||||||
|
goa = GroupOrderArticle.last
|
||||||
|
expect(goa).to_not be_nil
|
||||||
|
expect(goa.result).to eq 8
|
||||||
|
expect(page).to have_selector("#group_order_article_#{goa.id}")
|
||||||
|
expect(find("#r_#{goa.id}").value.to_f).to eq 8
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'can modify an ordergroup result' do
|
||||||
|
click_link article.name
|
||||||
|
within("#group_order_articles_#{oa.id}") do
|
||||||
|
fill_in "r_#{goa1.id}", :with => 5
|
||||||
|
# leave input box and wait a bit so that update is sent using ajax
|
||||||
|
find("#r_#{goa1.id}").native.send_keys :tab
|
||||||
|
sleep 1
|
||||||
|
end
|
||||||
|
expect(goa1.reload.result).to eq 5
|
||||||
|
expect(find("#group_order_articles_#{oa.id} tfoot td:nth-child(3)").text.to_f).to eq 6
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'can modify an ordergroup result using the + button' do
|
||||||
|
click_link article.name
|
||||||
|
within("#group_order_article_#{goa1.id}") do
|
||||||
|
4.times { find('button[data-increment]').click }
|
||||||
|
sleep 1
|
||||||
|
end
|
||||||
|
expect(goa1.reload.result).to eq 7
|
||||||
|
expect(find("#group_order_articles_#{oa.id} tfoot td:nth-child(3)").text.to_f).to eq 8
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'can add an article' do
|
||||||
|
new_article = create :article, supplier: supplier
|
||||||
|
expect(page).to_not have_content(new_article.name)
|
||||||
|
click_link I18n.t('finance.balancing.edit_results_by_articles.add_article')
|
||||||
|
expect(page).to have_selector('form#new_order_article')
|
||||||
|
within('#new_order_article') do
|
||||||
|
select new_article.name, :from => 'order_article_article_id'
|
||||||
|
find('input[type="submit"]').click
|
||||||
|
end
|
||||||
|
expect(page).to_not have_selector('form#new_order_article')
|
||||||
|
expect(page).to have_content(new_article.name)
|
||||||
|
expect(order.order_articles.where(article_id: new_article.id)).to_not be nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,66 +1,63 @@
|
||||||
require_relative '../spec_helper'
|
require_relative '../spec_helper'
|
||||||
|
|
||||||
describe 'admin/configs', type: :feature do
|
feature 'admin/configs' do
|
||||||
let(:name) { Faker::Lorem.words(rand(2..4)).join(' ') }
|
let(:name) { Faker::Lorem.words(rand(2..4)).join(' ') }
|
||||||
let(:email) { Faker::Internet.email }
|
let(:email) { Faker::Internet.email }
|
||||||
|
let(:admin) { create :admin }
|
||||||
|
|
||||||
describe type: :feature, js: true do
|
before { login admin }
|
||||||
let(:admin) { create :admin }
|
|
||||||
before { login admin }
|
|
||||||
|
|
||||||
it 'has initial value' do
|
it 'has initial value' do
|
||||||
FoodsoftConfig[:name] = name
|
FoodsoftConfig[:name] = name
|
||||||
visit admin_config_path
|
visit admin_config_path
|
||||||
within('form.config') do
|
within('form.config') do
|
||||||
expect(find_field('config_name').value).to eq name
|
expect(find_field('config_name').value).to eq name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'can modify a value' do
|
||||||
|
visit admin_config_path
|
||||||
|
fill_in 'config_name', with: name
|
||||||
|
within('form.config') do
|
||||||
|
find('input[type="submit"]').click
|
||||||
|
expect(find_field('config_name').value).to eq name
|
||||||
|
end
|
||||||
|
expect(FoodsoftConfig[:name]).to eq name
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'keeps config the same without changes' do
|
||||||
|
orig_values = get_full_config
|
||||||
|
visit admin_config_path
|
||||||
|
within('form.config') do
|
||||||
|
find('input[type="submit"]').click
|
||||||
|
expect(find_field('config_name').value).to eq FoodsoftConfig[:name]
|
||||||
|
end
|
||||||
|
expect(get_full_config).to eq orig_values
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'can modify a nested value' do
|
||||||
|
visit admin_config_path
|
||||||
|
fill_in 'config_contact_email', with: email
|
||||||
|
within('form.config') do
|
||||||
|
find('input[type="submit"]').click
|
||||||
|
expect(find_field('config_contact_email').value).to eq email
|
||||||
|
end
|
||||||
|
expect(FoodsoftConfig[:contact][:email]).to eq email
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_full_config
|
||||||
|
cfg = FoodsoftConfig.to_hash.deep_dup
|
||||||
|
compact_hash_deep!(cfg)
|
||||||
|
end
|
||||||
|
|
||||||
|
def compact_hash_deep!(h)
|
||||||
|
h.each do |k,v|
|
||||||
|
if v.is_a? Hash
|
||||||
|
compact_hash_deep!(v)
|
||||||
|
v.reject! {|k,v| v.blank?}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
h.reject! {|k,v| v.blank?}
|
||||||
it 'can modify a value' do
|
h
|
||||||
visit admin_config_path
|
|
||||||
fill_in 'config_name', with: name
|
|
||||||
within('form.config') do
|
|
||||||
find('input[type="submit"]').click
|
|
||||||
expect(find_field('config_name').value).to eq name
|
|
||||||
end
|
|
||||||
expect(FoodsoftConfig[:name]).to eq name
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'keeps config the same without changes' do
|
|
||||||
orig_values = get_full_config
|
|
||||||
visit admin_config_path
|
|
||||||
within('form.config') do
|
|
||||||
find('input[type="submit"]').click
|
|
||||||
expect(find_field('config_name').value).to eq FoodsoftConfig[:name]
|
|
||||||
end
|
|
||||||
expect(get_full_config).to eq orig_values
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'can modify a nested value' do
|
|
||||||
visit admin_config_path
|
|
||||||
fill_in 'config_contact_email', with: email
|
|
||||||
within('form.config') do
|
|
||||||
find('input[type="submit"]').click
|
|
||||||
expect(find_field('config_contact_email').value).to eq email
|
|
||||||
end
|
|
||||||
expect(FoodsoftConfig[:contact][:email]).to eq email
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_full_config
|
|
||||||
cfg = FoodsoftConfig.to_hash.deep_dup
|
|
||||||
compact_hash_deep!(cfg)
|
|
||||||
end
|
|
||||||
|
|
||||||
def compact_hash_deep!(h)
|
|
||||||
h.each do |k,v|
|
|
||||||
if v.is_a? Hash
|
|
||||||
compact_hash_deep!(v)
|
|
||||||
v.reject! {|k,v| v.blank?}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
h.reject! {|k,v| v.blank?}
|
|
||||||
h
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,42 +1,45 @@
|
||||||
require_relative '../spec_helper'
|
require_relative '../spec_helper'
|
||||||
|
|
||||||
describe LoginController, :type => :feature do
|
feature LoginController do
|
||||||
let(:user) { create :user }
|
let(:user) { create :user }
|
||||||
|
|
||||||
describe 'forgot password', :type => :feature do
|
describe 'forgot password' do
|
||||||
|
before { visit forgot_password_path }
|
||||||
it 'is accessible' do
|
it 'is accessible' do
|
||||||
get forgot_password_path
|
expect(page).to have_selector 'input[id=user_email]'
|
||||||
expect(response).to be_success
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sends a reset email' do
|
it 'sends a reset email' do
|
||||||
post reset_password_path, user: {email: user.email}
|
fill_in 'user_email', with: user.email
|
||||||
|
find('input[type=submit]').click
|
||||||
|
expect(page).to have_selector '.alert-success'
|
||||||
email = ActionMailer::Base.deliveries.first
|
email = ActionMailer::Base.deliveries.first
|
||||||
expect(email.to).to eq [user.email]
|
expect(email.to).to eq [user.email]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'reset password', :type => :feature do
|
describe 'and reset it' do
|
||||||
let(:token) { user.reset_password_token }
|
let(:token) { user.reset_password_token }
|
||||||
let(:newpass) { user.new_random_password }
|
let(:newpass) { user.new_random_password }
|
||||||
before do
|
before { user.request_password_reset! }
|
||||||
post reset_password_path, user: {email: user.email}
|
before { visit new_password_path(id: user.id, token: token) }
|
||||||
user.reload
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'is accessible' do
|
it 'is accessible' do
|
||||||
get new_password_path, id: user.id, token: token
|
expect(page).to have_selector 'input[type=password]'
|
||||||
expect(response).to be_success
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'is not accessible with wrong token' do
|
describe 'with wrong token' do
|
||||||
get new_password_path, id: user.id, token: '123'
|
let(:token) { 'foobar' }
|
||||||
expect(response).to_not be_success
|
it 'is not accessible' do
|
||||||
|
expect(page).to have_selector '.alert-error'
|
||||||
|
expect(page).to_not have_selector 'input[type=password]'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'changes the password' do
|
it 'changes the password' do
|
||||||
patch update_password_path, id: user.id, token: token, user: {password: newpass, password_confirmation: newpass}
|
fill_in 'user_password', with: newpass
|
||||||
expect(page).to_not have_selector('.alert-error')
|
fill_in 'user_password_confirmation', with: newpass
|
||||||
|
find('input[type=submit]').click
|
||||||
expect(User.authenticate(user.email, newpass)).to eq user
|
expect(User.authenticate(user.email, newpass)).to eq user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require_relative '../spec_helper'
|
require_relative '../spec_helper'
|
||||||
|
|
||||||
describe Order, type: :feature do
|
feature Order, js: true do
|
||||||
let(:admin) { create :user, groups:[create(:workgroup, role_orders: true)] }
|
let(:admin) { create :user, groups:[create(:workgroup, role_orders: true)] }
|
||||||
let(:article) { create :article, unit_quantity: 1 }
|
let(:article) { create :article, unit_quantity: 1 }
|
||||||
let(:order) { create :order, supplier: article.supplier, article_ids: [article.id] } # need to ref article
|
let(:order) { create :order, supplier: article.supplier, article_ids: [article.id] } # need to ref article
|
||||||
|
@ -8,41 +8,39 @@ describe Order, type: :feature do
|
||||||
let(:oa) { order.order_articles.find_by_article_id(article.id) }
|
let(:oa) { order.order_articles.find_by_article_id(article.id) }
|
||||||
let(:goa1) { create :group_order_article, group_order: go1, order_article: oa }
|
let(:goa1) { create :group_order_article, group_order: go1, order_article: oa }
|
||||||
|
|
||||||
describe type: :feature, js: true do
|
before { login admin }
|
||||||
before { login admin }
|
|
||||||
|
|
||||||
it 'can get to the new order page' do
|
it 'can get to the new order page' do
|
||||||
article.supplier
|
article.supplier
|
||||||
visit orders_path
|
visit orders_path
|
||||||
click_link_or_button I18n.t('orders.index.new_order')
|
click_link_or_button I18n.t('orders.index.new_order')
|
||||||
click_link_or_button order.name
|
click_link_or_button order.name
|
||||||
expect(page).to have_text I18n.t('orders.new.title')
|
expect(page).to have_text I18n.t('orders.new.title')
|
||||||
expect(page).to have_text article.name
|
expect(page).to have_text article.name
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'fills in the end date with a schedule' do
|
it 'fills in the end date with a schedule' do
|
||||||
FoodsoftConfig[:time_zone] = 'UTC'
|
FoodsoftConfig[:time_zone] = 'UTC'
|
||||||
FoodsoftConfig[:order_schedule] = {ends: {recurr: 'FREQ=MONTHLY;BYMONTHDAY=1', time: '12:00'}}
|
FoodsoftConfig[:order_schedule] = {ends: {recurr: 'FREQ=MONTHLY;BYMONTHDAY=1', time: '12:00'}}
|
||||||
visit new_order_path(supplier_id: article.supplier.id)
|
visit new_order_path(supplier_id: article.supplier.id)
|
||||||
expect(page).to have_text I18n.t('orders.new.title')
|
expect(page).to have_text I18n.t('orders.new.title')
|
||||||
expect(find_field('order_ends_time_value').value).to eq '12:00'
|
expect(find_field('order_ends_time_value').value).to eq '12:00'
|
||||||
expect(find_field('order_ends_date_value').value).to eq Date.today.next_month.at_beginning_of_month.strftime('%Y-%m-%d')
|
expect(find_field('order_ends_date_value').value).to eq Date.today.next_month.at_beginning_of_month.strftime('%Y-%m-%d')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can create a new order' do
|
it 'can create a new order' do
|
||||||
visit new_order_path(supplier_id: article.supplier.id)
|
visit new_order_path(supplier_id: article.supplier.id)
|
||||||
expect(page).to have_text I18n.t('orders.new.title')
|
expect(page).to have_text I18n.t('orders.new.title')
|
||||||
find('input[type="submit"]').click
|
find('input[type="submit"]').click
|
||||||
expect(Order.count).to eq 1
|
expect(Order.count).to eq 1
|
||||||
expect(Order.first.supplier).to eq article.supplier
|
expect(Order.first.supplier).to eq article.supplier
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can close an order' do
|
it 'can close an order' do
|
||||||
setup_and_close_order
|
setup_and_close_order
|
||||||
expect(order).to be_finished
|
expect(order).to be_finished
|
||||||
expect(page).to_not have_link I18n.t('orders.index.action_end')
|
expect(page).to_not have_link I18n.t('orders.index.action_end')
|
||||||
expect(oa.units_to_order).to eq 1
|
expect(oa.units_to_order).to eq 1
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_and_close_order
|
def setup_and_close_order
|
||||||
|
@ -57,5 +55,4 @@ describe Order, type: :feature do
|
||||||
order.reload
|
order.reload
|
||||||
oa.reload
|
oa.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require_relative '../spec_helper'
|
require_relative '../spec_helper'
|
||||||
|
|
||||||
describe 'product distribution', :type => :feature do
|
feature 'product distribution', js: true do
|
||||||
let(:admin) { create :admin }
|
let(:admin) { create :admin }
|
||||||
let(:user_a) { create :user, groups: [create(:ordergroup)] }
|
let(:user_a) { create :user, groups: [create(:ordergroup)] }
|
||||||
let(:user_b) { create :user, groups: [create(:ordergroup)] }
|
let(:user_b) { create :user, groups: [create(:ordergroup)] }
|
||||||
|
@ -9,49 +9,47 @@ describe 'product distribution', :type => :feature do
|
||||||
let(:order) { create(:order, supplier: supplier, article_ids: [article.id]) }
|
let(:order) { create(:order, supplier: supplier, article_ids: [article.id]) }
|
||||||
let(:oa) { order.order_articles.first }
|
let(:oa) { order.order_articles.first }
|
||||||
|
|
||||||
describe :type => :feature do
|
before do
|
||||||
# make sure users have enough money to order
|
# make sure users have enough money to order
|
||||||
before do
|
[user_a, user_b].each do |user|
|
||||||
[user_a, user_b].each do |user|
|
ordergroup = Ordergroup.find(user.ordergroup.id)
|
||||||
ordergroup = Ordergroup.find(user.ordergroup.id)
|
ordergroup.add_financial_transaction! 5000, 'for ordering', admin
|
||||||
ordergroup.add_financial_transaction! 5000, 'for ordering', admin
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'agrees to documented example', :js => true do
|
|
||||||
# gruppe a bestellt 2(3), weil sie auf jeden fall was von x bekommen will
|
|
||||||
login user_a
|
|
||||||
visit new_group_order_path(:order_id => order.id)
|
|
||||||
2.times { find("[data-increase_quantity='#{oa.id}']").click }
|
|
||||||
3.times { find("[data-increase_tolerance='#{oa.id}']").click }
|
|
||||||
find('input[type=submit]').click
|
|
||||||
expect(page).to have_selector('body')
|
|
||||||
# gruppe b bestellt 2(0)
|
|
||||||
login user_b
|
|
||||||
visit new_group_order_path(:order_id => order.id)
|
|
||||||
2.times { find("[data-increase_quantity='#{oa.id}']").click }
|
|
||||||
find('input[type=submit]').click
|
|
||||||
expect(page).to have_selector('body')
|
|
||||||
# gruppe a faellt ein dass sie doch noch mehr braucht von x und aendert auf 4(1).
|
|
||||||
login user_a
|
|
||||||
visit edit_group_order_path(order.group_order(user_a.ordergroup), :order_id => order.id)
|
|
||||||
2.times { find("[data-increase_quantity='#{oa.id}']").click }
|
|
||||||
2.times { find("[data-decrease_tolerance='#{oa.id}']").click }
|
|
||||||
find('input[type=submit]').click
|
|
||||||
expect(page).to have_selector('body')
|
|
||||||
# die zuteilung
|
|
||||||
order.finish!(admin)
|
|
||||||
oa.reload
|
|
||||||
# Endstand: insg. Bestellt wurden 6(1)
|
|
||||||
expect(oa.quantity).to eq(6)
|
|
||||||
expect(oa.tolerance).to eq(1)
|
|
||||||
# Gruppe a bekommt 3 einheiten.
|
|
||||||
goa_a = oa.group_order_articles.joins(:group_order).where(:group_orders => {:ordergroup_id => user_a.ordergroup.id}).first
|
|
||||||
expect(goa_a.result).to eq(3)
|
|
||||||
# gruppe b bekommt 2 einheiten.
|
|
||||||
goa_b = oa.group_order_articles.joins(:group_order).where(:group_orders => {:ordergroup_id => user_b.ordergroup.id}).first
|
|
||||||
expect(goa_b.result).to eq(2)
|
|
||||||
end
|
end
|
||||||
|
order # make sure order is referenced
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'agrees to documented example' do
|
||||||
|
# gruppe a bestellt 2(3), weil sie auf jeden fall was von x bekommen will
|
||||||
|
login user_a
|
||||||
|
visit new_group_order_path(order_id: order.id)
|
||||||
|
2.times { find("[data-increase_quantity='#{oa.id}']").click }
|
||||||
|
3.times { find("[data-increase_tolerance='#{oa.id}']").click }
|
||||||
|
find('input[type=submit]').click
|
||||||
|
expect(page).to have_selector('body')
|
||||||
|
# gruppe b bestellt 2(0)
|
||||||
|
login user_b
|
||||||
|
visit new_group_order_path(order_id: order.id)
|
||||||
|
2.times { find("[data-increase_quantity='#{oa.id}']").click }
|
||||||
|
find('input[type=submit]').click
|
||||||
|
expect(page).to have_selector('body')
|
||||||
|
# gruppe a faellt ein dass sie doch noch mehr braucht von x und aendert auf 4(1).
|
||||||
|
login user_a
|
||||||
|
visit edit_group_order_path(id: order.group_order(user_a.ordergroup).id, order_id: order.id)
|
||||||
|
2.times { find("[data-increase_quantity='#{oa.id}']").click }
|
||||||
|
2.times { find("[data-decrease_tolerance='#{oa.id}']").click }
|
||||||
|
find('input[type=submit]').click
|
||||||
|
expect(page).to have_selector('body')
|
||||||
|
# die zuteilung
|
||||||
|
order.finish!(admin)
|
||||||
|
oa.reload
|
||||||
|
# Endstand: insg. Bestellt wurden 6(1)
|
||||||
|
expect(oa.quantity).to eq(6)
|
||||||
|
expect(oa.tolerance).to eq(1)
|
||||||
|
# Gruppe a bekommt 3 einheiten.
|
||||||
|
goa_a = oa.group_order_articles.joins(:group_order).where(:group_orders => {:ordergroup_id => user_a.ordergroup.id}).first
|
||||||
|
expect(goa_a.result).to eq(3)
|
||||||
|
# gruppe b bekommt 2 einheiten.
|
||||||
|
goa_b = oa.group_order_articles.joins(:group_order).where(:group_orders => {:ordergroup_id => user_b.ordergroup.id}).first
|
||||||
|
expect(goa_b.result).to eq(2)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require_relative '../spec_helper'
|
require_relative '../spec_helper'
|
||||||
|
|
||||||
describe 'receiving an order', :type => :feature do
|
feature 'receiving an order', js: true do
|
||||||
let(:admin) { create :user, groups:[create(:workgroup, role_orders: true)] }
|
let(:admin) { create :user, groups:[create(:workgroup, role_orders: true)] }
|
||||||
let(:supplier) { create :supplier }
|
let(:supplier) { create :supplier }
|
||||||
let(:article) { create :article, supplier: supplier, unit_quantity: 3 }
|
let(:article) { create :article, supplier: supplier, unit_quantity: 3 }
|
||||||
|
@ -34,74 +34,69 @@ describe 'receiving an order', :type => :feature do
|
||||||
expect(goa2.destroyed? ? 0 : goa2.result).to be_within(1e-3).of q2
|
expect(goa2.destroyed? ? 0 : goa2.result).to be_within(1e-3).of q2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
before { login admin }
|
||||||
|
|
||||||
describe :type => :feature, :js => true do
|
it 'has product ordered visible' do
|
||||||
before { login admin }
|
set_quantities [3,0], [0,0]
|
||||||
|
visit receive_order_path(id: order.id)
|
||||||
it 'has product ordered visible' do
|
expect(page).to have_content(article.name)
|
||||||
set_quantities [3,0], [0,0]
|
expect(page).to have_selector("#order_article_#{oa.id}")
|
||||||
visit receive_order_path(order)
|
|
||||||
expect(page).to have_content(article.name)
|
|
||||||
expect(page).to have_selector("#order_article_#{oa.id}")
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'has product not ordered invisible' do
|
|
||||||
set_quantities [0,0], [0,0]
|
|
||||||
visit receive_order_path(order)
|
|
||||||
expect(page).to_not have_selector("#order_article_#{oa.id}")
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'is not received by default' do
|
|
||||||
set_quantities [3,0], [0,0]
|
|
||||||
visit receive_order_path(order)
|
|
||||||
expect(find("#order_articles_#{oa.id}_units_received").value).to eq ''
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not change anything when received is ordered' do
|
|
||||||
set_quantities [2,0], [3,2]
|
|
||||||
visit receive_order_path(order)
|
|
||||||
fill_in "order_articles_#{oa.id}_units_received", :with => oa.units_to_order
|
|
||||||
find('input[type="submit"]').click
|
|
||||||
expect(page).to have_selector('body')
|
|
||||||
check_quantities 2, 2, 4
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'redistributes properly when received is more' do
|
|
||||||
set_quantities [2,0], [3,2]
|
|
||||||
visit receive_order_path(order)
|
|
||||||
fill_in "order_articles_#{oa.id}_units_received", :with => 3
|
|
||||||
find('input[type="submit"]').click
|
|
||||||
expect(page).to have_selector('body')
|
|
||||||
check_quantities 3, 2, 5
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'redistributes properly when received is less' do
|
|
||||||
set_quantities [2,0], [3,2]
|
|
||||||
visit receive_order_path(order)
|
|
||||||
fill_in "order_articles_#{oa.id}_units_received", :with => 1
|
|
||||||
find('input[type="submit"]').click
|
|
||||||
expect(page).to have_selector('body')
|
|
||||||
check_quantities 1, 2, 1
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'has a locked field when edited elsewhere' do
|
|
||||||
set_quantities [2,0], [3,2]
|
|
||||||
goa1.result = goa1.result + 1
|
|
||||||
goa1.save!
|
|
||||||
visit receive_order_path(order)
|
|
||||||
expect(find("#order_articles_#{oa.id}_units_received")).to be_disabled
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'leaves locked rows alone when submitted' do
|
|
||||||
set_quantities [2,0], [3,2]
|
|
||||||
goa1.result = goa1.result + 1
|
|
||||||
goa1.save!
|
|
||||||
visit receive_order_path(order)
|
|
||||||
find('input[type="submit"]').click
|
|
||||||
expect(page).to have_selector('body')
|
|
||||||
check_quantities 2, 3, 4
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'has product not ordered invisible' do
|
||||||
|
set_quantities [0,0], [0,0]
|
||||||
|
visit receive_order_path(id: order.id)
|
||||||
|
expect(page).to_not have_selector("#order_article_#{oa.id}")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'is not received by default' do
|
||||||
|
set_quantities [3,0], [0,0]
|
||||||
|
visit receive_order_path(id: order.id)
|
||||||
|
expect(find("#order_articles_#{oa.id}_units_received").value).to be_blank
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not change anything when received is ordered' do
|
||||||
|
set_quantities [2,0], [3,2]
|
||||||
|
visit receive_order_path(id: order.id)
|
||||||
|
fill_in "order_articles_#{oa.id}_units_received", :with => oa.units_to_order
|
||||||
|
find('input[type="submit"]').click
|
||||||
|
expect(page).to have_selector('body')
|
||||||
|
check_quantities 2, 2, 4
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'redistributes properly when received is more' do
|
||||||
|
set_quantities [2,0], [3,2]
|
||||||
|
visit receive_order_path(id: order.id)
|
||||||
|
fill_in "order_articles_#{oa.id}_units_received", :with => 3
|
||||||
|
find('input[type="submit"]').click
|
||||||
|
expect(page).to have_selector('body')
|
||||||
|
check_quantities 3, 2, 5
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'redistributes properly when received is less' do
|
||||||
|
set_quantities [2,0], [3,2]
|
||||||
|
visit receive_order_path(id: order.id)
|
||||||
|
fill_in "order_articles_#{oa.id}_units_received", :with => 1
|
||||||
|
find('input[type="submit"]').click
|
||||||
|
expect(page).to have_selector('body')
|
||||||
|
check_quantities 1, 2, 1
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has a locked field when edited elsewhere' do
|
||||||
|
set_quantities [2,0], [3,2]
|
||||||
|
goa1.result = goa1.result + 1
|
||||||
|
goa1.save!
|
||||||
|
visit receive_order_path(id: order.id)
|
||||||
|
expect(find("#order_articles_#{oa.id}_units_received")).to be_disabled
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'leaves locked rows alone when submitted' do
|
||||||
|
set_quantities [2,0], [3,2]
|
||||||
|
goa1.result = goa1.result + 1
|
||||||
|
goa1.save!
|
||||||
|
visit receive_order_path(id: order.id)
|
||||||
|
find('input[type="submit"]').click
|
||||||
|
expect(page).to have_selector('body')
|
||||||
|
check_quantities 2, 3, 4
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
require_relative '../spec_helper'
|
require_relative '../spec_helper'
|
||||||
|
|
||||||
describe 'the session', :type => :feature do
|
feature 'the session' do
|
||||||
let(:user) { create :user }
|
let(:user) { create :user }
|
||||||
|
|
||||||
describe 'login page', :type => :feature do
|
describe 'login page' do
|
||||||
it 'is accessible' do
|
it 'is accessible' do
|
||||||
get login_path
|
visit login_path
|
||||||
expect(response).to be_success
|
expect(page).to have_selector('input[type=password]')
|
||||||
end
|
end
|
||||||
it 'logs me in' do
|
it 'logs me in' do
|
||||||
login user
|
login user
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
require_relative '../spec_helper'
|
require_relative '../spec_helper'
|
||||||
|
|
||||||
describe SuppliersController, :type => :feature do
|
feature 'supplier' do
|
||||||
let(:supplier) { create :supplier }
|
let(:supplier) { create :supplier }
|
||||||
|
|
||||||
describe :type => :feature, :js => true do
|
describe 'create new' do
|
||||||
let(:user) { create :user, groups:[create(:workgroup, role_suppliers: true)] }
|
let(:user) { create :user, groups:[create(:workgroup, role_suppliers: true)] }
|
||||||
before { login user }
|
before { login user }
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,7 @@ ENV["FOODSOFT_APP_CONFIG"] ||= 'spec/app_config.yml' # load special foodsoft con
|
||||||
require_relative 'support/coverage' # needs to be first
|
require_relative 'support/coverage' # needs to be first
|
||||||
require File.expand_path("../../config/environment", __FILE__)
|
require File.expand_path("../../config/environment", __FILE__)
|
||||||
require 'rspec/rails'
|
require 'rspec/rails'
|
||||||
require 'rspec/autorun'
|
|
||||||
|
|
||||||
require 'capybara/rails'
|
require 'capybara/rails'
|
||||||
require 'capybara/rspec'
|
|
||||||
|
|
||||||
# Requires supporting ruby files with custom matchers and macros, etc,
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
||||||
# in spec/support/ and its subdirectories.
|
# in spec/support/ and its subdirectories.
|
||||||
|
@ -58,7 +55,7 @@ RSpec.configure do |config|
|
||||||
# --seed 1234
|
# --seed 1234
|
||||||
config.order = "random"
|
config.order = "random"
|
||||||
|
|
||||||
config.include SessionHelper
|
config.include SessionHelper, type: :feature
|
||||||
|
|
||||||
# Automatically determine spec from directory structure, see:
|
# Automatically determine spec from directory structure, see:
|
||||||
# https://www.relishapp.com/rspec/rspec-rails/v/3-0/docs/directory-structure
|
# https://www.relishapp.com/rspec/rspec-rails/v/3-0/docs/directory-structure
|
||||||
|
@ -76,8 +73,8 @@ module Faker
|
||||||
end
|
end
|
||||||
|
|
||||||
# include default foodsoft scope in urls, so that *_path works
|
# include default foodsoft scope in urls, so that *_path works
|
||||||
ActionDispatch::Integration::Runner.class_eval do
|
# https://github.com/rspec/rspec-rails/issues/255
|
||||||
undef default_url_options
|
class ActionDispatch::Routing::RouteSet
|
||||||
def default_url_options(options={})
|
def default_url_options(options={})
|
||||||
{foodcoop: FoodsoftConfig.scope}.merge(options)
|
{foodcoop: FoodsoftConfig.scope}.merge(options)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue