js-client-bridge 0.1.4 → 0.1.5

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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- js-client-bridge (0.1.4)
4
+ js-client-bridge (0.1.5)
5
5
  json_pure (~> 1.4.6)
6
6
 
7
7
  GEM
@@ -83,7 +83,6 @@ DEPENDENCIES
83
83
  dm-types (~> 1.0.2)
84
84
  dm-validations (~> 1.0.2)
85
85
  js-client-bridge!
86
- json_pure (~> 1.4.6)
87
86
  mocha (~> 0.9.8)
88
87
  rcov (~> 0.9.8)
89
88
  rspec (~> 2.0.0)
@@ -15,7 +15,7 @@ module JsClientBridge #:nodoc:
15
15
  def respond_with(type, args)
16
16
  unless args.blank?
17
17
  options = args.last.is_a?(Hash) ? args.pop.dup : {}
18
- options[:_message] = args.shift.dup if args.first.is_a?(String)
18
+ options['_message'] = args.shift.dup if args.first.is_a?(String)
19
19
  else
20
20
  options = {}
21
21
  end
@@ -26,7 +26,7 @@ module JsClientBridge #:nodoc:
26
26
  formatting[para] = options.delete(para) if options.include?(para)
27
27
  end
28
28
 
29
- [options.merge({ :_status => type.to_s }), formatting]
29
+ [options.merge({ '_status' => type.to_s }), formatting]
30
30
  end
31
31
 
32
32
  def format_response(response, formatting_options = {})
@@ -7,16 +7,31 @@ module JsClientBridge #:nodoc:
7
7
  # used as the _status options. It will also honour custom optionss as long
8
8
  # they don't clash with the standard ones.
9
9
  #
10
- # ==== Parameters
11
- # message<String>:: An optional message.
12
- # options<Hash>:: Custom optionss.
10
+ # @param <String> message
11
+ # An optional message.
12
+ # @param <Hash> options
13
+ # Custom optionss.
13
14
  #
14
- # ==== Returns
15
- # JSON String::
15
+ # @return <Hash>
16
+ # The response as a Hash
16
17
  def respond_with_error(*args)
17
- format_response(*respond_with('error', args))
18
+ respond_with('error', args).first
18
19
  end
19
20
 
21
+ # Generates a error response. If the first parameter is a string is will be
22
+ # used as the _status options. It will also honour custom optionss as long
23
+ # they don't clash with the standard ones.
24
+ #
25
+ # @param <String> message
26
+ # An optional message.
27
+ # @param <Hash> options
28
+ # Custom optionss.
29
+ #
30
+ # @return <Hash>
31
+ # The response as a String encoded JSON object.
32
+ def render_error(*args)
33
+ format_response(*respond_with('error', args))
34
+ end
20
35
  end # module Error
21
36
  end # module Responses
22
37
  end # module JsClientBridge
@@ -25,6 +25,30 @@ module JsClientBridge #:nodoc:
25
25
  :backtrace => exception.backtrace
26
26
  }]
27
27
 
28
+ response
29
+ end
30
+
31
+ def render_exception(*args)
32
+ raise ArgumentError.new("respond_with_exception requires an exception as it's first parameter") if args.blank? || !args.first.is_a?(StandardError)
33
+
34
+ exception = args.shift
35
+ options = args.last.is_a?(Hash) ? args.pop : {}
36
+
37
+ # Ensure we have our required fields
38
+ raise ArgumentError.new("respond_with_exception requires the request_uri option") unless options.include?(:request_uri)
39
+
40
+ # Set some defaults
41
+ options[:parameters] ||= {}
42
+
43
+ # Generate our response hash and add the exceptions parameter
44
+ response, formatting = respond_with('exception', [options])
45
+ response[:exceptions] = [{
46
+ :name => exception.class,
47
+ :short_name => exception.class.to_s.split('::').last,
48
+ :message => CGI.escape(exception.message),
49
+ :backtrace => exception.backtrace
50
+ }]
51
+
28
52
  format_response(response, formatting)
29
53
  end
30
54
 
@@ -52,6 +76,33 @@ module JsClientBridge #:nodoc:
52
76
  }
53
77
  end
54
78
 
