#RubyOnRails - 23 October 2017
« Back 1 day Forward 1 day »
[06:24:52] mikeyhew: How can I run a specific test method with `rake test`? Assuming `ActiveSupport::TestCase`
[06:28:04] matthewd: mikeyhew: `rake test TEST=test/some_test.rb TESTOPT="-n test_foo"` should work, I think?
[06:28:54] matthewd: On newer Rails, it's `rails test test/some_test.rb:123` or (maybe?) `rails test test/some_test.rb -n test_foo`
[06:30:07] dminuoso: matthewd: Thank you for your input the other day regarding those inexplicable delays in TTFB if you recall. Helped me a bunch.
[06:31:32] matthewd: dminuoso: No worries! I recall the problem, but not a conclusion.. what did it turn out to be?
[06:32:13] dminuoso: matthewd: Webpacker. Turns out the middleware transparently would try to detect if the webpack dev server was running on each request, with a timeout of 1000ms.
[06:32:45] dminuoso: Something that was already addressed (by making it both configurable and default to 100ms rather).
[06:33:44] dminuoso: matthewd: Would I be correct in assuming, that all the actioncable magic does not through rack?
[06:34:20] dminuoso: I mean the rack middlewares seem to work, it looks like streaming would be impossible if there's a single middleware that does not behave.
[06:34:55] matthewd: The initial request passes through rack, but then the connection gets hijacked instead of sending a normal response
[06:35:36] mikeyhew: matthewd: I'm not in a rails app, so a `rake` command will have to do. With `-n test_foo` it says it can't find a file with the name "test_foo"...
[06:36:59] dminuoso: matthewd: Yeah that's a shame. At times I wish I could trivially stream from regular controllers. :(
[06:38:54] matthewd: mikeyhew: Do you actually need rake involved? The real way to do it is `ruby -Itest test/some_test.rb -n test_foo`
[10:42:54] lxsameer: hey folks, I have two exactly the same controller spec but the second one return 404 , how can i debug this ?
[10:44:06] dminuoso: lxsameer: It implies that either you have tests running concurrently with mutable state, or you don't properly clean up after tests.
[10:44:46] lxsameer: dminuoso: hmm, but why 404 ? the endpoint is there and I don't have any logic to return 404 manually
[11:48:11] lxsameer: dminuoso: yeah, I'm using a gem ( which authored in the company ), that gem rescue from an specific exception in controllers to 404
[11:51:24] dminuoso: lxsameer: Ah yeah. Rails has this behavior out of the box for the ActiveRecord::RecordNotFound exception for example.
[11:52:19] lxsameer: dminuoso: I never liked implicit stuff like this in big projects, It usually cause headache for the next dev
[12:00:58] drale2k_: Not sure how to structure this. I am creating a feature called "Jobs" where i can start some jobs. Now i will have like 10 different kinds of jobs but they all have in common that they are jobs. They will all use the same model. Now i am not sure how to structure the controller and routes for this
[12:01:29] drale2k_: Should i have 1 "Jobs" controller and then have if statements to distinguish between the different kinds of jobs and show the propper UI or should i have 1 controller per job
[12:02:25] drale2k_: i will start the jobs by having a dropdown and then clicking on the job i want to create, That will redirect to the job's controller
[12:02:34] mikecmpbll: how different is the UI? how different is the behaviour? (pretty much same question)
[12:03:00] drale2k_: it can be very different. That's why i would like to have different controllers
[12:03:22] drale2k_: but i would like to nest them in a sub-folder "jobs", not sure how to do that and have the proper routes
[12:04:04] drale2k_: currently i have the following routes nested https://gist.github.com/drale2k/35568250afc4f510eb19f125e2f86cb6
[12:10:00] drale2k_: if i wanted to have a subfolder like controllers/jobs/somejob_controller.rb, how would i go about the routes ?
[12:11:05] frojnd: Problem is that the moment I call HTTParty.get(...) And I get that error I can't catch response.code since response is nul
[12:48:31] Andr3as: hi guys.. i've a bit of a designing question.. lets say i have a user model which has_many subscriptions and each of that subscription cannot overlap.. so for a given day there is max 1 active subscription... - lets also say there is a model tradeplan which has a date..
[12:49:45] Andr3as: aybe he had a subscription from june 1st until 30th and from aug 10th until aug 31st
[15:04:13] drale2k_: due to lot of nesting / namepsacing, i have now very long helpers for paths, like operation_agent_jobs_meterpreter
[15:07:02] drale2k_: mikecmpbll: thanks, i have set now "resources :meterpreter, as: :meterpreter_jobs" but hwen i run "rails routes" i still only see the long path
[15:11:06] drale2k_: and walso when i add "as: :meterpreter_jobs" it required my model to be like "Jobs::MeterpreterJob < Jobs" instead of "MeterprterJob < Job"
[15:11:59] mikecmpbll: and i'm pretty sure `as` has no other affect than changing the helper path so it won't cause your model stuff.
[15:12:06] drale2k_: iam fine with the long urls but i can't get the form to work with "form_with @job"
[15:14:46] drale2k_: "<%= form_with [@operation, @agent, @job] do |form| %>" ... gives "wrong number of arguments (given 1, expected 0)"
[15:15:41] drale2k_: this is my route.rb https://gist.github.com/drale2k/08b7b2e73cf7d729c9f6ae02a232e11d
[15:26:45] mikecmpbll: aye, i've not used form_with yet. from docs though looks like it wants `form_with model: @job` or `form_with model: [@operation, @agent, @job]`
[15:27:51] drale2k_: now it is back to complaining about "undefined method `meterpreter_jobs_path' "
[15:32:30] drale2k_: i get "Unable to autoload constant Jobs::MeterpreterJob, expected /Users/drale2k/Dropbox/htdocs/work/dsirf/subzero/subzero_rails/app/models/jobs/meterpreter_job.rb to define it" in "@job = MeterpreterJob.new"
[15:35:35] mikecmpbll: docs examples show this usage http://api.rubyonrails.org/v5.1/classes/ActionView/Helpers/FormHelper.html#method-i-form_with-label-Examples
[15:37:27] drale2k_: i wonder if it has issues because my model is in models/jobs/meterpreter_job.rb which inherits from models/job.rb using STI
[15:39:09] matthewd: drale2k_: Sounds like you may have several overlapping problems in play. Find something that's behaving itself, and work slowly forward from there.
[17:25:55] cagomez: that is, besides delivering Foo's where bar = x, you also specify a default Order (like created_at)
[17:32:25] workmad3: cagomez: I'd generally avoid it, because it can cause a bunch of difficulty when trying to compose the scope with joins, etc. included
[17:44:39] cagomez: does ORDER BY timestamp imply asc or desc? what's a proper name for a collection sorted by desc timestamps?
[18:11:10] Andr3as: is there a better way to check if a value is within an array than "include?" - or do i need to workaround include if that given value might be NIL?
[18:13:41] nickjj: because then you can just use .any? , and it'll return true if it finds 1 or more nils
[18:13:44] NL3limin4t0r: Do you mean the Array might be `nil`, or the value you pass to the `#include?` method?
[18:14:11] Andr3as: i meant that the value i pass into include could be nil, but include is fine with nil
[18:16:49] NL3limin4t0r: As far as I know `#include?` is the best option. It is natively supported by Ruby.
[18:20:53] NL3limin4t0r: If you want to check muliple values, you should have a look at the Set class.
[18:23:56] Technodrome: say I am using devise with an omniauth provider, what is the best way for that omni auth authenticated user to have a local user profile class with additional user information, not on the (service side) ?
[18:28:39] NL3limin4t0r: I can't answer that one for you. Generaly it's never a good idea to store info on the client side, since it can be manipulated. You can do it for conviniance, but still have to validate it on the server to check if no ominous things happend.
[19:00:32] harrycs: probably a dumb question, but I'm very new to TDD. Do you create tests for every single controller action?
[19:01:07] frojnd: I have a tile that I've created it with multiple divs and styles... now I would like to make it a link. Can I do it with link_to or in this case a href?
[19:04:19] harrycs: frojnd: i'm not 100% on this, but can't you pass the divs and styles to link_to in the options hash?
[19:06:35] frojnd: harrycs: I think I found a solution: `<%= link_to path do %> <div class="my-class"> ... </div> <% end %>` seems to wrap my divs with a href
[19:18:48] rcdvl: Hey guys, I'm returning to rails after some years and I'm with some issues while coding my models... It's this the right place to make this kind of questions?
[19:24:04] rcdvl: Nice :) I have a user table and a business table. Users can own many business and belong to many businesses. On the other hand, a business can have many users but belong to only one owner
[19:25:13] rcdvl: How would you do such relation in rails? I thought about using habtm but then a business could also have many owners
[19:29:57] havenwood: rcdvl: So you might say a business belongs to a user as owner? And then a business has and belongs to many users?
[19:32:54] rcdvl: Hmm I don't think so... A business has only one owner but has many users. A user has many businesses and belongs to many businesses
[21:14:22] piratepete: I’ve created a blog from the getting started guide, converted to Slim, added Bootstrap and checked into my Gitlab. Can I generate a new app and not wipe or destroy the main database in sqllite3?
[21:17:01] piratepete: baweaver: I guess I didn’t remember choosing main but I think it’s the default
[21:17:54] baweaver: rcdvl: pretty much that. You could also make an Owners table which has user_id and business_id which may simplify things a bit.
[21:18:43] baweaver: Though if I have any particularly risky migrations I write it as a rake task and test the heck out of it
[21:20:55] baweaver: I'd agree with lupine though on the separate table. It'll be a lot easier to maintain and change later if you need to
[21:21:26] baweaver: Inheritance style table design is a journey of nightmares when your app gets larger
[21:25:23] cjohnson: My approach is start off this way, then if it grows and needs to get metadata of its own, it's not a hard migration to write
[21:25:40] cjohnson: I try not to overengineer everything, a db migration and a code refactor aren't overly difficult
[23:39:40] platzhirsch: well, I am a bit sad that searching for a naming scheme didn't yield any results
[23:50:14] Radar: or maybe you should just split your app up into M I C R O S E R V I C E S and communicate betwixt them with CQRS