eyeballs 0.5.12.1 → 0.5.13

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -27,7 +27,7 @@ begin
27
27
  require 'jeweler'
28
28
  Jeweler::Tasks.new do |s|
29
29
  s.name = "eyeballs"
30
- s.version = "0.5.12.1"
30
+ s.version = "0.5.13"
31
31
  s.author = "Paul Campbell"
32
32
  s.email = "paul@rslw.com"
33
33
  s.homepage = "http://www.github.com/paulca/eyeballs.js"
data/app.rb CHANGED
@@ -3,6 +3,15 @@ require 'sinatra'
3
3
  set :static, true
4
4
  set :public, Proc.new { File.expand_path('.') }
5
5
 
6
+ get '/tests.js' do
7
+ content_type 'application/javascript'
8
+ files = []
9
+ Dir["#{File.join(File.expand_path('.'), 'test', 'unit')}/*.html"].each do |file|
10
+ files << "'#{File.basename(file)}'"
11
+ end
12
+ "var test_files = [#{files.join(',')}];"
13
+ end
14
+
6
15
  get '/reviews' do
7
16
  '[{"id": "1", "title":"Local, baby"}]'
8
17
  end
@@ -40,12 +49,21 @@ end
40
49
 
41
50
  post '/rails_reviews' do
42
51
  if params[:rails_review]
43
- 'ok'
52
+ '{"rails_review": {"id":"1"}}'
44
53
  else
45
54
  'fail'
46
55
  end
47
56
  end
48
57
 
58
+ get '/rails_reviews/1' do
59
+ '{"rails_review": {"id":"1"}}'
60
+ end
61
+
62
+ get '/alternate_rails_reviews/1' do
63
+ '{"alternate_rails_review": {"id":"1"}}'
64
+ end
65
+
66
+
49
67
  post '/alternate_rails_reviews' do
50
68
  if params[:alternate_object]
51
69
  'ok'
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{eyeballs}
8
- s.version = "0.5.12.1"
8
+ s.version = "0.5.13"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Paul Campbell"]
12
- s.date = %q{2010-11-07}
12
+ s.date = %q{2010-12-01}
13
13
  s.default_executable = %q{eyeballs}
14
14
  s.email = %q{paul@rslw.com}
15
15
  s.executables = ["eyeballs"]
@@ -57,9 +57,10 @@ Gem::Specification.new do |s|
57
57
  "templates/scaffold_edit.html.mustache",
58
58
  "templates/scaffold_index.html",
59
59
  "templates/scaffold_partial.html.mustache",
60
- "test/index.html",
60
+ "test/run_unit_tests.html",
61
61
  "test/unit/qunit.css",
62
62
  "test/unit/qunit.js",
63
+ "test/unit/run_all.js",
63
64
  "test/unit/test_binding.html",
64
65
  "test/unit/test_controller.html",
65
66
  "test/unit/test_dom.html",
@@ -69,6 +70,7 @@ Gem::Specification.new do |s|
69
70
  "test/unit/test_model_with_callbacks.html",
70
71
  "test/unit/test_params.html",
71
72
  "test/unit/test_rest.html",
73
+ "test/unit/test_rest_global_config.html",
72
74
  "test/unit/test_routing.html"
73
75
  ]