79
+ response
80
+ end
81
+
82
+ def render_exceptions(*args)
83
+ raise ArgumentError.new("respond_with_exception requires an array of exceptions as it's first parameter") if args.blank? || !args.first.is_a?(Array)
84
+
85
+ exceptions = args.shift
86
+ options = args.last.is_a?(Hash) ? args.pop : {}
87
+
88
+ # Ensure we have our required fields
89
+ raise ArgumentError.new("respond_with_exception requires the request_uri option") unless options.include?(:request_uri)
90
+
91
+ # Set some defaults
92
+ options[:parameters] ||= {}
93
+
94
+ # Generate our response hash and add the exceptions parameter
95
+ response, formatting = respond_with('exception', [options])
96
+
97
+ response[:exceptions] = exceptions.map do |exception|
98
+ {
99
+ :name => exception.class,
100
+ :short_name => exception.class.to_s.split('::').last,
101
+ :message => CGI.escape(exception.message),
102
+ :backtrace => exception.backtrace
103
+ }
104
+ end
105
+
55
106
  format_response(response, formatting)
56
107
  end
57
108
 
@@ -3,17 +3,33 @@ require 'cgi'
3
3
  module JsClientBridge #:nodoc:
4
4
  module Responses #:nodoc:
5
5
  module Ok
6
- # Generates a 'ok' status response. If the first parameter is a string is will be
6
+ # Generates a 'ok' status response as a Hash. If the first parameter is a string is will be
7
7
  # used as the _status options. It will also honour custom optionss as long
8
8
  # they don't clash with the standard ones.
9
9
  #
10
- # ==== Parameters
11
- # message<String>:: An optional message.
12
- # options<Hash>:: Custom optionss.
10
+ # @param <String> message
11
+ # An optional message.
12
+ # @param <Hash> options
13
+ # Custom optionss.
13
14
  #
14
- # ==== Returns
15
- # JSON String::
15
+ # @return <Hash>
16
+ # The response as a Hash
16
17
  def respond_with_ok(*args)
18
+ respond_with('ok', args).first
19
+ end
20
+
21
+ # Generates a 'ok' status response. If the first parameter is a string is will be
22
+ # used as the _status options. It will also honour custom optionss as long
23
+ # they don't clash with the standard ones.
24
+ #
25
+ # @param <String> message
26
+ # An optional message.
27
+ # @param <Hash> options
28
+ # Custom optionss.
29
+ #
30
+ # @return <String>
31
+ # A JSON object encoded as a String.
32
+ def render_ok(*args)
17
33
  format_response(*respond_with('ok', args))
18
34
  end
19
35
  end # module Ok
@@ -7,16 +7,42 @@ module JsClientBridge #:nodoc:
7
7
  # used as the _status options. It will also honour custom optionss as long
8
8
  # they don't clash with the standard ones.
9
9
  #
10
- # ==== Parameters
11
- # message<String>:: An optional message.
12
- # options<Hash>:: Custom optionss.
10
+ # @param <String> message
11
+ # An optional message.
12
+ # @param <Hash> options
13
+ # Custom optionss.
13
14
  #
14
- # ==== Returns
15
- # JSON String::
15
+ # @return <Hash>
16
+ # The response as a Hash
16
17
  def respond_with_validation_error(*args)
17
18
  obj = args.shift
18
19
  options = args.last.is_a?(Hash) ? args.pop : {}
19
20
 
21
+ # Generate our response hash and add the exceptions parameter
22
+ response = if options.include?(:message)
23
+ options.merge( validation_errors_to_hash(obj, options.delete(:message)) )
24
+ else
25
+ options.merge( validation_errors_to_hash(obj) )
26
+ end
27
+
28
+ response
29
+ end
30
+
31
+ # Generates a validation error status response. If the first parameter is a string is will be
32
+ # used as the _status options. It will also honour custom optionss as long
33
+ # they don't clash with the standard ones.
34
+ #
35
+ # @param <String> message
36
+ # An optional message.
37
+ # @param <Hash> options
38
+ # Custom optionss.
39
+ #
40
+ # @return <String>
41
+ # The response as a String encoded JSON object
42
+ def render_validation(*args)
43
+ obj = args.shift
44
+ options = args.last.is_a?(Hash) ? args.pop : {}
45
+
20
46
  # Generate our response hash and add the exceptions parameter
21
47
  response = if options.include?(:message)
22
48
  options.merge( validation_errors_to_hash(obj, options.delete(:message)) )
@@ -33,14 +59,14 @@ module JsClientBridge #:nodoc:
33
59
  short_type = data_object.class.to_s.split('::').last
34
60
 
35
61
  validation = {
36
- :_status => 'validation',
37
- :_type => data_object.class.to_s,
38
- :_short_type => short_type,
39
- :_message => message,
40
- :validation => data_object.errors.to_hash,
62
+ '_status' => 'validation',
63
+ '_type' => data_object.class.to_s,
64
+ '_short_type' => short_type,
65
+ '_message' => message,
66
+ 'validation' => data_object.errors.to_hash,
41
67
  }
42
68
 
43
- validation[:id] = data_object.id.to_s unless data_object.new?
69
+ validation['id'] = data_object.id.to_s unless data_object.new?
44
70
 
45
71
  validation
46
72
  end
@@ -1,3 +1,3 @@
1
1
  module JsClientBridge
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -1,26 +1,46 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
2
 
3
3
  describe "Error Responses" do
4
- it "should generate a basic error response" do
5
- JSON.parse(JsClientBridge::Responses.respond_with_error).should == {'_status' => 'error'}
6
- end
4
+ describe "#render_error" do
5
+ it "should generate a basic error response" do
6
+ JSON.parse(JsClientBridge::Responses.render_error).should == {'_status' => 'error'}
7
+ end
7
8
 
8
- it "should generate a error response with a status message" do
9
- JSON.parse(JsClientBridge::Responses.respond_with_error('a message')).should == {'_status' => 'error', '_message' => "a message"}
10
- end
9
+ it "should generate a error response with a status message" do
10
+ JSON.parse(JsClientBridge::Responses.render_error('a message')).should == {'_status' => 'error', '_message' => "a message"}
11
+ end
11
12
 
12
- it "should generate a error response with a status message and additional custom properties" do
13
- JSON.parse(JsClientBridge::Responses.respond_with_error('a message', 'blame' => 'the user')).should == {'_status' => 'error', '_message' => "a message", 'blame' => 'the user'}
14
- end
15
-
16
- it "should generate a error response with custom properties but not message" do
17
- JSON.parse(JsClientBridge::Responses.respond_with_error('blame' => 'the user')).should == {'_status' => 'error', 'blame' => 'the user'}
13
+ it "should generate a error response with a status message and additional custom properties" do
14
+ JSON.parse(JsClientBridge::Responses.render_error('a message', 'blame' => 'the user')).should == {'_status' => 'error', '_message' => "a message", 'blame' => 'the user'}
15
+ end
16
+
17
+ it "should generate a error response with custom properties but not message" do
18
+ JSON.parse(JsClientBridge::Responses.render_error('blame' => 'the user')).should == {'_status' => 'error', 'blame' => 'the user'}
19
+ end
20
+
21
+ it "should generate a basic error response using JSONP" do
22
+ jsonp = JsClientBridge::Responses.render_error('a message', :jsonp => 'jsonp1')
23
+ jsonp[0..6].should == 'jsonp1('
24
+ jsonp[-1..-1].should == ')'
25
+ JSON.parse(jsonp[7..-2]).should == {'_message' => "a message", '_status' => 'error'}
26
+ end
18
27
  end
19
-
20
- it "should generate a basic error response using JSONP" do
21
- jsonp = JsClientBridge::Responses.respond_with_error('a message', :jsonp => 'jsonp1')
22
- jsonp[0..6].should == 'jsonp1('
23
- jsonp[-1..-1].should == ')'
24
- JSON.parse(jsonp[7..-2]).should == {'_message' => "a message", '_status' => 'error'}
28
+
29
+ describe "#respond_with_error" do
30
+ it "should generate a basic error response" do
31
+ JsClientBridge::Responses.respond_with_error.should == {'_status' => 'error'}
32
+ end
33
+
34
+ it "should generate a error response with a status message" do
35
+ JsClientBridge::Responses.respond_with_error('a message').should == {'_status' => 'error', '_message' => "a message"}
36
+ end
37
+
38
+ it "should generate a error response with a status message and additional custom properties" do
39
+ JsClientBridge::Responses.respond_with_error('a message', 'blame' => 'the user').should == {'_status' => 'error', '_message' => "a message", 'blame' => 'the user'}
40
+ end
41
+
42
+ it "should generate a error response with custom properties but not message" do
43
+ JsClientBridge::Responses.respond_with_error('blame' => 'the user').should == {'_status' => 'error', 'blame' => 'the user'}
44
+ end
25
45
  end
26
46
  end
@@ -5,52 +5,99 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
5
5
  class TestException < StandardError; end
6
6
 
7
7
  describe "Exception Responses" do
8
+ describe "#respond_with_exception" do
9
+ it "should generate an exception response" do
10
+ exception = TestException.new('An exception')
8
11
 
9
- it "should generate an exception response" do
10
- exception = TestException.new('An exception')
12
+ ex = JsClientBridge::Responses.respond_with_exception(exception, :request_uri => '/', :parameters => {:param1 => 'value1'})
11
13
 
12
- ex = JSON.parse(JsClientBridge::Responses.respond_with_exception(exception, :request_uri => '/', :parameters => {:param1 => 'value1'}))
14
+ ex['_status'].should == 'exception'
15
+ ex['request_uri'].should == '/'
16
+ ex['parameters'].should == {'param1' => 'value1'}
17
+ ex['exceptions'].length.should == 1
13
18
 
14
- ex['_status'].should == 'exception'
15
- ex['request_uri'].should == '/'
16
- ex['parameters'].should == {'param1' => 'value1'}
17
- ex['exceptions'].length.should == 1
19
+ e = ex['exceptions'].first
20
+ e['name'].should == exception.class.to_s
21
+ e['message'].should == CGI.escape(exception.message)
22
+ e['backtrace'].should == exception.backtrace
23
+ e['short_name'].should == exception.class.to_s.split('::').last
24
+ end
18
25
 
19
- e = ex['exceptions'].first
20
- e['name'].should == exception.class.to_s
21
- e['message'].should == CGI.escape(exception.message)
22
- e['backtrace'].should == exception.backtrace
23
- e['short_name'].should == exception.class.to_s.split('::').last
26
+ it "should require the request_uri option" do
27
+ lambda {
28
+ JsClientBridge::Responses.respond_with_exception(TestException.new('An exception'), :parameters => {:param1 => 'value1'})
29
+ }.should raise_error(ArgumentError)
30
+ end
31
+
32
+ it "should require the exception option" do
33
+ lambda {
34
+ JsClientBridge::Responses.respond_with_exception(:request_uri => '/', :parameters => {:param1 => 'value1'})
35
+ }.should raise_error(ArgumentError)
36
+ end
24
37
  end
25
38
 
26
- it "should generate an exceptions response" do
27
- exceptions = [TestException.new('An exception'), TestException.new('Another exception')]
39
+ describe "#respond_with_exceptions" do
40
+ it "should generate an exceptions response" do
41
+ exceptions = [TestException.new('An exception'), TestException.new('Another exception')]
28
42
 
29
- ex = JSON.parse(JsClientBridge::Responses.respond_with_exceptions(exceptions, :request_uri => '/', :parameters => {:param1 => 'value1'}))
43
+ ex = JsClientBridge::Responses.respond_with_exceptions(exceptions, :request_uri => '/', :parameters => {:param1 => 'value1'})
30
44
 
31
- ex['_status'].should == 'exception'
32
- ex['request_uri'].should == '/'
33
- ex['parameters'].should == {'param1' => 'value1'}
34
- ex['exceptions'].length.should == 2
45
+ ex['_status'].should == 'exception'
46
+ ex['request_uri'].should == '/'
47
+ ex['parameters'].should == {'param1' => 'value1'}
48
+ ex['exceptions'].length.should == 2
49
+ end
35
50
  end
51
+
52
+ describe "#render_exception" do
53
+ it "should generate an exception response" do
54
+ exception = TestException.new('An exception')
36
55
 
37
- it "should require the request_uri option" do
38
- lambda {
39
- JsClientBridge::Responses.respond_with_exception(TestException.new('An exception'), :parameters => {:param1 => 'value1'})
40
- }.should raise_error(ArgumentError)
41
- end
56
+ ex = JSON.parse(JsClientBridge::Responses.render_exception(exception, :request_uri => '/', :parameters => {:param1 => 'value1'}))
57
+
58
+ ex['_status'].should == 'exception'
59
+ ex['request_uri'].should == '/'
60
+ ex['parameters'].should == {'param1' => 'value1'}
61
+ ex['exceptions'].length.should == 1
62
+
63
+ e = ex['exceptions'].first
64
+ e['name'].should == exception.class.to_s
65
+ e['message'].should == CGI.escape(exception.message)
66
+ e['backtrace'].should == exception.backtrace
67
+ e['short_name'].should == exception.class.to_s.split('::').last
68
+ end
42
69
 
