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
Peristalsis
Apr 5, 2004
Move along.
I've started working with RSpec and Capybara, and it's going okay, but I'm wondering what the best way is to query information when a test fails. In particular, I have an intermittent failing expectation on the page object after submitting a form:
code:
expect(page).to have_content('Info message here')
The page has an incorrect field error instead of the expected informational message, so I put a debugger in just after the field in question should be filled in with the command
code:
fill_in "Minimum Quantity', with: 0.01
and then executed page.find('#aliquot_min_quantity').text at the debug prompt, which returns an empty string.

1) Am I mis-using fill_in in some way? I tried passing in the string "0.01" instead, but it didn't change anything.
2) Am I mis-using page in some way? Does it only have data after returning from a post command?
3) I got this far by printing page.html at the debug prompt, copying it into a file, opening that file in a browser, and noticing that it had an error message indicating that the field in question was too large (but not empty*). This seems like a very clunky workflow - is there a better approach or tool I should be using? I like some of the features of RSpec compared to test::unit, but I miss just being able to print out stuff from the object being tested.

More background:
1) Another (student hourly) developer claims not to get any errors when running this test.
2) Some similar errors came down to issues with FactoryGirl giving invalid objects. That may well be the root cause here, but I really need to learn the tools and skills for debugging failed tests.

* An empty field should actually have triggered a different error, so I'm guessing that I don't get what I think I should get with page.find.

Peristalsis fucked around with this message at 19:36 on Jul 20, 2016

Adbot
ADBOT LOVES YOU

necrotic
Aug 2, 2005
I owe my brother big time for this!
Are you submitting the form, or is it a frontend validation onBlur/onChange?

Peristalsis
Apr 5, 2004
Move along.

necrotic posted:

Are you submitting the form, or is it a frontend validation onBlur/onChange?

