|
1 | | -# require 'spec_helper' |
2 | | -# require 'ammeter/init' |
3 | | -# |
4 | | -# # Generators are not automatically loaded by Rails |
5 | | -# require 'generators/closure_tree/migration_generator' |
6 | | -# |
7 | | -# RSpec.describe ClosureTree::Generators::MigrationGenerator, type: :generator do |
8 | | -# TMPDIR = Dir.mktmpdir |
9 | | -# # Tell generator where to put its output |
10 | | -# destination TMPDIR |
11 | | -# before { prepare_destination } |
12 | | -# |
13 | | -# describe 'generator output' do |
14 | | -# before { run_generator %w(tag) } |
15 | | -# subject { migration_file('db/migrate/create_tag_hierarchies.rb') } |
16 | | -# it { is_expected.to be_a_migration } |
17 | | -# it { is_expected.to contain(/t.integer :ancestor_id, null: false/) } |
18 | | -# it { is_expected.to contain(/t.integer :descendant_id, null: false/) } |
19 | | -# it { is_expected.to contain(/t.integer :generations, null: false/) } |
20 | | -# it { is_expected.to contain(/add_index :tag_hierarchies/) } |
21 | | -# end |
22 | | -# |
23 | | -# describe 'generator output with namespaced model' do |
24 | | -# before { run_generator %w(Namespace::Type) } |
25 | | -# subject { migration_file('db/migrate/create_namespace_type_hierarchies.rb') } |
26 | | -# it { is_expected.to be_a_migration } |
27 | | -# it { is_expected.to contain(/t.integer :ancestor_id, null: false/) } |
28 | | -# it { is_expected.to contain(/t.integer :descendant_id, null: false/) } |
29 | | -# it { is_expected.to contain(/t.integer :generations, null: false/) } |
30 | | -# it { is_expected.to contain(/add_index :namespace_type_hierarchies/) } |
31 | | -# end |
32 | | -# |
33 | | -# describe 'generator output with namespaced model with /' do |
34 | | -# before { run_generator %w(namespace/type) } |
35 | | -# subject { migration_file('db/migrate/create_namespace_type_hierarchies.rb') } |
36 | | -# it { is_expected.to be_a_migration } |
37 | | -# it { is_expected.to contain(/t.integer :ancestor_id, null: false/) } |
38 | | -# it { is_expected.to contain(/t.integer :descendant_id, null: false/) } |
39 | | -# it { is_expected.to contain(/t.integer :generations, null: false/) } |
40 | | -# it { is_expected.to contain(/add_index :namespace_type_hierarchies/) } |
41 | | -# end |
42 | | -# |
43 | | -# it 'should run all tasks in generator without errors' do |
44 | | -# gen = generator %w(tag) |
45 | | -# expect(gen).to receive :create_migration_file |
46 | | -# capture(:stdout) { gen.invoke_all } |
47 | | -# end |
48 | | -# end |
| 1 | +require 'spec_helper' |
| 2 | +require "generator_spec/test_case" |
| 3 | + |
| 4 | +# Generators are not automatically loaded by Rails |
| 5 | +require 'generators/closure_tree/migration_generator' |
| 6 | + |
| 7 | +RSpec.describe ClosureTree::Generators::MigrationGenerator, type: :generator do |
| 8 | + include GeneratorSpec::TestCase |
| 9 | + |
| 10 | + # Tell generator where to put its output |
| 11 | + destination Dir.mktmpdir |
| 12 | + before { prepare_destination } |
| 13 | + |
| 14 | + describe 'generator output' do |
| 15 | + before { run_generator %w(tag) } |
| 16 | + subject { File.read migration_file_name('db/migrate/create_tag_hierarchies.rb') } |
| 17 | + it { is_expected.to match(/t.integer :ancestor_id, null: false/) } |
| 18 | + it { is_expected.to match(/t.integer :descendant_id, null: false/) } |
| 19 | + it { is_expected.to match(/t.integer :generations, null: false/) } |
| 20 | + it { is_expected.to match(/add_index :tag_hierarchies/) } |
| 21 | + end |
| 22 | + |
| 23 | + describe 'generator output with namespaced model' do |
| 24 | + before { run_generator %w(Namespace::Type) } |
| 25 | + subject { File.read migration_file_name('db/migrate/create_namespace_type_hierarchies.rb') } |
| 26 | + it { is_expected.to match(/t.integer :ancestor_id, null: false/) } |
| 27 | + it { is_expected.to match(/t.integer :descendant_id, null: false/) } |
| 28 | + it { is_expected.to match(/t.integer :generations, null: false/) } |
| 29 | + it { is_expected.to match(/add_index :namespace_type_hierarchies/) } |
| 30 | + end |
| 31 | + |
| 32 | + describe 'generator output with namespaced model with /' do |
| 33 | + before { run_generator %w(namespace/type) } |
| 34 | + subject { File.read migration_file_name('db/migrate/create_namespace_type_hierarchies.rb') } |
| 35 | + it { is_expected.to match(/t.integer :ancestor_id, null: false/) } |
| 36 | + it { is_expected.to match(/t.integer :descendant_id, null: false/) } |
| 37 | + it { is_expected.to match(/t.integer :generations, null: false/) } |
| 38 | + it { is_expected.to match(/add_index :namespace_type_hierarchies/) } |
| 39 | + end |
| 40 | + |
| 41 | + it 'should run all tasks in generator without errors' do |
| 42 | + gen = generator %w(tag) |
| 43 | + expect(gen).to receive :create_migration_file |
| 44 | + capture(:stdout) { gen.invoke_all } |
| 45 | + end |
| 46 | +end |
0 commit comments