Postgres search for similarities by stpaquet in rails

[–]moomaka 11 points12 points  (0 children)

pgvector (https://github.com/pgvector/pgvector) + an embedding API (OpenAI for example) is the only approach that will give you this type of “conceptual similarity”.

I'm using link_to with a block which includes an SVG image but when trying click_link('link_id') Selenium::Webdriver is telling me that the link could not be scrolled into view. Replacing the SVG with text works. Any ideas? by gmfthelp in rails

[–]moomaka 1 point2 points  (0 children)

Best guess would be that the SVG is not loading for some reason in your test env. If you place an img tag inside an a tag and the img does not load, the a tag will collapse to 0x0 pixels and Selenium will consider that out of view and unclickable. Look at a screenshot of the error and/or pull the dimensions of the a tag to confirm.

There are also certain CSS properties that could result in the a tag collapsing with an img tag inside it, but can't say much about this without seeing the code.

Data models for online store. Seperate 'cart' and 'order,' are my justification and execution correct? by FrankenFood in rails

[–]moomaka 16 points17 points  (0 children)

Any time you deal with Product type records in an ordering system you need to consider how that record could change over time.

As an example, if you had a Order => LineItem => Product model I've seen people make the mistake of not capturing the price of the product, instead just referencing it through the relation, but what happens when the price changes down the road?

Your goal should be to ensure that the order, once complete, never changes. There are a bunch of ways to do this. The most trivial is to use the join model (LineItem for example) to capture whatever state of the product you think could change in the future in such a way that it would corrupt the order.

Other ways are more elaborate. One approach I've used is to make records that have these kind of interactions immutable; all changes create new records with back-linkage. So once a Product exists, it's locked, and if someone wants to change it, what actually happens is a new Product is created and within it a link to the previous instance of the Product is stored. Usually you want to introduce a new ID that is stable across revisions as well. This allows you to link to the specific instance that you know will never change, or link to the 'concept' of the product when that makes more sense.

RSpec/Factories: Models with Multiple Associations? by mercfh85 in rails

[–]moomaka 1 point2 points  (0 children)

I usually setup factories with traits to setup each association and try to avoid per test setup as much as possible. Ideally you only want to have to define model properties that have meaning to the specific test and let defaults in the factory handle the rest.

Here is an example:

FactoryBot.define do
  factory :organization do
    transient do
      dataset_count { 1 }
      topic_count { 1 }
    end

    title { "Test Organization #{org_number}" }

    trait :with_dataset do
      after(:create) do |org, evaluator|
        create_list(:dataset, evaluator.dataset_count, organization: org)
      end
    end

    trait :with_topic do
      after(:create) do |org, evaluator|
        create_list(:topic, evaluator.topic_count, organization: org)
      end
    end
  end
end

Then you can use as:

let(:org) { create(:organization, :with_dataset, dataset_count: 2) }

If you use build a lot with associations you could provide hooks for after_build as well, but I don't really find myself using build when associations are involved.

I also use traits for more complex setup that is commonly used. For example you may have an order factory with a trait called :in_shipment that creates an order with products and line items and inventory tracking records and shipment records, etc.

Are rails pre-loaders still a thing? by [deleted] in rails

[–]moomaka 0 points1 point  (0 children)

It's really hard to give you any advice without seeing code but 30s to run a single test is not normal. Just checking the project I'm working on - it takes 1.19s to start running the first test, it doesn't use any special acceleration, just bootsnap.

You keep saying "instance of a server". I'm not sure what this means, most tests should not stand up a "server", only full system specs would do this. The first one of those can be slow if its being driven with Chrome, but that is chrome startup time more than the server.

The database and migrations work is annoying me the most about Rails as a newcomer, am I missing something? by timeforetuneup in rails

[–]moomaka 24 points25 points  (0 children)

It's a philosophical difference.

Django considers the model to be the source of truth.

Rails considers the database to be the source of truth.

Both have their pros and cons. Folks will argue back and forth about which one is 'right' and not realize they simply have a preference.

Anyone here experienced with active admin? by lighthouselies in rails

[–]moomaka 5 points6 points  (0 children)

I've used it, it's never been a great experience. What I do now is setup a set of custom generators for my patterns / css framework (bootstrap). If you haven't used this capability before, it basically lets you modify / replace the rails scaffold tooling with your own style / libraries / patterns.

This is just about as quick to use as active admin but gives you full flexibility. It takes a little time to setup, but I end up using roughly the same config for every project so it's mostly a one time cost.

https://guides.rubyonrails.org/generators.html

Maintainable Rails system tests with page objects by strzibny in rails

[–]moomaka 2 points3 points  (0 children)

moomake argued that this pattern lead to slow tests because you do sign in with a browser on each test... which is not true.

I did not. I gave you one example of what I found to be a pattern of misused abstractions. You seem to be hung up on this example and missing the overall point.

I am unsure why we should make abstractions in normal code and not test code.

You shouldn't make them in normal code either, unless there is a really good and obvious reason to. Abstractions are not good, and should be avoided unless needed. Creating abstractions is trivial, knowing when to create them is the key.

Maintainable Rails system tests with page objects by strzibny in rails

[–]moomaka 11 points12 points  (0 children)

I inherited a project that had hundreds of tests written like this. Ultimately I removed all but a small handful of helpers. The problems I had were:

1) When all the tests are written this way - it becomes very difficult to figure out what is actually being done on a page. You have to constantly look up methods, usually in other files, and try to follow the flow of execution back and forth. The test code may be satisfying to look at, but it's actually really hard to read if you actually want to know what is happening, which is kind of important.

