Bundle update & restructure tests (RSpec 3)

This commit is contained in:
wvengen 2015-04-24 15:19:57 +02:00
parent 7b2bcedb16
commit aa7a2a31ae
14 changed files with 412 additions and 413 deletions

View file

@ -103,8 +103,9 @@ group :test do
gem 'database_cleaner'
gem 'connection_pool'
# 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-legacy_formatters'
gem 'i18n-spec'
# code coverage
gem 'simplecov', require: false

View file

@ -337,27 +337,32 @@ GEM
nokogiri
rubyzip
spreadsheet (> 0.6.4)
rspec (2.99.0)
rspec-core (~> 2.99.0)
rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.99.0)
rspec-collection_matchers (1.1.2)
rspec-expectations (>= 2.99.0.beta1)
rspec-core (2.99.2)
rspec-expectations (2.99.2)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.99.3)
rspec-rails (2.99.0)
actionpack (>= 3.0)
activemodel (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-collection_matchers
rspec-core (~> 2.99.0)
rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.99.0)
rspec (3.2.0)
rspec-core (~> 3.2.0)
rspec-expectations (~> 3.2.0)
rspec-mocks (~> 3.2.0)
rspec-core (3.2.3)
rspec-support (~> 3.2.0)
rspec-expectations (3.2.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.2.0)
rspec-legacy_formatters (1.0.0)
rspec-core (>= 3.0.0.beta2)
rspec-support (>= 3.0.0.beta2)
rspec-mocks (3.2.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.2.0)
rspec-rails (3.2.1)
actionpack (>= 3.0, < 4.3)
activesupport (>= 3.0, < 4.3)
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
rspec-support (3.2.2)
ruby-ole (1.2.11.8)
ruby-prof (0.15.6)
ruby-units (1.4.5)
@ -518,7 +523,8 @@ DEPENDENCIES
recurring_select
resque
roo (~> 1.13.2)
rspec-core (~> 2.99)
rspec-core (~> 3.2)
rspec-legacy_formatters
rspec-rails
rspec-rerun
ruby-prof

View file

@ -15,12 +15,7 @@ class LoginController < ApplicationController
end
if (user = User.find_by_email(params[:user][:email]))
user.reset_password_token = user.new_random_password(16)
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
user.request_password_reset!
end
redirect_to login_url, :notice => I18n.t('login.controller.reset_password.notice')
end

View file

@ -119,7 +119,21 @@ class User < ActiveRecord::Base
end
r
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
def role_admin?
groups.detect {|group| group.role_admin?}

View file

@ -1,14 +1,14 @@
# encoding: utf-8
require_relative '../spec_helper'
describe ArticlesController, :type => :feature do
feature ArticlesController do
let(:user) { create :user, groups:[create(:workgroup, role_article_meta: true)] }
let (:supplier) { create :supplier }
let!(:article_category) { create :article_category }
before { login user }
describe ":index", :type => :feature, :js => true do
before { visit supplier_articles_path(supplier) }
describe ':index', js: true do
before { visit supplier_articles_path(supplier_id: supplier.id) }
it 'can visit supplier articles path' do
expect(page).to have_content(supplier.name)
@ -35,11 +35,11 @@ describe ArticlesController, :type => :feature do
end
end
describe ":upload", :type => :feature, :js => true do
describe ':upload' do
let(:filename) { 'foodsoft_file_02.csv' }
let(:file) { Rails.root.join("spec/fixtures/#{filename}") }
before do
visit upload_supplier_articles_path(supplier)
visit upload_supplier_articles_path(supplier_id: supplier.id)
attach_file 'articles_file', file
end

View file

@ -1,6 +1,6 @@
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(:user) { create :user, groups:[create(:ordergroup)] }
let(:supplier) { create :supplier }
@ -27,158 +27,154 @@ describe 'settling an order', :type => :feature do
expect(goa2.result).to eq(1)
end
describe :type => :feature, :js => true do
before { login admin }
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
before { login admin }
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
end

View file

@ -1,66 +1,63 @@
require_relative '../spec_helper'
describe 'admin/configs', type: :feature do
feature 'admin/configs' do
let(:name) { Faker::Lorem.words(rand(2..4)).join(' ') }
let(:email) { Faker::Internet.email }
let(:admin) { create :admin }
describe type: :feature, js: true do
let(:admin) { create :admin }
before { login admin }
before { login admin }
it 'has initial value' do
FoodsoftConfig[:name] = name
visit admin_config_path
within('form.config') do
expect(find_field('config_name').value).to eq name
it 'has initial value' do
FoodsoftConfig[:name] = name
visit admin_config_path
within('form.config') do
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
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
h.reject! {|k,v| v.blank?}
h
end
h.reject! {|k,v| v.blank?}
h
end
end

View file

@ -1,42 +1,45 @@
require_relative '../spec_helper'
describe LoginController, :type => :feature do
feature LoginController do
let(:user) { create :user }
describe 'forgot password', :type => :feature do
describe 'forgot password' do
before { visit forgot_password_path }
it 'is accessible' do
get forgot_password_path
expect(response).to be_success
expect(page).to have_selector 'input[id=user_email]'
end
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
expect(email.to).to eq [user.email]
end
end
describe 'reset password', :type => :feature do
describe 'and reset it' do
let(:token) { user.reset_password_token }
let(:newpass) { user.new_random_password }
before do
post reset_password_path, user: {email: user.email}
user.reload
end
before { user.request_password_reset! }
before { visit new_password_path(id: user.id, token: token) }
it 'is accessible' do
get new_password_path, id: user.id, token: token
expect(response).to be_success
expect(page).to have_selector 'input[type=password]'
end
it 'is not accessible with wrong token' do
get new_password_path, id: user.id, token: '123'
expect(response).to_not be_success
describe 'with wrong token' do
let(:token) { 'foobar' }
it 'is not accessible' do
expect(page).to have_selector '.alert-error'
expect(page).to_not have_selector 'input[type=password]'
end
end
it 'changes the password' do
patch update_password_path, id: user.id, token: token, user: {password: newpass, password_confirmation: newpass}
expect(page).to_not have_selector('.alert-error')
fill_in 'user_password', with: newpass
fill_in 'user_password_confirmation', with: newpass
find('input[type=submit]').click
expect(User.authenticate(user.email, newpass)).to eq user
end
end

