rails-backbone-generator 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +135 -0
- data/Rakefile +2 -0
- data/lib/generators/backbone/collection_generator.rb +65 -0
- data/lib/generators/backbone/model_generator.rb +56 -0
- data/lib/generators/backbone/namespace_generator.rb +68 -0
- data/lib/generators/backbone/templates/app/assets/javascripts/%namespace%/collections/%collection_name%.coffee.tt +4 -0
- data/lib/generators/backbone/templates/app/assets/javascripts/%namespace%/collections/.gitkeep +0 -0
- data/lib/generators/backbone/templates/app/assets/javascripts/%namespace%/models/%model_name%.coffee.tt +15 -0
- data/lib/generators/backbone/templates/app/assets/javascripts/%namespace%/models/.gitkeep +0 -0
- data/lib/generators/backbone/templates/app/assets/javascripts/%namespace%/routes/.gitkeep +0 -0
- data/lib/generators/backbone/templates/app/assets/javascripts/%namespace%/templates/.gitkeep +0 -0
- data/lib/generators/backbone/templates/app/assets/javascripts/%namespace%/views/.gitkeep +0 -0
- data/lib/generators/backbone/templates/app/assets/javascripts/%namespace%.coffee.tt +16 -0
- data/lib/generators/backbone/templates/app/assets/javascripts/shared/.gitkeep +0 -0
- data/lib/generators/backbone/templates/app/assets/javascripts/shared/core_extentions/collections_extentions.coffee +30 -0
- data/lib/generators/backbone/templates/app/assets/javascripts/shared/helpers/.gitkeep +0 -0
- data/lib/generators/backbone/templates/app/assets/javascripts/shared/utils/.gitkeep +0 -0
- data/lib/generators/backbone/templates/spec/javascripts/%namespace%/collections/%collection_name%_spec.coffee.tt +8 -0
- data/lib/generators/backbone/templates/spec/javascripts/%namespace%/collections/.gitkeep +0 -0
- data/lib/generators/backbone/templates/spec/javascripts/%namespace%/factories/%model_name%_factory.coffee.tt +43 -0
- data/lib/generators/backbone/templates/spec/javascripts/%namespace%/factories/.gitkeep +0 -0
- data/lib/generators/backbone/templates/spec/javascripts/%namespace%/models/%model_name%_spec.coffee.tt +12 -0
- data/lib/generators/backbone/templates/spec/javascripts/%namespace%/models/.gitkeep +0 -0
- data/lib/generators/backbone/templates/spec/javascripts/%namespace%/views/.gitkeep +0 -0
- data/lib/generators/backbone/templates/spec/javascripts/helpers/association_helpers.coffee +3 -0
- data/lib/generators/backbone/templates/spec/javascripts/helpers/common_helpers.coffee +13 -0
- data/lib/generators/backbone/templates/spec/javascripts/helpers/fake_host.coffee +18 -0
- data/lib/generators/backbone/templates/spec/javascripts/helpers/headless_webkit_helper.coffee +9 -0
- data/lib/generators/backbone/templates/spec/javascripts/helpers/state_helpers.coffee +4 -0
- data/lib/generators/backbone/templates/spec/javascripts/support/jasmine.yml +81 -0
- data/lib/generators/backbone/templates/vendor/javascripts/.gitkeep +0 -0
- data/lib/generators/backbone/templates/vendor/javascripts/backbone/backbone-0.9.2.js +1431 -0
- data/lib/generators/backbone/templates/vendor/javascripts/backbone/backbone-bind-to-1.0.0.coffee +47 -0
- data/lib/generators/backbone/templates/vendor/javascripts/backbone/backbone-handlebars-1.0.0.coffee +1920 -0
- data/lib/generators/backbone/templates/vendor/javascripts/backbone/backbone-query-0.1.2.js +325 -0
- data/lib/generators/backbone/templates/vendor/javascripts/backbone/backbone-relational-0.6.0.js +1687 -0
- data/lib/generators/backbone/templates/vendor/javascripts/backbone/handlebars-1.0.rc.1.js +1920 -0
- data/lib/generators/backbone/templates/vendor/javascripts/backbone/underscore-1.3.3.js +1059 -0
- data/lib/generators/backbone/templates/vendor/javascripts/browser_compatibility/json2.js +487 -0
- data/lib/generators/backbone/templates/vendor/javascripts/browser_compatibility/localstorage-polyfill.js +92 -0
- data/lib/generators/backbone/templates/vendor/javascripts/jquery/jquery-1.8.0.js +9227 -0
- data/lib/generators/backbone/templates/vendor/javascripts/jquery/jquery-ui.min.js +17 -0
- data/lib/generators/backbone/templates/vendor/javascripts/jquery/jquery.easing-1.3.js +205 -0
- data/lib/generators/backbone/templates/vendor/javascripts/jquery/jquery_ujs.js +368 -0
- data/lib/generators/backbone/templates/vendor/javascripts/testing/backbone-factory.js +53 -0
- data/lib/generators/backbone/templates/vendor/javascripts/testing/jasmine-jquery-1.3.1.js +288 -0
- data/lib/generators/backbone/templates/vendor/javascripts/testing/jasmine-sinon.js +43 -0
- data/lib/generators/backbone/templates/vendor/javascripts/testing/mock-ajax.js +207 -0
- data/lib/generators/backbone/templates/vendor/javascripts/testing/sinon-1.4.2.js +4081 -0
- data/lib/generators/backbone_generator.rb +3 -0
- data/lib/rails_backbone_generator/version.rb +3 -0
- data/lib/rails_backbone_generator.rb +4 -0
- data/rails_backbone_generator.gemspec +20 -0
- metadata +135 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Chip Miller
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
# RailsBackboneGenerator
|
2
|
+
Inspired by ``rails generate`` - Generates [Backbone.js](/documentcloud/backbone) models and collections with [BackboneFactory](/SupportBee/Backbone-Factory) and [Jasmine](/pivotal/jasmine) tests.
|
3
|
+
```
|
4
|
+
$ rails generate backbone:collection Dashboard::Widget
|
5
|
+
|
6
|
+
app/assets/javascripts/dashboard
|
7
|
+
├── collections
|
8
|
+
│ └── widgets.coffee
|
9
|
+
└── models
|
10
|
+
└── widget.coffee
|
11
|
+
|
12
|
+
spec/javascripts/dashboard
|
13
|
+
├── collections
|
14
|
+
│ └── widgets_spec.coffee
|
15
|
+
├── factories
|
16
|
+
│ └── widget_factory.coffee
|
17
|
+
└── models
|
18
|
+
└── widget_spec.coffee
|
19
|
+
```
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
Add this line to your application's Gemfile:
|
23
|
+
|
24
|
+
gem 'rails_backbone_generator'
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
|
28
|
+
$ bundle
|
29
|
+
|
30
|
+
Or install it yourself as:
|
31
|
+
|
32
|
+
$ gem install rails_backbone_generator
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
The gem has three generators:
|
36
|
+
```
|
37
|
+
$ rails g # for generate
|
38
|
+
|
39
|
+
Backbone:
|
40
|
+
backbone:collection
|
41
|
+
backbone:model
|
42
|
+
backbone:namespace
|
43
|
+
```
|
44
|
+
## backbone:namespace
|
45
|
+
Creates a namespaced directory structure
|
46
|
+
```
|
47
|
+
$ rails g backbone:namespace dashboard
|
48
|
+
|
49
|
+
app/assets/javascripts/dashboard
|
50
|
+
│ ├── collections
|
51
|
+
│ ├── models
|
52
|
+
│ ├── routes
|
53
|
+
│ ├── templates
|
54
|
+
│ └── views
|
55
|
+
├── dashboard.coffee
|
56
|
+
├── application.js
|
57
|
+
└── shared
|
58
|
+
├── core_extentions
|
59
|
+
│ └── collections_extentions.coffee
|
60
|
+
├── helpers
|
61
|
+
└── utils
|
62
|
+
|
63
|
+
spec/javascripts/dashboard/
|
64
|
+
├── collections
|
65
|
+
├── factories
|
66
|
+
├── models
|
67
|
+
└── views
|
68
|
+
```
|
69
|
+
|
70
|
+
## backbone:collection
|
71
|
+
Creates a model and plural-collection
|
72
|
+
```
|
73
|
+
$ rails g backbone:collection Dashboard::Widgets
|
74
|
+
|
75
|
+
app/assets/javascripts/dashboard
|
76
|
+
├── collections
|
77
|
+
│ └── widgets.coffee
|
78
|
+
└── models
|
79
|
+
└── widget.coffee
|
80
|
+
|
81
|
+
spec/javascripts/dashboard/
|
82
|
+
├── collections
|
83
|
+
│ └── widgets_spec.coffee
|
84
|
+
├── factories
|
85
|
+
│ └── widget_factory.coffee
|
86
|
+
└── models
|
87
|
+
└── widget_spec.coffee
|
88
|
+
```
|
89
|
+
|
90
|
+
|
91
|
+
## backbone:model
|
92
|
+
Creates a model w/out a collection
|
93
|
+
```
|
94
|
+
$ rails g backbone:model Dashboard::Widget
|
95
|
+
create app/assets/javascripts/dashboard/widget.coffee
|
96
|
+
create spec/javascripts/dashboard/factories/widget_factory.coffee
|
97
|
+
create spec/javascripts/dashboard/models/widget_spec.coffee
|
98
|
+
|
99
|
+
app/assets/javascript/dashboard
|
100
|
+
└── models
|
101
|
+
└── widget.coffee
|
102
|
+
|
103
|
+
spec/javascripts/dashboard
|
104
|
+
├── factories
|
105
|
+
│ └── widget_factory.coffee
|
106
|
+
└── models
|
107
|
+
└── widget_spec.coffee
|
108
|
+
|
109
|
+
|
110
|
+
```
|
111
|
+
## Factories
|
112
|
+
Similar to ruby's FactoryGirl, BackboneFactory adds factories to Jasmine.js. ``Factory.widget({ options:obj }) #=> Backbone.Model``
|
113
|
+
The generator adds ``Factory.model_name({optional:override})`` and ``Factory.collection_name({optional:override})``
|
114
|
+
```
|
115
|
+
# spec/javascripts/dashboard/factories/widget_factory.coffee
|
116
|
+
|
117
|
+
BackboneFactory.define 'widget', Dashboard.Models.Widget, ->
|
118
|
+
reminder: 'Remember to update with attributes'
|
119
|
+
hint: 'attributes can be other factories'
|
120
|
+
```
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
## Contributing
|
125
|
+
|
126
|
+
1. Fork it
|
127
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
128
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
129
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
130
|
+
5. Create new Pull Request
|
131
|
+
|
132
|
+
<hr/>
|
133
|
+
[](http://http://www.rafter.com/)
|
134
|
+
RailsBackboneGenerator is maintained by [Chip Miller](/chip-miller) and and funded by [Rafter](http://http://www.rafter.com/)
|
135
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rails/generators'
|
3
|
+
|
4
|
+
module Backbone
|
5
|
+
class CollectionGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
desc "Creates a BackboneModel, BackboneCollection, & Jasmine tests/factory\nrails g backbone:collection Navigation::Buttons"
|
8
|
+
argument :raw_collection_name, required: true, type: 'string'
|
9
|
+
|
10
|
+
def create_collection
|
11
|
+
destination_dir = File.join( ['app/assets/javascripts', namespace, 'collections', "#{collection_name}.coffee"].compact )
|
12
|
+
template 'app/assets/javascripts/%namespace%/collections/%collection_name%.coffee.tt', destination_dir
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_model
|
16
|
+
destination_dir = File.join( ['app/assets/javascripts', namespace, 'models', "#{model_name}.coffee"].compact )
|
17
|
+
template 'app/assets/javascripts/%namespace%/models/%model_name%.coffee.tt', destination_dir
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_specs
|
21
|
+
destination_dir = File.join( ['spec/javascripts', namespace].compact )
|
22
|
+
spec_paths = ['collections/%collection_name%_spec.coffee', 'factories/%model_name%_factory.coffee', 'models/%model_name%_spec.coffee']
|
23
|
+
spec_paths.each do |path|
|
24
|
+
template "spec/javascripts/%namespace%/#{path}.tt", "spec/javascripts/%namespace%/#{path}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def print_tree
|
29
|
+
tree = <<-TREE
|
30
|
+
|
31
|
+
app/assets/javascripts/dashboard
|
32
|
+
├── collections
|
33
|
+
│ └── widgets.coffee
|
34
|
+
└── models
|
35
|
+
└── widget.coffee
|
36
|
+
|
37
|
+
spec/javascripts/dashboard
|
38
|
+
├── collections
|
39
|
+
│ └── widgets_spec.coffee
|
40
|
+
├── factories
|
41
|
+
│ └── widget_factory.coffee
|
42
|
+
└── models
|
43
|
+
└── widget_spec.coffee
|
44
|
+
TREE
|
45
|
+
say tree.gsub(/dashboard/, namespace.to_s).gsub(/widget/, model_name)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Helpers
|
49
|
+
def collection_name(classify=false)
|
50
|
+
style = classify ? :camelize : :underscore
|
51
|
+
_collection_name, _namespace = raw_collection_name.split('::').reverse
|
52
|
+
_collection_name.pluralize.send(style)
|
53
|
+
end
|
54
|
+
|
55
|
+
def namespace(classify=false)
|
56
|
+
style = classify ? :camelize : :underscore
|
57
|
+
_collection_name, _namespace = raw_collection_name.split('::').reverse
|
58
|
+
_namespace && _namespace.singularize.send(style)
|
59
|
+
end
|
60
|
+
|
61
|
+
def model_name(classify=false)
|
62
|
+
collection_name(classify).singularize
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rails/generators'
|
3
|
+
|
4
|
+
module Backbone
|
5
|
+
class ModelGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
desc "Creates a BackboneModel, Jasmine tests/factory"
|
8
|
+
argument :raw_model_name, required: true, type: 'string'
|
9
|
+
|
10
|
+
def create_model
|
11
|
+
destination_dir = File.join( ['app/assets/javascripts', namespace, "#{model_name}.coffee"].compact )
|
12
|
+
template 'app/assets/javascripts/%namespace%/models/%model_name%.coffee.tt', destination_dir
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_specs
|
16
|
+
destination_dir = File.join( ['spec/javascripts', namespace].compact )
|
17
|
+
spec_paths = ['factories/%model_name%_factory.coffee', 'models/%model_name%_spec.coffee']
|
18
|
+
spec_paths.each do |path|
|
19
|
+
template "spec/javascripts/%namespace%/#{path}.tt", "spec/javascripts/%namespace%/#{path}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def print_tree
|
24
|
+
tree = <<-TREE
|
25
|
+
|
26
|
+
app/assets/javascript/dashboard
|
27
|
+
└── models
|
28
|
+
└── widget.coffee
|
29
|
+
|
30
|
+
spec/javascripts/dashboard
|
31
|
+
├── factories
|
32
|
+
│ └── widget_factory.coffee
|
33
|
+
└── models
|
34
|
+
└── widget_spec.coffee
|
35
|
+
TREE
|
36
|
+
say tree.gsub(/\/dashboard/, namespace.to_s).gsub(/widget/, model_name)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Helpers
|
40
|
+
def namespace(classify=false)
|
41
|
+
@model_name, @namespace = raw_model_name.split('::').reverse
|
42
|
+
style = classify ? :camelize : :underscore
|
43
|
+
@namespace && @namespace.singularize.send(style)
|
44
|
+
end
|
45
|
+
|
46
|
+
def model_name(classify=false)
|
47
|
+
@model_name, @namespace = raw_model_name.split('::').reverse
|
48
|
+
style = classify ? :camelize : :underscore
|
49
|
+
@model_name.singularize.send(style)
|
50
|
+
end
|
51
|
+
|
52
|
+
def collection_name(classify=false)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rails/generators'
|
3
|
+
require 'find'
|
4
|
+
|
5
|
+
module Backbone
|
6
|
+
class NamespaceGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
desc "Setup a Backbone namespace"
|
9
|
+
argument :raw_namespace, :type => :string, :required => true
|
10
|
+
|
11
|
+
def ensure_namespaced_app_dir # :nodoc:
|
12
|
+
directory 'app/assets/javascripts'
|
13
|
+
|
14
|
+
# add to application.js
|
15
|
+
append_to_file 'app/assets/javascripts/application.js', "\n\n"
|
16
|
+
gsub_file 'app/assets/javascripts/application.js', /\/\/.*\n\s/ do |match|
|
17
|
+
match.sub /\n\s/, "\n//= require ./#{namespace}\n\n"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def ensure_namespaced_spec_dir # :nodoc:
|
22
|
+
directory 'spec/javascripts'
|
23
|
+
end
|
24
|
+
|
25
|
+
# removes %un-namespaced% files
|
26
|
+
def cleanup
|
27
|
+
['app/assets/javascripts', 'spec/javascripts'].each do |base|
|
28
|
+
Dir.glob("#{base}/**/__delte__*").each do |file|
|
29
|
+
remove_file( file )
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def print_tree
|
35
|
+
tree = <<-TREE
|
36
|
+
|
37
|
+
app/assets/javascripts/dashboard
|
38
|
+
│ ├── collections
|
39
|
+
│ ├── models
|
40
|
+
│ ├── routes
|
41
|
+
│ ├── templates
|
42
|
+
│ └── views
|
43
|
+
├── dashboard.coffee
|
44
|
+
├── application.js
|
45
|
+
└── shared
|
46
|
+
├── core_extentions
|
47
|
+
│ └── collections_extentions.coffee
|
48
|
+
├── helpers
|
49
|
+
└── utils
|
50
|
+
|
51
|
+
spec/javascripts/dashboard/
|
52
|
+
├── collections
|
53
|
+
├── factories
|
54
|
+
├── models
|
55
|
+
└── views
|
56
|
+
TREE
|
57
|
+
say tree.gsub(/dashboard/, namespace).gsub(/widget/, model_name)
|
58
|
+
end
|
59
|
+
|
60
|
+
def namespace(classify=false)
|
61
|
+
style = classify ? :camelize : :underscore
|
62
|
+
raw_namespace.send(style)
|
63
|
+
end
|
64
|
+
|
65
|
+
def model_name(classify=false); '__delte__' ;end
|
66
|
+
def collection_name(classify=false); '__delte__' ;end
|
67
|
+
end
|
68
|
+
end
|
data/lib/generators/backbone/templates/app/assets/javascripts/%namespace%/collections/.gitkeep
ADDED
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class <%= [namespace('classify'), "Models", model_name('classify')].compact.join('.') %> extends Backbone.RelationalModel
|
2
|
+
|
3
|
+
# relations:[
|
4
|
+
# {
|
5
|
+
# type: 'HasMany'
|
6
|
+
# key: 'examples'
|
7
|
+
# relatedModel: '<%= [namespace('classify'), "Models", "Example"].compact.join('.') %>'
|
8
|
+
# collectionType: '<%= [namespace('classify'), "Collections", "Examples"].compact.join('.') %>'
|
9
|
+
# reverseRelation:
|
10
|
+
# key: 'example_id'
|
11
|
+
# type: 'HasOne'
|
12
|
+
# }
|
13
|
+
# ]
|
14
|
+
#
|
15
|
+
# defaults: {}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#= require_tree ./shared
|
2
|
+
#= require_self
|
3
|
+
#= require_tree ./<%= namespace %>
|
4
|
+
window.<%= namespace( :classify ) %> ||= {}
|
5
|
+
_(<%= namespace( :classify ) %>).extend
|
6
|
+
Collections: {}
|
7
|
+
Models: {}
|
8
|
+
Routers: {}
|
9
|
+
Views: {}
|
10
|
+
Templates: {}
|
11
|
+
Environment: {}
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
$(document).ready ->
|
16
|
+
|
File without changes
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class Backbone.ExtendedCollection extends Backbone.Collection
|
2
|
+
|
3
|
+
# Backwards compatable interface update
|
4
|
+
# Allows the Backbone.Collection#constructor to accept a single hash of attributes.
|
5
|
+
# The 'models' attribute is used as the collection's enumerable
|
6
|
+
#
|
7
|
+
# new Sample({
|
8
|
+
# models:[ model1, model2],
|
9
|
+
# title: 'great for factories'
|
10
|
+
# })
|
11
|
+
#
|
12
|
+
constructor: (models=[], other_options={})->
|
13
|
+
unless models instanceof Array
|
14
|
+
_(other_options).extend( _(models).tap (obj)->
|
15
|
+
models = models.models
|
16
|
+
delete obj.options
|
17
|
+
)
|
18
|
+
|
19
|
+
# store attributes
|
20
|
+
@attributes = _.clone @defaults || {}
|
21
|
+
_.chain(@attributes).keys().each (attr)=>
|
22
|
+
@attributes[attr]= other_options[attr] if other_options[attr]?
|
23
|
+
|
24
|
+
# continue building obj
|
25
|
+
super( models, other_options )
|
26
|
+
|
27
|
+
|
28
|
+
toJSON: => { collection: @models }
|
29
|
+
|
30
|
+
first: => @at(0)
|
File without changes
|
File without changes
|
@@ -0,0 +1,8 @@
|
|
1
|
+
describe "<%= [namespace('classify'), 'Collections'].compact.join('.') %>", ->
|
2
|
+
|
3
|
+
describe "<%= collection_name('classify') %>", ->
|
4
|
+
@<%= collection_name %> = Factory.<%= collection_name %>()
|
5
|
+
|
6
|
+
it "should build from factory", =>
|
7
|
+
expect(@<%= collection_name %>).toBeA(<%= [namespace('classify'), "Collections", collection_name('classify')].compact.join('.') %>)
|
8
|
+
expect(@<%= collection_name %>.at(0)).toBeA(<%= [namespace('classify'), "Models", model_name('classify')].compact.join('.') %>)
|
File without changes
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# ====================================================
|
2
|
+
# = Model =
|
3
|
+
# ====================================================
|
4
|
+
BackboneFactory.define '<%= model_name %>', <%= "#{namespace('classify')}.Models.#{model_name('classify')}" %>, ->
|
5
|
+
# title: 'Your Title Here'
|
6
|
+
# description: 'string, function, or another Factory'
|
7
|
+
# size: _(['Tall', 'Grande', 'Venti', 'Trenta']).shuffle()[0]
|
8
|
+
# section: Factory.section()
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
# =======================================================
|
14
|
+
# = FactoryGirl Interface: =
|
15
|
+
# = Factory.modleName( {overrides:here} ) =
|
16
|
+
# =======================================================
|
17
|
+
window.Factory = (->
|
18
|
+
factories = [{}].concat _(BackboneFactory.factories).keys()
|
19
|
+
_(factories).inject (memo, factory)->
|
20
|
+
memo[factory]= (overrides)-> BackboneFactory.create factory, -> overrides
|
21
|
+
memo
|
22
|
+
)()
|
23
|
+
|
24
|
+
|
25
|
+
<%- if collection_name -%>
|
26
|
+
# ====================================================
|
27
|
+
# = Collection =
|
28
|
+
# ====================================================
|
29
|
+
_(window.Factory).extend({
|
30
|
+
<%= collection_name %>: (overrides)-> new <%= "#{namespace('classify')}.Collections.#{collection_name('classify')}" %> _({
|
31
|
+
models: _([1,2,3]).map -> BackboneFactory.create('<%= model_name %>', ->)
|
32
|
+
}).extend( overrides )
|
33
|
+
|
34
|
+
})
|
35
|
+
<%- end -%>
|
36
|
+
|
37
|
+
|
38
|
+
# ====================================================
|
39
|
+
# = Complex Factories =
|
40
|
+
# ====================================================
|
41
|
+
|
42
|
+
# section_w_section_materials: (overrides)-> Factory.section( _( section_materials: Factory.section_materials().models ).extend(overrides) )
|
43
|
+
# distributor_w_offers: (overrides)-> Factory.distributor( _(offers: Factory.offers().models ).extend(overrides))
|
File without changes
|
@@ -0,0 +1,12 @@
|
|
1
|
+
describe "<%= [namespace('classify'), 'Models'].compact.join('.') %>", ->
|
2
|
+
|
3
|
+
describe "<%= model_name('classify') %>", ->
|
4
|
+
@<%= model_name %> = Factory.<%= model_name %>()
|
5
|
+
|
6
|
+
it "should build from factory", =>
|
7
|
+
expect(@<%= model_name %>).toBeA( <%= [namespace('classify'), "Models", model_name('classify')].compact.join('.') %> )
|
8
|
+
# expect(@<%= model_name %>).toHaveAssociated('examples')
|
9
|
+
|
10
|
+
it "should have better tests", =>
|
11
|
+
# TODO
|
12
|
+
|
File without changes
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
beforeEach ->
|
2
|
+
@addMatchers toBeEmpty: ->
|
3
|
+
_(@actual).isEmpty()
|
4
|
+
|
5
|
+
@addMatchers toBeA: (expeced) ->
|
6
|
+
@actual instanceof expeced
|
7
|
+
|
8
|
+
@addMatchers toBeValid: () ->
|
9
|
+
@actual.isValid()
|
10
|
+
|
11
|
+
# Non-recursive version of toContain()
|
12
|
+
@addMatchers toInclude: (expeced) ->
|
13
|
+
_(@actual).include(expeced)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#= require_tree ../fixtures
|
2
|
+
#= require ../../../vendor/assets/javascripts/testing/sinon-1.4.2
|
3
|
+
|
4
|
+
# FakeHost.respond() to complete request
|
5
|
+
beforeEach ->
|
6
|
+
|
7
|
+
localStorage.clear()
|
8
|
+
window.FakeHost = sinon.fakeServer.create();
|
9
|
+
#window.FakeHost.respondWith("GET", ShopCompare.routes.course_search_path(), [200, { "Content-Type": "application/json" }, JSON.stringify( Fixtures.courses )] )
|
10
|
+
window.FakeHost.respondWith("GET", new RegExp(ShopCompare.routes.section_books_path("[\\d]+$")), [200, { "Content-Type": "application/json" }, JSON.stringify( Fixtures.section )] )
|
11
|
+
window.FakeHost.respondWith("GET", new RegExp(ShopCompare.routes.book_info_path({isbn : "[\\d]+$"})), [200, { "Content-Type": "application/json" }, JSON.stringify( Fixtures.book )] )
|
12
|
+
window.FakeHost.respondWith("GET", ShopCompare.escapeRegExp(ShopCompare.offer_route("REG"), "REG", "[\\d]+"), [200, { "Content-Type": "application/json" }, JSON.stringify( Fixtures.offers )] )
|
13
|
+
# window.FakeHost.respondWith("GET", /\/applications.json/, [200, { "Content-Type": "application/json" }, JSON.stringify( Fixtures.rafter_apps )] )
|
14
|
+
# window.FakeHost.respondWith("GET", new RegExp(ShopCompare.routes.sections_path() + "\\?keywords=[^&]*$"), [200, { "Content-Type": "application/json" }, JSON.stringify( Fixtures.courses )])
|
15
|
+
# window.FakeHost.respondWith("GET", new RegExp(ShopCompare.routes.sections_path()), [200, { "Content-Type": "application/json" }, JSON.stringify( Fixtures.sections )])
|
16
|
+
|
17
|
+
afterEach ->
|
18
|
+
window.FakeHost.restore()
|