Merge pull request #3842 from luisramos0/rubocop-line-length

Fix a few rubocop warnings manually and run rubocop autocorrect
This commit is contained in:
Luis Ramos
2019-05-28 14:08:16 +01:00
committed by GitHub
422 changed files with 2781 additions and 4706 deletions

View File

@@ -22,48 +22,43 @@
Metrics/LineLength:
Max: 100
Exclude:
- Gemfile
- app/controllers/admin/bulk_line_items_controller.rb
- app/controllers/admin/contents_controller.rb
- app/controllers/admin/customers_controller.rb
- app/controllers/admin/enterprises_controller.rb
- app/controllers/admin/enterprise_fees_controller.rb
- app/controllers/admin/enterprise_groups_controller.rb
- app/controllers/admin/enterprise_relationships_controller.rb
- app/controllers/admin/enterprises_controller.rb
- app/controllers/admin/enterprise_roles_controller.rb
- app/controllers/admin/inventory_items_controller.rb
- app/controllers/admin/manager_invitations_controller.rb
- app/controllers/admin/order_cycles_controller.rb
- app/controllers/admin/product_import_controller.rb
- app/controllers/admin/proxy_orders_controller.rb
- app/controllers/admin/schedules_controller.rb
- app/controllers/admin/subscription_line_items_controller.rb
- app/controllers/admin/subscriptions_controller.rb
- app/controllers/admin/variant_overrides_controller.rb
- app/controllers/api/enterprise_attachment_controller.rb
- app/controllers/api/order_cycles_controller.rb
- app/controllers/api/product_images_controller.rb
- app/controllers/application_controller.rb
- app/controllers/base_controller.rb
- app/controllers/cart_controller.rb
- app/controllers/checkout_controller.rb
- app/controllers/shop_controller.rb
- app/controllers/spree/admin/adjustments_controller_decorator.rb
- app/controllers/spree/admin/base_controller_decorator.rb
- app/controllers/spree/admin/line_items_controller_decorator.rb
- app/controllers/spree/admin/orders_controller_decorator.rb
- app/controllers/spree/admin/payments_controller_decorator.rb
- app/controllers/spree/admin/payment_methods_controller_decorator.rb
- app/controllers/spree/admin/products_controller_decorator.rb
- app/controllers/spree/admin/reports_controller_decorator.rb
- app/controllers/spree/admin/shipping_methods_controller_decorator.rb
- app/controllers/spree/api/products_controller_decorator.rb
- app/controllers/spree/credit_cards_controller.rb
- app/controllers/spree/orders_controller_decorator.rb
- app/controllers/spree/paypal_controller_decorator.rb
- app/controllers/stripe/callbacks_controller.rb
- app/controllers/user_confirmations_controller.rb
- app/helpers/admin/account_helper.rb
- app/helpers/admin/injection_helper.rb
- app/helpers/angular_form_builder.rb
- app/helpers/angular_form_helper.rb
- app/helpers/application_helper.rb
- app/helpers/checkout_helper.rb
- app/helpers/enterprises_helper.rb
- app/helpers/footer_links_helper.rb
@@ -75,17 +70,17 @@ Metrics/LineLength:
- app/helpers/spree/admin/navigation_helper_decorator.rb
- app/helpers/spree/admin/orders_helper_decorator.rb
- app/helpers/spree/orders_helper.rb
- app/jobs/products_cache_integrity_checker_job.rb
- app/jobs/subscription_confirm_job.rb
- app/jobs/subscription_placement_job.rb
- app/mailers/producer_mailer.rb
- app/mailers/spree/order_mailer_decorator.rb
- app/mailers/subscription_mailer.rb
- app/models/column_preference.rb
- app/models/concerns/order_shipment.rb
- app/models/concerns/product_stock.rb
- app/models/concerns/variant_stock.rb
- app/models/content_configuration.rb
- app/models/customer.rb
- app/models/enterprise_fee.rb
- app/models/enterprise.rb
- app/models/enterprise_fee.rb
- app/models/enterprise_group.rb
- app/models/enterprise_relationship.rb
- app/models/enterprise_role.rb
- app/models/exchange.rb
@@ -101,9 +96,10 @@ Metrics/LineLength:
- app/models/schedule.rb
- app/models/spree/ability_decorator.rb
- app/models/spree/adjustment_decorator.rb
- app/models/spree/app_configuration_decorator.rb
- app/models/spree/calculator/default_tax_decorator.rb
- app/models/spree/calculator/flexi_rate_decorator.rb
- app/models/spree/classification_decorator.rb
- app/models/spree/concerns/payment_method_distributors.rb
- app/models/spree/gateway/stripe_connect.rb
- app/models/spree/line_item_decorator.rb
- app/models/spree/order_decorator.rb
@@ -112,16 +108,14 @@ Metrics/LineLength:
- app/models/spree/product_decorator.rb
- app/models/spree/shipment_decorator.rb
- app/models/spree/shipping_method_decorator.rb
- app/models/spree/tax_rate_decorator.rb
- app/models/spree/taxon_decorator.rb
- app/models/spree/user_decorator.rb
- app/models/spree/variant_decorator.rb
- app/models/subscription.rb
- app/models/variant_override.rb
- app/models/variant_override_set.rb
- app/overrides/add_distributor_details_js_to_product.rb
- app/overrides/add_enterprise_fees_to_admin_configurations_menu.rb
- app/overrides/replace_checkout_payment_button.rb
- app/overrides/replace_payment_name_with_description.rb
- app/serializers/api/admin/basic_enterprise_serializer.rb
- app/serializers/api/admin/enterprise_fee_serializer.rb
- app/serializers/api/admin/enterprise_serializer.rb
@@ -131,36 +125,34 @@ Metrics/LineLength:
- app/serializers/api/admin/index_order_cycle_serializer.rb
- app/serializers/api/admin/line_item_serializer.rb
- app/serializers/api/admin/order_cycle_serializer.rb
- app/serializers/api/admin/product_serializer.rb
- app/serializers/api/admin/subscription_serializer.rb
- app/serializers/api/admin/tag_rule_serializer.rb
- app/serializers/api/admin/variant_override_serializer.rb
- app/serializers/api/admin/variant_serializer.rb
- app/services/cart_service.rb
- app/services/default_stock_location.rb
- app/services/embedded_page_service.rb
- app/services/line_item_syncer.rb
- app/services/order_cycle_form.rb
- app/services/order_factory.rb
- app/services/order_syncer.rb
- app/services/subscriptions_count.rb
- app/services/variants_stock_levels.rb
- app/views/json/_groups.rabl
- app/views/json/partials/_enterprise.rabl
- app/views/json/_producer.rabl
- app/views/json/partials/_enterprise.rabl
- app/views/spree/api/products/bulk_show.v1.rabl
- app/views/spree/api/variants/bulk_show.v1.rabl
- engines/web/app/helpers/web/cookies_policy_helper.rb
- Gemfile
- lib/discourse/single_sign_on.rb
- lib/open_food_network/available_payment_method_filter.rb
- lib/open_food_network/bulk_coop_report.rb
- lib/open_food_network/customers_report.rb
- app/services/order_cycle_distributed_variants.rb
- lib/open_food_network/enterprise_fee_applicator.rb
- lib/open_food_network/enterprise_fee_calculator.rb
- lib/open_food_network/enterprise_issue_validator.rb
- lib/open_food_network/group_buy_report.rb
- lib/open_food_network/lettuce_share_report.rb
- lib/open_food_network/locking.rb
- lib/open_food_network/order_and_distributor_report.rb
- lib/open_food_network/order_cycle_form_applicator.rb
- lib/open_food_network/order_cycle_management_report.rb
@@ -170,8 +162,8 @@ Metrics/LineLength:
- lib/open_food_network/payments_report.rb
- lib/open_food_network/permalink_generator.rb
- lib/open_food_network/permissions.rb
- lib/open_food_network/products_and_inventory_report_base.rb
- lib/open_food_network/products_cache.rb
- lib/open_food_network/products_renderer.rb
- lib/open_food_network/proxy_order_syncer.rb
- lib/open_food_network/reports/bulk_coop_allocation_report.rb
- lib/open_food_network/reports/line_items.rb
@@ -179,16 +171,13 @@ Metrics/LineLength:
- lib/open_food_network/users_and_enterprises_report.rb
- lib/open_food_network/variant_and_line_item_naming.rb
- lib/open_food_network/xero_invoices_report.rb
- lib/spree/core/calculated_adjustments_decorator.rb
- lib/spree/core/controller_helpers/respond_with_decorator.rb
- lib/spree/localized_number.rb
- lib/spree/product_filters.rb
- lib/stripe/profile_storer.rb
- lib/tasks/cache.rake
- lib/tasks/data.rake
- lib/tasks/dev.rake
- lib/tasks/enterprises.rake
- spec/archive/features/consumer/checkout_spec.rb
- spec/controllers/admin/bulk_line_items_controller_spec.rb
- spec/controllers/admin/column_preferences_controller_spec.rb
- spec/controllers/admin/customers_controller_spec.rb
@@ -216,18 +205,20 @@ Metrics/LineLength:
- spec/controllers/shops_controller_spec.rb
- spec/controllers/spree/admin/adjustments_controller_spec.rb
- spec/controllers/spree/admin/base_controller_spec.rb
- spec/controllers/spree/admin/line_items_controller_spec.rb
- spec/controllers/spree/admin/orders_controller_spec.rb
- spec/controllers/spree/admin/orders/customer_details_controller_spec.rb
- spec/controllers/spree/admin/orders_controller_spec.rb
- spec/controllers/spree/admin/payment_methods_controller_spec.rb
- spec/controllers/spree/admin/payments_controller_spec.rb
- spec/controllers/spree/admin/reports_controller_spec.rb
- spec/controllers/spree/admin/variants_controller_spec.rb
- spec/controllers/spree/api/line_items_controller_spec.rb
- spec/controllers/spree/api/products_controller_spec.rb
- spec/controllers/spree/api/shipments_controller_spec.rb
- spec/controllers/spree/api/variants_controller_spec.rb
- spec/controllers/spree/credit_cards_controller_spec.rb
- spec/controllers/spree/orders_controller_spec.rb
- spec/controllers/spree/users_controller_spec.rb
- spec/controllers/spree/user_sessions_controller_spec.rb
- spec/controllers/spree/users_controller_spec.rb
- spec/controllers/stripe/callbacks_controller_spec.rb
- spec/controllers/stripe/webhooks_controller_spec.rb
- spec/controllers/user_confirmations_controller_spec.rb
@@ -239,10 +230,10 @@ Metrics/LineLength:
- spec/features/admin/enterprise_fees_spec.rb
- spec/features/admin/enterprise_relationships_spec.rb
- spec/features/admin/enterprise_roles_spec.rb
- spec/features/admin/enterprise_user_spec.rb
- spec/features/admin/enterprises/images_spec.rb
- spec/features/admin/enterprises/index_spec.rb
- spec/features/admin/enterprises_spec.rb
- spec/features/admin/enterprise_user_spec.rb
- spec/features/admin/image_settings_spec.rb
- spec/features/admin/multilingual_spec.rb
- spec/features/admin/order_cycles_spec.rb
@@ -283,6 +274,7 @@ Metrics/LineLength:
- spec/helpers/order_cycles_helper_spec.rb
- spec/helpers/spree/admin/base_helper_spec.rb
- spec/jobs/confirm_order_job_spec.rb
- spec/jobs/products_cache_integrity_checker_job_spec.rb
- spec/jobs/refresh_products_cache_job_spec.rb
- spec/jobs/subscription_confirm_job_spec.rb
- spec/jobs/subscription_placement_job_spec.rb
@@ -290,7 +282,6 @@ Metrics/LineLength:
- spec/lib/open_food_network/bulk_coop_report_spec.rb
- spec/lib/open_food_network/cached_products_renderer_spec.rb
- spec/lib/open_food_network/customers_report_spec.rb
- spec/services/order_cycle_distributed_variants.rb
- spec/lib/open_food_network/enterprise_fee_applicator_spec.rb
- spec/lib/open_food_network/enterprise_fee_calculator_spec.rb
- spec/lib/open_food_network/enterprise_injection_data_spec.rb
@@ -301,6 +292,7 @@ Metrics/LineLength:
- spec/lib/open_food_network/order_cycle_form_applicator_spec.rb
- spec/lib/open_food_network/order_cycle_permissions_spec.rb
- spec/lib/open_food_network/order_grouper_spec.rb
- spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb
- spec/lib/open_food_network/packing_report_spec.rb
- spec/lib/open_food_network/permissions_spec.rb
- spec/lib/open_food_network/products_and_inventory_report_spec.rb
@@ -319,6 +311,8 @@ Metrics/LineLength:
- spec/mailers/producer_mailer_spec.rb
- spec/mailers/subscription_mailer_spec.rb
- spec/models/column_preference_spec.rb
- spec/models/concerns/order_shipment_spec.rb
- spec/models/concerns/product_stock_spec.rb
- spec/models/customer_spec.rb
- spec/models/enterprise_caching_spec.rb
- spec/models/enterprise_fee_spec.rb
@@ -345,8 +339,8 @@ Metrics/LineLength:
- spec/models/spree/product_spec.rb
- spec/models/spree/property_spec.rb
- spec/models/spree/shipping_method_spec.rb
- spec/models/spree/taxon_spec.rb
- spec/models/spree/tax_rate_spec.rb
- spec/models/spree/taxon_spec.rb
- spec/models/spree/user_spec.rb
- spec/models/spree/variant_spec.rb
- spec/models/stripe_account_spec.rb
@@ -370,17 +364,19 @@ Metrics/LineLength:
- spec/serializers/admin/for_order_cycle/supplied_product_serializer_spec.rb
- spec/serializers/admin/subscription_customer_serializer_spec.rb
- spec/serializers/admin/variant_override_serializer_spec.rb
- spec/serializers/current_order_serializer.rb
- spec/serializers/enterprise_serializer_spec.rb
- spec/serializers/api/enterprise_shopfront_serializer_spec.rb
- spec/serializers/current_order_serializer_spec.rb
- spec/serializers/order_serializer_spec.rb
- spec/services/cart_service_spec.rb
- spec/services/embedded_page_service_spec.rb
- spec/services/order_cycle_distributed_variants_spec.rb
- spec/services/order_cycle_form_spec.rb
- spec/services/order_factory_spec.rb
- spec/services/order_syncer_spec.rb
- spec/services/subscription_estimator_spec.rb
- spec/services/subscription_form_spec.rb
- spec/services/subscription_validator_spec.rb
- spec/services/subscription_variants_service_spec.rb
- spec/spec_helper.rb
- spec/support/cancan_helper.rb
- spec/support/delayed_job_helper.rb
@@ -397,8 +393,8 @@ Metrics/AbcSize:
Exclude:
- app/controllers/admin/bulk_line_items_controller.rb
- app/controllers/admin/customers_controller.rb
- app/controllers/admin/enterprise_fees_controller.rb
- app/controllers/admin/enterprises_controller.rb
- app/controllers/admin/enterprise_fees_controller.rb
- app/controllers/admin/order_cycles_controller.rb
- app/controllers/admin/product_import_controller.rb
- app/controllers/admin/schedules_controller.rb
@@ -412,17 +408,19 @@ Metrics/AbcSize:
- app/controllers/cart_controller.rb
- app/controllers/checkout_controller.rb
- app/controllers/discourse_sso_controller.rb
- app/controllers/enterprises_controller.rb
- app/controllers/spree/admin/adjustments_controller_decorator.rb
- app/controllers/spree/admin/line_items_controller_decorator.rb
- app/controllers/spree/admin/orders/customer_details_controller_decorator.rb
- app/controllers/spree/admin/orders_controller_decorator.rb
- app/controllers/spree/admin/overview_controller_decorator.rb
- app/controllers/spree/admin/payment_methods_controller_decorator.rb
- app/controllers/spree/admin/payments_controller_decorator.rb
- app/controllers/spree/admin/payment_methods_controller_decorator.rb
- app/controllers/spree/admin/products_controller_decorator.rb
- app/controllers/spree/admin/reports_controller_decorator.rb
- app/controllers/spree/admin/search_controller_decorator.rb
- app/controllers/spree/admin/shipping_methods_controller_decorator.rb
- app/controllers/spree/admin/variants_controller_decorator.rb
- app/controllers/spree/api/products_controller_decorator.rb
- app/controllers/spree/api/shipments_controller_decorator.rb
- app/controllers/spree/credit_cards_controller.rb
- app/controllers/spree/orders_controller_decorator.rb
- app/controllers/spree/user_sessions_controller_decorator.rb
@@ -439,15 +437,14 @@ Metrics/AbcSize:
- app/mailers/producer_mailer.rb
- app/models/calculator/flat_percent_per_item.rb
- app/models/column_preference.rb
- app/models/enterprise_group.rb
- app/models/enterprise.rb
- app/models/enterprise_group.rb
- app/models/enterprise_relationship.rb
- app/models/model_set.rb
- app/models/product_import/entry_processor.rb
- app/models/product_import/entry_validator.rb
- app/models/proxy_order.rb
- app/models/spree/ability_decorator.rb
- app/models/spree/adjustment_decorator.rb
- app/models/spree/calculator/default_tax_decorator.rb
- app/models/spree/calculator/flexi_rate_decorator.rb
- app/models/spree/line_item_decorator.rb
@@ -457,7 +454,6 @@ Metrics/AbcSize:
- app/models/spree/product_set.rb
- app/models/spree/taxon_decorator.rb
- app/serializers/api/admin/enterprise_serializer.rb
- app/serializers/api/enterprise_serializer.rb
- app/serializers/api/product_serializer.rb
- app/serializers/api/variant_serializer.rb
- app/services/cart_service.rb
@@ -478,7 +474,6 @@ Metrics/AbcSize:
- lib/open_food_network/orders_and_fulfillments_report.rb
- lib/open_food_network/packing_report.rb
- lib/open_food_network/payments_report.rb
- lib/open_food_network/permissions.rb
- lib/open_food_network/products_and_inventory_report.rb
- lib/open_food_network/reports/line_items.rb
- lib/open_food_network/sales_tax_report.rb
@@ -489,9 +484,11 @@ Metrics/AbcSize:
- lib/spree/localized_number.rb
- lib/stripe/account_connector.rb
- lib/tasks/enterprises.rake
- spec/archive/features/consumer/checkout_spec.rb
- spec/controllers/spree/admin/orders_controller_spec.rb
- lib/tasks/sample_data/product_factory.rb
- spec/controllers/spree/api/shipments_controller_spec.rb
- spec/features/admin/product_import_spec.rb
- spec/features/admin/reports_spec.rb
- spec/features/admin/subscriptions_spec.rb
- spec/features/consumer/shopping/checkout_spec.rb
- spec/features/consumer/shopping/variant_overrides_spec.rb
- spec/models/enterprise_spec.rb
@@ -501,10 +498,10 @@ Metrics/AbcSize:
Metrics/CyclomaticComplexity:
Max: 6
Exclude:
- app/controllers/admin/enterprise_fees_controller.rb
- app/controllers/admin/enterprises_controller.rb
- app/controllers/admin/enterprise_fees_controller.rb
- app/controllers/checkout_controller.rb
- app/controllers/spree/admin/orders_controller_decorator.rb
- app/controllers/spree/admin/payments_controller_decorator.rb
- app/controllers/spree/orders_controller_decorator.rb
- app/helpers/checkout_helper.rb
- app/helpers/i18n_helper.rb
@@ -515,7 +512,6 @@ Metrics/CyclomaticComplexity:
- app/models/product_import/entry_processor.rb
- app/models/product_import/entry_validator.rb
- app/models/spree/ability_decorator.rb
- app/models/spree/adjustment_decorator.rb
- app/models/spree/payment_decorator.rb
- app/models/spree/product_decorator.rb
- app/models/spree/product_set.rb
@@ -535,7 +531,7 @@ Metrics/PerceivedComplexity:
Exclude:
- app/controllers/admin/enterprises_controller.rb
- app/controllers/checkout_controller.rb
- app/controllers/spree/admin/orders_controller_decorator.rb
- app/controllers/spree/admin/payments_controller_decorator.rb
- app/controllers/spree/orders_controller_decorator.rb
- app/helpers/checkout_helper.rb
- app/helpers/i18n_helper.rb
@@ -545,7 +541,6 @@ Metrics/PerceivedComplexity:
- app/models/product_import/entry_processor.rb
- app/models/product_import/entry_validator.rb
- app/models/spree/ability_decorator.rb
- app/models/spree/line_item_decorator.rb
- app/models/spree/order_decorator.rb
- app/models/spree/product_decorator.rb
- app/models/spree/product_set.rb
@@ -562,8 +557,8 @@ Metrics/MethodLength:
Max: 10
Exclude:
- app/controllers/admin/customers_controller.rb
- app/controllers/admin/enterprise_fees_controller.rb
- app/controllers/admin/enterprises_controller.rb
- app/controllers/admin/enterprise_fees_controller.rb
- app/controllers/admin/manager_invitations_controller.rb
- app/controllers/admin/order_cycles_controller.rb
- app/controllers/admin/stripe_accounts_controller.rb
@@ -572,14 +567,12 @@ Metrics/MethodLength:
- app/controllers/cart_controller.rb
- app/controllers/checkout_controller.rb
- app/controllers/shop_controller.rb
- app/controllers/spree/admin/line_items_controller_decorator.rb
- app/controllers/spree/admin/orders_controller_decorator.rb
- app/controllers/spree/admin/payment_methods_controller_decorator.rb
- app/controllers/spree/admin/orders/customer_details_controller_decorator.rb
- app/controllers/spree/admin/payments_controller_decorator.rb
- app/controllers/spree/admin/payment_methods_controller_decorator.rb
- app/controllers/spree/admin/products_controller_decorator.rb
- app/controllers/spree/admin/reports_controller_decorator.rb
- app/controllers/spree/admin/search_controller_decorator.rb
- app/controllers/spree/admin/shipping_methods_controller_decorator.rb
- app/controllers/spree/credit_cards_controller.rb
- app/controllers/spree/orders_controller_decorator.rb
- app/controllers/spree/user_sessions_controller_decorator.rb
@@ -601,24 +594,23 @@ Metrics/MethodLength:
- app/models/product_import/entry_validator.rb
- app/models/product_import/product_importer.rb
- app/models/spree/ability_decorator.rb
- app/models/spree/adjustment_decorator.rb
- app/models/spree/calculator/default_tax_decorator.rb
- app/models/spree/calculator/flexi_rate_decorator.rb
- app/models/spree/line_item_decorator.rb
- app/models/spree/order_decorator.rb
- app/models/spree/payment_decorator.rb
- app/models/spree/payment_method_decorator.rb
- app/models/spree/product_decorator.rb
- app/models/spree/product_set.rb
- app/models/spree/taxon_decorator.rb
- app/serializers/api/admin/order_cycle_serializer.rb
- app/services/cart_service.rb
- app/serializers/api/cached_enterprise_serializer.rb
- app/services/order_cycle_form.rb
- engines/order_management/app/services/order_management/reports/enterprise_fee_summary/scope.rb
- lib/discourse/single_sign_on.rb
- lib/open_food_network/bulk_coop_report.rb
- lib/open_food_network/cached_products_renderer.rb
- lib/open_food_network/column_preference_defaults.rb
- lib/open_food_network/customers_report.rb
- lib/open_food_network/enterprise_fee_calculator.rb
- lib/open_food_network/enterprise_issue_validator.rb
- lib/open_food_network/group_buy_report.rb
- lib/open_food_network/lettuce_share_report.rb
- lib/open_food_network/option_value_namer.rb
@@ -643,7 +635,7 @@ Metrics/MethodLength:
- lib/spree/core/controller_helpers/respond_with_decorator.rb
- lib/spree/localized_number.rb
- lib/stripe/profile_storer.rb
- spec/archive/features/consumer/checkout_spec.rb
- lib/tasks/sample_data/product_factory.rb
- spec/features/consumer/shopping/checkout_spec.rb
- spec/features/consumer/shopping/variant_overrides_spec.rb
- spec/models/product_importer_spec.rb
@@ -662,8 +654,10 @@ Metrics/ClassLength:
- app/models/product_import/entry_validator.rb
- app/models/product_import/product_importer.rb
- app/models/spree/ability_decorator.rb
- app/serializers/api/enterprise_serializer.rb
- app/serializers/api/cached_enterprise_serializer.rb
- app/serializers/api/enterprise_shopfront_serializer.rb
- app/services/cart_service.rb
- engines/order_management/app/services/order_management/reports/enterprise_fee_summary/scope.rb
- lib/open_food_network/bulk_coop_report.rb
- lib/open_food_network/enterprise_fee_calculator.rb
- lib/open_food_network/order_cycle_form_applicator.rb
@@ -686,6 +680,7 @@ Metrics/ModuleLength:
- spec/controllers/api/orders_controller_spec.rb
- spec/controllers/spree/api/products_controller_spec.rb
- spec/lib/open_food_network/address_finder_spec.rb
- spec/lib/open_food_network/cached_products_renderer_spec.rb
- spec/lib/open_food_network/customers_report_spec.rb
- spec/lib/open_food_network/enterprise_fee_calculator_spec.rb
- spec/lib/open_food_network/option_value_namer_spec.rb
@@ -716,8 +711,3 @@ Metrics/ParameterLists:
- app/models/product_import/entry_validator.rb
- lib/open_food_network/xero_invoices_report.rb
- spec/features/admin/reports_spec.rb
Metrics/BlockNesting:
Max: 3
Exclude:
- app/controllers/checkout_controller.rb

View File

@@ -194,8 +194,6 @@ Metrics/BlockNesting:
Metrics/ClassLength:
Max: 100
Exclude:
- engines/order_management/app/services/order_management/reports/enterprise_fee_summary/scope.rb
Metrics/ModuleLength:
Max: 100
@@ -205,8 +203,6 @@ Metrics/CyclomaticComplexity:
Metrics/MethodLength:
Max: 10
Exclude:
- engines/order_management/app/services/order_management/reports/enterprise_fee_summary/scope.rb
Metrics/ParameterLists:
Max: 5

File diff suppressed because it is too large Load Diff

88
Gemfile
View File

@@ -2,11 +2,11 @@ source 'https://rubygems.org'
ruby "2.1.5"
git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" }
gem 'i18n', '~> 0.6.11'
gem 'i18n-js', '~> 3.2.2'
gem 'rails', '~> 3.2.22'
gem 'rails-i18n', '~> 3.0.0'
gem 'rails_safe_tasks', '~> 1.0'
gem 'i18n', '~> 0.6.11'
gem 'i18n-js', '~> 3.2.2'
# Patched version. See http://rubysec.com/advisories/CVE-2015-5312/.
gem 'nokogiri', '>= 1.6.7.1'
@@ -21,8 +21,8 @@ gem 'pg'
# for details.
gem 'spree', github: 'openfoodfoundation/spree', branch: '2-0-4-stable'
gem 'spree_i18n', github: 'spree/spree_i18n', branch: '1-3-stable'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-0-stable'
gem 'spree_i18n', github: 'spree/spree_i18n', branch: '1-3-stable'
# Our branch contains two changes
# - Pass customer email and phone number to PayPal (merged to upstream master)
@@ -34,51 +34,51 @@ gem 'stripe'
# which is needed for Pin Payments (and possibly others).
gem 'activemerchant', '~> 1.78'
gem 'oauth2', '~> 1.4.1' # Used for Stripe Connect
gem 'jwt', '~> 2.1'
gem 'oauth2', '~> 1.4.1' # Used for Stripe Connect
gem 'delayed_job_active_record'
gem 'daemons'
gem 'delayed_job_active_record'
gem 'delayed_job_web'
# Fix bug in simple_form preventing collection_check_boxes usage within form_for block
# When merged, revert to upstream gem
gem 'simple_form', github: 'RohanM/simple_form'
gem 'unicorn'
gem 'andand'
gem 'angularjs-rails', '1.5.5'
gem 'aws-sdk'
gem 'bugsnag'
gem 'db2fog'
gem 'haml'
gem 'rabl'
gem 'redcarpet'
gem 'sass', "~> 3.3"
gem 'sass-rails', '~> 3.2.3', groups: [:default, :assets]
gem 'redcarpet'
gem 'aws-sdk'
gem 'db2fog'
gem 'andand'
gem 'truncate_html'
gem 'rabl'
gem 'unicorn'
# AMS is pinned to 0.8.4 because 0.9.x is a complete re-write, as is 0.10.x
# Once Rails is updated to 5.x we should bump directly to 0.10.x
gem "active_model_serializers", "0.8.4"
gem 'oj'
gem 'deface', '1.0.2'
gem 'paperclip', '~> 3.4.1'
gem 'acts-as-taggable-on', '~> 3.4'
gem 'angularjs-file-upload-rails', '~> 2.4.1'
gem 'blockenspiel'
gem 'custom_error_message', github: 'jeremydurham/custom-err-msg'
gem 'dalli'
gem 'deface', '1.0.2'
gem 'diffy'
gem 'figaro'
gem 'geocoder'
gem 'gmaps4rails'
gem 'spinjs-rails'
gem 'rack-ssl', require: 'rack/ssl'
gem 'rack-rewrite'
gem 'custom_error_message', github: 'jeremydurham/custom-err-msg'
gem 'angularjs-file-upload-rails', '~> 2.4.1'
gem 'roadie-rails', '~> 1.1.1'
gem 'figaro'
gem 'blockenspiel'
gem 'acts-as-taggable-on', '~> 3.4'
gem 'oj'
gem 'paper_trail', '~> 5.2.3'
gem 'diffy'
gem 'paperclip', '~> 3.4.1'
gem 'rack-rewrite'
gem 'rack-ssl', require: 'rack/ssl'
gem 'roadie-rails', '~> 1.1.1'
gem 'skylight', '< 2.0'
gem 'spinjs-rails'
gem 'combine_pdf'
gem 'wicked_pdf'
@@ -94,64 +94,64 @@ gem 'whenever', require: false
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'compass-rails'
gem 'coffee-rails', '~> 3.2.1'
gem 'compass-rails'
gem 'therubyracer', '=0.12.0'
gem 'uglifier', '>= 1.0.3'
gem 'turbo-sprockets-rails3'
gem 'angular-rails-templates', '~> 0.3.0'
gem 'foundation-icons-sass-rails'
gem 'momentjs-rails'
gem 'angular-rails-templates', '~> 0.3.0'
gem 'turbo-sprockets-rails3'
end
gem "foundation-rails"
gem 'foundation_rails_helper', github: 'willrjmarshall/foundation_rails_helper', branch: "rails3"
gem 'jquery-rails', '3.0.4'
gem 'jquery-migrate-rails'
gem 'jquery-rails', '3.0.4'
gem 'ofn-qz', github: 'openfoodfoundation/ofn-qz', ref: '60da2ae4c44cbb4c8d602f59fb5fff8d0f21db3c'
group :test, :development do
# Pretty printed test output
gem 'fuubar', '~> 2.3.2'
gem 'rspec-rails', ">= 3.5.2"
gem 'shoulda-matchers'
gem "factory_bot_rails", require: false
gem 'atomic'
gem 'awesome_print'
gem 'capybara', '>= 2.15.4'
gem 'database_cleaner', '0.7.1', require: false
gem 'awesome_print'
gem 'letter_opener', '>= 1.4.1'
gem 'timecop'
gem 'selenium-webdriver'
gem 'rspec-retry'
gem "factory_bot_rails", require: false
gem 'fuubar', '~> 2.3.2'
gem 'json_spec', '~> 1.1.4'
gem 'unicorn-rails'
gem 'atomic'
gem 'knapsack'
gem 'letter_opener', '>= 1.4.1'
gem 'rspec-rails', ">= 3.5.2"
gem 'rspec-retry'
gem 'selenium-webdriver'
gem 'shoulda-matchers'
gem 'timecop'
gem 'unicorn-rails'
gem 'webdrivers', '3.8.1'
end
group :test do
gem 'webmock'
gem 'simplecov', require: false
gem 'webmock'
# See spec/spec_helper.rb for instructions
#gem 'perftools.rb'
# gem 'perftools.rb'
end
group :development do
gem 'byebug', '~> 9.0.0' # 9.1 requires ruby 2.2
gem "newrelic_rpm", "~> 3.0"
gem 'pry-byebug', '>= 3.4.3'
gem 'debugger-linecache'
gem 'guard'
gem 'listen', '3.0.8' # 3.1.0 requires ruby 2.2
gem 'guard-livereload'
gem 'guard-rails'
gem 'guard-rspec', '~> 4.7.3'
gem 'listen', '3.0.8' # 3.1.0 requires ruby 2.2
gem "newrelic_rpm", "~> 3.0"
gem 'pry-byebug', '>= 3.4.3'
gem 'rubocop', '>= 0.49.1'
gem 'spring', '1.7.2'
gem 'spring-commands-rspec'

0
Rakefile Normal file → Executable file
View File

View File

@@ -22,9 +22,9 @@ module Admin
order.with_lock do
if @line_item.update_attributes(params[:line_item])
order.update_distribution_charge!
render nothing: true, status: 204 # No Content, does not trigger ng resource auto-update
render nothing: true, status: :no_content # No Content, does not trigger ng resource auto-update
else
render json: { errors: @line_item.errors }, status: 412
render json: { errors: @line_item.errors }, status: :precondition_failed
end
end
end
@@ -36,7 +36,7 @@ module Admin
authorize! :update, order
@line_item.destroy
render nothing: true, status: 204 # No Content, does not trigger ng resource auto-update
render nothing: true, status: :no_content # No Content, does not trigger ng resource auto-update
end
private

View File

@@ -12,9 +12,9 @@ module Admin
render json: @cp_set.collection, each_serializer: Api::Admin::ColumnPreferenceSerializer
else
if @cp_set.errors.present?
render json: { errors: @cp_set.errors }, status: 400
render json: { errors: @cp_set.errors }, status: :bad_request
else
render nothing: true, status: 500
render nothing: true, status: :internal_server_error
end
end
end
@@ -23,7 +23,7 @@ module Admin
def load_collection
collection_hash = Hash[params[:column_preferences].each_with_index.map { |cp, i| [i, cp] }]
collection_hash.reject!{ |i, cp| cp[:action_name] != params[:action_name] }
collection_hash.select!{ |_i, cp| cp[:action_name] == params[:action_name] }
@cp_set = ColumnPreferenceSet.new @column_preferences, collection_attributes: collection_hash
end

View File

@@ -16,7 +16,7 @@ module Admin
# Save any uploaded images
ContentConfig.save
flash[:success] = t(:successfully_updated, :resource => I18n.t('admin.contents.edit.your_content'))
flash[:success] = t(:successfully_updated, resource: I18n.t('admin.contents.edit.your_content'))
redirect_to main_app.edit_admin_contents_path
end

View File

@@ -34,7 +34,7 @@ module Admin
tag_rule_mapping = TagRule.mapping_for(Enterprise.where(id: @customer.enterprise))
render_as_json @customer, tag_rule_mapping: tag_rule_mapping
else
render json: { errors: @customer.errors.full_messages }, status: 400
render json: { errors: @customer.errors.full_messages }, status: :bad_request
end
else
redirect_to '/unauthorized'

View File

@@ -1,9 +1,8 @@
module Admin
class EnterpriseFeesController < ResourceController
before_filter :load_enterprise_fee_set, :only => :index
before_filter :load_enterprise_fee_set, only: :index
before_filter :load_data
def index
@include_calculators = params[:include_calculators].present?
@enterprise = current_enterprise
@@ -34,18 +33,17 @@ module Admin
if params.key? :enterprise_id
redirect_path = main_app.admin_enterprise_fees_path(enterprise_id: params[:enterprise_id])
end
redirect_to redirect_path, :notice => I18n.t(:enterprise_fees_update_notice)
redirect_to redirect_path, notice: I18n.t(:enterprise_fees_update_notice)
else
render :index
end
end
private
def load_enterprise_fee_set
@enterprise_fee_set = EnterpriseFeeSet.new :collection => collection
@enterprise_fee_set = EnterpriseFeeSet.new collection: collection
end
def load_data
@@ -60,7 +58,7 @@ module Admin
coordinator = Enterprise.find_by_id(params[:coordinator_id]) if params[:coordinator_id]
order_cycle = OrderCycle.new(coordinator: coordinator) if order_cycle.nil? && coordinator.present?
enterprises = OpenFoodNetwork::OrderCyclePermissions.new(spree_current_user, order_cycle).visible_enterprises
return EnterpriseFee.for_enterprises(enterprises).order('enterprise_id', 'fee_type', 'name')
EnterpriseFee.for_enterprises(enterprises).order('enterprise_id', 'fee_type', 'name')
else
collection = EnterpriseFee.managed_by(spree_current_user).order('enterprise_id', 'fee_type', 'name')
collection = collection.for_enterprise(current_enterprise) if current_enterprise
@@ -75,6 +73,5 @@ module Admin
def current_enterprise
Enterprise.find params[:enterprise_id] if params.key? :enterprise_id
end
end
end

View File

@@ -12,7 +12,7 @@ module Admin
if @enterprise_relationship.save
render text: Api::Admin::EnterpriseRelationshipSerializer.new(@enterprise_relationship).to_json
else
render status: 400, json: {errors: @enterprise_relationship.errors.full_messages.join(', ')}
render status: :bad_request, json: { errors: @enterprise_relationship.errors.full_messages.join(', ') }
end
end

View File

@@ -13,7 +13,7 @@ module Admin
render text: Api::Admin::EnterpriseRoleSerializer.new(@enterprise_role).to_json
else
render status: 400, json: {errors: @enterprise_role.errors.full_messages.join(', ')}
render status: :bad_request, json: { errors: @enterprise_role.errors.full_messages.join(', ') }
end
end

View File

@@ -6,11 +6,11 @@ module Admin
prepend_before_filter :override_owner, only: :create
prepend_before_filter :override_sells, only: :create
before_filter :load_enterprise_set, :only => :index
before_filter :load_countries, :except => [:index, :register, :check_permalink]
before_filter :load_methods_and_fees, :only => [:edit, :update]
before_filter :load_groups, :only => [:new, :edit, :update, :create]
before_filter :load_taxons, :only => [:new, :edit, :update, :create]
before_filter :load_enterprise_set, only: :index
before_filter :load_countries, except: [:index, :register, :check_permalink]
before_filter :load_methods_and_fees, only: [:edit, :update]
before_filter :load_groups, only: [:new, :edit, :update, :create]
before_filter :load_taxons, only: [:new, :edit, :update, :create]
before_filter :check_can_change_sells, only: :update
before_filter :check_can_change_bulk_sells, only: :bulk_update
before_filter :check_can_change_owner, only: :update
@@ -45,7 +45,7 @@ module Admin
flash[:success] = flash_message_for(@object, :successfully_updated)
respond_with(@object) do |format|
format.html { redirect_to location_after_save }
format.js { render :layout => false }
format.js { render layout: false }
format.json { render_as_json @object, ams_prefix: 'index', spree_current_user: spree_current_user }
end
else
@@ -142,7 +142,7 @@ module Admin
@order_cycle = OrderCycle.find_by_id(params[:order_cycle_id]) if params[:order_cycle_id]
coordinator = Enterprise.find_by_id(params[:coordinator_id]) if params[:coordinator_id]
@order_cycle = OrderCycle.new(coordinator: coordinator) if @order_cycle.nil? && coordinator.present?
return OpenFoodNetwork::OrderCyclePermissions.new(spree_current_user, @order_cycle).visible_enterprises
OpenFoodNetwork::OrderCyclePermissions.new(spree_current_user, @order_cycle).visible_enterprises
when :index
if spree_current_user.admin?
OpenFoodNetwork::Permissions.new(spree_current_user).
@@ -168,9 +168,20 @@ module Admin
end
def load_methods_and_fees
@payment_methods = Spree::PaymentMethod.managed_by(spree_current_user).sort_by!{ |pm| [(@enterprise.payment_methods.include? pm) ? 0 : 1, pm.name] }
@shipping_methods = Spree::ShippingMethod.managed_by(spree_current_user).sort_by!{ |sm| [(@enterprise.shipping_methods.include? sm) ? 0 : 1, sm.name] }
@enterprise_fees = EnterpriseFee.managed_by(spree_current_user).for_enterprise(@enterprise).order(:fee_type, :name).all
# rubocop:disable Style/TernaryParentheses
@payment_methods = Spree::PaymentMethod.managed_by(spree_current_user).sort_by! do |pm|
[(@enterprise.payment_methods.include? pm) ? 0 : 1, pm.name]
end
@shipping_methods = Spree::ShippingMethod.managed_by(spree_current_user).sort_by! do |sm|
[(@enterprise.shipping_methods.include? sm) ? 0 : 1, sm.name]
end
# rubocop:enable Style/TernaryParentheses
@enterprise_fees = EnterpriseFee
.managed_by(spree_current_user)
.for_enterprise(@enterprise)
.order(:fee_type, :name)
.all
end
def load_groups
@@ -187,8 +198,8 @@ module Admin
# methods that are specific to each class do not become available until after the
# record is persisted. This problem is compounded by the use of calculators.
@object.transaction do
tag_rules_attributes.select{ |i, attrs| attrs[:type].present? }.each do |i, attrs|
rule = @object.tag_rules.find_by_id(attrs.delete :id) || attrs[:type].constantize.new(enterprise: @object)
tag_rules_attributes.select{ |_i, attrs| attrs[:type].present? }.each do |_i, attrs|
rule = @object.tag_rules.find_by_id(attrs.delete(:id)) || attrs[:type].constantize.new(enterprise: @object)
create_calculator_for(rule, attrs) if rule.type == "TagRule::DiscountOrder" && rule.calculator.nil?
rule.update_attributes(attrs)
end
@@ -204,13 +215,13 @@ module Admin
def create_calculator_for(rule, attrs)
if attrs[:calculator_type].present? && attrs[:calculator_attributes].present?
rule.update_attributes(calculator_type: attrs[:calculator_type])
attrs[:calculator_attributes].merge!( { id: rule.calculator.id } )
attrs[:calculator_attributes].merge!( id: rule.calculator.id )
end
end
def check_can_change_bulk_sells
unless spree_current_user.admin?
params[:enterprise_set][:collection_attributes].each do |i, enterprise_params|
params[:enterprise_set][:collection_attributes].each do |_i, enterprise_params|
enterprise_params.delete :sells unless spree_current_user == Enterprise.find_by_id(enterprise_params[:id]).owner
end
end
@@ -230,7 +241,7 @@ module Admin
unless spree_current_user.admin?
has_hub = spree_current_user.owned_enterprises.is_hub.any?
new_enterprise_is_producer = Enterprise.new(params[:enterprise]).is_primary_producer
params[:enterprise][:sells] = (has_hub && !new_enterprise_is_producer) ? 'any' : 'none'
params[:enterprise][:sells] = has_hub && !new_enterprise_is_producer ? 'any' : 'none'
end
end
@@ -242,7 +253,7 @@ module Admin
def check_can_change_bulk_owner
unless spree_current_user.admin?
params[:enterprise_set][:collection_attributes].each do |i, enterprise_params|
params[:enterprise_set][:collection_attributes].each do |_i, enterprise_params|
enterprise_params.delete :owner_id
end
end
@@ -273,8 +284,10 @@ module Admin
# Overriding method on Spree's resource controller
def location_after_save
referer_path = OpenFoodNetwork::RefererParser::path(request.referer)
referer_path = OpenFoodNetwork::RefererParser.path(request.referer)
# rubocop:disable Style/RegexpLiteral
refered_from_producer_properties = referer_path =~ /\/producer_properties$/
# rubocop:enable Style/RegexpLiteral
if refered_from_producer_properties
main_app.admin_enterprise_producer_properties_path(@enterprise)

View File

@@ -1,6 +1,5 @@
module Admin
class InventoryItemsController < ResourceController
respond_to :json
respond_override update: { json: {

View File

@@ -20,7 +20,7 @@ module Admin
if new_user
render json: { user: new_user.id }, status: :ok
else
render json: { errors: t('admin.enterprises.invite_manager.error') }, status: 500
render json: { errors: t('admin.enterprises.invite_manager.error') }, status: :internal_server_error
end
end

View File

@@ -53,7 +53,7 @@ module Admin
respond_to do |format|
flash[:notice] = I18n.t(:order_cycles_update_notice) if params[:reloading] == '1'
format.html { redirect_to main_app.edit_admin_order_cycle_path(@order_cycle) }
format.json { render json: { :success => true } }
format.json { render json: { success: true } }
end
else
render json: { errors: @order_cycle.errors.full_messages }, status: :unprocessable_entity
@@ -82,20 +82,19 @@ module Admin
redirect_to main_app.admin_order_cycles_path, notice: I18n.t(:order_cycles_email_to_producers_notice)
end
protected
def collection
return Enterprise.where("1=0") unless json_request?
return order_cycles_from_set if params[:order_cycle_set]
ocs = if params[:as] == "distributor"
OrderCycle.preload(:schedules).ransack(params[:q]).result.
involving_managed_distributors_of(spree_current_user).order('updated_at DESC')
elsif params[:as] == "producer"
OrderCycle.preload(:schedules).ransack(params[:q]).result.
involving_managed_producers_of(spree_current_user).order('updated_at DESC')
else
OrderCycle.preload(:schedules).ransack(params[:q]).result.accessible_by(spree_current_user)
OrderCycle.preload(:schedules).ransack(params[:q]).result.
involving_managed_distributors_of(spree_current_user).order('updated_at DESC')
elsif params[:as] == "producer"
OrderCycle.preload(:schedules).ransack(params[:q]).result.
involving_managed_producers_of(spree_current_user).order('updated_at DESC')
else
OrderCycle.preload(:schedules).ransack(params[:q]).result.accessible_by(spree_current_user)
end
ocs.undated |
@@ -115,7 +114,7 @@ module Admin
# Split ransack params into all those that currently exist and new ones to limit returned ocs to recent or undated
orders_close_at_gt = params[:q].andand.delete(:orders_close_at_gt) || 31.days.ago
params[:q] = {
g: [ params.delete(:q) || {}, { m: 'or', orders_close_at_gt: orders_close_at_gt, orders_close_at_null: true } ]
g: [params.delete(:q) || {}, { m: 'or', orders_close_at_gt: orders_close_at_gt, orders_close_at_null: true }]
}
@collection = collection
end
@@ -158,7 +157,7 @@ module Admin
params[:order_cycle].delete :coordinator_id
unless Enterprise.managed_by(spree_current_user).include?(@order_cycle.coordinator)
params[:order_cycle].delete_if{ |k,v| [:name, :orders_open_at, :orders_close_at].include? k.to_sym }
params[:order_cycle].delete_if{ |k, _v| [:name, :orders_open_at, :orders_close_at].include? k.to_sym }
end
end
@@ -173,7 +172,7 @@ module Admin
def order_cycles_from_set
remove_unauthorized_bulk_attrs
OrderCycle.where(id: params[:order_cycle_set][:collection_attributes].map{ |k,v| v[:id] })
OrderCycle.where(id: params[:order_cycle_set][:collection_attributes].map{ |_k, v| v[:id] })
end
def order_cycle_set

View File

@@ -4,7 +4,6 @@ module Admin
before_filter :load_properties
before_filter :setup_property, only: [:index]
private
def collection_url

View File

@@ -1,7 +1,7 @@
module Admin
class ResourceController < Spree::Admin::ResourceController
def model_class
"#{controller_name.classify}".constantize
controller_name.classify.to_s.constantize
end
# URL helpers
@@ -22,7 +22,7 @@ module Admin
end
def object_url(object = nil, options = {})
target = object ? object : @object
target = object || @object
if parent_data.present?
main_app.public_send "admin_#{model_name}_#{object_name}_url", parent, target, options
else

View File

@@ -18,7 +18,7 @@ module Admin
def update
Spree::Config.set(params[:settings])
resource = t('admin.controllers.stripe_connect_settings.resource')
flash[:success] = t(:successfully_updated, :resource => resource)
flash[:success] = t(:successfully_updated, resource: resource)
redirect_to_edit
end

View File

@@ -1,10 +1,9 @@
module Admin
class TagRulesController < ResourceController
respond_to :json
respond_override destroy: { json: {
success: lambda { render nothing: true, :status => 204 }
success: lambda { render nothing: true, status: :no_content }
} }
def map_by_tag
@@ -16,7 +15,6 @@ module Admin
end
end
private
def collection_actions

View File

@@ -9,9 +9,7 @@ module Admin
before_filter :load_collection, only: [:bulk_update]
before_filter :load_spree_api_key, only: :index
def index
end
def index; end
def bulk_update
# Ensure we're authorised to update all variant overrides
@@ -22,9 +20,9 @@ module Admin
render json: @vo_set.collection, each_serializer: Api::Admin::VariantOverrideSerializer
else
if @vo_set.errors.present?
render json: { errors: @vo_set.errors }, status: 400
render json: { errors: @vo_set.errors }, status: :bad_request
else
render nothing: true, status: 500
render nothing: true, status: :internal_server_error
end
end
end
@@ -35,13 +33,12 @@ module Admin
@collection.each(&:reset_stock!)
if collection_errors.present?
render json: { errors: collection_errors }, status: 400
render json: { errors: collection_errors }, status: :bad_request
else
render json: @collection, each_serializer: Api::Admin::VariantOverrideSerializer
end
end
private
def load_data

View File

@@ -10,7 +10,7 @@ module Api
authorize! :update, @customer
if @customer.update_attributes(params[:customer])
render json: @customer, serializer: CustomerSerializer, status: 200
render json: @customer, serializer: CustomerSerializer, status: :ok
else
invalid_resource!(@customer)
end

View File

@@ -6,9 +6,9 @@ module Api
authorize! :destroy, enterprise_fee
if enterprise_fee.destroy
render text: I18n.t(:successfully_removed), status: 204
render text: I18n.t(:successfully_removed), status: :no_content
else
render text: enterprise_fee.errors.full_messages.first, status: 403
render text: enterprise_fee.errors.full_messages.first, status: :forbidden
end
end

View File

@@ -1,6 +1,5 @@
module Api
class EnterprisesController < BaseController
before_filter :override_owner, only: [:create, :update]
before_filter :check_type, only: :update
before_filter :override_sells, only: [:create, :update]
@@ -17,7 +16,7 @@ module Api
@enterprise = Enterprise.new(params[:enterprise])
if @enterprise.save
render text: @enterprise.id, :status => 201
render text: @enterprise.id, status: :created
else
invalid_resource!(@enterprise)
end
@@ -28,7 +27,7 @@ module Api
authorize! :update, @enterprise
if @enterprise.update_attributes(params[:enterprise])
render text: @enterprise.id, :status => 200
render text: @enterprise.id, status: :ok
else
invalid_resource!(@enterprise)
end
@@ -38,10 +37,10 @@ module Api
@enterprise = Enterprise.find_by_permalink(params[:id]) || Enterprise.find(params[:id])
authorize! :update, @enterprise
if params[:logo] && @enterprise.update_attributes( { logo: params[:logo] } )
render text: @enterprise.logo.url(:medium), :status => 200
elsif params[:promo] && @enterprise.update_attributes( { promo_image: params[:promo] } )
render text: @enterprise.promo_image.url(:medium), :status => 200
if params[:logo] && @enterprise.update_attributes( logo: params[:logo] )
render text: @enterprise.logo.url(:medium), status: :ok
elsif params[:promo] && @enterprise.update_attributes( promo_image: params[:promo] )
render text: @enterprise.promo_image.url(:medium), status: :ok
else
invalid_resource!(@enterprise)
end

View File

@@ -10,13 +10,13 @@ module Api
def accessible
@order_cycles = if params[:as] == "distributor"
OrderCycle.ransack(params[:q]).result.
involving_managed_distributors_of(current_api_user).order('updated_at DESC')
elsif params[:as] == "producer"
OrderCycle.ransack(params[:q]).result.
involving_managed_producers_of(current_api_user).order('updated_at DESC')
else
OrderCycle.ransack(params[:q]).result.accessible_by(current_api_user)
OrderCycle.ransack(params[:q]).result.
involving_managed_distributors_of(current_api_user).order('updated_at DESC')
elsif params[:as] == "producer"
OrderCycle.ransack(params[:q]).result.
involving_managed_producers_of(current_api_user).order('updated_at DESC')
else
OrderCycle.ransack(params[:q]).result.accessible_by(current_api_user)
end
render params[:template] || :bulk_index

View File

@@ -3,10 +3,9 @@ module Api
respond_to :json
def job_queue
render json: {alive: job_queue_alive?}
render json: { alive: job_queue_alive? }
end
private
def job_queue_alive?

View File

@@ -4,19 +4,24 @@ class ApplicationController < ActionController::Base
protect_from_forgery
prepend_before_filter :restrict_iframes
before_filter :set_cache_headers # Issue #1213, prevent cart emptying via cache when using back button
before_filter :set_cache_headers # prevent cart emptying via cache when using back button #1213
include EnterprisesHelper
def redirect_to(options = {}, response_status = {})
::Rails.logger.error("Redirected by #{caller(1).first rescue "unknown"}")
::Rails.logger.error("Redirected by #{begin
caller(1).first
rescue StandardError
'unknown'
end}")
super(options, response_status)
end
def set_checkout_redirect
referer_path = OpenFoodNetwork::RefererParser::path(request.referer)
referer_path = OpenFoodNetwork::RefererParser.path(request.referer)
if referer_path
session["spree_user_return_to"] = [main_app.checkout_path].include?(referer_path) ? referer_path : root_path
is_checkout_path_the_referer = [main_app.checkout_path].include?(referer_path)
session["spree_user_return_to"] = is_checkout_path_the_referer ? referer_path : root_path
end
end
@@ -27,13 +32,13 @@ class ApplicationController < ActionController::Base
def enable_embedded_styles
session[:embedded_shopfront] = true
render json: {}, status: 200
render json: {}, status: :ok
end
def disable_embedded_styles
session.delete :embedded_shopfront
session.delete :shopfront_redirect
render json: {}, status: 200
render json: {}, status: :ok
end
protected
@@ -44,7 +49,7 @@ class ApplicationController < ActionController::Base
end
def after_sign_out_path_for(_resource_or_scope)
session[:shopfront_redirect] ? session[:shopfront_redirect] : root_path
session[:shopfront_redirect] || root_path
end
private
@@ -81,8 +86,8 @@ class ApplicationController < ActionController::Base
# This condition is more rigourous than required by development to avoid coupling this
# condition to every controller spec
if current_distributor && current_order &&
current_distributor.respond_to?(:ready_for_checkout?) &&
!current_distributor.ready_for_checkout?
current_distributor.respond_to?(:ready_for_checkout?) &&
!current_distributor.ready_for_checkout?
current_order.empty!
current_order.set_distribution! nil, nil
@@ -105,10 +110,10 @@ class ApplicationController < ActionController::Base
# Useful for rendering html within a JSON response, particularly if the specified
# template or partial then goes on to render further partials without specifying
# their format.
def with_format(format, &block)
def with_format(format)
old_formats = formats
self.formats = [format]
block.call
yield
self.formats = old_formats
nil
end
@@ -118,5 +123,4 @@ class ApplicationController < ActionController::Base
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
end
end

View File

@@ -32,7 +32,9 @@ class BaseController < ApplicationController
@order_cycles = OrderCycle.with_distributor(@distributor).active
.order(@distributor.preferred_shopfront_order_cycle_order)
applicator = OpenFoodNetwork::TagRuleApplicator.new(@distributor, "FilterOrderCycles", current_customer.andand.tag_list)
applicator = OpenFoodNetwork::TagRuleApplicator.new(@distributor,
"FilterOrderCycles",
current_customer.andand.tag_list)
applicator.filter!(@order_cycles)
# And default to the only order cycle if there's only the one

View File

@@ -40,15 +40,15 @@ class CheckoutController < Spree::CheckoutController
next if advance_order_state(@order)
if @order.errors.present?
flash[:error] = @order.errors.full_messages.to_sentence
else
flash[:error] = t(:payment_processing_failed)
end
flash[:error] = if @order.errors.present?
@order.errors.full_messages.to_sentence
else
t(:payment_processing_failed)
end
update_failed
return
end
return update_failed unless @order.state == "complete" || @order.completed?
return update_failed unless @order.state == "complete" || @order.completed?
set_default_bill_address
set_default_ship_address
@@ -59,10 +59,10 @@ class CheckoutController < Spree::CheckoutController
flash[:notice] = t(:order_processed_successfully)
respond_to do |format|
format.html do
respond_with(@order, :location => order_path(@order))
respond_with(@order, location: order_path(@order))
end
format.json do
render json: {path: order_path(@order)}, status: 200
render json: { path: order_path(@order) }, status: :ok
end
end
end
@@ -82,10 +82,14 @@ class CheckoutController < Spree::CheckoutController
new_bill_address = @order.bill_address.clone.attributes
user_bill_address_id = spree_current_user.bill_address.andand.id
spree_current_user.update_attributes(bill_address_attributes: new_bill_address.merge('id' => user_bill_address_id))
spree_current_user.update_attributes(
bill_address_attributes: new_bill_address.merge('id' => user_bill_address_id)
)
customer_bill_address_id = @order.customer.bill_address.andand.id
@order.customer.update_attributes(bill_address_attributes: new_bill_address.merge('id' => customer_bill_address_id))
@order.customer.update_attributes(
bill_address_attributes: new_bill_address.merge('id' => customer_bill_address_id)
)
end
end
@@ -94,35 +98,43 @@ class CheckoutController < Spree::CheckoutController
new_ship_address = @order.ship_address.clone.attributes
user_ship_address_id = spree_current_user.ship_address.andand.id
spree_current_user.update_attributes(ship_address_attributes: new_ship_address.merge('id' => user_ship_address_id))
spree_current_user.update_attributes(
ship_address_attributes: new_ship_address.merge('id' => user_ship_address_id)
)
customer_ship_address_id = @order.customer.ship_address.andand.id
@order.customer.update_attributes(ship_address_attributes: new_ship_address.merge('id' => customer_ship_address_id))
@order.customer.update_attributes(
ship_address_attributes: new_ship_address.merge('id' => customer_ship_address_id)
)
end
end
def check_order_for_phantom_fees
phantom_fees = @order.adjustments.joins('LEFT OUTER JOIN spree_line_items ON spree_line_items.id = spree_adjustments.source_id').
where("originator_type = 'EnterpriseFee' AND source_type = 'Spree::LineItem' AND spree_line_items.id IS NULL")
phantom_fees = @order.adjustments.
joins("LEFT OUTER JOIN spree_line_items"\
" ON spree_line_items.id = spree_adjustments.source_id").
where("originator_type = 'EnterpriseFee'"\
" AND source_type = 'Spree::LineItem' AND spree_line_items.id IS NULL")
if phantom_fees.any?
Bugsnag.notify(RuntimeError.new("Phantom Fees"), {
phantom_fees: {
phantom_total: phantom_fees.sum(&:amount).to_s,
phantom_fees: phantom_fees.as_json
}
})
Bugsnag.notify(RuntimeError.new("Phantom Fees"),
phantom_fees: {
phantom_total: phantom_fees.sum(&:amount).to_s,
phantom_fees: phantom_fees.as_json
})
end
end
# Copied and modified from spree. Remove check for order state, since the state machine is
# progressed all the way in one go with the one page checkout.
def object_params
# For payment step, filter order parameters to produce the expected nested attributes for a single payment and its source, discarding attributes for payment methods other than the one selected
# For payment step, filter order parameters to produce the expected
# nested attributes for a single payment and its source,
# discarding attributes for payment methods other than the one selected
if params[:payment_source].present? && source_params = params.delete(:payment_source)[params[:order][:payments_attributes].first[:payment_method_id].underscore]
params[:order][:payments_attributes].first[:source_attributes] = source_params
end
if (params[:order][:payments_attributes])
if params[:order][:payments_attributes]
params[:order][:payments_attributes].first[:amount] = @order.total
end
if params[:order][:existing_card_id]
@@ -149,12 +161,13 @@ class CheckoutController < Spree::CheckoutController
render :edit
end
format.json do
render json: {errors: @order.errors, flash: flash.to_hash}.to_json, status: 400
render json: { errors: @order.errors, flash: flash.to_hash }.to_json, status: :bad_request
end
end
end
# When we have a pickup Shipping Method, we clone the distributor address into ship_address before_save
# When we have a pickup Shipping Method,
# we clone the distributor address into ship_address before_save
# We don't want this data in the form, so we clear it out
def clear_ship_address
unless current_order.shipping_method.andand.require_ship_address
@@ -168,9 +181,9 @@ class CheckoutController < Spree::CheckoutController
def load_order
@order = current_order
redirect_to main_app.shop_path and return unless @order and @order.checkout_allowed?
redirect_to_cart_path and return unless valid_order_line_items?
redirect_to main_app.shop_path and return if @order.completed?
redirect_to(main_app.shop_path) && return unless @order && @order.checkout_allowed?
redirect_to_cart_path && return unless valid_order_line_items?
redirect_to(main_app.shop_path) && return if @order.completed?
before_address
setup_for_current_state
end
@@ -185,7 +198,9 @@ class CheckoutController < Spree::CheckoutController
end
def valid_order_line_items?
@order.insufficient_stock_lines.empty? && OrderCycleDistributedVariants.new(@order.order_cycle, @order.distributor).distributes_order_variants?(@order)
@order.insufficient_stock_lines.empty? &&
OrderCycleDistributedVariants.new(@order.order_cycle, @order.distributor).
distributes_order_variants?(@order)
end
def redirect_to_cart_path
@@ -195,7 +210,7 @@ class CheckoutController < Spree::CheckoutController
end
format.json do
render json: {path: cart_path}, status: 400
render json: { path: cart_path }, status: :bad_request
end
end
end
@@ -203,10 +218,12 @@ class CheckoutController < Spree::CheckoutController
def redirect_to_paypal_express_form_if_needed
return unless params[:order][:payments_attributes]
payment_method = Spree::PaymentMethod.find(params[:order][:payments_attributes].first[:payment_method_id])
return unless payment_method.kind_of?(Spree::Gateway::PayPalExpress)
payment_method_id = params[:order][:payments_attributes].first[:payment_method_id]
payment_method = Spree::PaymentMethod.find(payment_method_id)
return unless payment_method.is_a?(Spree::Gateway::PayPalExpress)
render json: {path: spree.paypal_express_path(payment_method_id: payment_method.id)}, status: 200
render json: { path: spree.paypal_express_path(payment_method_id: payment_method.id) },
status: :ok
true
end
@@ -230,7 +247,7 @@ class CheckoutController < Spree::CheckoutController
flash[:error] = t(:spree_gateway_error_flash_for_checkout, error: error.message)
respond_to do |format|
format.html { render :edit }
format.json { render json: { flash: flash.to_hash }, status: 400 }
format.json { render json: { flash: flash.to_hash }, status: :bad_request }
end
end
end

View File

@@ -41,7 +41,7 @@ class DiscourseSsoController < ApplicationController
end
def require_config
raise ActionController::RoutingError.new('Not Found') unless discourse_configured?
raise ActionController::RoutingError, 'Not Found' unless discourse_configured?
end
def require_activation?

View File

@@ -42,13 +42,15 @@ class EnterprisesController < BaseController
end
def check_permalink
render text: params[:permalink], status: 409 and return if Enterprise.find_by_permalink params[:permalink]
if Enterprise.find_by_permalink params[:permalink]
render(text: params[:permalink], status: :conflict) && return
end
begin
Rails.application.routes.recognize_path( "/#{ params[:permalink].to_s }" )
render text: params[:permalink], status: 409
Rails.application.routes.recognize_path( "/#{params[:permalink]}" )
render text: params[:permalink], status: :conflict
rescue ActionController::RoutingError
render text: params[:permalink], status: 200
render text: params[:permalink], status: :ok
end
end
@@ -67,7 +69,8 @@ class EnterprisesController < BaseController
end
def reset_order
distributor = Enterprise.is_distributor.find_by_permalink(params[:id]) || Enterprise.is_distributor.find(params[:id])
distributor = Enterprise.is_distributor.find_by_permalink(params[:id]) ||
Enterprise.is_distributor.find(params[:id])
order = current_order(true)
reset_distributor(order, distributor)

View File

@@ -12,7 +12,5 @@ class HomeController < BaseController
end
end
def sell
end
def sell; end
end

View File

@@ -28,11 +28,11 @@ class LineItemsController < BaseController
def unauthorized
status = spree_current_user ? 403 : 401
render nothing: true, status: status and return
render(nothing: true, status: status) && return
end
def not_found
render nothing: true, status: 404 and return
render(nothing: true, status: :not_found) && return
end
def destroy_with_lock(item)

View File

@@ -1,6 +1,5 @@
class MapController < BaseController
layout 'darkswarm'
def index
end
def index; end
end

View File

@@ -3,6 +3,5 @@ class ProducersController < BaseController
before_filter :enable_embedded_shopfront
def index
end
def index; end
end

View File

@@ -10,17 +10,16 @@ class ShopController < BaseController
end
def products
begin
renderer = OpenFoodNetwork::CachedProductsRenderer.new(current_distributor, current_order_cycle)
renderer = OpenFoodNetwork::CachedProductsRenderer.new(current_distributor,
current_order_cycle)
# If we add any more filtering logic, we should probably
# move it all to a lib class like 'CachedProductsFilterer'
products_json = filter(renderer.products_json)
# If we add any more filtering logic, we should probably
# move it all to a lib class like 'CachedProductsFilterer'
products_json = filter(renderer.products_json)
render json: products_json
rescue OpenFoodNetwork::CachedProductsRenderer::NoProducts
render status: 404, json: ''
end
render json: products_json
rescue OpenFoodNetwork::CachedProductsRenderer::NoProducts
render status: :not_found, json: ''
end
def order_cycle
@@ -30,7 +29,7 @@ class ShopController < BaseController
@current_order_cycle = oc
render partial: "json/order_cycle"
else
render status: 404, json: ""
render status: :not_found, json: ""
end
else
render partial: "json/order_cycle"
@@ -59,6 +58,8 @@ class ShopController < BaseController
def applicator
return @applicator unless @applicator.nil?
@applicator = OpenFoodNetwork::TagRuleApplicator.new(current_distributor, "FilterProducts", current_customer.andand.tag_list)
@applicator = OpenFoodNetwork::TagRuleApplicator.new(current_distributor,
"FilterProducts",
current_customer.andand.tag_list)
end
end

View File

@@ -47,7 +47,6 @@ Spree::Admin::BaseController.class_eval do
end
end
private
def active_distributors_not_ready_for_checkout
@@ -74,7 +73,7 @@ Spree::Admin::BaseController.class_eval do
request.format.json?
end
def render_as_json(data, options={})
def render_as_json(data, options = {})
ams_prefix = options.delete :ams_prefix
if [Array, ActiveRecord::Relation].include? data.class
render options.merge(json: data, each_serializer: serializer(ams_prefix))

View File

@@ -3,7 +3,6 @@ module Spree
GeneralSettingsController.class_eval do
end
module GeneralSettingsEditPreferences
def edit
super

View File

@@ -2,5 +2,5 @@ Spree::Admin::ImagesController.class_eval do
# This will make resource controller redirect correctly after deleting product images.
# This can be removed after upgrading to Spree 2.1.
# See here https://github.com/spree/spree/commit/334a011d2b8e16355e4ae77ae07cd93f7cbc8fd1
belongs_to 'spree/product', :find_by => :permalink
belongs_to 'spree/product', find_by: :permalink
end

View File

@@ -13,7 +13,7 @@ Spree::Admin::Orders::CustomerDetailsController.class_eval do
flash[:success] = Spree.t('customer_details_updated')
redirect_to admin_order_customer_path(@order)
else
render :action => :edit
render action: :edit
end
end

View File

@@ -3,7 +3,7 @@ require 'open_food_network/spree_api_key_loader'
Spree::Admin::OrdersController.class_eval do
include OpenFoodNetwork::SpreeApiKeyLoader
helper CheckoutHelper
before_filter :load_spree_api_key, :only => :bulk_management
before_filter :load_spree_api_key, only: :bulk_management
before_filter :load_order, only: %i[show edit update fire resend invoice print print_ticket]
before_filter :load_distribution_choices, only: [:new, :edit, :update]
@@ -16,7 +16,7 @@ Spree::Admin::OrdersController.class_eval do
# fees! This is a quick fix for that.
# TODO: update fees when adding/removing line items
# instead of the update_distribution_charge method.
after_filter :update_distribution_charge, :only => :update
after_filter :update_distribution_charge, only: :update
before_filter :require_distributor_abn, only: :invoice
@@ -43,7 +43,7 @@ Spree::Admin::OrdersController.class_eval do
def update
unless @order.update_attributes(params[:order]) && @order.line_items.present?
@order.errors.add(:line_items, Spree.t('errors.messages.blank')) if @order.line_items.empty?
return redirect_to edit_admin_order_path(@order), :flash => { :error => @order.errors.full_messages.join(', ') }
return redirect_to edit_admin_order_path(@order), flash: { error: @order.errors.full_messages.join(', ') }
end
@order.update!
@@ -88,7 +88,7 @@ Spree::Admin::OrdersController.class_eval do
private
def require_distributor_abn
unless @order.distributor.abn.present?
if @order.distributor.abn.blank?
flash[:error] = t(:must_have_valid_business_number, enterprise_name: @order.distributor.name)
respond_with(@order) { |format| format.html { redirect_to edit_admin_order_path(@order) } }
end

View File

@@ -12,7 +12,7 @@ module Spree
def collection
return parent.public_send(controller_name) if parent_data.present?
collection = if model_class.respond_to?(:accessible_by) &&
!current_ability.has_block?(params[:action], model_class)
!current_ability.has_block?(params[:action], model_class)
model_class.accessible_by(current_ability, action)
@@ -41,7 +41,7 @@ module Spree
@payment_method = PaymentMethod.find(params[:pm_id])
end
else
@payment_method = params[:provider_type].constantize.new()
@payment_method = params[:provider_type].constantize.new
end
render partial: 'provider_settings'
end
@@ -53,17 +53,21 @@ module Spree
end
def load_data
if spree_current_user.admin? || Rails.env.test?
@providers = Gateway.providers.sort{|p1, p2| p1.name <=> p2.name }
else
@providers = Gateway.providers.reject{ |p| p.name.include? "Bogus" }.sort{|p1, p2| p1.name <=> p2.name }
end
@providers = if spree_current_user.admin? || Rails.env.test?
Gateway.providers.sort_by(&:name)
else
Gateway.providers.reject{ |p| p.name.include? "Bogus" }.sort_by(&:name)
end
@providers.reject!{ |p| p.name.ends_with? "StripeConnect" } unless show_stripe?
@calculators = PaymentMethod.calculators.sort_by(&:name)
end
def load_hubs
@hubs = Enterprise.managed_by(spree_current_user).is_distributor.sort_by!{ |d| [(@payment_method.has_distributor? d) ? 0 : 1, d.name] }
# rubocop:disable Style/TernaryParentheses
@hubs = Enterprise.managed_by(spree_current_user).is_distributor.sort_by! do |d|
[(@payment_method.has_distributor? d) ? 0 : 1, d.name]
end
# rubocop:enable Style/TernaryParentheses
end
# Show Stripe as an option if enabled, or if the

View File

@@ -3,7 +3,7 @@ Spree::Admin::PaymentsController.class_eval do
def create
@payment = @order.payments.build(object_params)
if @payment.payment_method.is_a?(Spree::Gateway) && @payment.payment_method.payment_profiles_supported? && params[:card].present? and params[:card] != 'new'
if @payment.payment_method.is_a?(Spree::Gateway) && @payment.payment_method.payment_profiles_supported? && params[:card].present? && (params[:card] != 'new')
@payment.source = CreditCard.find_by_id(params[:card])
end
@@ -17,16 +17,15 @@ Spree::Admin::PaymentsController.class_eval do
@payment.process!
flash[:success] = flash_message_for(@payment, :successfully_created)
redirect_to admin_order_payments_path(@order)
redirect_to admin_order_payments_path(@order)
else
AdvanceOrderService.new(@order).call!
flash[:success] = Spree.t(:new_order_completed)
redirect_to edit_admin_order_url(@order)
end
rescue Spree::Core::GatewayError => e
flash[:error] = "#{e.message}"
flash[:error] = e.message.to_s
redirect_to new_admin_order_payment_path(@order)
end
end
@@ -50,12 +49,11 @@ Spree::Admin::PaymentsController.class_eval do
redirect_to request.referer
end
private
# Only show payments for the order's distributor
def filter_payment_methods
@payment_methods = @payment_methods.select{ |pm| pm.has_distributor? @order.distributor}
@payment_methods = @payment_methods.select{ |pm| pm.has_distributor? @order.distributor }
@payment_method ||= @payment_methods.first
end
end

View File

@@ -7,8 +7,8 @@ Spree::Admin::ProductsController.class_eval do
include EnterprisesHelper
before_filter :load_data
before_filter :load_form_data, :only => [:index, :new, :create, :edit, :update]
before_filter :load_spree_api_key, :only => [:index, :variant_overrides]
before_filter :load_form_data, only: [:index, :new, :create, :edit, :update]
before_filter :load_spree_api_key, only: [:index, :variant_overrides]
before_filter :strip_new_properties, only: [:create, :update]
respond_override create: { html: {
@@ -21,7 +21,8 @@ Spree::Admin::ProductsController.class_eval do
},
failure: lambda {
render :new
} } }
}
} }
def index
@current_user = spree_current_user
@@ -41,8 +42,8 @@ Spree::Admin::ProductsController.class_eval do
end
def bulk_update
collection_hash = Hash[params[:products].each_with_index.map { |p,i| [i,p] }]
product_set = Spree::ProductSet.new({:collection_attributes => collection_hash})
collection_hash = Hash[params[:products].each_with_index.map { |p, i| [i, p] }]
product_set = Spree::ProductSet.new(collection_attributes: collection_hash)
params[:filters] ||= {}
bulk_index_query = params[:filters].reduce("") do |string, filter|
@@ -56,14 +57,13 @@ Spree::Admin::ProductsController.class_eval do
redirect_to "/api/products/bulk_products?page=1;per_page=500;#{bulk_index_query}"
else
if product_set.errors.present?
render json: { errors: product_set.errors }, status: 400
render json: { errors: product_set.errors }, status: :bad_request
else
render :nothing => true, :status => 500
render nothing: true, status: :internal_server_error
end
end
end
protected
def collection
@@ -100,7 +100,6 @@ Spree::Admin::ProductsController.class_eval do
[:index, :bulk_update]
end
private
def load_form_data
@@ -115,11 +114,11 @@ Spree::Admin::ProductsController.class_eval do
joins(:product).
where('spree_products.supplier_id IN (?)', editable_enterprises.collect(&:id)).
where('spree_variants.import_date IS NOT NULL').
where(spree_variants: {is_master: false}).
where(spree_variants: {deleted_at: nil}).
where(spree_variants: { is_master: false }).
where(spree_variants: { deleted_at: nil }).
order('spree_variants.import_date DESC')
options = [{id: '0', name: ''}]
options = [{ id: '0', name: '' }]
import_dates.collect(&:import_date).map { |i| options.push(id: i.to_date, name: i.to_date.to_formatted_s(:long)) }
options

