Skip to content

Commit

Permalink
patch install_generator to allow whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmaroli committed Nov 27, 2016
1 parent 27ec39a commit e1f2729
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
11 changes: 7 additions & 4 deletions lib/generators/shopify_app/install/install_generator.rb
Expand Up @@ -7,17 +7,20 @@ class InstallGenerator < Rails::Generators::Base
include Rails::Generators::Migration
source_root File.expand_path('../templates', __FILE__)

class_option :application_name, type: :string
class_option :application_name, type: :array
class_option :api_key, type: :string, default: '<api_key>'
class_option :secret, type: :string, default: '<secret>'
class_option :scope, type: :string, default: 'read_orders, read_products'
class_option :scope, type: :array, default: ['read_orders,', 'read_products']
class_option :embedded, type: :string, default: 'true'

def create_shopify_app_initializer
@application_name = options['application_name']
#
# enable users to provide options containing whitespace and strip them off 'double-quotes', if present.
#
@application_name = options['application_name'].join(' ').tr('"', '') if options['application_name']
@api_key = options['api_key']
@secret = options['secret']
@scope = options['scope']
@scope = options['scope'].join(' ').tr('"', '')

template 'shopify_app.rb', 'config/initializers/shopify_app.rb'
end
Expand Down
17 changes: 14 additions & 3 deletions test/generators/install_generator_test.rb
Expand Up @@ -23,12 +23,23 @@ class InstallGeneratorTest < Rails::Generators::TestCase
end

test "creates the ShopifyApp initializer with args" do
run_generator %w(--application_name name --api_key key --secret shhhhh --scope read_orders,write_products)
run_generator %w(--application_name Test Name --api_key key --secret shhhhh --scope read_orders, write_products)
assert_file "config/initializers/shopify_app.rb" do |shopify_app|
assert_match 'config.application_name = "name"', shopify_app
assert_match 'config.application_name = "Test Name"', shopify_app
assert_match 'config.api_key = "key"', shopify_app
assert_match 'config.secret = "shhhhh"', shopify_app
assert_match 'config.scope = "read_orders,write_products"', shopify_app
assert_match 'config.scope = "read_orders, write_products"', shopify_app
assert_match "config.embedded_app = true", shopify_app
end
end

test "creates the ShopifyApp initializer with double-quoted args" do
run_generator %w(--application_name "Test Name" --api_key key --secret shhhhh --scope "read_orders, write_products")
assert_file "config/initializers/shopify_app.rb" do |shopify_app|
assert_match 'config.application_name = "Test Name"', shopify_app
assert_match 'config.api_key = "key"', shopify_app
assert_match 'config.secret = "shhhhh"', shopify_app
assert_match 'config.scope = "read_orders, write_products"', shopify_app
assert_match "config.embedded_app = true", shopify_app
end
end
Expand Down

0 comments on commit e1f2729

Please sign in to comment.