spec/generators/resource_generator_spec.rb in adminpanel-2.0.1 vs spec/generators/resource_generator_spec.rb in adminpanel-2.1.0

- old
+ new

@@ -11,33 +11,59 @@ after do prepare_destination end + describe 'with args and option -g false' do + + before do + # File.new "#{Rails.root}/tmp/config/initializers/adminpanel_setup.rb", 'w+' do |f| + # create config/initializers/adminpanel_setup.rb file under generator + # f.puts 'hi' + # end + run_generator %w( + post + name + description:wysiwyg + number:float + -g=false + ) + end + + it "shouldn't generate the gallery " do + file('app/models/adminpanel/postfile.rb').should_not exist + end + + # it "should add ':posts,' to file adminpanel_setup.rb" do + # file('config/initializers/adminpanel_setup.rb').should( + # contain(/:posts,/) + # ) + # end + end + describe 'with arguments %w(post name description:wysiwyg number:float - quantity:integer date:datepicker photo:images)' do + quantity:integer date:datepicker)' do before do run_generator %w( post name description:wysiwyg number:float flag:boolean quantity:integer date:datepicker - photo:images ) end it 'should generate the posts migration' do - migration_file('db/migrate/create_posts_table.rb').should be_a_migration + migration_file('db/migrate/create_adminpanel_posts.rb').should be_a_migration end context 'the migration' do it 'should have the correct fields' do - migration_file('db/migrate/create_posts_table.rb').should( + migration_file('db/migrate/create_adminpanel_posts.rb').should( contain(/t.string :name/) && contain(/t.float :number/) && contain(/t.boolean :flag/) && contain(/t.integer :quantity/) && contain(/t.string :date/) && @@ -58,14 +84,13 @@ contain(/:description/) && contain(/:number/) && contain(/:flag/) && contain(/:quantity/) && contain(/:date/) && - contain(/{:postfiles_attributes => \[:id, :file, :_destroy\]}/) + contain(/{ postfiles_attributes: \[:id, :file, :_destroy\] }/) ) end - end it 'should generate post model' do file('app/models/adminpanel/post.rb').should exist @@ -111,11 +136,11 @@ category:belongs_to product:belongs_to ) end - it 'shouldn\'t generate categorizations controller' do + it "shouldn't generate categorizations controller" do file('app/controllers/adminpanel/categorizations_controller').should_not exist end it 'should generate categorization model' do file('app/models/adminpanel/categorization.rb').should( @@ -123,22 +148,22 @@ contain(/belongs_to :category/) ) end end - describe 'with arguments post name products,categorizations:has_many_through' do + describe 'with arguments post name products:has_many' do before do run_generator %w( post name - products,categorizations:has_many_through + products:has_many ) end it 'should generate the model with has_many :categorizations' do file('app/models/adminpanel/post.rb').should( - contain(/has_many :categorizations/) && - contain(/has_many :products, :through => :categorizations/) + contain(/# has_many :categorizations/) && + contain(/# has_many :products, :through => :categorizations/) ) end end end