Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #121 from Shopify/configurable-myshopify-domain
Browse files Browse the repository at this point in the history
Allow override myshopify_domain from shopify_app.yml
  • Loading branch information
kmcphillips committed Feb 20, 2015
2 parents d5b8930 + c3a04f4 commit 48ec263
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/shopify_app/configuration.rb
@@ -1,5 +1,5 @@
class ShopifyApp::Configuration
VALID_KEYS = [:api_key, :secret]
VALID_KEYS = [:api_key, :secret, :myshopify_domain]
attr_writer *VALID_KEYS

def initialize(params={})
Expand Down
2 changes: 1 addition & 1 deletion lib/shopify_app/version.rb
@@ -1,3 +1,3 @@
module ShopifyApp
VERSION = "5.0.1"
VERSION = "5.0.2"
end
1 change: 1 addition & 0 deletions test/config/development_config_file.yml
Expand Up @@ -5,3 +5,4 @@ common:
development:
api_key: development key
secret: development secret
myshopify_domain: myshopify.com
1 change: 1 addition & 0 deletions test/config/other_config_file.yml
@@ -1,3 +1,4 @@
common:
api_key: api key from other file
secret: secret from other file
myshopify_domain: example.com
1 change: 1 addition & 0 deletions test/config/shopify_app.yml
@@ -1,3 +1,4 @@
common:
api_key: api key from default file
secret: secret from default file
myshopify_domain: myshopify.com
13 changes: 13 additions & 0 deletions test/lib/shopify_app/configuration_test.rb
Expand Up @@ -14,65 +14,78 @@ def test_define_method_creates_readers
config = ShopifyApp::Configuration.new
config.respond_to?(:api_key)
config.respond_to?(:secret)
config.respond_to?(:myshopify_domain)
end

def test_defaults_to_empty_string
config = ShopifyApp::Configuration.new(config_file: config_file('empty_config_file.yml'))

assert_equal '', config.api_key
assert_equal '', config.secret
assert_equal '', config.myshopify_domain
end

def test_environment_has_precedence_over_common
config = ShopifyApp::Configuration.new(config_file: config_file('development_config_file.yml'))

assert_equal 'development key', config.api_key
assert_equal 'development secret', config.secret
assert_equal 'myshopify.com', config.myshopify_domain
end

def test_rails_has_precedence_over_environment
config = ShopifyApp::Configuration.new(config_file: config_file('development_config_file.yml'))

assert_equal 'development key', config.api_key
assert_equal 'development secret', config.secret
assert_equal 'myshopify.com', config.myshopify_domain

config.api_key = 'rails key'
config.secret = 'rails secret'
config.myshopify_domain = 'example.com'

assert_equal 'rails key', config.api_key
assert_equal 'rails secret', config.secret
assert_equal 'example.com', config.myshopify_domain
end

def test_env_has_precedence_over_rails
config = ShopifyApp::Configuration.new
config.api_key = 'rails key'
config.secret = 'rails secret'
config.myshopify_domain = 'myshopify.com'

assert_equal 'rails key', config.api_key
assert_equal 'rails secret', config.secret
assert_equal 'myshopify.com', config.myshopify_domain

ENV.expects(:[]).with('SHOPIFY_APP_API_KEY').returns('env key')
ENV.expects(:[]).with('SHOPIFY_APP_SECRET').returns('env secret')
ENV.expects(:[]).with('SHOPIFY_APP_MYSHOPIFY_DOMAIN').returns('example.com')

assert_equal 'env key', config.api_key
assert_equal 'env secret', config.secret
assert_equal 'example.com', config.myshopify_domain
end

def test_reads_config_from_default_config_file
config = ShopifyApp::Configuration.new
assert_equal 'api key from default file', config.api_key
assert_equal 'secret from default file', config.secret
assert_equal 'myshopify.com', config.myshopify_domain
end

def test_reads_config_from_specified_config_file
config = ShopifyApp::Configuration.new(config_file: config_file('other_config_file.yml'))
assert_equal 'api key from other file', config.api_key
assert_equal 'secret from other file', config.secret
assert_equal 'example.com', config.myshopify_domain
end

def test_handles_missing_config_file
config = ShopifyApp::Configuration.new(config_file: config_file('missing_config_file.yml'))
assert_equal '', config.api_key
assert_equal '', config.secret
assert_equal '', config.myshopify_domain
end
end

0 comments on commit 48ec263

Please sign in to comment.