The form is submitted. Here's more context:
code:
feature 'Material owner requests an aliquot' do
  let(:project) { user.projects.sample }
  let(:material) { FactoryGirl.create(:material, owner: user, perishable: false, status: 'Ready for distribution', \
       quantity_remaining: 100.0, original_quantity: 100.0, project: project) }
    ...
  scenario 'with invalid min quantity', js: true do
    # validation should only check on creation
    bad_quantity = material.quantity_remaining + 1
    visit material_path(material)
    click_link 'Request an Aliquot' 
    fill_in 'Minimum Quantity', with: bad_quantity
    fill_in 'Intended Use', with: 'Intended Use'
    select(material.project.display_name, from: 'Requesting Project*')
    click_button 'Send Request'                                # <== This is the submit button
    expect(page).to have_content("Min quantity must be less than the Parent Material's remaining quantity!. \
       Remaining: #{material.quantity_remaining.to_f}. Min: #{bad_quantity}")

    # use valid qty and save
    click_link 'Request an Aliquot'
    fill_in 'Minimum Quantity', with: 0.01
    fill_in 'Intended Use', with: 'Intended Use'
    select(material.project.display_name, from: 'Requesting Project*')
    click_button 'Send Request'                                # <== This is the submit button
    expect(page).to have_content('Aliquot requested. You will receive an \  # <== This is the expectation that fails intermittently
       email notification when it has been dispensed by the provider.')     
  end
end
When I check page.html after that second expect(page) command, it has the error message about the min quantity from the top part of the test. I suppose if the click_button fails for some reason, I could just still be on that page.

In any case, I suspect I could resolve this by splitting it into multiple scenarios, but I really want to figure out why the line fill_in 'Minimum Quantity', with: 0.01 doesn't seem to be working. Or if it is working, why querying the page object for it returns an empty string.

Edit for formatting

Peristalsis fucked around with this message at 22:26 on Jul 20, 2016

Peristalsis
Apr 5, 2004
Move along.

Peristalsis posted:

The form is submitted. Here's more context:
code:
feature 'Material owner requests an aliquot' do
  let(:project) { user.projects.sample }
  let(:material) { FactoryGirl.create(:material, owner: user, perishable: false, status: 'Ready for distribution', \
       quantity_remaining: 100.0, original_quantity: 100.0, project: project) }
    ...
  scenario 'with invalid min quantity', js: true do
    # validation should only check on creation
    bad_quantity = material.quantity_remaining + 1
    visit material_path(material)
    click_link 'Request an Aliquot' 
    fill_in 'Minimum Quantity', with: bad_quantity
    fill_in 'Intended Use', with: 'Intended Use'
    select(material.project.display_name, from: 'Requesting Project*')
    click_button 'Send Request'                                # <== This is the submit button
    expect(page).to have_content("Min quantity must be less than the Parent Material's remaining quantity!. \
       Remaining: #{material.quantity_remaining.to_f}. Min: #{bad_quantity}")

    # use valid qty and save
    click_link 'Request an Aliquot'
    fill_in 'Minimum Quantity', with: 0.01
    fill_in 'Intended Use', with: 'Intended Use'
    select(material.project.display_name, from: 'Requesting Project*')
    click_button 'Send Request'                                # <== This is the submit button
    expect(page).to have_content('Aliquot requested. You will receive an \  # <== This is the expectation that fails intermittently
       email notification when it has been dispensed by the provider.')     
  end
end
When I check page.html after that second expect(page) command, it has the error message about the min quantity from the top part of the test. I suppose if the click_button fails for some reason, I could just still be on that page.

In any case, I suspect I could resolve this by splitting it into multiple scenarios, but I really want to figure out why the line fill_in 'Minimum Quantity', with: 0.01 doesn't seem to be working. Or if it is working, why querying the page object for it returns an empty string.

Edit for formatting

Apparently I need to be checking the value method instead of the text method, and find_field('Minimum Quantity').value does return "0.01".
Putting a debugger in there to stop when that value isn't returned has made it harder to reproduce the error, but I did finally get it again. The value of the field does come back as "0.01", but the page still doesn't contain the expected message (second expectation line at end of code above).

I noticed that the documentation for finders says that they wait for the element to appear. Is it possible that there's some sort of delay causing this? That the fill_in method is just taking a long time to update the page object, so that when I submit, it has stale data? I'd think this would be precluded by the fact that it just happened despite the finder returning the correct value before submitting, but I'm grasping at straws.

EVGA Longoria
Dec 25, 2005

Let's go exploring!

Peristalsis posted:

Apparently I need to be checking the value method instead of the text method, and find_field('Minimum Quantity').value does return "0.01".
Putting a debugger in there to stop when that value isn't returned has made it harder to reproduce the error, but I did finally get it again. The value of the field does come back as "0.01", but the page still doesn't contain the expected message (second expectation line at end of code above).

I noticed that the documentation for finders says that they wait for the element to appear. Is it possible that there's some sort of delay causing this? That the fill_in method is just taking a long time to update the page object, so that when I submit, it has stale data? I'd think this would be precluded by the fact that it just happened despite the finder returning the correct value before submitting, but I'm grasping at straws.

As a rule, most people generally prefer 1 expectation per spec. Feature specs sometimes get an exception, but that's more for testing multiple things that come back from a single action. You're testing two scenarios in a single example.

If you test that exact scenario with live code (Filling 101.0 in on that form, then filling in 0.01) does it work?

As far as waiting goes, Capybara has a "Default max wait time" it will wait for something to happen. "Something" is a DOM change, a URL change, or an ajax request completion. I want to say it's 5 seconds, but that might be my team overwriting the defaults. In general, as long as you don't have 300 things happening on the page, it shouldn't be an issue.

Does this functionality you're testing use Javascript in any way? If not, turn off js: true in the spec. If it does, try using poltergeist and have js_errors set to true, so you can see if it's JS freaking out.

Check the log/test.log file after the test runs -- see if you're seeing the second request hit, or if any exceptions show up.

EVGA Longoria fucked around with this message at 13:22 on Jul 22, 2016

Peristalsis
Apr 5, 2004
Move along.

EVGA Longoria posted:

As a rule, most people generally prefer 1 expectation per spec. Feature specs sometimes get an exception, but that's more for testing multiple things that come back from a single action. You're testing two scenarios in a single example.

I briefly tried splitting them out to separate tests, but that didn't resolve the problem (thought it's possible I didn't get them split completely - I got distracted by something else before doing a lot of work on it). I didn't write this test originally, but it's daisy-chained like this because the setup for the last test allows a couple of other tests along the way.

EVGA Longoria posted:

If you test that exact scenario with live code (Filling 101.0 in on that form, then filling in 0.01) does it work?

Yes, but it works most of the time (say, 90%+) in this test, too. However, it's hard to recreate the exact same scenario as the test, because it's using some other made-up data.

EVGA Longoria posted:

As far as waiting goes, Capybara has a "Default max wait time" it will wait for something to happen. "Something" is a DOM change, a URL change, or an ajax request completion. I want to say it's 5 seconds, but that might be my team overwriting the defaults. In general, as long as you don't have 300 things happening on the page, it shouldn't be an issue.

The default is 2 seconds, and I've tried changing it to 5, which didn't help.

EVGA Longoria posted:

Does this functionality you're testing use Javascript in any way? If not, turn off js: true in the spec. If it does, try using poltergeist and have js_errors set to true, so you can see if it's JS freaking out.

Check the log/test.log file after the test runs -- see if you're seeing the second request hit, or if any exceptions show up.

I'll take a look at poltergeist, and see what I can do. In the mean time, I did find out a few other things:
1) It's a really bad idea to run the test 10 times in a row with a script in Rails console. Instead of deleting the test data at the end of the test, it deleted my dev environment's data. I'm using shell commands to run it multiple times now.
2) I was finally able to reproduce the failing test on the other developer's computer (still intermittently), so it's not just my system being flaky.
3) It's not just the last expectation that can fail. At least one of the other ones failed in my latest batch of tests (I don't have the results in front of me, so I can't say for sure if all three have failed at this point).
4) I removed the FactoryGirl input and just created some static dummy data to use, and that didn't help, either, to my surprise.
5) Executing commands at a debug prompt in the middle of a failing test seems to cause a lot of segmentation faults. Right now, checking valid? on a new object is doing it every time I get to the debugger at a certain point.

I also tried saving off snapshots of the page just before failures, and I don't see anything on them that indicate that the submission is about to fail.

I really just need a way to poke around and check data without causing core dumps.

Edit: I just had Capybara save off an image after clicking the Update (submit) button. Clicking on submit didn't change the page - page.save_screenshot shows that I'm still on the modal popup with the min quantity, etc, and not on the screen that that should route me to for the new object. This might be similar to something that happened the other day - the student developer had a test that failed because inserting a message into the screen adjusted the position of the submit button, and the click_button method seemed to "miss" because the button had moved, and it didn't notice. Is this a thing in RSpec/Capybara? I don't see anything on this particular screenshot that would obviously have moved the modal's controls around, but maybe there's something else like this that could be causing the issue.

Edit2: The return value of click_button is a hash of coordinates:
code:
[1] pry(#<RSpec::ExampleGroups::Aliquots::MaterialOwnerRequestsAnAliquot>)> res
=> {"position"=>{"x"=>389.5, "y"=>496.5}}
Presumably, that's the point on the screen where the click took place. Is there a way to find out if the click succeeded, instead?

Peristalsis fucked around with this message at 18:31 on Jul 22, 2016

Peristalsis
Apr 5, 2004
Move along.

Peristalsis posted:

Whole lotta words.

Based on a StackOverflow post, I changed click_button("Request Aliquot") to find("#button_id_string").trigger("click"), and my problems magically disappeared.

Peristalsis fucked around with this message at 20:33 on Jul 22, 2016

EVGA Longoria
Dec 25, 2005

Let's go exploring!

Peristalsis posted:

Based on a StackOverflow post, I changed click_button("Request Aliquot") to find("#button_id_string").trigger("click"), and my problems magically disappeared.

So, using `trigger` like that triggers the browser-level(slash JS level) event -- do you have some kind of binding on it in JS?

So weird that it's happening that way. I'd give it a lot of runs to see if it fixes it. In my experience, things like this don't actually fix failing specs, Capybara just decides to play nice for a day or two before making GBS threads the bed again.

Half of my job seems to be fixing people's intermittently failing Capybara specs.

Peristalsis
Apr 5, 2004
Move along.

EVGA Longoria posted:

So, using `trigger` like that triggers the browser-level(slash JS level) event -- do you have some kind of binding on it in JS?

So weird that it's happening that way. I'd give it a lot of runs to see if it fixes it. In my experience, things like this don't actually fix failing specs, Capybara just decides to play nice for a day or two before making GBS threads the bed again.

Half of my job seems to be fixing people's intermittently failing Capybara specs.

I'm in training all week this week, so I probably won't be looking at these tests until at least Monday. If you want, I can post an update then (can PM results if you're curious, but don't want to clutter up the thread).

prom candy
Dec 16, 2005

Only I may dance

Pollyanna posted:

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

What are the best tools for doing this? I tried to get something going with capybara but it didn't seem like it was built to test JSON responses.

prom candy
Dec 16, 2005

Only I may dance

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?

Sprockets is really slow compared to some of the node-based stuff for asset compilation, and there's a lot of great tooling in the javascript world that's miles ahead of Sprockets in terms of developer happiness (eg. webpack-dev-server with hot module reloading) but the sacrifice is you have to do a lot of configuration up front and it's a pain in the rear end.

I have a setup mostly working now where my JS stuff lives in the same project as Rails and is just compiled by webpack and imported into my Rails app. I've built apps where the client and API are separate projects and it's a pain in the rear end dealing with sync and deployment.

There's no one good answer right now, Rails is fantastically convenient for getting a project off the ground but the front-end tooling is currently behind the curve. I've heard rumours that 5.1 is going to address allowing developers to swap out Sprockets with alternate systems a little more easily. I hope that's true.

Less Fat Luke
May 23, 2003

Exciting Lemon

prom candy posted:

What are the best tools for doing this? I tried to get something going with capybara but it didn't seem like it was built to test JSON responses.
Using minitest it's pretty straightforward. Start with inheriting from ActionDispatch::IntegrationTest and do something like:
code:
class TestMyShit < ActionDispatch::IntegrationTest
  test 'check a response' do
    post '/rest.json', { param: :value }, { header: :value }
    assert_response :success
    parsed_response = JSON.parse(response.body)
    
    expected_data = { just: :a, big: :old, hash: :representing, the: :response }
    assert_equal expected_data, parsed_response
  end
end
You can get fancy and save the resultant JSON somewhere, configure your auth or data fixtures in the setup, etc. But that's the general pattern I've seen. Some tests go all fine grained and do like:
code:
assert_equal parsed_response[:key][:key2], value

kayakyakr
Feb 16, 2004

Kayak is true

prom candy posted:

There's no one good answer right now, Rails is fantastically convenient for getting a project off the ground but the front-end tooling is currently behind the curve. I've heard rumours that 5.1 is going to address allowing developers to swap out Sprockets with alternate systems a little more easily. I hope that's true.

This is my biggest current wishlist item.

The Journey Fraternity
Nov 25, 2003



I found this on the ground!
New Turbolinks is the tits.

That is all.

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home

The Journey Fraternity posted:

New Turbolinks is the tits.

That is all.

I'm a fan of how it Actually Works now.

Pollyanna
Mar 5, 2005

Milk's on them.


Out of curiosity, what is it that made old Turbolinks bad and new Turbolinks good? I was always told to avoid it, so it's new territory to me.

EVGA Longoria
Dec 25, 2005

Let's go exploring!

prom candy posted:

What are the best tools for doing this? I tried to get something going with capybara but it didn't seem like it was built to test JSON responses.

Rack::Test is designed for this. Instead of serving your app as an http server, it treats it like a function and checks input output without any http requests. It's significantly faster and more stable.

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home

Pollyanna posted:

Out of curiosity, what is it that made old Turbolinks bad and new Turbolinks good? I was always told to avoid it, so it's new territory to me.

Previous versions were pretty buggy, and created a lot of havoc with other libraries like jQuery. 5 is a total rewrite, I've deployed it a few times now and it's been flawless. You still have to adjust your listeners for the turbolinks events and not the standard document ones but that's really it.

They also now have iOS and Android bindings for creating hybrid apps from your views which I'd like to try out.

EVGA Longoria posted:

Rack::Test is designed for this. Instead of serving your app as an http server, it treats it like a function and checks input output without any http requests. It's significantly faster and more stable.

Yeah capybara is for behavior testing, they even specifically say do not use it for testing APIs.

Chilled Milk fucked around with this message at 15:28 on Jul 28, 2016

GlyphGryph
Jun 23, 2013

Down came the glitches and burned us in ditches and we slept after eating our dead.
Turbolinks is still garbage, it is just garbage in new and exciting ways now, I finally gave up and turned it off after I realized it was the source of every single one of my websocket bugs.

Other new and exciting changes in Rails 5 include a redefinition of the belongs_to behaviour to include automatic presence validations which is kind of a horrible surprise since there is no indication of why your new models are failing validations you never wrote.

And it stills ships with a version of Jquery that generates incompatible json ajax requests by default, was kinda hoping they would fix that one.

Well ActionCable seems nice enough I guess

GlyphGryph fucked around with this message at 22:53 on Aug 2, 2016

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

GlyphGryph posted:

Other new and exciting changes in Rails 5 include a redefinition of the belongs_to behaviour to include automatic presence validations which is kind of a horrible surprise since there is no indication of why your new models are failing validations you never wrote.

Did you upgrade without reading the patch notes or something?

quote:

And it stills ships with a version of Jquery that generates incompatible json ajax requests by default, was kinda hoping they would fix that one.

Is there an open issue for that? I don't use jquery but I can't imagine that being broken.

edit: maybe try using a different jquery

https://github.com/rails/jquery-rails

necrotic fucked around with this message at 03:55 on Aug 3, 2016

GlyphGryph
Jun 23, 2013

Down came the glitches and burned us in ditches and we slept after eating our dead.

necrotic posted:

Did you upgrade without reading the patch notes or something?
Actually it doesn't work that way if you upgrade, only if you install a new app, so that's something at least. And of course I switched to the new version without reading all the patch notes! I read up on the changes I thought would be relevant, I didn't expect surprise validations being added to . I'll get around to reading the rest of the patch notes before I do anything more important than the Awful game jam, but it still seems like an anti-feature and I absolutely know it's one of those things that's going to trip me up again in the future.

quote:

Is there an open issue for that? I don't use jquery but I can't imagine that being broken.

You know, I couldn't find one. I was sure I remember one existing at one point, but can't seem to find it in either the jquery or rails projects, just a bunch of people complaining about it. I'll check and see if I'm pulling in an old version or something, and if I'm not maybe I should get off my rear end and submit a fix myself because god drat is it the most annoying thing and even knowing it doesn't work I still keep expecting it to work. Easy to work around once you know what the problem is (from either the rails side or the jquery side), but really hard to figure out that somewhere between jquery and rack all your json arrays are getting turned into objects when you expect something so simple-seeming (send json, receive json) to "just work" and actually be the same json on both ends.

Although that was less of an issue here since I swapped over to letting the websockets handle that stuff, and it works fine there, just not in "normal" requests.

GlyphGryph fucked around with this message at 15:20 on Aug 3, 2016

Pollyanna
Mar 5, 2005

Milk's on them.


If I have two domain objects that behave identically, have the same attributes, and are associated with the same aggregate model, but are rendered differently e.g. images and videos, how do I handle them ORM-wise? Should I differentiate their kinds with some kind of type enum attribute, or by making then totally different models? e.g. a Media virtual model that Image and Video extend. What do I switch on to determine how they are rendered?

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

Pollyanna posted:

If I have two domain objects that behave identically, have the same attributes, and are associated with the same aggregate model, but are rendered differently e.g. images and videos, how do I handle them ORM-wise? Should I differentiate their kinds with some kind of type enum attribute, or by making then totally different models? e.g. a Media virtual model that Image and Video extend. What do I switch on to determine how they are rendered?

The approach we use at work for a very similar problem is a Media model which has a polymorphic item associated. The item itself is the video or image. In the Media model you have general metadata (name, description, timestamps, etc) and then the item model has type-specific data.

code:
class Media < ActiveRecord::Base
  # Or use has_many for multiple formats/encodings
  has_one :item, polymorphic: true

  validates :name, :description, presence: true
  validates :item_type, inclusion: {in: %w(Video Image)}
end

class Video < ActiveRecord::Base
  validates :length, numericality: {greater_than_or_equal_to: 0}
end

class Image < ActiveRecord::Base
end
This keeps you away from terrible abstract models and allows you to keep domain logic isolated.

You can then switch on Media#item_type or the class type of the associated object.

Pollyanna
Mar 5, 2005

Milk's on them.


Sweet, that'll come in real handy soon. As for enumerated attributes, did Rails enums fall out of favor or something? I don't see people using the enum syntax in models much, even for things that are simple like statuses.

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

Pollyanna posted:

Sweet, that'll come in real handy soon. As for enumerated attributes, did Rails enums fall out of favor or something? I don't see people using the enum syntax in models much, even for things that are simple like statuses.

I don't know about ActiveRecord::Enum, I try to use postgres enums directly when I can instead. Rails 4+ makes it relatively easy to support them properly (5 is even easier) and then you get sweet enums in your actual database.

Pardot
Jul 25, 2001




necrotic posted:

I don't know about ActiveRecord::Enum, I try to use postgres enums directly when I can instead. Rails 4+ makes it relatively easy to support them properly (5 is even easier) and then you get sweet enums in your actual database.

In general, I think you should put as many constraints as possible in the database. Your schema and constraints in the database change an order of magnitude or two less than changes to your code. So you're much more likely to introduce a code bug that starts putting in bad data.

Set every column that "will never be null" to not null, use appropriate data types (like enum), use check constraints, use foreign keys. It's better to have your database as the last line of defense against bad data getting in, than to do a manual cleanup job after poo poo has gotten in for months unnoticed.

kayakyakr
Feb 16, 2004

Kayak is true

Pollyanna posted:

Sweet, that'll come in real handy soon. As for enumerated attributes, did Rails enums fall out of favor or something? I don't see people using the enum syntax in models much, even for things that are simple like statuses.

Honestly don't know that many people are aware of AR::Enum. I like it a bunch, especially like that it integrates easily with PG Enum types.

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home
I definitely use ActiveRecord enums, I'd wager it's just not a widely known feature.

necrotic
Aug 2, 2005
I owe my brother big time for this!
I didn't even know it existed until he asked. Doesn't help that the main product I work on is still on 3.0 :suicide:

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
Enums were introduced in Rails 4.1, so you never really had chance.

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

Am I correct that using native postgres types forces you to switch your app schema over to :sql format? That seemed to be required last time I tried to use them, and I can't remember why that was undesirable exactly. Has anyone experienced any problems there?

necrotic
Aug 2, 2005
I owe my brother big time for this!
Yeah, unless you write extensions to the Ruby dump supporting the native stuff. Straight to SQL is way easier currently.

Pollyanna
Mar 5, 2005

Milk's on them.


Well, I like enum. We should use it more for simple status things. :colbert:

I've got a Vagrant-Docker-Compose setup going, and I'm looking for a simple dev setup and run script, for building, migrating, and running the project. They're just a few lines of shell commands. Is there a more elegant option than bash build.sh && bash run.sh or is that the better choice?

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

Pollyanna posted:

Well, I like enum. We should use it more for simple status things. :colbert:

I've got a Vagrant-Docker-Compose setup going, and I'm looking for a simple dev setup and run script, for building, migrating, and running the project. They're just a few lines of shell commands. Is there a more elegant option than bash build.sh && bash run.sh or is that the better choice?

I usually have a single entry point that handles any required setup (with some checks so it doesn't do it every time) and then start. Splitting out is nice, though.

Why still use Vagrant, though? Docker for OSX uses xhyve now and Hyper-V on Windows.

Sivart13
May 18, 2003
I have neglected to come up with a clever title

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.
I write a ton of tests at work, and I don't think that's true at all. Controller tests still work fine in Rails 5, you just need the rails-controller-testing gem if you want to test the instance variables assigned by the controller.

Capybara tests are great, but they're slow as hell and run into all sorts of async issues that can make your suite flaketastic in a hurry.

A good test suite has coverage at EVERY level, with high-level acceptance tests covering the a subset of all paths while lower-level service and unit tests handle the edge cases. See http://martinfowler.com/bliki/TestPyramid.html for more words on the topic I generally agree with.

Sivart13
May 18, 2003
I have neglected to come up with a clever title
Hey Rails thread, first time long time.

For any of you out there who've tried to upgrade an existing app to Rails 5 you may have noticed the need to change test code like
code:
get :users, search: 'staraptor', format: :json
expect(response).to be_success
to
code:
get :users, params: { search: 'staraptor' }, format: :json
expect(response).to be_success
in all your tests. Since that can be a real pain in the rear end, I wrote a tool called rails5-spec-converter to do it for you.

I'd really love it if any of y'all tried it out on your next upgrade, or told any Rails5-upgrading friends about it. Hopefully the amount of time it might eventually save will exceed the time I spent writing it :)

EVGA Longoria
Dec 25, 2005

Let's go exploring!

Sivart13 posted:

Hey Rails thread, first time long time.

For any of you out there who've tried to upgrade an existing app to Rails 5 you may have noticed the need to change test code like
code:

get :users, search: 'staraptor', format: :json
expect(response).to be_success
to
code:

get :users, params: { search: 'staraptor' }, format: :json
expect(response).to be_success

in all your tests. Since that can be a real pain in the rear end, I wrote a tool called rails5-spec-converter to do it for you.

I'd really love it if any of y'all tried it out on your next upgrade, or told any Rails5-upgrading friends about it. Hopefully the amount of time it might eventually save will exceed the time I spent writing it :)

