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

Added notice when a database is successfully created or dropped. #24551

Merged
merged 1 commit into from Apr 17, 2016

Conversation

bogdanvlviv
Copy link
Contributor

@bogdanvlviv bogdanvlviv commented Apr 14, 2016

Added notice when a database is successfully created or dropped.

Example:

  $ bin/rails db:create
  Created database 'blog_development'
  Created database 'blog_test'
  $ bin/rails db:drop
  Dropped database 'blog_development'
  Dropped database 'blog_test'

Changed older notices
blog_development already exists to Database 'blog_development' already exists and
Couldn't drop blog_development to Couldn't drop database 'blog_development'.

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @pixeltrix (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@@ -107,8 +107,9 @@ def current_config(options = {})
def create(*arguments)
configuration = arguments.first
class_for_adapter(configuration['adapter']).new(*arguments).create
$stdout.puts "Create database '#{configuration['database']}'"
Copy link
Contributor

Choose a reason for hiding this comment

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

Create --> Created

@bogdanvlviv
Copy link
Contributor Author

bogdanvlviv commented Apr 14, 2016

I am trying fix tests. I don't know how i can delete from test's logs this. Could you help me?

......S............................................................................
...........................................................................
..............................................................................
...................................................................................
.................................................................................
............................................
.Created database 'my-app-db'
.Created database 'my-app-db'
.Created database 'my-app-db'
.Created database 'my-app-db'
.Created database 'my-app-db'
.Created database 'my-app-db'
.Created database 'my-app-db'
.Dropped database 'my-app-db'
.Dropped database 'my-app-db'
.........................................
........................................
...........................................................

@maclover7
Copy link
Contributor

Can you push up your changes -- I'm not sure which tests you are trying to run above ^^

@bogdanvlviv bogdanvlviv changed the title add notice for tasks db:create, db:drop Added notice when database successfully created or dropped. Apr 14, 2016
@bogdanvlviv
Copy link
Contributor Author

bogdanvlviv commented Apr 14, 2016

@vipulnsward, i think PR should have label 'activerecord'.

$stdout.expects(:puts).with("Dropped database 'my-app-db'").once

ActiveRecord::Tasks::DatabaseTasks.drop @configuration
end
end

class MySQLPurgeTest < ActiveRecord::TestCase
Copy link
Member

Choose a reason for hiding this comment

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

succsessfylly → successfully

@jeremy
Copy link
Member

jeremy commented Apr 15, 2016

I don't know how i can delete from test's logs this

To suppress that output from the test logs, you could introduce an ouput @logger = Logger.new($stdout) and use @logger.info instead of $stdout.puts.

Then, in tests, set logger to @test_output = StringIO.new; @logger = Logger.new(@test_output) instead.

That'll capture all output without needing to $stdout.expect(:puts), too: you can assert against @test_output.string contents.

@bogdanvlviv
Copy link
Contributor Author

bogdanvlviv commented Apr 15, 2016

@jeremy, i have got log output:

#` Running:

...I, [2016-04-15T08:31:36.130198 #7403]  INFO -- : Created database 'db_create.sqlite3'
.I, [2016-04-15T08:31:36.133723 #7403]  INFO -- : Created database 'db_create.sqlite3'
..I, [2016-04-15T08:31:36.143367 #7403]  INFO -- : Created database 'db_create.sqlite3'`
.........

@bogdanvlviv
Copy link
Contributor Author

bogdanvlviv commented Apr 15, 2016

@jeremy, will be correctly if i set in tests?

@original_stdout = $stdout
$stdout = StringIO.new

@jeremy
Copy link
Member

jeremy commented Apr 15, 2016

Give it a shot, @bogdanvlviv! How'd it work out for you?

@bogdanvlviv
Copy link
Contributor Author

bogdanvlviv commented Apr 15, 2016

@jeremy, i am trying make better.

@bogdanvlviv bogdanvlviv force-pushed the notice_for_tasks branch 3 times, most recently from 7a7907b to ddf5198 Compare April 15, 2016 20:17
@bogdanvlviv
Copy link
Contributor Author

I have done suppress the output from the test logs. Could this PR be revised?

@@ -4,6 +4,28 @@

*Sean Griffin*

* Added notice when database successfully created or dropped.
Copy link
Contributor

Choose a reason for hiding this comment

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

when a database is

@bogdanvlviv bogdanvlviv changed the title Added notice when database successfully created or dropped. Added notice when a database is successfully created or dropped. Apr 15, 2016
@@ -15,6 +15,9 @@ def setup
File.stubs(:exist?).returns(false)
ActiveRecord::Base.stubs(:connection).returns(@connection)
ActiveRecord::Base.stubs(:establish_connection).returns(true)

@original_stdout = $stdout
Copy link
Member

Choose a reason for hiding this comment

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

I can't see any use of the @original_stdout instance variable.
Should we assert on the content of this variable instead of $stdout.expects(:puts) as @jeremy mentioned?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Edouard-chin, yes, i dont use @original_stdout. i defined this variable because of i think it is correctly save link to original $stdout, as you can see i override $stdout for tests in next line after defining @original_stdout.

Copy link
Member

Choose a reason for hiding this comment

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

Set $stdout = @original_stdout in teardown to ensure we don't hijack stdout for other tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jeremy, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@bogdanvlviv bogdanvlviv force-pushed the notice_for_tasks branch 2 times, most recently from 71ccd78 to 1b2d9c7 Compare April 15, 2016 22:26
@jeremy
Copy link
Member

jeremy commented Apr 15, 2016

I have done suppress the output from the test logs. Could this PR be revised?

@bogdanvlviv To revise the PR, you can rebase your branch against master (git rebase -i master) then force-push your branch back to GitHub (git push -f)

@bogdanvlviv
Copy link
Contributor Author

Could this PR be merged?

@@ -8,6 +8,9 @@ def setup
ActiveRecord::Tasks::MySQLDatabaseTasks.stubs(:new).returns @mysql_tasks
ActiveRecord::Tasks::PostgreSQLDatabaseTasks.stubs(:new).returns @postgresql_tasks
ActiveRecord::Tasks::SQLiteDatabaseTasks.stubs(:new).returns @sqlite_tasks

@original_stdout = $stdout
$stdout = StringIO.new
Copy link
Member

Choose a reason for hiding this comment

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

Are you setting $stdout back to @original_stdout somewhere (def teardown …)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I am not but it is good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Set $stdout = @original_stdout in teardown to ensure we don't hijack stdout for other tests.

Done!

Copy link
Member

Choose a reason for hiding this comment

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

You can do a one-line multiple assignment to make this a little more concise:

$stdout, @original_stdout = StringIO.new, $stdout

@bogdanvlviv
Copy link
Contributor Author

@jeremy, could we finish this PR?


def teardown
$stdout = @original_stdout
@original_stdout = nil
Copy link
Member

Choose a reason for hiding this comment

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

No need to set this to nil. Just set stdout back to its original value.

@bogdanvlviv
Copy link
Contributor Author

@jeremy, thanks for review! I made changes.

@jeremy jeremy merged commit 5154701 into rails:master Apr 17, 2016
@jeremy
Copy link
Member

jeremy commented Apr 17, 2016

Great work @bogdanvlviv. Thank you for improving this!

@bogdanvlviv
Copy link
Contributor Author

Thanks @jeremy!

@arthurnn
Copy link
Member

arthurnn commented May 5, 2016

👍

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

Successfully merging this pull request may close these issues.

None yet

8 participants