Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails way #26

Merged
merged 151 commits into from
Nov 11, 2023
Merged

Rails way #26

merged 151 commits into from
Nov 11, 2023

Conversation

JuzerShakir
Copy link
Owner

@JuzerShakir JuzerShakir commented Nov 10, 2023

This PR brings some big improvements focusing on backend system. I have highlighted some of it here.

Linting Errors

erblint

Currently

Screenshot from 2023-11-10 17-55-52

this PR

Screenshot from 2023-11-10 18-08-32

rubocop

(includes rspec, factory-bot, capybara & rails)

Currently

Screenshot from 2023-11-10 18-01-47
..
..
after scrolling for a few moments 🥱
..
..
Screenshot from 2023-11-10 18-04-03

this PR

Screenshot from 2023-11-10 18-11-56
(this will be auto-corrected later)

Test Suite

Currently (without headless)

Screenshot from 2023-11-10 18-39-37

this PR (with headless)

Screenshot from 2023-11-10 18-45-18

Metric Currently this PR Percentage improvement
Run time 1 minute and 32.45 seconds 47.25 seconds 72.83%
Load time 1.61 seconds 1.31 seconds 18.63%

Requests

Some actions render both HTML & turbo_stream actions like Thaalis#index action, Transactions#all action, etc. The logic defined in these actions runs twice, each for both actions, HTML & turbo_stream.

Meaning if you have logic that triggers a SQL request, it would make that request twice, for each action.

So we need those resources to load only for turbo stream action but it is not explicitly defined in the controller. So currently it loads resources for HTML action too. For example:

Thaali index (Homepage)

Currently

Screenshot from 2023-11-10 19-44-04

this PR

By using the respond_to method, we avoid making unnecessary SQL calls hence making the HTML template load faster:

Screenshot from 2023-11-10 19-24-08


Gems added:

  1. robocop-rspec
  2. rubocop-rails
  3. rails-i18n
  4. active_record_union
  5. rolify
  6. cancancan

Here is the list of changes:

In schema

  • Merge migration files.
  • Remove sabeels' name uniqueness constraint with its.
  • Remove thaalis' year uniqueness constraint with number.
  • Change table name from thaali_takhmeens to thaalis.
  • Remove the address, balance, paid, is_complete, and role attributes.
  • use rollify library to support roles for users.

In tests

  • Add robocop-rspec, and rubocop-capybara gems to address all linting errors in test suites.
  • Re-organise tests, rename test titles, delete redundant tests, and add new tests where necessary.
  • Create new and rename existing factories.
  • Configure Selenium to run js tests with a headless browser (firefox).
  • Divide feature tests of all controllers into different files with respect to their actions/views.
  • Divide requests tests of all controllers into different files with respect to their actions.

In controllers

  • Load resources only in the turbo_stream action and not in both html & turbo_stream.
  • Use the preload method to load associated resources resulting in faster response time.
  • Use the length instead of the count method which avoids making separate SQL queries.
  • Use Cancancan gem for authorization and remove redundant before actions from all controller files and methods from application_controller

In views

  • Format amounts with grouped thousands using the number_with_delimeter method.
  • Use locales for validation and flash messages, and use custom attribute names.
  • Update turbo_steram files to show no_results partial if resources don't exist.
  • Show balance amount instead of font awesome icons: check & x-mark in turbo_stream pages.
  • Show the same content in Sabeel#active & Sabeel#inactive views.
  • Do Not show edit, delete, new thaali & new transaction buttons if the user type is a viewer.
  • Shows font-awesome icon with content without the html-safe method.

In seeds

  • Seed 100 sabeels instead of 1000.
  • Generate Roles and a user with a viewer type.

Constants

  • Remove the concept of Phase, deleting its constants, factories, scopes, and tests.
  • Init APARTMENT with 5 apartment names.
  • Init MODES with 3 modes.
  • Init ROLES with 3 roles.

Misc:

  • Use 2-space indentation.
  • Add frozen_string_literal comments.
  • Add rubocop-rails to address all linting errors for rails.
  • Alphabetically order gems in Gemfile & methods, and attributes in model files.
  • Add new and rename existing scopes.

@JuzerShakir JuzerShakir marked this pull request as ready for review November 11, 2023 05:29
@JuzerShakir JuzerShakir merged commit f63fefa into master Nov 11, 2023
@JuzerShakir JuzerShakir mentioned this pull request Nov 15, 2023
@JuzerShakir JuzerShakir deleted the rails-way branch January 30, 2024 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant