#RubyOnRails - 01 November 2018
« Back 1 day Forward 1 day »
[06:53:17] syndikate: If time cop is not used in `before` block would the time freezing leak out globally to all specs?
[07:00:25] Cork: is there any way to get the post string in an encoding honnoring the charset header value?
[07:03:44] syndikate: Or rather I am looking for a strong argument on why time cop should be in `before` blcok
[08:38:07] timdotrb: I’m having trouble with getting values from an “add another” select. I’ve set the name of the field to be an array, but I’m not getting any values in the params: https://gist.github.com/willc0de4food/a50b3b925d4e170207cf2a4cd59cabb2
[10:02:23] hightower3: Hey, I am looking at rspec tests where they invoke e.g. "post" to make a HTTP POST request, and then the response object is automatically available in the 'response' variable or method. How exactly is this 'response' defined and set? I would need to write a helper method which does the same thing essentially
[10:21:59] tbuehlmann: hightower3: it's a simple getter (https://github.com/rails/rails/blob/v5.2.1/actionpack/lib/action_controller/test_case.rb#L335), and the variable is set here: https://github.com/rails/rails/blob/v5.2.1/actionpack/lib/action_controller/test_case.rb#L519 when processing the "post"
[10:32:22] hightower3: tbuehlmann, hm, yeah I was trying to assign @response with no effect. Must be I have been doing it on the wrong class
[10:32:41] hightower3: (for a quick test I just placed @response = in the test itself, but that didn't have effect)
[10:37:57] tbuehlmann: so there's no #response method, but #method_missing will pick it up and call #response on @controller
[10:46:08] DaniG2k: hello all. I have an index on a table that looks like the following: add_index "vessel_plans", ["voyage_id"], name: "index_vessel_plans_on_voyage_id", using: :btree
[10:46:25] DaniG2k: add_index :vessel_plans, %i[status voyage_id], algorithm: :concurrently, unique: true
[10:46:40] DaniG2k: but rake tells me I can't because obviously there's already an index on voyage_id
[10:47:18] DaniG2k: anyone know how I can remove the last index, create the new one and ensure the previous entries are all indexed?
[10:49:35] DaniG2k: Index name 'index_vessel_plans_on_status_and_voyage_id' on table 'vessel_plans' already exists
[10:50:00] DaniG2k: I just have `add_index "vessel_plans", ["voyage_id"], name: "index_vessel_plans_on_voyage_id", using: :btree` right now
[10:53:13] DaniG2k: yep it's in front of me. I've grepped the file for that index but it definitely doesn't exist
[11:05:56] tbuehlmann: it seems you or some other person created the index directly in the database without using rails, or your migrations/schema is not correct
[11:07:14] DaniG2k: here's my migration file: https://gist.github.com/DaniG2k/83ce2c515108ff13f4960f4b1a78c5f5
[11:10:02] tbuehlmann: not sure how disable_ddl_transaction! behaves in case with an exception (probably just like mysql). did the migration fail earlier so the migration was not successful but the changes wasn't rolled back?
[11:13:42] DaniG2k: ah nevermind, the docs say "If you forget disable_ddl_transaction!, the migration will fail."
[13:12:14] Psy-Q: overriding initialize seems to be discouraged in ActiveRecord. how can i pass some parameters in that are just used for a bunch of class variables, not persisted to the DB (so they don't have columns)?
[18:51:19] Inside: Design Q: Controllers. Let's say I'm using acts_as_list and a model has a position within its parent's context.
[19:34:28] samort7: So I'm trying to figure out what has_many I need to use and if I need to use "through" and if I need to create a third, intermediary model to relate users to kit_lists that they have favorited
[19:35:03] samort7: Sorry, I'm having trouble formulating the question I need to ask, because I'm not exactly sure how I should be structuring this
[19:35:32] samort7: It's like, I want a user to have a collection of kit_lists that they have favorited
[19:37:53] samort7: Can I just add "has_many :kit_lists" to my user model? And if I do that, can two different users be owners of the same kit_list?
[19:39:25] samort7: ("owner" is probably the wrong word there. Can two diff users "have a relationship" with the same kit_list?)
[19:50:21] samort7: by join table, that means I need an intermediary table which contains both ids for users and ids for kit_lists?
[19:52:02] samort7: So the user will have "has_many :kit_lists" and the kit_list will have "has_and_belongs_to_many :users"\
[19:52:22] samort7: I just finished Hartle's tutorial and had only learned the "has_many" relationship
[19:56:37] Inside: ie: let's say you want call back to fire whenever a user has like 500 kits to give them a badge
[19:57:23] Inside: I believe has_and_belongs_to_many just assumes that you have a table and magically creates records in that table
[19:58:25] Inside: with has many_through, the association model gets created and you can add logic later
[21:00:37] glasz: hey Inside, remember my question about prevent sprockets from loading sass partials (_partial.scss)?
[21:01:51] glasz: ended up writing a custom DirectiveProcessor, replacing the build-in one, and just not loading any text/css-type file that starts with _. wonder why that's not the default. makes everything a whole lot more easier and nobody names their files _foo.css anyway.
[21:20:15] glasz: hm. having a weird issue with using provided rubygems + bundler. `bundle install` will install into `/opt/rh/rh-ruby25/root/usr/share/gems` but after that, ruby will complain that non of the native extensions of the gems that just built theirs are not built and i should run `gem pristine` respectively. gem pristine does fix the issue but something is going wrong in the first place. scl ruby has --user-install as the default but bundler just ignores it.
[21:23:28] glasz: yes. i have it in `/etc/profile.d/scl.sh` or something along those lines. `ruby -v` and `which ruby` report that the proper version is used.
[21:24:15] Inside: oh wait no, that's because I had multiple rails projects running different versions of ruby
[21:38:10] glasz: holy smokes. scl ruby does some scl-centric gymnastics in /opt/rh/rh-ruby25/root/usr/share/rubygems/rubygems/defaults/operating_system.rb though i'm not sure it's the problem.
[21:40:37] Inside: I hate asking questions like that, but I think with ruby it's more standard to use the existing environment managers since they're better supported
[21:42:57] mlt-: How would I pin down a cause for (Mini)test failure? I mean if I re-run the failed test alone, it passes. It only fails if I run all tests with certain seeds. So I suspect that something is not getting cleaned up. But I'm totally lost as how to figure out what.
[21:44:33] Inside: you give it a seed and it'll tell you which tests you need to run in order to reproduce your test failure
[21:44:38] mlt-: glasz: when it fails, it says "ActiveRecord::RecordNotFound: Couldn't find MyControllerName with 'my_id'=1234"
[21:45:36] glasz: Inside: re scl: yeah. but getting scl up and running was easier than getting rbenv up. also spares me the compilation. when bundling images, i really prefer using vendor-provided binaries.
[21:50:36] mlt-: glasz: it is failing at the line that gets the fixture... setup do @stuff = things(:mything) ...
[21:52:39] mlt-: No, not in this one. But I do some funky stuff with other tables... there might be some FK problems. I gonna give it a try.. will get back.
[21:57:05] mlt-: glasz, Inside: I tried ... where.. first! It fails with all tests and same seed, but passes for a single test.
[21:59:21] mlt-: glasz: I believe they are transactional by default... I turn it off only in one separate IntegrationTest
[22:03:16] glasz: > Every Active Record database supports transactions except MySQL MyISAM. Use InnoDB, MaxDB, or NDB instead.
[22:05:03] glasz: https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html#class-ActiveRecord::FixtureSet-label-Transactional+Tests
[22:06:33] mlt-: I'm on PostgreSQL. I turn off transactional tests on one very specific set of integration tests. I want to split all those into smaller chunks, but setup takes quite some time, so I turn them off and i_suck_and_my_tests_are_order_dependent!
[22:09:07] mlt-: I might just rewrite that into one single test thus keeping everything transactional.... instead of trying to find the problem as is
[22:26:46] glasz: > By default, Bundler installs gems system-wide, which is contrary to the behaviour of gem itself
[22:27:48] glasz: > To correct this, add the following to your ~/.bashrc: `export GEM_HOME=$(ruby -e 'print Gem.user_dir')`.
[22:38:17] mlt-: nah... i got tired using VirtualBox before... seems nice to just run stuff locally. I just use WSL occasionally to test something out specific
[22:40:48] mlt-: uname -a gives Linux UMN201657146 4.4.0-43-Microsoft #1-Microsoft Wed Dec 31 14:42:53 PST 2014 x86_64 GNU/Linux
[22:47:29] Radar: One day I'll have to try that WSL thing out. It will actually require me purchasing Windows which would offend my Mac aesthetique.
[22:48:46] mlt-: ehm...what is the point of using WSL if you use Mac? Don't you have docker and all other fun stuff OOB?
[22:49:46] Radar: My main reason for trying it would be to see if it would be an OK thing to recommend to newbies who want to try Rails.
[22:50:11] Radar: I will use a mac until the day I die or they turn the keyboard into a big touch screen. Whichever comes first.
[22:50:43] Radar: mlt-: What's the startup time of a bare Rails app like? < 30 s? Did Nokogiri actually compile first time?
[22:51:01] Radar: mlt-: it's not hte _running_ that's a bad thing. It's the setup on Windows which is a complete pain in the ass.
[23:00:57] mlt-: I dunno if this is still a thing and/or windows specific https://stackoverflow.com/q/50552742/673826
[23:01:23] mlt-: Also while we are at it... I posted a SO question with a problem I came across while upgrading Rails... Can I re-use fixture_file_upload? Or do I have to call it explicitly every time? https://stackoverflow.com/q/53015697/673826
[23:02:35] MasterAsia: I included jquery and I'm using $.post but it is being altered by rails somehow to include the x-csrf-token
[23:02:37] MasterAsia: https://github.com/rails/rails/commit/ad3a47759e67a411f3534309cdd704f12f6930a7
[23:12:26] MasterAsia: https://github.com/rails/rails/commit/ad3a47759e67a411f3534309cdd704f12f6930a7#diff-4bc3e1543a0718421103a654c6974442R24