Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass ar5 tests #689

Merged
merged 1 commit into from Jan 26, 2016
Merged

Pass ar5 tests #689

merged 1 commit into from Jan 26, 2016

Conversation

owenr
Copy link
Contributor

@owenr owenr commented Jan 12, 2016

Update test code to address deprecations/warnings and fix one legitimate issue with AR5. Not happy with several aspects of this change:

  • Gem rails-controller-testing does not work as advertised (possibly an issue with load order?) and I could only get it working when manually included, see test_helper.rb
  • HTTP request test methods in Rails 5 need parameter hash keys named 'params', so a new wrapper function is introduced twice (once in test_helper, again in spec_helper)
  • Addressing the AR5 issue seems to require a way of preventing #save on the has_one object, and there is almost certainly a better way than temporarily redefining #save on the instance

Having said that, the changes pass tests locally on MRI 2.3 (ar5) and 1.9.3-p551 (ar3/ar4). Comments and suggestions welcome.

@jaredbeck

@owenr
Copy link
Contributor Author

owenr commented Jan 12, 2016

Having some issues with tests intermittently failing. Any ideas on that are also welcome.

@bronson
Copy link

bronson commented Jan 12, 2016

Interesting... Ten tests failed the first time I ran rake, but that was it. Now I can't get any to fail.

Here's the log: https://gist.github.com/bronson/70dd3c4aaf395df4bf93