74
76
  s.homepage = %q{http://www.github.com/paulca/eyeballs.js}
@@ -14,7 +14,7 @@ describe Eyeballs::ModelGenerator do
14
14
  end
15
15
 
16
16
  it "should create my file" do
17
- model_file.read.should include("o_O('Paul', function(paul){")
17
+ model_file.read.should include("o_O('Paul', function(){")
18
18
  end
19
19
 
20
20
  after(:all) do
@@ -21,7 +21,7 @@ describe Eyeballs::ModelGenerator do
21
21
  end
22
22
 
23
23
  it "should fill out the model file" do
24
- model_file.read.should include("o_O('Review', function(review){")
24
+ model_file.read.should include("o_O('Review', function(){")
25
25
  end
26
26
 
27
27
  it "should fill out the controller file" do
@@ -1,5 +1,10 @@
1
1
  // REST & Rails, woop!
2
2
  o_O.rest = {
3
+ include_json_root: function(object){
4
+ return !!( o_O.config.include_json_root &&
5
+ window[object.model_name]['include_json_root'] == void(0)) ||
6
+ ( window[object.model_name]['include_json_root'] === true )
7
+ },
3
8
  figure_url: function(original_callback, object){
4
9
  if(typeof original_callback.url === 'string')
5
10
  {
@@ -47,13 +52,24 @@ o_O.rest = {
47
52
  {
48
53
  var object_to_save = {};
49
54
  var url;
55
+ var include_json_root = this.include_json_root(object)
50
56
  for(var i = 0; i < object.attributes.length; i++)
51
57
  {
52
58
  object_to_save[object.attributes[i]] = object[object.attributes[i]];
53
59
  }
54
60
  var respond = function(response){
55
61
  try{
56
- var saved_object = JSON.parse(response);
62
+ if(typeof response === 'string') {
63
+ response = JSON.parse(response);
64
+ }
65
+
66
+ var saved_object = null;
67
+ if(include_json_root) {
68
+ saved_object = response[object.model_name.underscore()];
69
+ } else {
70
+ saved_object = response;
71
+ }
72
+
57
73
  for(var attribute in saved_object)
58
74
  {
59
75
  object_to_save[attribute] = saved_object[attribute];
@@ -70,8 +86,8 @@ o_O.rest = {
70
86
  }
71
87
  }
72
88
  url = this.figure_url(original_callback, object);
73
-
74
- if(window[object.model_name]['include_json_root'] === true)
89
+
90
+ if(this.include_json_root(object))
75
91
  {
76
92
  var object_name;
77
93
  new_object_to_save = {};
@@ -107,6 +123,7 @@ o_O.rest = {
107
123
  find: function(model, id, callback, options)
108
124
  {
109
125
  var url = this.figure_url(options, model) + '/' + id;
126
+ var include_json_root = this.include_json_root(model)
110
127
  $.get(url, function(response){
111
128
  if(typeof response === 'object')
112
129
  {
@@ -116,6 +133,10 @@ o_O.rest = {
116
133
  {
117
134
  try{
118
135
  var retrieved_object = JSON.parse(response);
136
+ if(include_json_root)
137
+ {
138
+ retrieved_object = retrieved_object[model.model_name.underscore()]
139
+ }
119
140
  }
120
141
  catch(e){
121
142
  var retrieved_object = model.initialize({id: id});
@@ -4,6 +4,7 @@
4
4
  o_O.model.adapter = o_O.rest;
5
5
  o_O.config.authenticity_token = $('meta[name=csrf-token]').attr('content')
6
6
  o_O.config.template_path = '/javascripts/app/views';
7
+ o_O.config.include_json_root = true;
7
8
 
8
9
  jQuery.ajaxSetup({
9
10
  'beforeSend': function(xhr) {xhr.setRequestHeader("Accept",
@@ -0,0 +1,9 @@
1
+ <html>
2
+ <head>
3
+ <script src="/tests.js"></script>
4
+ <script>
5
+ console.log(test_files[0] + '#run_all')
6
+ document.location.href = 'unit/' + test_files[0] + '#run_all'
7
+ </script>
8
+ </head>
9
+ </html>
@@ -0,0 +1,17 @@
1
+ var current_test = document.location.pathname.split('/')[document.location.pathname.split('/').length - 1];
2
+ var index = test_files.indexOf(current_test)
3
+
4
+ if(index > -1 && document.location.hash === '#run_all')
5
+ {
6
+ setInterval(next_test_if_complete, 20)
7
+ }
8
+
9
+ function next_test_if_complete(){
10
+ if($('li.pass').length > 0 && $('li.fail').length === 0 && $('p#qunit-testresult'))
11
+ {
12
+ if(test_files[index+1])
13
+ {
14
+ document.location.href = test_files[index+1] + '#run_all'
15
+ }
16
+ }
17
+ }
@@ -5,6 +5,8 @@
5
5
  <script src="../../dist/jquery/jquery-1.4.2.min.js"></script>
6
6
  <script src="../../src/o_O.js"></script>
7
7
  <script src="../../src/modules/o_O.model.js"></script>
8
+ <script src="/tests.js"></script>
9
+ <script src="run_all.js"></script>
8
10
 
9
11
  <link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />
10
12
  <script type="text/javascript" src="qunit.js"></script>
@@ -15,7 +17,7 @@
15
17
 
16
18
  o_O.config.bind_to = MyApp;
17
19
 
18
- o_O('Review');
20
+ o_O('Review', function(){});
19
21
 
20
22
  $(document).ready(function(){
21
23
 
@@ -5,6 +5,9 @@
5
5
  <script src="../../dist/jquery/jquery-1.4.2.min.js"></script>
6
6
  <script src="../../src/o_O.js"></script>
7
7
  <script src="../../src/drivers/jquery/modules/o_O.controller.js"></script>
8
+ <script src="/tests.js"></script>
9
+ <script src="run_all.js"></script>
10
+
8
11
  <link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />
9
12
  <script type="text/javascript" src="qunit.js"></script>
10
13
 
@@ -9,6 +9,9 @@
9
9
  <script src="../../src/drivers/jquery/adapters/o_O.dom.js"></script>
10
10
  <script src="../../src/drivers/jquery/modules/o_O.controller.js"></script>
11
11
  <script src="../../src/drivers/jquery/modules/o_O.support.js"></script>
12
+ <script src="/tests.js"></script>
13
+ <script src="run_all.js"></script>
14
+
12
15
  <link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />
13
16
  <script type="text/javascript" src="qunit.js"></script>
14
17
 
@@ -9,6 +9,9 @@
9
9
  <script src="../../src/drivers/jquery/adapters/o_O.dom.js"></script>
10
10
  <script src="../../src/drivers/jquery/modules/o_O.controller.js"></script>
11
11
  <script src="../../src/drivers/jquery/modules/o_O.support.js"></script>
12
+ <script src="/tests.js"></script>
13
+ <script src="run_all.js"></script>
14
+
12
15
  <link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />
13
16
  <script type="text/javascript" src="qunit.js"></script>
14
17
 
@@ -9,6 +9,9 @@
9
9
  <script src="../../src/adapters/o_O.localstorage.js"></script>
10
10
  <script src="../../src/drivers/jquery/modules/o_O.controller.js"></script>
11
11
  <script src="../../src/drivers/jquery/modules/o_O.support.js"></script>
12
+ <script src="/tests.js"></script>
13
+ <script src="run_all.js"></script>
14
+
12
15
  <link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />
13
16
  <script type="text/javascript" src="qunit.js"></script>
14
17
 
@@ -9,6 +9,9 @@
9
9
  <script src="../../src/drivers/jquery/adapters/o_O.dom.js"></script>
10
10
  <script src="../../src/drivers/jquery/modules/o_O.controller.js"></script>
11
11
  <script src="../../src/drivers/jquery/modules/o_O.support.js"></script>
12
+ <script src="/tests.js"></script>
13
+ <script src="run_all.js"></script>
14
+
12
15
  <link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />
13
16
  <script type="text/javascript" src="qunit.js"></script>
14
17
 
@@ -9,6 +9,9 @@
9
9
  <script src="../../src/drivers/jquery/adapters/o_O.dom.js"></script>
10
10
  <script src="../../src/drivers/jquery/modules/o_O.controller.js"></script>
11
11
  <script src="../../src/drivers/jquery/modules/o_O.support.js"></script>
12
+ <script src="/tests.js"></script>
13
+ <script src="run_all.js"></script>
14
+
12
15
  <link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />
13
16
  <script type="text/javascript" src="qunit.js"></script>
14
17
 
@@ -10,6 +10,9 @@
10
10
  <script src="../../src/drivers/jquery/adapters/o_O.dom.js"></script>
11
11
  <script src="../../src/drivers/jquery/modules/o_O.controller.js"></script>
12
12
  <script src="../../src/drivers/jquery/modules/o_O.support.js"></script>
13
+ <script src="/tests.js"></script>
14
+ <script src="run_all.js"></script>
15
+
13
16
  <link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />
14
17
  <script type="text/javascript" src="qunit.js"></script>
15
18
 
@@ -10,6 +10,9 @@
10
10
  <script src="../../src/drivers/jquery/adapters/o_O.rest.js"></script>
11
11
  <script src="../../src/drivers/jquery/modules/o_O.controller.js"></script>
12
12
  <script src="../../src/drivers/jquery/modules/o_O.support.js"></script>
13
+ <script src="/tests.js"></script>
14
+ <script src="run_all.js"></script>
15
+
13
16
  <link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />
14
17
  <script type="text/javascript" src="qunit.js"></script>
15
18
 
@@ -27,9 +30,10 @@
27
30
  fake_review.url = '/reviews'
28
31
  });
29
32
 
30
- asyncTest('storing a basic basic thing', 3, function(){
33
+ asyncTest('Review.save() storing a basic basic thing', 3, function(){
31
34
  var review = Review.initialize({title: 'Magic!'})
32
35
  review.save(function(saved_review){
36
+ console.log(saved_review)
33
37
  equals(saved_review.title, review.title, 'title should match');
34
38
  equals(saved_review.id, '1', "Rails should give back the ID");
35
39
  equals(saved_review.model_name, 'Review', 'should save the model name');
@@ -37,7 +41,7 @@
37
41
  });
38
42
  });
39
43
 
40
- asyncTest('storing a basic basic thing with custom URL set in the model', function(){
44
+ asyncTest('FakeReview.create() storing a basic basic thing with custom URL set in the model', function(){
41
45
  FakeReview.create({title: 'Magic!'}, function(saved_review){
42
46
  equals(FakeReview.url, '/reviews', 'Should be set');
43
47
  equals(saved_review.title, 'Magic!', 'title should match');
@@ -46,7 +50,7 @@
46
50
  });
47
51
  });
48
52
 
49
- asyncTest('storing a basic basic thing with a custom URL set in the save', function(){
53
+ asyncTest('review.save() storing a basic basic thing with a custom URL set in the save', function(){
50
54
  var review = Review.initialize({title: 'Magic!'})
51
55
  review.save({
52
56
  url: "/alternate_reviews",
@@ -66,20 +70,27 @@
66
70
  review.json_root_name = 'alternate_object'
67
71
  });
68
72
 
69
- asyncTest('storing a basic basic thing with include_root', function(){
73
+ asyncTest('RailsReview.create() storing a basic basic thing with include_root', function(){
70
74
  RailsReview.create({title: "Awesome"},function(review, response){
71
- equals(response, 'ok', 'should send things with a root');
75
+ equals(review.id, '1', 'should fetch a tasty RailsReview');
76
+ start();
77
+ });
78
+ });
79
+
80
+ asyncTest('fetching with include_root', function(){
81
+ RailsReview.find(1,function(review, response){
82
+ equals(review.id, '1', 'should fetch a tasty RailsReview');
72
83
  start();
73
84
  });
74
85
  });
75
86
 
76
- asyncTest('specifying a custom json_root_name', function(){
77
- AlternateRailsReview.create({title: "Awesome"},function(review, response){
78
- equals(response, 'ok', 'should send things to /alternate_rails_reviews');
87
+ asyncTest('fetching while specifying a custom json_root_name', function(){
88
+ AlternateRailsReview.find(1,function(review, response){
89
+ equals(review.id, '1', 'should get an alternate_rails_review back');
79
90
  start();
80
91
  });
81
92
  });
82
-
93
+
83
94
  o_O.config.authenticity_token = 'a12345';
84
95
  asyncTest('CSRF token', function(){
85
96
  RailsReview.create({title: "Unnecessary"}, {
@@ -142,7 +153,7 @@
142
153
  });
143
154
  });
144
155
 
145
- asyncTest('pulling something in', 2, function(){
156
+ asyncTest('Review.initialize(...).save(...) pulling something in', 2, function(){
146
157
  var review = Review.initialize({title: 'More Magic!'});
147
158
  review.save(function(){
148
159
  found_review = Review.find(review.id, function(found_review){
@@ -153,7 +164,7 @@
153
164
  });
154
165
  })
155
166
 
156
- asyncTest('pulling something in by itself', 1, function(){
167
+ asyncTest('Review.find(2) pulling something in by itself', 1, function(){
157
168
  Review.find(2, {success: function(found_review){
158
169
  equals(found_review.title, 'funtimes');
159
170
  start();
@@ -0,0 +1,61 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2
+ "http://www.w3.org/TR/html4/loose.dtd">
3
+ <html>
4
+ <head>
5
+ <script src="../../dist/jquery/jquery-1.4.2.min.js"></script>
6
+
7
+ <script src="../../src/o_O.js"></script>
8
+ <script src="../../src/modules/o_O.model.js"></script>
9
+ <script src="../../src/modules/o_O.validations.js"></script>
10
+ <script src="../../src/drivers/jquery/adapters/o_O.rest.js"></script>
11
+ <script src="../../src/drivers/jquery/modules/o_O.controller.js"></script>
12
+ <script src="../../src/drivers/jquery/modules/o_O.support.js"></script>
13
+ <script src="/tests.js"></script>
14
+ <script src="run_all.js"></script>
15
+
16
+ <link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />
17
+ <script type="text/javascript" src="qunit.js"></script>
18
+
19
+ <script>
20
+
21
+
22
+ $(document).ready(function(){
23
+
24
+ o_O.model.adapter = o_O.rest;
25
+
26
+ module("REST Interface Test (with jQuery) testing Global config");
27
+
28
+ o_O.config.include_json_root = true
29
+
30
+ o_O('RailsReview', function(){
31
+ });
32
+ o_O('AlternateRailsReview', function(){
33
+ this.json_root_name = 'alternate_object'
34
+ });
35
+
36
+ asyncTest('RailsReview.create() storing a basic basic thing with include_root', function(){
37
+ RailsReview.create({title: "Awesome"},function(review, response){
38
+ equals(review.id, '1', 'should send things with a root');
39
+ start();
40
+ });
41
+ });
42
+
43
+ asyncTest('specifying a custom json_root_name', function(){
44
+ AlternateRailsReview.create({title: "Awesome"},function(review, response){
45
+ equals(response, 'ok', 'should send things to /alternate_rails_reviews');
46
+ start();
47
+ });
48
+ });
49
+
50
+
51
+ });
52
+ </script>
53
+
54
+ </head>
55
+ <body>
56
+ <h1 id="qunit-header">REST Interface Tests (with jQuery)</h1>
57
+ <h2 id="qunit-banner"></h2>
58
+ <h2 id="qunit-userAgent"></h2>
59
+ <ol id="qunit-tests"></ol>
60
+ </body>
61
+ </html>
@@ -11,6 +11,8 @@
11
11
  <script src="../../src/drivers/jquery/modules/o_O.controller.js"></script>
12
12
  <script src="../../src/drivers/jquery/modules/o_O.support.js"></script>
13
13
  <script src="../../src/drivers/jquery/modules/o_O.routes.js"></script>
14
+ <script src="/tests.js"></script>
15
+ <script src="run_all.js"></script>
14
16
 
15
17
  <link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />
16
18
  <script type="text/javascript" src="qunit.js"></script>
@@ -87,8 +89,12 @@
87
89
  equals(o_O.routes.rules['my/action'].action(), ReviewsController.namespaced_index())
88
90
  })
89
91
 
90
- test('o_O.routes.root', function(){
91
- equals($('div#root').html(), 'rooting for you');
92
+ asyncTest('o_O.routes.root', function(){
93
+ document.location.hash = ''
94
+ setTimeout(function(){
95
+ equals($('div#root').html(), 'rooting for you');
96
+ start()
97
+ }, 300)
92
98
  })
93
99
 
94
100
  asyncTest('map.match',function(){
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eyeballs
3
3
  version: !ruby/object:Gem::Version
4
- hash: 85
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 12
10
- - 1
11
- version: 0.5.12.1
9
+ - 13
10
+ version: 0.5.13
12
11
  platform: ruby
13
12
  authors:
14
13
  - Paul Campbell
@@ -16,7 +15,7 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2010-11-07 00:00:00 +00:00
18
+ date: 2010-12-01 00:00:00 +00:00
20
19
  default_executable: eyeballs
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
@@ -96,9 +95,10 @@ files:
96
95
  - templates/scaffold_edit.html.mustache
97
96
  - templates/scaffold_index.html
98
97
  - templates/scaffold_partial.html.mustache
99
- - test/index.html
98
+ - test/run_unit_tests.html
100
99
  - test/unit/qunit.css
101
100
  - test/unit/qunit.js
101
+ - test/unit/run_all.js
102
102
  - test/unit/test_binding.html
103
103
  - test/unit/test_controller.html
104
104
  - test/unit/test_dom.html
@@ -108,6 +108,7 @@ files:
108
108
  - test/unit/test_model_with_callbacks.html
109
109
  - test/unit/test_params.html
110
110
  - test/unit/test_rest.html
111
+ - test/unit/test_rest_global_config.html
111
112
  - test/unit/test_routing.html
112
113
  - spec/app_generator_spec.rb
113
114
  - spec/controller_generator_spec.rb
File without changes