Conversation
Current Code Coverage Percent of this PR:96.71 %Files having coverage below 100%
|
ca8b162 to
097a37f
Compare
rohitjoshixyz
left a comment
There was a problem hiding this comment.
Provided some feedback
| private | ||
|
|
||
| def load_invoice | ||
| @invoice = Invoice.includes(client: :company).find(params[:invoice_id]) |
There was a problem hiding this comment.
We can remove the load_invoice before action
| @invoice = Invoice.includes(client: :company).find(params[:invoice_id]) | |
| def invoice | |
| @_invoice ||= Invoice.includes(client: :company).find(params[:invoice_id]) | |
| end |
There was a problem hiding this comment.
We follow this convention in Miru for memorized variables. Global search for @_
There was a problem hiding this comment.
Btw how will the view templates access this instance variable since we are not loading this in before_action?
There was a problem hiding this comment.
Just one last confusion, Why are we using instance variables if we want to pass them as locals? They should anyway be available to the views, right?
It feels like we are deliberately not taking advantage of the magic that Rails provides us.
Is there any specific reason we decided to move away from our own set standards in Miru?
There was a problem hiding this comment.
I think because, in this action, we are using the variable only to pass as locals, but for a complex action we might use the invoice method at multiple places and so an instance variable will be accessible everywhere, for example a private method would not need an argument to be passed
| # frozen_string_literal: true | ||
|
|
||
| class ApplicationService | ||
| def self.process(*args, &block) |
There was a problem hiding this comment.
I prefer to name the method perform. Also @alkesh26 @keshavbiswa @akhilgkrishnan We were going to use an interactor pattern right? Or since this PR is urgent, we could go with service classes and then refactor later
There was a problem hiding this comment.
Yes initially the plan was to add interactor classes rather than service classes, if the PR is urgent we can go with service classes too.
| class Checkout < ApplicationService | ||
| def initialize(params) | ||
| @invoice = params[:invoice] | ||
| @company = invoice.client.company |
There was a problem hiding this comment.
Can we add an association, or delegation so we could access like invoice.company
| ensure_client_registered! | ||
| checkout! |
There was a problem hiding this comment.
Just curious why are we using bang methods everywhere?
There was a problem hiding this comment.
Since we are not rescuing the exceptions, I added ! to indicate that we should expect these methods to raise exceptions.
| def description | ||
| "Invoice from #{company.name} for #{currency} #{invoice.amount} due on #{invoice.due_date}" | ||
| end |
There was a problem hiding this comment.
Let's consider adding an invoice_presenter cc @keshavbiswa @alkesh26
There was a problem hiding this comment.
Presenters are needed in many places, maybe we can start with this PR.
|
|
||
| class AddStripeIdToClients < ActiveRecord::Migration[7.0] | ||
| def change | ||
| add_column :clients, :stripe_id, :string, default: nil |
There was a problem hiding this comment.
@supriya3105 Do we have only one stripe account per client?
There was a problem hiding this comment.
This is to sync customers and payments on stripe.
| require "rails_helper" | ||
|
|
||
| RSpec.describe "Invoices::Payments", type: :request do | ||
| describe "GET /index" do | ||
| pending "add some examples (or delete) #{__FILE__}" | ||
| end | ||
| end |
There was a problem hiding this comment.
Specs are pending, checkout https://github.com/stripe-ruby-mock/stripe-ruby-mock
There was a problem hiding this comment.
Thanks! This is awesome🚀
| @@ -4,5 +4,7 @@ Hi, <%= @invoice.client_name %> | |||
| You have an invoice - <%= @invoice.invoice_number %> with amount <%= @invoice.amount %> | |||
There was a problem hiding this comment.
Amount would be in cents, convert it to $
| def success | ||
| @invoice.paid! | ||
| end | ||
|
|
||
| def cancel | ||
| render | ||
| end |
There was a problem hiding this comment.
We prefer REST based controllers.
|
@apoorv1316 please test it and merge if all ok. |
Fixes #304
https://www.loom.com/share/a91974fb521e4e29afa830c50bd219ad