View File

@@ -1,28 +1,28 @@
Spree::Admin::SearchController.class_eval do
def known_users
if exact_match = Spree.user_class.find_by_email(params[:q])
@users = [exact_match]
else
@users = spree_current_user.known_users.ransack({
:m => 'or',
:email_start => params[:q],
:ship_address_firstname_start => params[:q],
:ship_address_lastname_start => params[:q],
:bill_address_firstname_start => params[:q],
:bill_address_lastname_start => params[:q]
}).result.limit(10)
end
@users = if exact_match = Spree.user_class.find_by_email(params[:q])
[exact_match]
else
spree_current_user.known_users.ransack(
m: 'or',
email_start: params[:q],
ship_address_firstname_start: params[:q],
ship_address_lastname_start: params[:q],
bill_address_firstname_start: params[:q],
bill_address_lastname_start: params[:q]
).result.limit(10)
end
render json: @users, each_serializer: Api::Admin::UserSerializer
end
def customers
if spree_current_user.enterprises.pluck(:id).include? params[:distributor_id].to_i
@customers = Customer.ransack({m: 'or', email_start: params[:q], name_start: params[:q]})
.result.where(enterprise_id: params[:distributor_id])
else
@customers = []
end
@customers = if spree_current_user.enterprises.pluck(:id).include? params[:distributor_id].to_i
Customer.ransack(m: 'or', email_start: params[:q], name_start: params[:q])
.result.where(enterprise_id: params[:distributor_id])
else
[]
end
render json: @customers, each_serializer: Api::Admin::CustomerSerializer
end

View File

@@ -1,7 +1,7 @@
module Spree
module Admin
ShippingMethodsController.class_eval do
before_filter :do_not_destroy_referenced_shipping_methods, :only => :destroy
before_filter :do_not_destroy_referenced_shipping_methods, only: :destroy
before_filter :load_hubs, only: [:new, :edit, :create, :update]
# Sort shipping methods by distributor name
@@ -17,20 +17,25 @@ module Spree
collection
end
# Spree allows soft deletes of shipping_methods but our reports are not adapted to that.
# So, this method prevents the deletion (even soft) of shipping_methods that are referenced in orders.
# Spree allows soft deletes of shipping_methods but our reports are not adapted to that
# Here we prevent the deletion (even soft) of shipping_methods that are referenced in orders
def do_not_destroy_referenced_shipping_methods
order = Order.joins(shipments: :shipping_rates).where( spree_shipping_rates: { :shipping_method_id => @object } ).first
if order
flash[:error] = I18n.t(:shipping_method_destroy_error, number: order.number)
redirect_to collection_url and return
end
order = Order.joins(shipments: :shipping_rates)
.where( spree_shipping_rates: { shipping_method_id: @object } )
.first
return unless order
flash[:error] = I18n.t(:shipping_method_destroy_error, number: order.number)
redirect_to(collection_url) && return
end
private
def load_hubs
@hubs = Enterprise.managed_by(spree_current_user).is_distributor.sort_by!{ |d| [(@shipping_method.has_distributor? d) ? 0 : 1, d.name] }
# rubocop:disable Style/TernaryParentheses
@hubs = Enterprise.managed_by(spree_current_user).is_distributor.sort_by! do |d|
[(@shipping_method.has_distributor? d) ? 0 : 1, d.name]
end
# rubocop:enable Style/TernaryParentheses
end
end
end

View File

@@ -22,11 +22,11 @@ Spree::Admin::VariantsController.class_eval do
def destroy
@variant = Spree::Variant.find(params[:id])
if VariantDeleter.new.delete(@variant) # This line changed
flash[:success] = Spree.t('notice_messages.variant_deleted')
else
flash[:success] = Spree.t('notice_messages.variant_not_deleted')
end
flash[:success] = if VariantDeleter.new.delete(@variant) # This line changed
Spree.t('notice_messages.variant_deleted')
else
Spree.t('notice_messages.variant_not_deleted')
end
respond_with(@variant) do |format|
format.html { redirect_to admin_product_variants_url(params[:product_id]) }
@@ -34,12 +34,11 @@ Spree::Admin::VariantsController.class_eval do
end
end
protected
def create_before
option_values = params[:new_variant]
option_values.andand.each_value {|id| @object.option_values << OptionValue.find(id)}
option_values.andand.each_value { |id| @object.option_values << OptionValue.find(id) }
@object.save
end
end

View File

@@ -34,7 +34,7 @@ Spree::Api::ProductsController.class_eval do
@product = find_product(params[:product_id])
authorize! :delete, @product
@product.destroy
respond_with(@product, :status => 204)
respond_with(@product, status: 204)
end
# POST /api/products/:product_id/clone

View File

@@ -1,7 +1,6 @@
require 'open_food_network/address_finder'
Spree::CheckoutController.class_eval do
include CheckoutHelper
before_filter :enable_embedded_shopfront

View File

@@ -39,14 +39,14 @@ Spree::OrdersController.class_eval do
@order = order_to_update
unless @order
flash[:error] = t(:order_not_found)
redirect_to root_path and return
redirect_to(root_path) && return
end
if @order.update_attributes(params[:order])
discard_empty_line_items
with_open_adjustments { update_totals_and_taxes }
render :edit and return unless apply_coupon_code
render(:edit) && return unless apply_coupon_code
if @order == current_order
fire_event('spree.order.contents_changed')
@@ -56,7 +56,7 @@ Spree::OrdersController.class_eval do
respond_with(@order) do |format|
format.html do
if params.has_key?(:checkout)
if params.key?(:checkout)
@order.next_transition.run_callbacks if @order.cart?
redirect_to checkout_state_path(@order.checkout_steps.first)
elsif @order.complete?
@@ -95,13 +95,13 @@ Spree::OrdersController.class_eval do
end
def filter_order_params
if params[:order] and params[:order][:line_items_attributes]
if params[:order] && params[:order][:line_items_attributes]
params[:order][:line_items_attributes] = remove_missing_line_items(params[:order][:line_items_attributes])
end
end
def remove_missing_line_items(attrs)
attrs.select do |i, line_item|
attrs.select do |_i, line_item|
Spree::LineItem.find_by_id(line_item[:id])
end
end
@@ -129,7 +129,6 @@ Spree::OrdersController.class_eval do
redirect_to request.referer || order_path(@order)
end
private
# Updates the various denormalized total attributes of the order and
@@ -185,7 +184,7 @@ Spree::OrdersController.class_eval do
return unless order_to_update.andand.complete?
items = params[:order][:line_items_attributes]
.andand.select{ |k,attrs| attrs["quantity"].to_i > 0 }
.andand.select{ |_k, attrs| attrs["quantity"].to_i > 0 }
if items.empty?
flash[:error] = I18n.t(:orders_cannot_remove_the_final_item)

View File

@@ -4,7 +4,7 @@ Spree::PaypalController.class_eval do
after_filter :reset_order_when_complete, only: :confirm
def cancel
flash[:notice] = Spree.t('flash.cancel', :scope => 'paypal')
flash[:notice] = Spree.t('flash.cancel', scope: 'paypal')
redirect_to main_app.checkout_path
end

View File

@@ -5,6 +5,6 @@ class Spree::StoreController
before_filter :set_locale
def unauthorized
render 'shared/unauthorized', :status => 401
render 'shared/unauthorized', status: :unauthorized
end
end

View File

@@ -15,7 +15,7 @@ module Stripe
end
redirect_to main_app.edit_admin_enterprise_path(connector.enterprise, anchor: 'payment_methods')
rescue Stripe::StripeError => e
render text: e.message, status: 500
render text: e.message, status: :internal_server_error
end
end
end

View File

@@ -20,9 +20,9 @@ module Stripe
signature = request.headers["HTTP_STRIPE_SIGNATURE"]
@event = Webhook.construct_event(payload, signature, Stripe.endpoint_secret)
rescue JSON::ParserError
render nothing: true, status: 400
render nothing: true, status: :bad_request
rescue Stripe::SignatureVerificationError
render nothing: true, status: 401
render nothing: true, status: :unauthorized
end
# Stripe interprets a 4xx or 3xx response as a failure to receive the webhook,

View File

@@ -1,5 +1,6 @@
class UserConfirmationsController < DeviseController
include Spree::Core::ControllerHelpers::Auth # Needed for access to current_ability, so we can authorize! actions
# Needed for access to current_ability, so we can authorize! actions
include Spree::Core::ControllerHelpers::Auth
# GET /resource/confirmation/new
def new
@@ -44,7 +45,9 @@ class UserConfirmationsController < DeviseController
end
if resource.reset_password_token.present?
return spree.edit_spree_user_password_path(reset_password_token: resource.reset_password_token)
return spree.edit_spree_user_password_path(
reset_password_token: resource.reset_password_token
)
end
path = (session[:confirmation_return_url] || login_path).to_s

View File

@@ -10,7 +10,7 @@ class UserPasswordsController < Spree::UserPasswordsController
if resource.errors.empty?
set_flash_message(:success, :send_instructions) if is_navigational_format?
respond_with resource, :location => spree.login_path
respond_with resource, location: spree.login_path
else
respond_to do |format|
format.html do

View File

@@ -33,31 +33,31 @@ module Admin
admin_inject_json_ams "admin.shippingMethods", "shippingMethod", @shipping_method, Api::Admin::ShippingMethodSerializer
end
def admin_inject_shops(opts={})
def admin_inject_shops(opts = {})
opts.reverse_merge!(module: 'admin.customers')
admin_inject_json_ams_array opts[:module], "shops", @shops, Api::Admin::IdNameSerializer
end
def admin_inject_available_countries(opts={})
def admin_inject_available_countries(opts = {})
opts.reverse_merge!(module: 'admin.customers')
admin_inject_json_ams_array opts[:module], 'availableCountries', available_countries, Api::CountrySerializer
end
def admin_inject_hubs(opts={})
def admin_inject_hubs(opts = {})
opts.reverse_merge!(module: 'ofn.admin')
admin_inject_json_ams_array opts[:module], "hubs", @hubs, Api::Admin::IdNameSerializer
end
def admin_inject_producers(opts={})
def admin_inject_producers(opts = {})
opts.reverse_merge!(module: 'ofn.admin')
admin_inject_json_ams_array opts[:module], "producers", @producers, Api::Admin::IdNameSerializer
end
def admin_inject_inventory_items(opts={module: 'ofn.admin'})
def admin_inject_inventory_items(opts = { module: 'ofn.admin' })
admin_inject_json_ams_array opts[:module], "inventoryItems", @inventory_items, Api::Admin::InventoryItemSerializer
end
def admin_inject_column_preferences(opts={})
def admin_inject_column_preferences(opts = {})
opts.reverse_merge!(module: 'ofn.admin', action: "#{controller_name}_#{action_name}")
column_preferences = ColumnPreference.for(spree_current_user, opts[:action])
admin_inject_json_ams_array opts[:module], "columns", column_preferences, Api::Admin::ColumnPreferenceSerializer
@@ -69,22 +69,22 @@ module Admin
def admin_inject_enterprise_permissions
permissions =
{can_manage_shipping_methods: can?(:manage_shipping_methods, @enterprise),
can_manage_payment_methods: can?(:manage_payment_methods, @enterprise),
can_manage_enterprise_fees: can?(:manage_enterprise_fees, @enterprise)}
{ can_manage_shipping_methods: can?(:manage_shipping_methods, @enterprise),
can_manage_payment_methods: can?(:manage_payment_methods, @enterprise),
can_manage_enterprise_fees: can?(:manage_enterprise_fees, @enterprise) }
admin_inject_json "admin.enterprises", "enterprisePermissions", permissions
end
def admin_inject_hub_permissions
render partial: "admin/json/injection_ams", locals: {ngModule: "admin.variantOverrides", name: "hubPermissions", json: @hub_permissions.to_json}
render partial: "admin/json/injection_ams", locals: { ngModule: "admin.variantOverrides", name: "hubPermissions", json: @hub_permissions.to_json }
end
def admin_inject_products
admin_inject_json_ams_array "ofn.admin", "products", @products, Api::Admin::ProductSerializer
end
def admin_inject_tax_categories(opts={module: 'ofn.admin'})
def admin_inject_tax_categories(opts = { module: 'ofn.admin' })
admin_inject_json_ams_array opts[:module], "tax_categories", @tax_categories, Api::Admin::TaxCategorySerializer
end
@@ -101,7 +101,7 @@ module Admin
end
def admin_inject_order_cycle_instance
render partial: "admin/json/injection_ams", locals: {ngModule: 'admin.orderCycles', name: 'ocInstance', json: "{coordinator_id: '#{@order_cycle.coordinator.id}'}"}
render partial: "admin/json/injection_ams", locals: { ngModule: 'admin.orderCycles', name: 'ocInstance', json: "{coordinator_id: '#{@order_cycle.coordinator.id}'}" }
end
def admin_inject_order_cycles
@@ -109,22 +109,22 @@ module Admin
end
def admin_inject_spree_api_key
render partial: "admin/json/injection_ams", locals: {ngModule: 'admin.indexUtils', name: 'SpreeApiKey', json: "'#{@spree_api_key.to_s}'"}
render partial: "admin/json/injection_ams", locals: { ngModule: 'admin.indexUtils', name: 'SpreeApiKey', json: "'#{@spree_api_key}'" }
end
def admin_inject_json(ngModule, name, data)
json = data.to_json
render partial: "admin/json/injection_ams", locals: {ngModule: ngModule, name: name, json: json}
render partial: "admin/json/injection_ams", locals: { ngModule: ngModule, name: name, json: json }
end
def admin_inject_json_ams(ngModule, name, data, serializer, opts = {})
json = serializer.new(data, {scope: spree_current_user}.merge(opts)).to_json
render partial: "admin/json/injection_ams", locals: {ngModule: ngModule, name: name, json: json}
json = serializer.new(data, { scope: spree_current_user }.merge(opts)).to_json
render partial: "admin/json/injection_ams", locals: { ngModule: ngModule, name: name, json: json }
end
def admin_inject_json_ams_array(ngModule, name, data, serializer, opts = {})
json = ActiveModel::ArraySerializer.new(data, {each_serializer: serializer, scope: spree_current_user}.merge(opts)).to_json
render partial: "admin/json/injection_ams", locals: {ngModule: ngModule, name: name, json: json}
json = ActiveModel::ArraySerializer.new(data, { each_serializer: serializer, scope: spree_current_user }.merge(opts)).to_json
render partial: "admin/json/injection_ams", locals: { ngModule: ngModule, name: name, json: json }
end
end
end

View File

@@ -5,8 +5,8 @@ module Admin
# We exclude shipping method adjustments because they are displayed in a
# separate table together with the order line items.
def order_adjustments_for_display(order)
order.adjustments.eligible.select do |adjustment|
adjustment.originator_type != "Spree::ShippingMethod"
order.adjustments.eligible.reject do |adjustment|
adjustment.originator_type == "Spree::ShippingMethod"
end
end
end

View File

@@ -1,32 +1,32 @@
class AngularFormBuilder < ActionView::Helpers::FormBuilder
def ng_fields_for(record_name, *args, &block)
def ng_fields_for(record_name, *_args)
raise "Nested ng_fields_for is not yet supported" if @fields_for_record_name.present?
@fields_for_record_name = record_name
block.call self
yield self
@fields_for_record_name = nil
end
def ng_text_field(method, options = {})
value = "{{ #{angular_model(method)} }}"
options.reverse_merge!({'id' => angular_id(method)})
options.reverse_merge!('id' => angular_id(method))
@template.text_field_tag angular_name(method), value, options
end
def ng_hidden_field(method, options = {})
def ng_hidden_field(method, _options = {})
value = "{{ #{angular_model(method)} }}"
@template.hidden_field_tag angular_name(method), value, :id => angular_id(method)
@template.hidden_field_tag angular_name(method), value, id: angular_id(method)
end
def ng_select(method, choices, angular_field, options = {})
options.reverse_merge!({'id' => angular_id(method), 'ng-model' => "#{angular_model(method)}"})
options.reverse_merge!('id' => angular_id(method), 'ng-model' => angular_model(method).to_s)
@template.select_tag angular_name(method), @template.ng_options_for_select(choices, angular_field), options
end
def ng_collection_select(method, collection, value_method, text_method, angular_field, options = {})
options.reverse_merge!({'id' => angular_id(method), 'ng-model' => "#{angular_model(method)}"})
options.reverse_merge!('id' => angular_id(method), 'ng-model' => angular_model(method).to_s)
@template.select_tag angular_name(method), @template.ng_options_from_collection_for_select(collection, value_method, text_method, angular_field), options
end

View File

@@ -1,10 +1,10 @@
module AngularFormHelper
def ng_options_for_select(container, angular_field=nil)
def ng_options_for_select(container, _angular_field = nil)
return container if String === container
container.map do |element|
html_attributes = option_html_attributes(element)
text, value = option_text_and_value(element).map { |item| item.to_s }
text, value = option_text_and_value(element).map(&:to_s)
%(<option value="#{ERB::Util.html_escape(value)}"#{html_attributes}>#{ERB::Util.html_escape(text)}</option>)
end.join("\n").html_safe
end
@@ -18,7 +18,6 @@ module AngularFormHelper
end
end
class ActionView::Helpers::InstanceTag
include AngularFormHelper
end

View File

@@ -8,13 +8,13 @@ module ApplicationHelper
def ng_form_for(name, *args, &block)
options = args.extract_options!
form_for(name, *(args << options.merge(:builder => AngularFormBuilder)), &block)
form_for(name, *(args << options.merge(builder: AngularFormBuilder)), &block)
end
# Pass URL helper calls on to spree where applicable so that we don't need to use
# spree.foo_path in any view rendered from non-spree-namespaced controllers.
def method_missing(method, *args, &block)
if (method.to_s.end_with?('_path') || method.to_s.end_with?('_url')) && spree.respond_to?(method)
if method.to_s.end_with?('_path', '_url') && spree.respond_to?(method)
spree.public_send(method, *args)
else
super

View File

@@ -3,7 +3,7 @@ module CheckoutHelper
current_order.distributor.allow_guest_orders?
end
def checkout_adjustments_for(order, opts={})
def checkout_adjustments_for(order, opts = {})
adjustments = order.adjustments.eligible
exclude = opts[:exclude] || {}
@@ -24,7 +24,7 @@ module CheckoutHelper
def display_checkout_admin_and_handling_adjustments_total_for(order)
adjustments = order.adjustments.eligible.where('originator_type = ? AND source_type != ? ', 'EnterpriseFee', 'Spree::LineItem')
Spree::Money.new adjustments.sum(&:amount) , currency: order.currency
Spree::Money.new adjustments.sum(&:amount), currency: order.currency
end
def checkout_line_item_adjustments(order)
@@ -36,7 +36,7 @@ module CheckoutHelper
end
def display_checkout_subtotal(order)
Spree::Money.new checkout_subtotal(order) , currency: order.currency
Spree::Money.new checkout_subtotal(order), currency: order.currency
end
def display_checkout_tax_total(order)
@@ -44,22 +44,22 @@ module CheckoutHelper
end
def display_checkout_taxes_hash(order)
order.tax_adjustment_totals.each_with_object(Hash.new) do |(tax_rate, tax_amount), hash|
hash[number_to_percentage(tax_rate.amount * 100, :precision => 1)] = Spree::Money.new tax_amount, currency: order.currency
order.tax_adjustment_totals.each_with_object({}) do |(tax_rate, tax_amount), hash|
hash[number_to_percentage(tax_rate.amount * 100, precision: 1)] = Spree::Money.new tax_amount, currency: order.currency
end
end
def display_line_item_tax_rates(line_item)
line_item.tax_rates.map { |tr| number_to_percentage(tr.amount * 100, :precision => 1) }.join(", ")
line_item.tax_rates.map { |tr| number_to_percentage(tr.amount * 100, precision: 1) }.join(", ")
end
def display_adjustment_tax_rates(adjustment)
tax_rates = TaxRateFinder.tax_rates_of(adjustment)
tax_rates.map { |tr| number_to_percentage(tr.amount * 100, :precision => 1) }.join(", ")
tax_rates.map { |tr| number_to_percentage(tr.amount * 100, precision: 1) }.join(", ")
end
def display_adjustment_amount(adjustment)
Spree::Money.new(adjustment.amount, { :currency => adjustment.currency })
Spree::Money.new(adjustment.amount, currency: adjustment.currency)
end
def display_checkout_total_less_tax(order)
@@ -68,10 +68,10 @@ module CheckoutHelper
def validated_input(name, path, args = {})
attributes = {
required: true,
type: :text,
name: path,
id: path,
:required => true,
:type => :text,
:name => path,
:id => path,
"ng-model" => path,
"ng-class" => "{error: !fieldValid('#{path}')}"
}.merge args
@@ -81,8 +81,8 @@ module CheckoutHelper
def validated_select(name, path, options, args = {})
attributes = {
required: true,
id: path,
:required => true,
:id => path,
"ng-model" => path,
"ng-class" => "{error: !fieldValid('#{path}')}"
}.merge args

View File

@@ -16,10 +16,10 @@ module DiscourseHelper
end
def discourse_url!
discourse_url or raise 'Missing Discourse URL'
discourse_url || raise('Missing Discourse URL')
end
def discourse_sso_secret!
ENV['DISCOURSE_SSO_SECRET'] or raise 'Missing SSO secret'
ENV['DISCOURSE_SSO_SECRET'] || raise('Missing SSO secret')
end
end

View File

@@ -11,7 +11,7 @@ module EnterprisesHelper
end
def available_shipping_methods
return [] unless current_distributor.present?
return [] if current_distributor.blank?
shipping_methods = current_distributor.shipping_methods
applicator = OpenFoodNetwork::TagRuleApplicator.new(current_distributor, "FilterShippingMethods", current_customer.andand.tag_list)
@@ -21,7 +21,7 @@ module EnterprisesHelper
end
def available_payment_methods
return [] unless current_distributor.present?
return [] if current_distributor.blank?
payment_methods = current_distributor.payment_methods.available(:front_end).all
filter = OpenFoodNetwork::AvailablePaymentMethodFilter.new
@@ -43,7 +43,7 @@ module EnterprisesHelper
order('is_primary_producer ASC, name')
end
def enterprises_options enterprises
def enterprises_options(enterprises)
enterprises.map { |enterprise| [enterprise.name + ": " + enterprise.address.address1 + ", " + enterprise.address.city, enterprise.id.to_i] }
end
@@ -74,7 +74,7 @@ module EnterprisesHelper
name = t(:delete)
options = {}
options[:class] = "delete-resource"
options[:data] = { :action => 'remove', :confirm => enterprise_confirm_delete_message(enterprise) }
options[:data] = { action: 'remove', confirm: enterprise_confirm_delete_message(enterprise) }
link_to_with_icon 'icon-trash', name, url, options
end

View File

@@ -36,12 +36,12 @@ module InjectionHelper
def inject_available_shipping_methods
inject_json_ams "shippingMethods", available_shipping_methods,
Api::ShippingMethodSerializer, current_order: current_order
Api::ShippingMethodSerializer, current_order: current_order
end
def inject_available_payment_methods
inject_json_ams "paymentMethods", available_payment_methods,
Api::PaymentMethodSerializer, current_order: current_order
Api::PaymentMethodSerializer, current_order: current_order
end
def inject_taxons
@@ -57,7 +57,7 @@ module InjectionHelper
end
def inject_spree_api_key
render partial: "json/injection_ams", locals: {name: 'spreeApiKey', json: "'#{@spree_api_key.to_s}'"}
render partial: "json/injection_ams", locals: { name: 'spreeApiKey', json: "'#{@spree_api_key}'" }
end
def inject_available_countries
@@ -65,7 +65,7 @@ module InjectionHelper
end
def inject_enterprise_attributes
render partial: "json/injection_ams", locals: {name: 'enterpriseAttributes', json: "#{@enterprise_attributes.to_json}"}
render partial: "json/injection_ams", locals: { name: 'enterpriseAttributes', json: @enterprise_attributes.to_json.to_s }
end
def inject_orders
@@ -89,7 +89,7 @@ module InjectionHelper
end
def inject_json(name, partial, opts = {})
render partial: "json/injection", locals: {name: name, partial: partial}.merge(opts)
render partial: "json/injection", locals: { name: name, partial: partial }.merge(opts)
end
def inject_json_ams(name, data, serializer, opts = {})
@@ -100,14 +100,13 @@ module InjectionHelper
serializer_instance = serializer.new(data, opts)
json = serializer_instance.to_json
render partial: "json/injection_ams", locals: {name: name, json: json}
render partial: "json/injection_ams", locals: { name: name, json: json }
end
private
def enterprise_injection_data
@enterprise_injection_data ||= OpenFoodNetwork::EnterpriseInjectionData.new
{data: @enterprise_injection_data}
{ data: @enterprise_injection_data }
end
end

View File

@@ -15,7 +15,7 @@ module OrderCyclesHelper
validated_enterprise_options permitted_producer_enterprises_for(order_cycle)
end
def permitted_coordinating_enterprises_for(order_cycle)
def permitted_coordinating_enterprises_for(_order_cycle)
Enterprise.managed_by(spree_current_user).is_distributor.by_name
end
@@ -54,7 +54,7 @@ module OrderCyclesHelper
distance_of_time_in_words_to_now(orders_close_at)]
end
def active_order_cycle_for_distributor?(distributor)
def active_order_cycle_for_distributor?(_distributor)
OrderCycle.active.with_distributor(@distributor).present?
end
@@ -80,7 +80,7 @@ module OrderCyclesHelper
private
def validated_enterprise_options(enterprises, options={})
def validated_enterprise_options(enterprises, options = {})
enterprises.map do |e|
disabled_message = nil
if options[:shipping_and_payment_methods] && (e.shipping_methods.empty? || e.payment_methods.available.empty?)
@@ -94,7 +94,7 @@ module OrderCyclesHelper
end
if disabled_message
["#{e.name} (#{disabled_message})", e.id, {disabled: true}]
["#{e.name} (#{disabled_message})", e.id, { disabled: true }]
else
[e.name, e.id]
end

View File

@@ -1,6 +1,6 @@
module SerializerHelper
def ids_to_objs(ids)
return [] if ids.blank?
ids.map { |id| {id: id} }
ids.map { |id| { id: id } }
end
end

View File

@@ -10,14 +10,13 @@ module Spree
end
alias_method_chain :preference_field_tag, :files
# Add support for options[:html], allowing additional HTML attributes
def link_to_remove_fields(name, f, options = {})
name = '' if options[:no_text]
options[:class] = '' unless options[:class]
options[:class] += 'no-text with-tip' if options[:no_text]
html_options = {class: "remove_fields #{options[:class]}", data: {action: 'remove'}, title: t(:remove)}
html_options = { class: "remove_fields #{options[:class]}", data: { action: 'remove' }, title: t(:remove) }
html_options.merge!(options[:html]) if options.key? :html
link_to_with_icon('icon-trash', name, '#', html_options) + f.hidden_field(:_destroy)

View File

@@ -5,9 +5,7 @@ module Spree
def klass_for(name)
model_name = name.to_s
["Spree::#{model_name.classify}", model_name.classify, model_name.gsub('_', '/').classify].find do |t|
t.safe_constantize
end.try(:safe_constantize)
["Spree::#{model_name.classify}", model_name.classify, model_name.tr('_', '/').classify].find(&:safe_constantize).try(:safe_constantize)
end
# Make it so that the Reports admin tab can be enabled/disabled through the cancan
@@ -27,11 +25,11 @@ module Spree
# TEMP: override method until it is fixed in Spree.
def tab_with_cancan_check(*args)
options = {:label => args.first.to_s}
options = { label: args.first.to_s }
if args.last.is_a?(Hash)
options = options.merge(args.last)
end
return '' if klass = klass_for(options[:label]) and cannot?(:admin, klass)
return '' if (klass = klass_for(options[:label])) && cannot?(:admin, klass)
tab_without_cancan_check(*args)
end
alias_method_chain :tab, :cancan_check

View File

@@ -18,9 +18,9 @@ module Spree
end
end
if @order.ready_to_ship?
links << { name: t(:ship_order), url: fire_admin_order_path(@order, :e => 'ship'), method: 'put', icon: 'icon-truck', confirm: t(:are_you_sure) }
links << { name: t(:ship_order), url: fire_admin_order_path(@order, e: 'ship'), method: 'put', icon: 'icon-truck', confirm: t(:are_you_sure) }
end
links << { name: t(:cancel_order), url: fire_admin_order_path(@order.number, { :e => 'cancel' }), icon: 'icon-trash', confirm: t(:are_you_sure) } if order.can_cancel?
links << { name: t(:cancel_order), url: fire_admin_order_path(@order.number, e: 'cancel'), icon: 'icon-trash', confirm: t(:are_you_sure) } if order.can_cancel?
links
end
end

View File

@@ -2,7 +2,7 @@ module Spree
module BaseHelper
# human readable list of variant options
# Override: Do not show out of stock text
def variant_options(v, options={})
def variant_options(v, _options = {})
v.options_text
end
end

View File

@@ -22,7 +22,8 @@ module Spree
state: 'complete',
user_id: spree_current_user.id,
distributor_id: current_distributor.id,
order_cycle_id: current_order_cycle.id)
order_cycle_id: current_order_cycle.id
)
end
def changeable_orders_link_path

View File

@@ -3,7 +3,7 @@ module Spree
# Return the price of the variant, overriding sprees price diff capability.
# This will allways return the variant price as if the show_variant_full_price is set.
def variant_price_diff(variant)
"(#{Spree::Money.new(variant.price).to_s})"
"(#{Spree::Money.new(variant.price)})"
end
def product_has_variant_unit_option_type?(product)

View File

@@ -6,7 +6,7 @@ module Spree
order_cycles.map do |oc|
orders_open_at = oc.orders_open_at.andand.to_s(:short) || 'NA'
orders_close_at = oc.orders_close_at.andand.to_s(:short) || 'NA'
[ "#{oc.name} &nbsp; (#{orders_open_at} - #{orders_close_at})".html_safe, oc.id ]
["#{oc.name} &nbsp; (#{orders_open_at} - #{orders_close_at})".html_safe, oc.id]
end
end

View File

@@ -14,7 +14,6 @@ ProductsCacheIntegrityCheckerJob = Struct.new(:distributor_id, :order_cycle_id)
end
end
private
def checker

View File

@@ -9,9 +9,9 @@ class EnterpriseMailer < Spree::BaseMailer
subject = t('enterprise_mailer.welcome.subject',
enterprise: @enterprise.name,
sitename: Spree::Config[:site_name])
mail(:to => enterprise.contact.email,
:from => from_address,
:subject => subject)
mail(to: enterprise.contact.email,
from: from_address,
subject: subject)
end
end

View File

@@ -9,6 +9,6 @@ Spree::BaseMailer.class_eval do
def roadie_options
# This lets us specify assets using relative paths in email templates
super.merge(url_options: {host: URI(spree.root_url).host })
super.merge(url_options: { host: URI(spree.root_url).host })
end
end

View File

@@ -17,10 +17,10 @@ Spree::OrderMailer.class_eval do
@order = find_order(order_or_order_id)
I18n.with_locale valid_locale(@order.user) do
subject = mail_subject(t('spree.order_mailer.confirm_email.subject'), resend)
mail(:to => @order.email,
:from => from_address,
:subject => subject,
:reply_to => @order.distributor.contact.email)
mail(to: @order.email,
from: from_address,
subject: subject,
reply_to: @order.distributor.contact.email)
end
end
@@ -28,9 +28,9 @@ Spree::OrderMailer.class_eval do
@order = find_order(order_or_order_id)
I18n.with_locale valid_locale(@order.user) do
subject = mail_subject(t('spree.order_mailer.confirm_email.subject'), resend)
mail(:to => @order.distributor.contact.email,
:from => from_address,
:subject => subject)
mail(to: @order.distributor.contact.email,
from: from_address,
subject: subject)
end
end

View File

@@ -4,8 +4,8 @@ Spree::UserMailer.class_eval do
def signup_confirmation(user)
@user = user
I18n.with_locale valid_locale(@user) do
mail(:to => user.email, :from => from_address,
:subject => t(:welcome_to) + Spree::Config[:site_name])
mail(to: user.email, from: from_address,
subject: t(:welcome_to) + Spree::Config[:site_name])
end
end

View File

@@ -9,7 +9,7 @@ class Calculator::FlatPercentPerItem < Spree::Calculator
# item level first, then multiply by the item quantity.
extend Spree::LocalizedNumber
preference :flat_percent, :decimal, :default => 0
preference :flat_percent, :decimal, default: 0
attr_accessible :preferred_flat_percent
@@ -25,7 +25,7 @@ class Calculator::FlatPercentPerItem < Spree::Calculator
raise ArgumentError, "object must respond to #price and #quantity"
end
value = (li.price * BigDecimal(self.preferred_flat_percent.to_s) / 100.0).round(2)
value = (li.price * BigDecimal(preferred_flat_percent.to_s) / 100.0).round(2)
value * li.quantity
end
end

View File

@@ -25,7 +25,7 @@ class ColumnPreference < ActiveRecord::Base
default_preferences.each_with_object([]) do |(column_name, default_attributes), preferences|
stored_preference = stored_preferences.find_by_column_name(column_name)
if stored_preference
stored_preference.assign_attributes(default_attributes.select{ |k,v| stored_preference[k].nil? })
stored_preference.assign_attributes(default_attributes.select{ |k, _v| stored_preference[k].nil? })
preferences << stored_preference
else
attributes = default_attributes.merge(user_id: user.id, action_name: action_name, column_name: column_name)
@@ -42,7 +42,7 @@ class ColumnPreference < ActiveRecord::Base
def self.known_actions
OpenFoodNetwork::ColumnPreferenceDefaults.private_instance_methods
.select{|m| m.to_s.end_with?("_columns")}.map{ |m| m.to_s.sub /_columns$/, ''}
.select{ |m| m.to_s.end_with?("_columns") }.map{ |m| m.to_s.sub /_columns$/, '' }
end
# Arbitrary filtering of default_preferences

View File

@@ -1,5 +1,5 @@
class ColumnPreferenceSet < ModelSet
def initialize(collection, attributes={})
def initialize(collection, attributes = {})
super(ColumnPreference, collection, attributes, nil, nil )
end
end

View File

@@ -36,7 +36,7 @@ module OrderShipment
shipping_rate = shipment.shipping_rates.find_by_shipping_method_id(shipping_method_id)
return unless shipping_rate
shipment.selected_shipping_rate_id=(shipping_rate.id)
shipment.selected_shipping_rate_id = shipping_rate.id
shipment.shipping_method
end
end

View File

@@ -54,7 +54,7 @@ class ContentConfiguration < Spree::Preferences::FileConfiguration
preference :footer_logo, :file
has_attached_file :footer_logo, default_url: "/assets/ofn-logo-footer.png"
#Other
# Other
preference :footer_facebook_url, :string, default: "https://www.facebook.com/OpenFoodNet"
preference :footer_twitter_url, :string, default: "https://twitter.com/OpenFoodNet"
preference :footer_instagram_url, :string, default: ""
@@ -69,10 +69,10 @@ class ContentConfiguration < Spree::Preferences::FileConfiguration
[News](/)
[Calendar](/)
EOS
EOS
preference :footer_about_url, :string, default: "http://www.openfoodnetwork.org/ofn-local/open-food-network-australia/"
#User Guide
# User Guide
preference :user_guide_link, :string, default: 'https://guide.openfoodnetwork.org/'
end

View File

@@ -5,11 +5,9 @@ class CoordinatorFee < ActiveRecord::Base
after_save :refresh_products_cache
after_destroy :refresh_products_cache
private
def refresh_products_cache
order_cycle.refresh_products_cache
end
end

View File

@@ -1,5 +1,5 @@
class DistributorShippingMethod < ActiveRecord::Base
self.table_name = "distributors_shipping_methods"
self.table_name = "distributors_shipping_methods"
belongs_to :shipping_method, class_name: Spree::ShippingMethod
belongs_to :distributor, class_name: Enterprise, touch: true
end

View File

@@ -1,5 +1,5 @@
class Enterprise < ActiveRecord::Base
SELLS = %w(unspecified none own any)
SELLS = %w(unspecified none own any).freeze
ENTERPRISE_SEARCH_RADIUS = 100
preference :shopfront_message, :text, default: ""
@@ -17,18 +17,18 @@ class Enterprise < ActiveRecord::Base
self.inheritance_column = nil
acts_as_gmappable :process_geocoding => false
acts_as_gmappable process_geocoding: false
has_many :relationships_as_parent, class_name: 'EnterpriseRelationship', foreign_key: 'parent_id', dependent: :destroy
has_many :relationships_as_child, class_name: 'EnterpriseRelationship', foreign_key: 'child_id', dependent: :destroy
has_and_belongs_to_many :groups, class_name: 'EnterpriseGroup'
has_many :producer_properties, foreign_key: 'producer_id'
has_many :properties, through: :producer_properties
has_many :supplied_products, :class_name => 'Spree::Product', :foreign_key => 'supplier_id', :dependent => :destroy
has_many :distributed_orders, :class_name => 'Spree::Order', :foreign_key => 'distributor_id'
belongs_to :address, :class_name => 'Spree::Address'
has_many :supplied_products, class_name: 'Spree::Product', foreign_key: 'supplier_id', dependent: :destroy
has_many :distributed_orders, class_name: 'Spree::Order', foreign_key: 'distributor_id'
belongs_to :address, class_name: 'Spree::Address'
has_many :enterprise_fees
has_many :enterprise_roles, :dependent => :destroy
has_many :enterprise_roles, dependent: :destroy
has_many :users, through: :enterprise_roles
belongs_to :owner, class_name: 'Spree::User', foreign_key: :owner_id, inverse_of: :owned_enterprises
has_and_belongs_to_many :payment_methods, join_table: 'distributors_payment_methods', class_name: 'Spree::PaymentMethod', foreign_key: 'distributor_id'
@@ -39,24 +39,24 @@ class Enterprise < ActiveRecord::Base
has_many :tag_rules
has_one :stripe_account, dependent: :destroy
delegate :latitude, :longitude, :city, :state_name, :to => :address
delegate :latitude, :longitude, :city, :state_name, to: :address
accepts_nested_attributes_for :address
accepts_nested_attributes_for :producer_properties, allow_destroy: true, reject_if: lambda { |pp| pp[:property_name].blank? }
accepts_nested_attributes_for :tag_rules, allow_destroy: true, reject_if: lambda { |tag_rule| tag_rule[:preferred_customer_tags].blank? }
has_attached_file :logo,
styles: { medium: "300x300>", small: "180x180>", thumb: "100x100>" },
url: '/images/enterprises/logos/:id/:style/:basename.:extension',
path: 'public/images/enterprises/logos/:id/:style/:basename.:extension'
styles: { medium: "300x300>", small: "180x180>", thumb: "100x100>" },
url: '/images/enterprises/logos/:id/:style/:basename.:extension',
path: 'public/images/enterprises/logos/:id/:style/:basename.:extension'
has_attached_file :promo_image,
styles: { large: ["1200x260#", :jpg], medium: ["720x156#", :jpg], thumb: ["100x100>", :jpg] },
url: '/images/enterprises/promo_images/:id/:style/:basename.:extension',
path: 'public/images/enterprises/promo_images/:id/:style/:basename.:extension'
styles: { large: ["1200x260#", :jpg], medium: ["720x156#", :jpg], thumb: ["100x100>", :jpg] },
url: '/images/enterprises/promo_images/:id/:style/:basename.:extension',
path: 'public/images/enterprises/promo_images/:id/:style/:basename.:extension'
validates_attachment_content_type :logo, :content_type => /\Aimage\/.*\Z/
validates_attachment_content_type :promo_image, :content_type => /\Aimage\/.*\Z/
validates_attachment_content_type :logo, content_type: /\Aimage\/.*\Z/
validates_attachment_content_type :promo_image, content_type: /\Aimage\/.*\Z/
include Spree::Core::S3Support
supports_s3 :logo
@@ -64,13 +64,13 @@ class Enterprise < ActiveRecord::Base
validates :name, presence: true
validate :name_is_unique
validates :sells, presence: true, inclusion: {in: SELLS}
validates :sells, presence: true, inclusion: { in: SELLS }
validates :address, presence: true, associated: true
validates_presence_of :owner
validates :owner, presence: true
validates :permalink, uniqueness: true, presence: true
validate :shopfront_taxons
validate :enforce_ownership_limit, if: lambda { owner_id_changed? && !owner_id.nil? }
validates_length_of :description, :maximum => 255
validates :description, length: { maximum: 255 }
before_validation :initialize_permalink, if: lambda { permalink.nil? }
before_validation :ensure_owner_is_manager, if: lambda { owner_id_changed? && !owner_id.nil? }
@@ -103,29 +103,29 @@ class Enterprise < ActiveRecord::Base
where("TRUE")
end
}
scope :is_primary_producer, where(:is_primary_producer => true)
scope :is_primary_producer, where(is_primary_producer: true)
scope :is_distributor, where('sells != ?', 'none')
scope :is_hub, where(sells: 'any')
scope :supplying_variant_in, lambda { |variants|
joins(:supplied_products => :variants_including_master).
joins(supplied_products: :variants_including_master).
where('spree_variants.id IN (?)', variants).
select('DISTINCT enterprises.*')
}
scope :with_order_cycles_as_supplier_outer,
joins("LEFT OUTER JOIN exchanges ON (exchanges.sender_id = enterprises.id AND exchanges.incoming = 't')").
joins("LEFT OUTER JOIN exchanges ON (exchanges.sender_id = enterprises.id AND exchanges.incoming = 't')").
joins('LEFT OUTER JOIN order_cycles ON (order_cycles.id = exchanges.order_cycle_id)')
scope :with_order_cycles_as_distributor_outer,
joins("LEFT OUTER JOIN exchanges ON (exchanges.receiver_id = enterprises.id AND exchanges.incoming = 'f')").
joins("LEFT OUTER JOIN exchanges ON (exchanges.receiver_id = enterprises.id AND exchanges.incoming = 'f')").
joins('LEFT OUTER JOIN order_cycles ON (order_cycles.id = exchanges.order_cycle_id)')
scope :with_order_cycles_outer,
joins("LEFT OUTER JOIN exchanges ON (exchanges.receiver_id = enterprises.id OR exchanges.sender_id = enterprises.id)").
joins("LEFT OUTER JOIN exchanges ON (exchanges.receiver_id = enterprises.id OR exchanges.sender_id = enterprises.id)").
joins('LEFT OUTER JOIN order_cycles ON (order_cycles.id = exchanges.order_cycle_id)')
scope :with_order_cycles_and_exchange_variants_outer,
with_order_cycles_as_distributor_outer.
with_order_cycles_as_distributor_outer.
joins('LEFT OUTER JOIN exchange_variants ON (exchange_variants.exchange_id = exchanges.id)').
joins('LEFT OUTER JOIN spree_variants ON (spree_variants.id = exchange_variants.variant_id)')
@@ -171,7 +171,7 @@ class Enterprise < ActiveRecord::Base
end
def contact
contact = users.where(enterprise_roles: {receives_notifications: true}).first
contact = users.where(enterprise_roles: { receives_notifications: true }).first
contact || owner
end
@@ -202,7 +202,7 @@ class Enterprise < ActiveRecord::Base
(SELECT child_id FROM enterprise_relationships WHERE enterprise_relationships.parent_id=?)
OR enterprises.id IN
(SELECT parent_id FROM enterprise_relationships WHERE enterprise_relationships.child_id=?)
", self.id, self.id)
", id, id)
end
def plus_relatives_and_oc_producers(order_cycles)
@@ -215,23 +215,23 @@ class Enterprise < ActiveRecord::Base
end
def distributors
self.relatives_including_self.is_distributor
relatives_including_self.is_distributor
end
def suppliers
self.relatives_including_self.is_primary_producer
relatives_including_self.is_primary_producer
end
def website
strip_url read_attribute(:website)
strip_url self[:website]
end
def facebook
strip_url read_attribute(:facebook)
strip_url self[:facebook]
end
def linkedin
strip_url read_attribute(:linkedin)
strip_url self[:linkedin]
end
def inventory_variants
@@ -247,18 +247,18 @@ class Enterprise < ActiveRecord::Base
end
def is_distributor
self.sells != "none"
sells != "none"
end
def is_hub
self.sells == 'any'
sells == 'any'
end
# Simplify enterprise categories for frontend logic and icons, and maybe other things.
def category
# Make this crazy logic human readable so we can argue about it sanely.
cat = self.is_primary_producer ? "producer_" : "non_producer_"
cat << "sells_" + self.sells
cat = is_primary_producer ? "producer_" : "non_producer_"
cat << "sells_" + sells
# Map backend cases to front end cases.
case cat
@@ -301,15 +301,15 @@ class Enterprise < ActiveRecord::Base
test_permalink = test_permalink.parameterize
test_permalink = "my-enterprise" if test_permalink.blank?
existing = Enterprise.select(:permalink).order(:permalink).where("permalink LIKE ?", "#{test_permalink}%").map(&:permalink)
unless existing.include?(test_permalink)
test_permalink
else
if existing.include?(test_permalink)
used_indices = existing.map do |p|
p.slice!(/^#{test_permalink}/)
p.match(/^\d+$/).to_s.to_i
end.select{ |p| p }
options = (1..existing.length).to_a - used_indices
test_permalink + options.first.to_s
else
test_permalink
end
end
@@ -335,7 +335,7 @@ class Enterprise < ActiveRecord::Base
end
def send_welcome_email
Delayed::Job.enqueue WelcomeEnterpriseJob.new(self.id)
Delayed::Job.enqueue WelcomeEnterpriseJob.new(id)
end
def strip_url(url)
@@ -361,7 +361,7 @@ class Enterprise < ActiveRecord::Base
end
def set_default_contact
update_contact self.owner_id
update_contact owner_id
end
def relate_to_owners_enterprises
@@ -408,8 +408,8 @@ class Enterprise < ActiveRecord::Base
end
def touch_distributors
Enterprise.distributing_products(self.supplied_products).
where('enterprises.id != ?', self.id).
each(&:touch)
Enterprise.distributing_products(supplied_products).
where('enterprises.id != ?', id).
find_each(&:touch)
end
end

View File

@@ -10,20 +10,17 @@ class EnterpriseFee < ActiveRecord::Base
has_many :exchange_fees, dependent: :destroy
has_many :exchanges, through: :exchange_fees
after_save :refresh_products_cache
# After destroy, the products cache is refreshed via the after_destroy hook for
# coordinator_fees and exchange_fees
attr_accessible :enterprise_id, :fee_type, :name, :tax_category_id, :calculator_type, :inherits_tax_category
FEE_TYPES = %w(packing transport admin sales fundraising)
PER_ORDER_CALCULATORS = ['Spree::Calculator::FlatRate', 'Spree::Calculator::FlexiRate', 'Spree::Calculator::PriceSack']
FEE_TYPES = %w(packing transport admin sales fundraising).freeze
PER_ORDER_CALCULATORS = ['Spree::Calculator::FlatRate', 'Spree::Calculator::FlexiRate', 'Spree::Calculator::PriceSack'].freeze
validates_inclusion_of :fee_type, :in => FEE_TYPES
validates_presence_of :name
validates :fee_type, inclusion: { in: FEE_TYPES }
validates :name, presence: true
before_save :ensure_valid_tax_category_settings
@@ -49,7 +46,6 @@ class EnterpriseFee < ActiveRecord::Base
order.adjustments.where(originator_type: 'EnterpriseFee').destroy_all
end
private
def ensure_valid_tax_category_settings
@@ -61,7 +57,7 @@ class EnterpriseFee < ActiveRecord::Base
elsif inherits_tax_category_changed?
self.tax_category_id = nil if inherits_tax_category?
end
return true
true
end
def refresh_products_cache

View File

@@ -1,5 +1,5 @@
class EnterpriseFeeSet < ModelSet
def initialize(attributes={})
def initialize(attributes = {})
super(EnterpriseFee, EnterpriseFee.all,
attributes,
proc { |attrs| attrs[:name].blank? })

View File

@@ -7,7 +7,7 @@ class EnterpriseGroup < ActiveRecord::Base
has_and_belongs_to_many :enterprises
belongs_to :owner, class_name: 'Spree::User', foreign_key: :owner_id, inverse_of: :owned_groups
belongs_to :address, :class_name => 'Spree::Address'
belongs_to :address, class_name: 'Spree::Address'
accepts_nested_attributes_for :address
validates :address, presence: true, associated: true
before_validation :set_undefined_address_fields
@@ -28,20 +28,20 @@ class EnterpriseGroup < ActiveRecord::Base
attr_accessible :address_attributes
attr_accessible :email, :website, :facebook, :instagram, :linkedin, :twitter
delegate :phone, :address1, :address2, :city, :zipcode, :state, :country, :to => :address
delegate :phone, :address1, :address2, :city, :zipcode, :state, :country, to: :address
has_attached_file :logo,
styles: {medium: "100x100"},
url: '/images/enterprise_groups/logos/:id/:style/:basename.:extension',
path: 'public/images/enterprise_groups/logos/:id/:style/:basename.:extension'
styles: { medium: "100x100" },
url: '/images/enterprise_groups/logos/:id/:style/:basename.:extension',
path: 'public/images/enterprise_groups/logos/:id/:style/:basename.:extension'
has_attached_file :promo_image,
styles: {large: ["1200x260#", :jpg]},
url: '/images/enterprise_groups/promo_images/:id/:style/:basename.:extension',
path: 'public/images/enterprise_groups/promo_images/:id/:style/:basename.:extension'
styles: { large: ["1200x260#", :jpg] },
url: '/images/enterprise_groups/promo_images/:id/:style/:basename.:extension',
path: 'public/images/enterprise_groups/promo_images/:id/:style/:basename.:extension'
validates_attachment_content_type :logo, :content_type => /\Aimage\/.*\Z/
validates_attachment_content_type :promo_image, :content_type => /\Aimage\/.*\Z/
validates_attachment_content_type :logo, content_type: /\Aimage\/.*\Z/
validates_attachment_content_type :promo_image, content_type: /\Aimage\/.*\Z/
include Spree::Core::S3Support
supports_s3 :logo
@@ -70,7 +70,7 @@ class EnterpriseGroup < ActiveRecord::Base
end
def unset_undefined_address_fields
return unless address.present?
return if address.blank?
address.phone.sub!(/^#{I18n.t(:undefined)}$/, '')
address.address1.sub!(/^#{I18n.t(:undefined)}$/, '')
address.city.sub!(/^#{I18n.t(:undefined)}$/, '')

View File

@@ -3,14 +3,14 @@ class EnterpriseRelationship < ActiveRecord::Base
belongs_to :child, class_name: 'Enterprise', touch: true
has_many :permissions, class_name: 'EnterpriseRelationshipPermission', dependent: :destroy
validates_presence_of :parent_id, :child_id
validates_uniqueness_of :child_id, scope: :parent_id, message: I18n.t('validation_msg_relationship_already_established')
validates :parent_id, :child_id, presence: true
validates :child_id, uniqueness: { scope: :parent_id, message: I18n.t('validation_msg_relationship_already_established') }
after_save :update_permissions_of_child_variant_overrides
before_destroy :revoke_all_child_variant_overrides
scope :with_enterprises,
joins('LEFT JOIN enterprises AS parent_enterprises ON parent_enterprises.id = enterprise_relationships.parent_id').
joins('LEFT JOIN enterprises AS parent_enterprises ON parent_enterprises.id = enterprise_relationships.parent_id').
joins('LEFT JOIN enterprises AS child_enterprises ON child_enterprises.id = enterprise_relationships.child_id')
scope :involving_enterprises, ->(enterprises) {
@@ -30,7 +30,7 @@ class EnterpriseRelationship < ActiveRecord::Base
# Load an array of the relatives of each enterprise (ie. any enterprise related to it in
# either direction). This array is split into distributors and producers, and has the format:
# {enterprise_id => {distributors: [id, ...], producers: [id, ...]} }
def self.relatives(activated_only=false)
def self.relatives(activated_only = false)
relationships = EnterpriseRelationship.includes(:child, :parent)
relatives = {}
@@ -44,8 +44,8 @@ class EnterpriseRelationship < ActiveRecord::Base
end
relationships.each do |r|
relatives[r.parent_id] ||= {distributors: Set.new, producers: Set.new}
relatives[r.child_id] ||= {distributors: Set.new, producers: Set.new}
relatives[r.parent_id] ||= { distributors: Set.new, producers: Set.new }
relatives[r.child_id] ||= { distributors: Set.new, producers: Set.new }
if !activated_only || r.child.activated?
relatives[r.parent_id][:producers] << r.child_id if r.child.is_primary_producer

View File

@@ -1,9 +1,9 @@
class EnterpriseRole < ActiveRecord::Base
belongs_to :user, :class_name => Spree.user_class
belongs_to :user, class_name: Spree.user_class
belongs_to :enterprise
validates_presence_of :user_id, :enterprise_id
validates_uniqueness_of :enterprise_id, scope: :user_id, message: I18n.t(:enterprise_role_uniqueness_error)
validates :user_id, :enterprise_id, presence: true
validates :enterprise_id, uniqueness: { scope: :user_id, message: I18n.t(:enterprise_role_uniqueness_error) }
scope :by_user_email, joins(:user).order('spree_users.email ASC')
end

View File

@@ -1,5 +1,5 @@
class EnterpriseSet < ModelSet
def initialize(collection, attributes={})
def initialize(collection, attributes = {})
super(Enterprise, collection, attributes)
end
end

View File

@@ -11,8 +11,8 @@ class Exchange < ActiveRecord::Base
has_many :exchange_fees, dependent: :destroy
has_many :enterprise_fees, through: :exchange_fees
validates_presence_of :order_cycle, :sender, :receiver
validates_uniqueness_of :sender_id, scope: [:order_cycle_id, :receiver_id, :incoming]
validates :order_cycle, :sender, :receiver, presence: true
validates :sender_id, uniqueness: { scope: [:order_cycle_id, :receiver_id, :incoming] }
after_save :refresh_products_cache
after_destroy :refresh_products_cache_from_destroy
@@ -53,13 +53,12 @@ class Exchange < ActiveRecord::Base
end
}
def clone!(new_order_cycle)
exchange = self.dup
exchange = dup
exchange.order_cycle = new_order_cycle
exchange.enterprise_fee_ids = self.enterprise_fee_ids
exchange.variant_ids = self.variant_ids
exchange.tag_ids = self.tag_ids
exchange.enterprise_fee_ids = enterprise_fee_ids
exchange.variant_ids = variant_ids
exchange.tag_ids = tag_ids
exchange.save!
exchange
end
@@ -72,15 +71,15 @@ class Exchange < ActiveRecord::Base
incoming? ? sender : receiver
end
def to_h(core_only=false)
h = attributes.merge({ 'variant_ids' => variant_ids.sort, 'enterprise_fee_ids' => enterprise_fee_ids.sort })
def to_h(core_only = false)
h = attributes.merge('variant_ids' => variant_ids.sort, 'enterprise_fee_ids' => enterprise_fee_ids.sort)
h.reject! { |k| %w(id order_cycle_id created_at updated_at).include? k } if core_only
h
end
def eql?(e)
if e.respond_to? :to_h
self.to_h(true) == e.to_h(true)
to_h(true) == e.to_h(true)
else
super e
end

View File

@@ -2,11 +2,9 @@ class ExchangeFee < ActiveRecord::Base
belongs_to :exchange
belongs_to :enterprise_fee
after_save :refresh_products_cache
after_destroy :refresh_products_cache
private
def refresh_products_cache

View File

@@ -1,4 +1,4 @@
class ExchangeVariant < ActiveRecord::Base
belongs_to :exchange
belongs_to :variant, :class_name => 'Spree::Variant'
belongs_to :variant, class_name: 'Spree::Variant'
end

View File

@@ -16,7 +16,6 @@ class InventoryItem < ActiveRecord::Base
after_save :refresh_products_cache
private
def refresh_products_cache

View File

@@ -5,7 +5,7 @@ class ModelSet
attr_accessor :collection
def initialize(klass, collection, attributes={}, reject_if=nil, delete_if=nil)
def initialize(klass, collection, attributes = {}, reject_if = nil, delete_if = nil)
@klass, @collection, @reject_if, @delete_if = klass, collection, reject_if, delete_if
# Set here first, to ensure that we apply collection_attributes to the right collection
@@ -17,7 +17,7 @@ class ModelSet
end
def collection_attributes=(collection_attributes)
collection_attributes.each do |k, attributes|
collection_attributes.each do |_k, attributes|
# attributes == {:id => 123, :next_collection_at => '...'}
e = @collection.detect { |e| e.id.to_s == attributes[:id].to_s && !e.id.nil? }
if e.nil?

View File

@@ -1,12 +1,12 @@
require 'open_food_network/scope_variant_to_hub'
class OrderCycle < ActiveRecord::Base
belongs_to :coordinator, :class_name => 'Enterprise'
belongs_to :coordinator, class_name: 'Enterprise'
has_many :coordinator_fee_refs, class_name: 'CoordinatorFee'
has_many :coordinator_fees, through: :coordinator_fee_refs, source: :enterprise_fee
has_many :exchanges, :dependent => :destroy
has_many :exchanges, dependent: :destroy
# These scope names are prepended with "cached_" because there are existing accessor methods
# :incoming_exchanges and :outgoing_exchanges.
@@ -20,7 +20,7 @@ class OrderCycle < ActiveRecord::Base
attr_accessor :incoming_exchanges, :outgoing_exchanges
validates_presence_of :name, :coordinator_id
validates :name, :coordinator_id, presence: true
validate :orders_close_at_after_orders_open_at?
after_save :refresh_products_cache
@@ -119,13 +119,13 @@ class OrderCycle < ActiveRecord::Base
end
def clone!
oc = self.dup
oc = dup
oc.name = I18n.t("models.order_cycle.cloned_order_cycle_name", order_cycle: oc.name)
oc.orders_open_at = oc.orders_close_at = nil
oc.coordinator_fee_ids = self.coordinator_fee_ids
oc.preferred_product_selection_from_coordinator_inventory_only = self.preferred_product_selection_from_coordinator_inventory_only
oc.coordinator_fee_ids = coordinator_fee_ids
oc.preferred_product_selection_from_coordinator_inventory_only = preferred_product_selection_from_coordinator_inventory_only
oc.save!
self.exchanges.each { |e| e.clone!(oc) }
exchanges.each { |e| e.clone!(oc) }
oc.reload
end
@@ -138,15 +138,15 @@ class OrderCycle < ActiveRecord::Base
end
def supplied_variants
self.exchanges.incoming.map(&:variants).flatten.uniq.reject(&:deleted?)
exchanges.incoming.map(&:variants).flatten.uniq.reject(&:deleted?)
end
def distributed_variants
self.exchanges.outgoing.map(&:variants).flatten.uniq.reject(&:deleted?)
exchanges.outgoing.map(&:variants).flatten.uniq.reject(&:deleted?)
end
def variants_distributed_by(distributor)
return Spree::Variant.where("1=0") unless distributor.present?
return Spree::Variant.where("1=0") if distributor.blank?
Spree::Variant.
joins(:exchanges).
merge(distributor.inventory_variants).
@@ -160,15 +160,15 @@ class OrderCycle < ActiveRecord::Base
end
def products
self.variants.map(&:product).uniq
variants.map(&:product).uniq
end
def has_distributor?(distributor)
self.distributors.include? distributor
distributors.include? distributor
end
def has_variant?(variant)
self.variants.include? variant
variants.include? variant
end
def dated?
@@ -176,20 +176,20 @@ class OrderCycle < ActiveRecord::Base
end
def undated?
self.orders_open_at.nil? || self.orders_close_at.nil?
orders_open_at.nil? || orders_close_at.nil?
end
def upcoming?
self.orders_open_at && Time.zone.now < self.orders_open_at
orders_open_at && Time.zone.now < orders_open_at
end
def open?
self.orders_open_at && self.orders_close_at &&
Time.zone.now > self.orders_open_at && Time.zone.now < self.orders_close_at
orders_open_at && orders_close_at &&
Time.zone.now > orders_open_at && Time.zone.now < orders_close_at
end
def closed?
self.orders_close_at && Time.zone.now > self.orders_close_at
orders_close_at && Time.zone.now > orders_close_at
end
def exchange_for_distributor(distributor)

View File

@@ -1,5 +1,5 @@
class OrderCycleSet < ModelSet
def initialize(collection, attributes={})
def initialize(collection, attributes = {})
super(OrderCycle, collection, attributes)
end
end

Some files were not shown because too many files have changed in this diff Show More