View file

@ -1,6 +1,6 @@
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(:article) { create :article, unit_quantity: 1 }
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(: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
article.supplier
visit orders_path
click_link_or_button I18n.t('orders.index.new_order')
click_link_or_button order.name
expect(page).to have_text I18n.t('orders.new.title')
expect(page).to have_text article.name
end
it 'can get to the new order page' do
article.supplier
visit orders_path
click_link_or_button I18n.t('orders.index.new_order')
click_link_or_button order.name
expect(page).to have_text I18n.t('orders.new.title')
expect(page).to have_text article.name
end
it 'fills in the end date with a schedule' do
FoodsoftConfig[:time_zone] = 'UTC'
FoodsoftConfig[:order_schedule] = {ends: {recurr: 'FREQ=MONTHLY;BYMONTHDAY=1', time: '12:00'}}
visit new_order_path(supplier_id: article.supplier.id)
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_date_value').value).to eq Date.today.next_month.at_beginning_of_month.strftime('%Y-%m-%d')
end
it 'fills in the end date with a schedule' do
FoodsoftConfig[:time_zone] = 'UTC'
FoodsoftConfig[:order_schedule] = {ends: {recurr: 'FREQ=MONTHLY;BYMONTHDAY=1', time: '12:00'}}
visit new_order_path(supplier_id: article.supplier.id)
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_date_value').value).to eq Date.today.next_month.at_beginning_of_month.strftime('%Y-%m-%d')
end
it 'can create a new order' do
visit new_order_path(supplier_id: article.supplier.id)
expect(page).to have_text I18n.t('orders.new.title')
find('input[type="submit"]').click
expect(Order.count).to eq 1
expect(Order.first.supplier).to eq article.supplier
end
it 'can create a new order' do
visit new_order_path(supplier_id: article.supplier.id)
expect(page).to have_text I18n.t('orders.new.title')
find('input[type="submit"]').click
expect(Order.count).to eq 1
expect(Order.first.supplier).to eq article.supplier
end
it 'can close an order' do
setup_and_close_order
expect(order).to be_finished
expect(page).to_not have_link I18n.t('orders.index.action_end')
expect(oa.units_to_order).to eq 1
end
it 'can close an order' do
setup_and_close_order
expect(order).to be_finished
expect(page).to_not have_link I18n.t('orders.index.action_end')
expect(oa.units_to_order).to eq 1
end
def setup_and_close_order
@ -57,5 +55,4 @@ describe Order, type: :feature do
order.reload
oa.reload
end
end

View file

@ -1,6 +1,6 @@
require_relative '../spec_helper'
describe 'product distribution', :type => :feature do
feature 'product distribution', js: true do
let(:admin) { create :admin }
let(:user_a) { 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(:oa) { order.order_articles.first }
describe :type => :feature do
before do
# make sure users have enough money to order
before do
[user_a, user_b].each do |user|
ordergroup = Ordergroup.find(user.ordergroup.id)
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)
[user_a, user_b].each do |user|
ordergroup = Ordergroup.find(user.ordergroup.id)
ordergroup.add_financial_transaction! 5000, 'for ordering', admin
end
order # make sure order is referenced
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

View file

@ -1,6 +1,6 @@
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(:supplier) { create :supplier }
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
end
before { login admin }
describe :type => :feature, :js => true do
before { login admin }
it 'has product ordered visible' do
set_quantities [3,0], [0,0]
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
it 'has product ordered visible' do
set_quantities [3,0], [0,0]
visit receive_order_path(id: order.id)
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(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

View file

@ -1,12 +1,12 @@
require_relative '../spec_helper'
describe 'the session', :type => :feature do
feature 'the session' do
let(:user) { create :user }
describe 'login page', :type => :feature do
describe 'login page' do
it 'is accessible' do
get login_path
expect(response).to be_success
visit login_path
expect(page).to have_selector('input[type=password]')
end
it 'logs me in' do
login user

View file

@ -1,10 +1,10 @@
# encoding: utf-8
require_relative '../spec_helper'
describe SuppliersController, :type => :feature do
feature 'supplier' do
let(:supplier) { create :supplier }
describe :type => :feature, :js => true do
describe 'create new' do
let(:user) { create :user, groups:[create(:workgroup, role_suppliers: true)] }
before { login user }

View file

@ -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 File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rails'
require 'capybara/rspec'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
@ -58,7 +55,7 @@ RSpec.configure do |config|
# --seed 1234
config.order = "random"
config.include SessionHelper
config.include SessionHelper, type: :feature
# Automatically determine spec from directory structure, see:
# https://www.relishapp.com/rspec/rspec-rails/v/3-0/docs/directory-structure
@ -76,8 +73,8 @@ module Faker
end
# include default foodsoft scope in urls, so that *_path works
ActionDispatch::Integration::Runner.class_eval do
undef default_url_options
# https://github.com/rspec/rspec-rails/issues/255
class ActionDispatch::Routing::RouteSet
def default_url_options(options={})
{foodcoop: FoodsoftConfig.scope}.merge(options)
end