mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-29 21:17:17 +00:00
Inspecting 1483 files
..............................................................................................................................................................C.............................................................................................................................................................................CC.............................................................................................................................................................................C.................................................................................................................................................................................................................................................................................................................................................................C.................................................................................C..............................................................................................................................................................................................C.....................................................................................................................................................................................................................................C......................................................................................................................
Offenses:
app/helpers/discourse_helper.rb:9:5: C: [Corrected] Style/FetchEnvVar: Use ENV.fetch('DISCOURSE_URL') or ENV.fetch('DISCOURSE_URL', nil) instead of ENV['DISCOURSE_URL'].
ENV['DISCOURSE_URL']
^^^^^^^^^^^^^^^^^^^^
app/models/spree/preferences/configuration.rb:35:10: C: [Corrected] Style/FetchEnvVar: Use ENV.fetch('RAILS_CACHE_ID') or ENV.fetch('RAILS_CACHE_ID', nil) instead of ENV['RAILS_CACHE_ID'].
[ENV['RAILS_CACHE_ID'], self.class.name, name].flatten.join('::').underscore
^^^^^^^^^^^^^^^^^^^^^
app/models/spree/preferences/preferable.rb:84:10: C: [Corrected] Style/FetchEnvVar: Use ENV.fetch("RAILS_CACHE_ID") or ENV.fetch("RAILS_CACHE_ID", nil) instead of ENV["RAILS_CACHE_ID"].
[ENV["RAILS_CACHE_ID"], self.class.name, name, id].join('::').underscore
^^^^^^^^^^^^^^^^^^^^^
app/services/default_country.rb:13:40: C: [Corrected] Style/FetchEnvVar: Use ENV.fetch("DEFAULT_COUNTRY_CODE") or ENV.fetch("DEFAULT_COUNTRY_CODE", nil) instead of ENV["DEFAULT_COUNTRY_CODE"].
Spree::Country.cached_find_by(iso: ENV["DEFAULT_COUNTRY_CODE"]) || Spree::Country.first
^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/default_country.rb:13:73: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
Spree::Country.cached_find_by(iso: ENV.fetch("DEFAULT_COUNTRY_CODE",
^
app/services/default_country.rb:13:101: C: [Corrected] Layout/LineLength: Line is too long. [102/100]
Spree::Country.cached_find_by(iso: ENV.fetch("DEFAULT_COUNTRY_CODE", nil)) || Spree::Country.first
^^
app/services/default_country.rb:14:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
nil)) || Spree::Country.first
^^^
spec/base_spec_helper.rb:51:49: C: [Corrected] Style/FetchEnvVar: Use ENV.fetch("SITE_URL") or ENV.fetch("SITE_URL", nil) instead of ENV["SITE_URL"].
ActionMailer::Base.default_url_options[:host] = ENV["SITE_URL"]
^^^^^^^^^^^^^^^
spec/controllers/spree/credit_cards_controller_spec.rb:8:20: C: [Corrected] Style/FetchEnvVar: Use ENV.fetch('STRIPE_SECRET_TEST_API_KEY') or ENV.fetch('STRIPE_SECRET_TEST_API_KEY', nil) instead of ENV['STRIPE_SECRET_TEST_API_KEY'].
let(:secret) { ENV['STRIPE_SECRET_TEST_API_KEY'] }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/order_balance_spec.rb:48:70: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
expect(order_balance.display_amount).to eq(Spree::Money.new(20,
^
spec/models/order_balance_spec.rb:48:81: C: [Corrected] Style/FetchEnvVar: Use ENV.fetch('currency') or ENV.fetch('currency', nil) instead of ENV['currency'].
expect(order_balance.display_amount).to eq(Spree::Money.new(20, currency: ENV['currency']))
^^^^^^^^^^^^^^^
spec/models/order_balance_spec.rb:48:101: C: [Corrected] Layout/LineLength: Line is too long. [108/100]
expect(order_balance.display_amount).to eq(Spree::Money.new(20, currency: ENV.fetch('currency', nil)))
^^^^^^^^
spec/models/order_balance_spec.rb:49:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
currency: ENV.fetch('currency', nil)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/order_balance_spec.rb:49:98: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
currency: ENV.fetch('currency',
^
spec/models/order_balance_spec.rb:49:101: C: [Corrected] Layout/LineLength: Line is too long. [104/100]
currency: ENV.fetch('currency', nil)))
^^^^
spec/models/order_balance_spec.rb:50:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
nil)))
^^^
spec/support/vcr_setup.rb:10:50: C: [Corrected] Style/FetchEnvVar: Use ENV.fetch('STRIPE_SECRET_TEST_API_KEY') or ENV.fetch('STRIPE_SECRET_TEST_API_KEY', nil) instead of ENV['STRIPE_SECRET_TEST_API_KEY'].
config.filter_sensitive_data('<HIDDEN_KEY>') { ENV['STRIPE_SECRET_TEST_API_KEY'] }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/support/vcr_setup.rb:11:55: C: [Corrected] Style/FetchEnvVar: Use ENV.fetch('STRIPE_CUSTOMER') or ENV.fetch('STRIPE_CUSTOMER', nil) instead of ENV['STRIPE_CUSTOMER'].
config.filter_sensitive_data('<HIDDEN_CUSTOMER>') { ENV['STRIPE_CUSTOMER'] }
^^^^^^^^^^^^^^^^^^^^^^
1483 files inspected, 18 offenses detected, 18 offenses corrected
184 lines
4.3 KiB
Ruby
184 lines
4.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
describe OrderBalance do
|
|
subject(:order_balance) { described_class.new(order) }
|
|
let(:order) { build(:order) }
|
|
let(:user) { order.user }
|
|
|
|
describe '#label' do
|
|
context 'when the balance is positive' do
|
|
before do
|
|
allow(order).to receive(:new_outstanding_balance) { 10 }
|
|
end
|
|
|
|
it "returns 'balance due'" do
|
|
expect(order_balance.label).to eq('Balance due')
|
|
end
|
|
end
|
|
|
|
context 'when the balance is negative' do
|
|
before do
|
|
allow(order).to receive(:new_outstanding_balance) { -10 }
|
|
end
|
|
|
|
it "returns 'credit owed'" do
|
|
expect(order_balance.label).to eq('Credit Owed')
|
|
end
|
|
end
|
|
|
|
context 'when the balance is zero' do
|
|
before do
|
|
allow(order).to receive(:new_outstanding_balance) { 0 }
|
|
end
|
|
|
|
it "returns 'balance due'" do
|
|
expect(order_balance.label).to eq('Balance due')
|
|
end
|
|
end
|
|
end
|
|
|
|
describe '#display_amount' do
|
|
before do
|
|
allow(order).to receive(:new_outstanding_balance) { 20 }
|
|
end
|
|
|
|
it 'returns the balance wraped in a Money object' do
|
|
expect(order_balance.display_amount).to eq(Spree::Money.new(20,
|
|
currency: ENV.fetch('currency',
|
|
nil)))
|
|
end
|
|
end
|
|
|
|
describe '#zero?' do
|
|
context 'when the balance is zero' do
|
|
before do
|
|
allow(order).to receive(:new_outstanding_balance) { 0 }
|
|
end
|
|
|
|
it 'returns true' do
|
|
expect(order_balance.zero?).to eq(true)
|
|
end
|
|
end
|
|
|
|
context 'when the balance is positive' do
|
|
before do
|
|
allow(order).to receive(:new_outstanding_balance) { 10 }
|
|
end
|
|
|
|
it 'returns false' do
|
|
expect(order_balance.zero?).to eq(false)
|
|
end
|
|
end
|
|
|
|
context 'when the balance is negative' do
|
|
before do
|
|
allow(order).to receive(:new_outstanding_balance) { -10 }
|
|
end
|
|
|
|
it 'returns false' do
|
|
expect(order_balance.zero?).to eq(false)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe '#amount' do
|
|
before do
|
|
allow(order).to receive(:new_outstanding_balance) { 123 }
|
|
end
|
|
|
|
it 'calls #new_outstanding_balance' do
|
|
expect(order).to receive(:new_outstanding_balance)
|
|
expect(order_balance.amount).to eq(123)
|
|
end
|
|
end
|
|
|
|
describe '#abs' do
|
|
context 'when the balance is zero' do
|
|
before do
|
|
allow(order).to receive(:new_outstanding_balance) { 0 }
|
|
end
|
|
|
|
it 'returns its absolute value' do
|
|
expect(order_balance.abs).to eq(0)
|
|
end
|
|
end
|
|
|
|
context 'when the balance is positive' do
|
|
before do
|
|
allow(order).to receive(:new_outstanding_balance) { 10 }
|
|
end
|
|
|
|
it 'returns its absolute value' do
|
|
expect(order_balance.abs).to eq(10)
|
|
end
|
|
end
|
|
|
|
context 'when the balance is negative' do
|
|
before do
|
|
allow(order).to receive(:new_outstanding_balance) { -10 }
|
|
end
|
|
|
|
it 'returns its absolute value' do
|
|
expect(order_balance.abs).to eq(10)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe '#to_s' do
|
|
before do
|
|
allow(order).to receive(:new_outstanding_balance) { 10 }
|
|
end
|
|
|
|
it 'returns the balance as a string' do
|
|
expect(order_balance.to_s).to eq('10')
|
|
end
|
|
end
|
|
|
|
describe '#to_f' do
|
|
before do
|
|
allow(order).to receive(:new_outstanding_balance) { 10 }
|
|
end
|
|
|
|
it 'returns the balance as a float' do
|
|
expect(order_balance.to_f).to eq(10.0)
|
|
end
|
|
end
|
|
|
|
describe '#to_d' do
|
|
before do
|
|
allow(order).to receive(:new_outstanding_balance) { 10 }
|
|
end
|
|
|
|
it 'returns the balance as a decimal' do
|
|
expect(order_balance.to_d).to eq(10.0)
|
|
end
|
|
end
|
|
|
|
describe '#+' do
|
|
let(:other_order_balance) { described_class.new(order) }
|
|
|
|
before do
|
|
allow(order).to receive(:new_outstanding_balance) { 10 }
|
|
end
|
|
|
|
it 'returns the balance as a string' do
|
|
expect(order_balance + other_order_balance).to eq(20.0)
|
|
end
|
|
end
|
|
|
|
describe '#< and #>' do
|
|
before do
|
|
allow(order).to receive(:new_outstanding_balance) { 10 }
|
|
end
|
|
|
|
it 'correctly returns true or false' do
|
|
expect(order_balance > 5).to eq true
|
|
expect(order_balance > 20).to eq false
|
|
expect(order_balance < 15).to eq true
|
|
expect(order_balance < 5).to eq false
|
|
end
|
|
end
|
|
end
|