angular_velocity 0.0.3alpha → 0.0.4alpha

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/README.md CHANGED
@@ -18,11 +18,89 @@ Or install it yourself as:
18
18
 
19
19
 
20
20
  ## Usage
21
- ```
22
- rails g angular_velocity:install -f
23
- rm public/index.html
24
21
 
25
- ```
22
+
23
+ $ rails g angular_velocity:install -f
24
+ $ rm public/index.html
25
+
26
26
 
27
27
  File are created under app/assets/javascripts/<application_name>/
28
- And jasmine specs are created under spec/javascripts/<application_name>/
28
+ And jasmine specs are created under spec/javascripts/<application_name>/
29
+
30
+ ## Commands
31
+
32
+
33
+ $ rails g angular_velocity:install
34
+
35
+ This command installs Angular and Jasmine into your Rails project. You can confirm Angular
36
+ is installed by going to: http://localhost:3000/. Also, you can confirm jasmine is installed by
37
+ going to: http://localhost:3000/specs
38
+
39
+ The directory structure created will resemble:
40
+ --app<br/>
41
+ ---assets<br/>
42
+ ----javascripts<br/>
43
+ -----<--AppName--><br/>
44
+ --------views<br/>
45
+ --------controllers<br/>
46
+ --------services<br/>
47
+ --spec<br/>
48
+ ---javascripts<br/>
49
+ ----controllers<br/>
50
+ ----services<br/>
51
+
52
+
53
+ $ rails g angular_velocity:contoller <resource_name>
54
+
55
+ This command creates a contoller template for angular along with the spec for testing. The controller is place in:
56
+
57
+ --app<br/>
58
+ ---assets<br/>
59
+ ----javascripts<br/>
60
+ -----<--AppName--><br/>
61
+ --------controllers<br/>
62
+ --spec<br/>
63
+ ---javascripts<br/>
64
+ ----controllers<br/>
65
+
66
+
67
+ $ rails g angular_velocity:service <resource_name>
68
+
69
+ This command creates a service template for angular along with the spec for testing. The service is place in:
70
+
71
+ --app<br/>
72
+ ---assets<br/>
73
+ ----javascripts<br/>
74
+ -----<--AppName--><br/>
75
+ --------services<br/>
76
+ --spec<br/>
77
+ ---javascripts<br/>
78
+ ----services<br/>
79
+
80
+
81
+
82
+ $ rails g angular_velocity:scaffold <resource_name>
83
+
84
+ This command creates all angular files and jasmine files plus the rails controller and model files for a resource.
85
+
86
+ --app<br/>
87
+ --controllers<br/>
88
+ --- <--RailsController--><br/>
89
+ --models<br/>
90
+ --- <--RailsModel--><br/>
91
+ ---assets<br/>
92
+ ----javascripts<br/>
93
+ -----<--AppName--><br/>
94
+ --------views<br/>
95
+ --------controllers<br/>
96
+ --------services<br/>
97
+ --spec<br/>
98
+ --controllers<br/>
99
+ --- <--RailsControllerSpec--><br/>
100
+ --models<br/>
101
+ --- <--RailsModelSpec--><br/>
102
+ ---javascripts<br/>
103
+ ----controllers<br/>
104
+ ----services<br/>
105
+
106
+
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["alan.lee.pies@gmail.com","shayne.defazio@move.com"]
11
11
  spec.description = %q{Setup new rails projects for angular/jasmine, includes generators for angular MVC files.}
12
12
  spec.summary = %q{angular/jasmine seed for rails}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/apies/AngularVelocity"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = (`git ls-files`.split($/)).select { |file_name| !file_name.include?("tmp") }
@@ -23,5 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency "bundler", "~> 1.3"
24
24
  spec.add_dependency "rake"
25
25
  spec.add_dependency "rspec"
26
- spec.add_dependency "jasmine-rails"
26
+ spec.add_dependency "jasmine-rails", "=0.3.3"
27
27
  end
@@ -1,3 +1,3 @@
1
1
  module AngularVelocity
2
- VERSION = "0.0.3alpha"
2
+ VERSION = "0.0.4alpha"
3
3
  end
@@ -11,11 +11,21 @@ module AngularVelocity
11
11
  end
12
12
 
13
13
  def angular_path
