snf_core 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/lib/snf_core/engine.rb +1 -1
  3. data/lib/snf_core/version.rb +1 -1
  4. data/spec/dummy/Rakefile +6 -0
  5. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  6. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  7. data/spec/dummy/app/jobs/application_job.rb +7 -0
  8. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  9. data/spec/dummy/app/models/application_record.rb +3 -0
  10. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  11. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  12. data/spec/dummy/bin/dev +2 -0
  13. data/spec/dummy/bin/rails +4 -0
  14. data/spec/dummy/bin/rake +4 -0
  15. data/spec/dummy/bin/setup +34 -0
  16. data/spec/dummy/config/application.rb +43 -0
  17. data/spec/dummy/config/boot.rb +5 -0
  18. data/spec/dummy/config/cable.yml +10 -0
  19. data/spec/dummy/config/database.yml +20 -0
  20. data/spec/dummy/config/environment.rb +5 -0
  21. data/spec/dummy/config/environments/development.rb +67 -0
  22. data/spec/dummy/config/environments/production.rb +86 -0
  23. data/spec/dummy/config/environments/test.rb +53 -0
  24. data/spec/dummy/config/initializers/cors.rb +16 -0
  25. data/spec/dummy/config/initializers/filter_parameter_logging.rb +8 -0
  26. data/spec/dummy/config/initializers/inflections.rb +16 -0
  27. data/spec/dummy/config/locales/en.yml +31 -0
  28. data/spec/dummy/config/puma.rb +38 -0
  29. data/spec/dummy/config/routes.rb +3 -0
  30. data/spec/dummy/config/storage.yml +38 -0
  31. data/spec/dummy/config.ru +6 -0
  32. data/spec/dummy/db/migrate/20250226123213_create_active_storage_tables.active_storage.rb +57 -0
  33. data/spec/dummy/db/schema.rb +181 -0
  34. data/spec/dummy/log/development.log +901 -0
  35. data/spec/dummy/log/test.log +12199 -0
  36. data/spec/dummy/spec/fixtures/files/sample.pdf +0 -0
  37. data/spec/dummy/tmp/local_secret.txt +1 -0
  38. data/spec/dummy/tmp/storage/13/1y/131yod70wqijazn3ix829yvuuvge +0 -0
  39. data/spec/dummy/tmp/storage/16/na/16na9nc1z98jt6fyn3axj3bhudes +0 -0
  40. data/spec/dummy/tmp/storage/1t/oy/1toyz0i6f9u5xexr4cpwttr04ood +0 -0
  41. data/spec/dummy/tmp/storage/1x/i3/1xi33eqr5ipoaz0upakb8yy7qc4o +0 -0
  42. data/spec/dummy/tmp/storage/24/69/2469t9kpepg4fd8ki960h025li0b +0 -0
  43. data/spec/dummy/tmp/storage/2a/0u/2a0uyihfk1wn5c1fuz09unocwy2m +0 -0
  44. data/spec/dummy/tmp/storage/4t/86/4t862kv9wcz0p7wgdvpmtmczdadt +0 -0
  45. data/spec/dummy/tmp/storage/5s/zb/5szbksq6mg3768g9vtk788gc49gw +0 -0
  46. data/spec/dummy/tmp/storage/6g/dc/6gdc40iivivwbln1zs4dqedt5ni7 +0 -0
  47. data/spec/dummy/tmp/storage/6o/7a/6o7ax3ihg25bswxp4d601mqo7tl3 +0 -0
  48. data/spec/dummy/tmp/storage/6z/86/6z862zpc67sikzl0otbf418t2clj +0 -0
  49. data/spec/dummy/tmp/storage/92/hw/92hw9u9j6728qgwpcn7oqphe9tzj +0 -0
  50. data/spec/dummy/tmp/storage/9a/3q/9a3qd5qc7j6dzzmg16wcpvwoowmp +0 -0
  51. data/spec/dummy/tmp/storage/al/8s/al8szf81ccm4ckpvxh3bv6vlgp0y +0 -0
  52. data/spec/dummy/tmp/storage/b8/8l/b88ln7wuq13v4akgwgc0dgac8887 +0 -0
  53. data/spec/dummy/tmp/storage/bs/y9/bsy9t4961ra8hwlq06wjtgrrcflp +0 -0
  54. data/spec/dummy/tmp/storage/cs/x9/csx9mv26ab1lm82a7itryfq4v6rq +0 -0
  55. data/spec/dummy/tmp/storage/dp/0f/dp0fx9ji1bqvx1najwjgns6n7fhf +0 -0
  56. data/spec/dummy/tmp/storage/em/kc/emkc4tc71k65mfcurv6k8z1ylswl +0 -0
  57. data/spec/dummy/tmp/storage/em/vx/emvx0c15o74mr0nlcvdc7m88j2gi +0 -0
  58. data/spec/dummy/tmp/storage/ga/7e/ga7eiyyv0llme2i4xby0kdp4a4h8 +0 -0
  59. data/spec/dummy/tmp/storage/h4/vg/h4vgoatz21dhjrztrrbg2hdhkwjb +0 -0
  60. data/spec/dummy/tmp/storage/hi/9h/hi9ho77symoy2j0ye28fxgnxw3kt +0 -0
  61. data/spec/dummy/tmp/storage/hl/yy/hlyyu150rt2yos1sa9ed1qw49y26 +0 -0
  62. data/spec/dummy/tmp/storage/j7/6x/j76x0oirv7i4t6p3blseuaknp7pw +0 -0
  63. data/spec/dummy/tmp/storage/jq/95/jq95rqhv5usgucn2d2mmkhjufapu +0 -0
  64. data/spec/dummy/tmp/storage/ky/1y/ky1ys68lmat11bxs2395dqugiyig +0 -0
  65. data/spec/dummy/tmp/storage/ln/0f/ln0fz4opsdycu80q7urfez9ar7kn +0 -0
  66. data/spec/dummy/tmp/storage/mk/4w/mk4w528bsn47ewri0odui9s40f87 +0 -0
  67. data/spec/dummy/tmp/storage/na/6r/na6rrohinrnjofsq27u95up5rp8k +0 -0
  68. data/spec/dummy/tmp/storage/oc/f8/ocf8zs18lm9fnkpqj6wpshdpyf43 +0 -0
  69. data/spec/dummy/tmp/storage/oe/bq/oebq593a6bpwkbxpx6segtwyy0jy +0 -0
  70. data/spec/dummy/tmp/storage/qs/jk/qsjkqiiarr85uobud0qsnnmpraol +0 -0
  71. data/spec/dummy/tmp/storage/qw/7z/qw7zsf91njf7ga6454nrjpvddjn5 +0 -0
  72. data/spec/dummy/tmp/storage/rh/0h/rh0h80b8er9vp1u8dcocy1u58obf +0 -0
  73. data/spec/dummy/tmp/storage/tc/gu/tcgurel05x9fk9ksm4hxwfla3hg3 +0 -0
  74. data/spec/dummy/tmp/storage/tm/ce/tmce54998rdnz191k02fzowpebvw +0 -0
  75. data/spec/dummy/tmp/storage/w2/3f/w23f3igzkn7bddqxry5x4wsu2ths +0 -0
  76. data/spec/dummy/tmp/storage/wo/81/wo813rsnwvoa55h0vq0fr79iajuw +0 -0
  77. data/spec/dummy/tmp/storage/wy/14/wy14megn3o5zqplv9xg6u32uwkr6 +0 -0
  78. data/spec/dummy/tmp/storage/xj/yy/xjyygdd3znvvpt9ufz1vv4lfsx3w +0 -0
  79. data/spec/dummy/tmp/storage/yf/49/yf49a4ydheqf3cqs0u49sanbl4ms +0 -0
  80. data/spec/dummy/tmp/storage/yh/q1/yhq1muao2dpuykmj12bxhd0x4ntk +0 -0
  81. data/spec/dummy/tmp/storage/yx/jp/yxjpumjyo1jysjpg20qaxgsqg4fw +0 -0
  82. data/spec/dummy/tmp/storage/z1/gr/z1grp34d5vw7mi4g8vw8yfu91ny2 +0 -0
  83. data/spec/examples.txt +66 -0
  84. data/spec/factories/snf_core/addresses.rb +10 -0
  85. data/spec/factories/snf_core/business_documents.rb +18 -0
  86. data/spec/factories/snf_core/businesses.rb +10 -0
  87. data/spec/factories/snf_core/categories.rb +7 -0
  88. data/spec/factories/snf_core/customer_groups.rb +9 -0
  89. data/spec/factories/snf_core/groups.rb +6 -0
  90. data/spec/factories/snf_core/products.rb +9 -0
  91. data/spec/factories/snf_core/store_inventories.rb +8 -0
  92. data/spec/factories/snf_core/stores.rb +9 -0
  93. data/spec/factories/snf_core/users.rb +10 -0
  94. data/spec/factories/snf_core/wallets.rb +7 -0
  95. data/spec/models/snf_core/address_spec.rb +15 -0
  96. data/spec/models/snf_core/business_document_spec.rb +20 -0
  97. data/spec/models/snf_core/business_spec.rb +14 -0
  98. data/spec/models/snf_core/category_spec.rb +12 -0
  99. data/spec/models/snf_core/customer_group_spec.rb +11 -0
  100. data/spec/models/snf_core/group_spec.rb +11 -0
  101. data/spec/models/snf_core/product_spec.rb +17 -0
  102. data/spec/models/snf_core/store_inventory_spec.rb +24 -0
  103. data/spec/models/snf_core/store_spec.rb +13 -0
  104. data/spec/models/snf_core/user_spec.rb +23 -0
  105. data/spec/models/snf_core/wallet_spec.rb +28 -0
  106. data/spec/rails_helper.rb +46 -0
  107. data/spec/sample_spec.rb +5 -0
  108. data/spec/spec_helper.rb +36 -0
  109. data/spec/support/models/shared_examples.rb +49 -0
  110. data/spec/support/requests/shared_requests.rb +130 -0
  111. metadata +108 -1
@@ -0,0 +1 @@
1
+ c59d42c24752f82ebdb926f0cd4fe36ecd68f759f28641bc8670f65412fba944ea7a9f328a09e2f909795f01f3e40cc57c4dc771d6874acb3b0243681352bd78
data/spec/examples.txt ADDED
@@ -0,0 +1,66 @@
1
+ example_id | status | run_time |
2
+ ----------------------------------------------------- | ------ | --------------- |
3
+ ./spec/models/snf_core/address_spec.rb[1:1] | passed | 0.03319 seconds |
4
+ ./spec/models/snf_core/address_spec.rb[1:2] | passed | 0.1237 seconds |
5
+ ./spec/models/snf_core/address_spec.rb[1:3] | passed | 0.06078 seconds |
6
+ ./spec/models/snf_core/address_spec.rb[1:4] | passed | 0.1097 seconds |
7
+ ./spec/models/snf_core/address_spec.rb[1:5] | passed | 0.05095 seconds |
8
+ ./spec/models/snf_core/address_spec.rb[1:6] | passed | 0.0749 seconds |
9
+ ./spec/models/snf_core/address_spec.rb[1:7] | passed | 0.04658 seconds |
10
+ ./spec/models/snf_core/address_spec.rb[1:8] | passed | 0.05566 seconds |
11
+ ./spec/models/snf_core/business_document_spec.rb[1:1] | passed | 1.18 seconds |
12
+ ./spec/models/snf_core/business_document_spec.rb[1:2] | passed | 1.2 seconds |
13
+ ./spec/models/snf_core/business_document_spec.rb[1:3] | passed | 10.94 seconds |
14
+ ./spec/models/snf_core/business_document_spec.rb[1:4] | passed | 0.87525 seconds |
15
+ ./spec/models/snf_core/business_document_spec.rb[1:5] | passed | 1.09 seconds |
16
+ ./spec/models/snf_core/business_spec.rb[1:1] | passed | 0.25265 seconds |
17
+ ./spec/models/snf_core/business_spec.rb[1:2] | passed | 0.36121 seconds |
18
+ ./spec/models/snf_core/business_spec.rb[1:3] | passed | 0.33781 seconds |
19
+ ./spec/models/snf_core/business_spec.rb[1:4] | passed | 0.46619 seconds |
20
+ ./spec/models/snf_core/business_spec.rb[1:5] | passed | 0.50193 seconds |
21
+ ./spec/models/snf_core/business_spec.rb[1:6] | passed | 0.23985 seconds |
22
+ ./spec/models/snf_core/business_spec.rb[1:7] | passed | 0.43902 seconds |
23
+ ./spec/models/snf_core/category_spec.rb[1:1] | passed | 0.07059 seconds |
24
+ ./spec/models/snf_core/category_spec.rb[1:2] | passed | 0 seconds |
25
+ ./spec/models/snf_core/category_spec.rb[1:3] | passed | 0.07684 seconds |
26
+ ./spec/models/snf_core/category_spec.rb[1:4] | passed | 0.05951 seconds |
27
+ ./spec/models/snf_core/customer_group_spec.rb[1:1] | passed | 0.19376 seconds |
28
+ ./spec/models/snf_core/customer_group_spec.rb[1:2] | passed | 0.20793 seconds |
29
+ ./spec/models/snf_core/customer_group_spec.rb[1:3] | passed | 0.29917 seconds |
30
+ ./spec/models/snf_core/group_spec.rb[1:1] | passed | 0.17801 seconds |
31
+ ./spec/models/snf_core/group_spec.rb[1:2] | passed | 0.29573 seconds |
32
+ ./spec/models/snf_core/group_spec.rb[1:3] | passed | 0.19857 seconds |
33
+ ./spec/models/snf_core/product_spec.rb[1:1] | passed | 0.08596 seconds |
34
+ ./spec/models/snf_core/product_spec.rb[1:2] | passed | 0.14479 seconds |
35
+ ./spec/models/snf_core/product_spec.rb[1:3] | passed | 0.21441 seconds |
36
+ ./spec/models/snf_core/product_spec.rb[1:4] | passed | 0.14814 seconds |
37
+ ./spec/models/snf_core/product_spec.rb[1:5:1] | passed | 0.16835 seconds |
38
+ ./spec/models/snf_core/product_spec.rb[1:5:2] | passed | 0.16636 seconds |
39
+ ./spec/models/snf_core/store_inventory_spec.rb[1:1] | passed | 0.23812 seconds |
40
+ ./spec/models/snf_core/store_inventory_spec.rb[1:2] | passed | 0.4514 seconds |
41
+ ./spec/models/snf_core/store_inventory_spec.rb[1:3] | passed | 0.3376 seconds |
42
+ ./spec/models/snf_core/store_inventory_spec.rb[1:4] | passed | 0.45055 seconds |
43
+ ./spec/models/snf_core/store_inventory_spec.rb[1:5] | passed | 0.23316 seconds |
44
+ ./spec/models/snf_core/store_inventory_spec.rb[1:6] | passed | 0.59619 seconds |
45
+ ./spec/models/snf_core/store_inventory_spec.rb[1:7:1] | passed | 0.22992 seconds |
46
+ ./spec/models/snf_core/store_spec.rb[1:1] | passed | 0.14422 seconds |
47
+ ./spec/models/snf_core/store_spec.rb[1:2] | passed | 0.14919 seconds |
48
+ ./spec/models/snf_core/store_spec.rb[1:3] | passed | 0.15109 seconds |
49
+ ./spec/models/snf_core/store_spec.rb[1:4] | passed | 0.13989 seconds |
50
+ ./spec/models/snf_core/store_spec.rb[1:5] | passed | 0.14587 seconds |
51
+ ./spec/models/snf_core/user_spec.rb[1:1] | passed | 0.08359 seconds |
52
+ ./spec/models/snf_core/user_spec.rb[1:2] | passed | 0.19769 seconds |
53
+ ./spec/models/snf_core/user_spec.rb[1:3] | passed | 0.09936 seconds |
54
+ ./spec/models/snf_core/user_spec.rb[1:4] | passed | 0.14341 seconds |
55
+ ./spec/models/snf_core/user_spec.rb[1:5] | passed | 0.11211 seconds |
56
+ ./spec/models/snf_core/user_spec.rb[1:6] | passed | 0.12025 seconds |
57
+ ./spec/models/snf_core/user_spec.rb[1:7] | passed | 0.13896 seconds |
58
+ ./spec/models/snf_core/user_spec.rb[1:8:1] | passed | 0.1389 seconds |
59
+ ./spec/models/snf_core/wallet_spec.rb[1:1] | passed | 0.17215 seconds |
60
+ ./spec/models/snf_core/wallet_spec.rb[1:2] | passed | 0.29964 seconds |
61
+ ./spec/models/snf_core/wallet_spec.rb[1:3] | passed | 0.2178 seconds |
62
+ ./spec/models/snf_core/wallet_spec.rb[1:4] | passed | 0.16067 seconds |
63
+ ./spec/models/snf_core/wallet_spec.rb[1:5] | passed | 0.24842 seconds |
64
+ ./spec/models/snf_core/wallet_spec.rb[1:6:1] | passed | 0.29817 seconds |
65
+ ./spec/models/snf_core/wallet_spec.rb[1:6:2] | passed | 0.54702 seconds |
66
+ ./spec/sample_spec.rb[1:1] | passed | 0.00058 seconds |
@@ -0,0 +1,10 @@
1
+ FactoryBot.define do
2
+ factory :address, class: "SnfCore::Address" do
3
+ address_type { "store1" }
4
+ city { Faker::Address.city }
5
+ sub_city { Faker::Address.street_name }
6
+ woreda { Faker::Address.community }
7
+ latitude { Faker::Address.latitude }
8
+ longitude { Faker::Address.longitude }
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ FactoryBot.define do
2
+ factory :business_document, class: "SnfCore::BusinessDocument" do
3
+ business
4
+ document_type { 0 }
5
+ verified_at { "2025-02-26 13:29:31" }
6
+ verified_by { create(:user) }
7
+ is_verified { false }
8
+ uploaded_at { "2025-02-26 13:29:31" }
9
+
10
+ after(:build) do |business_document|
11
+ business_document.document.attach(
12
+ io: File.open(Rails.root.join('spec', 'fixtures', 'files', 'sample.pdf')),
13
+ filename: 'sample.pdf',
14
+ content_type: 'application/pdf'
15
+ )
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ FactoryBot.define do
2
+ factory :business, class: "SnfCore::Business" do
3
+ user
4
+ business_name { Faker::Company.name }
5
+ tin_number { Faker::Company.name }
6
+ business_type { 1 }
7
+ verified_at { Time.now }
8
+ verification_status { 0 }
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :category, class: "SnfCore::Category" do
3
+ name { Faker::Name.name }
4
+ description { Faker::Lorem.word }
5
+ parent { nil }
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ FactoryBot.define do
2
+ factory :customer_group, class: "SnfCore::CustomerGroup" do
3
+ discount_code { Faker::Alphanumeric.alpha(number: 10) }
4
+ expire_date { DateTime.tomorrow }
5
+ is_used { false }
6
+ group
7
+ customer { create(:user) }
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ FactoryBot.define do
2
+ factory :group, class: "SnfCore::Group" do
3
+ name { Faker::Name.name }
4
+ business
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ FactoryBot.define do
2
+ factory :product, class: "SnfCore::Product" do
3
+ sku { Faker::Alphanumeric.alpha(number: 10) }
4
+ name { Faker::Commerce.product_name }
5
+ description { Faker::Lorem.word }
6
+ category
7
+ base_price { Faker::Number.between(from: 10.0, to: 10000.0) }
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :store_inventory, class: "SnfCore::StoreInventory" do
3
+ store
4
+ product
5
+ status { 0 }
6
+ base_price { Faker::Commerce.price(range: 10..1000.0) }
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ FactoryBot.define do
2
+ factory :store, class: "SnfCore::Store" do
3
+ name { Faker::Name.name }
4
+ email { Faker::Internet.email }
5
+ operational_status { 1 }
6
+ business
7
+ address
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ FactoryBot.define do
2
+ factory :user, class: "SnfCore::User" do
3
+ first_name { Faker::Name.first_name }
4
+ middle_name { Faker::Name.middle_name }
5
+ last_name { Faker::Name.last_name }
6
+ email { Faker::Internet.email }
7
+ phone_number { Faker::Alphanumeric.alpha(number: 10) }
8
+ role { 1 }
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :wallet, class: "SnfCore::Wallet" do
3
+ user
4
+ balance { 0.0 }
5
+ is_active { true }
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails_helper'
2
+
3
+ module SnfCore
4
+ RSpec.describe Address, type: :model do
5
+ attributes = [
6
+ { address_type: :presence },
7
+ { city: :presence },
8
+ { sub_city: :presence },
9
+ { latitude: %i[presence numericality] },
10
+ { longitude: %i[presence numericality] }
11
+ ]
12
+
13
+ include_examples("model_shared_spec", :address, attributes)
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ require 'rails_helper'
2
+
3
+ module SnfCore
4
+ RSpec.describe BusinessDocument, type: :model do
5
+ attributes = [
6
+ { business: :belong_to },
7
+ { document_type: :presence },
8
+ { uploaded_at: :presence }
9
+ ]
10
+ include_examples("model_shared_spec", :business_document, attributes)
11
+
12
+
13
+ it "has verified_by that belongs to user but can be null" do
14
+ business_document = create(:business_document)
15
+ expect(business_document.verified_by).to be_a(SnfCore::User)
16
+ business_document.verified_by = nil
17
+ expect(business_document.valid?).to be_truthy
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails_helper'
2
+
3
+ module SnfCore
4
+ RSpec.describe Business, type: :model do
5
+ attributes = [
6
+ { business_name: :presence },
7
+ { tin_number: %i[presence uniqueness] },
8
+ { business_type: :presence },
9
+ { verification_status: :presence },
10
+ { user: :belong_to }
11
+ ]
12
+ include_examples("model_shared_spec", :business, attributes)
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ require 'rails_helper'
2
+
3
+ module SnfCore
4
+ RSpec.describe Category, type: :model do
5
+ attributes = [
6
+ { name: %i[presence uniqueness] }
7
+ ]
8
+ include_examples("model_shared_spec", :category, attributes)
9
+
10
+ it { is_expected.to belong_to(:parent).class_name('Category').optional }
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ require 'rails_helper'
2
+
3
+ module SnfCore
4
+ RSpec.describe CustomerGroup, type: :model do
5
+ attributes = [
6
+ { group: :belong_to },
7
+ { customer: :belong_to }
8
+ ]
9
+ include_examples("model_shared_spec", :customer_group, attributes)
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'rails_helper'
2
+
3
+ module SnfCore
4
+ RSpec.describe Group, type: :model do
5
+ attributes = [
6
+ { business: :belong_to },
7
+ { name: :presence }
8
+ ]
9
+ include_examples("model_shared_spec", :group, attributes)
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails_helper'
2
+
3
+ module SnfCore
4
+ RSpec.describe Product, type: :model do
5
+ attributes = [
6
+ { name: :presence },
7
+ { sku: %i[presence uniqueness] }
8
+ ]
9
+ include_examples("model_shared_spec", :product, attributes)
10
+
11
+
12
+ describe "Product active storage" do
13
+ it { is_expected.to have_one_attached(:thumbnail_image) }
14
+ it { is_expected.to have_many_attached(:images) }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ require 'rails_helper'
2
+
3
+ module SnfCore
4
+ RSpec.describe StoreInventory, type: :model do
5
+ attributes = [
6
+ { store: :belong_to },
7
+ { product: :belong_to },
8
+ { base_price: %i[presence numericality] },
9
+ { status: :presence }
10
+ ]
11
+ include_examples("model_shared_spec", :store_inventory, attributes)
12
+
13
+ describe 'validations' do
14
+ it 'validates unique store-product combination' do
15
+ store_inventory = create(:store_inventory)
16
+ duplicate = build(:store_inventory,
17
+ store: store_inventory.store,
18
+ product: store_inventory.product
19
+ )
20
+ expect(duplicate).not_to be_valid
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails_helper'
2
+
3
+ module SnfCore
4
+ RSpec.describe Store, type: :model do
5
+ attributes = [
6
+ { name: :presence },
7
+ { operational_status: :presence },
8
+ { business: :belong_to },
9
+ { address: :belong_to }
10
+ ]
11
+ include_examples("model_shared_spec", :store, attributes)
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ require 'rails_helper'
2
+
3
+ module SnfCore
4
+ RSpec.describe User, type: :model do
5
+ attributes = [
6
+ { first_name: :presence },
7
+ { middle_name: :presence },
8
+ { last_name: :presence },
9
+ { role: :presence },
10
+ { phone_number: %i[presence uniqueness] }
11
+ ]
12
+ include_examples("model_shared_spec", :user, attributes)
13
+
14
+ describe 'wallet creation' do
15
+ it 'creates a wallet automatically for the user' do
16
+ user = create(:user)
17
+ expect(user.wallet).to be_present
18
+ expect(user.wallet.balance).to eq(0.0)
19
+ expect(user.wallet.is_active).to be_truthy
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ require 'rails_helper'
2
+
3
+ module SnfCore
4
+ RSpec.describe Wallet, type: :model do
5
+ attributes = [
6
+ { wallet_number: :presence },
7
+ { balance: :presence },
8
+ { is_active: :presence },
9
+ { user: :belong_to }
10
+ ]
11
+
12
+ include_examples("model_shared_spec", :wallet, attributes)
13
+
14
+ describe 'wallet number generation' do
15
+ it 'automatically generates a wallet number on creation' do
16
+ wallet = create(:wallet)
17
+ expect(wallet.wallet_number).to be_present
18
+ expect(wallet.wallet_number.length).to eq(12)
19
+ end
20
+
21
+ it 'ensures wallet numbers are unique' do
22
+ first_wallet = create(:wallet)
23
+ second_wallet = create(:wallet)
24
+ expect(first_wallet.wallet_number).not_to eq(second_wallet.wallet_number)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,46 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ require "spec_helper"
3
+ ENV["RAILS_ENV"] ||= "test"
4
+ require_relative "../spec/dummy/config/environment"
5
+ abort("The Rails environment is running in production mode!") if Rails.env.production?
6
+
7
+ require "rspec/rails"
8
+ require "database_cleaner/active_record"
9
+ require "factory_bot_rails"
10
+ require "faker"
11
+ require "shoulda-matchers"
12
+
13
+ begin
14
+ ActiveRecord::Migration.maintain_test_schema!
15
+ rescue ActiveRecord::PendingMigrationError => e
16
+ abort e.to_s.strip
17
+ end
18
+
19
+ RSpec.configure do |config|
20
+ config.before(:suite) do
21
+ DatabaseCleaner.strategy = :transaction
22
+ DatabaseCleaner.clean_with(:truncation)
23
+ end
24
+
25
+ config.before do
26
+ DatabaseCleaner.strategy = :transaction
27
+ DatabaseCleaner.start
28
+ end
29
+
30
+ config.append_after do
31
+ DatabaseCleaner.clean
32
+ end
33
+
34
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
35
+ config.use_transactional_fixtures = true
36
+ config.infer_spec_type_from_file_location!
37
+ config.filter_rails_from_backtrace!
38
+ config.include FactoryBot::Syntax::Methods
39
+ end
40
+
41
+ Shoulda::Matchers.configure do |config|
42
+ config.integrate do |with|
43
+ with.test_framework(:rspec)
44
+ with.library(:rails)
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ RSpec.describe "Sample Spec" do
2
+ it "runs spec successfully" do
3
+ expect(1).to eq 1
4
+ end
5
+ end
@@ -0,0 +1,36 @@
1
+ require "simplecov"
2
+ require "./spec/support/models/shared_examples"
3
+ require "./spec/support/requests/shared_requests"
4
+ require "rspec/retry"
5
+
6
+ RSpec.configure do |config|
7
+ config.expect_with :rspec do |expectations|
8
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
9
+ end
10
+
11
+ config.formatter = RSpec::Core::Formatters::DocumentationFormatter
12
+
13
+ config.mock_with :rspec do |mocks|
14
+ mocks.verify_partial_doubles = true
15
+ end
16
+
17
+ config.shared_context_metadata_behavior = :apply_to_host_groups
18
+ config.example_status_persistence_file_path = "spec/examples.txt"
19
+ config.disable_monkey_patching!
20
+ config.profile_examples = 10
21
+ config.order = :random
22
+ Kernel.srand config.seed
23
+
24
+ config.verbose_retry = true
25
+ config.display_try_failure_messages = true
26
+ config.around :each, :js do |ex|
27
+ ex.run_with_retry retry: 3
28
+ end
29
+ end
30
+
31
+ SimpleCov.start("rails") do
32
+ add_filter("/lib/")
33
+ add_filter("/bin/")
34
+ add_filter("/db/")
35
+ add_filter("/spec/")
36
+ end