diff --git a/Gemfile b/Gemfile index 9f4c0ae..62863fd 100644 --- a/Gemfile +++ b/Gemfile @@ -16,15 +16,12 @@ group :development, :test do # rails is not used because activerecord should not be included, but rails would normally coordinate the versions # between its dependencies, which is now handled by this constraint. # @todo MSP-9654 - rails_version_constraint = [ - '>= 4.0.9', - '< 4.1.0' - ] - + rails_version_constraint = '>= 4.2.1' + # Dummy app uses actionpack for ActionController, but not rails since it doesn't use activerecord. - gem 'actionpack', *rails_version_constraint + gem 'actionpack', rails_version_constraint # Engine tasks are loaded using railtie - gem 'railties', *rails_version_constraint + gem 'railties', rails_version_constraint # need rspec-rails >= 2.12.0 as 2.12.0 adds support for redefining named subject in nested context that uses the # named subject from the outer context without causing a stack overflow. gem 'rspec-rails', '>= 2.12.0' @@ -44,5 +41,5 @@ group :test do # @see https://github.com/thoughtbot/shoulda-matchers/issues/480 gem 'shoulda-matchers', '< 2.6.0' # code coverage of tests - gem 'simplecov', :require => false + gem 'simplecov', require: false end diff --git a/app/models/metasploit/concern/loader.rb b/app/models/metasploit/concern/loader.rb index 9d0fbb0..188b784 100644 --- a/app/models/metasploit/concern/loader.rb +++ b/app/models/metasploit/concern/loader.rb @@ -16,8 +16,7 @@ class Metasploit::Concern::Loader # Validations # - validates :root, - presence: true + validates :root, presence: true # # Methods @@ -35,13 +34,11 @@ class Metasploit::Concern::Loader def each_pathname_constant(mechanism:, parent_pathname:) parent_pathname.each_child do |child_pathname| constant = constantize_pathname( - mechanism: mechanism, - pathname: child_pathname + mechanism: mechanism, + pathname: child_pathname ) - if constant - yield constant - end + yield constant if constant end end @@ -53,7 +50,7 @@ def glob end # @param attributes [Hash{Symbol => String,nil}] - def initialize(attributes={}) + def initialize(attributes = {}) attributes.each do |attribute, value| public_send("#{attribute}=", value) end @@ -65,12 +62,12 @@ def initialize(attributes={}) def module_pathname_set concern_paths = Dir.glob(glob) - concern_paths.each_with_object(Set.new) { |concern_path, module_pathname_set| + concern_paths.each_with_object(Set.new) do |concern_path, module_pathname_set| concern_pathname = Pathname.new(concern_path) module_pathname = concern_pathname.parent module_pathname_set.add module_pathname - } + end end # Registers load hooks with `ActiveSupport.on_load`. @@ -141,4 +138,4 @@ def pathname_to_constant_name(descendant_pathname) constant_name end -end \ No newline at end of file +end diff --git a/features/support/env.rb b/features/support/env.rb index 48c3614..435cb2a 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -7,8 +7,8 @@ SimpleCov.formatter = Coveralls::SimpleCov::Formatter else SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ - # either generate the local report - SimpleCov::Formatter::HTMLFormatter + # either generate the local report + SimpleCov::Formatter::HTMLFormatter ] end @@ -16,7 +16,7 @@ # only does jruby customization if actually in JRuby require 'aruba/jruby' -if ['jruby', 'rbx'].include? RUBY_ENGINE +if %w(jruby rbx).include? RUBY_ENGINE Before do @aruba_timeout_seconds = 12 end diff --git a/lib/metasploit/concern/engine.rb b/lib/metasploit/concern/engine.rb index 68ee4e1..259b989 100644 --- a/lib/metasploit/concern/engine.rb +++ b/lib/metasploit/concern/engine.rb @@ -1,5 +1,15 @@ require 'rails' +module Rails + class Engine + class Railties + def engines + @engines ||= ::Rails::Engine.subclasses.map(&:instance) + end + end + end +end + module Metasploit module Concern # Rails engine for Metasploit::Concern that sets up an initializer to load the concerns from app/concerns in other diff --git a/lib/metasploit/concern/version.rb b/lib/metasploit/concern/version.rb index bcd9fa8..84140ec 100644 --- a/lib/metasploit/concern/version.rb +++ b/lib/metasploit/concern/version.rb @@ -8,6 +8,9 @@ module Version MINOR = 0 # The patch number, scoped to the {MINOR} version number. PATCH = 0 + # the prerelease identifier + PRERELEASE = 'rails-4.2' + # The full version string, including the {MAJOR}, {MINOR}, {PATCH}, and optionally, the `PRERELEASE` in the # {http://semver.org/spec/v2.0.0.html semantic versioning v2.0.0} format. @@ -16,11 +19,7 @@ module Version # other than master. def self.full version = "#{MAJOR}.#{MINOR}.#{PATCH}" - - if defined? PRERELEASE - version = "#{version}-#{PRERELEASE}" - end - + version = "#{version}-#{PRERELEASE}" if defined? PRERELEASE version end diff --git a/metasploit-concern.gemspec b/metasploit-concern.gemspec index 3be8755..3d863f4 100644 --- a/metasploit-concern.gemspec +++ b/metasploit-concern.gemspec @@ -17,9 +17,8 @@ Gem::Specification.new do |s| 'descendents from other gems when layering schemas.' s.files = Dir['{app,config,lib}/**/*'] + ['CONTRIBUTING.md', 'LICENSE', 'Rakefile', 'README.md'] + Dir['spec/support/**/*.rb'] - - rails_version_constraints = ['>= 4.0.9', '< 4.1.0'] - + + rails_version_constraints = '>= 4.2.1' s.required_ruby_version = '>= 2.1' @@ -27,8 +26,8 @@ Gem::Specification.new do |s| # uses ActiveSupport.on_load to include concerns # it is only defined in version 3.0.0 and newer - s.add_runtime_dependency 'activerecord', *rails_version_constraints - s.add_runtime_dependency 'activesupport', *rails_version_constraints + s.add_runtime_dependency 'activerecord', rails_version_constraints + s.add_runtime_dependency 'activesupport', rails_version_constraints # for engine - s.add_runtime_dependency 'railties', *rails_version_constraints + s.add_runtime_dependency 'railties', rails_version_constraints end diff --git a/spec/app/models/metasploit/concern/loader_spec.rb b/spec/app/models/metasploit/concern/loader_spec.rb index bfad298..38b82e4 100644 --- a/spec/app/models/metasploit/concern/loader_spec.rb +++ b/spec/app/models/metasploit/concern/loader_spec.rb @@ -73,9 +73,7 @@ def remove_load_hooks end subject(:loader) do - described_class.new( - root: root - ) + described_class.new(root: root) end # @@ -83,9 +81,8 @@ def remove_load_hooks # def remove_root - if root.exist? - root.rmtree - end + return unless root.exist? + root.rmtree end def root @@ -225,9 +222,9 @@ def each_pathname_constant(&block) it 'yields concerns' do concern_names = [] - each_pathname_constant { |constant| + each_pathname_constant do |constant| concern_names << constant.name - } + end expect(concern_names).to match_array([concern_name]) end @@ -251,9 +248,9 @@ def each_pathname_constant(&block) end let(:expected_module_pathnames) do - Array.new(2) { |i| + Array.new(2) do |i| root.join('metasploit', 'concern', "module_with_concerns#{i}") - } + end end let(:non_module_pathname) do @@ -267,9 +264,9 @@ def each_pathname_constant(&block) expected_module_pathname.mkpath concern_pathname = expected_module_pathname.join('concern_for_module.rb') - concern_pathname.open('w') { |f| + concern_pathname.open('w') do |f| f.puts '# A concern' - } + end end end @@ -353,19 +350,17 @@ def each_pathname_constant(&block) end it 'has base class loaded' do - expect { + expect do Metasploit::Concern::ModuleWithConcerns - }.not_to raise_error + end.not_to raise_error expect(Metasploit::Concern::ModuleWithConcerns).to be_a Class end it 'includes concerns' do - expect { - register - }.to change { - Metasploit::Concern::ModuleWithConcerns.ancestors.map(&:name).include? concern_name - }.to(true) + expect { register }.to change { + Metasploit::Concern::ModuleWithConcerns.ancestors.map(&:name).include? concern_name + }.to(true) end it 'does not end up with two copies of concern when reloaded' do @@ -374,15 +369,13 @@ def each_pathname_constant(&block) Metasploit::Concern::ModuleWithConcerns expect(Metasploit::Concern::ModuleWithConcerns.ancestors.map(&:name).count(concern_name)).to eq(1) - expect { - ActiveSupport::Dependencies.clear - }.not_to change { - Metasploit::Concern::ModuleWithConcerns.constants.include? concern_relative_name.to_sym - } + expect { ActiveSupport::Dependencies.clear }.not_to change { + Metasploit::Concern::ModuleWithConcerns.constants.include? concern_relative_name.to_sym + } Metasploit::Concern::ModuleWithConcerns.send( - :include, - Metasploit::Concern::ModuleWithConcerns::ConcernForModule + :include, + Metasploit::Concern::ModuleWithConcerns::ConcernForModule ) expect(Metasploit::Concern::ModuleWithConcerns.ancestors.map(&:name).count(concern_name)).to eq(1) @@ -395,19 +388,17 @@ def each_pathname_constant(&block) end it 'has base class loaded' do - expect { + expect do Metasploit::Concern::ModuleWithConcerns - }.not_to raise_error + end.not_to raise_error expect(Metasploit::Concern::ModuleWithConcerns).to be_a Class end it 'includes concerns' do - expect { - register - }.to change { - Metasploit::Concern::ModuleWithConcerns.ancestors.map(&:name).include? concern_name - }.to(true) + expect { register }.to change { + Metasploit::Concern::ModuleWithConcerns.ancestors.map(&:name).include? concern_name + }.to(true) end it 'does not end up with two copies of concern when reloaded and included' do @@ -470,4 +461,4 @@ def each_pathname_constant(&block) end end end -end \ No newline at end of file +end diff --git a/spec/dummy/app/concerns/dummy/model_with_concern/concern_for_model.rb b/spec/dummy/app/concerns/dummy/model_with_concern/concern_for_model.rb index be54ad9..19d3e45 100644 --- a/spec/dummy/app/concerns/dummy/model_with_concern/concern_for_model.rb +++ b/spec/dummy/app/concerns/dummy/model_with_concern/concern_for_model.rb @@ -7,11 +7,9 @@ module Dummy::ModelWithConcern::ConcernForModel module ClassMethods def class_method_from_concern - end end def instance_method_from_concern - end -end \ No newline at end of file +end diff --git a/spec/dummy/app/helpers/.gitkeep b/spec/dummy/app/helpers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/app/helpers/application_helper.rb b/spec/dummy/app/helpers/application_helper.rb deleted file mode 100644 index de6be79..0000000 --- a/spec/dummy/app/helpers/application_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ApplicationHelper -end diff --git a/spec/dummy/app/models/dummy/model_with_concern.rb b/spec/dummy/app/models/dummy/model_with_concern.rb index ba42a97..07adc8b 100644 --- a/spec/dummy/app/models/dummy/model_with_concern.rb +++ b/spec/dummy/app/models/dummy/model_with_concern.rb @@ -1,3 +1,3 @@ class Dummy::ModelWithConcern ActiveSupport.run_load_hooks(:dummy_model_with_concern, self) -end \ No newline at end of file +end diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index 842b9d1..c6788ef 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -49,4 +49,3 @@ class Application < Rails::Application config.paths.add 'app/concerns', autoload: true end end - diff --git a/spec/dummy/config/boot.rb b/spec/dummy/config/boot.rb index eba0681..5be62d5 100644 --- a/spec/dummy/config/boot.rb +++ b/spec/dummy/config/boot.rb @@ -7,4 +7,4 @@ Bundler.setup end -$:.unshift File.expand_path('../../../../lib', __FILE__) \ No newline at end of file +$:.unshift File.expand_path('../../../../lib', __FILE__) diff --git a/spec/lib/metasploit/concern/engine_spec.rb b/spec/lib/metasploit/concern/engine_spec.rb index af71708..5aa9d78 100644 --- a/spec/lib/metasploit/concern/engine_spec.rb +++ b/spec/lib/metasploit/concern/engine_spec.rb @@ -17,9 +17,9 @@ # lets # - let(:application) { + let(:application) do Class.new(Rails::Engine) - } + end let(:context) { Object.new @@ -177,4 +177,4 @@ end end end -end \ No newline at end of file +end diff --git a/spec/lib/metasploit/concern_spec.rb b/spec/lib/metasploit/concern_spec.rb index 4d6de82..bf10a69 100644 --- a/spec/lib/metasploit/concern_spec.rb +++ b/spec/lib/metasploit/concern_spec.rb @@ -12,4 +12,4 @@ end end end -end \ No newline at end of file +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index edc38dd..e1e5be0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,7 @@ # This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' +require 'minitest/autorun' require 'rubygems' require 'bundler' Bundler.setup(:default, :test) @@ -15,8 +16,8 @@ SimpleCov.formatter = Coveralls::SimpleCov::Formatter else SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ - # either generate the local report - SimpleCov::Formatter::HTMLFormatter + # either generate the local report + SimpleCov::Formatter::HTMLFormatter ] end diff --git a/spec/support/shared/examples/metasploit/concern/run.rb b/spec/support/shared/examples/metasploit/concern/run.rb index 64d2518..7f430b9 100644 --- a/spec/support/shared/examples/metasploit/concern/run.rb +++ b/spec/support/shared/examples/metasploit/concern/run.rb @@ -31,4 +31,4 @@ expect(actual_bases).to include(described_class) end end -end \ No newline at end of file +end