14
- "app/assets/javascripts/#{application_name}"
14
+ path = ""
15
+ if Rails.env == "test"
16
+ path = "spec/tmp/app/assets/javascripts/#{application_name}"
17
+ else
18
+ path = "app/assets/javascripts/#{application_name}"
19
+ end
20
+ path
15
21
  end
16
22
 
17
23
  def angular_spec_path
18
- "spec/javascripts/#{application_name}"
24
+ if Rails.env == "test"
25
+ "spec/tmp/spec/javascripts/#{application_name}"
26
+ else
27
+ "spec/javascripts/#{application_name}"
28
+ end
19
29
  end
20
30
 
21
31
  end
@@ -14,6 +14,10 @@ module AngularVelocity
14
14
  template "controller.coffee", "#{angular_path}/controllers/#{file_name}_controller.coffee"
15
15
  end
16
16
 
17
+ def create_angular_controller_spec
18
+ template "controller_spec.coffee", "#{angular_spec_path}/controllers/#{file_name}_controller_spec.coffee"
19
+ end
20
+
17
21
 
18
22
  end
19
23
 
@@ -0,0 +1,19 @@
1
+ describe "Controller: <%= file_name.camelize %>Ctrl", () ->
2
+
3
+ <%= file_name.camelize %>Ctrl = {}
4
+ scope = {}
5
+
6
+ beforeEach(module('<%= application_name.camelize %>'))
7
+ <%= file_name.camelize %>Ctrl = {}
8
+ scope = {}
9
+ beforeEach(inject( ($rootScope, $controller) ->
10
+
11
+ scope = $rootScope.$new()
12
+ <%= file_name.camelize %>Ctrl = $controller( '<%= file_name.camelize %>Ctrl', {
13
+ $scope: scope
14
+ })
15
+
16
+ ))
17
+
18
+ it "should attach a list of awesomeThings to the scope", () ->
19
+ expect(scope.awesomeThings.length).toBe(3)
@@ -0,0 +1,32 @@
1
+ require 'generators/angular_velocity/angular_config'
2
+ require "generators/angular_velocity/controller/controller_generator"
3
+
4
+ #Rails.root.join('public','images','logo.png')
5
+
6
+ module AngularVelocity
7
+ module Generators
8
+
9
+ class ScaffoldGenerator < Rails::Generators::NamedBase
10
+
11
+ include AngularVelocity::Generators::AngularConfig
12
+ source_root File.expand_path('../../controller/templates', __FILE__)
13
+ desc "This generator creates an angular service"
14
+
15
+ def run_rails_generators
16
+ pp "2"
17
+ Rails::Generators.invoke("controller", [file_name])
18
+ Rails::Generators.invoke("model", [file_name])
19
+ end
20
+
21
+ def run_angular_generators
22
+ pp "2"
23
+ Rails::Generators.invoke("angular_velocity:controller", [file_name])
24
+ Rails::Generators.invoke("angular_velocity:service", [file_name])
25
+ end
26
+
27
+
28
+
29
+
30
+ end
31
+ end
32
+ end
@@ -13,6 +13,10 @@ module AngularVelocity
13
13
  def create_angular_service
14
14
  template "service.coffee", "#{angular_path}/services/#{file_name}_service.coffee"
15
15
  end
16
+
17
+ def create_angular_service_spec
18
+ template "service_spec.coffee", "#{angular_spec_path}/services/#{file_name}_service_spec.coffee"
19
+ end
16
20
 
17
21
  end
18
22
 
