Skip to content

Commit

Permalink
Make the dummy app available to bin/console
Browse files Browse the repository at this point in the history
Usage example:

$ bin/console
USAGE:
  dummy_app             # Load the dummy app and return the Rails.application instance
  dummy_app.initialize! # Initialize the dummy app
  dummy_app.migrate!    # Run all the dummy app migrations
>> dummy_app
Loading the dummy app...done.
=> #<DummyApp::Application root=/Users/elia/Code/Nebulab/solidus>
>> dummy_app.initialize!
=> #<DummyApp::Application root=/Users/elia/Code/Nebulab/solidus>
>> dummy_app.migrate!
== 20100107141738 AddApiKeyToSpreeUsers: migrating ============================
-- add_column(:spree_users, :api_key, :string, {:limit=>40})
   -> 0.0019s
== 20100107141738 AddApiKeyToSpreeUsers: migrated (0.0020s) ===================

...

== 20190220093635 DropSpreeStoreCreditUpdateReasons: migrating ================
-- table_exists?(:spree_store_credit_update_reasons)
   -> 0.0003s
-- drop_table(:spree_store_credit_update_reasons)
   -> 0.0002s
-- column_exists?(:spree_store_credit_events, :update_reason_id)
   -> 0.0004s
-- remove_column(:spree_store_credit_events, :update_reason_id)
   -> 0.0075s
== 20190220093635 DropSpreeStoreCreditUpdateReasons: migrated (0.0084s) =======

=> #<DummyApp::Application root=/Users/elia/Code/Nebulab/solidus>
>>
  • Loading branch information
elia committed Feb 3, 2020
1 parent 3626abb commit 2491bca
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,48 @@
require "bundler/setup"
require "solidus"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
module IRBSolidusHelpers
def dummy_app
@dummy_app ||= begin
print "Loading the dummy app..."
ENV['DATABASE_URL'] ||= 'sqlite3::memory:?pool=1'

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start
require "spree/testing_support/dummy_app"

class << (Rails.application)
# Allow to run migrations from the console
def migrate!
ActiveRecord::Migrator.migrations_paths =
Rails.application.migration_railties.flat_map do |engine|
(engine.paths['db/migrate'] if engine.respond_to?(:paths)).to_a
end
ActiveRecord::Migration.verbose = false
ActiveRecord::Base.connection.migration_context.run(:up, '20160101010000_solidus_one_four'.to_i)
ActiveRecord::Tasks::DatabaseTasks.migrate
self
end

# Avoid flooding the console with the original #inspect
def inspect
"#<#{self.class.name} root=#{root}>"
end
end

puts "done."
Rails.application
end
end

USAGE = <<~TXT
USAGE:
dummy_app # Load the dummy app and return the Rails.application instance
dummy_app.initialize! # Initialize the dummy app
dummy_app.migrate! # Run all the dummy app migrations
TXT
end

puts IRBSolidusHelpers::USAGE

require "irb"
IRB::ExtendCommandBundle.prepend IRBSolidusHelpers
IRB.start(__FILE__)

0 comments on commit 2491bca

Please sign in to comment.