Skip to content

Commit 5a6d709

Browse files
committed
Ensure the dummy app uses the same template as real apps.
1 parent 29ab036 commit 5a6d709

File tree

12 files changed

+113
-50
lines changed

12 files changed

+113
-50
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,5 @@ Gemfile.lock
9292
*.txt
9393

9494
*.orig
95+
db/
96+
config/initializers

authentication/lib/generators/refinery/authentication/authentication_generator.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
module Refinery
22
class AuthenticationGenerator < Rails::Generators::Base
3+
class_option :skip_migrations, :type => :boolean, :default => false,
4+
:aliases => nil, :group => :runtime,
5+
:desc => "Skip over installing or running migrations."
6+
37
source_root File.expand_path("../templates", __FILE__)
48

59
def rake_db
6-
rake "refinery_authentication:install:migrations"
10+
rake "refinery_authentication:install:migrations" unless self.options[:skip_migrations]
711
end
812

913
def generate_authentication_initializer

core/lib/generators/refinery/cms/cms_generator.rb

+5-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'pathname'
2+
require 'refinery/core/environment_checker'
23

34
module Refinery
45
class CmsGenerator < Rails::Generators::Base
@@ -191,36 +192,14 @@ def deploy_to_hosting_heroku!(message = nil)
191192
run "heroku restart"
192193
end
193194

194-
# Helper method to quickly convert destination_root to a Pathname for easy file path manipulation
195+
# Helper method to quickly convert destination_root to a Pathname
196+
# for easy file path manipulation
195197
def destination_path
196198
@destination_path ||= Pathname.new(self.destination_root)
197199
end
198200

199201
def ensure_environments_are_sane!
200-
# Massage environment files
201-
%w(development test production).map{ |e| "config/environments/#{e}.rb"}.each do |env|
202-
next unless destination_path.join(env).file?
203-
204-
# Refinery does not necessarily expect action_mailer to be available as
205-
# we may not always require it (currently only the authentication extension).
206-
# Rails, however, will optimistically place config entries for action_mailer.
207-
current_mailer_config = File.read(destination_path.join(env)).to_s.
208-
match(%r{^\s.+?config\.action_mailer\..+([\w\W]*\})?}).
209-
to_a.flatten.first
210-
211-
if current_mailer_config.present?
212-
new_mailer_config = [
213-
" if config.respond_to?(:action_mailer)",
214-
current_mailer_config.gsub(%r{\A\n+?}, ''). # remove extraneous newlines at the start
215-
gsub(%r{^\ \ }) { |line| " #{line}" }, # add indentation on each line
216-
" end"
217-
].join("\n")
218-
219-
gsub_file env, current_mailer_config, new_mailer_config, :verbose => false
220-
end
221-
222-
gsub_file env, "config.assets.compile = false", "config.assets.compile = true", :verbose => false
223-
end
202+
Refinery::Core::EnvironmentChecker.new(destination_path).call
224203
end
225204

226205
def forced_overwriting?
@@ -305,7 +284,7 @@ def sanity_check_heroku_application_name!
305284
message.join("\n")
306285
end
307286

308-
options[:heroku] = '' if options[:heroku] == 'heroku'
287+
options.delete(:heroku) if options[:heroku] == 'heroku'
309288
end
310289

311290
def start_pretending?

core/lib/generators/refinery/dummy/dummy_generator.rb

+23-10
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
1-
require 'rails/generators'
21
require 'rails/generators/rails/app/app_generator'
32

43
module Refinery
54
class DummyGenerator < Rails::Generators::Base
6-
desc "Creates blank Rails application, installs Refinery CMS, and all sample data"
5+
desc "Creates a blank Rails application with Refinery CMS installed."
76

87
class_option :database, :default => ''
98

109
def self.source_paths
11-
paths = self.superclass.source_paths
12-
paths << File.expand_path('../templates', __FILE__)
13-
paths.flatten
10+
[
11+
self.superclass.source_paths,
12+
File.expand_path('../templates', __FILE__)
13+
].flatten.compact
1414
end
1515

1616
PASSTHROUGH_OPTIONS = [
17-
:skip_active_record, :skip_javascript, :database, :javascript, :quiet, :pretend, :force, :skip
17+
:skip_active_record, :skip_javascript, :database, :javascript, :quiet,
18+
:pretend, :force, :skip
1819
]
1920

2021
def generate_test_dummy
2122
opts = (options || {}).slice(*PASSTHROUGH_OPTIONS)
2223
opts[:database] = 'sqlite3' if opts[:database].blank?
2324
opts[:force] = true
2425
opts[:skip_bundle] = true
26+
opts[:skip_keeps] = true
27+
opts[:skip_migrate] = true
28+
opts[:template] = refinery_path.join("templates", "refinery", "edge.rb").to_s
2529

26-
invoke Rails::Generators::AppGenerator, [ File.expand_path(dummy_path, destination_root) ], opts
30+
invoke Rails::Generators::AppGenerator,
31+
[ File.expand_path(dummy_path, destination_root) ],
32+
opts
2733
end
2834

2935
def test_dummy_config
@@ -65,19 +71,22 @@ def test_dummy_inherited_templates
6571

6672
attr :database
6773

68-
protected
74+
protected
6975

7076
def dummy_path
7177
'spec/dummy'
7278
end
7379

80+
def dummy_application_path
81+
File.expand_path("#{dummy_path}/config/application.rb", destination_root)
82+
end
83+
7484
def module_name
7585
'Dummy'
7686
end
7787

7888
def application_definition
7989
@application_definition ||= begin
80-
dummy_application_path = File.expand_path("#{dummy_path}/config/application.rb", destination_root)
8190
unless options[:pretend] || !File.exists?(dummy_application_path)
8291
contents = File.read(dummy_application_path)
8392
contents[(contents.index("module #{module_name}"))..-1]
@@ -91,7 +100,11 @@ def camelized
91100
end
92101

93102
def gemfile_path
94-
'../../../../Gemfile'
103+
"../../../../Gemfile"
104+
end
105+
106+
def refinery_path
107+
Pathname.new File.expand_path("../../../../../../", __FILE__)
95108
end
96109
end
97110
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Check that Rails application configuration is consistent with what we expect.
2+
require 'pathname'
3+
4+
module Refinery
5+
module Core
6+
class EnvironmentChecker
7+
8+
def initialize(root_path, environments: %w(development test production))
9+
@root_path = Pathname.new(root_path)
10+
@environments = environments
11+
end
12+
13+
def call
14+
environment_files.each do |env_file|
15+
# Refinery does not necessarily expect action_mailer to be available as
16+
# we may not always require it (currently only the authentication extension).
17+
# Rails, however, will optimistically place config entries for action_mailer.
18+
current_mailer_config = mailer_config(env_file)
19+
20+
if current_mailer_config.present?
21+
new_mailer_config = [
22+
" if config.respond_to?(:action_mailer)",
23+
current_mailer_config.gsub(%r{\A\n+?}, ''). # remove extraneous newlines at the start
24+
gsub(%r{^\ \ }) { |line| " #{line}" }, # add indentation on each line
25+
" end"
26+
].join("\n")
27+
28+
env_file.write(
29+
env_file.read.gsub(current_mailer_config, new_mailer_config)
30+
)
31+
end
32+
33+
env_file.write(
34+
env_file.read.gsub("assets.compile = false", "assets.compile = true")
35+
)
36+
end
37+
end
38+
39+
private
40+
attr_reader :environments, :root_path
41+
42+
def environment_files
43+
environments.map { |env| root_path.join("config", "environments", "#{env}.rb") }
44+
.select(&:file?)
45+
end
46+
47+
def mailer_config(environment_file)
48+
root_path.join(environment_file).read.match(
49+
%r{^\s.+?config\.action_mailer\..+([\w\W]*\})?}
50+
).to_a.flatten.first
51+
end
52+
end
53+
end
54+
end

images/db/migrate/20100913234707_create_refinerycms_images_schema.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def change
99
t.string :image_uid
1010
t.string :image_ext
1111

12-
t.timestamps
12+
t.timestamps null: false
1313
end
1414
end
1515
end

images/lib/generators/refinery/images/images_generator.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module Refinery
22
class ImagesGenerator < Rails::Generators::Base
3-
class_option :skip_migrations, :type => :boolean, :default => false, :aliases => nil, :group => :runtime,
4-
:desc => "Skip over installing or running migrations."
3+
class_option :skip_migrations, :type => :boolean, :default => false,
4+
:aliases => nil, :group => :runtime,
5+
:desc => "Skip over installing or running migrations."
56

67
source_root File.expand_path('../templates', __FILE__)
78

pages/db/migrate/20100913234708_create_refinerycms_pages_schema.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def up
66
t.text :body
77
t.integer :position
88

9-
t.timestamps
9+
t.timestamps null: false
1010
end
1111

1212
add_index :refinery_page_parts, :id
@@ -29,7 +29,7 @@ def up
2929
t.string :view_template
3030
t.string :layout_template
3131

32-
t.timestamps
32+
t.timestamps null: false
3333
end
3434

3535
add_index :refinery_pages, :depth

pages/lib/generators/refinery/pages/pages_generator.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module Refinery
22
class PagesGenerator < Rails::Generators::Base
3-
class_option :skip_migrations, :type => :boolean, :default => false, :aliases => nil, :group => :runtime,
4-
:desc => "Skip over installing or running migrations."
3+
class_option :skip_migrations, :type => :boolean, :default => false,
4+
:aliases => nil, :group => :runtime,
5+
:desc => "Skip over installing or running migrations."
56

67
source_root File.expand_path('../templates', __FILE__)
78

resources/db/migrate/20100913234709_create_refinerycms_resources_schema.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def change
77
t.string :file_uid
88
t.string :file_ext
99

10-
t.timestamps
10+
t.timestamps null: false
1111
end
1212
end
1313
end

resources/lib/generators/refinery/resources/resources_generator.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module Refinery
22
class ResourcesGenerator < Rails::Generators::Base
3-
class_option :skip_migrations, :type => :boolean, :default => false, :aliases => nil, :group => :runtime,
4-
:desc => "Skip over installing or running migrations."
3+
class_option :skip_migrations, :type => :boolean, :default => false,
4+
:aliases => nil, :group => :runtime,
5+
:desc => "Skip over installing or running migrations."
56

67
source_root File.expand_path('../templates', __FILE__)
78

templates/refinery/edge.rb

+11-3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@
1414
gem "coffee-rails", :group => :assets
1515
end
1616

17+
refinerycms_source = if ENV['REFINERY_PATH']
18+
"path: '#{ENV['REFINERY_PATH']}'"
19+
else
20+
"git: 'https://github.com/refinery/refinerycms', branch: 'master'"
21+
end
22+
1723
append_file 'Gemfile' do
1824
"
19-
gem 'refinerycms', git: 'https://github.com/refinery/refinerycms', branch: 'master'
25+
gem 'refinerycms', #{refinerycms_source}
2026
21-
gem 'quiet_assets', :group => :development
27+
gem 'quiet_assets', group: :development
2228
2329
# Add support for searching inside Refinery's admin interface.
2430
gem 'refinerycms-acts-as-indexed', ['~> 2.0', '>= 2.0.0']
@@ -31,10 +37,12 @@
3137
run 'bundle install'
3238

3339
rake 'db:create'
40+
require 'refinery/core/environment_checker'
41+
Refinery::Core::EnvironmentChecker.new(destination_root).call
3442
generate "refinery:cms --fresh-installation #{ARGV.join(' ')}"
3543

3644
say <<-SAY
3745
============================================================================
38-
Your new Refinery CMS application is now running on edge and mounted to /.
46+
Your new Refinery CMS application is now running on edge and mounted at '/'
3947
============================================================================
4048
SAY

0 commit comments

Comments
 (0)