commit
5f9b144c53
17 changed files with 65 additions and 63 deletions
|
@ -10,7 +10,7 @@ FactoryGirl.define do
|
|||
deposit { rand(10) < 8 ? 0 : [0.0, 0.80, 1.20, 12.00].sample }
|
||||
unit_quantity { rand(5) < 3 ? 1 : rand(1..20) }
|
||||
#supplier_id
|
||||
article_category { FactoryGirl.create :article_category }
|
||||
article_category { create :article_category }
|
||||
end
|
||||
|
||||
factory :article_category do
|
||||
|
|
|
@ -4,7 +4,7 @@ FactoryGirl.define do
|
|||
|
||||
# requires order
|
||||
factory :group_order do
|
||||
ordergroup { FactoryGirl.create(:user, groups: [FactoryGirl.create(:ordergroup)]).ordergroup }
|
||||
ordergroup { create(:user, groups: [FactoryGirl.create(:ordergroup)]).ordergroup }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ FactoryGirl.define do
|
|||
|
||||
factory :order do
|
||||
starts { Time.now }
|
||||
supplier { FactoryGirl.create :supplier, article_count: (article_count.nil? ? true : article_count) }
|
||||
supplier { create :supplier, article_count: (article_count.nil? ? true : article_count) }
|
||||
article_ids { supplier.articles.map(&:id) unless supplier.nil? }
|
||||
|
||||
ignore do
|
||||
|
|
|
@ -14,7 +14,7 @@ FactoryGirl.define do
|
|||
after :create do |supplier, evaluator|
|
||||
article_count = evaluator.article_count
|
||||
article_count = rand(1..99) if article_count == true
|
||||
FactoryGirl.create_list :article, article_count, supplier: supplier
|
||||
create_list :article, article_count, supplier: supplier
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ FactoryGirl.define do
|
|||
sequence(:nick) { |n| "admin#{n}" }
|
||||
first_name 'Administrator'
|
||||
after :create do |user, evaluator|
|
||||
FactoryGirl.create :workgroup, role_admin: true, user_ids: [user.id]
|
||||
create :workgroup, role_admin: true, user_ids: [user.id]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
require 'spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
|
||||
describe 'settling an order', :type => :feature do
|
||||
let(:admin) { FactoryGirl.create :user, groups:[FactoryGirl.create(:workgroup, role_finance: true)] }
|
||||
let(:supplier) { FactoryGirl.create :supplier }
|
||||
let(:article) { FactoryGirl.create :article, supplier: supplier, unit_quantity: 1 }
|
||||
let(:order) { FactoryGirl.create :order, supplier: supplier, article_ids: [article.id] } # need to ref article
|
||||
let(:go1) { FactoryGirl.create :group_order, order: order }
|
||||
let(:go2) { FactoryGirl.create :group_order, order: order }
|
||||
let(:admin) { create :user, groups:[create(:workgroup, role_finance: true)] }
|
||||
let(:supplier) { create :supplier }
|
||||
let(:article) { create :article, supplier: supplier, unit_quantity: 1 }
|
||||
let(:order) { create :order, supplier: supplier, article_ids: [article.id] } # need to ref article
|
||||
let(:go1) { create :group_order, order: order }
|
||||
let(:go2) { create :group_order, order: order }
|
||||
let(:oa) { order.order_articles.find_by_article_id(article.id) }
|
||||
let(:goa1) { FactoryGirl.create :group_order_article, group_order: go1, order_article: oa }
|
||||
let(:goa2) { FactoryGirl.create :group_order_article, group_order: go2, order_article: oa }
|
||||
let(:goa1) { create :group_order_article, group_order: go1, order_article: oa }
|
||||
let(:goa2) { create :group_order_article, group_order: go2, order_article: oa }
|
||||
before do
|
||||
goa1.update_quantities(3, 0)
|
||||
goa2.update_quantities(1, 0)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
require 'spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
|
||||
describe 'product distribution', :type => :feature do
|
||||
let(:admin) { FactoryGirl.create :admin }
|
||||
let(:user_a) { FactoryGirl.create :user, groups: [FactoryGirl.create(:ordergroup)] }
|
||||
let(:user_b) { FactoryGirl.create :user, groups: [FactoryGirl.create(:ordergroup)] }
|
||||
let(:supplier) { FactoryGirl.create :supplier }
|
||||
let(:article) { FactoryGirl.create :article, supplier: supplier, unit_quantity: 5 }
|
||||
let(:order) { FactoryGirl.create(:order, supplier: supplier, article_ids: [article.id]) }
|
||||
let(:admin) { create :admin }
|
||||
let(:user_a) { create :user, groups: [create(:ordergroup)] }
|
||||
let(:user_b) { create :user, groups: [create(:ordergroup)] }
|
||||
let(:supplier) { create :supplier }
|
||||
let(:article) { create :article, supplier: supplier, unit_quantity: 5 }
|
||||
let(:order) { create(:order, supplier: supplier, article_ids: [article.id]) }
|
||||
let(:oa) { order.order_articles.first }
|
||||
|
||||
describe :type => :feature do
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
|
||||
describe 'the session', :type => :feature do
|
||||
let(:user) { FactoryGirl.create :user }
|
||||
let(:user) { create :user }
|
||||
|
||||
describe 'login page', :type => :feature do
|
||||
it 'is accesible' do
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
require 'spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
|
||||
describe 'supplier', :type => :feature do
|
||||
let(:supplier) { FactoryGirl.create :supplier }
|
||||
let(:supplier) { create :supplier }
|
||||
|
||||
describe :type => :feature, :js => true do
|
||||
let(:user) { FactoryGirl.create :user, groups:[FactoryGirl.create(:workgroup, role_suppliers: true)] }
|
||||
let(:user) { create :user, groups:[create(:workgroup, role_suppliers: true)] }
|
||||
before { login user }
|
||||
|
||||
it 'can be created' do
|
||||
visit suppliers_path
|
||||
click_on I18n.t('suppliers.index.action_new')
|
||||
supplier = FactoryGirl.build :supplier
|
||||
supplier = build :supplier
|
||||
within('#new_supplier') do
|
||||
fill_in 'supplier_name', :with => supplier.name
|
||||
fill_in 'supplier_address', :with => supplier.address
|
||||
|
@ -28,8 +28,8 @@ describe 'supplier', :type => :feature do
|
|||
end
|
||||
|
||||
describe :type => :feature, :js => true do
|
||||
let(:article_category) { FactoryGirl.create :article_category }
|
||||
let(:user) { FactoryGirl.create :user, groups:[FactoryGirl.create(:workgroup, role_article_meta: true)] }
|
||||
let(:article_category) { create :article_category }
|
||||
let(:user) { create :user, groups:[create(:workgroup, role_article_meta: true)] }
|
||||
before { login user }
|
||||
|
||||
it 'can visit supplier articles path' do
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
|
||||
describe Article do
|
||||
let(:supplier) { FactoryGirl.create :supplier }
|
||||
let(:article) { FactoryGirl.create :article, supplier: supplier }
|
||||
let(:supplier) { create :supplier }
|
||||
let(:article) { create :article, supplier: supplier }
|
||||
|
||||
it 'has a unique name' do
|
||||
article2 = FactoryGirl.build :article, supplier: supplier, name: article.name
|
||||
|
@ -43,5 +43,4 @@ describe Article do
|
|||
article.save!
|
||||
expect(article.article_prices.all.map(&:price)).to eq([article.price, oldprice])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
require 'spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
|
||||
describe GroupOrderArticle do
|
||||
let(:user) { FactoryGirl.create :user, groups: [FactoryGirl.create(:ordergroup)] }
|
||||
let(:order) { FactoryGirl.create(:order).reload }
|
||||
let(:go) { FactoryGirl.create :group_order, order: order, ordergroup: user.ordergroup }
|
||||
let(:goa) { FactoryGirl.create :group_order_article, group_order: go, order_article: order.order_articles.first }
|
||||
let(:user) { create :user, groups: [create(:ordergroup)] }
|
||||
let(:order) { create(:order) }
|
||||
let(:go) { create :group_order, order: order, ordergroup: user.ordergroup }
|
||||
let(:goa) { create :group_order_article, group_order: go, order_article: order.order_articles.first }
|
||||
|
||||
it 'has zero quantity by default' do expect(goa.quantity).to eq(0) end
|
||||
it 'has zero tolerance by default' do expect(goa.tolerance).to eq(0) end
|
||||
|
@ -13,9 +13,9 @@ describe GroupOrderArticle do
|
|||
it 'has zero total price by default' do expect(goa.total_price).to eq(0) end
|
||||
|
||||
describe do
|
||||
let(:article) { FactoryGirl.create :article, supplier: order.supplier, unit_quantity: 1 }
|
||||
let(:article) { create :article, supplier: order.supplier, unit_quantity: 1 }
|
||||
let(:oa) { order.order_articles.create(:article => article) }
|
||||
let(:goa) { FactoryGirl.create :group_order_article, group_order: go, order_article: oa }
|
||||
let(:goa) { create :group_order_article, group_order: go, order_article: oa }
|
||||
|
||||
it 'can be ordered by piece' do
|
||||
goa.update_quantities(1, 0)
|
||||
|
@ -42,7 +42,6 @@ describe GroupOrderArticle do
|
|||
expect(goa.quantity).to eq(0)
|
||||
expect(goa.tolerance).to eq(0)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
|
||||
describe GroupOrder do
|
||||
let(:user) { FactoryGirl.create :user, groups: [FactoryGirl.create(:ordergroup)] }
|
||||
let(:order) { FactoryGirl.create :order }
|
||||
let(:user) { create :user, groups: [create(:ordergroup)] }
|
||||
let(:order) { create :order }
|
||||
|
||||
# the following two tests are currently disabled - https://github.com/foodcoops/foodsoft/issues/158
|
||||
|
||||
|
@ -15,7 +15,7 @@ describe GroupOrder do
|
|||
#end
|
||||
|
||||
describe do
|
||||
let(:go) { FactoryGirl.create :group_order, order: order, ordergroup: user.ordergroup }
|
||||
let(:go) { create :group_order, order: order, ordergroup: user.ordergroup }
|
||||
|
||||
it 'has zero price initially' do
|
||||
expect(go.price).to eq(0)
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
require 'spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
|
||||
describe Order do
|
||||
|
||||
it 'needs a supplier' do
|
||||
expect(FactoryGirl.build(:order, supplier: nil)).to be_invalid
|
||||
expect(build(:order, supplier: nil)).to be_invalid
|
||||
end
|
||||
|
||||
it 'needs order articles' do
|
||||
supplier = FactoryGirl.create :supplier, article_count: 0
|
||||
expect(FactoryGirl.build(:order, supplier: supplier)).to be_invalid
|
||||
supplier = create :supplier, article_count: 0
|
||||
expect(build(:order, supplier: supplier)).to be_invalid
|
||||
end
|
||||
|
||||
it 'can be created' do
|
||||
expect(FactoryGirl.build(:order, article_count: 1)).to be_valid
|
||||
expect(build(:order, article_count: 1)).to be_valid
|
||||
end
|
||||
|
||||
describe 'with articles' do
|
||||
let(:order) { FactoryGirl.create :order }
|
||||
let(:order) { create :order }
|
||||
|
||||
it 'is open by default' do expect(order).to be_open end
|
||||
it 'is not finished by default' do expect(order).to_not be_finished end
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
require 'spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
|
||||
describe Supplier do
|
||||
let(:supplier) { FactoryGirl.create :supplier }
|
||||
let(:supplier) { create :supplier }
|
||||
|
||||
it 'has a unique name' do
|
||||
supplier2 = FactoryGirl.build :supplier, name: supplier.name
|
||||
supplier2 = build :supplier, name: supplier.name
|
||||
expect(supplier2).to be_invalid
|
||||
end
|
||||
|
||||
it 'has valid articles' do
|
||||
supplier = FactoryGirl.create :supplier, article_count: true
|
||||
supplier = create :supplier, article_count: true
|
||||
supplier.articles.all.each {|a| expect(a).to be_valid }
|
||||
end
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
require 'spec_helper'
|
||||
require_relative '../spec_helper'
|
||||
|
||||
describe User do
|
||||
|
||||
it 'is correctly created' do
|
||||
user = FactoryGirl.create :user,
|
||||
user = create :user,
|
||||
nick: 'johnnydoe', first_name: 'Johnny', last_name: 'DoeBar',
|
||||
email: 'johnnydoe@foodcoop.test', phone: '+1234567890'
|
||||
expect(user.nick).to eq('johnnydoe')
|
||||
|
@ -15,7 +15,7 @@ describe User do
|
|||
end
|
||||
|
||||
describe 'does not have the role' do
|
||||
let(:user) { FactoryGirl.create :user }
|
||||
let(:user) { create :user }
|
||||
it 'admin' do expect(user.role_admin?).to be_false end
|
||||
it 'finance' do expect(user.role_finance?).to be_false end
|
||||
it 'article_meta' do expect(user.role_article_meta?).to be_false end
|
||||
|
@ -24,7 +24,7 @@ describe User do
|
|||
end
|
||||
|
||||
describe do
|
||||
let(:user) { FactoryGirl.create :user, password: 'blahblah' }
|
||||
let(:user) { create :user, password: 'blahblah' }
|
||||
|
||||
it 'can authenticate with correct password' do
|
||||
expect(User.authenticate(user.nick, 'blahblah')).to be_true
|
||||
|
@ -44,15 +44,15 @@ describe User do
|
|||
end
|
||||
|
||||
it 'has a unique nick' do
|
||||
expect(FactoryGirl.build(:user, nick: user.nick, email: "x-#{user.email}")).to be_invalid
|
||||
expect(build(:user, nick: user.nick, email: "x-#{user.email}")).to be_invalid
|
||||
end
|
||||
it 'has a unique email' do
|
||||
expect(FactoryGirl.build(:user, email: "#{user.email}")).to be_invalid
|
||||
expect(build(:user, email: "#{user.email}")).to be_invalid
|
||||
end
|
||||
end
|
||||
|
||||
describe 'admin' do
|
||||
let(:user) { FactoryGirl.create :admin }
|
||||
let(:user) { create :admin }
|
||||
it 'default admin role' do expect(user.role_admin?).to be_true end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
||||
ENV["RAILS_ENV"] ||= 'test'
|
||||
require 'support/coverage' # needs to be first
|
||||
require_relative 'support/coverage' # needs to be first
|
||||
require File.expand_path("../../config/environment", __FILE__)
|
||||
require 'rspec/rails'
|
||||
require 'rspec/autorun'
|
||||
|
|
4
spec/support/factory_girl.rb
Normal file
4
spec/support/factory_girl.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
RSpec.configure do |config|
|
||||
# load FactoryGirl shortcuts create(), etc.
|
||||
config.include FactoryGirl::Syntax::Methods
|
||||
end
|
Loading…
Reference in a new issue