diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7f5a804 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,42 @@ +# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files. + +# Ignore git directory. +/.git/ +/.gitignore + +# Ignore bundler config. +/.bundle + +# Ignore all environment files (except templates). +/.env* +!/.env*.erb + +# Ignore all default key files. +/config/master.key +/config/credentials/*.key + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore pidfiles, but keep the directory. +/tmp/pids/* +!/tmp/pids/.keep + +# Ignore storage (uploaded files in development and any SQLite databases). +/storage/* +!/storage/.keep +/tmp/storage/* +!/tmp/storage/.keep + +# Ignore CI service files. +/.github + +# Ignore development files +/.devcontainer + +# Ignore Docker-related files +/.dockerignore +/Dockerfile* diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8dc4323 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +# See https://git-scm.com/docs/gitattributes for more about git attribute files. + +# Mark the database schema as having been generated. +db/schema.rb linguist-generated + +# Mark any vendored files as having been vendored. +vendor/* linguist-vendored +config/credentials/*.yml.enc diff=rails_credentials +config/credentials.yml.enc diff=rails_credentials diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..ce1856e --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +version: 2 +updates: + - package-ecosystem: bundler + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 + - package-ecosystem: github-actions + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d063cae --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,73 @@ +name: CI + +on: + pull_request: + push: + branches: [ main ] + +jobs: + scan_ruby: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: .ruby-version + bundler-cache: true + + - name: Scan for common Rails security vulnerabilities using static analysis + run: bin/brakeman --no-pager + + scan_js: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: .ruby-version + bundler-cache: true + + - name: Scan for security vulnerabilities in JavaScript dependencies + run: bin/importmap audit + + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: .ruby-version + bundler-cache: true + + - name: Lint code for consistent style + run: bin/rubocop -f github + + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: .ruby-version + bundler-cache: true + + - name: Install dependencies + run: bundle install + + - name: Run RSpec tests + run: bundle exec rspec diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ba3862 --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# Temporary files generated by your text editor or operating system +# belong in git's global ignore instead: +# `$XDG_CONFIG_HOME/git/ignore` or `~/.config/git/ignore` + +# Ignore bundler config. +/.bundle + +# Ignore all environment files (except templates). +/.env* +!/.env*.erb + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore pidfiles, but keep the directory. +/tmp/pids/* +!/tmp/pids/ +!/tmp/pids/.keep + +# Ignore storage (uploaded files in development and any SQLite databases). +/storage/* +!/storage/.keep +/tmp/storage/* +!/tmp/storage/ +!/tmp/storage/.keep + +# Ignore master key for decrypting credentials and more. +/config/master.key diff --git a/.idea/commercecore-product-management-service.iml b/.idea/commercecore-product-management-service.iml new file mode 100644 index 0000000..a25fd67 --- /dev/null +++ b/.idea/commercecore-product-management-service.iml @@ -0,0 +1,555 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + file://$MODULE_DIR$/app + + + file://$MODULE_DIR$/app/assets + + + file://$MODULE_DIR$/app/channels + + + file://$MODULE_DIR$/app/controllers + + + file://$MODULE_DIR$/app/helpers + + + file://$MODULE_DIR$/app/mailers + + + file://$MODULE_DIR$/app/models + + + file://$MODULE_DIR$/app/views + + + file://$MODULE_DIR$/config + + + file://$MODULE_DIR$/config/cable.yml + + + file://$MODULE_DIR$/config/database.yml + + + file://$MODULE_DIR$/config/environment.rb + + + file://$MODULE_DIR$/config/environments + + + file://$MODULE_DIR$/config/initializers + + + file://$MODULE_DIR$/config/locales + + + file://$MODULE_DIR$/config/routes + + + file://$MODULE_DIR$/config/routes.rb + + + file://$MODULE_DIR$/db + + + file://$MODULE_DIR$/db/migrate + + + file://$MODULE_DIR$/db/seeds.rb + + + file://$MODULE_DIR$/lib + + + file://$MODULE_DIR$/lib/assets + + + file://$MODULE_DIR$/lib/tasks + + + file://$MODULE_DIR$/lib/templates + + + file://$MODULE_DIR$/log/development.log + + + file://$MODULE_DIR$/public + + + file://$MODULE_DIR$/public/javascripts + + + file://$MODULE_DIR$/public/stylesheets + + + file://$MODULE_DIR$/spec/mailers/previews + file://$MODULE_DIR$/test/mailers/previews + file://$MODULE_DIR$/test/mailers/previews + + + file://$MODULE_DIR$/tmp + + + file://$MODULE_DIR$/vendor + + + file://$MODULE_DIR$/vendor/assets + + + + + + \ No newline at end of file diff --git a/.idea/dataSources.local.xml b/.idea/dataSources.local.xml new file mode 100644 index 0000000..28ee74b --- /dev/null +++ b/.idea/dataSources.local.xml @@ -0,0 +1,20 @@ + + + + + + " + + + master_key + thelazyprogrammer + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..f318a8d --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + postgresql + true + org.postgresql.Driver + jdbc:postgresql://localhost:5432/commercecore_product_management_service_development + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/dataSources/998b672d-5b09-4c86-b8e1-367e51781704.xml b/.idea/dataSources/998b672d-5b09-4c86-b8e1-367e51781704.xml new file mode 100644 index 0000000..570b2d8 --- /dev/null +++ b/.idea/dataSources/998b672d-5b09-4c86-b8e1-367e51781704.xml @@ -0,0 +1,4416 @@ + + + + + mdy + 1||-9223372036854775808|c|G +1||10|c|G +1||10|C|G +1||10|T|G +4||-9223372036854775808|c|G +4||10|c|G +4||10|C|G +4||10|T|G + 2096 + 16.4 + 1725658132 + true ACDT +true ACSST +false ACST +false ACT +false ACWST +true ADT +true AEDT +true AESST +false AEST +false AFT +true AKDT +false AKST +true ALMST +false ALMT +false AMST +false AMT +false ANAST +false ANAT +false ARST +false ART +false AST +true AWSST +false AWST +true AZOST +false AZOT +false AZST +false AZT +false Africa/Abidjan +false Africa/Accra +false Africa/Addis_Ababa +false Africa/Algiers +false Africa/Asmara +false Africa/Bamako +false Africa/Bangui +false Africa/Banjul +false Africa/Bissau +false Africa/Blantyre +false Africa/Brazzaville +false Africa/Bujumbura +true Africa/Cairo +false Africa/Casablanca +true Africa/Ceuta +false Africa/Conakry +false Africa/Dakar +false Africa/Dar_es_Salaam +false Africa/Djibouti +false Africa/Douala +false Africa/El_Aaiun +false Africa/Freetown +false Africa/Gaborone +false Africa/Harare +false Africa/Johannesburg +false Africa/Juba +false Africa/Kampala +false Africa/Khartoum +false Africa/Kigali +false Africa/Kinshasa +false Africa/Lagos +false Africa/Libreville +false Africa/Lome +false Africa/Luanda +false Africa/Lubumbashi +false Africa/Lusaka +false Africa/Malabo +false Africa/Maputo +false Africa/Maseru +false Africa/Mbabane +false Africa/Mogadishu +false Africa/Monrovia +false Africa/Nairobi +false Africa/Ndjamena +false Africa/Niamey +false Africa/Nouakchott +false Africa/Ouagadougou +false Africa/Porto-Novo +false Africa/Sao_Tome +false Africa/Timbuktu +false Africa/Tripoli +false Africa/Tunis +false Africa/Windhoek +true America/Adak +true America/Anchorage +false America/Anguilla +false America/Antigua +false America/Araguaina +false America/Argentina/Buenos_Aires +false America/Argentina/Catamarca +false America/Argentina/Cordoba +false America/Argentina/Jujuy +false America/Argentina/La_Rioja +false America/Argentina/Mendoza +false America/Argentina/Rio_Gallegos +false America/Argentina/Salta +false America/Argentina/San_Juan +false America/Argentina/San_Luis +false America/Argentina/Tucuman +false America/Argentina/Ushuaia +false America/Aruba +false America/Asuncion +false America/Atikokan +true America/Atka +false America/Bahia +false America/Bahia_Banderas +false America/Barbados +false America/Belem +false America/Belize +false America/Blanc-Sablon +false America/Boa_Vista +false America/Bogota +true America/Boise +true America/Cambridge_Bay +false America/Campo_Grande +false America/Cancun +false America/Caracas +false America/Cayenne +false America/Cayman +true America/Chicago +false America/Chihuahua +true America/Ciudad_Juarez +false America/Coral_Harbour +false America/Costa_Rica +false America/Creston +false America/Cuiaba +false America/Curacao +false America/Danmarkshavn +false America/Dawson +false America/Dawson_Creek +true America/Denver +true America/Detroit +false America/Dominica +true America/Edmonton +false America/Eirunepe +false America/El_Salvador +true America/Ensenada +false America/Fort_Nelson +false America/Fortaleza +true America/Glace_Bay +true America/Goose_Bay +true America/Grand_Turk +false America/Grenada +false America/Guadeloupe +false America/Guatemala +false America/Guayaquil +false America/Guyana +true America/Halifax +true America/Havana +false America/Hermosillo +true America/Indiana/Indianapolis +true America/Indiana/Knox +true America/Indiana/Marengo +true America/Indiana/Petersburg +true America/Indiana/Tell_City +true America/Indiana/Vevay +true America/Indiana/Vincennes +true America/Indiana/Winamac +true America/Inuvik +true America/Iqaluit +false America/Jamaica +true America/Juneau +true America/Kentucky/Louisville +true America/Kentucky/Monticello +false America/Kralendijk +false America/La_Paz +false America/Lima +true America/Los_Angeles +false America/Lower_Princes +false America/Maceio +false America/Managua +false America/Manaus +false America/Marigot +false America/Martinique +true America/Matamoros +false America/Mazatlan +true America/Menominee +false America/Merida +true America/Metlakatla +false America/Mexico_City +true America/Miquelon +true America/Moncton +false America/Monterrey +false America/Montevideo +true America/Montreal +false America/Montserrat +true America/Nassau +true America/New_York +true America/Nipigon +true America/Nome +false America/Noronha +true America/North_Dakota/Beulah +true America/North_Dakota/Center +true America/North_Dakota/New_Salem +true America/Nuuk +true America/Ojinaga +false America/Panama +true America/Pangnirtung +false America/Paramaribo +false America/Phoenix +true America/Port-au-Prince +false America/Port_of_Spain +false America/Porto_Acre +false America/Porto_Velho +false America/Puerto_Rico +false America/Punta_Arenas +true America/Rainy_River +true America/Rankin_Inlet +false America/Recife +false America/Regina +true America/Resolute +false America/Rio_Branco +true America/Santa_Isabel +false America/Santarem +false America/Santiago +false America/Santo_Domingo +false America/Sao_Paulo +true America/Scoresbysund +true America/Shiprock +true America/Sitka +false America/St_Barthelemy +true America/St_Johns +false America/St_Kitts +false America/St_Lucia +false America/St_Thomas +false America/St_Vincent +false America/Swift_Current +false America/Tegucigalpa +true America/Thule +true America/Thunder_Bay +true America/Tijuana +true America/Toronto +false America/Tortola +true America/Vancouver +false America/Virgin +false America/Whitehorse +true America/Winnipeg +true America/Yakutat +true America/Yellowknife +false Antarctica/Casey +false Antarctica/Davis +false Antarctica/DumontDUrville +false Antarctica/Macquarie +false Antarctica/Mawson +false Antarctica/McMurdo +false Antarctica/Palmer +false Antarctica/Rothera +false Antarctica/Syowa +true Antarctica/Troll +false Antarctica/Vostok +true Arctic/Longyearbyen +false Asia/Aden +false Asia/Almaty +false Asia/Amman +false Asia/Anadyr +false Asia/Aqtau +false Asia/Aqtobe +false Asia/Ashgabat +false Asia/Atyrau +false Asia/Baghdad +false Asia/Bahrain +false Asia/Baku +false Asia/Bangkok +false Asia/Barnaul +true Asia/Beirut +false Asia/Bishkek +false Asia/Brunei +false Asia/Chita +false Asia/Choibalsan +false Asia/Chongqing +false Asia/Colombo +false Asia/Damascus +false Asia/Dhaka +false Asia/Dili +false Asia/Dubai +false Asia/Dushanbe +true Asia/Famagusta +true Asia/Gaza +false Asia/Harbin +true Asia/Hebron +false Asia/Ho_Chi_Minh +false Asia/Hong_Kong +false Asia/Hovd +false Asia/Irkutsk +false Asia/Istanbul +false Asia/Jakarta +false Asia/Jayapura +true Asia/Jerusalem +false Asia/Kabul +false Asia/Kamchatka +false Asia/Karachi +false Asia/Kashgar +false Asia/Kathmandu +false Asia/Khandyga +false Asia/Kolkata +false Asia/Krasnoyarsk +false Asia/Kuala_Lumpur +false Asia/Kuching +false Asia/Kuwait +false Asia/Macau +false Asia/Magadan +false Asia/Makassar +false Asia/Manila +false Asia/Muscat +true Asia/Nicosia +false Asia/Novokuznetsk +false Asia/Novosibirsk +false Asia/Omsk +false Asia/Oral +false Asia/Phnom_Penh +false Asia/Pontianak +false Asia/Pyongyang +false Asia/Qatar +false Asia/Qostanay +false Asia/Qyzylorda +false Asia/Riyadh +false Asia/Sakhalin +false Asia/Samarkand +false Asia/Seoul +false Asia/Shanghai +false Asia/Singapore +false Asia/Srednekolymsk +false Asia/Taipei +false Asia/Tashkent +false Asia/Tbilisi +false Asia/Tehran +true Asia/Tel_Aviv +false Asia/Thimphu +false Asia/Tokyo +false Asia/Tomsk +false Asia/Ulaanbaatar +false Asia/Urumqi +false Asia/Ust-Nera +false Asia/Vientiane +false Asia/Vladivostok +false Asia/Yakutsk +false Asia/Yangon +false Asia/Yekaterinburg +false Asia/Yerevan +true Atlantic/Azores +true Atlantic/Bermuda +true Atlantic/Canary +false Atlantic/Cape_Verde +true Atlantic/Faroe +true Atlantic/Jan_Mayen +true Atlantic/Madeira +false Atlantic/Reykjavik +false Atlantic/South_Georgia +false Atlantic/St_Helena +false Atlantic/Stanley +false Australia/Adelaide +false Australia/Brisbane +false Australia/Broken_Hill +false Australia/Canberra +false Australia/Currie +false Australia/Darwin +false Australia/Eucla +false Australia/Hobart +false Australia/Lindeman +false Australia/Lord_Howe +false Australia/Melbourne +false Australia/Perth +false Australia/Sydney +false Australia/Yancowinna +true BDST +false BDT +false BNT +false BORT +false BOT +false BRA +true BRST +false BRT +true BST +false BTT +true CADT +false CAST +false CCT +true CDT +true CEST +false CET +true CETDST +true CHADT +false CHAST +false CHUT +false CKT +true CLST +false CLT +false COT +false CST +true CST6CDT +false CXT +false DAVT +false DDUT +false EASST +false EAST +false EAT +true EDT +true EEST +false EET +true EETDST +true EGST +false EGT +false EST +true EST5EDT +false Etc/GMT +false Etc/GMT+0 +false Etc/GMT+1 +false Etc/GMT+10 +false Etc/GMT+11 +false Etc/GMT+12 +false Etc/GMT+2 +false Etc/GMT+3 +false Etc/GMT+4 +false Etc/GMT+5 +false Etc/GMT+6 +false Etc/GMT+7 +false Etc/GMT+8 +false Etc/GMT+9 +false Etc/GMT-0 +false Etc/GMT-1 +false Etc/GMT-10 +false Etc/GMT-11 +false Etc/GMT-12 +false Etc/GMT-13 +false Etc/GMT-14 +false Etc/GMT-2 +false Etc/GMT-3 +false Etc/GMT-4 +false Etc/GMT-5 +false Etc/GMT-6 +false Etc/GMT-7 +false Etc/GMT-8 +false Etc/GMT-9 +false Etc/GMT0 +false Etc/Greenwich +false Etc/UCT +false Etc/UTC +false Etc/Universal +false Etc/Zulu +true Europe/Amsterdam +true Europe/Andorra +false Europe/Astrakhan +true Europe/Athens +true Europe/Belfast +true Europe/Belgrade +true Europe/Berlin +true Europe/Bratislava +true Europe/Brussels +true Europe/Bucharest +true Europe/Budapest +true Europe/Busingen +true Europe/Chisinau +true Europe/Copenhagen +false Europe/Dublin +true Europe/Gibraltar +true Europe/Guernsey +true Europe/Helsinki +true Europe/Isle_of_Man +false Europe/Istanbul +true Europe/Jersey +false Europe/Kaliningrad +false Europe/Kirov +true Europe/Kyiv +true Europe/Lisbon +true Europe/Ljubljana +true Europe/London +true Europe/Luxembourg +true Europe/Madrid +true Europe/Malta +true Europe/Mariehamn +false Europe/Minsk +true Europe/Monaco +false Europe/Moscow +true Europe/Nicosia +true Europe/Oslo +true Europe/Paris +true Europe/Podgorica +true Europe/Prague +true Europe/Riga +true Europe/Rome +false Europe/Samara +true Europe/San_Marino +true Europe/Sarajevo +false Europe/Saratov +false Europe/Simferopol +true Europe/Skopje +true Europe/Sofia +true Europe/Stockholm +true Europe/Tallinn +true Europe/Tirane +true Europe/Tiraspol +false Europe/Ulyanovsk +true Europe/Vaduz +true Europe/Vatican +true Europe/Vienna +true Europe/Vilnius +false Europe/Volgograd +true Europe/Warsaw +true Europe/Zagreb +true Europe/Zurich +false FET +true FJST +false FJT +false FKST +false FKT +true FNST +false FNT +false Factory +false GALT +false GAMT +false GEST +false GET +false GFT +false GILT +false GMT +false GYT +false HKT +false HST +false ICT +true IDT +false IOT +false IRKST +false IRKT +false IRT +false IST +false Indian/Antananarivo +false Indian/Chagos +false Indian/Christmas +false Indian/Cocos +false Indian/Comoro +false Indian/Kerguelen +false Indian/Mahe +false Indian/Maldives +false Indian/Mauritius +false Indian/Mayotte +false Indian/Reunion +false JAYT +false JST +true KDT +true KGST +false KGT +false KOST +false KRAST +false KRAT +false KST +false LHDT +false LHST +false LIGT +false LINT +false LKT +false MAGST +false MAGT +false MART +false MAWT +true MDT +true MEST +true MESZ +true MET +true METDST +false MEZ +false MHT +false MMT +false MPT +true MSD +false MSK +false MST +true MST7MDT +true MUST +false MUT +false MVT +false MYT +true NDT +false NFT +false NOVST +false NOVT +false NPT +false NST +false NUT +true NZDT +false NZST +false NZT +false OMSST +false OMST +true PDT +false PET +false PETST +false PETT +false PGT +false PHT +true PKST +false PKT +true PMDT +false PMST +false PONT +false PST +true PST8PDT +false PWT +true PYST +false PYT +false Pacific/Apia +false Pacific/Auckland +false Pacific/Bougainville +false Pacific/Chatham +false Pacific/Chuuk +false Pacific/Easter +false Pacific/Efate +false Pacific/Fakaofo +false Pacific/Fiji +false Pacific/Funafuti +false Pacific/Galapagos +false Pacific/Gambier +false Pacific/Guadalcanal +false Pacific/Guam +false Pacific/Honolulu +false Pacific/Johnston +false Pacific/Kanton +false Pacific/Kiritimati +false Pacific/Kosrae +false Pacific/Kwajalein +false Pacific/Majuro +false Pacific/Marquesas +false Pacific/Midway +false Pacific/Nauru +false Pacific/Niue +false Pacific/Norfolk +false Pacific/Noumea +false Pacific/Pago_Pago +false Pacific/Palau +false Pacific/Pitcairn +false Pacific/Pohnpei +false Pacific/Port_Moresby +false Pacific/Rarotonga +false Pacific/Saipan +false Pacific/Samoa +false Pacific/Tahiti +false Pacific/Tarawa +false Pacific/Tongatapu +false Pacific/Wake +false Pacific/Wallis +false Pacific/Yap +false RET +true SADT +false SAST +false SCT +false SGT +false TAHT +false TFT +false TJT +false TKT +false TMT +false TOT +false TRUT +false TVT +false UCT +true ULAST +false ULAT +false UT +false UTC +true UYST +false UYT +true UZST +false UZT +false VET +false VLAST +false VLAT +false VOLT +false VUT +true WADT +false WAKT +false WAST +false WAT +true WDT +true WET +true WETDST +false WFT +true WGST +false WGT +false XJT +false YAKST +false YAKT +false YAPT +true YEKST +false YEKT +false Z +false ZULU +false localtime +true posixrules + + + + 16450 + thelazyprogrammer + + + 16451 + thelazyprogrammer + + + 1 + 11||10|C|G +11||-9223372036854775808|U|G +11||10|U|G +2200||6171|C|G +2200||-9223372036854775808|U|G +2200||6171|U|G +13292||10|C|G +13292||-9223372036854775808|U|G +13292||10|U|G + 2096 + 16881 + thelazyprogrammer + + + 16933 + thelazyprogrammer + + + default administrative connection database + 5 + postgres + + + 16792 + thelazyprogrammer + + + 16670 + thelazyprogrammer + + + 4544 + + + 6304 + + + 6171 + + + 4571 + + + 3373 + 3374 +3375 +3377 + + + 6181 + + + 3374 + + + 3375 + + + 4569 + + + 4200 + + + 3377 + + + 4550 + + + 6182 + + + 4570 + + + 1 + 1 + 1 + 1 + 10 + 1 + 1 + + + 1 + 1 + 16388 + + + 1663 + 1 + postgres + + + 1664 + 1 + postgres + + + block range index (BRIN) access method + 3580 + 1 + index + 335 + brinhandler + pg_catalog + + + b-tree index access method + 403 + 1 + index + 330 + bthandler + pg_catalog + + + GIN index access method + 2742 + 1 + index + 333 + ginhandler + pg_catalog + + + GiST index access method + 783 + 1 + index + 332 + gisthandler + pg_catalog + + + hash index access method + 405 + 1 + index + 331 + hashhandler + pg_catalog + + + heap table access method + 2 + 1 + table + 3 + heap_tableam_handler + pg_catalog + + + SP-GiST index access method + 4000 + 1 + index + 334 + spghandler + pg_catalog + + + explicit + function + 10035 + 1 + 2558 + int4 + pg_catalog + 16 + bool + pg_catalog + 23 + int4 + pg_catalog + + + assignment + function + 10201 + 1 + 2971 + text + pg_catalog + 16 + bool + pg_catalog + 1042 + bpchar + pg_catalog + + + assignment + function + 10191 + 1 + 2971 + text + pg_catalog + 16 + bool + pg_catalog + 25 + text + pg_catalog + + + assignment + function + 10196 + 1 + 2971 + text + pg_catalog + 16 + bool + pg_catalog + 1043 + varchar + pg_catalog + + + explicit + function + 10143 + 1 + 77 + int4 + pg_catalog + 18 + char + pg_catalog + 23 + int4 + pg_catalog + + + assignment + function + 10133 + 1 + 946 + text + pg_catalog + 18 + char + pg_catalog + 1043 + varchar + pg_catalog + + + implicit + function + 10131 + 1 + 946 + text + pg_catalog + 18 + char + pg_catalog + 25 + text + pg_catalog + + + assignment + function + 10132 + 1 + 860 + bpchar + pg_catalog + 18 + char + pg_catalog + 1042 + bpchar + pg_catalog + + + assignment + function + 10135 + 1 + 408 + bpchar + pg_catalog + 19 + name + pg_catalog + 1042 + bpchar + pg_catalog + + + implicit + function + 10134 + 1 + 406 + text + pg_catalog + 19 + name + pg_catalog + 25 + text + pg_catalog + + + assignment + function + 10136 + 1 + 1401 + varchar + pg_catalog + 19 + name + pg_catalog + 1043 + varchar + pg_catalog + + + implicit + function + 10090 + 1 + 1287 + oid + pg_catalog + 20 + int8 + pg_catalog + 2206 + regtype + pg_catalog + + + implicit + function + 10060 + 1 + 1287 + oid + pg_catalog + 20 + int8 + pg_catalog + 2203 + regoper + pg_catalog + + + implicit + function + 10003 + 1 + 482 + float8 + pg_catalog + 20 + int8 + pg_catalog + 701 + float8 + pg_catalog + + + implicit + function + 10069 + 1 + 1287 + oid + pg_catalog + 20 + int8 + pg_catalog + 2204 + regoperator + pg_catalog + + + assignment + function + 10001 + 1 + 480 + int4 + pg_catalog + 20 + int8 + pg_catalog + 23 + int4 + pg_catalog + + + implicit + function + 10044 + 1 + 1287 + oid + pg_catalog + 20 + int8 + pg_catalog + 24 + regproc + pg_catalog + + + implicit + function + 10113 + 1 + 1287 + oid + pg_catalog + 20 + int8 + pg_catalog + 4096 + regrole + pg_catalog + + + implicit + function + 10120 + 1 + 1287 + oid + pg_catalog + 20 + int8 + pg_catalog + 4089 + regnamespace + pg_catalog + + + implicit + function + 10002 + 1 + 652 + float4 + pg_catalog + 20 + int8 + pg_catalog + 700 + float4 + pg_catalog + + + implicit + function + 10104 + 1 + 1287 + oid + pg_catalog + 20 + int8 + pg_catalog + 3769 + regdictionary + pg_catalog + + + implicit + function + 10083 + 1 + 1287 + oid + pg_catalog + 20 + int8 + pg_catalog + 4191 + regcollation + pg_catalog + + + assignment + function + 10033 + 1 + 3812 + money + pg_catalog + 20 + int8 + pg_catalog + 790 + money + pg_catalog + + + implicit + function + 10037 + 1 + 1287 + oid + pg_catalog + 20 + int8 + pg_catalog + 26 + oid + pg_catalog + + + implicit + function + 10097 + 1 + 1287 + oid + pg_catalog + 20 + int8 + pg_catalog + 3734 + regconfig + pg_catalog + + + assignment + function + 10000 + 1 + 714 + int2 + pg_catalog + 20 + int8 + pg_catalog + 21 + int2 + pg_catalog + + + explicit + function + 10185 + 1 + 2075 + bit + pg_catalog + 20 + int8 + pg_catalog + 1560 + bit + pg_catalog + + + implicit + function + 10004 + 1 + 1781 + numeric + pg_catalog + 20 + int8 + pg_catalog + 1700 + numeric + pg_catalog + + + implicit + function + 10053 + 1 + 1287 + oid + pg_catalog + 20 + int8 + pg_catalog + 2202 + regprocedure + pg_catalog + + + implicit + function + 10076 + 1 + 1287 + oid + pg_catalog + 20 + int8 + pg_catalog + 2205 + regclass + pg_catalog + + + implicit + function + 10045 + 1 + 313 + int4 + pg_catalog + 21 + int2 + pg_catalog + 24 + regproc + pg_catalog + + + implicit + function + 10091 + 1 + 313 + int4 + pg_catalog + 21 + int2 + pg_catalog + 2206 + regtype + pg_catalog + + + implicit + function + 10084 + 1 + 313 + int4 + pg_catalog + 21 + int2 + pg_catalog + 4191 + regcollation + pg_catalog + + + implicit + function + 10070 + 1 + 313 + int4 + pg_catalog + 21 + int2 + pg_catalog + 2204 + regoperator + pg_catalog + + + implicit + function + 10038 + 1 + 313 + int4 + pg_catalog + 21 + int2 + pg_catalog + 26 + oid + pg_catalog + + + implicit + function + 10009 + 1 + 1782 + numeric + pg_catalog + 21 + int2 + pg_catalog + 1700 + numeric + pg_catalog + + + implicit + function + 10077 + 1 + 313 + int4 + pg_catalog + 21 + int2 + pg_catalog + 2205 + regclass + pg_catalog + + + implicit + function + 10006 + 1 + 313 + int4 + pg_catalog + 21 + int2 + pg_catalog + 23 + int4 + pg_catalog + + + implicit + function + 10054 + 1 + 313 + int4 + pg_catalog + 21 + int2 + pg_catalog + 2202 + regprocedure + pg_catalog + + + implicit + function + 10007 + 1 + 236 + float4 + pg_catalog + 21 + int2 + pg_catalog + 700 + float4 + pg_catalog + + + implicit + function + 10005 + 1 + 754 + int8 + pg_catalog + 21 + int2 + pg_catalog + 20 + int8 + pg_catalog + + + implicit + function + 10114 + 1 + 313 + int4 + pg_catalog + 21 + int2 + pg_catalog + 4096 + regrole + pg_catalog + + + implicit + function + 10008 + 1 + 235 + float8 + pg_catalog + 21 + int2 + pg_catalog + 701 + float8 + pg_catalog + + + implicit + function + 10105 + 1 + 313 + int4 + pg_catalog + 21 + int2 + pg_catalog + 3769 + regdictionary + pg_catalog + + + implicit + function + 10121 + 1 + 313 + int4 + pg_catalog + 21 + int2 + pg_catalog + 4089 + regnamespace + pg_catalog + + + implicit + function + 10061 + 1 + 313 + int4 + pg_catalog + 21 + int2 + pg_catalog + 2203 + regoper + pg_catalog + + + implicit + function + 10098 + 1 + 313 + int4 + pg_catalog + 21 + int2 + pg_catalog + 3734 + regconfig + pg_catalog + + + implicit + binary + 10078 + 1 + 23 + int4 + pg_catalog + 2205 + regclass + pg_catalog + + + implicit + binary + 10085 + 1 + 23 + int4 + pg_catalog + 4191 + regcollation + pg_catalog + + + implicit + binary + 10115 + 1 + 23 + int4 + pg_catalog + 4096 + regrole + pg_catalog + + + explicit + function + 10144 + 1 + 78 + char + pg_catalog + 23 + int4 + pg_catalog + 18 + char + pg_catalog + + + implicit + binary + 10122 + 1 + 23 + int4 + pg_catalog + 4089 + regnamespace + pg_catalog + + + implicit + function + 10010 + 1 + 481 + int8 + pg_catalog + 23 + int4 + pg_catalog + 20 + int8 + pg_catalog + + + implicit + binary + 10106 + 1 + 23 + int4 + pg_catalog + 3769 + regdictionary + pg_catalog + + + implicit + binary + 10099 + 1 + 23 + int4 + pg_catalog + 3734 + regconfig + pg_catalog + + + assignment + function + 10011 + 1 + 314 + int2 + pg_catalog + 23 + int4 + pg_catalog + 21 + int2 + pg_catalog + + + implicit + binary + 10092 + 1 + 23 + int4 + pg_catalog + 2206 + regtype + pg_catalog + + + implicit + binary + 10071 + 1 + 23 + int4 + pg_catalog + 2204 + regoperator + pg_catalog + + + implicit + binary + 10062 + 1 + 23 + int4 + pg_catalog + 2203 + regoper + pg_catalog + + + implicit + binary + 10046 + 1 + 23 + int4 + pg_catalog + 24 + regproc + pg_catalog + + + implicit + binary + 10055 + 1 + 23 + int4 + pg_catalog + 2202 + regprocedure + pg_catalog + + + explicit + function + 10034 + 1 + 2557 + bool + pg_catalog + 23 + int4 + pg_catalog + 16 + bool + pg_catalog + + + implicit + function + 10014 + 1 + 1740 + numeric + pg_catalog + 23 + int4 + pg_catalog + 1700 + numeric + pg_catalog + + + implicit + binary + 10039 + 1 + 23 + int4 + pg_catalog + 26 + oid + pg_catalog + + + explicit + function + 10186 + 1 + 1683 + bit + pg_catalog + 23 + int4 + pg_catalog + 1560 + bit + pg_catalog + + + implicit + function + 10012 + 1 + 318 + float4 + pg_catalog + 23 + int4 + pg_catalog + 700 + float4 + pg_catalog + + + implicit + function + 10013 + 1 + 316 + float8 + pg_catalog + 23 + int4 + pg_catalog + 701 + float8 + pg_catalog + + + assignment + function + 10032 + 1 + 3811 + money + pg_catalog + 23 + int4 + pg_catalog + 790 + money + pg_catalog + + + assignment + binary + 10048 + 1 + 24 + regproc + pg_catalog + 23 + int4 + pg_catalog + + + assignment + function + 10047 + 1 + 1288 + int8 + pg_catalog + 24 + regproc + pg_catalog + 20 + int8 + pg_catalog + + + implicit + binary + 10043 + 1 + 24 + regproc + pg_catalog + 26 + oid + pg_catalog + + + implicit + binary + 10049 + 1 + 24 + regproc + pg_catalog + 2202 + regprocedure + pg_catalog + + + implicit + binary + 10125 + 1 + 25 + text + pg_catalog + 1042 + bpchar + pg_catalog + + + implicit + function + 10140 + 1 + 407 + name + pg_catalog + 25 + text + pg_catalog + 19 + name + pg_catalog + + + assignment + function + 10137 + 1 + 944 + char + pg_catalog + 25 + text + pg_catalog + 18 + char + pg_catalog + + + implicit + binary + 10126 + 1 + 25 + text + pg_catalog + 1043 + varchar + pg_catalog + + + explicit + function + 10193 + 1 + 2896 + xml + pg_catalog + 25 + text + pg_catalog + 142 + xml + pg_catalog + + + implicit + function + 10109 + 1 + 1079 + regclass + pg_catalog + 25 + text + pg_catalog + 2205 + regclass + pg_catalog + + + implicit + binary + 10074 + 1 + 26 + oid + pg_catalog + 2205 + regclass + pg_catalog + + + implicit + binary + 10051 + 1 + 26 + oid + pg_catalog + 2202 + regprocedure + pg_catalog + + + implicit + binary + 10095 + 1 + 26 + oid + pg_catalog + 3734 + regconfig + pg_catalog + + + implicit + binary + 10058 + 1 + 26 + oid + pg_catalog + 2203 + regoper + pg_catalog + + + implicit + binary + 10081 + 1 + 26 + oid + pg_catalog + 4191 + regcollation + pg_catalog + + + implicit + binary + 10067 + 1 + 26 + oid + pg_catalog + 2204 + regoperator + pg_catalog + + + implicit + binary + 10042 + 1 + 26 + oid + pg_catalog + 24 + regproc + pg_catalog + + + assignment + function + 10040 + 1 + 1288 + int8 + pg_catalog + 26 + oid + pg_catalog + 20 + int8 + pg_catalog + + + implicit + binary + 10111 + 1 + 26 + oid + pg_catalog + 4096 + regrole + pg_catalog + + + implicit + binary + 10102 + 1 + 26 + oid + pg_catalog + 3769 + regdictionary + pg_catalog + + + implicit + binary + 10088 + 1 + 26 + oid + pg_catalog + 2206 + regtype + pg_catalog + + + assignment + binary + 10041 + 1 + 26 + oid + pg_catalog + 23 + int4 + pg_catalog + + + implicit + binary + 10118 + 1 + 26 + oid + pg_catalog + 4089 + regnamespace + pg_catalog + + + assignment + io + 10214 + 1 + 114 + json + pg_catalog + 3802 + jsonb + pg_catalog + + + assignment + binary + 10202 + 1 + 142 + xml + pg_catalog + 1042 + bpchar + pg_catalog + + + assignment + binary + 10197 + 1 + 142 + xml + pg_catalog + 1043 + varchar + pg_catalog + + + assignment + binary + 10192 + 1 + 142 + xml + pg_catalog + 25 + text + pg_catalog + + + implicit + binary + 10145 + 1 + 194 + pg_node_tree + pg_catalog + 25 + text + pg_catalog + + + assignment + function + 10165 + 1 + 4091 + box + pg_catalog + 600 + point + pg_catalog + 603 + box + pg_catalog + + + explicit + function + 10166 + 1 + 1532 + point + pg_catalog + 601 + lseg + pg_catalog + 600 + point + pg_catalog + + + assignment + function + 10167 + 1 + 1449 + polygon + pg_catalog + 602 + path + pg_catalog + 604 + polygon + pg_catalog + + + explicit + function + 10168 + 1 + 1534 + point + pg_catalog + 603 + box + pg_catalog + 600 + point + pg_catalog + + + explicit + function + 10171 + 1 + 1479 + circle + pg_catalog + 603 + box + pg_catalog + 718 + circle + pg_catalog + + + explicit + function + 10169 + 1 + 1541 + lseg + pg_catalog + 603 + box + pg_catalog + 601 + lseg + pg_catalog + + + assignment + function + 10170 + 1 + 1448 + polygon + pg_catalog + 603 + box + pg_catalog + 604 + polygon + pg_catalog + + + explicit + function + 10172 + 1 + 1540 + point + pg_catalog + 604 + polygon + pg_catalog + 600 + point + pg_catalog + + + explicit + function + 10175 + 1 + 1474 + circle + pg_catalog + 604 + polygon + pg_catalog + 718 + circle + pg_catalog + + + explicit + function + 10174 + 1 + 1446 + box + pg_catalog + 604 + polygon + pg_catalog + 603 + box + pg_catalog + + + assignment + function + 10173 + 1 + 1447 + path + pg_catalog + 604 + polygon + pg_catalog + 602 + path + pg_catalog + + + assignment + function + 10194 + 1 + 730 + text + pg_catalog + 650 + cidr + pg_catalog + 1043 + varchar + pg_catalog + + + assignment + function + 10199 + 1 + 730 + text + pg_catalog + 650 + cidr + pg_catalog + 1042 + bpchar + pg_catalog + + + assignment + function + 10189 + 1 + 730 + text + pg_catalog + 650 + cidr + pg_catalog + 25 + text + pg_catalog + + + implicit + binary + 10181 + 1 + 650 + cidr + pg_catalog + 869 + inet + pg_catalog + + + assignment + function + 10016 + 1 + 238 + int2 + pg_catalog + 700 + float4 + pg_catalog + 21 + int2 + pg_catalog + + + assignment + function + 10015 + 1 + 653 + int8 + pg_catalog + 700 + float4 + pg_catalog + 20 + int8 + pg_catalog + + + implicit + function + 10018 + 1 + 311 + float8 + pg_catalog + 700 + float4 + pg_catalog + 701 + float8 + pg_catalog + + + assignment + function + 10019 + 1 + 1742 + numeric + pg_catalog + 700 + float4 + pg_catalog + 1700 + numeric + pg_catalog + + + assignment + function + 10017 + 1 + 319 + int4 + pg_catalog + 700 + float4 + pg_catalog + 23 + int4 + pg_catalog + + + assignment + function + 10024 + 1 + 1743 + numeric + pg_catalog + 701 + float8 + pg_catalog + 1700 + numeric + pg_catalog + + + assignment + function + 10020 + 1 + 483 + int8 + pg_catalog + 701 + float8 + pg_catalog + 20 + int8 + pg_catalog + + + assignment + function + 10021 + 1 + 237 + int2 + pg_catalog + 701 + float8 + pg_catalog + 21 + int2 + pg_catalog + + + assignment + function + 10022 + 1 + 317 + int4 + pg_catalog + 701 + float8 + pg_catalog + 23 + int4 + pg_catalog + + + assignment + function + 10023 + 1 + 312 + float4 + pg_catalog + 701 + float8 + pg_catalog + 700 + float4 + pg_catalog + + + explicit + function + 10178 + 1 + 1544 + polygon + pg_catalog + 718 + circle + pg_catalog + 604 + polygon + pg_catalog + + + explicit + function + 10176 + 1 + 1416 + point + pg_catalog + 718 + circle + pg_catalog + 600 + point + pg_catalog + + + explicit + function + 10177 + 1 + 1480 + box + pg_catalog + 718 + circle + pg_catalog + 603 + box + pg_catalog + + + implicit + function + 10180 + 1 + 4124 + macaddr + pg_catalog + 774 + macaddr8 + pg_catalog + 829 + macaddr + pg_catalog + + + assignment + function + 10030 + 1 + 3823 + numeric + pg_catalog + 790 + money + pg_catalog + 1700 + numeric + pg_catalog + + + implicit + function + 10179 + 1 + 4123 + macaddr8 + pg_catalog + 829 + macaddr + pg_catalog + 774 + macaddr8 + pg_catalog + + + assignment + function + 10195 + 1 + 730 + text + pg_catalog + 869 + inet + pg_catalog + 1043 + varchar + pg_catalog + + + assignment + function + 10190 + 1 + 730 + text + pg_catalog + 869 + inet + pg_catalog + 25 + text + pg_catalog + + + assignment + function + 10182 + 1 + 1715 + cidr + pg_catalog + 869 + inet + pg_catalog + 650 + cidr + pg_catalog + + + assignment + function + 10200 + 1 + 730 + text + pg_catalog + 869 + inet + pg_catalog + 1042 + bpchar + pg_catalog + + + implicit + function + 10204 + 1 + 668 + bpchar + pg_catalog + 1042 + bpchar + pg_catalog + 1042 + bpchar + pg_catalog + + + implicit + function + 10128 + 1 + 401 + text + pg_catalog + 1042 + bpchar + pg_catalog + 1043 + varchar + pg_catalog + + + explicit + function + 10203 + 1 + 2896 + xml + pg_catalog + 1042 + bpchar + pg_catalog + 142 + xml + pg_catalog + + + implicit + function + 10127 + 1 + 401 + text + pg_catalog + 1042 + bpchar + pg_catalog + 25 + text + pg_catalog + + + assignment + function + 10138 + 1 + 944 + char + pg_catalog + 1042 + bpchar + pg_catalog + 18 + char + pg_catalog + + + implicit + function + 10141 + 1 + 409 + name + pg_catalog + 1042 + bpchar + pg_catalog + 19 + name + pg_catalog + + + implicit + binary + 10129 + 1 + 1043 + varchar + pg_catalog + 25 + text + pg_catalog + + + implicit + function + 10142 + 1 + 1400 + name + pg_catalog + 1043 + varchar + pg_catalog + 19 + name + pg_catalog + + + implicit + binary + 10130 + 1 + 1043 + varchar + pg_catalog + 1042 + bpchar + pg_catalog + + + explicit + function + 10198 + 1 + 2896 + xml + pg_catalog + 1043 + varchar + pg_catalog + 142 + xml + pg_catalog + + + implicit + function + 10110 + 1 + 1079 + regclass + pg_catalog + 1043 + varchar + pg_catalog + 2205 + regclass + pg_catalog + + + implicit + function + 10205 + 1 + 669 + varchar + pg_catalog + 1043 + varchar + pg_catalog + 1043 + varchar + pg_catalog + + + assignment + function + 10139 + 1 + 944 + char + pg_catalog + 1043 + varchar + pg_catalog + 18 + char + pg_catalog + + + implicit + function + 10152 + 1 + 2024 + timestamp + pg_catalog + 1082 + date + pg_catalog + 1114 + timestamp + pg_catalog + + + implicit + function + 10153 + 1 + 1174 + timestamptz + pg_catalog + 1082 + date + pg_catalog + 1184 + timestamptz + pg_catalog + + + implicit + function + 10206 + 1 + 1968 + time + pg_catalog + 1083 + time + pg_catalog + 1083 + time + pg_catalog + + + implicit + function + 10155 + 1 + 2047 + timetz + pg_catalog + 1083 + time + pg_catalog + 1266 + timetz + pg_catalog + + + implicit + function + 10154 + 1 + 1370 + interval + pg_catalog + 1083 + time + pg_catalog + 1186 + interval + pg_catalog + + + implicit + function + 10158 + 1 + 2028 + timestamptz + pg_catalog + 1114 + timestamp + pg_catalog + 1184 + timestamptz + pg_catalog + + + assignment + function + 10156 + 1 + 2029 + date + pg_catalog + 1114 + timestamp + pg_catalog + 1082 + date + pg_catalog + + + assignment + function + 10157 + 1 + 1316 + time + pg_catalog + 1114 + timestamp + pg_catalog + 1083 + time + pg_catalog + + + implicit + function + 10207 + 1 + 1961 + timestamp + pg_catalog + 1114 + timestamp + pg_catalog + 1114 + timestamp + pg_catalog + + + assignment + function + 10159 + 1 + 1178 + date + pg_catalog + 1184 + timestamptz + pg_catalog + 1082 + date + pg_catalog + + + assignment + function + 10162 + 1 + 1388 + timetz + pg_catalog + 1184 + timestamptz + pg_catalog + 1266 + timetz + pg_catalog + + + assignment + function + 10160 + 1 + 2019 + time + pg_catalog + 1184 + timestamptz + pg_catalog + 1083 + time + pg_catalog + + + assignment + function + 10161 + 1 + 2027 + timestamp + pg_catalog + 1184 + timestamptz + pg_catalog + 1114 + timestamp + pg_catalog + + + implicit + function + 10208 + 1 + 1967 + timestamptz + pg_catalog + 1184 + timestamptz + pg_catalog + 1184 + timestamptz + pg_catalog + + + implicit + function + 10209 + 1 + 1200 + interval + pg_catalog + 1186 + interval + pg_catalog + 1186 + interval + pg_catalog + + + assignment + function + 10163 + 1 + 1419 + time + pg_catalog + 1186 + interval + pg_catalog + 1083 + time + pg_catalog + + + assignment + function + 10164 + 1 + 2046 + time + pg_catalog + 1266 + timetz + pg_catalog + 1083 + time + pg_catalog + + + implicit + function + 10210 + 1 + 1969 + timetz + pg_catalog + 1266 + timetz + pg_catalog + 1266 + timetz + pg_catalog + + + explicit + function + 10187 + 1 + 2076 + int8 + pg_catalog + 1560 + bit + pg_catalog + 20 + int8 + pg_catalog + + + implicit + function + 10211 + 1 + 1685 + bit + pg_catalog + 1560 + bit + pg_catalog + 1560 + bit + pg_catalog + + + implicit + binary + 10183 + 1 + 1560 + bit + pg_catalog + 1562 + varbit + pg_catalog + + + explicit + function + 10188 + 1 + 1684 + int4 + pg_catalog + 1560 + bit + pg_catalog + 23 + int4 + pg_catalog + + + implicit + binary + 10184 + 1 + 1562 + varbit + pg_catalog + 1560 + bit + pg_catalog + + + implicit + function + 10212 + 1 + 1687 + varbit + pg_catalog + 1562 + varbit + pg_catalog + 1562 + varbit + pg_catalog + + + assignment + function + 10025 + 1 + 1779 + int8 + pg_catalog + 1700 + numeric + pg_catalog + 20 + int8 + pg_catalog + + + assignment + function + 10026 + 1 + 1783 + int2 + pg_catalog + 1700 + numeric + pg_catalog + 21 + int2 + pg_catalog + + + assignment + function + 10027 + 1 + 1744 + int4 + pg_catalog + 1700 + numeric + pg_catalog + 23 + int4 + pg_catalog + + + implicit + function + 10213 + 1 + 1703 + numeric + pg_catalog + 1700 + numeric + pg_catalog + 1700 + numeric + pg_catalog + + + implicit + function + 10029 + 1 + 1746 + float8 + pg_catalog + 1700 + numeric + pg_catalog + 701 + float8 + pg_catalog + + + assignment + function + 10031 + 1 + 3824 + money + pg_catalog + 1700 + numeric + pg_catalog + 790 + money + pg_catalog + + + implicit + function + 10028 + 1 + 1745 + float4 + pg_catalog + 1700 + numeric + pg_catalog + 700 + float4 + pg_catalog + + + assignment + binary + 10057 + 1 + 2202 + regprocedure + pg_catalog + 23 + int4 + pg_catalog + + + implicit + binary + 10052 + 1 + 2202 + regprocedure + pg_catalog + 26 + oid + pg_catalog + + + assignment + function + 10056 + 1 + 1288 + int8 + pg_catalog + 2202 + regprocedure + pg_catalog + 20 + int8 + pg_catalog + + + implicit + binary + 10050 + 1 + 2202 + regprocedure + pg_catalog + 24 + regproc + pg_catalog + + + implicit + binary + 10065 + 1 + 2203 + regoper + pg_catalog + 2204 + regoperator + pg_catalog + + + assignment + function + 10063 + 1 + 1288 + int8 + pg_catalog + 2203 + regoper + pg_catalog + 20 + int8 + pg_catalog + + + implicit + binary + 10059 + 1 + 2203 + regoper + pg_catalog + 26 + oid + pg_catalog + + + assignment + binary + 10064 + 1 + 2203 + regoper + pg_catalog + 23 + int4 + pg_catalog + + + assignment + binary + 10073 + 1 + 2204 + regoperator + pg_catalog + 23 + int4 + pg_catalog + + + implicit + binary + 10068 + 1 + 2204 + regoperator + pg_catalog + 26 + oid + pg_catalog + + + assignment + function + 10072 + 1 + 1288 + int8 + pg_catalog + 2204 + regoperator + pg_catalog + 20 + int8 + pg_catalog + + + implicit + binary + 10066 + 1 + 2204 + regoperator + pg_catalog + 2203 + regoper + pg_catalog + + + assignment + function + 10079 + 1 + 1288 + int8 + pg_catalog + 2205 + regclass + pg_catalog + 20 + int8 + pg_catalog + + + implicit + binary + 10075 + 1 + 2205 + regclass + pg_catalog + 26 + oid + pg_catalog + + + assignment + binary + 10080 + 1 + 2205 + regclass + pg_catalog + 23 + int4 + pg_catalog + + + assignment + function + 10093 + 1 + 1288 + int8 + pg_catalog + 2206 + regtype + pg_catalog + 20 + int8 + pg_catalog + + + assignment + binary + 10094 + 1 + 2206 + regtype + pg_catalog + 23 + int4 + pg_catalog + + + implicit + binary + 10089 + 1 + 2206 + regtype + pg_catalog + 26 + oid + pg_catalog + + + implicit + binary + 10146 + 1 + 3361 + pg_ndistinct + pg_catalog + 17 + bytea + pg_catalog + + + implicit + io + 10147 + 1 + 3361 + pg_ndistinct + pg_catalog + 25 + text + pg_catalog + + + implicit + binary + 10148 + 1 + 3402 + pg_dependencies + pg_catalog + 17 + bytea + pg_catalog + + + implicit + io + 10149 + 1 + 3402 + pg_dependencies + pg_catalog + 25 + text + pg_catalog + + + implicit + binary + 10096 + 1 + 3734 + regconfig + pg_catalog + 26 + oid + pg_catalog + + + assignment + function + 10100 + 1 + 1288 + int8 + pg_catalog + 3734 + regconfig + pg_catalog + 20 + int8 + pg_catalog + + + assignment + binary + 10101 + 1 + 3734 + regconfig + pg_catalog + 23 + int4 + pg_catalog + + + implicit + binary + 10103 + 1 + 3769 + regdictionary + pg_catalog + 26 + oid + pg_catalog + + + assignment + binary + 10108 + 1 + 3769 + regdictionary + pg_catalog + 23 + int4 + pg_catalog + + + assignment + function + 10107 + 1 + 1288 + int8 + pg_catalog + 3769 + regdictionary + pg_catalog + 20 + int8 + pg_catalog + + + assignment + io + 10215 + 1 + 3802 + jsonb + pg_catalog + 114 + json + pg_catalog + + + explicit + function + 10218 + 1 + 3450 + int2 + pg_catalog + 3802 + jsonb + pg_catalog + 21 + int2 + pg_catalog + + + explicit + function + 10220 + 1 + 3452 + int8 + pg_catalog + 3802 + jsonb + pg_catalog + 20 + int8 + pg_catalog + + + explicit + function + 10219 + 1 + 3451 + int4 + pg_catalog + 3802 + jsonb + pg_catalog + 23 + int4 + pg_catalog + + + explicit + function + 10216 + 1 + 3556 + bool + pg_catalog + 3802 + jsonb + pg_catalog + 16 + bool + pg_catalog + + + explicit + function + 10221 + 1 + 3453 + float4 + pg_catalog + 3802 + jsonb + pg_catalog + 700 + float4 + pg_catalog + + + explicit + function + 10217 + 1 + 3449 + numeric + pg_catalog + 3802 + jsonb + pg_catalog + 1700 + numeric + pg_catalog + + + explicit + function + 10222 + 1 + 2580 + float8 + pg_catalog + 3802 + jsonb + pg_catalog + 701 + float8 + pg_catalog + + + explicit + function + 10223 + 1 + 4281 + int4multirange + pg_catalog + 3904 + int4range + pg_catalog + 4451 + int4multirange + pg_catalog + + + explicit + function + 10225 + 1 + 4284 + nummultirange + pg_catalog + 3906 + numrange + pg_catalog + 4532 + nummultirange + pg_catalog + + + explicit + function + 10227 + 1 + 4287 + tsmultirange + pg_catalog + 3908 + tsrange + pg_catalog + 4533 + tsmultirange + pg_catalog + + + explicit + function + 10228 + 1 + 4290 + tstzmultirange + pg_catalog + 3910 + tstzrange + pg_catalog + 4534 + tstzmultirange + pg_catalog + + + explicit + function + 10226 + 1 + 4293 + datemultirange + pg_catalog + 3912 + daterange + pg_catalog + 4535 + datemultirange + pg_catalog + + + explicit + function + 10224 + 1 + 4296 + int8multirange + pg_catalog + 3926 + int8range + pg_catalog + 4536 + int8multirange + pg_catalog + + + assignment + binary + 10124 + 1 + 4089 + regnamespace + pg_catalog + 23 + int4 + pg_catalog + + + assignment + function + 10123 + 1 + 1288 + int8 + pg_catalog + 4089 + regnamespace + pg_catalog + 20 + int8 + pg_catalog + + + implicit + binary + 10119 + 1 + 4089 + regnamespace + pg_catalog + 26 + oid + pg_catalog + + + assignment + binary + 10117 + 1 + 4096 + regrole + pg_catalog + 23 + int4 + pg_catalog + + + implicit + binary + 10112 + 1 + 4096 + regrole + pg_catalog + 26 + oid + pg_catalog + + + assignment + function + 10116 + 1 + 1288 + int8 + pg_catalog + 4096 + regrole + pg_catalog + 20 + int8 + pg_catalog + + + assignment + function + 10086 + 1 + 1288 + int8 + pg_catalog + 4191 + regcollation + pg_catalog + 20 + int8 + pg_catalog + + + assignment + binary + 10087 + 1 + 4191 + regcollation + pg_catalog + 23 + int4 + pg_catalog + + + implicit + binary + 10082 + 1 + 4191 + regcollation + pg_catalog + 26 + oid + pg_catalog + + + implicit + binary + 10150 + 1 + 5017 + pg_mcv_list + pg_catalog + 17 + bytea + pg_catalog + + + implicit + io + 10151 + 1 + 5017 + pg_mcv_list + pg_catalog + 25 + text + pg_catalog + + + explicit + function + 10036 + 1 + 5071 + xid + pg_catalog + 5069 + xid8 + pg_catalog + 28 + xid + pg_catalog + + + PL/pgSQL procedural language + 13644 + 683 + 1.0 + 11 + pg_catalog + 13645 +13646 +13647 +13648 + + + dynamically-loaded C functions + 13 + 1 + fmgr_c_validator + pg_catalog + + + built-in functions + 12 + 1 + fmgr_internal_validator + pg_catalog + + + PL/pgSQL procedural language + plpgsql_call_handler + pg_catalog + plpgsql_inline_handler + pg_catalog + 13648 + 683 + 1 + plpgsql_validator + pg_catalog + + + SQL-language functions + 14 + 1 + 1 + fmgr_sql_validator + pg_catalog + + + 13292 + 529 + postgres + + + system catalog schema + 11 + 523 + postgres + + + standard public schema + 1 + 2096 + 2024-09-07.01:04:17 + 2200 + 523 + pg_database_owner + + + 16904 + 1952 + 2 + thelazyprogrammer +
+ + 16911 + 1955 + 2 + thelazyprogrammer +
+ + 16919 + 1955 + 2 + thelazyprogrammer +
+ + 16897 + 1951 + 2 + thelazyprogrammer +
+ + 1 + 1 + 1952 + varchar|0s + 1043 + + + 2 + 1952 + varchar|0s + 1043 + + + 1 + 3 + 1952 + timestamp(6)|0s + 1114 + + + 1 + 4 + 1952 + timestamp(6)|0s + 1114 + + + key + 1 + 16909 + 1 + 1952 + 1 + 403 + default + 100 + pg_catalog + + + 1 + 16910 + 1 + 1952 + 16909 + + + gen_random_uuid() + 1 + 1 + 1954 + uuid|0s + 2950 + + + 2 + 1954 + varchar|0s + 1043 + + + 3 + 1954 + text|0s + 25 + + + 4 + 1954 + uuid|0s + 2950 + + + 1 + 5 + 1954 + timestamp(6)|0s + 1114 + + + 1 + 6 + 1954 + timestamp(6)|0s + 1114 + + + id + 1 + 16917 + 1 + 1954 + 1 + 403 + + + 1 + 16918 + 1 + 1954 + 16917 + + + gen_random_uuid() + 1 + 1 + 1955 + uuid|0s + 2950 + + + 2 + 1955 + varchar|0s + 1043 + + + 3 + 1955 + text|0s + 25 + + + 4 + 1955 + numeric|0s + 1700 + + + 5 + 1955 + integer|0s + 23 + + + 1 + 6 + 1955 + uuid|0s + 2950 + + + 7 + 1955 + uuid|0s + 2950 + + + 8 + 1955 + uuid|0s + 2950 + + + 1 + 9 + 1955 + timestamp(6)|0s + 1114 + + + 1 + 10 + 1955 + timestamp(6)|0s + 1114 + + + category_id + 16927 + 1955 + 1 + 16911 + + + id + 1 + 16925 + 1 + 1955 + 1 + 403 + + + category_id + 16932 + 1955 + 403 + + + 1 + 16926 + 1 + 1955 + 16925 + + + 1 + 1 + 1951 + varchar|0s + 1043 + + + version + 1 + 16902 + 1 + 1951 + 1 + 403 + default + 100 + pg_catalog + + + 1 + 16903 + 1 + 1951 + 16902 + +
+
\ No newline at end of file diff --git a/.idea/dataSources/998b672d-5b09-4c86-b8e1-367e51781704/storage_v2/_src_/database/commercecore_product_management_service_development.6gzDZA.meta b/.idea/dataSources/998b672d-5b09-4c86-b8e1-367e51781704/storage_v2/_src_/database/commercecore_product_management_service_development.6gzDZA.meta new file mode 100644 index 0000000..878be5e --- /dev/null +++ b/.idea/dataSources/998b672d-5b09-4c86-b8e1-367e51781704/storage_v2/_src_/database/commercecore_product_management_service_development.6gzDZA.meta @@ -0,0 +1 @@ +#n:commercecore_product_management_service_development \ No newline at end of file diff --git a/.idea/dataSources/998b672d-5b09-4c86-b8e1-367e51781704/storage_v2/_src_/database/commercecore_product_management_service_development.6gzDZA/schema/public.abK9xQ.meta b/.idea/dataSources/998b672d-5b09-4c86-b8e1-367e51781704/storage_v2/_src_/database/commercecore_product_management_service_development.6gzDZA/schema/public.abK9xQ.meta new file mode 100644 index 0000000..5ee0ad4 --- /dev/null +++ b/.idea/dataSources/998b672d-5b09-4c86-b8e1-367e51781704/storage_v2/_src_/database/commercecore_product_management_service_development.6gzDZA/schema/public.abK9xQ.meta @@ -0,0 +1,2 @@ +#n:public +! [2096, 0, null, null, -2147483648, -2147483648] diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..29542b6 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,90 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6c00174 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..a081b18 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/watcherTasks.xml b/.idea/watcherTasks.xml new file mode 100644 index 0000000..e0fba0f --- /dev/null +++ b/.idea/watcherTasks.xml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..d59e3f4 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + { + "lastFilter": { + "state": "OPEN", + "assignee": "nanafox" + } +} + { + "selectedUrlAndAccountId": { + "url": "https://github.com/Backendly/commercecore-product-management-service", + "accountId": "36e4ea78-8abc-4393-aa2d-08d03927a210" + } +} + + + { + "associatedIndex": 6 +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1725614160766 + + + + + + + + \ No newline at end of file diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..c99d2e7 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..5f6ee01 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,24 @@ +# Inherit from your local RuboCop configuration file +inherit_from: <%= ENV['RUBOCOP_LOCAL_CONFIG'] %> + +# Omakase Ruby styling for Rails +inherit_gem: + rubocop-rails-omakase: rubocop.yml + +# Overwrite or add rules to create your own house style +# +# # Use `[a, [b, c]]` not `[ a, [ b, c ] ]` +# Layout/SpaceInsideArrayLiteralBrackets: +# Enabled: false + +Metrics/BlockLength: + Exclude: + - 'spec/**/*' + +Metrics/MethodLength: + Exclude: + - 'spec/**/*' + +Metrics/ClassLength: + Exclude: + - 'spec/**/*' diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..6d5369b --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-3.3.4 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0aceeda --- /dev/null +++ b/Dockerfile @@ -0,0 +1,66 @@ +# syntax = docker/dockerfile:1 + +# This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand: +# docker build -t my-app . +# docker run -d -p 80:80 -p 443:443 --name my-app -e RAILS_MASTER_KEY= my-app + +# Make sure RUBY_VERSION matches the Ruby version in .ruby-version +ARG RUBY_VERSION=3.3.4 +FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base + +# Rails app lives here +WORKDIR /rails + +# Install base packages +RUN apt-get update -qq && \ + apt-get install --no-install-recommends -y curl libjemalloc2 libvips postgresql-client && \ + rm -rf /var/lib/apt/lists /var/cache/apt/archives + +# Set production environment +ENV RAILS_ENV="production" \ + BUNDLE_DEPLOYMENT="1" \ + BUNDLE_PATH="/usr/local/bundle" \ + BUNDLE_WITHOUT="development" + +# Throw-away build stage to reduce size of final image +FROM base AS build + +# Install packages needed to build gems +RUN apt-get update -qq && \ + apt-get install --no-install-recommends -y build-essential git libpq-dev pkg-config && \ + rm -rf /var/lib/apt/lists /var/cache/apt/archives + +# Install application gems +COPY Gemfile Gemfile.lock ./ +RUN bundle install && \ + rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \ + bundle exec bootsnap precompile --gemfile + +# Copy application code +COPY . . + +# Precompile bootsnap code for faster boot times +RUN bundle exec bootsnap precompile app/ lib/ + + + + +# Final stage for app image +FROM base + +# Copy built artifacts: gems, application +COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}" +COPY --from=build /rails /rails + +# Run and own only the runtime files as a non-root user for security +RUN groupadd --system --gid 1000 rails && \ + useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \ + chown -R rails:rails db log storage tmp +USER 1000:1000 + +# Entrypoint prepares the database. +ENTRYPOINT ["/rails/bin/docker-entrypoint"] + +# Start the server by default, this can be overwritten at runtime +EXPOSE 3000 +CMD ["./bin/rails", "server"] diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..bdaa89a --- /dev/null +++ b/Gemfile @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +source 'https://rubygems.org' + +# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" +gem 'rails', '~> 7.2.1' +# Use postgresql as the database for Active Record +gem 'pg', '~> 1.1' +# Use the Puma web server [https://github.com/puma/puma] +gem 'puma', '>= 5.0' +# Build JSON APIs with ease [https://github.com/rails/jbuilder] +gem 'jbuilder' +# Use Redis adapter to run Action Cable in production +# gem "redis", ">= 4.0.1" + +# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] +# gem "kredis" + +# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] +# gem "bcrypt", "~> 3.1.7" + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem 'tzinfo-data', platforms: %i[windows jruby] + +# Reduces boot times through caching; required in config/boot.rb +gem 'bootsnap', require: false + +# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] +# gem "image_processing", "~> 1.2" + +# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin Ajax possible +# gem "rack-cors" + +group :development, :test do + # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem + gem 'debug', platforms: %i[mri windows], require: 'debug/prelude' + + # Static analysis for security vulnerabilities [https://brakemanscanner.org/] + gem 'brakeman', require: false + + # Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/] + gem 'rubocop-rails-omakase', require: false + + gem 'rspec-rails', '~> 7.0' + + gem 'factory_bot_rails' +end + +gem 'uuid7', '~> 0.2.0' + +# for pagination +gem 'kaminari' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..a90ffd1 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,297 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (7.2.1) + actionpack (= 7.2.1) + activesupport (= 7.2.1) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + zeitwerk (~> 2.6) + actionmailbox (7.2.1) + actionpack (= 7.2.1) + activejob (= 7.2.1) + activerecord (= 7.2.1) + activestorage (= 7.2.1) + activesupport (= 7.2.1) + mail (>= 2.8.0) + actionmailer (7.2.1) + actionpack (= 7.2.1) + actionview (= 7.2.1) + activejob (= 7.2.1) + activesupport (= 7.2.1) + mail (>= 2.8.0) + rails-dom-testing (~> 2.2) + actionpack (7.2.1) + actionview (= 7.2.1) + activesupport (= 7.2.1) + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4, < 3.2) + rack-session (>= 1.0.1) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + useragent (~> 0.16) + actiontext (7.2.1) + actionpack (= 7.2.1) + activerecord (= 7.2.1) + activestorage (= 7.2.1) + activesupport (= 7.2.1) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (7.2.1) + activesupport (= 7.2.1) + builder (~> 3.1) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (7.2.1) + activesupport (= 7.2.1) + globalid (>= 0.3.6) + activemodel (7.2.1) + activesupport (= 7.2.1) + activerecord (7.2.1) + activemodel (= 7.2.1) + activesupport (= 7.2.1) + timeout (>= 0.4.0) + activestorage (7.2.1) + actionpack (= 7.2.1) + activejob (= 7.2.1) + activerecord (= 7.2.1) + activesupport (= 7.2.1) + marcel (~> 1.0) + activesupport (7.2.1) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + logger (>= 1.4.2) + minitest (>= 5.1) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + ast (2.4.2) + base64 (0.2.0) + bigdecimal (3.1.8) + bootsnap (1.18.4) + msgpack (~> 1.2) + brakeman (6.2.1) + racc + builder (3.3.0) + concurrent-ruby (1.3.4) + connection_pool (2.4.1) + crass (1.0.6) + date (3.3.4) + debug (1.9.2) + irb (~> 1.10) + reline (>= 0.3.8) + diff-lcs (1.5.1) + drb (2.2.1) + erubi (1.13.0) + factory_bot (6.4.6) + activesupport (>= 5.0.0) + factory_bot_rails (6.4.3) + factory_bot (~> 6.4) + railties (>= 5.0.0) + globalid (1.2.1) + activesupport (>= 6.1) + i18n (1.14.5) + concurrent-ruby (~> 1.0) + io-console (0.7.2) + irb (1.14.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + jbuilder (2.12.0) + actionview (>= 5.0.0) + activesupport (>= 5.0.0) + json (2.7.2) + kaminari (1.2.2) + activesupport (>= 4.1.0) + kaminari-actionview (= 1.2.2) + kaminari-activerecord (= 1.2.2) + kaminari-core (= 1.2.2) + kaminari-actionview (1.2.2) + actionview + kaminari-core (= 1.2.2) + kaminari-activerecord (1.2.2) + activerecord + kaminari-core (= 1.2.2) + kaminari-core (1.2.2) + language_server-protocol (3.17.0.3) + logger (1.6.1) + loofah (2.22.0) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) + mail (2.8.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.4) + mini_mime (1.1.5) + minitest (5.25.1) + msgpack (1.7.2) + net-imap (0.4.16) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.5.0) + net-protocol + nio4r (2.7.3) + nokogiri (1.16.7-aarch64-linux) + racc (~> 1.4) + nokogiri (1.16.7-arm-linux) + racc (~> 1.4) + nokogiri (1.16.7-arm64-darwin) + racc (~> 1.4) + nokogiri (1.16.7-x86-linux) + racc (~> 1.4) + nokogiri (1.16.7-x86_64-darwin) + racc (~> 1.4) + nokogiri (1.16.7-x86_64-linux) + racc (~> 1.4) + parallel (1.26.3) + parser (3.3.5.0) + ast (~> 2.4.1) + racc + pg (1.5.8) + psych (5.1.2) + stringio + puma (6.4.2) + nio4r (~> 2.0) + racc (1.8.1) + rack (3.1.7) + rack-session (2.0.0) + rack (>= 3.0.0) + rack-test (2.1.0) + rack (>= 1.3) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) + rails (7.2.1) + actioncable (= 7.2.1) + actionmailbox (= 7.2.1) + actionmailer (= 7.2.1) + actionpack (= 7.2.1) + actiontext (= 7.2.1) + actionview (= 7.2.1) + activejob (= 7.2.1) + activemodel (= 7.2.1) + activerecord (= 7.2.1) + activestorage (= 7.2.1) + activesupport (= 7.2.1) + bundler (>= 1.15.0) + railties (= 7.2.1) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (7.2.1) + actionpack (= 7.2.1) + activesupport (= 7.2.1) + irb (~> 1.13) + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + rainbow (3.1.1) + rake (13.2.1) + rdoc (6.7.0) + psych (>= 4.0.0) + regexp_parser (2.9.2) + reline (0.5.10) + io-console (~> 0.5) + rspec-core (3.13.1) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-rails (7.0.1) + actionpack (>= 7.0) + activesupport (>= 7.0) + railties (>= 7.0) + rspec-core (~> 3.13) + rspec-expectations (~> 3.13) + rspec-mocks (~> 3.13) + rspec-support (~> 3.13) + rspec-support (3.13.1) + rubocop (1.66.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 2.4, < 3.0) + rubocop-ast (>= 1.32.2, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.32.3) + parser (>= 3.3.1.0) + rubocop-minitest (0.36.0) + rubocop (>= 1.61, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-performance (1.21.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rails (2.26.0) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.52.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rails-omakase (1.0.0) + rubocop + rubocop-minitest + rubocop-performance + rubocop-rails + ruby-progressbar (1.13.0) + securerandom (0.3.1) + stringio (3.1.1) + thor (1.3.2) + timeout (0.4.1) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (2.5.0) + useragent (0.16.10) + uuid7 (0.2.0) + zeitwerk (~> 2.4) + webrick (1.8.1) + websocket-driver (0.7.6) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + zeitwerk (2.6.18) + +PLATFORMS + aarch64-linux + arm-linux + arm64-darwin + x86-linux + x86_64-darwin + x86_64-linux + +DEPENDENCIES + bootsnap + brakeman + debug + factory_bot_rails + jbuilder + kaminari + pg (~> 1.1) + puma (>= 5.0) + rails (~> 7.2.1) + rspec-rails (~> 7.0) + rubocop-rails-omakase + tzinfo-data + uuid7 (~> 0.2.0) + +BUNDLED WITH + 2.5.18 diff --git a/README.md b/README.md new file mode 100644 index 0000000..a0418d8 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# CommerceCore Product Management Microservice + +## System dependencies + +* Ruby version: 3.3.4 + +To install the dependencies for the project, run `bundle install` and every +dependency used in this project will be installed. + +## Database initialization + +To initialize the database, simply perform the migrations with the following +commands. + +```shell +rails db:create # if the databases are not yet created + +rails db:migrate +``` + +Be sure that the configuration in the `config/database.yml` mimics your setup. + +## How to run the test suite + +### Running all test cases + +Tests are written using RSpec, so while on the on command line you execute the +command + +```shell +bundle exec rspec +``` + +This will run all the tests available. + +### Running tests for a specific file + +If you need to run specific tests, you can specify the file. For example + +```shell +bundle exec rspec spec/models/category_spec.rb +``` + +### Running specific lines from the file + +Just running the tests for a file, specify the name of the file followed by the +line number where the test you want to run is defined + +```shell +bundle exec rspec spec/models/category.rb:38 +``` diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..9a5ea73 --- /dev/null +++ b/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative "config/application" + +Rails.application.load_tasks diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb new file mode 100644 index 0000000..d672697 --- /dev/null +++ b/app/channels/application_cable/channel.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb new file mode 100644 index 0000000..0ff5442 --- /dev/null +++ b/app/channels/application_cable/connection.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000..4ac8823 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < ActionController::API +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb new file mode 100644 index 0000000..d394c3d --- /dev/null +++ b/app/jobs/application_job.rb @@ -0,0 +1,7 @@ +class ApplicationJob < ActiveJob::Base + # Automatically retry jobs that encountered a deadlock + # retry_on ActiveRecord::Deadlocked + + # Most jobs are safe to ignore if the underlying records are no longer available + # discard_on ActiveJob::DeserializationError +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000..3c34c81 --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: "from@example.com" + layout "mailer" +end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000..4cf1d18 --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,13 @@ +class ApplicationRecord < ActiveRecord::Base + primary_abstract_class + + before_create :generate_uuid_v7 + + private + + def generate_uuid_v7 + return if self.class.attribute_types["id"].type != :uuid + + self.id ||= UUID7.generate + end +end diff --git a/app/models/category.rb b/app/models/category.rb new file mode 100644 index 0000000..88a451e --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +# Category model +class Category < ApplicationRecord + include WordCountValidatable + + has_many :products, dependent: :nullify + + validates :name, :description, + presence: { message: '%s must be provided' }, + length: { minimum: 3 } + + validates :developer_id, + presence: { message: 'developer_id must be provided' } + + validates_word_count_of :description, min_words: 2, max_words: 10 + validates_word_count_of :name, min_words: 1, max_words: 10 + + validates :name, + uniqueness: { scope: :developer_id, case_sensitive: false, + message: '%s already exists' } +end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/models/concerns/word_count_validatable.rb b/app/models/concerns/word_count_validatable.rb new file mode 100644 index 0000000..cdaaf1c --- /dev/null +++ b/app/models/concerns/word_count_validatable.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +# Validate the word counts in a string-like field +module WordCountValidatable + extend ActiveSupport::Concern + + included do + def self.validates_word_count_of(attribute, min_words: 10, max_words: 50) + validate do + word_count = send(attribute).to_s.split.size + if word_count < min_words || word_count > max_words + errors.add(attribute, + "must be between #{min_words} and #{max_words} words") + end + end + end + end +end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 0000000..c9b4a39 --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +# Product model +class Product < ApplicationRecord + include WordCountValidatable + + belongs_to :category + + validates :developer_id, :name, :category_id, :price, :user_id, + :stock_quantity, :description, presence: true + + validate :price_must_be_numeric + validates :stock_quantity, numericality: { only_integer: true } + validates :price, numericality: { only_numeric: true } + + # ensure there's at least one product before it is created + validates :stock_quantity, + numericality: { greater_than_or_equal_to: 1 }, on: :create + + validates_word_count_of :name, min_words: 1, max_words: 20 + validates_word_count_of :description, min_words: 10, max_words: 100 + + validates :name, length: { minimum: 3 } + + private + + def price_must_be_numeric + errors.add(:price, 'must be a number') unless price.is_a?(Numeric) + end +end diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb new file mode 100644 index 0000000..45b6020 --- /dev/null +++ b/app/views/layouts/mailer.html.erb @@ -0,0 +1,13 @@ + + + + + + + + +<%= yield %> + + diff --git a/app/views/layouts/mailer.text.erb b/app/views/layouts/mailer.text.erb new file mode 100644 index 0000000..37f0bdd --- /dev/null +++ b/app/views/layouts/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/bin/brakeman b/bin/brakeman new file mode 100755 index 0000000..ace1c9b --- /dev/null +++ b/bin/brakeman @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby +require "rubygems" +require "bundler/setup" + +ARGV.unshift("--ensure-latest") + +load Gem.bin_path("brakeman", "brakeman") diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 0000000..5ce8057 --- /dev/null +++ b/bin/bundle @@ -0,0 +1,120 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'bundle' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "rubygems" + +m = Module.new do + module_function + + def invoked_as_script? + File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__) + end + + def env_var_version + ENV["BUNDLER_VERSION"] + end + + def cli_arg_version + return unless invoked_as_script? # don't want to hijack other binstubs + # must be running `bundle update` + return unless "update".start_with?(ARGV.first || " ") + + bundler_version = nil + update_index = nil + ARGV.each_with_index do |a, i| + if update_index && update_index.succ == i && a.match?(Gem::Version::ANCHORED_VERSION_PATTERN) + bundler_version = a + end + unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ + next + end + + bundler_version = Regexp.last_match(1) + update_index = i + end + bundler_version + end + + def gemfile + gemfile = ENV["BUNDLE_GEMFILE"] + return gemfile if gemfile.present? + + File.expand_path("../Gemfile", __dir__) + end + + def lockfile + lockfile = + case File.basename(gemfile) + when "gems.rb" then gemfile.sub(/\.rb$/, ".locked") + else "#{gemfile}.lock" + end + File.expand_path(lockfile) + end + + def lockfile_version + return unless File.file?(lockfile) + + lockfile_contents = File.read(lockfile) + unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ + return + end + + Regexp.last_match(1) + end + + def bundler_requirement + @bundler_requirement ||= + env_var_version || + cli_arg_version || + bundler_requirement_for(lockfile_version) + end + + def bundler_requirement_for(version) + return "#{Gem::Requirement.default}.a" unless version + + bundler_gem_version = Gem::Version.new(version) + + bundler_gem_version.approximate_recommendation + end + + def load_bundler! + ENV["BUNDLE_GEMFILE"] ||= gemfile + + activate_bundler + end + + def activate_bundler + gem_error = activation_error_handling do + gem "bundler", bundler_requirement + end + return if gem_error.nil? + + require_error = activation_error_handling do + require "bundler/version" + end + if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + return + end + + warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" + exit 42 + end + + def activation_error_handling + yield + nil + rescue StandardError, LoadError => e + e + end +end + +m.load_bundler! + +load Gem.bin_path("bundler", "bundle") if m.invoked_as_script? diff --git a/bin/docker-entrypoint b/bin/docker-entrypoint new file mode 100755 index 0000000..840d093 --- /dev/null +++ b/bin/docker-entrypoint @@ -0,0 +1,13 @@ +#!/bin/bash -e + +# Enable jemalloc for reduced memory usage and latency. +if [ -z "${LD_PRELOAD+x}" ] && [ -f /usr/lib/*/libjemalloc.so.2 ]; then + export LD_PRELOAD="$(echo /usr/lib/*/libjemalloc.so.2)" +fi + +# If running the rails server then create or migrate existing database +if [ "${1}" == "./bin/rails" ] && [ "${2}" == "server" ]; then + ./bin/rails db:prepare +fi + +exec "${@}" diff --git a/bin/rails b/bin/rails new file mode 100755 index 0000000..efc0377 --- /dev/null +++ b/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path("../config/application", __dir__) +require_relative "../config/boot" +require "rails/commands" diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000..4fbf10b --- /dev/null +++ b/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative "../config/boot" +require "rake" +Rake.application.run diff --git a/bin/rubocop b/bin/rubocop new file mode 100755 index 0000000..40330c0 --- /dev/null +++ b/bin/rubocop @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +require "rubygems" +require "bundler/setup" + +# explicit rubocop config increases performance slightly while avoiding config confusion. +ARGV.unshift("--config", File.expand_path("../.rubocop.yml", __dir__)) + +load Gem.bin_path("rubocop", "rubocop") diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..8ddc5ed --- /dev/null +++ b/bin/setup @@ -0,0 +1,37 @@ +#!/usr/bin/env ruby +require "fileutils" + +APP_ROOT = File.expand_path("..", __dir__) +APP_NAME = "commercecore-product-management-service" + +def system!(*args) + system(*args, exception: true) +end + +FileUtils.chdir APP_ROOT do + # This script is a way to set up or update your development environment automatically. + # This script is idempotent, so that you can run it at any time and get an expectable outcome. + # Add necessary setup steps to this file. + + puts "== Installing dependencies ==" + system! "gem install bundler --conservative" + system("bundle check") || system!("bundle install") + + # puts "\n== Copying sample files ==" + # unless File.exist?("config/database.yml") + # FileUtils.cp "config/database.yml.sample", "config/database.yml" + # end + + puts "\n== Preparing database ==" + system! "bin/rails db:prepare" + + puts "\n== Removing old logs and tempfiles ==" + system! "bin/rails log:clear tmp:clear" + + puts "\n== Restarting application server ==" + system! "bin/rails restart" + + # puts "\n== Configuring puma-dev ==" + # system "ln -nfs #{APP_ROOT} ~/.puma-dev/#{APP_NAME}" + # system "curl -Is https://#{APP_NAME}.test/up | head -n 1" +end diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..4a3c09a --- /dev/null +++ b/config.ru @@ -0,0 +1,6 @@ +# This file is used by Rack-based servers to start the application. + +require_relative "config/environment" + +run Rails.application +Rails.application.load_server diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 0000000..7b94a6f --- /dev/null +++ b/config/application.rb @@ -0,0 +1,48 @@ +require_relative "boot" + +require "rails" +# Pick the frameworks you want: +require "active_model/railtie" +require "active_job/railtie" +require "active_record/railtie" +require "active_storage/engine" +require "action_controller/railtie" +require "action_mailer/railtie" +require "action_mailbox/engine" +require "action_text/engine" +require "action_view/railtie" +require "action_cable/engine" +# require "rails/test_unit/railtie" + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module CommercecoreProductManagementService + class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 7.2 + + # Please, add to the `ignore` list any other `lib` subdirectories that do + # not contain `.rb` files, or that should not be reloaded or eager loaded. + # Common ones are `templates`, `generators`, or `middleware`, for example. + config.autoload_lib(ignore: %w[assets tasks]) + + # Configuration for the application, engines, and railties goes here. + # + # These settings can be overridden in specific environments using the files + # in config/environments, which are processed later. + # + # config.time_zone = "Central Time (US & Canada)" + # config.eager_load_paths << Rails.root.join("extras") + + # Only loads a smaller set of middleware suitable for API only apps. + # Middleware like session, flash, cookies can be added back manually. + # Skip views, helpers and assets when generating a new resource. + config.api_only = true + + config.generators do |generate| + generate.orm :active_record, primary_key_type: :uuid + end + end +end diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 0000000..988a5dd --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,4 @@ +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +require "bundler/setup" # Set up gems listed in the Gemfile. +require "bootsnap/setup" # Speed up boot time by caching expensive operations. diff --git a/config/cable.yml b/config/cable.yml new file mode 100644 index 0000000..2a855d9 --- /dev/null +++ b/config/cable.yml @@ -0,0 +1,10 @@ +development: + adapter: async + +test: + adapter: test + +production: + adapter: redis + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> + channel_prefix: commercecore_product_management_service_production diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc new file mode 100644 index 0000000..b9904ac --- /dev/null +++ b/config/credentials.yml.enc @@ -0,0 +1 @@ +0gTdvpalm8VfEe8ONs1tY1tx7WAfBB22w93SVkj73gZ3cm4RrbZWh6jCUNvfO1wWrP3qMTywYOmFwAX0Sm/1cRScKDSix39WtfTlQdK+7hFcEdfxn1cYmQfUBxHSI2gEhWeFIZPtd3CWyfxqU+WPDArqwgftIun2CdGK88njp/5dvY8tyqOJNasBFY1Y4f9fa6Y8UEC7ekhjDKJ3jgpfupLIj5ysuShzaZPP9el58X1PlmBYtT3eArLWHFWYU7JbMozWELeaBPRxOwa5JLNce3RloiD6dqEV2DEUiEYgt36qk80EjPBThaihBKrHyhcHmCtyP14MSkL+YwU69EE8ha7ID9T16wrPll3Sxh9ZfiFe/u+qOE9Sf5RMNkoVuCcZVdpsDQfAqpBJ5ZUp7jVax6sJj4XS--23tiLlGBwqOXLVjz--gE52tkZmFIEwDEdP/EkO7Q== \ No newline at end of file diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000..fd82de8 --- /dev/null +++ b/config/database.yml @@ -0,0 +1,83 @@ +# PostgreSQL. Versions 9.3 and up are supported. +# +# Install the pg driver: +# gem install pg +# On macOS with Homebrew: +# gem install pg -- --with-pg-config=/usr/local/bin/pg_config +# On Windows: +# gem install pg +# Choose the win32 build. +# Install PostgreSQL and put its /bin directory on your path. +# +# Configure Using Gemfile +# gem "pg" +# +default: &default + adapter: postgresql + encoding: unicode + # For details on connection pooling, see Rails configuration guide + # https://guides.rubyonrails.org/configuring.html#database-pooling + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + + +development: + <<: *default + database: commercecore_product_management_service_development + + # The specified database role being used to connect to PostgreSQL. + # To create additional roles in PostgreSQL see `$ createuser --help`. + # When left blank, PostgreSQL will use the default role. This is + # the same name as the operating system user running Rails. + #username: commercecore_product_management_service + + # The password associated with the PostgreSQL role (username). + #password: + + # Connect on a TCP socket. Omitted by default since the client uses a + # domain socket that doesn't need configuration. Windows does not have + # domain sockets, so uncomment these lines. + #host: localhost + + # The TCP port the server listens on. Defaults to 5432. + # If your server runs on a different port number, change accordingly. + #port: 5432 + + # Schema search path. The server defaults to $user,public + #schema_search_path: myapp,sharedapp,public + + # Minimum log levels, in increasing order: + # debug5, debug4, debug3, debug2, debug1, + # log, notice, warning, error, fatal, and panic + # Defaults to warning. + #min_messages: notice + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: commercecore_product_management_service_test + +# As with config/credentials.yml, you never want to store sensitive information, +# like your database password, in your source code. If your source code is +# ever seen by anyone, they now have access to your database. +# +# Instead, provide the password or a full connection URL as an environment +# variable when you boot the app. For example: +# +# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" +# +# If the connection URL is provided in the special DATABASE_URL environment +# variable, Rails will automatically merge its configuration values on top of +# the values provided in this file. Alternatively, you can specify a connection +# URL environment variable explicitly: +# +# production: +# url: <%= ENV["MY_APP_DATABASE_URL"] %> +# +# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database +# for a full overview on how database connection configuration can be specified. +# +production: + <<: *default + url: <%= ENV['DATABASE_URL'] %> diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 0000000..cac5315 --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative "application" + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb new file mode 100644 index 0000000..98128ff --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,75 @@ +require "active_support/core_ext/integer/time" + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded any time + # it changes. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.enable_reloading = true + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable server timing. + config.server_timing = true + + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + if Rails.root.join("tmp/caching-dev.txt").exist? + config.cache_store = :memory_store + config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{2.days.to_i}" } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + # Disable caching for Action Mailer templates even if Action Controller + # caching is enabled. + config.action_mailer.perform_caching = false + + config.action_mailer.default_url_options = { host: "localhost", port: 3000 } + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + + # Highlight code that enqueued background job in logs. + config.active_job.verbose_enqueue_logs = true + + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + config.action_view.annotate_rendered_view_with_filenames = true + + # Uncomment if you wish to allow Action Cable access from any origin. + # config.action_cable.disable_request_forgery_protection = true + + # Raise error when a before_action's only/except options reference missing actions. + config.action_controller.raise_on_missing_callback_actions = true + + # Apply autocorrection by RuboCop to files generated by `bin/rails generate`. + # config.generators.apply_rubocop_autocorrect_after_generate! +end diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 0000000..927c442 --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,97 @@ +# frozen_string_literal: true + +require 'active_support/core_ext/integer/time' + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.enable_reloading = false + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + + # Ensures that a master key has been made available in ENV["RAILS_MASTER_KEY"], config/master.key, or an environment + # key such as config/credentials/production.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true + + # Disable serving static files from `public/`, relying on NGINX/Apache to do so instead. + # config.public_file_server.enabled = false + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.asset_host = "http://assets.example.com" + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache + # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Mount Action Cable outside main process or domain. + # config.action_cable.mount_path = nil + # config.action_cable.url = "wss://example.com/cable" + # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] + + # Assume all access to the app is happening through a SSL-terminating reverse proxy. + # Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies. + # config.assume_ssl = true + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + config.force_ssl = true + + # Skip http-to-https redirect for the default health check endpoint. + # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } + + # Log to STDOUT by default + config.logger = ActiveSupport::Logger.new($stdout) + .tap { |logger| logger.formatter = ::Logger::Formatter.new } + .then { |logger| ActiveSupport::TaggedLogging.new(logger) } + + # Prepend all log lines with the following tags. + config.log_tags = [:request_id] + + # "info" includes generic and useful information about system operation, but avoids logging too much + # information to avoid inadvertent exposure of personally identifiable information (PII). If you + # want to log everything, set the level to "debug". + config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info') + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment). + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "commercecore_product_management_service_production" + + # Disable caching for Action Mailer templates even if Action Controller + # caching is enabled. + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Don't log any deprecations. + config.active_support.report_deprecations = false + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false + + # Enable DNS rebinding protection and other `Host` header attacks. + # config.hosts = [ + # "example.com", # Allow requests from example.com + # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com` + # ] + # Skip DNS rebinding protection for the default health check endpoint. + # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } +end diff --git a/config/environments/test.rb b/config/environments/test.rb new file mode 100644 index 0000000..0c616a1 --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,67 @@ +require "active_support/core_ext/integer/time" + +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # While tests run files are not watched, reloading is not necessary. + config.enable_reloading = false + + # Eager loading loads your entire application. When running a single test locally, + # this is usually not necessary, and can slow down your test suite. However, it's + # recommended that you enable it in continuous integration systems to ensure eager + # loading is working properly before deploying your code. + config.eager_load = ENV["CI"].present? + + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{1.hour.to_i}" } + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + config.cache_store = :null_store + + # Render exception templates for rescuable exceptions and raise for other exceptions. + config.action_dispatch.show_exceptions = :rescuable + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Store uploaded files on the local file system in a temporary directory. + config.active_storage.service = :test + + # Disable caching for Action Mailer templates even if Action Controller + # caching is enabled. + config.action_mailer.perform_caching = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Unlike controllers, the mailer instance doesn't have any context about the + # incoming request so you'll need to provide the :host parameter yourself. + config.action_mailer.default_url_options = { host: "www.example.com" } + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true + + # Raise error when a before_action's only/except options reference missing actions. + config.action_controller.raise_on_missing_callback_actions = true +end diff --git a/config/initializers/cors.rb b/config/initializers/cors.rb new file mode 100644 index 0000000..0c5dd99 --- /dev/null +++ b/config/initializers/cors.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Avoid CORS issues when API is called from the frontend app. +# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin Ajax requests. + +# Read more: https://github.com/cyu/rack-cors + +# Rails.application.config.middleware.insert_before 0, Rack::Cors do +# allow do +# origins "example.com" +# +# resource "*", +# headers: :any, +# methods: [:get, :post, :put, :patch, :delete, :options, :head] +# end +# end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000..c010b83 --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. +# Use this to limit dissemination of sensitive information. +# See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. +Rails.application.config.filter_parameters += [ + :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn +] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb new file mode 100644 index 0000000..3860f65 --- /dev/null +++ b/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, "\\1en" +# inflect.singular /^(ox)en/i, "\\1" +# inflect.irregular "person", "people" +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym "RESTful" +# end diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..6c349ae --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,31 @@ +# Files in the config/locales directory are used for internationalization and +# are automatically loaded by Rails. If you want to use locales other than +# English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t "hello" +# +# In views, this is aliased to just `t`: +# +# <%= t("hello") %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more about the API, please read the Rails Internationalization guide +# at https://guides.rubyonrails.org/i18n.html. +# +# Be aware that YAML interprets the following case-insensitive strings as +# booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings +# must be quoted to be interpreted as strings. For example: +# +# en: +# "yes": yup +# enabled: "ON" + +en: + hello: "Hello world" diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 0000000..03c166f --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,34 @@ +# This configuration file will be evaluated by Puma. The top-level methods that +# are invoked here are part of Puma's configuration DSL. For more information +# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html. + +# Puma starts a configurable number of processes (workers) and each process +# serves each request in a thread from an internal thread pool. +# +# The ideal number of threads per worker depends both on how much time the +# application spends waiting for IO operations and on how much you wish to +# to prioritize throughput over latency. +# +# As a rule of thumb, increasing the number of threads will increase how much +# traffic a given process can handle (throughput), but due to CRuby's +# Global VM Lock (GVL) it has diminishing returns and will degrade the +# response time (latency) of the application. +# +# The default is set to 3 threads as it's deemed a decent compromise between +# throughput and latency for the average Rails application. +# +# Any libraries that use a connection pool or another resource pool should +# be configured to provide at least as many connections as the number of +# threads. This includes Active Record's `pool` parameter in `database.yml`. +threads_count = ENV.fetch("RAILS_MAX_THREADS", 3) +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +port ENV.fetch("PORT", 3000) + +# Allow puma to be restarted by `bin/rails restart` command. +plugin :tmp_restart + +# Specify the PID file. Defaults to tmp/pids/server.pid in development. +# In other environments, only set the PID file if requested. +pidfile ENV["PIDFILE"] if ENV["PIDFILE"] diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..a125ef0 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,10 @@ +Rails.application.routes.draw do + # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html + + # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. + # Can be used by load balancers and uptime monitors to verify that the app is live. + get "up" => "rails/health#show", as: :rails_health_check + + # Defines the root path route ("/") + # root "posts#index" +end diff --git a/config/storage.yml b/config/storage.yml new file mode 100644 index 0000000..4942ab6 --- /dev/null +++ b/config/storage.yml @@ -0,0 +1,34 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket-<%= Rails.env %> + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket-<%= Rails.env %> + +# Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# microsoft: +# service: AzureStorage +# storage_account_name: your_account_name +# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> +# container: your_container_name-<%= Rails.env %> + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] diff --git a/db/migrate/20240906221109_create_categories.rb b/db/migrate/20240906221109_create_categories.rb new file mode 100644 index 0000000..26d3388 --- /dev/null +++ b/db/migrate/20240906221109_create_categories.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class CreateCategories < ActiveRecord::Migration[7.2] + def change + create_table :categories, id: :uuid do |t| + t.string :name + t.text :description + t.uuid :developer_id + + t.timestamps + end + end +end diff --git a/db/migrate/20240906221153_create_products.rb b/db/migrate/20240906221153_create_products.rb new file mode 100644 index 0000000..1ce2bba --- /dev/null +++ b/db/migrate/20240906221153_create_products.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class CreateProducts < ActiveRecord::Migration[7.2] + def change + create_table :products, id: :uuid do |t| + t.string :name + t.text :description + t.decimal :price + t.integer :stock_quantity + t.references :category, null: false, foreign_key: true, type: :uuid + t.uuid :user_id + t.uuid :developer_id + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..2c008c5 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema[7.2].define(version: 20_240_906_221_153) do + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "categories", id: :uuid, default: lambda { + "gen_random_uuid()" + }, force: :cascade do |t| + t.string "name" + t.text "description" + t.uuid "developer_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "products", id: :uuid, default: lambda { + "gen_random_uuid()" + }, force: :cascade do |t| + t.string "name" + t.text "description" + t.decimal "price" + t.integer "stock_quantity" + t.uuid "category_id", null: false + t.uuid "user_id" + t.uuid "developer_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["category_id"], name: "index_products_on_category_id" + end + + add_foreign_key "products", "categories" +end diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000..4fbd6ed --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,9 @@ +# This file should ensure the existence of records required to run the application in every environment (production, +# development, test). The code here should be idempotent so that it can be executed at any point in every environment. +# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). +# +# Example: +# +# ["Action", "Comedy", "Drama", "Horror"].each do |genre_name| +# MovieGenre.find_or_create_by!(name: genre_name) +# end diff --git a/lib/tasks/.keep b/lib/tasks/.keep new file mode 100644 index 0000000..e69de29 diff --git a/log/.keep b/log/.keep new file mode 100644 index 0000000..e69de29 diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..c19f78a --- /dev/null +++ b/public/robots.txt @@ -0,0 +1 @@ +# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file diff --git a/spec/factories/categories.rb b/spec/factories/categories.rb new file mode 100644 index 0000000..1ce3e00 --- /dev/null +++ b/spec/factories/categories.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :category do + end +end diff --git a/spec/factories/products.rb b/spec/factories/products.rb new file mode 100644 index 0000000..0ea34cf --- /dev/null +++ b/spec/factories/products.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :product do + end +end diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb new file mode 100644 index 0000000..20fb852 --- /dev/null +++ b/spec/models/category_spec.rb @@ -0,0 +1,137 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Category, type: :model do + describe 'Developer ID validations' do + it 'throws an error when the developer_id is omitted' do + expect do + Category.create!(name: 'Electronics', + description: 'Everything electronics') + end.to raise_error(ActiveRecord::RecordInvalid) + end + + it 'throws an error when the developer_id is not a UUID' do + expect do + Category.create!(name: 'Category 1', description: 'A short Description', + developer_id: 1234) + end.to raise_error(ActiveRecord::RecordInvalid) + end + + it 'creates the category when the developer_id is present and valid' do + developer_id = UUID7.generate + + expect do + Category.create(name: 'Category 1', + description: 'Description for category 1', + developer_id:) + end.to_not raise_error + + expect(Category.count).to eq(1) + category = Category.first + + expect(category.name).to eq('Category 1') + expect(category.developer_id).to eq(developer_id) + end + end + + describe 'Description field length constraints' do + it 'rejects categories with no descriptions' do + expect do + Category.create!(name: 'Category 1', developer_id: UUID7.generate) + end.to raise_error(ActiveRecord::RecordInvalid) + + expect(Product.count).to eq(0) + end + + it 'rejects categories with a description of less than 2 words' do + expect do + Category.create!(name: 'Category 1', developer_id: UUID7.generate, + description: 'Category') + end.to raise_error(ActiveRecord::RecordInvalid) + + expect(Product.count).to eq(0) + end + + it 'handles only whitespace characters-only description' do + expect do + Category.create!(name: 'White-spaced Description Category', + developer_id: UUID7.generate, description: ' ' * 2) + end.to raise_error(ActiveRecord::RecordInvalid) + + expect(Product.count).to eq(0) + end + + it 'creates a category with a description of at least two words' do + expect do + Category.create!(name: 'Home Appliances', + developer_id: UUID7.generate, + description: 'Everything Appliances') + end.to_not raise_error + + expect(Category.count).to eq(1) + end + + it 'creates a category with a description of at most ten words' do + description = 'For all products in the home appliance and ' \ + 'electronics family' + expect do + Category.create!(name: 'Home Appliances', + developer_id: UUID7.generate, description:) + end.to_not raise_error + + expect(Category.count).to eq(1) + end + + it 'rejects categories with more than ten words for description' do + description = 'description ' * 11 + + appliance = Category.create(name: 'Home Appliances', + developer_id: UUID7.generate, description:) + + expect(Category.count).to eq(0) + expect(appliance).to be_invalid + + expect(appliance.errors.full_messages[0]).to eq( + 'Description must be between 2 and 10 words' + ) + end + + it 'throws an error on duplicate category creation' do + developer_id = UUID7.generate + + # first time + Category.create!(name: 'Home Appliances', + developer_id:, + description: 'Home appliance products category') + + # second time + expect do + Category.create!(name: 'Home Appliances', + developer_id:, + description: 'Home appliance products category') + end.to raise_error(ActiveRecord::RecordInvalid) + + expect(Category.count).to eq(1) + end + + it 'creates the same category for two different developers' do + developer_1_id = UUID7.generate + developer_2_id = UUID7.generate + + # first time + Category.create!(name: 'Home Appliances', + developer_id: developer_1_id, + description: 'Home appliance products category') + + # second time + expect do + Category.create!(name: 'Home Appliances', + developer_id: developer_2_id, + description: 'Home appliance products category') + end.to_not raise_error + + expect(Category.count).to eq(2) + end + end +end diff --git a/spec/models/product_spec.rb b/spec/models/product_spec.rb new file mode 100644 index 0000000..bbd8614 --- /dev/null +++ b/spec/models/product_spec.rb @@ -0,0 +1,85 @@ +# frozen_string_literal: true + +require 'rails_helper' +RSpec.describe Product, type: :model do + let(:developer_id) { UUID7.generate } + let(:user_id) { UUID7.generate } + let(:category) do + FactoryBot.create(:category, name: 'Home Appliances', + description: 'Home appliance for user needs', + developer_id:) + end + + it 'throws an error when creating with a nil category_id' do + expect do + Product.create!(name: 'Laptop cases', developer_id:, category_id: nil, + price: 100, user_id:, stock_quantity: 10, + description: 'A case for laptops') + end.to raise_error(ActiveRecord::RecordInvalid) + end + + it 'is invalid with a non-existent category_id' do + product = Product.new(name: 'Laptop cases', developer_id:, + category_id: UUID7.generate, price: 100, user_id:, + stock_quantity: 10, description: 'A case for laptops') + + expect(product).to be_invalid + expect(Product.count).to eq(0) + end + + it 'is valid with all required attributes' do + product = Product.new(name: 'Laptop cases', developer_id:, + category_id: category.id, price: 100, user_id:, + stock_quantity: 10, + description: 'A case for laptops' * 3) + + expect(product).to be_valid + + product.save + expect(Product.count).to eq(1) + end + + it 'is invalid without a name' do + product = Product.new(developer_id:, category_id: category.id, price: 100, + user_id:, stock_quantity: 10, + description: 'A case for laptops' * 3) + + expect(product).not_to be_valid + + expect { product.save! }.to raise_error(ActiveRecord::RecordInvalid) + end + + it 'is invalid with non-integer stock_quantity' do + product = Product.new(name: 'Laptop cases', developer_id:, + category_id: category.id, price: 100, user_id:, + stock_quantity: 'ten', + description: 'A case for laptops') + + expect(product).not_to be_valid + expect { product.save! }.to raise_error(ActiveRecord::RecordInvalid) + end + + it 'is invalid with non-numeric price' do + product = Product.new(name: 'Laptop cases', developer_id:, + category_id: category.id, + price: 'one hundred', user_id:, + stock_quantity: 10, + description: 'A case for laptops' * 3) + + expect(product).not_to be_valid + expect { product.save! }.to raise_error(ActiveRecord::RecordInvalid) + end + + it 'is invalid with zero stock quantity during creation' do + product = Product.new(name: 'Laptop cases', developer_id:, + category_id: category.id, + price: 13.56, user_id:, + stock_quantity: 0, + description: 'A case for laptops' * 3) + + expect(product).to be_invalid + expect(product.errors.full_messages_for(:stock_quantity)[0]).to eq( + 'Stock quantity must be greater than or equal to 1' + ) + end +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 0000000..0cd9a90 --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,68 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +require 'spec_helper' +ENV['RAILS_ENV'] ||= 'test' +require_relative '../config/environment' +# Prevent database truncation if the environment is production +abort("The Rails environment is running in production mode!") if Rails.env.production? +# Uncomment the line below in case you have `--require rails_helper` in the `.rspec` file +# that will avoid rails generators crashing because migrations haven't been run yet +# return unless Rails.env.test? +require 'rspec/rails' +# Add additional requires below this line. Rails is not loaded until this point! + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# directory. Alternatively, in the individual `*_spec.rb` files, manually +# require only the support files necessary. +# +# Rails.root.glob('spec/support/**/*.rb').sort_by(&:to_s).each { |f| require f } + +# Checks for pending migrations and applies them before tests are run. +# If you are not using ActiveRecord, you can remove these lines. +begin + ActiveRecord::Migration.maintain_test_schema! +rescue ActiveRecord::PendingMigrationError => e + abort e.to_s.strip +end +RSpec.configure do |config| + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_paths = [ + Rails.root.join('spec/fixtures') + ] + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = true + + # You can uncomment this line to turn off ActiveRecord support entirely. + # config.use_active_record = false + + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, type: :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://rspec.info/features/7-0/rspec-rails + config.infer_spec_type_from_file_location! + + # Filter lines from Rails gems in backtraces. + config.filter_rails_from_backtrace! + # arbitrary gems may also be filtered via: + # config.filter_gems_from_backtrace("gem name") +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..409c64b --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,94 @@ +# frozen_string_literal: true + +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + # # This allows you to limit a spec run to individual examples or groups + # # you care about by tagging them with `:focus` metadata. When nothing + # # is tagged with `:focus`, all examples get run. RSpec also provides + # # aliases for `it`, `describe`, and `context` that include `:focus` + # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + # config.filter_run_when_matching :focus + # + # # Allows RSpec to persist some state between runs in order to support + # # the `--only-failures` and `--next-failure` CLI options. We recommend + # # you configure your source control system to ignore this file. + # config.example_status_persistence_file_path = "spec/examples.txt" + # + # # Limits the available syntax to the non-monkey patched syntax that is + # # recommended. For more details, see: + # # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/ + # config.disable_monkey_patching! + # + # # Many RSpec users commonly either run the entire suite or an individual + # # file, and it's useful to allow more verbose output when running an + # # individual spec file. + # if config.files_to_run.one? + # # Use the documentation formatter for detailed output, + # # unless a formatter has already been configured + # # (e.g. via a command-line flag). + # config.default_formatter = "doc" + # end + # + # # Print the 10 slowest examples and example groups at the + # # end of the spec run, to help surface which specs are running + # # particularly slow. + # config.profile_examples = 10 + # + # # Run specs in random order to surface order dependencies. If you find an + # # order dependency and want to debug it, you can fix the order by providing + # # the seed, which is printed after each run. + # # --seed 1234 + # config.order = :random + # + # # Seed global randomization in this process using the `--seed` CLI option. + # # Setting this allows you to use `--seed` to deterministically reproduce + # # test failures related to randomization by passing the same `--seed` value + # # as the one that triggered the failure. + # Kernel.srand config.seed +end diff --git a/storage/.keep b/storage/.keep new file mode 100644 index 0000000..e69de29 diff --git a/tmp/.keep b/tmp/.keep new file mode 100644 index 0000000..e69de29 diff --git a/tmp/pids/.keep b/tmp/pids/.keep new file mode 100644 index 0000000..e69de29 diff --git a/tmp/storage/.keep b/tmp/storage/.keep new file mode 100644 index 0000000..e69de29 diff --git a/vendor/.keep b/vendor/.keep new file mode 100644 index 0000000..e69de29