kobaltzPRO

Joined 7/18/2015
kobaltz PRO said 2 months ago:

Thank you! Correction has been made.

kobaltz PRO said 2 months ago:

It seems like request.env['action_dispatch.show_detailed_exceptions'] is returning true or false instead of the actual messages.

bertrand.signoret PRO said 2 months ago:

I was simulating a 500 error. Wasn't I supposed to get more from exception ?

kobaltz PRO said about 2 months ago:

I hadn't planned on covering testing on these since there are already some videos on the topic. https://www.driftingruby.com/episodes?query%5Bname%5D=&tag=test

However, I'll gladly add this episode in if the community would like to see them.

kobaltz PRO said about 2 months ago:

In this example where users may already exist, I would have a rake task which would populate the tokens for the users. Once the tokens have been generated, I would have another migration which would set the column to a null: false.

But I believe your confusion is valid as it should be unless instead of if.

break if self.class.exists?(token: token) would cause an endless loop while break unless self.class.exists?(token: token) would give the desired functionality.

AA PRO said about 2 months ago:

So why not simply use an until loop, like so?

until self.class.exists?(token: token)
self.token = SecureRandom.hex
end

Thank you

kobaltz PRO said about 2 months ago:

If by chance the token already exists then it will not generate the token. This probably would rarely happen on a small app with SecureRandom.hex, but on a larger table could be a concern.

Another way to write it could be something like

def generate_token
  begin
    self.token = SecureRandom.hex
  end while self.class.exists?(token: token)
end

AA PRO said about 2 months ago:

Hi,
Thank you for the quick reply...
But isn't nil at the first time, so the loop is always entered at least once?

kobaltz PRO said about 2 months ago:

Haha yes, good point. Sorry, I'm winding down for the night and obviously not thinking correctly.

kobaltz PRO said about 2 months ago:

Try setting the domain and use the url to https://note-book-diary.herokuapp.com/

So you'd need to update the host and the domain settings. You can check the Certificate within Chrome to see what the common name (or domain name) to see where the mismatch is.

kobaltz PRO said about 2 months ago:

Hello Steve, it really is the code organization which benefits from extracting the methods out. I've worked on similar applications in terms of size as the GitLab app and the fat models made it very difficult to work on. Grouping and moving ideas, like the friendships in the episode example, make the overall maintenance of the model easier over time. Yes, things are now in multiple files, but it ended up still being preferred over a large model. Ultimately, it does come down to the team's preference and their style of coding in which case I think should always be consistent on a per project basis. However, bringing a new person on board, it would be overwhelming to have to work in a large model like GitLab's user model. I consider most things, with exceptions, which makes something easier to maintain, lowering technical debt.

[email protected] PRO said about 2 months ago:

What OO gurus would suggest is that this object's "friendship" responsibility should be slit into POROs that can send messages to the original User object and be tested independently. Is there no other PORO way to do this?

AA PRO said about 2 months ago:

I've started to read about the POODR book..
And indeed, it seems a better approach instead of simply modules...
But since I'm new, I don't see yet how to figure out the abstraction/decomposition...

kobaltz PRO said about 2 months ago:

If by chance the token already exists then it will not generate the token. This probably would rarely happen on a small app with SecureRandom.hex, but on a larger table could be a concern.

Another way to write it could be something like

def generate_token
  begin
    self.token = SecureRandom.hex
  end while self.class.exists?(token: token)
end

AA PRO said about 2 months ago:

Hi,
Thank you for the quick reply...
But isn't nil at the first time, so the loop is always entered at least once?

kobaltz PRO said about 2 months ago:

Haha yes, good point. Sorry, I'm winding down for the night and obviously not thinking correctly.

kobaltz PRO said about 2 months ago:

Haha yes, good point. Sorry, I'm winding down for the night and obviously not thinking correctly.

kobaltz PRO said about 2 months ago:

Do you have a use case in mind for this?

kobaltz PRO said about 2 months ago:

Great idea! Have you seen https://github.com/RailsApps/rails-composer from Daniel Kehoe

Simon Kiteley PRO said about 1 month ago:

No but I do see your new episode :) many thanks. I will be starting to client projects soon so will give it a go :)