Thanks, this has been something we've been looking at. Anything that makes it easier is great. Will let you know how it goes.

necrotic
Aug 2, 2005
I owe my brother big time for this!
Neat! I was about to start looking around for an AST transformer to help with our next big upgrade, this helps a ton!

Peristalsis
Apr 5, 2004
Move along.
I think there's a weird view issue in our Rails 4 app.

We have a form with a partial, call them _my_form.html.erb and _my_partial.html.erb. I'd like to pass an instance object from the form to the partial. If this had been written by a sane person, I'd just put this line in the form:
code:
<%= render partial: "my_partial", locals: {my_model_object: @my_model_object} %>
However, the partial is actually rendered by an ajax call. So, in my_class.js, there's an ajax call that calls a controller method, which renders the partial.

So, in the ajax call, we have
code:
...
  complete: function complete(xhr) {
    $('#placeholder-div').html(xhr.responseText);
  },
...
and the HTML is updated by this ajax call, removing my opportunity to pass data to the partial.

My question, quite simply, is this: Is there an easy way to pass @my_model_object from the form to the partial in this case? I could probably pass its attributes to the ajax call, then reconstitute it somehow in the partial, but I'd like to avoid that.

Adbot
ADBOT LOVES YOU

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
The JRuby documentation is so bad that it almost seems like the project is abandoned.

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