-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from emptyflask/fix/generator
fixed generator specs and added migration version
- Loading branch information
Showing
4 changed files
with
59 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
lib/generators/closure_tree/templates/create_hierarchies_table.rb.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,46 @@ | ||
# require 'spec_helper' | ||
# require 'ammeter/init' | ||
# | ||
# # Generators are not automatically loaded by Rails | ||
# require 'generators/closure_tree/migration_generator' | ||
# | ||
# RSpec.describe ClosureTree::Generators::MigrationGenerator, type: :generator do | ||
# TMPDIR = Dir.mktmpdir | ||
# # Tell generator where to put its output | ||
# destination TMPDIR | ||
# before { prepare_destination } | ||
# | ||
# describe 'generator output' do | ||
# before { run_generator %w(tag) } | ||
# subject { migration_file('db/migrate/create_tag_hierarchies.rb') } | ||
# it { is_expected.to be_a_migration } | ||
# it { is_expected.to contain(/t.integer :ancestor_id, null: false/) } | ||
# it { is_expected.to contain(/t.integer :descendant_id, null: false/) } | ||
# it { is_expected.to contain(/t.integer :generations, null: false/) } | ||
# it { is_expected.to contain(/add_index :tag_hierarchies/) } | ||
# end | ||
# | ||
# describe 'generator output with namespaced model' do | ||
# before { run_generator %w(Namespace::Type) } | ||
# subject { migration_file('db/migrate/create_namespace_type_hierarchies.rb') } | ||
# it { is_expected.to be_a_migration } | ||
# it { is_expected.to contain(/t.integer :ancestor_id, null: false/) } | ||
# it { is_expected.to contain(/t.integer :descendant_id, null: false/) } | ||
# it { is_expected.to contain(/t.integer :generations, null: false/) } | ||
# it { is_expected.to contain(/add_index :namespace_type_hierarchies/) } | ||
# end | ||
# | ||
# describe 'generator output with namespaced model with /' do | ||
# before { run_generator %w(namespace/type) } | ||
# subject { migration_file('db/migrate/create_namespace_type_hierarchies.rb') } | ||
# it { is_expected.to be_a_migration } | ||
# it { is_expected.to contain(/t.integer :ancestor_id, null: false/) } | ||
# it { is_expected.to contain(/t.integer :descendant_id, null: false/) } | ||
# it { is_expected.to contain(/t.integer :generations, null: false/) } | ||
# it { is_expected.to contain(/add_index :namespace_type_hierarchies/) } | ||
# end | ||
# | ||
# it 'should run all tasks in generator without errors' do | ||
# gen = generator %w(tag) | ||
# expect(gen).to receive :create_migration_file | ||
# capture(:stdout) { gen.invoke_all } | ||
# end | ||
# end | ||
require 'spec_helper' | ||
require "generator_spec/test_case" | ||
|
||
# Generators are not automatically loaded by Rails | ||
require 'generators/closure_tree/migration_generator' | ||
|
||
RSpec.describe ClosureTree::Generators::MigrationGenerator, type: :generator do | ||
include GeneratorSpec::TestCase | ||
|
||
# Tell generator where to put its output | ||
destination Dir.mktmpdir | ||
before { prepare_destination } | ||
|
||
describe 'generator output' do | ||
before { run_generator %w(tag) } | ||
subject { File.read migration_file_name('db/migrate/create_tag_hierarchies.rb') } | ||
it { is_expected.to match(/t.integer :ancestor_id, null: false/) } | ||
it { is_expected.to match(/t.integer :descendant_id, null: false/) } | ||
it { is_expected.to match(/t.integer :generations, null: false/) } | ||
it { is_expected.to match(/add_index :tag_hierarchies/) } | ||
end | ||
|
||
describe 'generator output with namespaced model' do | ||
before { run_generator %w(Namespace::Type) } | ||
subject { File.read migration_file_name('db/migrate/create_namespace_type_hierarchies.rb') } | ||
it { is_expected.to match(/t.integer :ancestor_id, null: false/) } | ||
it { is_expected.to match(/t.integer :descendant_id, null: false/) } | ||
it { is_expected.to match(/t.integer :generations, null: false/) } | ||
it { is_expected.to match(/add_index :namespace_type_hierarchies/) } | ||
end | ||
|
||
describe 'generator output with namespaced model with /' do | ||
before { run_generator %w(namespace/type) } | ||
subject { File.read migration_file_name('db/migrate/create_namespace_type_hierarchies.rb') } | ||
it { is_expected.to match(/t.integer :ancestor_id, null: false/) } | ||
it { is_expected.to match(/t.integer :descendant_id, null: false/) } | ||
it { is_expected.to match(/t.integer :generations, null: false/) } | ||
it { is_expected.to match(/add_index :namespace_type_hierarchies/) } | ||
end | ||
|
||
it 'should run all tasks in generator without errors' do | ||
gen = generator %w(tag) | ||
expect(gen).to receive :create_migration_file | ||
capture(:stdout) { gen.invoke_all } | ||
end | ||
end |