diff options
author | Jared Norman <jared@super.gd> | 2020-07-07 18:30:11 -0700 |
---|---|---|
committer | Jared Norman <jared@super.gd> | 2020-07-14 13:07:55 -0700 |
commit | c170aa6c7e82560747e252682852984d2e8fdba0 (patch) | |
tree | 61c1019cadb134fec4f34ffc3680c933826eeba9 | |
parent | 15e30c62c721bd6f5e17dcd3d2f610f4b164269c (diff) |
Run project through standardrb
-rwxr-xr-x | bin/rails-engine | 12 | ||||
-rwxr-xr-x | bin/rails-sandbox | 8 | ||||
-rw-r--r-- | lib/super_good-solidus_taxjar.rb | 2 | ||||
-rw-r--r-- | lib/super_good/solidus_taxjar.rb | 6 | ||||
-rw-r--r-- | lib/super_good/solidus_taxjar/api.rb | 2 | ||||
-rw-r--r-- | lib/super_good/solidus_taxjar/api_params.rb | 10 | ||||
-rw-r--r-- | lib/super_good/solidus_taxjar/calculator_helper.rb | 2 | ||||
-rw-r--r-- | lib/super_good/solidus_taxjar/tax_calculator.rb | 18 | ||||
-rw-r--r-- | lib/super_good/solidus_taxjar/tax_rate_calculator.rb | 7 | ||||
-rw-r--r-- | spec/spec_helper.rb | 10 | ||||
-rw-r--r-- | spec/super_good/solidus_taxjar/api_params_spec.rb | 26 | ||||
-rw-r--r-- | spec/super_good/solidus_taxjar/api_spec.rb | 50 | ||||
-rw-r--r-- | spec/super_good/solidus_taxjar/discount_calculator_spec.rb | 2 | ||||
-rw-r--r-- | spec/super_good/solidus_taxjar/tax_calculator_spec.rb | 2 | ||||
-rw-r--r-- | spec/super_good/solidus_taxjar/tax_rate_calculator_spec.rb | 4 | ||||
-rw-r--r-- | spec/super_good/solidus_taxjar_spec.rb | 16 |
16 files changed, 88 insertions, 89 deletions
diff --git a/bin/rails-engine b/bin/rails-engine index 3684b30..5853e4d 100755 --- a/bin/rails-engine +++ b/bin/rails-engine @@ -2,12 +2,12 @@ # This command will automatically be run when you run "rails" with Rails gems # installed from the root of your application. -ENGINE_ROOT = File.expand_path('..', __dir__) -ENGINE_PATH = File.expand_path('../lib/solidus_taxjar/engine', __dir__) +ENGINE_ROOT = File.expand_path("..", __dir__) +ENGINE_PATH = File.expand_path("../lib/solidus_taxjar/engine", __dir__) # Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) -require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) +require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) -require 'rails/all' -require 'rails/engine/commands' +require "rails/all" +require "rails/engine/commands" diff --git a/bin/rails-sandbox b/bin/rails-sandbox index c89b2ae..78020af 100755 --- a/bin/rails-sandbox +++ b/bin/rails-sandbox @@ -1,16 +1,16 @@ #!/usr/bin/env ruby -app_root = 'sandbox' +app_root = "sandbox" unless File.exist? "#{app_root}/bin/rails" - warn 'Creating the sandbox app...' + warn "Creating the sandbox app..." Dir.chdir "#{__dir__}/.." do system "#{__dir__}/sandbox" or begin # rubocop:disable Style/AndOr - warn 'Automatic creation of the sandbox app failed' + warn "Automatic creation of the sandbox app failed" exit 1 end end end Dir.chdir app_root -exec 'bin/rails', *ARGV +exec "bin/rails", *ARGV diff --git a/lib/super_good-solidus_taxjar.rb b/lib/super_good-solidus_taxjar.rb index e41f8a4..f7f97c7 100644 --- a/lib/super_good-solidus_taxjar.rb +++ b/lib/super_good-solidus_taxjar.rb @@ -1 +1 @@ -require 'super_good/solidus_taxjar' +require "super_good/solidus_taxjar" diff --git a/lib/super_good/solidus_taxjar.rb b/lib/super_good/solidus_taxjar.rb index 2c47dda..bdd2dcd 100644 --- a/lib/super_good/solidus_taxjar.rb +++ b/lib/super_good/solidus_taxjar.rb @@ -1,6 +1,6 @@ -require 'solidus_core' -require 'solidus_support' -require 'taxjar' +require "solidus_core" +require "solidus_support" +require "taxjar" require "super_good/solidus_taxjar/version" require "super_good/solidus_taxjar/api_params" diff --git a/lib/super_good/solidus_taxjar/api.rb b/lib/super_good/solidus_taxjar/api.rb index 601a2ae..865bb45 100644 --- a/lib/super_good/solidus_taxjar/api.rb +++ b/lib/super_good/solidus_taxjar/api.rb @@ -4,7 +4,7 @@ module SuperGood def self.default_taxjar_client ::Taxjar::Client.new( api_key: ENV.fetch("TAXJAR_API_KEY"), - api_url: ENV.fetch("TAXJAR_API_URL") { 'https://api.taxjar.com' } # Sandbox URL: https://api.sandbox.taxjar.com + api_url: ENV.fetch("TAXJAR_API_URL") { "https://api.taxjar.com" } # Sandbox URL: https://api.sandbox.taxjar.com ) end diff --git a/lib/super_good/solidus_taxjar/api_params.rb b/lib/super_good/solidus_taxjar/api_params.rb index b3c02fe..ebce8fe 100644 --- a/lib/super_good/solidus_taxjar/api_params.rb +++ b/lib/super_good/solidus_taxjar/api_params.rb @@ -8,7 +8,7 @@ module SuperGood .merge(order_address_params(order.tax_address)) .merge(line_items_params(order.line_items)) .merge(shipping: shipping(order)) - .merge(SuperGood::SolidusTaxJar.custom_order_params.(order)) + .merge(SuperGood::SolidusTaxJar.custom_order_params.call(order)) .tap do |params| next unless SuperGood::SolidusTaxJar.logging_enabled @@ -33,7 +33,7 @@ module SuperGood def tax_rate_address_params(address) { amount: 100, - shipping: 0, + shipping: 0 }.merge(order_address_params(address)) end @@ -71,7 +71,7 @@ module SuperGood def customer_params(order) return {} unless order.user_id - { customer_id: order.user_id.to_s } + {customer_id: order.user_id.to_s} end def order_address_params(address) @@ -80,7 +80,7 @@ module SuperGood to_zip: address.zipcode, to_city: address.city, to_state: address&.state&.abbr || address.state_name, - to_street: address.address1, + to_street: address.address1 } end @@ -127,7 +127,7 @@ module SuperGood end def shipping(order) - SuperGood::SolidusTaxJar.shipping_calculator.(order) + SuperGood::SolidusTaxJar.shipping_calculator.call(order) end def sales_tax(order) diff --git a/lib/super_good/solidus_taxjar/calculator_helper.rb b/lib/super_good/solidus_taxjar/calculator_helper.rb index dbde950..f8690b5 100644 --- a/lib/super_good/solidus_taxjar/calculator_helper.rb +++ b/lib/super_good/solidus_taxjar/calculator_helper.rb @@ -22,7 +22,7 @@ module SuperGood end def taxable_address?(address) - SuperGood::SolidusTaxJar.taxable_address_check.(address) + SuperGood::SolidusTaxJar.taxable_address_check.call(address) end def cache diff --git a/lib/super_good/solidus_taxjar/tax_calculator.rb b/lib/super_good/solidus_taxjar/tax_calculator.rb index 7fac1bd..520fffe 100644 --- a/lib/super_good/solidus_taxjar/tax_calculator.rb +++ b/lib/super_good/solidus_taxjar/tax_calculator.rb @@ -23,8 +23,8 @@ module SuperGood shipment_taxes: shipment_taxes ) end - rescue StandardError => e - exception_handler.(e) + rescue => e + exception_handler.call(e) no_tax end @@ -34,7 +34,7 @@ module SuperGood def line_item_taxes @line_item_taxes ||= - taxjar_breakdown.line_items.map do |taxjar_line_item| + taxjar_breakdown.line_items.map { |taxjar_line_item| spree_line_item_id = taxjar_line_item.id.to_i # Searching in memory because this association is loaded and most @@ -48,13 +48,13 @@ module SuperGood amount: taxjar_line_item.tax_collectable, included_in_price: false ) - end + } end def shipment_taxes @shipment_taxes ||= if taxjar_breakdown.shipping? && - (total_shipping_tax = taxjar_breakdown.shipping.tax_collectable) != 0 + (total_shipping_tax = taxjar_breakdown.shipping.tax_collectable) != 0 # Distribute shipping tax across shipments: # TaxJar does not provide a breakdown of shipping taxes, so we have @@ -114,22 +114,22 @@ module SuperGood end def cache_key - SuperGood::SolidusTaxJar.cache_key.(order) + SuperGood::SolidusTaxJar.cache_key.call(order) end def taxable_order?(order) - SuperGood::SolidusTaxJar.taxable_order_check.(order) + SuperGood::SolidusTaxJar.taxable_order_check.call(order) end def shipping_tax_label(shipment, shipping_tax) - SuperGood::SolidusTaxJar.shipping_tax_label_maker.( + SuperGood::SolidusTaxJar.shipping_tax_label_maker.call( shipment, shipping_tax ) end def line_item_tax_label(taxjar_line_item, spree_line_item) - SuperGood::SolidusTaxJar.line_item_tax_label_maker.(taxjar_line_item, spree_line_item) + SuperGood::SolidusTaxJar.line_item_tax_label_maker.call(taxjar_line_item, spree_line_item) end end end diff --git a/lib/super_good/solidus_taxjar/tax_rate_calculator.rb b/lib/super_good/solidus_taxjar/tax_rate_calculator.rb index dc3d771..8f513a5 100644 --- a/lib/super_good/solidus_taxjar/tax_rate_calculator.rb +++ b/lib/super_good/solidus_taxjar/tax_rate_calculator.rb @@ -14,9 +14,8 @@ module SuperGood cache do api.tax_rate_for(address).to_d end - - rescue StandardError => e - exception_handler.(e) + rescue => e + exception_handler.call(e) no_rate end @@ -29,7 +28,7 @@ module SuperGood end def cache_key - SuperGood::SolidusTaxJar.cache_key.(address) + SuperGood::SolidusTaxJar.cache_key.call(address) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e55b5c5..ae3528d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,18 +1,18 @@ # frozen_string_literal: true # Configure Rails Environment -ENV['RAILS_ENV'] = 'test' +ENV["RAILS_ENV"] = "test" -require File.expand_path('dummy/config/environment.rb', __dir__).tap { |file| +require File.expand_path("dummy/config/environment.rb", __dir__).tap { |file| # Create the dummy app if it's still missing. - system 'bin/rake extension:test_app' unless File.exist? file + system "bin/rake extension:test_app" unless File.exist? file } -require 'solidus_dev_support/rspec/rails_helper' +require "solidus_dev_support/rspec/rails_helper" # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. -Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f } +Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each { |f| require f } RSpec.configure do |config| config.infer_spec_type_from_file_location! diff --git a/spec/super_good/solidus_taxjar/api_params_spec.rb b/spec/super_good/solidus_taxjar/api_params_spec.rb index 8e9536f..3f9d85c 100644 --- a/spec/super_good/solidus_taxjar/api_params_spec.rb +++ b/spec/super_good/solidus_taxjar/api_params_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" RSpec.describe SuperGood::SolidusTaxJar::APIParams do let(:order) do @@ -144,15 +144,15 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do context "when custom params are used" do around do |example| default = SuperGood::SolidusTaxJar.custom_order_params - SuperGood::SolidusTaxJar.custom_order_params = -> (order) { + SuperGood::SolidusTaxJar.custom_order_params = ->(order) { { nexus_addresses: [ { - id: 'Main Location', - country: 'AU', - zip: 'NSW 2000', - city: 'Sydney', - street: '483 George St', + id: "Main Location", + country: "AU", + zip: "NSW 2000", + city: "Sydney", + street: "483 George St" } ] } @@ -172,11 +172,11 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do unit_price: 10.00 }], nexus_addresses: [{ - id: 'Main Location', - country: 'AU', - zip: 'NSW 2000', - city: 'Sydney', - street: '483 George St', + id: "Main Location", + country: "AU", + zip: "NSW 2000", + city: "Sydney", + street: "483 George St" }], shipping: 3.01, to_city: "Los Angeles", @@ -324,7 +324,7 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do to_street: "475 N Beverly Dr", to_zip: "90210", transaction_date: "2018-03-06T12:10:33Z", - transaction_id: "R111222333", + transaction_id: "R111222333" }) end end diff --git a/spec/super_good/solidus_taxjar/api_spec.rb b/spec/super_good/solidus_taxjar/api_spec.rb index 8b0a5db..d3c51ea 100644 --- a/spec/super_good/solidus_taxjar/api_spec.rb +++ b/spec/super_good/solidus_taxjar/api_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" RSpec.describe SuperGood::SolidusTaxJar::API do describe "#tax_for" do @@ -12,15 +12,15 @@ RSpec.describe SuperGood::SolidusTaxJar::API do allow(SuperGood::SolidusTaxJar::APIParams) .to receive(:order_params) .with(order) - .and_return({ order: "params" }) + .and_return({order: "params"}) allow(dummy_client) .to receive(:tax_for_order) - .with({ order: "params" }) - .and_return({ some_kind_of: "response" }) + .with({order: "params"}) + .and_return({some_kind_of: "response"}) end - it { is_expected.to eq({ some_kind_of: "response" }) } + it { is_expected.to eq({some_kind_of: "response"}) } end describe "tax_rate_for" do @@ -36,11 +36,11 @@ RSpec.describe SuperGood::SolidusTaxJar::API do allow(SuperGood::SolidusTaxJar::APIParams) .to receive(:tax_rate_address_params) .with(address) - .and_return({ address: "params" }) + .and_return({address: "params"}) allow(dummy_client) .to receive(:tax_for_order) - .with({ address: "params" }) + .with({address: "params"}) .and_return(response) end @@ -58,15 +58,15 @@ RSpec.describe SuperGood::SolidusTaxJar::API do allow(SuperGood::SolidusTaxJar::APIParams) .to receive(:address_params) .with(address) - .and_return(["zipcode", { address: "params" }]) + .and_return(["zipcode", {address: "params"}]) allow(dummy_client) .to receive(:rates_for_location) - .with("zipcode", { address: "params" }) - .and_return({ some_kind_of: "response" }) + .with("zipcode", {address: "params"}) + .and_return({some_kind_of: "response"}) end - it { is_expected.to eq({ some_kind_of: "response" }) } + it { is_expected.to eq({some_kind_of: "response"}) } end describe "#create_transaction_for" do @@ -80,15 +80,15 @@ RSpec.describe SuperGood::SolidusTaxJar::API do allow(SuperGood::SolidusTaxJar::APIParams) .to receive(:transaction_params) .with(order) - .and_return({ transaction: "params" }) + .and_return({transaction: "params"}) allow(dummy_client) .to receive(:create_order) - .with({ transaction: "params" }) - .and_return({ some_kind_of: "response" }) + .with({transaction: "params"}) + .and_return({some_kind_of: "response"}) end - it { is_expected.to eq({ some_kind_of: "response" }) } + it { is_expected.to eq({some_kind_of: "response"}) } end describe "#update_transaction_for" do @@ -102,15 +102,15 @@ RSpec.describe SuperGood::SolidusTaxJar::API do allow(SuperGood::SolidusTaxJar::APIParams) .to receive(:transaction_params) .with(order) - .and_return({ transaction: "params" }) + .and_return({transaction: "params"}) allow(dummy_client) .to receive(:update_order) - .with({ transaction: "params" }) - .and_return({ some_kind_of: "response" }) + .with({transaction: "params"}) + .and_return({some_kind_of: "response"}) end - it { is_expected.to eq({ some_kind_of: "response" }) } + it { is_expected.to eq({some_kind_of: "response"}) } end describe "#update_transaction_for" do @@ -124,10 +124,10 @@ RSpec.describe SuperGood::SolidusTaxJar::API do allow(dummy_client) .to receive(:delete_order) .with("R111222333") - .and_return({ some_kind_of: "response" }) + .and_return({some_kind_of: "response"}) end - it { is_expected.to eq({ some_kind_of: "response" }) } + it { is_expected.to eq({some_kind_of: "response"}) } end describe "#create_refund_for" do @@ -141,14 +141,14 @@ RSpec.describe SuperGood::SolidusTaxJar::API do allow(SuperGood::SolidusTaxJar::APIParams) .to receive(:refund_params) .with(reimbursement) - .and_return({ refund: "params" }) + .and_return({refund: "params"}) allow(dummy_client) .to receive(:create_refund) - .with({ refund: "params" }) - .and_return({ some_kind_of: "response" }) + .with({refund: "params"}) + .and_return({some_kind_of: "response"}) end - it { is_expected.to eq({ some_kind_of: "response" }) } + it { is_expected.to eq({some_kind_of: "response"}) } end end diff --git a/spec/super_good/solidus_taxjar/discount_calculator_spec.rb b/spec/super_good/solidus_taxjar/discount_calculator_spec.rb index b89b4dc..65f3bc4 100644 --- a/spec/super_good/solidus_taxjar/discount_calculator_spec.rb +++ b/spec/super_good/solidus_taxjar/discount_calculator_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" RSpec.describe SuperGood::SolidusTaxJar::DiscountCalculator do describe "#discount" do diff --git a/spec/super_good/solidus_taxjar/tax_calculator_spec.rb b/spec/super_good/solidus_taxjar/tax_calculator_spec.rb index c9ecbcd..c88be44 100644 --- a/spec/super_good/solidus_taxjar/tax_calculator_spec.rb +++ b/spec/super_good/solidus_taxjar/tax_calculator_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" RSpec.describe ::SuperGood::SolidusTaxJar::TaxCalculator do describe "#calculate" do diff --git a/spec/super_good/solidus_taxjar/tax_rate_calculator_spec.rb b/spec/super_good/solidus_taxjar/tax_rate_calculator_spec.rb index 3af89e5..057d58d 100644 --- a/spec/super_good/solidus_taxjar/tax_rate_calculator_spec.rb +++ b/spec/super_good/solidus_taxjar/tax_rate_calculator_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" RSpec.describe ::SuperGood::SolidusTaxJar::TaxRateCalculator do describe "#calculate" do @@ -44,7 +44,7 @@ RSpec.describe ::SuperGood::SolidusTaxJar::TaxRateCalculator do context "when we're not rescuing from errors" do around do |example| handler = SuperGood::SolidusTaxJar.exception_handler - SuperGood::SolidusTaxJar.exception_handler = -> (error) { raise error } + SuperGood::SolidusTaxJar.exception_handler = ->(error) { raise error } example.run SuperGood::SolidusTaxJar.exception_handler = handler end diff --git a/spec/super_good/solidus_taxjar_spec.rb b/spec/super_good/solidus_taxjar_spec.rb index 2b04e7b..30a2d01 100644 --- a/spec/super_good/solidus_taxjar_spec.rb +++ b/spec/super_good/solidus_taxjar_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" RSpec.describe SuperGood::SolidusTaxJar do it "has a version number" do @@ -7,7 +7,7 @@ RSpec.describe SuperGood::SolidusTaxJar do describe "configuration" do describe ".cache_key" do - subject { described_class.cache_key.(order) } + subject { described_class.cache_key.call(order) } let(:order) { Spree::Order.new } @@ -15,7 +15,7 @@ RSpec.describe SuperGood::SolidusTaxJar do allow(SuperGood::SolidusTaxJar::APIParams) .to receive(:order_params) .with(order) - .and_return({ some: "hash", with: "stuff", in: "it" }) + .and_return({some: "hash", with: "stuff", in: "it"}) expect(subject).to eq '{"some":"hash","with":"stuff","in":"it"}' end @@ -32,7 +32,7 @@ RSpec.describe SuperGood::SolidusTaxJar do end describe ".exception_handler" do - subject { described_class.exception_handler.(exception) } + subject { described_class.exception_handler.call(exception) } let(:exception) { StandardError.new("Something happened") } @@ -45,7 +45,7 @@ RSpec.describe SuperGood::SolidusTaxJar do end describe ".taxable_address_check" do - subject { described_class.taxable_address_check.(address) } + subject { described_class.taxable_address_check.call(address) } let(:address) { Spree::Address.new } @@ -53,7 +53,7 @@ RSpec.describe SuperGood::SolidusTaxJar do end describe ".taxable_order_check" do - subject { described_class.taxable_order_check.(order) } + subject { described_class.taxable_order_check.call(order) } let(:order) { Spree::Order.new } @@ -61,14 +61,14 @@ RSpec.describe SuperGood::SolidusTaxJar do end describe ".shipping_tax_label_maker" do - subject { described_class.shipping_tax_label_maker.(shipment, shipping_tax) } + subject { described_class.shipping_tax_label_maker.call(shipment, shipping_tax) } let(:shipment) { Spree::Shipment.new } let(:shipping_tax) { BigDecimal("3.25") } it { is_expected.to eq "Sales Tax" } end describe ".line_item_tax_label_maker" do - subject { described_class.line_item_tax_label_maker.(taxjar_line_item, spree_line_item) } + subject { described_class.line_item_tax_label_maker.call(taxjar_line_item, spree_line_item) } let(:taxjar_line_item) { instance_double Taxjar::BreakdownLineItem } let(:spree_line_item) { Spree::LineItem.new } it { is_expected.to eq "Sales Tax" } |