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

always return Postgres table names with schema to avoid awfulness #282

Conversation

WattsInABox
Copy link
Contributor

  • without the schema, the migrations table gets truncated since the default AR method returns ‘public.schema_migrations’
  • also a possibility is truncation of tables other than desired once since without the schema, Postgres has no way of knowing which table to truncate if two schemas have the same table

describe '#database_cleaner_table_cache' do
it 'should default to the list of tables with their schema' do
connection.instance_variable_set(:@database_cleaner_tables, nil)
connection.should receive(:tables_with_schema)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer we didn't set an expectation on the internals of the class, but test the desired output state.

@JonRowe
Copy link
Contributor

JonRowe commented Dec 5, 2014

Thanks for this @BillyWatson, could you possibly tweak the spec like I suggested (roll them together) we don't need to test private methods, and we definitely don't need to partially mock this.

@WattsInABox
Copy link
Contributor Author

Will do

@JonRowe
Copy link
Contributor

JonRowe commented Dec 5, 2014

👍

@WattsInABox WattsInABox force-pushed the do_not_truncate_schema_migrations_table_in_postgresql branch from 98b2620 to c47b68f Compare December 5, 2014 23:19
@vrinek
Copy link
Contributor

vrinek commented Dec 11, 2014

Running the specs twice makes the new spec to fail. It begins with PG::DuplicateDatabase: ERROR: database "database_cleaner_test" already exists when trying to active_record_pg_setup and fails on the comparison of tables in the cache:

 Failure/Error: connection.database_cleaner_table_cache.should eq(['public.users'])

   expected: ["public.users"]
        got: ["public.precious_stones", "public.users", "public.worthless_junk", "public.replaceable_trifles"]

   (compared using ==)

I think that the problem does not lie with this PR though, it just got surfaced because of it.

UPDATE: I have prepared a fix for this in a local branch. I will wait until this PR has been merged to push my branch and prepare a new PR.

@WattsInABox
Copy link
Contributor Author

It could be a problem with mine, if I was supposed to trigger some cleanup or yeah, you could be right if the cleanup is supposed to be automagical.

@@ -35,6 +35,14 @@ module ConnectionAdapters
end
end

describe '#database_cleaner_table_cache' do
it 'should default to the list of tables with their schema' do
connection.instance_variable_set(:@database_cleaner_tables, nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't do this... It'd be better to figure out a way to test this without tampering with internals.

- without the schema, the migrations table gets truncated since the default AR method returns ‘public.schema_migrations’
- also a possibility is truncation of tables other than desired once since without the schema, Postgres has no way of knowing which table to truncate if two schemas have the same table
@WattsInABox WattsInABox force-pushed the do_not_truncate_schema_migrations_table_in_postgresql branch from c47b68f to 77bca12 Compare December 11, 2014 22:48
@WattsInABox
Copy link
Contributor Author

Updated the diff by changing the test:

connection.database_cleaner_table_cache.first.should match(/^public\./)

JonRowe added a commit that referenced this pull request Dec 12, 2014
…tions_table_in_postgresql

always return Postgres table names with schema to avoid awfulness
@JonRowe JonRowe merged commit 9e8522c into DatabaseCleaner:master Dec 12, 2014
@JonRowe
Copy link
Contributor

JonRowe commented Dec 12, 2014

LGTM

JonRowe added a commit that referenced this pull request Dec 12, 2014
[skip ci]
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.

3 participants