Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
19 changes: 8 additions & 11 deletions app/models/metasploit/concern/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ class Metasploit::Concern::Loader
# Validations
#

validates :root,
presence: true
validates :root, presence: true

#
# Methods
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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`.
Expand Down Expand Up @@ -141,4 +138,4 @@ def pathname_to_constant_name(descendant_pathname)

constant_name
end
end
end
6 changes: 3 additions & 3 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
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

require 'aruba/cucumber'
# 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
Expand Down
10 changes: 10 additions & 0 deletions lib/metasploit/concern/engine.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 4 additions & 5 deletions lib/metasploit/concern/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
11 changes: 5 additions & 6 deletions metasploit-concern.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ 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'

s.add_development_dependency 'metasploit-yard', '~> 1.0'

# 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
59 changes: 25 additions & 34 deletions spec/app/models/metasploit/concern/loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,16 @@ def remove_load_hooks
end

subject(:loader) do
described_class.new(
root: root
)
described_class.new(root: root)
end

#
# Methods
#

def remove_root
if root.exist?
root.rmtree
end
return unless root.exist?
root.rmtree
end

def root
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -470,4 +461,4 @@ def each_pathname_constant(&block)
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ module Dummy::ModelWithConcern::ConcernForModel

module ClassMethods
def class_method_from_concern

end
end

def instance_method_from_concern

end
end
end
Empty file added spec/dummy/app/helpers/.gitkeep
Empty file.
2 changes: 0 additions & 2 deletions spec/dummy/app/helpers/application_helper.rb

This file was deleted.

2 changes: 1 addition & 1 deletion spec/dummy/app/models/dummy/model_with_concern.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class Dummy::ModelWithConcern
ActiveSupport.run_load_hooks(:dummy_model_with_concern, self)
end
end
1 change: 0 additions & 1 deletion spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,3 @@ class Application < Rails::Application
config.paths.add 'app/concerns', autoload: true
end
end

2 changes: 1 addition & 1 deletion spec/dummy/config/boot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
Bundler.setup
end

$:.unshift File.expand_path('../../../../lib', __FILE__)
$:.unshift File.expand_path('../../../../lib', __FILE__)
6 changes: 3 additions & 3 deletions spec/lib/metasploit/concern/engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
# lets
#

let(:application) {
let(:application) do
Class.new(Rails::Engine)
}
end

let(:context) {
Object.new
Expand Down Expand Up @@ -177,4 +177,4 @@
end
end
end
end
end
2 changes: 1 addition & 1 deletion spec/lib/metasploit/concern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
end
end
end
end
end
5 changes: 3 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/support/shared/examples/metasploit/concern/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
expect(actual_bases).to include(described_class)
end
end
end
end