mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-04 02:31:33 +00:00
Compare commits
5 Commits
v4.2.22
...
add-abilit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c60a3a660 | ||
|
|
ac7a7b11a5 | ||
|
|
0fb273ce93 | ||
|
|
709dfa42bc | ||
|
|
9561140466 |
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -130,4 +130,4 @@ jobs:
|
||||
run: yarn jest
|
||||
|
||||
- name: Run all other tests
|
||||
run: bundle exec rspec --exclude-pattern "./models/**/*_spec.rb, ./controllers/**/*_spec.rb, ./serializers/**/*_spec.rb, ./lib/**/*_spec.rb, ./migrations/**/*_spec.rb, ./system/**/*_spec.rb"
|
||||
run: bundle exec rake ofn:specs:run:excluding_folders["models,controllers,serializers,features,lib,migrations,system"]
|
||||
|
||||
@@ -83,7 +83,7 @@ Then the main application tests can be run with:
|
||||
|
||||
The tests of all custom engines can be run with:
|
||||
|
||||
bundle exec rspec ./engines
|
||||
bundle exec rake ofn:specs:engines:rspec
|
||||
|
||||
Note: If your OS is not explicitly supported in the setup guides then not all tests may pass. However, you may still be able to develop.
|
||||
|
||||
|
||||
24
Gemfile.lock
24
Gemfile.lock
@@ -210,6 +210,7 @@ GEM
|
||||
rubyzip (>= 1.3.0, < 3)
|
||||
choice (0.2.0)
|
||||
chronic (0.10.2)
|
||||
cliver (0.3.2)
|
||||
coderay (1.1.3)
|
||||
coffee-rails (5.0.0)
|
||||
coffee-script (>= 2.2.0)
|
||||
@@ -228,9 +229,9 @@ GEM
|
||||
crass (1.0.6)
|
||||
css_parser (1.11.0)
|
||||
addressable
|
||||
cuprite (0.14.3)
|
||||
capybara (~> 3.0)
|
||||
ferrum (~> 0.13.0)
|
||||
cuprite (0.13)
|
||||
capybara (>= 2.1, < 4)
|
||||
ferrum (~> 0.11.0)
|
||||
database_cleaner (2.0.1)
|
||||
database_cleaner-active_record (~> 2.0.0)
|
||||
database_cleaner-active_record (2.0.0)
|
||||
@@ -280,10 +281,10 @@ GEM
|
||||
faraday-follow_redirects (0.3.0)
|
||||
faraday (>= 1, < 3)
|
||||
faraday-net_http (3.0.1)
|
||||
ferrum (0.13)
|
||||
ferrum (0.11)
|
||||
addressable (~> 2.5)
|
||||
cliver (~> 0.3)
|
||||
concurrent-ruby (~> 1.1)
|
||||
webrick (~> 1.7)
|
||||
websocket-driver (>= 0.6, < 0.8)
|
||||
ffaker (2.21.0)
|
||||
ffi (1.15.5)
|
||||
@@ -451,7 +452,7 @@ GEM
|
||||
activerecord (>= 5.2)
|
||||
request_store (~> 1.1)
|
||||
parallel (1.22.1)
|
||||
paranoia (2.6.1)
|
||||
paranoia (2.6.0)
|
||||
activerecord (>= 5.1, < 7.1)
|
||||
parser (3.1.2.1)
|
||||
ast (~> 2.4.1)
|
||||
@@ -524,7 +525,7 @@ GEM
|
||||
ruby-graphviz (~> 1.2)
|
||||
rails-html-sanitizer (1.4.3)
|
||||
loofah (~> 2.3)
|
||||
rails-i18n (7.0.6)
|
||||
rails-i18n (7.0.5)
|
||||
i18n (>= 0.7, < 2)
|
||||
railties (>= 6.0.0, < 8)
|
||||
rails_safe_tasks (1.0.0)
|
||||
@@ -591,7 +592,7 @@ GEM
|
||||
rspec-support (3.10.3)
|
||||
rswag-api (2.7.0)
|
||||
railties (>= 3.1, < 7.1)
|
||||
rswag-specs (2.8.0)
|
||||
rswag-specs (2.7.0)
|
||||
activesupport (>= 3.1, < 7.1)
|
||||
json-schema (>= 2.2, < 4.0)
|
||||
railties (>= 3.1, < 7.1)
|
||||
@@ -599,7 +600,7 @@ GEM
|
||||
rswag-ui (2.7.0)
|
||||
actionpack (>= 3.1, < 7.1)
|
||||
railties (>= 3.1, < 7.1)
|
||||
rubocop (1.39.0)
|
||||
rubocop (1.38.0)
|
||||
json (~> 2.3)
|
||||
parallel (~> 1.10)
|
||||
parser (>= 3.1.2.1)
|
||||
@@ -711,7 +712,7 @@ GEM
|
||||
activemodel (>= 3.0.0)
|
||||
public_suffix
|
||||
vcr (6.1.0)
|
||||
view_component (2.76.0)
|
||||
view_component (2.75.0)
|
||||
activesupport (>= 5.0.0, < 8.0)
|
||||
concurrent-ruby (~> 1.0)
|
||||
method_source (~> 1.0)
|
||||
@@ -736,7 +737,6 @@ GEM
|
||||
rack-proxy (>= 0.6.1)
|
||||
railties (>= 5.2)
|
||||
semantic_range (>= 2.3.0)
|
||||
webrick (1.7.0)
|
||||
websocket-driver (0.7.5)
|
||||
websocket-extensions (>= 0.1.0)
|
||||
websocket-extensions (0.1.5)
|
||||
@@ -748,7 +748,7 @@ GEM
|
||||
xml-simple (1.1.8)
|
||||
xpath (3.2.0)
|
||||
nokogiri (~> 1.8)
|
||||
zeitwerk (2.6.6)
|
||||
zeitwerk (2.6.4)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "open_food_network/feature_toggle"
|
||||
|
||||
class FeatureToggleConstraint
|
||||
def initialize(feature_name)
|
||||
@feature = feature_name
|
||||
@@ -12,6 +10,6 @@ class FeatureToggleConstraint
|
||||
end
|
||||
|
||||
def current_user(request)
|
||||
request.env['warden']&.user
|
||||
request.env['warden'].user
|
||||
end
|
||||
end
|
||||
|
||||
@@ -48,15 +48,7 @@ module Admin
|
||||
else
|
||||
I18n.t(:name, scope: [:admin, :reports, @report_type])
|
||||
end
|
||||
|
||||
# Initialize data
|
||||
params[:display_summary_row] = true if request.get?
|
||||
@params_fields_to_show = if request.get?
|
||||
@report.columns.keys - @report.fields_to_hide
|
||||
else
|
||||
params[:fields_to_show]
|
||||
end
|
||||
|
||||
@rendering_options = rendering_options
|
||||
@data = Reporting::FrontendData.new(spree_current_user)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -62,4 +62,27 @@ module ReportsActions
|
||||
def i18n_scope
|
||||
'admin.reports'
|
||||
end
|
||||
|
||||
def rendering_options
|
||||
@rendering_options ||= ReportRenderingOptions.where(
|
||||
user: spree_current_user,
|
||||
report_type: report_type,
|
||||
report_subtype: report_subtype
|
||||
).first_or_create do |new_instance|
|
||||
new_instance.options[:fields_to_show] = if @report.present?
|
||||
@report.columns.keys - @report.fields_to_hide
|
||||
else
|
||||
[]
|
||||
end
|
||||
new_instance.options[:display_summary_row] = request.get? || params[:display_summary_row].present?
|
||||
params[:display_header_row] = params[:display_header_row].present?
|
||||
end
|
||||
if params[:fields_to_show].present?
|
||||
@rendering_options.options[:fields_to_show] = params[:fields_to_show]
|
||||
end
|
||||
@rendering_options.options[:display_summary_row] = params[:display_summary_row].present?
|
||||
@rendering_options.options[:display_header_row] = params[:display_header_row].present?
|
||||
@rendering_options.save
|
||||
@rendering_options
|
||||
end
|
||||
end
|
||||
|
||||
4
app/models/report_rendering_options.rb
Normal file
4
app/models/report_rendering_options.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class ReportRenderingOptions < ApplicationRecord
|
||||
belongs_to :user, class_name: "Spree::User"
|
||||
serialize :options, Hash
|
||||
end
|
||||
@@ -32,8 +32,6 @@
|
||||
.four.columns.omega
|
||||
= f.radio_button :sells, "any", 'ng-model' => 'Enterprise.sells', data: {action: "change->primary-details#enterpriseSellsChanged"}
|
||||
= f.label :sells, t('.any'), value: "any"
|
||||
%span{ style: "width: 30px; height: 30px;", class: "hidden", data: { "primary-details-target": "spinner" } }
|
||||
= render partial: "components/admin_spinner"
|
||||
.row
|
||||
.three.columns.alpha
|
||||
%label= t('.visible_in_search')
|
||||
|
||||
@@ -16,16 +16,16 @@
|
||||
.omega.fourteen.columns
|
||||
- if @report.header_option?
|
||||
%span.inline-checkbox{ style: "margin-right: 1rem;" }
|
||||
= check_box_tag :display_header_row, true, params[:display_header_row]
|
||||
= check_box_tag :display_header_row, true, @render_options.options[:display_header_row]
|
||||
= label_tag :display_header_row, t(".header_row")
|
||||
- if @report.summary_row_option?
|
||||
%span.inline-checkbox
|
||||
= check_box_tag :display_summary_row, true, params[:display_summary_row], { "data-csv-select-target": "checkbox" }
|
||||
= check_box_tag :display_summary_row, true, @render_options.options[:display_summary_row], { "data-csv-select-target": "checkbox" }
|
||||
= label_tag :display_summary_row, t(".summary_row"), { "data-csv-select-target": "label" }
|
||||
|
||||
- if @report.available_headers.present?
|
||||
.row
|
||||
.alpha.two.columns= label_tag nil, t(:report_columns)
|
||||
.omega.fourteen.columns
|
||||
= render MultipleCheckedSelectComponent.new(name: "fields_to_show", options: @report.available_headers, selected: @params_fields_to_show)
|
||||
= render MultipleCheckedSelectComponent.new(name: "fields_to_show", options: @report.available_headers, selected: @render_options.options[:fields_to_show])
|
||||
|
||||
@@ -3,7 +3,6 @@ import CableReady from "cable_ready";
|
||||
|
||||
export default class extends Controller {
|
||||
static values = { primaryProducer: String, enterpriseSells: String };
|
||||
static targets = ["spinner"];
|
||||
|
||||
primaryProducerChanged(event) {
|
||||
this.primaryProducerValue = event.currentTarget.checked;
|
||||
@@ -13,7 +12,6 @@ export default class extends Controller {
|
||||
enterpriseSellsChanged(event) {
|
||||
if (event.currentTarget.checked) {
|
||||
this.enterpriseSellsValue = event.currentTarget.value;
|
||||
this.spinnerTarget.classList.remove("hidden");
|
||||
this.makeRequest();
|
||||
}
|
||||
}
|
||||
@@ -27,9 +25,6 @@ export default class extends Controller {
|
||||
}
|
||||
)
|
||||
.then((data) => data.json())
|
||||
.then((operation) => {
|
||||
CableReady.perform(operation);
|
||||
this.spinnerTarget.classList.add("hidden");
|
||||
});
|
||||
.then(CableReady.perform);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4110,7 +4110,7 @@ fr:
|
||||
thanks: "Merci pour votre commande."
|
||||
track_information: "Informations de suivi : %{tracking}"
|
||||
track_link: "Lien de suivi : %{url}"
|
||||
picked_up_instructions: "Votre commande auprès de %{distributor} vous a bien été délivrée :)"
|
||||
picked_up_instructions: "Votre commande de %{distributor} a bien été réceptionnée"
|
||||
picked_up_subject: "Notification de réception"
|
||||
test_mailer:
|
||||
test_email:
|
||||
|
||||
@@ -117,7 +117,7 @@ Openfoodnetwork::Application.routes.draw do
|
||||
|
||||
get 'sitemap.xml', to: 'sitemap#index', defaults: { format: 'xml' }
|
||||
|
||||
constraints FeatureToggleConstraint.new(:dfc_provider) do
|
||||
unless Rails.env.production?
|
||||
# Mount DFC API endpoints
|
||||
mount DfcProvider::Engine, at: '/'
|
||||
end
|
||||
|
||||
12
db/migrate/20221116095826_create_report_rendering_options.rb
Normal file
12
db/migrate/20221116095826_create_report_rendering_options.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class CreateReportRenderingOptions < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :report_rendering_options do |t|
|
||||
t.references :user
|
||||
t.text :options
|
||||
t.string :report_type
|
||||
t.string :report_subtype
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
12
db/schema.rb
12
db/schema.rb
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2022_10_07_105052) do
|
||||
ActiveRecord::Schema.define(version: 2022_11_16_095826) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_stat_statements"
|
||||
@@ -354,6 +354,16 @@ ActiveRecord::Schema.define(version: 2022_10_07_105052) do
|
||||
t.index ["subscription_id"], name: "index_proxy_orders_on_subscription_id"
|
||||
end
|
||||
|
||||
create_table "report_rendering_options", force: :cascade do |t|
|
||||
t.bigint "user_id"
|
||||
t.text "options"
|
||||
t.string "report_type"
|
||||
t.string "report_subtype"
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.index ["user_id"], name: "index_report_rendering_options_on_user_id"
|
||||
end
|
||||
|
||||
create_table "schedules", id: :serial, force: :cascade do |t|
|
||||
t.string "name", limit: 255, null: false
|
||||
t.datetime "created_at", null: false
|
||||
|
||||
78
lib/tasks/specs.rake
Normal file
78
lib/tasks/specs.rake
Normal file
@@ -0,0 +1,78 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
namespace :ofn do
|
||||
namespace :specs do
|
||||
namespace :run do
|
||||
def spec_folders
|
||||
Pathname("spec/").children.select(&:directory?).map { |p|
|
||||
p.split.last.to_s
|
||||
} - %w(support factories javascripts performance)
|
||||
end
|
||||
|
||||
def execute_rspec_for_pattern(pattern)
|
||||
system "bundle exec rspec --profile --pattern \"#{pattern}\""
|
||||
end
|
||||
|
||||
def execute_rspec_for_spec_folder(folder)
|
||||
execute_rspec_for_pattern("spec/#{folder}/{,/*/**}/*_spec.rb")
|
||||
end
|
||||
|
||||
def execute_rspec_for_spec_folders(folders)
|
||||
folders = folders.join(",")
|
||||
execute_rspec_for_pattern("spec/{#{folders}}/{,/*/**}/*_spec.rb")
|
||||
end
|
||||
|
||||
desc "Run Rspec tests excluding folders"
|
||||
task :excluding_folders, [:folders] => :environment do |_task, args|
|
||||
success = execute_rspec_for_spec_folders(
|
||||
spec_folders - (args[:folders].split(",") + args.extras)
|
||||
)
|
||||
abort "Failure when running tests" unless success
|
||||
end
|
||||
end
|
||||
|
||||
namespace :engines do
|
||||
def detect_engine_paths
|
||||
Pathname("engines/").children.select(&:directory?)
|
||||
end
|
||||
|
||||
def engine_name_for_engine(engine_path)
|
||||
engine_path.basename.to_path
|
||||
end
|
||||
|
||||
def execute_rspec_for_engine(engine_path)
|
||||
system "DISABLE_KNAPSACK=true bundle exec rspec #{engine_path.expand_path}/spec"
|
||||
end
|
||||
|
||||
engine_paths = detect_engine_paths
|
||||
|
||||
engine_paths.each do |engine_path|
|
||||
engine_name = engine_name_for_engine(engine_path)
|
||||
|
||||
namespace engine_name do
|
||||
desc "Run RSpec tests for engine \"#{engine_name}\""
|
||||
task rspec: :environment do
|
||||
success = execute_rspec_for_engine(engine_path)
|
||||
abort "Failure when running tests for engine \"#{engine_name}\"" unless success
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
namespace :all do
|
||||
desc "Run RSpec tests for all engines"
|
||||
task rspec: :environment do
|
||||
success = true
|
||||
|
||||
engine_paths.each do |engine_path|
|
||||
success = !!execute_rspec_for_engine(engine_path) && success
|
||||
end
|
||||
|
||||
abort "Failure encountered when running tests for engines" unless success
|
||||
end
|
||||
end
|
||||
|
||||
desc "Alias for openfoodnetwork:specs:engines:all:rspec"
|
||||
task rspec: "all:rspec"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -129,6 +129,7 @@ RSpec.configure do |config|
|
||||
config.include Spree::UrlHelpers
|
||||
config.include Spree::MoneyHelper
|
||||
config.include PreferencesHelper
|
||||
config.include OpenFoodNetwork::FeatureToggleHelper
|
||||
config.include OpenFoodNetwork::FiltersHelper
|
||||
config.include OpenFoodNetwork::EnterpriseGroupsHelper
|
||||
config.include OpenFoodNetwork::ProductsHelper
|
||||
|
||||
@@ -88,7 +88,10 @@ module PaymentGateways
|
||||
|
||||
context "using split checkout" do
|
||||
before do
|
||||
Flipper.enable(:split_checkout)
|
||||
allow(OpenFoodNetwork::FeatureToggle).
|
||||
to receive(:enabled?).with(:split_checkout) { true }
|
||||
allow(OpenFoodNetwork::FeatureToggle).
|
||||
to receive(:enabled?).with(:split_checkout, anything) { true }
|
||||
|
||||
order.update_attribute :state, "confirmation"
|
||||
end
|
||||
|
||||
@@ -16,7 +16,10 @@ describe SplitCheckoutController, type: :controller do
|
||||
let(:shipping_method) { distributor.shipping_methods.first }
|
||||
|
||||
before do
|
||||
Flipper.enable(:split_checkout)
|
||||
allow(OpenFoodNetwork::FeatureToggle).
|
||||
to receive(:enabled?).with(:split_checkout) { true }
|
||||
allow(OpenFoodNetwork::FeatureToggle).
|
||||
to receive(:enabled?).with(:split_checkout, anything) { true }
|
||||
|
||||
exchange.variants << order.line_items.first.variant
|
||||
allow(controller).to receive(:current_order) { order }
|
||||
|
||||
5
spec/models/report_rendering_options_spec.rb
Normal file
5
spec/models/report_rendering_options_spec.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ReportRenderingOptions, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
32
spec/performance/injection_helper_spec.rb
Normal file
32
spec/performance/injection_helper_spec.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe InjectionHelper, type: :helper, performance: true do
|
||||
let(:oc) { create(:simple_order_cycle) }
|
||||
let(:relative_supplier) { create(:supplier_enterprise) }
|
||||
let(:relative_distributor) { create(:distributor_enterprise) }
|
||||
|
||||
before do
|
||||
50.times do
|
||||
e = create(:enterprise)
|
||||
oc.distributors << e
|
||||
create(:enterprise_relationship, parent: e, child: relative_supplier)
|
||||
create(:enterprise_relationship, parent: e, child: relative_distributor)
|
||||
end
|
||||
end
|
||||
|
||||
it "is performant in injecting enterprises" do
|
||||
results = []
|
||||
4.times do |i|
|
||||
ActiveRecord::Base.connection.query_cache.clear
|
||||
Rails.cache.delete_matched('api\/cached_enterprise_serializer\/enterprises')
|
||||
result = Benchmark.measure { helper.inject_enterprises }
|
||||
results << result.total if i.positive?
|
||||
puts result
|
||||
end
|
||||
|
||||
avg = (results.sum / results.count * 1000).round(0)
|
||||
puts avg
|
||||
end
|
||||
end
|
||||
39
spec/performance/orders_controller_spec.rb
Normal file
39
spec/performance/orders_controller_spec.rb
Normal file
@@ -0,0 +1,39 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::OrdersController, type: :controller, performance: true do
|
||||
let(:distributor) { create(:distributor_enterprise) }
|
||||
let(:order_cycle) {
|
||||
create(:simple_order_cycle, distributors: [distributor], variants: products.map { |p|
|
||||
p.variants.first
|
||||
} )
|
||||
}
|
||||
let(:products) { (0...num_products).map { create(:product) } }
|
||||
let(:order) { subject.current_order(true) }
|
||||
let(:num_products) { 20 }
|
||||
|
||||
before do
|
||||
order.set_distribution! distributor, order_cycle
|
||||
controller.stub(:current_order) { order }
|
||||
|
||||
Spree::Config.currency = 'AUD'
|
||||
end
|
||||
|
||||
describe "adding products to cart" do
|
||||
it "adds products to cart" do
|
||||
puts "Pre-populating first product"
|
||||
spree_post :populate, variants: { products[0].variants.first.id => 1 }
|
||||
|
||||
result = Benchmark.measure do
|
||||
(1..num_products).each do |num_products|
|
||||
puts "Populating #{num_products} products"
|
||||
variants = Hash[products.map { |p| [p.variants.first.id, 1] }.first(num_products)]
|
||||
spree_post :populate, variants: variants
|
||||
end
|
||||
end
|
||||
|
||||
puts result
|
||||
end
|
||||
end
|
||||
end
|
||||
50
spec/performance/shop_controller_spec.rb
Normal file
50
spec/performance/shop_controller_spec.rb
Normal file
@@ -0,0 +1,50 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe ShopController, type: :controller, performance: true do
|
||||
include FileHelper
|
||||
|
||||
let(:d) { create(:distributor_enterprise) }
|
||||
let(:enterprise_fee) { create(:enterprise_fee) }
|
||||
let(:order_cycle) {
|
||||
create(:simple_order_cycle, distributors: [d], coordinator_fees: [enterprise_fee])
|
||||
}
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:current_distributor) { d }
|
||||
allow(controller).to receive(:current_order_cycle) { order_cycle }
|
||||
Spree::Config.currency = 'AUD'
|
||||
end
|
||||
|
||||
describe "fetching products" do
|
||||
let(:exchange) { order_cycle.exchanges.to_enterprises(d).outgoing.first }
|
||||
let(:image) { white_logo_file }
|
||||
let(:cache_key_patterns) do
|
||||
[
|
||||
'api\/taxon_serializer\/spree\/taxons',
|
||||
'enterprise'
|
||||
]
|
||||
end
|
||||
|
||||
before do
|
||||
11.times do
|
||||
p = create(:simple_product)
|
||||
p.set_property 'Organic Certified', 'NASAA 12345'
|
||||
v1 = create(:variant, product: p)
|
||||
v2 = create(:variant, product: p)
|
||||
Spree::Image.create! viewable_id: p.master.id, viewable_type: 'Spree::Variant',
|
||||
attachment: image
|
||||
|
||||
exchange.variants << [v1, v2]
|
||||
end
|
||||
end
|
||||
|
||||
it "returns products via json" do
|
||||
results = multi_benchmark(3, cache_key_patterns: cache_key_patterns) do
|
||||
get :products, xhr: true
|
||||
expect(response.status).to eq 200
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -3,6 +3,10 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe "routing for Stripe return URLS", type: :routing do
|
||||
before do
|
||||
allow_any_instance_of(FeatureToggleConstraint).to receive(:current_user) { build(:user) }
|
||||
end
|
||||
|
||||
context "checkout return URLs" do
|
||||
it "routes /checkout to checkout#edit" do
|
||||
expect(get: "checkout").
|
||||
|
||||
11
spec/support/feature_toggle_helper.rb
Normal file
11
spec/support/feature_toggle_helper.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module OpenFoodNetwork
|
||||
module FeatureToggleHelper
|
||||
def set_feature_toggle(feature, status)
|
||||
features = OpenFoodNetwork::FeatureToggle.features
|
||||
features[feature] = status
|
||||
allow(OpenFoodNetwork::FeatureToggle).to receive(:features) { features }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -28,18 +28,9 @@ module StripeHelper
|
||||
fill_in "cvc", with: "678"
|
||||
end
|
||||
|
||||
def stripe_enable
|
||||
def setup_stripe
|
||||
Stripe.api_key = "sk_test_12345"
|
||||
Stripe.publishable_key = "pk_test_12345"
|
||||
allow(Spree::Config).to receive(:stripe_connect_enabled).and_return(true)
|
||||
end
|
||||
|
||||
def with_stripe_setup(api_key = "sk_test_12345", publishable_key = "pk_test_12345")
|
||||
original_keys = [Stripe.api_key, Stripe.publishable_key]
|
||||
|
||||
Stripe.api_key = api_key
|
||||
Stripe.publishable_key = publishable_key
|
||||
|
||||
yield
|
||||
|
||||
Stripe.api_key, Stripe.publishable_key = original_keys
|
||||
end
|
||||
end
|
||||
|
||||
@@ -154,7 +154,7 @@ module WebHelper
|
||||
|
||||
def fill_in_tag(tag_name, selector = "tags-input .tags input")
|
||||
expect(page).to have_selector selector
|
||||
find(:css, selector).click
|
||||
find(:css, selector).send_keys ""
|
||||
find(:css, selector).set "#{tag_name}\n"
|
||||
expect(page).to have_selector ".tag-list .tag-item span", text: tag_name
|
||||
end
|
||||
|
||||
@@ -43,13 +43,12 @@ describe "Taxonomies" do
|
||||
end
|
||||
|
||||
context "edit" do
|
||||
it "should allow an admin to update an existing taxonomy", retry: 3 do
|
||||
it "should allow an admin to update an existing taxonomy" do
|
||||
create(:taxonomy)
|
||||
click_link "Taxonomies"
|
||||
within_row(1) { find(".icon-edit").click }
|
||||
fill_in "taxonomy_name", with: "sports 99"
|
||||
click_button "Update"
|
||||
expect(page).to have_current_path spree.admin_taxonomies_path
|
||||
expect(page).to have_content("successfully updated!")
|
||||
expect(page).to have_content("sports 99")
|
||||
end
|
||||
|
||||
@@ -18,11 +18,9 @@ describe '
|
||||
create(:stripe_account, enterprise: order.distributor, stripe_user_id: "abc123")
|
||||
end
|
||||
|
||||
around do |example|
|
||||
with_stripe_setup { example.run }
|
||||
end
|
||||
before { setup_stripe }
|
||||
|
||||
context "making a new Stripe payment" do
|
||||
context "making a new Stripe payment", js: true do
|
||||
before do
|
||||
stub_payment_methods_post_request
|
||||
stub_payment_intent_get_request
|
||||
|
||||
@@ -83,7 +83,8 @@ describe "As a consumer I want to check out my cart", js: true do
|
||||
|
||||
context "split checkout" do
|
||||
before do
|
||||
Flipper.enable(:split_checkout)
|
||||
allow(OpenFoodNetwork::FeatureToggle).to receive(:enabled?).with(:split_checkout) { true }
|
||||
allow(OpenFoodNetwork::FeatureToggle).to receive(:enabled?).with(:split_checkout, anything) { true }
|
||||
end
|
||||
include_examples "with different checkout types", "split_checkout"
|
||||
end
|
||||
|
||||
@@ -30,12 +30,8 @@ describe "Check out with Stripe", js: true do
|
||||
calculator: Calculator::FlatRate.new(preferred_amount: 5.67))
|
||||
}
|
||||
|
||||
around do |example|
|
||||
with_stripe_setup { example.run }
|
||||
end
|
||||
|
||||
before do
|
||||
stripe_enable
|
||||
setup_stripe
|
||||
set_order order
|
||||
add_product_to_cart order, product
|
||||
distributor.shipping_methods << [shipping_with_fee, free_shipping]
|
||||
|
||||
@@ -65,7 +65,8 @@ describe "As a consumer, I want to checkout my order", js: true do
|
||||
}
|
||||
|
||||
before do
|
||||
Flipper.enable(:split_checkout)
|
||||
allow(OpenFoodNetwork::FeatureToggle).to receive(:enabled?).with(:split_checkout).and_return(true)
|
||||
allow(OpenFoodNetwork::FeatureToggle).to receive(:enabled?).with(:split_checkout, anything).and_return(true)
|
||||
|
||||
add_enterprise_fee enterprise_fee
|
||||
set_order order
|
||||
@@ -643,12 +644,8 @@ describe "As a consumer, I want to checkout my order", js: true do
|
||||
end
|
||||
|
||||
context "for Stripe SCA", if: pay_method.eql?("Stripe SCA") do
|
||||
around do |example|
|
||||
with_stripe_setup { example.run }
|
||||
end
|
||||
|
||||
before do
|
||||
stripe_enable
|
||||
setup_stripe
|
||||
visit checkout_step_path(:payment)
|
||||
end
|
||||
|
||||
|
||||
@@ -111,7 +111,10 @@ describe "As a consumer, I want to see adjustment breakdown" do
|
||||
|
||||
context "on split-checkout" do
|
||||
before do
|
||||
Flipper.enable(:split_checkout)
|
||||
allow(OpenFoodNetwork::FeatureToggle).
|
||||
to receive(:enabled?).with(:split_checkout).and_return(true)
|
||||
allow(OpenFoodNetwork::FeatureToggle).
|
||||
to receive(:enabled?).with(:split_checkout, anything).and_return(true)
|
||||
|
||||
set_order order_within_zone
|
||||
login_as(user_within_zone)
|
||||
@@ -168,7 +171,10 @@ describe "As a consumer, I want to see adjustment breakdown" do
|
||||
|
||||
context "on split-checkout" do
|
||||
before do
|
||||
Flipper.enable(:split_checkout)
|
||||
allow(OpenFoodNetwork::FeatureToggle).
|
||||
to receive(:enabled?).with(:split_checkout).and_return(true)
|
||||
allow(OpenFoodNetwork::FeatureToggle).
|
||||
to receive(:enabled?).with(:split_checkout, anything).and_return(true)
|
||||
|
||||
set_order order_outside_zone
|
||||
login_as(user_outside_zone)
|
||||
|
||||
@@ -118,7 +118,10 @@ describe "As a consumer, I want to see adjustment breakdown" do
|
||||
|
||||
context "on split-checkout" do
|
||||
before do
|
||||
Flipper.enable(:split_checkout)
|
||||
allow(OpenFoodNetwork::FeatureToggle).
|
||||
to receive(:enabled?).with(:split_checkout).and_return(true)
|
||||
allow(OpenFoodNetwork::FeatureToggle).
|
||||
to receive(:enabled?).with(:split_checkout, anything).and_return(true)
|
||||
|
||||
set_order order_within_zone
|
||||
login_as(user_within_zone)
|
||||
@@ -178,7 +181,10 @@ describe "As a consumer, I want to see adjustment breakdown" do
|
||||
|
||||
context "on split-checkout" do
|
||||
before do
|
||||
Flipper.enable(:split_checkout)
|
||||
allow(OpenFoodNetwork::FeatureToggle).
|
||||
to receive(:enabled?).with(:split_checkout).and_return(true)
|
||||
allow(OpenFoodNetwork::FeatureToggle).
|
||||
to receive(:enabled?).with(:split_checkout, anything).and_return(true)
|
||||
|
||||
set_order order_outside_zone
|
||||
login_as(user_outside_zone)
|
||||
|
||||
22
yarn.lock
22
yarn.lock
@@ -1673,17 +1673,17 @@
|
||||
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.3.tgz#90420f9f9c6d3987f176a19a7d8e764271a2f55d"
|
||||
integrity sha512-Fxt+AfXgjMoin2maPIYzFZnQjAXjAL0PHscM5pRTtatFqB+vZxAM9tLp2Optnuw3QOQC40jTNeGYFOMvyf7v9g==
|
||||
|
||||
"@floating-ui/core@^1.0.2":
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/@floating-ui/core/-/core-1.0.2.tgz#d06a66d3ad8214186eda2432ac8b8d81868a571f"
|
||||
integrity sha512-Skfy0YS3NJ5nV9us0uuPN0HDk1Q4edljaOhRBJGDWs9EBa7ZVMYBHRFlhLvvmwEoaIM9BlH6QJFn9/uZg0bACg==
|
||||
"@floating-ui/core@^1.0.1":
|
||||
version "1.0.1"
|
||||
resolved "https://registry.npmjs.org/@floating-ui/core/-/core-1.0.1.tgz#00e64d74e911602c8533957af0cce5af6b2e93c8"
|
||||
integrity sha512-bO37brCPfteXQfFY0DyNDGB3+IMe4j150KFQcgJ5aBP295p9nBGeHEs/p0czrRbtlHq4Px/yoPXO/+dOCcF4uA==
|
||||
|
||||
"@floating-ui/dom@^1.0.1":
|
||||
version "1.0.6"
|
||||
resolved "https://registry.yarnpkg.com/@floating-ui/dom/-/dom-1.0.6.tgz#e42393ec381a4fe96673fbcee137a95e86c93ebc"
|
||||
integrity sha512-kt/tg1oip9OAH1xjCTcx1OpcUpu9rjDw3GKJ/rEhUqhO7QyJWfrHU0DpLTNsH67+JyFL5Kv9X1utsXwKFVtyEQ==
|
||||
version "1.0.4"
|
||||
resolved "https://registry.yarnpkg.com/@floating-ui/dom/-/dom-1.0.4.tgz#cc0f2a03db7193b1b932b90d09c5c81235682a60"
|
||||
integrity sha512-maYJRv+sAXTy4K9mzdv0JPyNW5YPVHrqtY90tEdI6XNpuLOP26Ci2pfwPsKBA/Wh4Z3FX5sUrtUFTdMYj9v+ug==
|
||||
dependencies:
|
||||
"@floating-ui/core" "^1.0.2"
|
||||
"@floating-ui/core" "^1.0.1"
|
||||
|
||||
"@hotwired/stimulus-webpack-helpers@^1.0.0":
|
||||
version "1.0.1"
|
||||
@@ -8268,9 +8268,9 @@ loader-runner@^2.4.0:
|
||||
integrity sha512-Jsmr89RcXGIwivFY21FcRrisYZfvLMTWx5kOLc+JTxtpBOG6xML0vzbc6SEQG2FO9/4Fc3wW4LVcB5DmGflaRw==
|
||||
|
||||
loader-utils@^1.1.0, loader-utils@^1.2.3, loader-utils@^1.4.0:
|
||||
version "1.4.2"
|
||||
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.4.2.tgz#29a957f3a63973883eb684f10ffd3d151fec01a3"
|
||||
integrity sha512-I5d00Pd/jwMD2QCduo657+YM/6L3KZu++pmX9VFncxaxvHcru9jx1lBaFft+r4Mt2jK0Yhp41XlRAihzPxHNCg==
|
||||
version "1.4.1"
|
||||
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.4.1.tgz#278ad7006660bccc4d2c0c1578e17c5c78d5c0e0"
|
||||
integrity sha512-1Qo97Y2oKaU+Ro2xnDMR26g1BwMT29jNbem1EvcujW2jqt+j5COXyscjM7bLQkM9HaxI7pkWeW7gnI072yMI9Q==
|
||||
dependencies:
|
||||
big.js "^5.2.2"
|
||||
emojis-list "^3.0.0"
|
||||
|
||||
Reference in New Issue
Block a user