2011-04-15 18:55:37 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'fileutils'
|
|
|
|
|
|
|
|
describe 'backbone-generator' do
|
|
|
|
def clean!
|
|
|
|
FileUtils.rm_rf 'public'
|
|
|
|
FileUtils.rm_rf 'spec/javascripts'
|
|
|
|
FileUtils.rm_rf 'app'
|
|
|
|
end
|
|
|
|
|
|
|
|
before { clean! }
|
|
|
|
after { clean! }
|
|
|
|
|
|
|
|
describe 'model' do
|
|
|
|
it "should generate the model files" do
|
|
|
|
system %{bin/backbone-generator model Section::Model}
|
|
|
|
|
2011-04-15 20:00:25 +00:00
|
|
|
File.file?(model = 'public/javascripts/models/section/model.js').should be_true
|
|
|
|
File.file?(spec = 'spec/javascripts/models/section/model_spec.js').should be_true
|
2011-04-15 18:55:37 +00:00
|
|
|
|
|
|
|
File.read(model).should match(/SectionModel/)
|
|
|
|
File.read(spec).should match(/SectionModel/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'view' do
|
|
|
|
it "should generate the view files" do
|
2011-04-15 19:32:04 +00:00
|
|
|
system %{bin/backbone-generator view Section::Model}
|
2011-04-15 18:55:37 +00:00
|
|
|
|
2011-04-15 19:58:47 +00:00
|
|
|
File.file?(view = 'public/javascripts/views/section/model_view.js').should be_true
|
|
|
|
File.file?(spec = 'spec/javascripts/views/section/model_view_spec.js').should be_true
|
2011-04-15 19:32:04 +00:00
|
|
|
File.file?(template = 'app/views/section/model.jst').should be_true
|
2011-04-15 18:55:37 +00:00
|
|
|
|
2011-04-15 19:32:04 +00:00
|
|
|
File.read(view).should match(/SectionModel/)
|
2011-04-15 20:14:18 +00:00
|
|
|
File.read(view).should match(/return this/)
|
2011-04-15 19:32:04 +00:00
|
|
|
File.read(view).should match(%r{template: JST\['section/model'\]})
|
|
|
|
File.read(spec).should match(/SectionModel/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'collection view' do
|
|
|
|
it "should generate the collection view files" do
|
|
|
|
system %{bin/backbone-generator collection-view Section::Model}
|
|
|
|
|
2011-04-15 19:58:47 +00:00
|
|
|
File.file?(view = 'public/javascripts/views/section/models_view.js').should be_true
|
|
|
|
File.file?(spec = 'spec/javascripts/views/section/models_view_spec.js').should be_true
|
2011-04-15 19:32:04 +00:00
|
|
|
File.file?(template = 'app/views/section/models.jst').should be_true
|
|
|
|
|
2011-04-15 19:52:27 +00:00
|
|
|
File.read(view).should match(/SectionModelsView/)
|
2011-04-15 20:11:57 +00:00
|
|
|
File.read(view).should match(/SectionModelView/)
|
2011-04-15 20:14:18 +00:00
|
|
|
File.read(view).should match(/return this/)
|
2011-04-15 19:32:04 +00:00
|
|
|
File.read(view).should match(%r{template: JST\['section/models'\]})
|
2011-04-15 19:52:27 +00:00
|
|
|
File.read(spec).should match(/SectionModelsView/)
|
2011-04-15 18:55:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'collection' do
|
|
|
|
it "should generate the collection files" do
|
2011-04-15 19:32:04 +00:00
|
|
|
system %{bin/backbone-generator collection Section::Model}
|
2011-04-15 18:55:37 +00:00
|
|
|
|
2011-04-15 20:02:22 +00:00
|
|
|
File.file?(collection = 'public/javascripts/collections/section/models.js').should be_true
|
|
|
|
File.file?(spec = 'spec/javascripts/collections/section/models_spec.js').should be_true
|
2011-04-15 18:55:37 +00:00
|
|
|
|
2011-04-15 20:02:22 +00:00
|
|
|
File.read(collection).should match(/SectionModels/)
|
2011-04-15 19:32:04 +00:00
|
|
|
File.read(collection).should match(%r{section/model})
|
2011-04-15 20:02:22 +00:00
|
|
|
File.read(spec).should match(/SectionModels/)
|
2011-04-15 18:55:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|