Skip to content

Commit 2ce8d43

Browse files
committed
Ensure the dummy app uses the same template as real apps.
1 parent 5fb301b commit 2ce8d43

File tree

11 files changed

+114
-58
lines changed

11 files changed

+114
-58
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,6 @@ Gemfile.lock
9898

9999
# rspec failures
100100
.rspec_failures
101+
102+
db/
103+
config/initializers

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
@@ -186,36 +187,14 @@ def deploy_to_hosting_heroku!(message = nil)
186187
run "heroku restart"
187188
end
188189

189-
# Helper method to quickly convert destination_root to a Pathname for easy file path manipulation
190+
# Helper method to quickly convert destination_root to a Pathname
191+
# for easy file path manipulation
190192
def destination_path
191193
@destination_path ||= Pathname.new(self.destination_root)
192194
end
193195

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

221200
def forced_overwriting?
@@ -310,7 +289,7 @@ def sanity_check_heroku_application_name!
310289
message.join("\n")
311290
end
312291

313-
options[:heroku] = '' if options[:heroku] == 'heroku'
292+
options.delete(:heroku) if options[:heroku] == 'heroku'
314293
end
315294

316295
def start_pretending?

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

+31-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
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, :skip_action_cable, :skip_action_mailer, :database, :javascript, :quiet, :pretend, :force, :skip
17+
:database,
18+
:force,
19+
:javascript,
20+
:pretend,
21+
:quiet,
22+
:skip,
23+
:skip_action_cable,
24+
:skip_action_mailer,
25+
:skip_active_record,
26+
:skip_javascript
1827
]
1928

2029
def generate_test_dummy
@@ -24,8 +33,13 @@ def generate_test_dummy
2433
opts[:skip_bundle] = true
2534
opts[:skip_action_cable] = true
2635
opts[:skip_action_mailer] = true
36+
opts[:skip_keeps] = true
37+
opts[:skip_migrate] = true
38+
opts[:template] = refinery_path.join("templates", "refinery", "edge.rb").to_s
2739

28-
invoke Rails::Generators::AppGenerator, [ File.expand_path(dummy_path, destination_root) ], opts
40+
invoke Rails::Generators::AppGenerator,
41+
[ File.expand_path(dummy_path, destination_root) ],
42+
opts
2943
end
3044

3145
def test_dummy_config
@@ -67,19 +81,22 @@ def test_dummy_inherited_templates
6781

6882
attr :database
6983

70-
protected
84+
protected
7185

7286
def dummy_path
7387
'spec/dummy'
7488
end
7589

90+
def dummy_application_path
91+
File.expand_path("#{dummy_path}/config/application.rb", destination_root)
92+
end
93+
7694
def module_name
7795
'Dummy'
7896
end
7997

8098
def application_definition
8199
@application_definition ||= begin
82-
dummy_application_path = File.expand_path("#{dummy_path}/config/application.rb", destination_root)
83100
unless options[:pretend] || !File.exists?(dummy_application_path)
84101
contents = File.read(dummy_application_path)
85102
contents[(contents.index("module #{module_name}"))..-1]
@@ -93,7 +110,11 @@ def camelized
93110
end
94111

95112
def gemfile_path
96-
'../../../../Gemfile'
113+
"../../../../Gemfile"
114+
end
115+
116+
def refinery_path
117+
Pathname.new File.expand_path("../../../../../../", __FILE__)
97118
end
98119
end
99120
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

+8-12
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,16 @@
1616
gem "coffee-rails", :group => :assets
1717
end
1818

19-
if ENV['REFINERY_PATH']
20-
append_file 'Gemfile' do
21-
"
22-
gem 'refinerycms', path: '#{ENV['REFINERY_PATH']}'
23-
"
24-
end
19+
refinerycms_source = if ENV['REFINERY_PATH']
20+
"path: '#{ENV['REFINERY_PATH']}'"
2521
else
26-
append_file 'Gemfile' do
27-
"
28-
gem 'refinerycms', git: 'https://github.com/refinery/refinerycms', branch: 'master'
29-
"
30-
end
22+
"git: 'https://github.com/refinery/refinerycms', branch: 'master'"
3123
end
3224

3325
append_file 'Gemfile' do
3426
"
27+
gem 'refinerycms', #{refinerycms_source}
28+
3529
# Add support for searching inside Refinery's admin interface.
3630
gem 'refinerycms-acts-as-indexed', ['~> 3.0', '>= 3.0.0']
3731
@@ -46,10 +40,12 @@
4640
run 'bundle install'
4741

4842
rake 'db:create'
43+
require 'refinery/core/environment_checker'
44+
Refinery::Core::EnvironmentChecker.new(destination_root).call
4945
generate "refinery:cms --fresh-installation #{ARGV.join(' ')}"
5046

5147
say <<-SAY
5248
============================================================================
53-
Your new Refinery CMS application is now running on edge and mounted to /.
49+
Your new Refinery CMS application is now running on edge and mounted at '/'
5450
============================================================================
5551
SAY

0 commit comments

Comments
 (0)