diff --git a/.rubocop.yml b/.rubocop.yml index 0ccf22a..c87b3eb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,11 +1,13 @@ require: - rubocop-factory_bot # - rubocop-i18n + - rubocop-rspec_rails + - rubocop-thread_safety + +plugins: - rubocop-performance - rubocop-rails - rubocop-rspec - - rubocop-rspec_rails - - rubocop-thread_safety AllCops: NewCops: enable diff --git a/Gemfile.lock b/Gemfile.lock index 5815ddc..1324dcb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -91,17 +91,18 @@ GEM uri (>= 0.13.1) ansi (1.5.0) ast (2.4.2) - aws-eventstream (1.3.0) - aws-partitions (1.1047.0) - aws-sdk-core (3.218.0) + aws-eventstream (1.3.1) + aws-partitions (1.1050.0) + aws-sdk-core (3.218.1) aws-eventstream (~> 1, >= 1.3.0) aws-partitions (~> 1, >= 1.992.0) aws-sigv4 (~> 1.9) + base64 jmespath (~> 1, >= 1.6.1) aws-sdk-kms (1.98.0) aws-sdk-core (~> 3, >= 3.216.0) aws-sigv4 (~> 1.5) - aws-sdk-s3 (1.180.0) + aws-sdk-s3 (1.181.0) aws-sdk-core (~> 3, >= 3.216.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.5) @@ -132,7 +133,7 @@ GEM railties (>= 4.1.0) responders warden (~> 1.2.3) - diff-lcs (1.5.1) + diff-lcs (1.6.0) docile (1.4.1) doorkeeper (5.8.1) railties (>= 5) @@ -161,8 +162,8 @@ GEM activesupport (>= 6.1) i18n (1.14.7) concurrent-ruby (~> 1.0) - image_processing (1.13.0) - mini_magick (>= 4.9.5, < 5) + image_processing (1.14.0) + mini_magick (>= 4.9.5, < 6) ruby-vips (>= 2.0.17, < 3) io-console (0.8.0) irb (1.15.1) @@ -170,10 +171,11 @@ GEM rdoc (>= 4.0.0) reline (>= 0.4.2) jmespath (1.6.2) - json (2.9.1) + json (2.10.1) jsonapi-renderer (0.2.2) language_server-protocol (3.17.0.4) - logger (1.6.5) + lint_roller (1.1.0) + logger (1.6.6) loofah (2.24.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -184,7 +186,9 @@ GEM net-smtp marcel (1.0.4) method_source (1.1.0) - mini_magick (4.13.2) + mini_magick (5.1.2) + benchmark + logger mini_mime (1.1.5) minitest (5.25.4) monetize (1.13.0) @@ -197,14 +201,15 @@ GEM money (~> 6.13) railties (>= 3.0) mustache (1.1.1) - net-imap (0.5.5) + net-imap (0.5.6) date net-protocol net-pop (0.1.2) net-protocol net-protocol (0.2.2) timeout - net-smtp (0.5.0) + net-smtp (0.5.1) + net-protocol nio4r (2.7.4) nokogiri (1.18.2-aarch64-linux-gnu) racc (~> 1.4) @@ -227,7 +232,7 @@ GEM parallel (1.26.3) paranoia (3.0.1) activerecord (>= 6, < 8.1) - parser (3.3.7.0) + parser (3.3.7.1) ast (~> 2.4.1) racc pg (1.5.9) @@ -245,7 +250,7 @@ GEM pundit (2.4.0) activesupport (>= 3.0.0) racc (1.8.1) - rack (3.1.9) + rack (3.1.10) rack-cors (2.0.2) rack (>= 2.0.0) rack-session (2.1.0) @@ -286,7 +291,7 @@ GEM zeitwerk (~> 2.6) rainbow (3.1.1) rake (13.2.1) - ransack (4.2.1) + ransack (4.3.0) activerecord (>= 6.1.5) activesupport (>= 6.1.5) i18n @@ -326,9 +331,10 @@ GEM rspec-mocks (~> 3.0) sidekiq (>= 5, < 8) rspec-support (3.13.2) - rubocop (1.71.2) + rubocop (1.72.2) json (~> 2.3) - language_server-protocol (>= 3.17.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.1.0) parallel (~> 1.10) parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) @@ -340,27 +346,30 @@ GEM parser (>= 3.3.1.0) rubocop-factory_bot (2.26.1) rubocop (~> 1.61) - rubocop-performance (1.23.1) - rubocop (>= 1.48.1, < 2.0) - rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rails (2.29.1) + rubocop-performance (1.24.0) + lint_roller (~> 1.1) + rubocop (>= 1.72.1, < 2.0) + rubocop-ast (>= 1.38.0, < 2.0) + rubocop-rails (2.30.1) activesupport (>= 4.2.0) + lint_roller (~> 1.1) rack (>= 1.1) - rubocop (>= 1.52.0, < 2.0) - rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rspec (3.4.0) - rubocop (~> 1.61) + rubocop (>= 1.72.1, < 2.0) + rubocop-ast (>= 1.38.0, < 2.0) + rubocop-rspec (3.5.0) + lint_roller (~> 1.1) + rubocop (~> 1.72, >= 1.72.1) rubocop-rspec_rails (2.30.0) rubocop (~> 1.61) rubocop-rspec (~> 3, >= 3.0.1) rubocop-thread_safety (0.6.0) rubocop (>= 1.48.1) ruby-progressbar (1.13.0) - ruby-vips (2.2.2) + ruby-vips (2.2.3) ffi (~> 1.12) logger securerandom (0.4.1) - sidekiq (7.3.8) + sidekiq (7.3.9) base64 connection_pool (>= 2.3.0) logger @@ -376,7 +385,7 @@ GEM terminal-table simplecov-html (0.13.1) simplecov_json_formatter (0.1.4) - stringio (3.1.2) + stringio (3.1.3) terminal-table (4.0.0) unicode-display_width (>= 1.1.1, < 4) thor (1.3.2) diff --git a/app/models/order.rb b/app/models/order.rb index dc96c0a..3d3c166 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -12,4 +12,9 @@ class Order < ApplicationRecord has_many :products, through: :order_products accepts_nested_attributes_for :order_products, allow_destroy: true + + validates :created_at, + absence: true, + unless: proc { |s| s.store.is_import_enabled? }, + on: :create end diff --git a/app/models/sale.rb b/app/models/sale.rb index b35bbac..8ec42d0 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -16,6 +16,10 @@ class Sale < ApplicationRecord accepts_nested_attributes_for :sale_products, allow_destroy: true validates_ownership_of :customer, with: :store + validates :created_at, + absence: true, + unless: proc { |s| s.store.is_import_enabled? }, + on: :create monetize :total_amount_cents diff --git a/app/models/shipping.rb b/app/models/shipping.rb index 8101ee8..e03ecf3 100644 --- a/app/models/shipping.rb +++ b/app/models/shipping.rb @@ -9,6 +9,10 @@ class Shipping < ApplicationRecord has_many :shipping_products, dependent: :destroy validates_ownership_of :provider, with: :store + validates :created_at, + absence: true, + unless: proc { |s| s.store.is_import_enabled? }, + on: :create accepts_nested_attributes_for :shipping_products, allow_destroy: true end diff --git a/app/policies/order_policy.rb b/app/policies/order_policy.rb index 3987d17..5f951ad 100644 --- a/app/policies/order_policy.rb +++ b/app/policies/order_policy.rb @@ -3,6 +3,7 @@ class OrderPolicy < Presets::UserEditablePolicy def permitted_attributes_for_create [ + :created_at, :customer_id, :store_id, { order_products_attributes: %i[product_id quantity amount_cents amount_currency] } diff --git a/app/policies/sale_policy.rb b/app/policies/sale_policy.rb index b1d5b20..d832ad5 100644 --- a/app/policies/sale_policy.rb +++ b/app/policies/sale_policy.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true class SalePolicy < Presets::UserEditablePolicy - def permitted_attributes_for_create + def permitted_attributes_for_create # rubocop:disable Metrics/MethodLength [ + :created_at, :store_id, :customer_id, :total_amount_cents, diff --git a/app/policies/shipping_policy.rb b/app/policies/shipping_policy.rb index 158950e..4106f46 100644 --- a/app/policies/shipping_policy.rb +++ b/app/policies/shipping_policy.rb @@ -6,6 +6,7 @@ class ShippingPolicy < Presets::UserEditablePolicy def permitted_attributes_for_create [ + :created_at, :store_id, :provider_id, { shipping_products_attributes: %i[ diff --git a/app/policies/store_policy.rb b/app/policies/store_policy.rb index 71c8f49..8155d77 100644 --- a/app/policies/store_policy.rb +++ b/app/policies/store_policy.rb @@ -34,7 +34,7 @@ def permitted_attributes_for_create end def permitted_attributes_for_update - %i[ + attributes = %i[ name address1 address2 @@ -45,6 +45,8 @@ def permitted_attributes_for_update color city ] + attributes << :is_import_enabled if user.store_owner?(record) + attributes end class Scope < ApplicationPolicy::Scope diff --git a/app/serializers/store_serializer.rb b/app/serializers/store_serializer.rb index 9f33e7c..6fed0b5 100644 --- a/app/serializers/store_serializer.rb +++ b/app/serializers/store_serializer.rb @@ -15,9 +15,5 @@ class StoreSerializer < ActiveModel::Serializer :created_at, :updated_at, :color, - :store_membership - - def store_membership - StoreMembership.find_by(user: scope, store: object) - end + :is_import_enabled end diff --git a/db/migrate/20250217165840_add_is_import_enabled_to_store.rb b/db/migrate/20250217165840_add_is_import_enabled_to_store.rb new file mode 100644 index 0000000..6ad8779 --- /dev/null +++ b/db/migrate/20250217165840_add_is_import_enabled_to_store.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddIsImportEnabledToStore < ActiveRecord::Migration[8.0] + def change + add_column :stores, :is_import_enabled, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 8fd3867..498b82f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_02_09_135124) do +ActiveRecord::Schema[8.0].define(version: 2025_02_17_165840) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" enable_extension "pgcrypto" @@ -372,6 +372,7 @@ t.string "email_address" t.string "color" t.string "city" + t.boolean "is_import_enabled", default: false t.index ["country_id"], name: "index_stores_on_country_id" t.index ["deleted_at"], name: "index_stores_on_deleted_at" end diff --git a/spec/acceptance/v2/orders_spec.rb b/spec/acceptance/v2/orders_spec.rb index a04bfc7..ca04306 100644 --- a/spec/acceptance/v2/orders_spec.rb +++ b/spec/acceptance/v2/orders_spec.rb @@ -22,6 +22,7 @@ with_options scope: :order, with_example: true do parameter :store_id, "Orders's store id", required: true parameter :customer_id, "Orders's customer id", required: true + parameter :created_at, "Orders's creation date" parameter :order_products_attributes, "Orders's products", type: :array, diff --git a/spec/acceptance/v2/stores_spec.rb b/spec/acceptance/v2/stores_spec.rb index ebf840f..3ef6416 100644 --- a/spec/acceptance/v2/stores_spec.rb +++ b/spec/acceptance/v2/stores_spec.rb @@ -57,8 +57,6 @@ body = JSON.parse(response_body) expect(body['id']).to eq(id) expect(body['name']).to eq(membership.store.name) - expect(body['store_membership']['id']).to eq(membership.id) - expect(body['store_membership']['role']).to eq(membership.role) end end diff --git a/spec/serializers/store_serializer_spec.rb b/spec/serializers/store_serializer_spec.rb index 74c0b26..8689daf 100644 --- a/spec/serializers/store_serializer_spec.rb +++ b/spec/serializers/store_serializer_spec.rb @@ -28,12 +28,4 @@ end end end - - describe 'belongs_to' do - it :store_membership do - expect(json['store_membership']).not_to be_nil - expect(json['store_membership']['id']).to eq(membership.id) - expect(json['store_membership']['role']).to eq(membership.role.to_s) - end - end end