@@ -1,8 +1,21 @@
1
- angular.module('<%= application_name %>Service', []).factory( '<%=file_name.camelize %>', [ '$scope','$http',
1
+ angular.module('<%= application_name %>Service', []).factory( '<%= file_name.camelize %>', [ '$http', ($http, $scope) ->
2
2
  class <%=file_name.camelize %>
3
3
  constructor: (data) ->
4
4
  @instantiate(data)
5
5
  instantiate: (data) ->
6
6
  @attributes = data
7
- angular.extend(@, data)
7
+ angular.extend(@, data)
8
+ @all: () ->
9
+ <%=file_name.pluralize %> = []
10
+ $http.get("api/<%= file_name.pluralize %>").then( (response) ->
11
+ <%=file_name.pluralize %>.push new <%=file_name.camelize %>(params) for params in response.data
12
+ )
13
+ <%=file_name.pluralize %>
14
+ @find: (<%=file_name %>Id) ->
15
+ <%=file_name%> = new <%=file_name.camelize %>
16
+ $http.get('api/<%= file_name.pluralize %>/<%=file_name %>Id').then( (response)->
17
+ <%=file_name%>.instantiate(response.data)
18
+ )
19
+ <%=file_name%>
20
+
8
21
  ])
@@ -0,0 +1,39 @@
1
+ describe "Service: <%= file_name.camelize %>", () ->
2
+
3
+ <%= file_name.camelize %> = {}
4
+ scope = {}
5
+ $httpBackend = {}
6
+
7
+ beforeEach(module('<%= application_name %>Service'))
8
+ <%= file_name.camelize %> = {}
9
+ scope = {}
10
+ beforeEach(inject( ( _$httpBackend_, $rootScope, _<%= file_name.camelize %>_ ) ->
11
+ $httpBackend = _$httpBackend_
12
+ $httpBackend.whenGET('api/<%= file_name.pluralize %>').respond([{content:"msg1"}, {content: "ms2"}])
13
+
14
+ scope = $rootScope.$new()
15
+ <%= file_name.camelize %> = _<%= file_name.camelize %>_
16
+
17
+ ))
18
+
19
+
20
+ it 'should be able to make a new instance of itself when it already has data', () ->
21
+ <%= file_name %> = new <%= file_name.camelize %>(name: 'Quiet Like Horses')
22
+ expect(<%= file_name %>.name).toBe('Quiet Like Horses')
23
+
24
+ it 'should give itself Picture attributes with instantiate for use with promises', () ->
25
+
26
+ <%= file_name %> = new <%= file_name.camelize %>
27
+ <%= file_name %>.instantiate(name: 'Quiet Like Horses')
28
+ expect(<%= file_name %>.name).toBe('Quiet Like Horses')
29
+ it "should be a base for more specific <%= file_name.pluralize %>", () ->
30
+ class <%= file_name.camelize %>Thing extends <%= file_name.camelize %>
31
+ thing: 'thing'
32
+ <%= file_name %>_thing = new <%= file_name.camelize %>Thing
33
+ <%= file_name %>_thing.instantiate(name: 'Alan Pies', age: 28)
34
+ expect(<%= file_name %>_thing.name).toBe('Alan Pies')
35
+ it 'should be able to fetch my blogger pictures from a rest api', () ->
36
+ <%= file_name.pluralize %> = <%= file_name.camelize %>.all()
37
+ $httpBackend.flush()
38
+ expect(<%= file_name.pluralize %>.length).toBe(2)
39
+
@@ -6,20 +6,27 @@ describe AngularVelocity::Generators::ControllerGenerator do
6
6
 
7
7
  include GeneratorSpec::TestCase
8
8
  include GenSpecHelpers
9
- include AngularVelocity::Generators::AngularConfig
9
+ include AngularVelocity::Generators::AngularConfig
10
10
 
11
11
  destination File.expand_path("../../tmp", __FILE__)
12
12
 
13
- before(:each) {prepare_destination}
13
+ before(:each) do
14
+ prepare_destination
15
+ run_generator ["post"]
16
+ end
14
17
 
15
18
  let(:angular_test_app_path) { "spec/tmp/#{angular_path}" }
19
+ let(:angular_test_app_spec_path) { "spec/tmp/#{angular_spec_path}" }
16
20
 
17
21
 
18
- it "should generator a controller" do
19
- run_generator ["post"]
20
- file_should_exist("#{angular_test_app_path}/controllers/post_controller.coffee")
22
+ it "should generate a controller" do
21
23
  ("#{angular_test_app_path}/controllers/post_controller.coffee").should be_a_file_containing_text(%{angular.module('AngularVelocityApp').controller( 'PostCtrl', [ '$scope', PostController ])})
22
24
  end
23
25
 
26
+ it "should generate a post controller spec" do
27
+ controller_spec_path = "#{angular_test_app_spec_path}/controllers/post_controller_spec.coffee"
28
+ controller_spec_path.should be_a_file_containing_text(%{describe "Controller: PostCtrl", () ->})
29
+ end
30
+
24
31
 
25
32
  end
@@ -0,0 +1,53 @@
1
+ require "spec_helper"
2
+ require "generators/angular_velocity/scaffold/scaffold_generator"
3
+ require "generators/angular_velocity/controller/controller_generator"
4
+
5
+ describe AngularVelocity::Generators::ScaffoldGenerator do
6
+ include GeneratorSpec::TestCase
7
+ include GenSpecHelpers
8
+ include AngularVelocity::Generators::AngularConfig
9
+
10
+ destination File.expand_path("../../tmp", __FILE__)
11
+
12
+
13
+
14
+ context "Angular Components" do
15
+
16
+ before(:each) do
17
+ prepare_destination
18
+ create_fixtures
19
+ @resource_name = "scaffold_test"
20
+ run_generator [@resource_name]
21
+ @angular_test_app_path = "#{angular_path}"
22
+ @test_app_path = "spec/tmp/app"
23
+ @angular_spec_path = "#{angular_spec_path}"
24
+ end
25
+
26
+ it "should generate a controller" do
27
+ ("#{@angular_test_app_path}/controllers/#{@resource_name}_controller.coffee").should be_a_file_containing_text(%{angular.module('AngularVelocityApp').controller( '#{@resource_name.camelize}Ctrl', [ '$scope', #{@resource_name.camelize}Controller ])})
28
+ file_should_exist("#{@angular_spec_path}/controllers/#{@resource_name}_controller_spec.coffee")
29
+ end
30
+
31
+ it "should generate a service" do
32
+ file_should_exist "#{@angular_spec_path}/services/#{@resource_name}_service_spec.coffee"
33
+ ("#{@angular_test_app_path}/services/#{@resource_name}_service.coffee").should be_a_file_containing_text(%{ class #{@resource_name.camelize}})
34
+ end
35
+ end
36
+
37
+ context "Rails Components" do
38
+ let(:resource_name) {"scaffold_test"}
39
+
40
+ it "should create a controller and a model" do
41
+ Rails::Generators.should_receive(:invoke).with("controller", ["scaffold_test"]).once
42
+ Rails::Generators.should_receive(:invoke).with("angular_velocity:controller", ["scaffold_test"]).once
43
+ Rails::Generators.should_receive(:invoke).with("angular_velocity:service", ["scaffold_test"]).once
44
+ Rails::Generators.should_receive(:invoke).with("model", ["scaffold_test"]).once
45
+ run_generator [resource_name]
46
+ end
47
+
48
+
49
+ end
50
+
51
+
52
+
53
+ end
@@ -10,15 +10,25 @@ describe AngularVelocity::Generators::ServiceGenerator do
10
10
 
11
11
  destination File.expand_path("../../tmp", __FILE__)
12
12
 
13
- before(:each) {prepare_destination}
13
+ before(:each) do
14
+ prepare_destination
15
+ run_generator ["post"]
16
+ end
14
17
 
15
18
  let(:angular_test_app_path) { "spec/tmp/#{angular_path}" }
19
+ let(:angular_test_app_spec_path) { "spec/tmp/#{angular_spec_path}" }
16
20
 
17
21
 
18
- it "should generator a controller" do
19
- run_generator ["post"]
22
+ it "should generator a post service" do
23
+
20
24
  ("#{angular_test_app_path}/services/post_service.coffee").should be_a_file_containing_text(%{ class Post})
21
25
  end
22
26
 
27
+
28
+ it "should generate a post service spec" do
29
+ service_spec_path = "#{angular_test_app_spec_path}/services/post_service_spec.coffee"
30
+ service_spec_path.should be_a_file_containing_text(%{describe "Service: Post", () ->})
31
+ end
32
+
23
33
 
24
34
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,11 @@
1
+ ENV["RAILS_ENV"] = 'test'
2
+
1
3
  require 'rails/all'
2
4
  require 'rspec-rails'
3
5
  #require 'rails/generators/test_case'
4
6
  require "generator_spec/test_case"
7
+ require 'generators/angular_velocity/angular_config'
8
+
5
9
  Dir["./spec/support/*.rb"].each {|f| require f}
6
10
 
7
11
  module AngularVelocity
@@ -10,12 +14,13 @@ module AngularVelocity
10
14
  end
11
15
 
12
16
 
13
- module GenSpecHelpers
17
+ module GenSpecHelpers
14
18
 
15
19
  def create_fixtures
16
20
  Dir.mkdir("spec/tmp/config") unless Dir.entries("spec/tmp/").include?("config")
17
- FileUtils.mkdir_p('spec/tmp/app/assets/javascripts/') unless Dir.entries("spec/tmp/").include?("app")
21
+ FileUtils.mkdir_p('spec/tmp/app/assets/javascripts/') #unless Dir.entries("spec/tmp/").include?("AngularVelocityApp")
18
22
  File.open('spec/tmp/app/assets/javascripts/application.js', 'w') do |f|
23
+ pp "IN create_fixtures"
19
24
  f.puts "//= require jquery"
20
25
  f.puts "//= require jquery_ujs"
21
26
  f.puts "//= require_tree ."
@@ -24,6 +29,7 @@ module GenSpecHelpers
24
29
  f.puts "Gui::Application.routes.draw do"
25
30
  f.puts "end"
26
31
  end
32
+ FileUtils.mkdir_p("#{angular_path}/controllers")
27
33
  end
28
34
 
29
35
  def file_should_exist(file_string)
@@ -5,6 +5,7 @@ RSpec::Matchers.define :be_a_file_containing_text do |expected_file_text|
5
5
 
6
6
 
7
7
  match do |file_path|
8
+ @expected_file_text = expected_file_text
8
9
  if is_a_file(file_path)
9
10
  File.readlines(file_path).any? {|line| line.include?(expected_file_text)}
10
11
  else
@@ -35,7 +36,7 @@ RSpec::Matchers.define :be_a_file_containing_text do |expected_file_text|
35
36
  "something strange going on here, you didnt pass a file_path"
36
37
  else
37
38
  "expected that the file #{file_path}
38
- would contain text #{expected_file_text}"
39
+ would contain text #{@expected_file_text}"
39
40
  end
40
41
  end
41
42
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: angular_velocity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3alpha
4
+ version: 0.0.4alpha
5
5
  prerelease: 5
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-09 00:00:00.000000000 Z
13
+ date: 2013-04-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -65,17 +65,17 @@ dependencies:
65
65
  requirement: !ruby/object:Gem::Requirement
66
66
  none: false
67
67
  requirements:
68
- - - ! '>='
68
+ - - '='
69
69
  - !ruby/object:Gem::Version
70
- version: '0'
70
+ version: 0.3.3
71
71
  type: :runtime
72
72
  prerelease: false
73
73
  version_requirements: !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
- - - ! '>='
76
+ - - '='
77
77
  - !ruby/object:Gem::Version
78
- version: '0'
78
+ version: 0.3.3
79
79
  description: Setup new rails projects for angular/jasmine, includes generators for
80
80
  angular MVC files.
81
81
  email:
@@ -97,6 +97,7 @@ files:
97
97
  - lib/generators/angular_velocity/angular_config.rb
98
98
  - lib/generators/angular_velocity/controller/controller_generator.rb
99
99
  - lib/generators/angular_velocity/controller/templates/controller.coffee
100
+ - lib/generators/angular_velocity/controller/templates/controller_spec.coffee
100
101
  - lib/generators/angular_velocity/install/install_generator.rb
101
102
  - lib/generators/angular_velocity/install/templates/AppLoader.js
102
103
  - lib/generators/angular_velocity/install/templates/angular-cookies.js
@@ -114,14 +115,17 @@ files:
114
115
  - lib/generators/angular_velocity/install/templates/main_controller.rb
115
116
  - lib/generators/angular_velocity/install/templates/main_controller_spec.coffee
116
117
  - lib/generators/angular_velocity/install/templates/templates_controller.rb
118
+ - lib/generators/angular_velocity/scaffold/scaffold_generator.rb
117
119
  - lib/generators/angular_velocity/service/service_generator.rb
118
120
  - lib/generators/angular_velocity/service/templates/service.coffee
121
+ - lib/generators/angular_velocity/service/templates/service_spec.coffee
119
122
  - spec/controller/controller_generator_spec.rb
120
123
  - spec/install/install_generator_spec.rb
124
+ - spec/scaffold/scaffold_generator_spec.rb
121
125
  - spec/service/service_generator_spec.rb
122
126
  - spec/spec_helper.rb
123
127
  - spec/support/generator_matcher.rb
124
- homepage: ''
128
+ homepage: https://github.com/apies/AngularVelocity
125
129
  licenses:
126
130
  - MIT
127
131
  post_install_message:
@@ -149,6 +153,7 @@ summary: angular/jasmine seed for rails
149
153
  test_files:
150
154
  - spec/controller/controller_generator_spec.rb
151
155
  - spec/install/install_generator_spec.rb
156
+ - spec/scaffold/scaffold_generator_spec.rb
152
157
  - spec/service/service_generator_spec.rb
153
158
  - spec/spec_helper.rb
154
159
  - spec/support/generator_matcher.rb