And, if I rm -r test/dummy/db/*.sqlite3 and run rake again, I get the same ten errors. Looks to be an issue related to a fresh database?

Is that the problem you're seeing?

@bronson
Copy link

bronson commented Jan 12, 2016

I'm at 25 iterations, no failures yet. I'll let it run for a few hundred.

ctr=; while rake; do echo ITERATION $((ctr += 1)); done

But, no, I'm not seeing any intermittent errors on your branch.

I'm using sqlite, are you testing on a different database?

@jaredbeck
Copy link
Member

Owen, thanks for this! I'll review what I can this week.

.. if I rm -r test/dummy/db/*.sqlite3 and run rake again, I get the same ten errors. Looks to be an issue related to a fresh database?

Scott, Yeah, that's a known issue with running the local test suite. If you can fix it, that'd be great.

@bronson
Copy link

bronson commented Jan 12, 2016

260 iterations, 0 failures. I don't see any intermittent issues. (sqlite, mac, ruby 2.2.2)

@owenr
Copy link
Contributor Author

owenr commented Jan 13, 2016

Initially tested using sqlite3 locally, no issues. As you can see, Travis CI failed all my builds for various reasons; it looks like Postgresql is the main issue now. Simulating locally it took me 22 runs before this failure (postgres, mac, 2.3.0):

PaperTrailCleanerTest#test_: `clean_versions!` method No options provided should removes the earliest version(s).  [/Users/owen/dev/paper_trail/test/unit/cleaner_test.rb:34]:
--- expected
+++ actual
@@ -1 +1 @@
-["Aglae Schaden", "Carley Doyle", "Karianne McDermott"]
+["Aglae Schaden", "Carley Doyle", "Jaime Witting"]

@bronson
Copy link

bronson commented Jan 13, 2016

Switched to postgres and I finally got a failure after 76 iterations: https://gist.github.com/bronson/01f05504f81efe072b40

Glancing at it, maybe it died because name contained a single quote... A sql injection opportunity? :) I'll look closer tomorrow if nobody beats me to it.

Also, there might be a test order dependency. At least:

rspec --seed=0: 0 errors
rspec --seed=1: 1 error
rspec --seed=9: 10 errors

Do the tests have a required order?

@owenr
Copy link
Contributor Author

owenr commented Jan 14, 2016

Confirmed, unescaped input (only when using postgres). I've written some failing tests and will open an issue. Unfortunately it seems unrelated to the failures from Travis here and here.

I'm not familiar with the impact of seeding on this test suite and I couldn't reproduce those spec failures with seeds 1 and 10 (mac, postgres, ruby 2.2.2).

@jaredbeck
Copy link
Member

When comparing gem versions, I like to use Gem::Version, e.g.

- ActiveRecord::VERSION::STRING >= '5.'
+ Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new("5")

PS: If we didn't have to support AR3, we could use the more convenient ActiveRecord.gem_version

@@ -162,6 +164,15 @@ def reify_has_ones(transaction_id, model, options = {})
end
end

# Suppress #save so we can reassociate with the reified master of a has_one relationship
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you expand on this comment? Specifically, please explain what changed in AR5.

Also, please alphabetize methods.

@jaredbeck
Copy link
Member

Owen, I've been cherry-picking the less controversial commits out of here.

I thought there was no sense in waiting, but it will mean you'll have to rebase this PR, sorry.

@owenr
Copy link
Contributor Author

owenr commented Jan 16, 2016

No problem at all; like I said, this code is not right and should be improved before merging.

Some comments:

  • I've reordered methods alphabetically as requested.
  • Switched to Gem::Version for comparisons, but note that comparison with '5' is insufficient ('5' is not >= '5.0.0.beta').
  • I can't find the AR5 change to has_one, but from the symptoms it looks like the associated object is persisted before the main object (which seems correct as per the AR4 documentation). I've elaborated on the comment.

@jaredbeck
Copy link
Member

Owen, It looks like this needs another rebase, sorry.

ActionDispatch::IntegrationTest.send(:include, Rails::Controller::Testing::Integration)

ActionView::TestCase.send(:include, Rails::Controller::Testing::TemplateAssertions)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole on_load could use a comment, e.g. why are we including these modules, why are we using send, why on_load, etc. I don't personally understand any of it, so the comment is mostly for me :p

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied wholesale from rails-controller-testing. I don't know why putting it here works but requiring the library doesn't. I've also tried require: false in the Gemfile and manually requiring it instead but that doesn't help. Removing this code, I get:

NoMethodError: assigns has been extracted to a gem. To continue using it,
        add `gem 'rails-controller-testing'` to your Gemfile.

Not knowing if this is caused by something in PaperTrail or an issue with rails-controller-testing itself (or Rails 5), I'm not sure whether I should raise an issue over there.

@jaredbeck
Copy link
Member

HTTP request test methods in Rails 5 need parameter hash keys named 'params'

Is this change documented in a changelog somewhere, or a guide?

@jaredbeck
Copy link
Member

HTTP request test methods in Rails 5 need parameter hash keys named 'params'

Is this change documented in a changelog somewhere, or a guide?

Found it. It's in the release notes for ActionPack 5:

Migrating to keyword arguments syntax in ActionController::TestCase and ActionDispatch::Integration HTTP request methods. (Pull Request)
http://edgeguides.rubyonrails.org/5_0_release_notes.html#action-pack

else
args
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment explaining the change to ".. keyword arguments syntax in ActionController::TestCase and ActionDispatch::Integration HTTP request methods." and include a link to the ActionPack changelog (https://github.com/tgxworld/rails/blob/master/actionpack/CHANGELOG.md)

@owenr
Copy link
Contributor Author

owenr commented Jan 21, 2016

Rebased. I also fixed one more deprecation warning (use_transactional_tests) and added a note about 1-second differences in tests (for MySQL and AR5). Still not happy.

@owenr
Copy link
Contributor Author

owenr commented Jan 22, 2016

I think this is just about done. Please review and let me know; I'll squash the commits.

@jaredbeck
Copy link
Member

This looks good to me. I will merge this unless Ben has any concerns @batter

I wish we didn't have to time-travel just to make MySQL happy, but it is something we've run into before (#314, 1d120ab)

@owenr
Copy link
Contributor Author

owenr commented Jan 24, 2016

Time travel is required due to a change in ActiveRecord 5 (if no attributes change, nothing is done). We could sleep instead of travel if that's preferred.
I've squashed the commits (and backed out an unneeded change to rubocop_todo picked up in review).

jaredbeck added a commit that referenced this pull request Jan 26, 2016
@jaredbeck jaredbeck merged commit d68587b into paper-trail-gem:master Jan 26, 2016
@jaredbeck
Copy link
Member

Merged. Thanks for your work on this, Owen.

@bronson
Copy link

bronson commented Jan 26, 2016

Wooo! Great job Owen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants