rubyamf-ouvrages 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ require 'spec_helper.rb'
2
+ require 'active_support/time_with_zone'
3
+
4
+ describe "Rails integration" do
5
+ it "should serialize TimeWithZone properly" do
6
+ zone = ActiveSupport::TimeZone.new('America/New_York')
7
+ time = Time.utc(2003, 2, 13, 0)
8
+ time_with_zone = ActiveSupport::TimeWithZone.new(time.getutc, zone)
9
+ RocketAMF.serialize(time_with_zone, 3).should == RocketAMF.serialize(time, 3)
10
+ end
11
+
12
+ describe "Rails 3", :if => Rails::VERSION::MAJOR == 3 do
13
+ it "should convert ActiveRecord::Relation to array for serialization" do
14
+ rel = Parent.where(:name => 'a')
15
+ rel.should be_a ActiveRecord::Relation
16
+
17
+ ser = RocketAMF.serialize(rel, 3)
18
+ des = RocketAMF.deserialize(ser, 3)
19
+ des.should be_a(Array)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,75 @@
1
+ require "spec_helper.rb"
2
+ require "rubyamf/rails/routing"
3
+
4
+ describe RubyAMF::Rails::Routing do
5
+ include RubyAMF::Rails::Routing
6
+ def test_map *args
7
+ map_amf *args
8
+ @mappings = RubyAMF.configuration.param_mappings
9
+ if @mappings.size == 1
10
+ @controller, @action = @mappings.keys[0].split("#")
11
+ @params = @mappings.values[0]
12
+ end
13
+ end
14
+
15
+ before :each do
16
+ RubyAMF.configuration = RubyAMF::Configuration.new # Reset configuration
17
+ end
18
+
19
+ it "should support string style call" do
20
+ test_map("user#show", [:asdf, :fdsa])
21
+ @controller.should == "UserController"
22
+ @action.should == "show"
23
+ @params.should == [:asdf, :fdsa]
24
+ end
25
+
26
+ it "should support option style call" do
27
+ test_map(:controller => "user", :action => "show", :params => [:asdf, :fdsa])
28
+ @controller.should == "UserController"
29
+ @action.should == "show"
30
+ @params.should == [:asdf, :fdsa]
31
+ end
32
+
33
+ it "should not camelize controller name if already camelized" do
34
+ test_map(:controller => "AdminController", :action => "login", :params => [])
35
+ @controller.should == "AdminController"
36
+ end
37
+
38
+ it "should support module-style namespace for non-rails" do
39
+ test_map("user#show", [], {:namespace => "NamespaceComplex::Nested"})
40
+ @controller.should == "NamespaceComplex::Nested::UserController"
41
+ end
42
+
43
+ it "should support multiple action mapping" do
44
+ test_map(:user, "show" => [:asdf, :fdsa], :login => [:fdsa, :asdf])
45
+ @mappings["UserController#show"].should == [:asdf, :fdsa]
46
+ @mappings["UserController#login"].should == [:fdsa, :asdf]
47
+ end
48
+
49
+ describe "Rails 2" do
50
+ it "should recognize namespace with string style call" do
51
+ test_map(:controller => "user", :action => "show", :params => [], :namespace => "namespace_complex/nested")
52
+ @controller.should == "NamespaceComplex::Nested::UserController"
53
+ end
54
+
55
+ it "should recognize namespace with option style call" do
56
+ test_map("user#show", [], {:namespace => "namespace/nested"})
57
+ @controller.should == "Namespace::Nested::UserController"
58
+ end
59
+
60
+ it "should recognize namespace with multiple action style call" do
61
+ test_map(:user, "show" => [:asdf, :fdsa], :login => [:fdsa, :asdf], :namespace => "namespace/nested")
62
+ @mappings.size.should == 2
63
+ @mappings["Namespace::Nested::UserController#show"].should == [:asdf, :fdsa]
64
+ @mappings["Namespace::Nested::UserController#login"].should == [:fdsa, :asdf]
65
+ end
66
+ end
67
+
68
+ describe "Rails 3" do
69
+ it "should recognize namespace" do
70
+ @scope = {:module => "namespace/nested"}
71
+ test_map("user#show", [])
72
+ @controller.should == "Namespace::Nested::UserController"
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe RubyAMF::RequestParser do
4
+ before :each do
5
+ @mock_next = mock("Middleware")
6
+ @app = RubyAMF::RequestParser.new(@mock_next)
7
+ @conf = RubyAMF.configuration = RubyAMF::Configuration.new
8
+ @conf.gateway_path = "/amf"
9
+ @env = {
10
+ 'PATH_INFO' => '/amf',
11
+ 'CONTENT_TYPE' => RubyAMF::MIME_TYPE,
12
+ 'rack.input' => StringIO.new(RocketAMF::Envelope.new.to_s)
13
+ }
14
+ end
15
+
16
+ it "should send HTML page if enabled for gateway requests" do
17
+ @env['CONTENT_TYPE'] = 'text/html'
18
+ @app.call(@env)[2].first.should =~ /html/
19
+ end
20
+
21
+ it "should send image if HTML page enabled" do
22
+ @env['PATH_INFO'] = "/amf/gateway.png"
23
+ @app.call(@env)[1]['Content-Type'].should == 'image/png'
24
+ end
25
+
26
+ it "should not send HTML page if not enabled" do
27
+ @conf.show_html_gateway = false
28
+ @env['CONTENT_TYPE'] = 'text/html'
29
+ @mock_next.should_receive(:call).and_return("success")
30
+ @app.call(@env).should == "success"
31
+ end
32
+
33
+ it "should pass through requests that aren't AMF" do
34
+ @env['PATH_INFO'] = "/invalid"
35
+ @mock_next.should_receive(:call).and_return("success")
36
+ @app.call(@env).should == "success"
37
+ end
38
+
39
+ it "should serialize to AMF if the response is constructed" do
40
+ @mock_next.stub!(:call) {|env| env['rubyamf.response'].should_receive('constructed?').and_return(true)}
41
+ RubyAMF.should_receive('logger').and_return(Logger.new(nil)) # Silence logging
42
+ response = @app.call(@env)
43
+ response[1]["Content-Type"].should == RubyAMF::MIME_TYPE
44
+ end
45
+
46
+ it "should send a 400 if there's a deserialize error" do
47
+ @env['rack.input'] = StringIO.new(0xFF.chr) # Invalid AMF stream
48
+ response = @app.call(@env)
49
+ response[0].should == 400
50
+ response[1]["Content-Type"].should == 'text/plain'
51
+ end
52
+ end
@@ -0,0 +1,119 @@
1
+ describe RubyAMF::Rails::RequestProcessor do
2
+ before :all do
3
+ class AmfTestController < ActionController::Base
4
+ def self._routes
5
+ @_routes ||= ActionDispatch::Routing::RouteSet.new
6
+ end
7
+
8
+ def simple_test
9
+ render :amf => "success"
10
+ end
11
+
12
+ def is_amf_test
13
+ render :amf => is_amf?
14
+ end
15
+
16
+ def params_test
17
+ render :amf => params
18
+ end
19
+
20
+ def scope_test
21
+ render :amf => {:prop_a => "asdf"}, :mapping_scope => :test_scope
22
+ end
23
+
24
+ def raise_test
25
+ raise "exception raised"
26
+ end
27
+
28
+ def fault_test
29
+ render :amf => FaultObject.new("exception raised")
30
+ end
31
+ end
32
+ end
33
+
34
+ before :each do
35
+ @mock_next = mock("Middleware")
36
+ @app = RubyAMF::Rails::RequestProcessor.new(@mock_next)
37
+ @conf = RubyAMF.configuration = RubyAMF::Configuration.new
38
+ end
39
+
40
+ it "should pass through if not AMF" do
41
+ env = Rack::MockRequest.env_for('/amf')
42
+ @mock_next.should_receive(:call).and_return("success")
43
+ @app.call(env).should == "success"
44
+ end
45
+
46
+ it "should call proper controller" do
47
+ env = RubyAMF::Test.create_call 3, "AmfTestController.simple_test"
48
+ @app.call(env)
49
+ env['rubyamf.response'].result.should == "success"
50
+ end
51
+
52
+ it "should underscore the method name if it can't find it normally" do
53
+ env = RubyAMF::Test.create_call 3, "AmfTestController.simpleTest"
54
+ @app.call(env)
55
+ env['rubyamf.response'].result.should == "success"
56
+ end
57
+
58
+ it "should should support is_amf? in controller" do
59
+ env = RubyAMF::Test.create_call 3, "AmfTestController.is_amf_test"
60
+ @app.call(env)
61
+ env['rubyamf.response'].result.should == true
62
+ end
63
+
64
+ it "should return an exception if the controller doesn't exist" do
65
+ env = RubyAMF::Test.create_call 3, "Kernel.exec", "puts 'Muhahaha!'"
66
+ @app.call(env)
67
+ err = env['rubyamf.response'].messages[0].data
68
+ err.should be_a(RocketAMF::Values::ErrorMessage)
69
+ err.faultString.should == "Service KernelController does not exist"
70
+ end
71
+
72
+ it "should return an exception if the controller doesn't respond to the action" do
73
+ env = RubyAMF::Test.create_call 3, "AmfTestController.non_existant"
74
+ @app.call(env)
75
+ err = env['rubyamf.response'].messages[0].data
76
+ err.should be_a(RocketAMF::Values::ErrorMessage)
77
+ err.faultString.should == "Service AmfTestController does not respond to non_existant"
78
+ end
79
+
80
+ it "shouldn't populate params hash if disabled" do
81
+ @conf.populate_params_hash = false
82
+ env = RubyAMF::Test.create_call 3, "AmfTestController.params_test", 1, 2, 3
83
+ @app.call(env)
84
+ params = env['rubyamf.response'].result
85
+ ["action", "controller"].each {|k| params.delete(k)} # Certain versions of rails 2.X don't remove them
86
+ params.should == {}
87
+ end
88
+
89
+ it "should map parameters if configured" do
90
+ @conf.map_params "AmfTestController", "params_test", [:param_1, :param_2, :param_3]
91
+ env = RubyAMF::Test.create_call 3, "AmfTestController.params_test", "asdf", "fdsa", 5
92
+ @app.call(env)
93
+ params = env['rubyamf.response'].result
94
+ params[1].should == "fdsa"
95
+ params[:param_1].should == "asdf"
96
+ end
97
+
98
+ it "should save mapping scope if rendered with one" do
99
+ env = RubyAMF::Test.create_call 3, "AmfTestController.scope_test"
100
+ @app.call(env)
101
+ env['rubyamf.response'].mapping_scope.should == :test_scope
102
+ end
103
+
104
+ it "should catch and handle raised exceptions" do
105
+ env = RubyAMF::Test.create_call 3, "AmfTestController.raise_test"
106
+ @app.call(env)
107
+ err = env['rubyamf.response'].messages[0].data
108
+ err.should be_a(RocketAMF::Values::ErrorMessage)
109
+ err.faultString.should == "exception raised"
110
+ end
111
+
112
+ it "should catch and handle returned FaultObjects" do
113
+ env = RubyAMF::Test.create_call 3, "AmfTestController.fault_test"
114
+ @app.call(env)
115
+ err = env['rubyamf.response'].messages[0].data
116
+ err.should be_a(RocketAMF::Values::ErrorMessage)
117
+ err.faultString.should == "exception raised"
118
+ end
119
+ end
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'rspec'
5
+ require 'rspec/autorun'
6
+
7
+ begin
8
+ # Rails 3+
9
+ require 'rails'
10
+ rescue LoadError => e
11
+ # Rails 2.3
12
+ require 'initializer'
13
+ RAILS_ROOT = File.dirname(__FILE__)
14
+ Rails.configuration = Rails::Configuration.new
15
+ end
16
+
17
+ # Active record setup
18
+ require 'active_record'
19
+ ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
20
+ ActiveRecord::Base.logger = Logger.new(STDOUT)
21
+ require 'composite_primary_keys'
22
+
23
+ ActiveRecord::Schema.define do
24
+ create_table "parents" do |t|
25
+ t.string "name"
26
+ end
27
+ create_table "homes" do |t|
28
+ t.string "address"
29
+ t.integer "parent_id"
30
+ end
31
+ create_table "children" do |t|
32
+ t.string "name"
33
+ t.integer "parent_id"
34
+ end
35
+ end
36
+
37
+ class Parent < ActiveRecord::Base
38
+ has_many :children
39
+ has_one :home
40
+ end
41
+
42
+ class Home < ActiveRecord::Base
43
+ belongs_to :parent
44
+ end
45
+
46
+ class Child < ActiveRecord::Base
47
+ belongs_to :parent
48
+ attr_accessor :meth
49
+ end
50
+
51
+ class CompositeChild < ActiveRecord::Base
52
+ set_table_name "children"
53
+ set_primary_keys :id, :name
54
+ end
55
+
56
+ # Load RubyAMF
57
+ require 'rubyamf'
58
+ RubyAMF.bootstrap
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubyamf-ouvrages
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 2.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Stephen Augenstein
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2013-05-03 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "2.3"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ description: RubyAMF is an open source flash remoting gateway for Ruby on Rails and other Rack-based web frameworks.
27
+ email:
28
+ - perl.programmer@gmail.com
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files:
34
+ - README.rdoc
35
+ files:
36
+ - .gitignore
37
+ - Gemfile
38
+ - README.rdoc
39
+ - Rakefile
40
+ - lib/rubyamf.rb
41
+ - lib/rubyamf/class_mapping.rb
42
+ - lib/rubyamf/configuration.rb
43
+ - lib/rubyamf/envelope.rb
44
+ - lib/rubyamf/fault.rb
45
+ - lib/rubyamf/gateway.png
46
+ - lib/rubyamf/intermediate_object.rb
47
+ - lib/rubyamf/logger.rb
48
+ - lib/rubyamf/model.rb
49
+ - lib/rubyamf/rails/controller.rb
50
+ - lib/rubyamf/rails/model.rb
51
+ - lib/rubyamf/rails/rails2_bootstrap.rb
52
+ - lib/rubyamf/rails/rails3_bootstrap.rb
53
+ - lib/rubyamf/rails/request_processor.rb
54
+ - lib/rubyamf/rails/routing.rb
55
+ - lib/rubyamf/rails/time.rb
56
+ - lib/rubyamf/request_parser.rb
57
+ - lib/rubyamf/test.rb
58
+ - lib/rubyamf/version.rb
59
+ - rubyamf.gemspec
60
+ - spec/class_mapping_spec.rb
61
+ - spec/configuration_spec.rb
62
+ - spec/envelope_spec.rb
63
+ - spec/fixtures/remotingMessage.bin
64
+ - spec/fixtures/requestWithNewCredentials.bin
65
+ - spec/fixtures/requestWithOldCredentials.bin
66
+ - spec/fixtures/rubyamf_config.rb
67
+ - spec/model_spec.rb
68
+ - spec/rails_integration_spec.rb
69
+ - spec/rails_routing_spec.rb
70
+ - spec/request_parser_spec.rb
71
+ - spec/request_processor_spec.rb
72
+ - spec/spec_helper.rb
73
+ homepage: ""
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options:
78
+ - --line-numbers
79
+ - --main
80
+ - README.rdoc
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ requirements: []
96
+
97
+ rubyforge_project: rubyamf
98
+ rubygems_version: 1.8.23
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: AMF remoting for Ruby and Rails
102
+ test_files: []
103
+