43
- it "should require the exception option" do
44
- lambda {
45
- JsClientBridge::Responses.respond_with_exception(:request_uri => '/', :parameters => {:param1 => 'value1'})
46
- }.should raise_error(ArgumentError)
70
+ it "should require the request_uri option" do
71
+ lambda {
72
+ JsClientBridge::Responses.render_exception(TestException.new('An exception'), :parameters => {:param1 => 'value1'})
73
+ }.should raise_error(ArgumentError)
74
+ end
75
+
76
+ it "should require the exception option" do
77
+ lambda {
78
+ JsClientBridge::Responses.render_exception(:request_uri => '/', :parameters => {:param1 => 'value1'})
79
+ }.should raise_error(ArgumentError)
80
+ end
81
+
82
+ it "should generate an exception response using JSONP" do
83
+ exception = TestException.new('An exception')
84
+
85
+ ex = JsClientBridge::Responses.render_exception(exception, :request_uri => '/', :parameters => {:param1 => 'value1'}, :jsonp => 'jsonp1')
86
+ ex[0..6].should == 'jsonp1('
87
+ ex[-1..-1].should == ')'
88
+ end
47
89
  end
48
90
 
49
- it "should generate an exception response using JSONP" do
50
- exception = TestException.new('An exception')
91
+ describe "#render_exceptions" do
92
+ it "should generate an exceptions response" do
93
+ exceptions = [TestException.new('An exception'), TestException.new('Another exception')]
94
+
95
+ ex = JSON.parse(JsClientBridge::Responses.render_exceptions(exceptions, :request_uri => '/', :parameters => {:param1 => 'value1'}))
51
96
 
52
- ex = JsClientBridge::Responses.respond_with_exception(exception, :request_uri => '/', :parameters => {:param1 => 'value1'}, :jsonp => 'jsonp1')
53
- ex[0..6].should == 'jsonp1('
54
- ex[-1..-1].should == ')'
97
+ ex['_status'].should == 'exception'
98
+ ex['request_uri'].should == '/'
99
+ ex['parameters'].should == {'param1' => 'value1'}
100
+ ex['exceptions'].length.should == 2
101
+ end
55
102
  end
56
103
  end
@@ -4,29 +4,49 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
4
 
5
5
 
6
6
  describe "Ok Responses" do
7
- it "should generate a basic ok response" do
8
- JSON.parse(JsClientBridge::Responses.respond_with_ok).should == {'_status' => 'ok'}
9
- end
7
+ describe "#respond_with_ok" do
8
+ it "should generate a basic ok response" do
9
+ JsClientBridge::Responses.respond_with_ok.should == {'_status' => 'ok'}
10
+ end
10
11
 
11
- it "should generate a ok response with a status message" do
12
- JSON.parse(JsClientBridge::Responses.respond_with_ok('a message')).should == {'_status' => 'ok', '_message' => "a message"}
13
- end
12
+ it "should generate a ok response with a status message" do
13
+ JsClientBridge::Responses.respond_with_ok('a message').should == {'_status' => 'ok', '_message' => "a message"}
14
+ end
14
15
 
15
- it "should generate a ok response with a status message and additional custom parameters" do
16
- JSON.parse(JsClientBridge::Responses.respond_with_ok('a message', 'awesomeness' => 'has happened')).should == {'_status' => 'ok', '_message' => "a message", 'awesomeness' => 'has happened'}
17
- end
18
-
19
- it "should generate a ok response with a status message and a complex parameters" do
20
- JSON.parse(JsClientBridge::Responses.respond_with_ok('a message', 'stuff' => complext_test_data)).should == {'_message' => "a message", 'stuff' => complext_test_data, '_status' => 'ok'}
16
+ it "should generate a ok response with a status message and additional custom parameters" do
17
+ JsClientBridge::Responses.respond_with_ok('a message', 'awesomeness' => 'has happened').should == {'_status' => 'ok', '_message' => "a message", 'awesomeness' => 'has happened'}
18
+ end
19
+
20
+ it "should generate a ok response with a status message and a complex parameters" do
21
+ JsClientBridge::Responses.respond_with_ok('a message', 'stuff' => complext_test_data).should == {'_message' => "a message", 'stuff' => complext_test_data, '_status' => 'ok'}
22
+ end
21
23
  end
