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

Fix mysql and sqlite3 database option bug #925

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/suspenders/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ def use_postgres_config_template
force: true
end

def add_database_to_gemfile(database)
if database == "sqlite3"
@generator.gem "sqlite3", "~> 1.3"
elsif database == "mysql"
@generator.gem "mysql2", "~> 0.5"
else
@generator.gem "pg", "~> 0.18"
end
end

def create_database
bundle_command "exec rails db:create db:migrate"
end
Expand Down
6 changes: 2 additions & 4 deletions lib/suspenders/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@ def customize_gemfile
def setup_database
say 'Setting up database'

if 'postgresql' == options[:database]
build :use_postgres_config_template
end

build :add_database_to_gemfile, options[:database]
build :use_postgres_config_template if options[:database] == "postgresql"
build :create_database
end

Expand Down
34 changes: 34 additions & 0 deletions spec/features/database_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

require "spec_helper"

RSpec.shared_context "Project Setup Hook" do |option|
before :context do
drop_dummy_database
remove_project_directory
run_suspenders option
setup_app_dependencies
end
end

RSpec.describe "Suspend a new project with custom database option" do
context "--database=sqlite3" do
include_context "Project Setup Hook", "--database=sqlite3"

it "adds sqlite3 to Gemfile" do
gemfile = IO.read "#{project_path}/Gemfile"

expect(gemfile).to match(/sqlite3/)
end
end

context "--database=mysql" do
include_context "Project Setup Hook", "--database=mysql"

it "adds mysql2 to Gemfile" do
gemfile = IO.read "#{project_path}/Gemfile"

expect(gemfile).to match(/mysql2/)
end
end
end
1 change: 0 additions & 1 deletion templates/Gemfile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ gem "autoprefixer-rails"
gem "flutie"
gem "honeybadger"
gem "jquery-rails"
gem "pg", "~> 0.18"
gem "puma"
gem "rack-canonical-host"
gem "rails", "<%= Suspenders::RAILS_VERSION %>"
Expand Down