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

Make the object column optional #1122

Merged
merged 1 commit into from
Aug 6, 2018

Conversation

seanlinsley
Copy link
Member

Part 1 of #1099

@seanlinsley seanlinsley mentioned this pull request Jul 24, 2018
4 tasks
@jaredbeck
Copy link
Member

Hi Sean. Just FYI that I haven't had a chance to review this yet because I've been focusing on #1108.

Copy link
Member

@jaredbeck jaredbeck left a comment

Choose a reason for hiding this comment

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

This looks great, Sean. My only concern is the one little thing with the linter.

ActiveRecord::Migration.add_column :versions, :object, :text
PaperTrail::Version.reset_column_information
end
# rubocop:enable RSpec/BeforeAfterAll
Copy link
Member

Choose a reason for hiding this comment

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

Should we try to do this without offending the linter? We could use before(:each), right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Normally I'd avoid doing this sort of thing in a before(:each) b/c that'd mean doing four extra database requests per test (removing the column, adding the column, and 2x reloading the schema).

It appears that the Rubocop error is concerned with transactional fixtures in Rails:

spec/paper_trail/model_spec.rb:882:5: C: RSpec/BeforeAfterAll: Beware of using before :all as it may cause state to leak between tests. If you are using rspec-rails, and use_transactional_fixtures is enabled, then records created in before :all are not automatically rolled back.
    before :all do
    ^^^^^^^^^^^
spec/paper_trail/model_spec.rb:886:5: C: RSpec/BeforeAfterAll: Beware of using after :all as it may cause state to leak between tests. If you are using rspec-rails, and use_transactional_fixtures is enabled, then records created in after :all are not automatically rolled back.
    after :all do

So perhaps we should disable this cop globally.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, apparently we do use transactional fixtures:

if active_record_gem_version < ::Gem::Version.new("5")
require "database_cleaner"
DatabaseCleaner.strategy = :truncation
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.before { DatabaseCleaner.start }
config.after { DatabaseCleaner.clean }
end
else
RSpec.configure do |config|
config.use_transactional_fixtures = true
end
end

Disallowing before(:all) seems to be preferable if your test suite is run in parallel: rubocop/rubocop-rspec#108. Is that something that's needed for this test suite? Probably not, since the tests on CI take 1-4 minutes.

Copy link
Member Author

Choose a reason for hiding this comment

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

That research ended up being fairly inconclusive. I'll update this to use before(:each) if you'd still prefer that approach.

@jaredbeck
Copy link
Member

jaredbeck commented Aug 5, 2018 via email

@jaredbeck jaredbeck merged commit 3f9b5be into paper-trail-gem:master Aug 6, 2018
@seanlinsley seanlinsley deleted the drop-object branch August 6, 2018 01:02
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

2 participants