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 '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
|
||||
|
|
46
Gemfile.lock
46
Gemfile.lock
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -120,6 +120,20 @@ class User < ActiveRecord::Base
|
|||
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?}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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,7 +27,6 @@ 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) }
|
||||
|
||||
|
@ -178,7 +177,4 @@ describe 'settling an order', :type => :feature do
|
|||
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,11 +1,10 @@
|
|||
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 }
|
||||
|
||||
describe type: :feature, js: true do
|
||||
let(:admin) { create :admin }
|
||||
|
||||
before { login admin }
|
||||
|
||||
it 'has initial value' do
|
||||
|
@ -61,6 +60,4 @@ describe 'admin/configs', type: :feature do
|
|||
h.reject! {|k,v| v.blank?}
|
||||
h
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,7 +8,6 @@ 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 }
|
||||
|
||||
it 'can get to the new order page' do
|
||||
|
@ -43,7 +42,6 @@ describe Order, type: :feature do
|
|||
expect(page).to_not have_link I18n.t('orders.index.action_end')
|
||||
expect(oa.units_to_order).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
def setup_and_close_order
|
||||
# have at least something ordered
|
||||
|
@ -57,5 +55,4 @@ describe Order, type: :feature do
|
|||
order.reload
|
||||
oa.reload
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -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,32 +9,32 @@ 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
|
||||
# make sure users have enough money to order
|
||||
before do
|
||||
# make sure users have enough money to order
|
||||
[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', :js => true do
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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
|
||||
|
@ -52,6 +52,4 @@ describe 'product distribution', :type => :feature do
|
|||
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'
|
||||
|
||||
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,32 +34,30 @@ describe 'receiving an order', :type => :feature do
|
|||
expect(goa2.destroyed? ? 0 : goa2.result).to be_within(1e-3).of q2
|
||||
end
|
||||
|
||||
|
||||
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)
|
||||
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(order)
|
||||
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(order)
|
||||
expect(find("#order_articles_#{oa.id}_units_received").value).to eq ''
|
||||
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(order)
|
||||
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')
|
||||
|
@ -68,7 +66,7 @@ describe 'receiving an order', :type => :feature do
|
|||
|
||||
it 'redistributes properly when received is more' do
|
||||
set_quantities [2,0], [3,2]
|
||||
visit receive_order_path(order)
|
||||
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')
|
||||
|
@ -77,7 +75,7 @@ describe 'receiving an order', :type => :feature do
|
|||
|
||||
it 'redistributes properly when received is less' do
|
||||
set_quantities [2,0], [3,2]
|
||||
visit receive_order_path(order)
|
||||
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')
|
||||
|
@ -88,7 +86,7 @@ describe 'receiving an order', :type => :feature do
|
|||
set_quantities [2,0], [3,2]
|
||||
goa1.result = goa1.result + 1
|
||||
goa1.save!
|
||||
visit receive_order_path(order)
|
||||
visit receive_order_path(id: order.id)
|
||||
expect(find("#order_articles_#{oa.id}_units_received")).to be_disabled
|
||||
end
|
||||
|
||||
|
@ -96,12 +94,9 @@ describe 'receiving an order', :type => :feature do
|
|||
set_quantities [2,0], [3,2]
|
||||
goa1.result = goa1.result + 1
|
||||
goa1.save!
|
||||
visit receive_order_path(order)
|
||||
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'
|
||||
|
||||
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
|
||||
|
|
|
@ -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 }
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue