diff --git a/.gitignore b/.gitignore index 6b90aed9bf..342abbdfbf 100644 --- a/.gitignore +++ b/.gitignore @@ -98,3 +98,6 @@ Gemfile.lock # rspec failures .rspec_failures + +db/ +config/initializers diff --git a/.travis.yml b/.travis.yml index 31b9c971e7..e35bc3eea8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ before_install: gem install bundler bundler_args: --without development before_script: - export RETRY_COUNT=3 - - bin/rake refinery:testing:dummy_app + - yes | bin/rake refinery:testing:dummy_app script: - bin/rspec $EXTENSION/spec env: diff --git a/Gemfile b/Gemfile index 74ad22d06c..05302e6241 100644 --- a/Gemfile +++ b/Gemfile @@ -51,6 +51,10 @@ group :test do gem 'rspec-retry' end +group :development, :test do + gem 'activejob' +end + # Load local gems according to Refinery developer preference. if File.exist? local_gemfile = File.expand_path('../.gemfile', __FILE__) eval File.read(local_gemfile) diff --git a/bin/rails b/bin/rails index 7fcd79c93b..8abbcc94d9 100755 --- a/bin/rails +++ b/bin/rails @@ -4,7 +4,7 @@ begin load File.join(File.expand_path('../../', __FILE__), 'spec/dummy/bin/rails') -rescue LoadError => load_error +rescue LoadError => _load_error warn "No dummy Rails application found! \n" \ "To create one in spec/dummy, please run: \n\n" \ " rake refinery:testing:dummy_app" diff --git a/core/lib/generators/refinery/cms/cms_generator.rb b/core/lib/generators/refinery/cms/cms_generator.rb index db1dcc11eb..adfb4ffcad 100644 --- a/core/lib/generators/refinery/cms/cms_generator.rb +++ b/core/lib/generators/refinery/cms/cms_generator.rb @@ -1,5 +1,6 @@ require 'pathname' require 'mkmf' +require 'refinery/core/environment_checker' module Refinery class CmsGenerator < Rails::Generators::Base @@ -17,6 +18,8 @@ class CmsGenerator < Rails::Generators::Base :desc => "Skip over any database creation, migration or seeding." class_option :skip_migrations, :type => :boolean, :default => false, :aliases => nil, :group => :runtime, :desc => "Skip over installing or running migrations." + class_option :skip_seeds, :type => :boolean, :default => false, :aliases => nil, :group => :runtime, + :desc => "Skip over seeding." def generate start_pretending? @@ -190,36 +193,14 @@ def deploy_to_hosting_heroku!(message = nil) run "heroku restart" end - # Helper method to quickly convert destination_root to a Pathname for easy file path manipulation + # Helper method to quickly convert destination_root to a Pathname + # for easy file path manipulation def destination_path @destination_path ||= Pathname.new(self.destination_root) end def ensure_environments_are_sane! - # Massage environment files - %w(development test production).map{ |e| "config/environments/#{e}.rb"}.each do |env| - next unless destination_path.join(env).file? - - # Refinery does not necessarily expect action_mailer to be available as - # we may not always require it (currently only the authentication extension). - # Rails, however, will optimistically place config entries for action_mailer. - current_mailer_config = File.read(destination_path.join(env)).to_s. - match(%r{^\s.+?config\.action_mailer\..+([\w\W]*\})?}). - to_a.flatten.first - - if current_mailer_config.present? - new_mailer_config = [ - " if config.respond_to?(:action_mailer)", - current_mailer_config.gsub(%r{\A\n+?}, ''). # remove extraneous newlines at the start - gsub(%r{^\ \ }) { |line| " #{line}" }, # add indentation on each line - " end" - ].join("\n") - - gsub_file env, current_mailer_config, new_mailer_config, :verbose => false - end - - gsub_file env, "config.assets.compile = false", "config.assets.compile = true", :verbose => false - end + Refinery::Core::EnvironmentChecker.new(destination_path).call end def forced_overwriting? @@ -266,7 +247,7 @@ def prepare_database! command = %w[railties:install:migrations] unless self.options[:skip_db] command |= %w[db:create db:migrate] - command |= %w[db:seed] unless self.options[:skip_migrations] + command |= %w[db:seed] unless self.options[:skip_seeds] end rake command.join(' ') end @@ -294,6 +275,7 @@ def run_additional_generators! generator_args = [] generator_args << '--quiet' if self.options[:quiet] generator_args << '--skip-migrations' if self.options[:skip_migrations] + generator_args << '--skip-seeds' if self.options[:skip_seeds] && !self.options[:skip_migrations] Refinery::CoreGenerator.start generator_args Refinery::Authentication::DeviseGenerator.start generator_args if defined?(Refinery::Authentication::DeviseGenerator) Refinery::Dragonfly::DragonflyGenerator.start generator_args if defined?(Refinery::Dragonfly::DragonflyGenerator) @@ -322,7 +304,7 @@ def sanity_check_heroku_application_name! message.join("\n") end - options[:heroku] = '' if options[:heroku] == 'heroku' + options.delete(:heroku) if options[:heroku] == 'heroku' end def start_pretending? diff --git a/core/lib/generators/refinery/dummy/dummy_generator.rb b/core/lib/generators/refinery/dummy/dummy_generator.rb index 4b7eec964b..7f80ea165b 100644 --- a/core/lib/generators/refinery/dummy/dummy_generator.rb +++ b/core/lib/generators/refinery/dummy/dummy_generator.rb @@ -1,20 +1,29 @@ -require 'rails/generators' require 'rails/generators/rails/app/app_generator' module Refinery class DummyGenerator < Rails::Generators::Base - desc "Creates blank Rails application, installs Refinery CMS, and all sample data" + desc "Creates a blank Rails application with Refinery CMS installed." class_option :database, :default => '' def self.source_paths - paths = self.superclass.source_paths - paths << File.expand_path('../templates', __FILE__) - paths.flatten + [ + self.superclass.source_paths, + File.expand_path('../templates', __FILE__) + ].flatten.compact end PASSTHROUGH_OPTIONS = [ - :skip_active_record, :skip_javascript, :skip_action_cable, :skip_action_mailer, :database, :javascript, :quiet, :pretend, :force, :skip + :database, + :force, + :javascript, + :pretend, + :quiet, + :skip, + :skip_action_cable, + :skip_action_mailer, + :skip_active_record, + :skip_javascript ] def generate_test_dummy @@ -24,8 +33,13 @@ def generate_test_dummy opts[:skip_bundle] = true opts[:skip_action_cable] = true opts[:skip_action_mailer] = true + opts[:skip_keeps] = true + opts[:skip_seeds] = true + opts[:template] = refinery_path.join("templates", "refinery", "edge.rb").to_s - invoke Rails::Generators::AppGenerator, [ File.expand_path(dummy_path, destination_root) ], opts + invoke Rails::Generators::AppGenerator, + [ File.expand_path(dummy_path, destination_root) ], + opts end def test_dummy_config @@ -67,19 +81,22 @@ def test_dummy_inherited_templates attr :database - protected + protected def dummy_path 'spec/dummy' end + def dummy_application_path + File.expand_path("#{dummy_path}/config/application.rb", destination_root) + end + def module_name 'Dummy' end def application_definition @application_definition ||= begin - dummy_application_path = File.expand_path("#{dummy_path}/config/application.rb", destination_root) unless options[:pretend] || !File.exists?(dummy_application_path) contents = File.read(dummy_application_path) contents[(contents.index("module #{module_name}"))..-1] @@ -93,7 +110,11 @@ def camelized end def gemfile_path - '../../../../Gemfile' + "../../../../Gemfile" + end + + def refinery_path + Pathname.new File.expand_path("../../../../../../", __FILE__) end end end diff --git a/core/lib/generators/refinery/dummy/templates/rails/application.rb.erb b/core/lib/generators/refinery/dummy/templates/rails/application.rb.erb index ac2be7c7fe..b6e1bc85cf 100644 --- a/core/lib/generators/refinery/dummy/templates/rails/application.rb.erb +++ b/core/lib/generators/refinery/dummy/templates/rails/application.rb.erb @@ -1,6 +1,9 @@ require File.expand_path('../boot', __FILE__) -require 'rails/all' +# Pick the frameworks you want: +require 'active_record/railtie' +require 'action_controller/railtie' +require 'sprockets/railtie' require 'bundler/setup' diff --git a/core/lib/refinery/core/environment_checker.rb b/core/lib/refinery/core/environment_checker.rb new file mode 100644 index 0000000000..59343b5958 --- /dev/null +++ b/core/lib/refinery/core/environment_checker.rb @@ -0,0 +1,50 @@ +# Check that Rails application configuration is consistent with what we expect. +require 'pathname' + +module Refinery + module Core + class EnvironmentChecker + + def initialize(root_path, environments: %w(development test production)) + @root_path = Pathname.new(root_path) + @environments = environments + end + + def call + environment_files.each do |env_file| + # Refinery does not necessarily expect action_mailer to be available as + # we may not always require it (currently only the authentication extension). + # Rails, however, will optimistically place config entries for action_mailer. + current_mailer_config = mailer_config(env_file) + + if current_mailer_config.present? + new_mailer_config = [ + " if config.respond_to?(:action_mailer)", + current_mailer_config.gsub(%r{\A\n+?}, ''). # remove extraneous newlines at the start + gsub(%r{^\ \ }) { |line| " #{line}" }, # add indentation on each line + " end" + ].join("\n") + + env_file.write( + env_file.read.gsub(current_mailer_config, new_mailer_config) + ) + end + end + end + + private + attr_reader :environments, :root_path + + def environment_files + environments.map { |env| root_path.join("config", "environments", "#{env}.rb") } + .select(&:file?) + end + + def mailer_config(environment_file) + root_path.join(environment_file).read.match( + %r{^\s.+?config\.action_mailer\..+([\w\W]*\})?} + ).to_a.flatten.first + end + end + end +end diff --git a/images/db/migrate/20100913234707_create_refinerycms_images_schema.rb b/images/db/migrate/20100913234707_create_refinerycms_images_schema.rb index 0ce4abb1d7..a48678061a 100644 --- a/images/db/migrate/20100913234707_create_refinerycms_images_schema.rb +++ b/images/db/migrate/20100913234707_create_refinerycms_images_schema.rb @@ -9,7 +9,7 @@ def change t.string :image_uid t.string :image_ext - t.timestamps + t.timestamps null: false end end end diff --git a/images/lib/generators/refinery/images/images_generator.rb b/images/lib/generators/refinery/images/images_generator.rb index c3b892f1bf..45acf2442f 100644 --- a/images/lib/generators/refinery/images/images_generator.rb +++ b/images/lib/generators/refinery/images/images_generator.rb @@ -1,7 +1,8 @@ module Refinery class ImagesGenerator < Rails::Generators::Base - class_option :skip_migrations, :type => :boolean, :default => false, :aliases => nil, :group => :runtime, - :desc => "Skip over installing or running migrations." + class_option :skip_migrations, :type => :boolean, :default => false, + :aliases => nil, :group => :runtime, + :desc => "Skip over installing or running migrations." source_root File.expand_path('../templates', __FILE__) diff --git a/pages/db/migrate/20100913234708_create_refinerycms_pages_schema.rb b/pages/db/migrate/20100913234708_create_refinerycms_pages_schema.rb index 0bdd262a0b..c8c51a756e 100644 --- a/pages/db/migrate/20100913234708_create_refinerycms_pages_schema.rb +++ b/pages/db/migrate/20100913234708_create_refinerycms_pages_schema.rb @@ -6,7 +6,7 @@ def up t.text :body t.integer :position - t.timestamps + t.timestamps null: false end add_index :refinery_page_parts, :id @@ -29,7 +29,7 @@ def up t.string :view_template t.string :layout_template - t.timestamps + t.timestamps null: false end add_index :refinery_pages, :depth diff --git a/pages/lib/generators/refinery/pages/pages_generator.rb b/pages/lib/generators/refinery/pages/pages_generator.rb index c1f530bde6..c81dfe6f34 100644 --- a/pages/lib/generators/refinery/pages/pages_generator.rb +++ b/pages/lib/generators/refinery/pages/pages_generator.rb @@ -1,7 +1,8 @@ module Refinery class PagesGenerator < Rails::Generators::Base - class_option :skip_migrations, :type => :boolean, :default => false, :aliases => nil, :group => :runtime, - :desc => "Skip over installing or running migrations." + class_option :skip_migrations, :type => :boolean, :default => false, + :aliases => nil, :group => :runtime, + :desc => "Skip over installing or running migrations." source_root File.expand_path('../templates', __FILE__) diff --git a/resources/db/migrate/20100913234709_create_refinerycms_resources_schema.rb b/resources/db/migrate/20100913234709_create_refinerycms_resources_schema.rb index 0b17948efd..72a2994f5b 100644 --- a/resources/db/migrate/20100913234709_create_refinerycms_resources_schema.rb +++ b/resources/db/migrate/20100913234709_create_refinerycms_resources_schema.rb @@ -7,7 +7,7 @@ def change t.string :file_uid t.string :file_ext - t.timestamps + t.timestamps null: false end end end diff --git a/resources/lib/generators/refinery/resources/resources_generator.rb b/resources/lib/generators/refinery/resources/resources_generator.rb index 24b6185702..b98d644a3f 100644 --- a/resources/lib/generators/refinery/resources/resources_generator.rb +++ b/resources/lib/generators/refinery/resources/resources_generator.rb @@ -1,7 +1,8 @@ module Refinery class ResourcesGenerator < Rails::Generators::Base - class_option :skip_migrations, :type => :boolean, :default => false, :aliases => nil, :group => :runtime, - :desc => "Skip over installing or running migrations." + class_option :skip_migrations, :type => :boolean, :default => false, + :aliases => nil, :group => :runtime, + :desc => "Skip over installing or running migrations." source_root File.expand_path('../templates', __FILE__) diff --git a/templates/refinery/edge.rb b/templates/refinery/edge.rb index 1d48cdf1a8..cf36aed363 100644 --- a/templates/refinery/edge.rb +++ b/templates/refinery/edge.rb @@ -16,22 +16,16 @@ gem "coffee-rails", :group => :assets end -if ENV['REFINERY_PATH'] - append_file 'Gemfile' do -" -gem 'refinerycms', path: '#{ENV['REFINERY_PATH']}' -" - end +refinerycms_source = if ENV['REFINERY_PATH'] + "path: '#{ENV['REFINERY_PATH']}'" else - append_file 'Gemfile' do -" -gem 'refinerycms', git: 'https://github.com/refinery/refinerycms', branch: 'master' -" - end + "git: 'https://github.com/refinery/refinerycms', branch: 'master'" end append_file 'Gemfile' do " +gem 'refinerycms', #{refinerycms_source} + # Add support for searching inside Refinery's admin interface. gem 'refinerycms-acts-as-indexed', ['~> 3.0', '>= 3.0.0'] @@ -46,10 +40,12 @@ run 'bundle install' rake 'db:create' +require 'refinery/core/environment_checker' +Refinery::Core::EnvironmentChecker.new(destination_root).call generate "refinery:cms --fresh-installation #{ARGV.join(' ')}" say <<-SAY ============================================================================ - Your new Refinery CMS application is now running on edge and mounted to /. + Your new Refinery CMS application is now running on edge and mounted at '/' ============================================================================ SAY diff --git a/testing/lib/refinery/tasks/testing.rake b/testing/lib/refinery/tasks/testing.rake index 1e018c8b26..09fc180d46 100644 --- a/testing/lib/refinery/tasks/testing.rake +++ b/testing/lib/refinery/tasks/testing.rake @@ -24,7 +24,7 @@ namespace :refinery do Refinery::DummyGenerator.start %W[--quiet --database=#{ENV['DB'].presence || 'sqlite3'}] - Refinery::CmsGenerator.start %w[--quiet --fresh-installation] + Refinery::CmsGenerator.start %w[--quiet --fresh-installation --skip-seeds] Dir.chdir dummy_app_path end