Permalink
Browse files

Optionally specify a host for the dummy instance

Host is specified according to `CONTRIBUTING.md`. Port is specified
accordingly.
  • Loading branch information...
1 parent 54fac6d commit 08e54021a7f6add8c6ce1c21ad4686353e4b3435 @aviav aviav committed Mar 4, 2016
View
@@ -1,12 +1,16 @@
# Contributing to Pageflow
-See the [GitHub wiki](https://github.com/codevise/pageflow/wiki) for details on how to contribute to Pageflow.
+See the [GitHub wiki](https://github.com/codevise/pageflow/wiki) for
+details on how to contribute to Pageflow.
## Running the Test Suite
Pageflow expects credentials of a MySQL user in the environment
variables `$PAGEFLOW_DB_USER` AND `PAGEFLOW_DB_PASSWORD`. By default
-`"root"` and the empty password are used.
+`"root"` and the empty password are used. If your MySQL is on a
+different host, you can specify a MySQL host in the environment
+variable `$PAGEFLOW_DB_HOST` and a port in `$PAGEFLOW_DB_PORT`
+(default: 3306).
Use the binstubs to invoke the Ruby test suite
@@ -18,10 +22,10 @@ or the headless browser based Javascript test suite
PhantomJS has to be installed on the system.
-The dummy Rails app used for tests is created automatically through the
+The dummy Rails app used for tests is created automatically through the
install generator during test runs. To have it regenerated,
-simply delete the contents of the `spec/dummy` directory. This is
-required everytime new migrations are added or if tests are failing
+simply delete the contents of the `spec/dummy` directory. This is
+required everytime new migrations are added or if tests are failing
after pulling changes into the local working tree.
Pageflow can run its test suite against Rails 4.0 and 4.1
@@ -8,17 +8,22 @@ def source_paths
# Setup database.yml to use credentials from env variable.
-gsub_file('config/database.yml',
- /^ database: /,
- " database: #{ENV.fetch('PAGEFLOW_PLUGIN_ENGINE', 'pageflow')}-")
+copy_file('database.yml', 'config/database.yml', force: true)
-gsub_file('config/database.yml',
- /^ username:.*\n/,
- " username: \"<%= ENV.fetch('PAGEFLOW_DB_USER', 'root') %>\"\n")
+rails_version_string = Rails::VERSION::STRING.tr!('.', '_')
+
+engine_name = ENV.fetch('PAGEFLOW_PLUGIN_ENGINE', 'pageflow')
+database_prefix = "#{engine_name}-rails-#{rails_version_string}"
gsub_file('config/database.yml',
- /^ password:.*\n/,
- " password: \"<%= ENV.fetch('PAGEFLOW_DB_PASSWORD', '') %>\"\n")
+ /^ database: /,
+ " database: #{database_prefix}-")
+
+append_to_file('config/application.rb', <<-END)
+ if ENV['PAGEFLOW_DB_HOST'].present?
+ ActiveRecord::Tasks::DatabaseTasks::LOCAL_HOSTS << ENV['PAGEFLOW_DB_HOST']
+ end
+END
# Recreate db. Ignore if it does not exist.
@@ -0,0 +1,27 @@
+development:
+ adapter: mysql2
+ encoding: utf8
+ database: development
+ pool: 5
+ username: <%= ENV.fetch('PAGEFLOW_DB_USER', 'root') %>
+ password: <%= ENV.fetch('PAGEFLOW_DB_PASSWORD', '') %>
+<% if ENV['PAGEFLOW_DB_HOST'].present? %>
+ host: <%= ENV['PAGEFLOW_DB_HOST'] %>
+ port: <%= ENV.fetch('PAGEFLOW_DB_PORT', '3306') %>
+<% else %>
+ socket: /var/run/mysqld/mysqld.sock
+<% end %>
+
+test:
+ adapter: mysql2
+ encoding: utf8
+ database: test
+ pool: 5
+ username: <%= ENV.fetch('PAGEFLOW_DB_USER', 'root') %>
+ password: <%= ENV.fetch('PAGEFLOW_DB_PASSWORD', '') %>
+<% if ENV['PAGEFLOW_DB_HOST'].present? %>
+ host: <%= ENV['PAGEFLOW_DB_HOST'] %>
+ port: <%= ENV.fetch('PAGEFLOW_DB_PORT', '3306') %>
+<% else %>
+ socket: /var/run/mysqld/mysqld.sock
+<% end %>

0 comments on commit 08e5402

Please sign in to comment.