axtro-actionwebservice 2.3.5.1.20101118142125
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +335 -0
- data/MIT-LICENSE +21 -0
- data/README +381 -0
- data/Rakefile +184 -0
- data/TODO +32 -0
- data/examples/googlesearch/README +143 -0
- data/examples/googlesearch/autoloading/google_search_api.rb +51 -0
- data/examples/googlesearch/autoloading/google_search_controller.rb +58 -0
- data/examples/googlesearch/delegated/google_search_service.rb +109 -0
- data/examples/googlesearch/delegated/search_controller.rb +8 -0
- data/examples/googlesearch/direct/google_search_api.rb +51 -0
- data/examples/googlesearch/direct/search_controller.rb +59 -0
- data/examples/metaWeblog/README +17 -0
- data/examples/metaWeblog/apis/blogger_api.rb +61 -0
- data/examples/metaWeblog/apis/blogger_service.rb +35 -0
- data/examples/metaWeblog/apis/meta_weblog_api.rb +68 -0
- data/examples/metaWeblog/apis/meta_weblog_service.rb +49 -0
- data/examples/metaWeblog/controllers/xmlrpc_controller.rb +17 -0
- data/generators/web_service/USAGE +28 -0
- data/generators/web_service/templates/api_definition.rb +6 -0
- data/generators/web_service/templates/controller.rb +9 -0
- data/generators/web_service/templates/functional_test.rb +20 -0
- data/generators/web_service/web_service_generator.rb +30 -0
- data/lib/action_web_service.rb +61 -0
- data/lib/action_web_service/acts_as_web_service.rb +26 -0
- data/lib/action_web_service/api.rb +298 -0
- data/lib/action_web_service/base.rb +39 -0
- data/lib/action_web_service/casting.rb +160 -0
- data/lib/action_web_service/client.rb +4 -0
- data/lib/action_web_service/client/base.rb +29 -0
- data/lib/action_web_service/client/soap_client.rb +114 -0
- data/lib/action_web_service/client/xmlrpc_client.rb +59 -0
- data/lib/action_web_service/container.rb +4 -0
- data/lib/action_web_service/container/action_controller_container.rb +94 -0
- data/lib/action_web_service/container/delegated_container.rb +87 -0
- data/lib/action_web_service/container/direct_container.rb +70 -0
- data/lib/action_web_service/dispatcher.rb +3 -0
- data/lib/action_web_service/dispatcher/abstract.rb +209 -0
- data/lib/action_web_service/dispatcher/action_controller_dispatcher.rb +397 -0
- data/lib/action_web_service/invocation.rb +203 -0
- data/lib/action_web_service/protocol.rb +5 -0
- data/lib/action_web_service/protocol/abstract.rb +113 -0
- data/lib/action_web_service/protocol/discovery.rb +38 -0
- data/lib/action_web_service/protocol/soap_protocol.rb +177 -0
- data/lib/action_web_service/protocol/soap_protocol/marshaler.rb +243 -0
- data/lib/action_web_service/protocol/soap_protocol/marshaler.rb~ +243 -0
- data/lib/action_web_service/protocol/xmlrpc_protocol.rb +124 -0
- data/lib/action_web_service/scaffolding.rb +282 -0
- data/lib/action_web_service/simple.rb +54 -0
- data/lib/action_web_service/string_to_datetime_for_soap.rb +17 -0
- data/lib/action_web_service/struct.rb +69 -0
- data/lib/action_web_service/support/class_inheritable_options.rb +27 -0
- data/lib/action_web_service/support/signature_types.rb +262 -0
- data/lib/action_web_service/templates/scaffolds/layout.html.erb +65 -0
- data/lib/action_web_service/templates/scaffolds/methods.html.erb +6 -0
- data/lib/action_web_service/templates/scaffolds/parameters.html.erb +29 -0
- data/lib/action_web_service/templates/scaffolds/result.html.erb +30 -0
- data/lib/action_web_service/test_invoke.rb +111 -0
- data/lib/action_web_service/version.rb +11 -0
- data/lib/action_web_service/version.rb~ +10 -0
- data/lib/actionwebservice.rb +2 -0
- data/setup.rb +1380 -0
- data/test/abstract_client.rb +185 -0
- data/test/abstract_dispatcher.rb +550 -0
- data/test/abstract_unit.rb +44 -0
- data/test/api_test.rb +103 -0
- data/test/apis/auto_load_api.rb +4 -0
- data/test/apis/broken_auto_load_api.rb +3 -0
- data/test/base_test.rb +43 -0
- data/test/casting_test.rb +96 -0
- data/test/client_soap_test.rb +157 -0
- data/test/client_xmlrpc_test.rb +155 -0
- data/test/container_test.rb +76 -0
- data/test/dispatcher_action_controller_soap_test.rb +147 -0
- data/test/dispatcher_action_controller_xmlrpc_test.rb +60 -0
- data/test/fixtures/db_definitions/mysql.sql +8 -0
- data/test/fixtures/db_definitions/sqlite3.sql +8 -0
- data/test/fixtures/users.yml +12 -0
- data/test/gencov +3 -0
- data/test/invocation_test.rb +187 -0
- data/test/run +6 -0
- data/test/scaffolded_controller_test.rb +148 -0
- data/test/struct_test.rb +85 -0
- data/test/test_invoke_test.rb +114 -0
- metadata +167 -0
data/test/gencov
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'abstract_unit'
|
3
|
+
|
4
|
+
module InvocationTest
|
5
|
+
class API < ActionWebService::API::Base
|
6
|
+
api_method :add, :expects => [:int, :int], :returns => [:int]
|
7
|
+
api_method :transmogrify, :expects_and_returns => [:string]
|
8
|
+
api_method :fail_with_reason
|
9
|
+
api_method :fail_generic
|
10
|
+
api_method :no_before
|
11
|
+
api_method :no_after
|
12
|
+
api_method :only_one
|
13
|
+
api_method :only_two
|
14
|
+
end
|
15
|
+
|
16
|
+
class Interceptor
|
17
|
+
attr :args
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@args = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def intercept(*args)
|
24
|
+
@args = args
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
InterceptorClass = Interceptor.new
|
29
|
+
|
30
|
+
class Service < ActionController::Base
|
31
|
+
acts_as_web_service
|
32
|
+
web_service_api API
|
33
|
+
|
34
|
+
before_invocation :intercept_before, :except => [:no_before]
|
35
|
+
after_invocation :intercept_after, :except => [:no_after]
|
36
|
+
prepend_after_invocation :intercept_after_first, :except => [:no_after]
|
37
|
+
prepend_before_invocation :intercept_only, :only => [:only_one, :only_two]
|
38
|
+
after_invocation(:only => [:only_one]) do |*args|
|
39
|
+
args[0].instance_variable_set('@block_invoked', args[1])
|
40
|
+
end
|
41
|
+
after_invocation InterceptorClass, :only => [:only_one]
|
42
|
+
|
43
|
+
attr_accessor :before_invoked
|
44
|
+
attr_accessor :after_invoked
|
45
|
+
attr_accessor :after_first_invoked
|
46
|
+
attr_accessor :only_invoked
|
47
|
+
attr_accessor :block_invoked
|
48
|
+
attr_accessor :invocation_result
|
49
|
+
|
50
|
+
def initialize
|
51
|
+
@before_invoked = nil
|
52
|
+
@after_invoked = nil
|
53
|
+
@after_first_invoked = nil
|
54
|
+
@only_invoked = nil
|
55
|
+
@invocation_result = nil
|
56
|
+
@block_invoked = nil
|
57
|
+
end
|
58
|
+
|
59
|
+
def add(a, b)
|
60
|
+
a + b
|
61
|
+
end
|
62
|
+
|
63
|
+
def transmogrify(str)
|
64
|
+
str.upcase
|
65
|
+
end
|
66
|
+
|
67
|
+
def fail_with_reason
|
68
|
+
end
|
69
|
+
|
70
|
+
def fail_generic
|
71
|
+
end
|
72
|
+
|
73
|
+
def no_before
|
74
|
+
5
|
75
|
+
end
|
76
|
+
|
77
|
+
def no_after
|
78
|
+
end
|
79
|
+
|
80
|
+
def only_one
|
81
|
+
end
|
82
|
+
|
83
|
+
def only_two
|
84
|
+
end
|
85
|
+
|
86
|
+
protected
|
87
|
+
def intercept_before(name, args)
|
88
|
+
@before_invoked = name
|
89
|
+
return [false, "permission denied"] if name == :fail_with_reason
|
90
|
+
return false if name == :fail_generic
|
91
|
+
end
|
92
|
+
|
93
|
+
def intercept_after(name, args, result)
|
94
|
+
@after_invoked = name
|
95
|
+
@invocation_result = result
|
96
|
+
end
|
97
|
+
|
98
|
+
def intercept_after_first(name, args, result)
|
99
|
+
@after_first_invoked = name
|
100
|
+
end
|
101
|
+
|
102
|
+
def intercept_only(name, args)
|
103
|
+
raise "Interception error" unless name == :only_one || name == :only_two
|
104
|
+
@only_invoked = name
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
class TC_Invocation < Test::Unit::TestCase
|
110
|
+
include ActionWebService::Invocation
|
111
|
+
|
112
|
+
def setup
|
113
|
+
@service = InvocationTest::Service.new
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_invocation
|
117
|
+
assert(perform_invocation(:add, 5, 10) == 15)
|
118
|
+
assert(perform_invocation(:transmogrify, "hello") == "HELLO")
|
119
|
+
assert_raises(NoMethodError) do
|
120
|
+
perform_invocation(:nonexistent_method_xyzzy)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_interceptor_registration
|
125
|
+
assert(InvocationTest::Service.before_invocation_interceptors.length == 2)
|
126
|
+
assert(InvocationTest::Service.after_invocation_interceptors.length == 4)
|
127
|
+
assert_equal(:intercept_only, InvocationTest::Service.before_invocation_interceptors[0])
|
128
|
+
assert_equal(:intercept_after_first, InvocationTest::Service.after_invocation_interceptors[0])
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_interception
|
132
|
+
assert(@service.before_invoked.nil?)
|
133
|
+
assert(@service.after_invoked.nil?)
|
134
|
+
assert(@service.only_invoked.nil?)
|
135
|
+
assert(@service.block_invoked.nil?)
|
136
|
+
assert(@service.invocation_result.nil?)
|
137
|
+
perform_invocation(:add, 20, 50)
|
138
|
+
assert(@service.before_invoked == :add)
|
139
|
+
assert(@service.after_invoked == :add)
|
140
|
+
assert(@service.invocation_result == 70)
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_interception_canceling
|
144
|
+
reason = nil
|
145
|
+
perform_invocation(:fail_with_reason){|r| reason = r}
|
146
|
+
assert(@service.before_invoked == :fail_with_reason)
|
147
|
+
assert(@service.after_invoked.nil?)
|
148
|
+
assert(@service.invocation_result.nil?)
|
149
|
+
assert(reason == "permission denied")
|
150
|
+
reason = true
|
151
|
+
@service.before_invoked = @service.after_invoked = @service.invocation_result = nil
|
152
|
+
perform_invocation(:fail_generic){|r| reason = r}
|
153
|
+
assert(@service.before_invoked == :fail_generic)
|
154
|
+
assert(@service.after_invoked.nil?)
|
155
|
+
assert(@service.invocation_result.nil?)
|
156
|
+
assert(reason == true)
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_interception_except_conditions
|
160
|
+
perform_invocation(:no_before)
|
161
|
+
assert(@service.before_invoked.nil?)
|
162
|
+
assert(@service.after_first_invoked == :no_before)
|
163
|
+
assert(@service.after_invoked == :no_before)
|
164
|
+
assert(@service.invocation_result == 5)
|
165
|
+
@service.before_invoked = @service.after_invoked = @service.invocation_result = nil
|
166
|
+
perform_invocation(:no_after)
|
167
|
+
assert(@service.before_invoked == :no_after)
|
168
|
+
assert(@service.after_invoked.nil?)
|
169
|
+
assert(@service.invocation_result.nil?)
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_interception_only_conditions
|
173
|
+
assert(@service.only_invoked.nil?)
|
174
|
+
perform_invocation(:only_one)
|
175
|
+
assert(@service.only_invoked == :only_one)
|
176
|
+
assert(@service.block_invoked == :only_one)
|
177
|
+
assert(InvocationTest::InterceptorClass.args[1] == :only_one)
|
178
|
+
@service.only_invoked = nil
|
179
|
+
perform_invocation(:only_two)
|
180
|
+
assert(@service.only_invoked == :only_two)
|
181
|
+
end
|
182
|
+
|
183
|
+
private
|
184
|
+
def perform_invocation(method_name, *args, &block)
|
185
|
+
@service.perform_invocation(method_name, args, &block)
|
186
|
+
end
|
187
|
+
end
|
data/test/run
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'test/unit'
|
3
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
4
|
+
args = Dir[File.join(File.dirname(__FILE__), '*_test.rb')] + Dir[File.join(File.dirname(__FILE__), 'ws/*_test.rb')]
|
5
|
+
(r = Test::Unit::AutoRunner.new(true)).process_args(args)
|
6
|
+
exit r.run
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'abstract_unit'
|
3
|
+
|
4
|
+
ActionController::Routing::Routes.draw do |map|
|
5
|
+
map.connect '', :controller => 'scaffolded'
|
6
|
+
map.connect ':controller/:action/:id'
|
7
|
+
end
|
8
|
+
|
9
|
+
ActionController::Base.view_paths = [ '.' ]
|
10
|
+
|
11
|
+
class ScaffoldPerson < ActionWebService::Struct
|
12
|
+
member :id, :int
|
13
|
+
member :name, :string
|
14
|
+
member :birth, :date
|
15
|
+
|
16
|
+
def ==(other)
|
17
|
+
self.id == other.id && self.name == other.name
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class ScaffoldedControllerTestAPI < ActionWebService::API::Base
|
22
|
+
api_method :hello, :expects => [{:integer=>:int}, :string], :returns => [:bool]
|
23
|
+
api_method :hello_struct_param, :expects => [{:person => ScaffoldPerson}], :returns => [:bool]
|
24
|
+
api_method :date_of_birth, :expects => [ScaffoldPerson], :returns => [:string]
|
25
|
+
api_method :bye, :returns => [[ScaffoldPerson]]
|
26
|
+
api_method :date_diff, :expects => [{:start_date => :date}, {:end_date => :date}], :returns => [:int]
|
27
|
+
api_method :time_diff, :expects => [{:start_time => :time}, {:end_time => :time}], :returns => [:int]
|
28
|
+
api_method :base64_upcase, :expects => [:base64], :returns => [:base64]
|
29
|
+
end
|
30
|
+
|
31
|
+
class ScaffoldedController < ActionController::Base
|
32
|
+
acts_as_web_service
|
33
|
+
web_service_api ScaffoldedControllerTestAPI
|
34
|
+
web_service_scaffold :scaffold_invoke
|
35
|
+
|
36
|
+
def hello(int, string)
|
37
|
+
0
|
38
|
+
end
|
39
|
+
|
40
|
+
def hello_struct_param(person)
|
41
|
+
0
|
42
|
+
end
|
43
|
+
|
44
|
+
def date_of_birth(person)
|
45
|
+
person.birth.to_s
|
46
|
+
end
|
47
|
+
|
48
|
+
def bye
|
49
|
+
[ScaffoldPerson.new(:id => 1, :name => "leon"), ScaffoldPerson.new(:id => 2, :name => "paul")]
|
50
|
+
end
|
51
|
+
|
52
|
+
def rescue_action(e)
|
53
|
+
raise e
|
54
|
+
end
|
55
|
+
|
56
|
+
def date_diff(start_date, end_date)
|
57
|
+
end_date - start_date
|
58
|
+
end
|
59
|
+
|
60
|
+
def time_diff(start_time, end_time)
|
61
|
+
end_time - start_time
|
62
|
+
end
|
63
|
+
|
64
|
+
def base64_upcase(data)
|
65
|
+
data.upcase
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class ScaffoldedControllerTest < ActionController::TestCase
|
70
|
+
# def setup
|
71
|
+
# @controller = ScaffoldedController.new
|
72
|
+
# @request = ActionController::TestRequest.new
|
73
|
+
# @response = ActionController::TestResponse.new
|
74
|
+
# end
|
75
|
+
|
76
|
+
def test_scaffold_invoke
|
77
|
+
get :scaffold_invoke
|
78
|
+
assert_template 'methods.html.erb'
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_scaffold_invoke_method_params
|
82
|
+
get :scaffold_invoke_method_params, :service => 'scaffolded', :method => 'Hello'
|
83
|
+
assert_template 'parameters.html.erb'
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_scaffold_invoke_method_params_with_struct
|
87
|
+
get :scaffold_invoke_method_params, :service => 'scaffolded', :method => 'HelloStructParam'
|
88
|
+
assert_template 'parameters.html.erb'
|
89
|
+
assert_tag :tag => 'form'
|
90
|
+
assert_tag :tag => 'input', :attributes => {:name => "method_params[0][name]"}
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_scaffold_invoke_submit_hello
|
94
|
+
post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'Hello', :method_params => {'0' => '5', '1' => 'hello world'}
|
95
|
+
assert_template 'result.html.erb'
|
96
|
+
assert_equal false, @controller.instance_eval{ @method_return_value }
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_scaffold_invoke_submit_bye
|
100
|
+
post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'Bye'
|
101
|
+
assert_template 'result.html.erb'
|
102
|
+
persons = [ScaffoldPerson.new(:id => 1, :name => "leon"), ScaffoldPerson.new(:id => 2, :name => "paul")]
|
103
|
+
assert_equal persons, @controller.instance_eval{ @method_return_value }
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_scaffold_date_params
|
107
|
+
get :scaffold_invoke_method_params, :service => 'scaffolded', :method => 'DateDiff'
|
108
|
+
(0..1).each do |param|
|
109
|
+
(1..3).each do |date_part|
|
110
|
+
assert_tag :tag => 'select', :attributes => {:name => "method_params[#{param}][#{date_part}]"},
|
111
|
+
:children => {:greater_than => 1, :only => {:tag => 'option'}}
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'DateDiff',
|
116
|
+
:method_params => {'0' => {'1' => '2006', '2' => '2', '3' => '1'}, '1' => {'1' => '2006', '2' => '2', '3' => '2'}}
|
117
|
+
assert_equal 1, @controller.instance_eval{ @method_return_value }
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_scaffold_struct_date_params
|
121
|
+
post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'DateOfBirth',
|
122
|
+
:method_params => {'0' => {'birth' => {'1' => '2006', '2' => '2', '3' => '1'}, 'id' => '1', 'name' => 'person'}}
|
123
|
+
assert_equal '2006-02-01', @controller.instance_eval{ @method_return_value }
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_scaffold_time_params
|
127
|
+
get :scaffold_invoke_method_params, :service => 'scaffolded', :method => 'TimeDiff'
|
128
|
+
(0..1).each do |param|
|
129
|
+
(1..6).each do |date_part|
|
130
|
+
assert_tag :tag => 'select', :attributes => {:name => "method_params[#{param}][#{date_part}]"},
|
131
|
+
:children => {:greater_than => 1, :only => {:tag => 'option'}}
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'TimeDiff',
|
136
|
+
:method_params => {'0' => {'1' => '2006', '2' => '2', '3' => '1', '4' => '1', '5' => '1', '6' => '1'},
|
137
|
+
'1' => {'1' => '2006', '2' => '2', '3' => '2', '4' => '1', '5' => '1', '6' => '1'}}
|
138
|
+
assert_equal 86400, @controller.instance_eval{ @method_return_value }
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_scaffold_base64
|
142
|
+
get :scaffold_invoke_method_params, :service => 'scaffolded', :method => 'Base64Upcase'
|
143
|
+
assert_tag :tag => 'textarea', :attributes => {:name => 'method_params[0]'}
|
144
|
+
|
145
|
+
post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'Base64Upcase', :method_params => {'0' => 'scaffold'}
|
146
|
+
assert_equal 'SCAFFOLD', @controller.instance_eval{ @method_return_value }
|
147
|
+
end
|
148
|
+
end
|
data/test/struct_test.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'abstract_unit'
|
3
|
+
|
4
|
+
module StructTest
|
5
|
+
class Struct < ActionWebService::Struct
|
6
|
+
member :id, Integer
|
7
|
+
member :name, String
|
8
|
+
member :items, [String]
|
9
|
+
member :deleted, :bool
|
10
|
+
member :emails, [:string]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class TC_Struct < Test::Unit::TestCase
|
15
|
+
include StructTest
|
16
|
+
|
17
|
+
def setup
|
18
|
+
@struct = Struct.new(:id => 5,
|
19
|
+
:name => 'hello',
|
20
|
+
:items => ['one', 'two'],
|
21
|
+
:deleted => true,
|
22
|
+
:emails => ['test@test.com'])
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_members
|
26
|
+
assert_equal(5, Struct.members.size)
|
27
|
+
assert_equal(Integer, Struct.members[:id][0].type_class)
|
28
|
+
assert_equal(String, Struct.members[:name][0].type_class)
|
29
|
+
assert_equal(String, Struct.members[:items][0].element_type.type_class)
|
30
|
+
assert_equal(TrueClass, Struct.members[:deleted][0].type_class)
|
31
|
+
assert_equal(String, Struct.members[:emails][0].element_type.type_class)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_initializer_and_lookup
|
35
|
+
assert_equal(5, @struct.id)
|
36
|
+
assert_equal('hello', @struct.name)
|
37
|
+
assert_equal(['one', 'two'], @struct.items)
|
38
|
+
assert_equal(true, @struct.deleted)
|
39
|
+
assert_equal(['test@test.com'], @struct.emails)
|
40
|
+
assert_equal(5, @struct['id'])
|
41
|
+
assert_equal('hello', @struct['name'])
|
42
|
+
assert_equal(['one', 'two'], @struct['items'])
|
43
|
+
assert_equal(true, @struct['deleted'])
|
44
|
+
assert_equal(['test@test.com'], @struct['emails'])
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_initializing_with_invalid_hash_and_not_checking
|
48
|
+
|
49
|
+
attrib_hash = { :id => 5,
|
50
|
+
:name => 'hello',
|
51
|
+
:items => ['one', 'two'],
|
52
|
+
:deleted => true,
|
53
|
+
:emails => ['test@test.com'],
|
54
|
+
:extra => "extra_field"
|
55
|
+
}
|
56
|
+
|
57
|
+
assert_raise NoMethodError do
|
58
|
+
struct = Struct.new(attrib_hash)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_initializing_with_invalid_hash_and_with_hash_checking
|
63
|
+
|
64
|
+
attrib_hash = { :id => 5,
|
65
|
+
:name => 'hello',
|
66
|
+
:items => ['one', 'two'],
|
67
|
+
:deleted => true,
|
68
|
+
:emails => ['test@test.com'],
|
69
|
+
:extra => "extra_field"
|
70
|
+
}
|
71
|
+
|
72
|
+
assert_nothing_raised do
|
73
|
+
struct = Struct.new(attrib_hash, true)
|
74
|
+
end
|
75
|
+
struct = Struct.new(attrib_hash, true)
|
76
|
+
assert_equal(5, struct['id'])
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_each_pair
|
80
|
+
@struct.each_pair do |name, value|
|
81
|
+
assert_equal @struct.__send__(name), value
|
82
|
+
assert_equal @struct[name], value
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|