Skip to content

Commit

Permalink
Adding created_at for imports
Browse files Browse the repository at this point in the history
  • Loading branch information
sofianegargouri committed Feb 17, 2025
1 parent a8c3369 commit 97635c8
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 48 deletions.
6 changes: 4 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
65 changes: 37 additions & 28 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -161,19 +162,20 @@ 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)
pp (>= 0.6.0)
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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions app/models/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions app/models/sale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions app/models/shipping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions app/policies/order_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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] }
Expand Down
3 changes: 2 additions & 1 deletion app/policies/sale_policy.rb
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
1 change: 1 addition & 0 deletions app/policies/shipping_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ShippingPolicy < Presets::UserEditablePolicy

def permitted_attributes_for_create
[
:created_at,
:store_id,
:provider_id,
{ shipping_products_attributes: %i[
Expand Down
4 changes: 3 additions & 1 deletion app/policies/store_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def permitted_attributes_for_create
end

def permitted_attributes_for_update
%i[
attributes = %i[
name
address1
address2
Expand All @@ -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
Expand Down
6 changes: 1 addition & 5 deletions app/serializers/store_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions db/migrate/20250217165840_add_is_import_enabled_to_store.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/acceptance/v2/orders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions spec/acceptance/v2/stores_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 0 additions & 8 deletions spec/serializers/store_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 97635c8

Please sign in to comment.