Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
The Journey Fraternity
Nov 25, 2003



I found this on the ground!

necrotic posted:

They've finally have first-class foreign key support in ActiveRecord migrations! I think the rails5 release is focused mostly on performance improvements and bug fixes over new features, with ActionCable being the big exception.

So just pure improvements since if I ever need sockets I'm gonna be using Phoenix :v:

Adbot
ADBOT LOVES YOU

necrotic
Aug 2, 2005
I owe my brother big time for this!

The Journey Fraternity posted:

So just pure improvements since if I ever need sockets I'm gonna be using Phoenix :v:

Yup. ActionCable is a wrapper around WebSockets, you can't even use a standard WebSocket library against it without implementing the API around ActionCable.

I honestly have no idea why they added the feature, outside of DHH doing it maybe? Ruby is horrible for web sockets (among other things).

kayakyakr
Feb 16, 2004

Kayak is true
I've found ActionCable to be OK. Not quite socket.io with node performant, but good enough and still living within the rails environment.

necrotic
Aug 2, 2005
I owe my brother big time for this!

kayakyakr posted:

I've found ActionCable to be OK. Not quite socket.io with node performant, but good enough and still living within the rails environment.

It's probably fine for lightweight use but I would in know way want to use it for anything serious.

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home

necrotic posted:

Yup. ActionCable is a wrapper around WebSockets, you can't even use a standard WebSocket library against it without implementing the API around ActionCable.

I honestly have no idea why they added the feature, outside of DHH doing it maybe? Ruby is horrible for web sockets (among other things).

Yeah, they needed it for Basecamp 3, so now it's a Rails core feature. FWIW it's come a long way from where it started, thanks to contributors going "well if this has to be here may as well make it as good as possible"

necrotic
Aug 2, 2005
I owe my brother big time for this!
It definitely has, and I don't mean to hate on the accomplishment the feature itself is. It's just that if I'm doing anything with WebSockets seriously I wouldn't want it to be Ruby at all. The language historically is really bad with evented (see how event machine works) and threaded (Ruby does not have real threads) workloads.

It has definitely gotten better over time, and ActionCable no longer depends on event machine, but there are still far superior choices for what WebSockets are (event based sockets, which I assume rails has to throw into some thread for ActionCable to work without its own dedicated process).

kayakyakr
Feb 16, 2004

Kayak is true

necrotic posted:

It definitely has, and I don't mean to hate on the accomplishment the feature itself is. It's just that if I'm doing anything with WebSockets seriously I wouldn't want it to be Ruby at all. The language historically is really bad with evented (see how event machine works) and threaded (Ruby does not have real threads) workloads.

It has definitely gotten better over time, and ActionCable no longer depends on event machine, but there are still far superior choices for what WebSockets are (event based sockets, which I assume rails has to throw into some thread for ActionCable to work without its own dedicated process).

It does work via threads. Used to use celluloid, too, along with event machine, but I think they dropped all of that. I've been deep, deep in ActionCable's guts. Scaling outward, I'll probably switch to something a bit beefier, but I've seen decent enough performance and connection width out of a single box. I do wish that we could move MRI beyond the GIL. Alas.

xenilk
Apr 17, 2004

ERRYDAY I BE SPLIT-TONING! Honestly, its the only skill I got other than shooting the back of women and calling it "Editorial".
Hey guys, I'm wondering what you guys use as far as error reporting goes ? I currently use honeybadger.io and my only grudge is that I feel I'm overpaying for such service since my apps don't report that many errors anymore.

I still like the idea of using an error reporting tool, so I'm wondering... is there any tool I can actually run on the same machine (or separate DigitalOcean block) to accomplish this very task?

Anveo
Mar 23, 2002

xenilk posted:

Hey guys, I'm wondering what you guys use as far as error reporting goes ? I currently use honeybadger.io and my only grudge is that I feel I'm overpaying for such service since my apps don't report that many errors anymore.

I still like the idea of using an error reporting tool, so I'm wondering... is there any tool I can actually run on the same machine (or separate DigitalOcean block) to accomplish this very task?

I use Rollbar on a few apps with a low volume of errors and pay nothing. If you want self-hosted then checkout Sentry.

If you try out Rollbar, I would suggest putting the following in your rollbar initializer:

code:
  config.exception_level_filters.merge!('ActiveRecord::RecordNotFound' => 'ignore')
  config.exception_level_filters.merge!('ActionController::RoutingError' => 'ignore')
That will suppress a lot of crap from crawlers.

Anveo fucked around with this message at 17:10 on Jul 1, 2016

necrotic
Aug 2, 2005
I owe my brother big time for this!

xenilk posted:

Hey guys, I'm wondering what you guys use as far as error reporting goes ? I currently use honeybadger.io and my only grudge is that I feel I'm overpaying for such service since my apps don't report that many errors anymore.

I still like the idea of using an error reporting tool, so I'm wondering... is there any tool I can actually run on the same machine (or separate DigitalOcean block) to accomplish this very task?

We use a combination of NewRelic and SignalFX: NewRelic for actual error analytics, and SignalFX for aggregate metrics that don't end up in NewRelic.

Sentry looks promising as a self-hosted solution, though I haven't tried it out yet. I plan on using some time this weekend to get it setup for some home projects, I can provide a trip report here if you want.

xenilk
Apr 17, 2004

ERRYDAY I BE SPLIT-TONING! Honestly, its the only skill I got other than shooting the back of women and calling it "Editorial".
Thanks necrotic and Anveo!

I've implemented rollbar, seems like it'll fit my needs for this project :) I'll keep honeybadger running concurrently with it for a bit and drop it off before it renews! :)

Please let me know what you think about Sentry if you end up implementing it!

kayakyakr
Feb 16, 2004

Kayak is true
I use Errbit hosted on a docker cloud instance which takes Airbrake messages.

MasterSlowPoke
Oct 9, 2005

Our courage will pull us through
I just set up Sentry this week. Haven't spent a lot of time with it but it looks pretty neat.

Pardot
Jul 25, 2001




MasterSlowPoke posted:

I just set up Sentry this week. Haven't spent a lot of time with it but it looks pretty neat.

They have a hosted version too that has been alright. I like that they rate limit you instead of charging extra when you have an error that is spamming exceptions in a loop.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
I've used Sentry somewhat lightly and does what it says on the box.

Arcaire
Jun 30, 2016

Pardot posted:

They have a hosted version too that has been alright. I like that they rate limit you instead of charging extra when you have an error that is spamming exceptions in a loop.

Care to share what sort of data do you *actually* get out of Sentry? I currently bounce between NewRelic (lol) and Skylight (good, but $$$). I need it to report errors to some degree, and stats. I get mixed information as to whether it's actually competing with NR/SL.

Pardot
Jul 25, 2001




Sentry is just for new errors in prod, so we can track them down and fix. There are a handful of normal errors, like net-ssh failing to connect because a server is booting, and for those I shove an event with the name, time, and some jsonb into a citusdb cluster and graph the hourly rate for each type. That's nice because you can see if something is out of whack recently and be able to trouble shoot, and not have it swamp sentry with these.

That graph query is just

code:
      SELECT count(*), name, date_trunc('hour', created_at) as hour
      FROM events
      WHERE created_at > now()-'1 week'::interval
      GROUP BY name, hour;
so not fancy at all, then that mozilla graphing library.

Hadlock
Nov 9, 2004

We use sentry and it catches weird things, I like it, but I've never used anything else.

Generally weird stuff that doesn't float up to the UI, or gives us instant insight to what caused the 500 error.

Most recently, we upgraded our key datatypes from v2 to v3 which I thought we fixed most of those things. One report was causing a 500 error, which was fixed in the next PR, so we I ran in to another one, I assumed it was the same problem. A quick glance at Sentry proved it was actually a completely different issue, but it presented itself in the same way as the first one that had been fixed.

If there's a better product than sentry, I want to hear about it, so we can start using it.

edit: another case where sentry was doing useful things, was we adjusted how user permissions worked for certain user level types, and sentry spit out all sorts of useful data when we tried accessing data via search that it was querying for but wasn't able to find/display

Hadlock fucked around with this message at 01:40 on Jul 4, 2016

Arcaire
Jun 30, 2016
I was wondering whether or not Sentry had any of Skylight's metrics functionality. If it did, it'd be perfect.

NewRelic is too busy telling me to buy an even pricier plan to give me much in way of useful reports.

Peristalsis
Apr 5, 2004
Move along.
Rails console and IRB both accept the operators &= and |=, but I can only find documentation online for &&= and ||=, and I certainly haven't found a comparison between the two forms. Is each shorter one just an alias for the corresponding longer one? There also seems to be some confusion over exactly what ||= does, but I"m not sure it's worth reading through if the other operators are what I want.

MasterSlowPoke
Oct 9, 2005

Our courage will pull us through
It's kind of like how += works:

a += 1
a = a + 1

Are both the same statement. So:

a ||= 1
a = a || 1

Means that a, if it's a falsy value (like nil), will equal 1. &= and |= aren't common, but they'll be

# for a = 9
a = a & 5
a &= 5

Both result in a being set to 1. Same thing for |=. Bitwise AND and OR simply aren't very popular or generally useful, so no one writes about them.

Peristalsis
Apr 5, 2004
Move along.

MasterSlowPoke posted:

It's kind of like how += works:

a += 1
a = a + 1

Are both the same statement. So:

a ||= 1
a = a || 1

Means that a, if it's a falsy value (like nil), will equal 1. &= and |= aren't common, but they'll be

# for a = 9
a = a & 5
a &= 5

Both result in a being set to 1. Same thing for |=. Bitwise AND and OR simply aren't very popular or generally useful, so no one writes about them.

Right, I think I understand what &&= and ||= do (though, as I said, I did find some pedantry at least about ||=), but I'm curious if &= and |= are the same. Are those 'bitwise'? They seem to work the same as &&= and ||= in my cursory testing.

MasterSlowPoke
Oct 9, 2005

Our courage will pull us through
You're probably just being tricked by the output. Consider:

Ruby code:
2.3.1 :001 > a = 7
 => 7 
2.3.1 :002 > a & 5
 => 5 
2.3.1 :003 > 5 & a
 => 5 
2.3.1 :004 > a && 5
 => 5 
2.3.1 :005 > 5 && a
 => 7 
& is the Bitwise AND operator. It looks at the bits set here comparing 7 (0111) and 5 (0101). 7 and 5 both have the 4's place and the 1's place set, so the answer is 5.

&& is the Logical AND operator. It look at the truthyness of the operands, and returns the last value looked at. 7 and 5 are both truthy, so it returns the last operand. This is useful for short circuiting - if you do:

if nil && 5

It first looks at nil, and as that's falsy, ends looking and returns nil. This causes the if check to fail.

Peristalsis
Apr 5, 2004
Move along.
I've started working with RSpec 3 in a rails 4 application, and I have a question.

I have a resource that is only viewable by admin users. "admin user" is defined by the method application_helper#is_admin? Eventually, this will be changed to an attribute in the user table, but I'm stuck with this structure for right now. In the controller spec for this resource, I want to make sure stuff only shows up for admins.

I tried overriding is_admin? with the helper object, but it's not available in controller specs.
So, base on a StackOverflow post, I tried just stubbing the method in the controller like this:
code:
Rspec.describe <stuff> do
  let(:admin_user) { FactoryGirl.build(:user, login: "admin_user") }
  let(:normal_user) {FactoryGirl.build(:user, login: "regularUser") }

...
  describe "GET #new" do
    it "assigns new resource for admin user" do
      allow(controller).to_receive(:is_admin?).with(@admin_user).and_return(true)
      allow(controller).to_receive(:is_admin?).with(@normal_user).and_return(false)
      ...
    end
  end
end
That causes an error apparently saying that the controller object does not implement is_admin? I get the same thing if I delete the with clause, and just try a simpler stubbing. It seems silly if I can only use allow to override existing methods, and not create new ones - am I missing something else here?

In case it matters, the application uses tabulous to control the main views. Tabulous specifies that this resource's tab shouldn't show for non-admins, but even when I take out that restriction and show to all, I get the same thing.

Peristalsis fucked around with this message at 18:43 on Jul 13, 2016

kayakyakr
Feb 16, 2004

Kayak is true
Controller specs have been abandoned like the red-headed stepchildren they are. Better off writing an integration test with capybara and poltergeist or webkit-headless.

Peristalsis
Apr 5, 2004
Move along.

kayakyakr posted:

Controller specs have been abandoned like the red-headed stepchildren they are. Better off writing an integration test with capybara and poltergeist or webkit-headless.

"Abandoned" as in they're not officially supported, and the scaffold shouldn't have put them in there to begin with, or "abandoned" as in "not fashionable any more"? Since the scaffold put them in there, it should be nice and easy to modify them to make sure that the pages only come up for admins. But if it's going to throw errors the next time we upgrade Rails versions because they've been officially deprecated, then I should probably find another approach.

Peristalsis fucked around with this message at 20:00 on Jul 13, 2016

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home
AFAIK they're discouraged not actually deprecated (so far). There was a lot of work done over the last year or two to speed up integration tests, since speed was really the only reason you'd want to spend time with controller tests anyway.

Peristalsis
Apr 5, 2004
Move along.

The Milkman posted:

AFAIK they're discouraged not actually deprecated (so far). There was a lot of work done over the last year or two to speed up integration tests, since speed was really the only reason you'd want to spend time with controller tests anyway.

Okay, so where should I put tests to make sure pages do or don't load, based on who is logged in? View specs?

Peristalsis fucked around with this message at 20:48 on Jul 13, 2016

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home

Peristalsis posted:

Okay, so where should I put tests to make sure pages do or don't load, based on who is logged in? View specs?

Integration tests (specs/features/some_feature_spec.rb)

https://github.com/jnicklas/capybara

https://robots.thoughtbot.com/rspec-integration-tests-with-capybara

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
If you have any kind of javascript running, integration tests are still dogshit slow in my experience and they can get unstable. And if there's one thing you can still test in the controller specs (and which controllers are used for anyway), it's the HTTP response so I don't see anything necessarily wrong with you writing them and you shouldn't get any deprecation warnings.

However if you write an integration test that checks the same thing basically (e.g. if you want to know that a specific flash message appeared for a non admin user and ends up redirected), then having a controller test seems redundant.

hmm yes
Dec 2, 2000
College Slice
effective_test_bot provides some helpers for integration tests, some baked-in sanity check tests you can run against any route, and can generate animated gifs of your integration tests for you. Requires minitest/devise/ujs. The README is pretty detailed. This gem is maintained by my company. We use it in about a dozen apps, but haven't done anything to push/promote it. Maybe you'll like it?

hmm yes fucked around with this message at 00:55 on Jul 14, 2016

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home

Gmaz posted:

If you have any kind of javascript running, integration tests are still dogshit slow in my experience and they can get unstable. And if there's one thing you can still test in the controller specs (and which controllers are used for anyway), it's the HTTP response so I don't see anything necessarily wrong with you writing them and you shouldn't get any deprecation warnings.

However if you write an integration test that checks the same thing basically (e.g. if you want to know that a specific flash message appeared for a non admin user and ends up redirected), then having a controller test seems redundant.

That's just a helpful nudge to rely less on JS :angel:. Unless you're doing a SPA, you shouldn't need it to test "if user logged in, display this" type stuff.

Once you learn it, IMO, capybara tests are more natural to write and cover more ground. But yeah, if you're only concerned with like HTTP status and stuff you could get by with controller tests.

atastypie posted:

effective_test_bot provides some helpers for integration tests, some baked-in sanity check tests you can run against any route, and can generate animated gifs of your integration tests for you. Requires minitest/devise/ujs. The README is pretty detailed. This gem is maintained by my company. We use it in about a dozen apps, but haven't done anything to push/promote it. Maybe you'll like it?

That's neat!

Pollyanna
Mar 5, 2005

Milk's on them.


I'm not sure how you can write integration tests that don't constantly break if you're still working on reorganizing your markup and changing things around. They seem very brittle, since they rely on CSS selectors 'n poo poo.

kayakyakr
Feb 16, 2004

Kayak is true

Pollyanna posted:

I'm not sure how you can write integration tests that don't constantly break if you're still working on reorganizing your markup and changing things around. They seem very brittle, since they rely on CSS selectors 'n poo poo.

Don't write tests that rely on CSS selectors? That's a pretty bad practice anyway.

Or if it's somehow absolutely necessary and you can't get around it no matter what, you could at least abstract out the selector so that you can update it once if the underlying structure changes?

Personally, I'm moving most of my stuff toward a service pattern, so the services are pretty easily testable and I can pretty much ignore the controllers.

Then again, I have also been moving more and more toward JS Client + API once the app gets to a point where I have to write actual JS. I used to piecemeal with turbolinks-aware JS, but at this point, I go whole hog as soon as its needed.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
If you do JS client + API with Rails do you make them as two completely separate apps or is the client still integrated with Rails/Asset pipeline?

Pollyanna
Mar 5, 2005

Milk's on them.


kayakyakr posted:

Don't write tests that rely on CSS selectors? That's a pretty bad practice anyway.

Or if it's somehow absolutely necessary and you can't get around it no matter what, you could at least abstract out the selector so that you can update it once if the underlying structure changes?

Personally, I'm moving most of my stuff toward a service pattern, so the services are pretty easily testable and I can pretty much ignore the controllers.

Then again, I have also been moving more and more toward JS Client + API once the app gets to a point where I have to write actual JS. I used to piecemeal with turbolinks-aware JS, but at this point, I go whole hog as soon as its needed.

Our current integration tests rely primarily on CSS selectors :( By which I mean, combinations of classes and the like. Clicking a button is doing something like selecting div.target-form form input.btn.btn-input.btn-form-input.btn-target-form-input which just sounds like an awful idea. I'd like us to instead select via IDs and just test individual partials and the like, but that would require us to write semantic HTML and have our stylesheet ducks in a row which is never, ever going to happen :shepface:

I'm used to testing APIs rather than HTML pages, since my experiences with Capybara have been pretty lovely.

kayakyakr
Feb 16, 2004

Kayak is true

Pollyanna posted:

Our current integration tests rely primarily on CSS selectors :( By which I mean, combinations of classes and the like. Clicking a button is doing something like selecting div.target-form form input.btn.btn-input.btn-form-input.btn-target-form-input which just sounds like an awful idea. I'd like us to instead select via IDs and just test individual partials and the like, but that would require us to write semantic HTML and have our stylesheet ducks in a row which is never, ever going to happen :shepface:

I'm used to testing APIs rather than HTML pages, since my experiences with Capybara have been pretty lovely.

expect(page).to have_text("Foo")

Buy you're right, it's lovely to have to write tests based on the structure of the page. That's why I don't do it that way, ever.

Gmaz posted:

If you do JS client + API with Rails do you make them as two completely separate apps or is the client still integrated with Rails/Asset pipeline?

Depends on which one you're using. Ember-cli-rails is phenomenally crafted and skirts around the asset pipeline while still being integrated into the monolith. React's version is not nearly as mature.

Personally, I prefer to keep it an integrated, monolith. That way your versions sync and you don't have to manage a split release.

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

controller tests are cool and good as long as you're testing a JSON api

Pollyanna
Mar 5, 2005

Milk's on them.


Even then, you should just use integration specs and test the JSON returned by the endpoints.

Adbot
ADBOT LOVES YOU

ZenVulgarity
Oct 9, 2012

I made the hat by transforming my zen

loving path, loving %path%

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply