Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added tests for the generator

  • Loading branch information...
commit 3e5a251c79f3c2afb10fa644985d551e4d93f3a0 1 parent c1f82a1
@benjackson benjackson authored
View
1  .rdebugrc
@@ -0,0 +1 @@
+set autolist on
View
8 lib/generators/neo4j/devise_generator.rb
@@ -2,15 +2,15 @@
module Neo4j
module Generators
- class DeviseGenerator < Rails::Generators::NamedBase
- include Devise::Generators::OrmHelpers
-
+ class DeviseGenerator < ::Rails::Generators::NamedBase
+ include ::Devise::Generators::OrmHelpers
+
def generate_model
invoke "neo4j:model", [name] unless model_exists? && behavior == :invoke
end
def inject_devise_content
- inject_into_file(model_path, class_name, model_contents + <<CONTENT) if model_exists?
+ inject_into_file(model_path, model_contents + <<CONTENT, :after => /Neo4j(::Rails)?::Model\n/) if model_exists?
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
CONTENT
View
27 test/generators/neo4j/devise_generator_test.rb
@@ -0,0 +1,27 @@
+require 'test_helper'
+require 'tmpdir'
+require 'rails/generators/test_case'
+require 'generators/neo4j/devise_generator.rb'
+
+class Neo4j::Generators::ModelGeneratorTest < Rails::Generators::TestCase
+ tests Neo4j::Generators::DeviseGenerator
+ destination File.join(Dir.tmpdir, File.dirname(__FILE__))
+ setup :prepare_destination
+
+ def assert_class(klass, content)
+ assert content =~ /class #{klass}(\(.+\))?(.*?)\nend/m, "Expected to have class #{klass}"
+ yield $2.strip if block_given?
+ end
+
+ test "invoke with model name" do
+ content = run_generator %w(Player)
+
+ assert_file "app/models/player.rb" do |player|
+ assert_class "Player", player do |klass|
+ assert_match /Neo4j::Rails::Model/, klass
+ assert_match /attr_accessible :email, :password, :password_confirmation, :remember_me/, klass
+ end
+ end
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.