rails-js 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7a095e9cfffa3e1d2b2c014a5337274493cd77a
4
- data.tar.gz: e95794d144143f42b1cc83cc919ee619c0d6986e
3
+ metadata.gz: 5b6a2bd81b231a037c5349034fc1e384f31094ad
4
+ data.tar.gz: cf7b16d0c18879372bc366b30d47a917fe212354
5
5
  SHA512:
6
- metadata.gz: 47ced54a87c6dbad5d2b70e8cd08d940bc892204cb04ae184945e053746b93179b43a6e52f471a81458d92fcaff46413372c745b38e8a2cf4c6a0e2f6f73abf8
7
- data.tar.gz: 9caa7c7725d5381a0874a43371ede315b1a45fea9803cfa841e479f234c452435ebaae08c188a263c999af7d8e015385b1a30a6a3ad42c6bd938f3a28e76a3c1
6
+ metadata.gz: 77c8e94fbe93046444942952696d3270cd29a3c713d25dbffbb147acc141dc1a8a1f21e814a6c56805d10dd1f07f24655755456ac9ec43fb7d05a4dba538a4d3
7
+ data.tar.gz: b4fa72e19206f711796a49cc715ec5fdd69b6465b8b1859d2e3a48ccbdadd64d9f39d06f39d0fb06e2d51b1bda057419f8a552a316ef21e9e5fee4d1bd962a5b
data/.gitignore CHANGED
@@ -1,3 +1,6 @@
1
1
  *.gem
2
2
  test/dummy/tmp/
3
3
  test/dummy/log/
4
+ coverage
5
+ .DS_STORE
6
+ test/dummy/db
data/Gemfile.lock CHANGED
@@ -1,33 +1,33 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails-js (0.0.2)
4
+ rails-js (0.0.3)
5
5
  rails (~> 4.1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actionmailer (4.1.1)
11
- actionpack (= 4.1.1)
12
- actionview (= 4.1.1)
13
- mail (~> 2.5.4)
14
- actionpack (4.1.1)
15
- actionview (= 4.1.1)
16
- activesupport (= 4.1.1)
10
+ actionmailer (4.1.6)
11
+ actionpack (= 4.1.6)
12
+ actionview (= 4.1.6)
13
+ mail (~> 2.5, >= 2.5.4)
14
+ actionpack (4.1.6)
15
+ actionview (= 4.1.6)
16
+ activesupport (= 4.1.6)
17
17
  rack (~> 1.5.2)
18
18
  rack-test (~> 0.6.2)
19
- actionview (4.1.1)
20
- activesupport (= 4.1.1)
19
+ actionview (4.1.6)
20
+ activesupport (= 4.1.6)
21
21
  builder (~> 3.1)
22
22
  erubis (~> 2.7.0)
23
- activemodel (4.1.1)
24
- activesupport (= 4.1.1)
23
+ activemodel (4.1.6)
24
+ activesupport (= 4.1.6)
25
25
  builder (~> 3.1)
26
- activerecord (4.1.1)
27
- activemodel (= 4.1.1)
28
- activesupport (= 4.1.1)
26
+ activerecord (4.1.6)
27
+ activemodel (= 4.1.6)
28
+ activesupport (= 4.1.6)
29
29
  arel (~> 5.0.0)
30
- activesupport (4.1.1)
30
+ activesupport (4.1.6)
31
31
  i18n (~> 0.6, >= 0.6.9)
32
32
  json (~> 1.7, >= 1.7.7)
33
33
  minitest (~> 5.1)
@@ -35,51 +35,65 @@ GEM
35
35
  tzinfo (~> 1.1)
36
36
  arel (5.0.1.20140414130214)
37
37
  builder (3.2.2)
38
- capybara (2.2.1)
38
+ capybara (2.4.3)
39
39
  mime-types (>= 1.16)
40
40
  nokogiri (>= 1.3.3)
41
41
  rack (>= 1.0.0)
42
42
  rack-test (>= 0.5.4)
43
43
  xpath (~> 2.0)
44
44
  cliver (0.3.2)
45
+ coveralls (0.7.1)
46
+ multi_json (~> 1.3)
47
+ rest-client
48
+ simplecov (>= 0.7)
49
+ term-ansicolor
50
+ thor
51
+ docile (1.1.5)
45
52
  erubis (2.7.0)
46
53
  hike (1.2.3)
47
54
  i18n (0.6.11)
48
55
  json (1.8.1)
49
- mail (2.5.4)
50
- mime-types (~> 1.16)
51
- treetop (~> 1.4.8)
52
- mime-types (1.25.1)
56
+ mail (2.6.1)
57
+ mime-types (>= 1.16, < 3)
58
+ mime-types (2.4.1)
53
59
  mini_portile (0.6.0)
54
- minitest (5.3.5)
60
+ minitest (5.4.2)
55
61
  multi_json (1.10.1)
56
- nokogiri (1.6.2.1)
62
+ netrc (0.7.7)
63
+ nokogiri (1.6.3.1)
57
64
  mini_portile (= 0.6.0)
58
65
  poltergeist (1.5.1)
59
66
  capybara (~> 2.1)
60
67
  cliver (~> 0.3.1)
61
68
  multi_json (~> 1.0)
62
69
  websocket-driver (>= 0.2.0)
63
- polyglot (0.3.5)
64
70
  rack (1.5.2)
65
71
  rack-test (0.6.2)
66
72
  rack (>= 1.0)
67
- rails (4.1.1)
68
- actionmailer (= 4.1.1)
69
- actionpack (= 4.1.1)
70
- actionview (= 4.1.1)
71
- activemodel (= 4.1.1)
72
- activerecord (= 4.1.1)
73
- activesupport (= 4.1.1)
73
+ rails (4.1.6)
74
+ actionmailer (= 4.1.6)
75
+ actionpack (= 4.1.6)
76
+ actionview (= 4.1.6)
77
+ activemodel (= 4.1.6)
78
+ activerecord (= 4.1.6)
79
+ activesupport (= 4.1.6)
74
80
  bundler (>= 1.3.0, < 2.0)
75
- railties (= 4.1.1)
81
+ railties (= 4.1.6)
76
82
  sprockets-rails (~> 2.0)
77
- railties (4.1.1)
78
- actionpack (= 4.1.1)
79
- activesupport (= 4.1.1)
83
+ railties (4.1.6)
84
+ actionpack (= 4.1.6)
85
+ activesupport (= 4.1.6)
80
86
  rake (>= 0.8.7)
81
87
  thor (>= 0.18.1, < 2.0)
82
88
  rake (10.3.2)
89
+ rest-client (1.7.2)
90
+ mime-types (>= 1.16, < 3.0)
91
+ netrc (~> 0.7)
92
+ simplecov (0.9.1)
93
+ docile (~> 1.1.0)
94
+ multi_json (~> 1.0)
95
+ simplecov-html (~> 0.8.0)
96
+ simplecov-html (0.8.0)
83
97
  sprockets (2.12.2)
84
98
  hike (~> 1.2)
85
99
  multi_json (~> 1.0)
@@ -92,15 +106,15 @@ GEM
92
106
  sqlite3 (1.3.9)
93
107
  teaspoon (0.8.0)
94
108
  railties (>= 3.2.5, < 5)
109
+ term-ansicolor (1.3.0)
110
+ tins (~> 1.0)
95
111
  thor (0.19.1)
96
112
  thread_safe (0.3.4)
97
113
  tilt (1.4.1)
98
- treetop (1.4.15)
99
- polyglot
100
- polyglot (>= 0.3.1)
101
- tzinfo (1.2.1)
114
+ tins (1.3.3)
115
+ tzinfo (1.2.2)
102
116
  thread_safe (~> 0.1)
103
- websocket-driver (0.3.4)
117
+ websocket-driver (0.3.5)
104
118
  xpath (2.0.0)
105
119
  nokogiri (~> 1.3)
106
120
 
@@ -108,6 +122,7 @@ PLATFORMS
108
122
  ruby
109
123
 
110
124
  DEPENDENCIES
125
+ coveralls (~> 0.7)
111
126
  poltergeist (~> 1.5)
112
127
  rails-js!
113
128
  sqlite3 (~> 1.3)
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  rails-js
2
2
  ========
3
+ [![Build Status](https://travis-ci.org/tonekk/rails-js.svg)](https://travis-ci.org/tonekk/rails-js)
4
+ [![Dependency Status](https://gemnasium.com/tonekk/rails-js.svg)](https://gemnasium.com/tonekk/rails-js)
5
+ [![Gem Version](http://img.shields.io/gem/v/rails-js.svg)](https://rubygems.org/gems/rails-js)
6
+ [![License](http://img.shields.io/:license-mit-blue.svg)](http://tonekk.mit-license.org)
3
7
 
4
8
  I worked on several Rails projects and there were many cases when it felt overkill to use a framework like ``Angular`` or ``Ember``, because javascript was only needed in some parts of the application.
5
9
  But by not using these frameworks I had to think of a way to *structure* the code by myself.
data/Rakefile CHANGED
@@ -15,5 +15,11 @@ Rake::TestTask.new(:test) do |t|
15
15
  t.verbose = false
16
16
  end
17
17
 
18
+ # teaspoon must be executed inside the dummy rails app
19
+ task :teaspoon do
20
+ Dir.chdir('test/dummy/')
21
+ sh 'bundle exec rake teaspoon'
22
+ end
18
23
 
24
+ # add teaspoon to default tasks
19
25
  task default: :test
@@ -7,25 +7,38 @@
7
7
  var controllers = {},
8
8
  globalHelpers = {},
9
9
  namespaceHooks = {},
10
- data = {};
10
+ data = {},
11
+ beforeAll = null;
11
12
 
12
13
  /*
13
14
  * Singleton that stores functions to create your apps' structure
14
15
  */
15
16
  Rails = window.Rails || {};
16
17
 
18
+ /*
19
+ * For testing. We want to start each test with emtpiness.
20
+ */
21
+ Rails.clear = function() {
22
+ controllers = {};
23
+ globalHelpers = {};
24
+ namespaceHooks = {};
25
+ data = {};
26
+ beforeAll = null;
27
+ };
28
+
17
29
  /*
18
30
  * Creates a Rails application (the javascript part!)
19
31
  *
20
32
  * Pass global helper and initial data as params
21
33
  */
22
- Rails.app = function(helpers, initialData, beforeAll) {
34
+ Rails.app = function(helpers, initialData, beforeHook) {
23
35
 
24
36
  /*
25
37
  * Store everything in our local variables
26
38
  */
27
39
  globalHelpers = helpers;
28
40
  data = initialData;
41
+ beforeAll = beforeHook;
29
42
 
30
43
  /*
31
44
  * Set event listener to execute controllers' javascript
@@ -40,13 +53,6 @@
40
53
  return;
41
54
  }
42
55
 
43
- /*
44
- * Also execute beforeAll() hook if defined
45
- */
46
- if(beforeAll && typeof(beforeAll) == 'function') {
47
- beforeAll();
48
- }
49
-
50
56
  Rails.execute();
51
57
  });
52
58
  };
@@ -100,6 +106,13 @@
100
106
  namespaceHook,
101
107
  controllerName = this.config.controller;
102
108
 
109
+ /*
110
+ * Execute beforeAll() hook if defined
111
+ */
112
+ if(beforeAll && typeof(beforeAll) == 'function') {
113
+ beforeAll();
114
+ }
115
+
103
116
  /*
104
117
  * Take care of namespace (e.g. admin/users)
105
118
  */
@@ -1,5 +1,5 @@
1
1
  module Rails
2
2
  module JS
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
data/rails-js.gemspec CHANGED
@@ -20,4 +20,5 @@ Gem::Specification.new do |s|
20
20
  s.add_development_dependency "sqlite3", "~> 1.3"
21
21
  s.add_development_dependency "teaspoon", "~> 0.8"
22
22
  s.add_development_dependency "poltergeist", "~> 1.5"
23
+ s.add_development_dependency "coveralls", "~> 0.7"
23
24
  end
@@ -0,0 +1,3 @@
1
+ Rails.application.config.assets.precompile += %w( teaspoon.css )
2
+ Rails.application.config.assets.precompile += %w( jasmine/1.3.1.js )
3
+ Rails.application.config.assets.precompile += %w( teaspoon-jasmine.js )
@@ -0,0 +1,165 @@
1
+
2
+ /*
3
+ * Test for rails.js
4
+ *
5
+ * For more information see rails.js itself
6
+ */
7
+
8
+ (function() {
9
+ describe('rails-js', function() {
10
+
11
+ /*
12
+ * define all functions spied on
13
+ */
14
+ var spies = { beforeAll: function() {},
15
+ namespaceHook: function() {},
16
+ usersIndex: function() {},
17
+ entitiesNew: function() {},
18
+ adminUsersIndex: function() {},
19
+ aHelper: function() {}
20
+ };
21
+
22
+ beforeEach(function() {
23
+
24
+ // Set config normally set by view_helper
25
+ Rails.config = {
26
+ controller: 'users',
27
+ action: 'index'
28
+ };
29
+
30
+
31
+ /*
32
+ * Clean up
33
+ */
34
+ Rails.clear();
35
+
36
+ spyOn(spies, 'beforeAll');
37
+ spyOn(spies, 'namespaceHook');
38
+ spyOn(spies, 'usersIndex');
39
+ spyOn(spies, 'entitiesNew');
40
+ spyOn(spies, 'adminUsersIndex');
41
+ spyOn(spies, 'aHelper');
42
+
43
+ /*
44
+ * Create an app
45
+ */
46
+ Rails.app({
47
+ // global helpers
48
+ answer: function() {
49
+ return 42
50
+ }
51
+ }, {
52
+ // initial data
53
+ foo: 'bar'
54
+ }, spies.beforeAll);
55
+
56
+ /*
57
+ * Create a controller
58
+ */
59
+ Rails.controller('users', {
60
+ index: spies.usersIndex,
61
+ new: function(h) {
62
+ // execute helper
63
+ h.aHelper();
64
+ }
65
+ }, {
66
+ aHelper: spies.aHelper
67
+ });
68
+ });
69
+
70
+ it('must be defined', function() {
71
+ expect(Rails).toBeDefined();
72
+ expect(R).toBeDefined();
73
+ });
74
+
75
+ it('must handle global variables', function() {
76
+ R('a.global.variable', 'foo');
77
+
78
+ expect(R('a')).toBeDefined();
79
+ expect(R('a.global')).toBeDefined();
80
+ expect(R('a.global.variable')).toBe('foo');
81
+ });
82
+
83
+ it('must be able to execute global helpers', function() {
84
+ expect(R.global('answer')).toBe(42);
85
+ });
86
+
87
+ it('must be able to read initial data', function() {
88
+ expect(R('foo')).toBe('bar');
89
+ });
90
+
91
+ it('must execute beforeAll hook', function() {
92
+ Rails.execute();
93
+ expect(spies.beforeAll).toHaveBeenCalled();
94
+ });
95
+
96
+ it('must execute right controller action', function() {
97
+ Rails.execute();
98
+ expect(spies.usersIndex).toHaveBeenCalled();
99
+
100
+ // Change action to users#new
101
+ Rails.config.action = 'new';
102
+
103
+ // A helper must be called from within users#new
104
+ Rails.execute();
105
+ expect(spies.aHelper).toHaveBeenCalled();
106
+
107
+ // Create entities controller
108
+ Rails.controller('entities', { new: spies.entitiesNew });
109
+ // Change controller to entities#new
110
+ Rails.config.controller = 'entities';
111
+
112
+ Rails.execute();
113
+ expect(spies.entitiesNew).toHaveBeenCalled();
114
+ });
115
+
116
+ it('must handle controller with same name but different namespace', function() {
117
+ Rails.controller('admin/users', {
118
+ index: spies.adminUsersIndex
119
+ });
120
+
121
+ Rails.config.namespace = 'admin';
122
+ Rails.execute();
123
+ expect(spies.adminUsersIndex).toHaveBeenCalled();
124
+ expect(spies.usersIndex).not.toHaveBeenCalled();
125
+ });
126
+
127
+ it('must execute foreign helper', function() {
128
+ Rails.controller('admin/users', {
129
+ index: function() {
130
+ R.helper('users', 'aHelper');
131
+ }
132
+ });
133
+
134
+ Rails.config.namespace = 'admin';
135
+ Rails.execute();
136
+ expect(spies.aHelper).toHaveBeenCalled();
137
+ });
138
+
139
+ it('must execute foreign action', function() {
140
+ Rails.controller('admin/users', {
141
+ index: function() {
142
+ R.action('users#index');
143
+ }
144
+ });
145
+
146
+ Rails.config.namespace = 'admin';
147
+ Rails.execute();
148
+ expect(spies.usersIndex).toHaveBeenCalled();
149
+ });
150
+
151
+ it('must execute namespace hook when in namespace', function() {
152
+ // Define namespace with hook
153
+ Rails.namespace('admin', spies.namespaceHook);
154
+
155
+ // First without namespace
156
+ Rails.execute();
157
+ expect(spies.namespaceHook).not.toHaveBeenCalled();
158
+
159
+ // Now with namespace
160
+ Rails.config.namespace = 'admin';
161
+ Rails.execute();
162
+ expect(spies.namespaceHook).toHaveBeenCalled();
163
+ });
164
+ });
165
+ })();
@@ -0,0 +1,31 @@
1
+ // Teaspoon includes some support files, but you can use anything from your own support path too.
2
+ // require support/jasmine-jquery-1.7.0
3
+ // require support/jasmine-jquery-2.0.0
4
+ // require support/sinon
5
+ // require support/your-support-file
6
+ //
7
+ // PhantomJS (Teaspoons default driver) doesn't have support for Function.prototype.bind, which has caused confusion.
8
+ // Use this polyfill to avoid the confusion.
9
+ //= require support/bind-poly
10
+ //
11
+ // Deferring execution
12
+ // If you're using CommonJS, RequireJS or some other asynchronous library you can defer execution. Call
13
+ // Teaspoon.execute() after everything has been loaded. Simple example of a timeout:
14
+ //
15
+ // Teaspoon.defer = true
16
+ // setTimeout(Teaspoon.execute, 1000)
17
+ //
18
+ // Matching files
19
+ // By default Teaspoon will look for files that match _spec.{js,js.coffee,.coffee}. Add a filename_spec.js file in your
20
+ // spec path and it'll be included in the default suite automatically. If you want to customize suites, check out the
21
+ // configuration in config/initializers/teaspoon.rb
22
+ //
23
+ // Manifest
24
+ // If you'd rather require your spec files manually (to control order for instance) you can disable the suite matcher in
25
+ // the configuration and use this file as a manifest.
26
+ //
27
+ // For more information: http://github.com/modeset/teaspoon
28
+ //
29
+ // You can require your own javascript files here. By default this will include everything in application, however you
30
+ // may get better load performance if you require the specific files that are being used in the spec that tests them.
31
+ //= require application
@@ -0,0 +1,13 @@
1
+ # Set RAILS_ROOT and load the environment if it's not already loaded.
2
+ unless defined?(Rails)
3
+ ENV["RAILS_ROOT"] = File.expand_path("../../", __FILE__)
4
+ require File.expand_path("../../config/environment", __FILE__)
5
+ end
6
+
7
+ Teaspoon.configure do |config|
8
+
9
+ config.suite do |suite|
10
+ suite.use_framework :jasmine, "1.3.1"
11
+ suite.matcher = "{spec/javascripts,app/assets}/**/*_spec.{js,js.coffee,coffee}"
12
+ end
13
+ end
data/test/test_helper.rb CHANGED
@@ -3,6 +3,9 @@ ENV["RAILS_ENV"] = "test"
3
3
 
4
4
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
5
  require "rails/test_help"
6
+ require "coveralls"
7
+
8
+ Coveralls.wear!
6
9
 
7
10
  Rails.backtrace_cleaner.remove_silencers!
8
11
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-js
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Finn-Lenanrt Heemeyer
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.7'
69
83
  description: Divide your javascript like you divide your ruby code. Put it in controllers
70
84
  and actions and write clean, scalable code.
71
85
  email: finn@heemeyer.net
@@ -113,6 +127,7 @@ files:
113
127
  - test/dummy/config/environments/development.rb
114
128
  - test/dummy/config/environments/production.rb
115
129
  - test/dummy/config/environments/test.rb
130
+ - test/dummy/config/initializers/assets.rb
116
131
  - test/dummy/config/initializers/backtrace_silencers.rb
117
132
  - test/dummy/config/initializers/cookies_serializer.rb
118
133
  - test/dummy/config/initializers/filter_parameter_logging.rb
@@ -129,6 +144,9 @@ files:
129
144
  - test/dummy/public/422.html
130
145
  - test/dummy/public/500.html
131
146
  - test/dummy/public/favicon.ico
147
+ - test/dummy/spec/javascripts/rails-js_spec.js
148
+ - test/dummy/spec/javascripts/spec_helper.js
149
+ - test/dummy/spec/teaspoon_env.rb
132
150
  - test/dummy/test/helpers/testing_helper_test.rb
133
151
  - test/teaspoon_env.rb
134
152
  - test/test_helper.rb