Skip to content

Instantly share code, notes, and snippets.

@xaviershay
Created November 7, 2010 07:34
Show Gist options
  • Save xaviershay/63d1660cb8c706dee4f7 to your computer and use it in GitHub Desktop.
Save xaviershay/63d1660cb8c706dee4f7 to your computer and use it in GitHub Desktop.
From 0f81ee6dc198b0cfe3119b0be4ae4a7aa544c818 Mon Sep 17 00:00:00 2001
From: Xavier Shay <xavier@rhnh.net>
Date: Sun, 7 Nov 2010 17:41:41 +1100
Subject: [PATCH] Allow https URIs to be supplied for rails templates
---
.../rails/generators/rails/app/app_generator.rb | 2 +-
railties/test/generators/app_generator_test.rb | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb
index 44f9fde..4e92610 100644
--- a/railties/lib/rails/generators/rails/app/app_generator.rb
+++ b/railties/lib/rails/generators/rails/app/app_generator.rb
@@ -351,7 +351,7 @@ module Rails
def set_default_accessors!
self.rails_template = case options[:template]
- when /^http:\/\//
+ when /^https?:\/\//
options[:template]
when String
File.expand_path(options[:template], Dir.pwd)
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index c7339cb..980f8f4 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -247,6 +247,15 @@ class AppGeneratorTest < Rails::Generators::TestCase
assert_match /It works!/, silence(:stdout){ generator.invoke_all }
end
+ def test_template_is_executed_when_supplied_from_https
+ path = "https://gist.github.com/103208.txt"
+ template = %{ say "It works!" }
+ template.instance_eval "def read; self; end" # Make the string respond to read
+
+ generator([destination_root], :template => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template)
+ assert_match /It works!/, silence(:stdout){ generator.invoke_all }
+ end
+
def test_usage_read_from_file
File.expects(:read).returns("USAGE FROM FILE")
assert_equal "USAGE FROM FILE", Rails::Generators::AppGenerator.desc
--
1.7.2.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment