Skip to content

Commit

Permalink
Move the class methods to above the protected section
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Apr 1, 2013
1 parent 5f370eb commit b2f62f5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 47 deletions.
3 changes: 0 additions & 3 deletions railties/lib/rails/generators/testing/assertions.rb
@@ -1,9 +1,7 @@
module Rails
module Generators
module Testing

module Assertions

# Asserts a given file exists. You need to supply an absolute path or a path relative
# to the configured destination:
#
Expand Down Expand Up @@ -118,7 +116,6 @@ def assert_field_default_value(attribute_type, value)
assert_equal(value, create_generated_attribute(attribute_type).default)
end
end

end
end
end
76 changes: 36 additions & 40 deletions railties/lib/rails/generators/testing/behaviour.rb
Expand Up @@ -8,7 +8,6 @@
module Rails
module Generators
module Testing

module Behaviour
extend ActiveSupport::Concern

Expand All @@ -21,6 +20,29 @@ module Behaviour
self.default_arguments = []
end

module ClassMethods
# Sets which generator should be tested:
#
# tests AppGenerator
def tests(klass)
self.generator_class = klass
end

# Sets default arguments on generator invocation. This can be overwritten when
# invoking it.
#
# arguments %w(app_name --skip-active-record)
def arguments(array)
self.default_arguments = array
end

# Sets the destination of generator files:
#
# destination File.expand_path("../tmp", File.dirname(__FILE__))
def destination(path)
self.destination_root = path
end
end

# Runs the generator configured for this class. The first argument is an array like
# command line arguments:
Expand Down Expand Up @@ -55,53 +77,27 @@ def create_generated_attribute(attribute_type, name = 'test', index = nil)
Rails::Generators::GeneratedAttribute.parse([name, attribute_type, index].compact.join(':'))
end

protected

def destination_root_is_set? # :nodoc:
raise "You need to configure your Rails::Generators::TestCase destination root." unless destination_root
end

def ensure_current_path # :nodoc:
cd current_path
end

def prepare_destination # :nodoc:
rm_rf(destination_root)
mkdir_p(destination_root)
end

def migration_file_name(relative) # :nodoc:
absolute = File.expand_path(relative, destination_root)
dirname, file_name = File.dirname(absolute), File.basename(absolute).sub(/\.rb$/, '')
Dir.glob("#{dirname}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first
end
protected

def destination_root_is_set? # :nodoc:
raise "You need to configure your Rails::Generators::TestCase destination root." unless destination_root
end

module ClassMethods
# Sets which generator should be tested:
#
# tests AppGenerator
def tests(klass)
self.generator_class = klass
def ensure_current_path # :nodoc:
cd current_path
end

# Sets default arguments on generator invocation. This can be overwritten when
# invoking it.
#
# arguments %w(app_name --skip-active-record)
def arguments(array)
self.default_arguments = array
def prepare_destination # :nodoc:
rm_rf(destination_root)
mkdir_p(destination_root)
end

# Sets the destination of generator files:
#
# destination File.expand_path("../tmp", File.dirname(__FILE__))
def destination(path)
self.destination_root = path
def migration_file_name(relative) # :nodoc:
absolute = File.expand_path(relative, destination_root)
dirname, file_name = File.dirname(absolute), File.basename(absolute).sub(/\.rb$/, '')
Dir.glob("#{dirname}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first
end
end
end

end
end
end
4 changes: 0 additions & 4 deletions railties/lib/rails/generators/testing/setup_and_teardown.rb
@@ -1,9 +1,7 @@
module Rails
module Generators
module Testing

module SetupAndTeardown

def setup # :nodoc:
destination_root_is_set?
ensure_current_path
Expand All @@ -14,9 +12,7 @@ def teardown # :nodoc:
ensure_current_path
super
end

end

end
end
end

0 comments on commit b2f62f5

Please sign in to comment.