Auto correct rubocop style issues

This commit is contained in:
Patrick Gansterer 2022-02-20 16:15:22 +01:00
parent f260e607bf
commit 7e8c1d041d
39 changed files with 115 additions and 199 deletions

View file

@ -5,7 +5,7 @@ describe Article do
let(:article) { create :article, supplier: supplier }
it 'has a unique name' do
article2 = FactoryBot.build :article, supplier: supplier, name: article.name
article2 = build :article, supplier: supplier, name: article.name
expect(article2).to be_invalid
end

View file

@ -130,6 +130,7 @@ describe OrderArticle do
describe 'boxfill' do
before { FoodsoftConfig[:use_boxfill] = true }
let(:article) { create :article, unit_quantity: 6 }
let(:order) { create :order, article_ids: [article.id], starts: 1.week.ago }
let(:oa) { order.order_articles.first }
@ -139,7 +140,7 @@ describe OrderArticle do
shared_examples "boxfill" do |success, q|
# initial situation
before do
goa.update_quantities *q.keys[0]
goa.update_quantities(*q.keys[0])
oa.update_results!; oa.reload
end
@ -149,11 +150,11 @@ describe OrderArticle do
end
# actual test
it (success ? 'succeeds' : 'fails') do
it(success ? 'succeeds' : 'fails') do
order.update_attributes(boxfill: boxfill_from)
r = proc {
goa.update_quantities *q.values[0]
goa.update_quantities(*q.values[0])
oa.update_results!
}
if success
@ -169,9 +170,11 @@ describe OrderArticle do
context 'before the date' do
let(:boxfill_from) { 1.hour.from_now }
context 'decreasing the missing units' do
include_examples "boxfill", true, [6, 0] => [5, 0], [6, 0, 0] => [5, 0, 1]
end
context 'decreasing the tolerance' do
include_examples "boxfill", true, [1, 2] => [1, 1], [1, 2, 3] => [1, 1, 4]
end
@ -179,21 +182,27 @@ describe OrderArticle do
context 'after the date' do
let(:boxfill_from) { 1.second.ago }
context 'changing nothing in particular' do
include_examples "boxfill", true, [4, 1] => [4, 1], [4, 1, 1] => [4, 1, 1]
end
context 'increasing missing units' do
include_examples "boxfill", false, [3, 0] => [2, 0], [3, 0, 3] => [3, 0, 3]
end
context 'increasing tolerance' do
include_examples "boxfill", true, [2, 1] => [2, 2], [2, 1, 3] => [2, 2, 2]
end
context 'decreasing quantity to fix missing units' do
include_examples "boxfill", true, [7, 0] => [6, 0], [7, 0, 5] => [6, 0, 0]
end
context 'decreasing quantity keeping missing units equal' do
include_examples "boxfill", false, [7, 0] => [1, 0], [7, 0, 5] => [7, 0, 5]
end
context 'moving tolerance to quantity' do
include_examples "boxfill", true, [4, 2] => [6, 0], [4, 2, 0] => [6, 0, 0]
end

View file

@ -24,46 +24,46 @@ describe Order do
let!(:received_order) { create :order, state: 'received' }
let!(:closed_order) { create :order, state: 'closed' }
it 'should retrieve open orders in the "open" scope' do
it 'retrieves open orders in the "open" scope' do
expect(Order.open.count).to eq(1)
expect(Order.open.where(id: open_order.id)).to exist
end
it 'should retrieve finished, received and closed orders in the "finished" scope' do
it 'retrieves finished, received and closed orders in the "finished" scope' do
expect(Order.finished.count).to eq(3)
expect(Order.finished.where(id: finished_order.id)).to exist
expect(Order.finished.where(id: received_order.id)).to exist
expect(Order.finished.where(id: closed_order.id)).to exist
end
it 'should retrieve finished and received orders in the "finished_not_closed" scope' do
it 'retrieves finished and received orders in the "finished_not_closed" scope' do
expect(Order.finished_not_closed.count).to eq(2)
expect(Order.finished_not_closed.where(id: finished_order.id)).to exist
expect(Order.finished_not_closed.where(id: received_order.id)).to exist
end
it 'should return valid boolean states for open orders' do
it 'returns valid boolean states for open orders' do
expect(open_order.open?).to be(true)
expect(open_order.finished?).to be(false)
expect(open_order.received?).to be(false)
expect(open_order.closed?).to be(false)
end
it 'should return valid boolean states for finished orders' do
it 'returns valid boolean states for finished orders' do
expect(finished_order.open?).to be(false)
expect(finished_order.finished?).to be(true)
expect(finished_order.received?).to be(false)
expect(finished_order.closed?).to be(false)
end
it 'should return valid boolean states for received orders' do
it 'returns valid boolean states for received orders' do
expect(received_order.open?).to be(false)
expect(received_order.finished?).to be(true)
expect(received_order.received?).to be(true)
expect(received_order.closed?).to be(false)
end
it 'should return valid boolean states for closed orders' do
it 'returns valid boolean states for closed orders' do
expect(closed_order.open?).to be(false)
expect(closed_order.finished?).to be(false)
expect(closed_order.received?).to be(false)
@ -122,6 +122,7 @@ describe Order do
describe 'with a default end date' do
let(:order) { create :order }
before do
FoodsoftConfig[:order_schedule] = { ends: { recurr: 'FREQ=WEEKLY;BYDAY=MO', time: '9:00' } }
order.init_dates

View file

@ -15,6 +15,7 @@ describe User do
describe 'does not have the role' do
let(:user) { create :user }
it 'admin' do expect(user.role_admin?).to be_falsey end
it 'finance' do expect(user.role_finance?).to be_falsey end
it 'article_meta' do expect(user.role_article_meta?).to be_falsey end
@ -28,20 +29,25 @@ describe User do
it 'can authenticate with correct password' do
expect(User.authenticate(user.nick, 'blahblahblah')).to be_truthy
end
it 'can not authenticate with incorrect password' do
expect(User.authenticate(user.nick, 'foobar')).to be_nil
end
it 'can not authenticate with nil nick' do
expect(User.authenticate(nil, 'blahblahblah')).to be_nil
end
it 'can not authenticate with nil password' do
expect(User.authenticate(user.nick, nil)).to be_nil
end
it 'can not set a password without matching confirmation' do
user.password = 'abcdefghijkl'
user.password_confirmation = 'foobaruvwxyz'
expect(user).to be_invalid
end
it 'can set a password with matching confirmation' do
user.password = 'abcdefghijkl'
user.password_confirmation = 'abcdefghijkl'
@ -51,6 +57,7 @@ describe User do
it 'has a unique nick' do
expect(build(:user, nick: user.nick, email: "x-#{user.email}")).to be_invalid
end
it 'has a unique email' do
expect(build(:user, email: "#{user.email}")).to be_invalid
end
@ -68,6 +75,7 @@ describe User do
describe 'admin' do
let(:user) { create :admin }
it 'default admin role' do expect(user.role_admin?).to be_truthy end
end
end