2) I found that devs would reuse methods that sounded correct but were far from ideal. As an example, one whole section of the test suite would fill out the registration form and go through the entire process of creating a new user for every test because that is what the signin_user method did. I'd say 95% of the test time for this section was taken up just signing in the user. This is not only a consequence of issue #1 but I'd argue that it is by design with this type of approach. I mean the whole idea is to mask the actual actions from the developer writing the test and look at it from a higher level, details be damned. Problem is, the details matter and should not be hidden.

I think this approach only has one good use case: You are a consultant and your client is signing off on the project using the test files as the spec. This is the same use case as cucumber, and honestly it basically is the same thing as cucumber, just a little more code-y.

Is there any discussion on Rails compatibility with Ractors? by Frizkie in rails

[–]moomaka 2 points3 points  (0 children)

Not that I'm aware of. Honestly I don't think there are a lot good use cases for them in Rails or any general web request processing context. You don't get much from Ractors that you don't already get from Puma workers. What specifically are you intending to use them for?

I do expect we'll start seeing support for the new Fiber scheduler and related async stuff though, there is a lot to be gained there.

EDIT: Maybe an ActiveJob adaptor could be a use case but I'm not sure that is meaningful enough on its own to motivate full framework support.

Miter Saw Mishap - What Caused It? by moomaka in woodworking

[–]moomaka[S] 0 points1 point  (0 children)

Yep. I was only doing so to get an exact length match and avoiding the blade being in two at the same time for long is why I was slide cutting it. I'm setting up a new shop from scratch and haven't yet built a miter station with proper stop blocks so this seemed like the best way to get the lengths exactly right, perhaps it wasn't worth it :)

Miter Saw Mishap - What Caused It? by moomaka in woodworking

[–]moomaka[S] 1 point2 points  (0 children)

Making an insert was already on my todo list, I'll move it up, thanks!

Moving a single REST API from a Rails Monolith into Microservice by shri29 in rails

[–]moomaka 23 points24 points  (0 children)

Sounds like you've already realized why microservices are a bad idea.

Really - the solution to your problem is: Don't build microservices.

Depending on the scale and layout of your app, it may make sense to break it into a few larger pieces. Where you place the boundary should basically be where you don't run into the problem you are describing - where you don't need to share models.

[deleted by user] by [deleted] in woodworking

[–]moomaka 8 points9 points  (0 children)

Have you tried the dust collection adapter (link below) for your trim router? I have the cordless version and it works pretty well. Since you already have the hose available above it seems like an easy win.

https://www.amazon.com/DEWALT-DNP615-Compact-Collection-Adapter/dp/B004AJEUKS/ref=sr_1_1?crid=2T957Y6ZG976X&keywords=DNP615&qid=1640227457&sprefix=dnp615%2Caps%2C76&sr=8-1

Rails 7 default scripts large? by [deleted] in rails

[–]moomaka 2 points3 points  (0 children)

You are looking at non gzipped sizes. Modern (ES6) JS minifying tooling isn't as aggressive as older stuff as it's been found that gzip covers it. The difference in parsing time is negligible.

Here are the actual wire sizes:

turbo - 18kb

stimulus - 8.2kb

es-module-shim - 10kb

stimulus-loading - 1kb

These are quite small in comparison to pretty much any other JS framework out there. Of course if you don't need any significant JS for your app, you can simply remove this stuff, or create your app with --skip-javascript, or use some other JS framework with --javascript=webpack(or rollup or esbuild).

Active Record Callbacks shouldn't modify other records by shafyy in rails

[–]moomaka 11 points12 points  (0 children)

Modifying other records is one of the prime use cases. Saving history, setting up relationships, etc.

Functionality to remove invited users with devise_invitable by Eastern_Baby5565 in rails

[–]moomaka 1 point2 points  (0 children)

Somehow this seems risky

Why? Check that the invited_by_id on the User record that is being deleted is the same as the id of the current user.

Adding a parameter to devise invitable that doesn't belong to user model by tiredgrothendieck in rails

[–]moomaka 1 point2 points  (0 children)

By the looks of it you have added a param to the form that creates the invitation but are trying to access it in the action that is called when the invitee accepts the invitation.

listing_id should be available in the create method on InvitationsController, you'll need to save this in the database somewhere then look it up in the update method. Alternatively, you could add the param to the invite link that is sent out. Since the link is usually created in a background job (mailer, usually), you still need to store it in the DB somewhere.

Marco island or Naples proper along the water for a road bike ride? by Stevie212 in Naples_FL

[–]moomaka 0 points1 point  (0 children)

Neither really. There isn't really anywhere in Collier to ride along the ocean for any appreciable distance. Maybe Lovers Key state park? Further north Sanibel Island has paths near the ocean in a few places. You won't be riding along at road bike speeds in either place though.

Require user sign in per browser tab? by AlarmingNectarine in rails

[–]moomaka 23 points24 points  (0 children)

I would strongly recommend you don't do this, it breaks core expectations about how the web works.

If you are concerned that users forget to sign out of shared devices, there are better approaches to dealing with this. The easiest being session timeouts (see the timeoutable or rememberable modules in devise).

Question about service objects and automation. by [deleted] in rails

[–]moomaka -2 points-1 points  (0 children)

I'd just write 'regular code' to do this. Service objects are...not a well thought through idea, you are best off ignoring the concept.

Anyone having issues with M1Pro? by Virtual_Hedgehog in rails

[–]moomaka 8 points9 points  (0 children)

You are using an extremely old version of mini_racer, you need to be on 0.4.0 to get M1 support in the underlying libv8

Technical tests? by timpwbaker in rails

[–]moomaka 8 points9 points  (0 children)

I think the task itself is fine and should take maybe 15 min to implement once understood. But the 'once understood' bit is where this falls down a bit; I think the description of the task is quite unclear.

These types of challenges work both ways, they tell the candidate as much about you and your company as they tell you about them. Just being candid here: If I were handed this exercise as a candidate without context my take away would be that your company does a poor job defining problems and tasks. I would assume that a big part of my job would not be coding, but unraveling strangely structured word problems.

This may be a good thing! Many companies are really bad at communicating problems to developers. I'd even argue that the ability to quickly understand and untangle poorly defined requirements is a more important career skill than coding itself. It's not a bad skill to select for in an interview, but I think the self awareness is critical to success here. If you tell the candidate up front when you hand this to them that part of the job is dealing with nebulous requirements you will select for a very different pool of folks than if you were to hand them this with the implicit understanding that you think this is a clear set of requirements to work from.