22
-
23
- it "should generate a basic ok response using JSONP" do
24
- jsonp = JsClientBridge::Responses.respond_with_ok('a message', :jsonp => 'jsonp1')
25
- jsonp[0..6].should == 'jsonp1('
26
- jsonp[-1..-1].should == ')'
27
- JSON.parse(jsonp[7..-2]).should == {'_status' => 'ok', '_message' => "a message"}
24
+
25
+ describe "#render_ok" do
26
+ it "should generate a basic ok response" do
27
+ JSON.parse(JsClientBridge::Responses.render_ok).should == {'_status' => 'ok'}
28
+ end
29
+
30
+ it "should generate a ok response with a status message" do
31
+ JSON.parse(JsClientBridge::Responses.render_ok('a message')).should == {'_status' => 'ok', '_message' => "a message"}
32
+ end
33
+
34
+ it "should generate a ok response with a status message and additional custom parameters" do
35
+ JSON.parse(JsClientBridge::Responses.render_ok('a message', 'awesomeness' => 'has happened')).should == {'_status' => 'ok', '_message' => "a message", 'awesomeness' => 'has happened'}
36
+ end
37
+
38
+ it "should generate a ok response with a status message and a complex parameters" do
39
+ JSON.parse(JsClientBridge::Responses.render_ok('a message', 'stuff' => complext_test_data)).should == {'_message' => "a message", 'stuff' => complext_test_data, '_status' => 'ok'}
40
+ end
41
+
42
+ it "should generate a basic ok response using JSONP" do
43
+ jsonp = JsClientBridge::Responses.render_ok('a message', :jsonp => 'jsonp1')
44
+ jsonp[0..6].should == 'jsonp1('
45
+ jsonp[-1..-1].should == ')'
46
+ JSON.parse(jsonp[7..-2]).should == {'_status' => 'ok', '_message' => "a message"}
47
+ end
28
48
  end
29
-
49
+
30
50
  def complext_test_data
31
51
  [
32
52
  {'name'=>"Whangarei",
@@ -26,24 +26,39 @@ describe "Validation Responses" do
26
26
  DataMapper.auto_migrate!
27
27
  end
28
28
 
29
- it "should generate a basic validation response" do
30
- test_do = Luma::Test::TestDO.new(:id => 'bob')
31
- test_do.save.should be_false
29
+ describe "#respond_with_validation" do
30
+ it "should generate a basic validation response" do
31
+ test_do = Luma::Test::TestDO.new(:id => 'bob')
32
+ test_do.save.should be_false
32
33
 
33
- ex = JSON.parse(JsClientBridge::Responses.respond_with_validation_error(test_do))
34
- pp ex
35
- ex['validation'].length.should == 2
36
- ex['_short_type'].should == "TestDO"
37
- ex['_type'].should == "Luma::Test::TestDO"
34
+ ex = JsClientBridge::Responses.respond_with_validation_error(test_do)
35
+ pp ex
36
+ ex['validation'].length.should == 2
37
+ ex['_short_type'].should == "TestDO"
38
+ ex['_type'].should == "Luma::Test::TestDO"
39
+ end
38
40
  end
39
-
40
- it "should generate a basic validation response using JSONP" do
41
- test_do = Luma::Test::TestDO.new(:id => 'bob')
42
- test_do.save.should be_false
43
41
 
44
- ex = JsClientBridge::Responses.respond_with_validation_error(test_do, :jsonp => 'jsonp1')
45
- ex[0..6].should == 'jsonp1('
46
- ex[-1..-1].should == ')'
42
+ describe "#render_validation" do
43
+ it "should generate a basic validation response" do
44
+ test_do = Luma::Test::TestDO.new(:id => 'bob')
45
+ test_do.save.should be_false
46
+
47
+ ex = JSON.parse(JsClientBridge::Responses.render_validation(test_do))
48
+ pp ex
49
+ ex['validation'].length.should == 2
50
+ ex['_short_type'].should == "TestDO"
51
+ ex['_type'].should == "Luma::Test::TestDO"
52
+ end
53
+
54
+ it "should generate a basic validation response using JSONP" do
55
+ test_do = Luma::Test::TestDO.new(:id => 'bob')
56
+ test_do.save.should be_false
57
+
58
+ ex = JsClientBridge::Responses.render_validation(test_do, :jsonp => 'jsonp1')
59
+ ex[0..6].should == 'jsonp1('
60
+ ex[-1..-1].should == ')'
61
+ end
47
62
  end
48
63
  end
49
64
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Rolly Fordham
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-21 00:00:00 +13:00
17
+ date: 2011-02-13 00:00:00 +13:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency