swxruby 0.7
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/CHANGELOG +21 -0
- data/LICENSE +20 -0
- data/README +143 -0
- data/Rakefile +111 -0
- data/bin/swxruby +58 -0
- data/examples/standalone/standalone.fla +0 -0
- data/examples/standalone/standalone.rb +37 -0
- data/examples/standalone/standalone.swf +0 -0
- data/init.rb +22 -0
- data/install.rb +69 -0
- data/lib/swxruby.rb +6 -0
- data/lib/swxruby/bytecode_converter.rb +139 -0
- data/lib/swxruby/core_extensions.rb +41 -0
- data/lib/swxruby/helper_module.rb +72 -0
- data/lib/swxruby/rails_integration/render_decorator.rb +20 -0
- data/lib/swxruby/rails_integration/swx.yml +18 -0
- data/lib/swxruby/rails_integration/swx_controller.rb +6 -0
- data/lib/swxruby/services/arithmetic.rb +9 -0
- data/lib/swxruby/services/discovery_service.rb +3 -0
- data/lib/swxruby/services/hello_world.rb +7 -0
- data/lib/swxruby/services/simple.rb +5 -0
- data/lib/swxruby/services/test_data_types.rb +94 -0
- data/lib/swxruby/swx_assembler.rb +138 -0
- data/lib/swxruby/swx_gateway.rb +104 -0
- data/lib/swxruby/version.rb +9 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/swxruby/bytecode_converter_spec.rb +162 -0
- data/spec/swxruby/core_extensions_spec.rb +16 -0
- data/spec/swxruby/fixtures/number_one_no_debug_compression_4.swx +0 -0
- data/spec/swxruby/fixtures/number_one_no_debug_no_compression.swx +0 -0
- data/spec/swxruby/fixtures/number_one_no_debug_no_compression_arbitrary_allow_domain.swx +0 -0
- data/spec/swxruby/fixtures/number_one_with_debug_compression_4.swx +0 -0
- data/spec/swxruby/fixtures/number_one_with_debug_no_compression.swx +0 -0
- data/spec/swxruby/rails_integration/init_spec.rb +0 -0
- data/spec/swxruby/rails_integration/render_decorator_spec.rb +73 -0
- data/spec/swxruby/rails_integration/swx_controller_spec.rb +5 -0
- data/spec/swxruby/swx_assembler_spec.rb +60 -0
- data/spec/swxruby/swx_gateway_spec.rb +160 -0
- metadata +108 -0
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'swx_assembler'
|
3
|
+
|
4
|
+
# Create a namespace (sandbox) for SWX service classes; ensures we don't get
|
5
|
+
# any bored twelve year-olds trying to call Kernel#system using our gateway
|
6
|
+
# (they would instead be calling SwxServiceClasses::Kernel#system)
|
7
|
+
module SwxServiceClasses; end
|
8
|
+
|
9
|
+
class SwxGateway
|
10
|
+
class << self
|
11
|
+
attr_accessor :app_root, :swx_config
|
12
|
+
|
13
|
+
# Eval all files in the services_path into the SwxServiceClasses namespace
|
14
|
+
def init_service_classes
|
15
|
+
Dir.glob(File.join(app_root, swx_config['services_path'], './**/*.rb')) do |filename|
|
16
|
+
# Load service class into SwxServiceClasses namespace.
|
17
|
+
SwxServiceClasses.module_eval(File.read(filename))
|
18
|
+
end
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
# Convert strings containing 'null' to nil. Null in Flash is equivalent to nil in Ruby.
|
23
|
+
def nillify_nulls(args_array)
|
24
|
+
# Convert all strings containing 'null' to nil
|
25
|
+
args_array.collect! { |arg| if arg == 'null' then nil else arg end }
|
26
|
+
# Return nil if the args array contained only 'null' strings
|
27
|
+
if args_array.compact.empty? then nil else args_array end
|
28
|
+
end
|
29
|
+
|
30
|
+
# The entry point for SWX request processing. Takes a hash of +params+ and goes to work generating SWX bytecode.
|
31
|
+
#
|
32
|
+
# Special note: Contrary to Ruby convention, keys in the +params+ hash are camelCase (instead of underscored). This
|
33
|
+
# is to maintain compatibility with the SWX AS library which sends request parameters
|
34
|
+
# using camelCase (ActionScript's variable naming convention).
|
35
|
+
#
|
36
|
+
# ==== Params
|
37
|
+
# * <tt>:args</tt> -- JSON string of arguments (converted to a Ruby object and passed to the specified method of the service class)
|
38
|
+
# * <tt>:debug</tt> -- Boolean. If set to true, the generated SWX file will attempt to establish a local connection the SWX Analyzer when opened in Flash Player.
|
39
|
+
# * <tt>:method</tt> -- specifies the method to be called on the service class. May be either camelCased or underscored (camelCased will be converted to underscored before being called on the service class)
|
40
|
+
# * <tt>:serviceClass</tt> -- specifies the service class
|
41
|
+
# * <tt>:url</tt> -- (optional) the url of the SWF file making this request. Added to the generated SWX file to skirt cross-domain issues. If not specified, the resulting SWX file allow access from any domain
|
42
|
+
#
|
43
|
+
# ==== Examples
|
44
|
+
# SwxGateway.process(:args => 'Hello World!', :debug => true, :method => 'echo_data', :serviceClass => 'Simple', :url => 'http://myfunkysite/swxconsumer.swf')
|
45
|
+
# # => A binary string of SWX bytecode containing the result of +Simple.new#echo_data('Hello World!')+; debugging enabled and allowing access from the specified url
|
46
|
+
#
|
47
|
+
# SwxGateway.process(:args => 'Hello World!', :debug => true, :method => 'echo_data', :serviceClass => 'Simple')
|
48
|
+
# # => Same as previous, except allows access from any url
|
49
|
+
#
|
50
|
+
# SwxGateway.process(:args => [1,2], :debug => false, :method => 'addNumbers', :serviceClass => 'Simple', :url => 'http://myfunkysite/swxconsumer.swf')
|
51
|
+
# # calls params[:method].underscore
|
52
|
+
# # => A binary string of SWX bytecode containing the result of +Simple.new#add_numbers(1, 2)+; no debugging and allowing access from the specified url
|
53
|
+
def process(params)
|
54
|
+
# Set defaults if the SWX gateway isn't configured
|
55
|
+
swx_config ||= {'compression_level' => 4, 'allow_domain' => true}
|
56
|
+
|
57
|
+
# convert JSON arguments to a Ruby object
|
58
|
+
args = json_to_ruby params[:args]
|
59
|
+
|
60
|
+
unless args.nil?
|
61
|
+
# Ensure that none of the arguments contain 'undefined'
|
62
|
+
raise ArgumentError, "The request contained undefined args.\n serviceClass: #{params[:serviceClass]}\n method: #{params[:method]}\n args: #{args.join(', ')}" if args.any? { |argument| argument == 'undefined' }
|
63
|
+
# Convert 'null' strings in args array to nil
|
64
|
+
args = nillify_nulls(args)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Fetch the class constant for the specified service class
|
68
|
+
validate_service_class_name(params[:serviceClass])
|
69
|
+
service_class = class_eval("SwxServiceClasses::#{params[:serviceClass]}")
|
70
|
+
|
71
|
+
# convert camelCased params[:method] to underscored (does nothing if params[:method] is already underscored)
|
72
|
+
# This effectively bridges the gap between ActionScript and Ruby variable/method naming conventions.
|
73
|
+
params[:method] = params[:method].underscore
|
74
|
+
|
75
|
+
# Prevent nefarious use of methods that the service class inherited from Object
|
76
|
+
raise NoMethodError unless (service_class.public_instance_methods - Object.public_instance_methods).include?(params[:method])
|
77
|
+
|
78
|
+
# Instantiate the service class, call the specified method, and capture the response
|
79
|
+
service_class_response = if args.nil?
|
80
|
+
# No args were passed, so assume the service class' method doesn't take any arguments
|
81
|
+
service_class.new.send(params[:method])
|
82
|
+
else
|
83
|
+
# Call the service class' method and pass in the arguments (uses an * to pass an array as multiple arguments)
|
84
|
+
service_class.new.send(params[:method], *args)
|
85
|
+
end
|
86
|
+
|
87
|
+
# convert 'true' and 'false' to real booleans
|
88
|
+
debug_param = params[:debug] == 'true' ? true : false
|
89
|
+
|
90
|
+
# assemble and return swx file
|
91
|
+
SwxAssembler.write_swf(service_class_response, debug_param, swx_config['compression_level'], params[:url], swx_config['allow_domain'])
|
92
|
+
end
|
93
|
+
|
94
|
+
def json_to_ruby(arguments) #:nodoc:
|
95
|
+
JSON.parse arguments unless arguments.nil? || arguments.empty?
|
96
|
+
end
|
97
|
+
|
98
|
+
def validate_service_class_name(service_class) #:nodoc:
|
99
|
+
unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ service_class
|
100
|
+
raise NameError, "#{service_class.inspect} is not a valid constant name!"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
require 'active_record'
|
4
|
+
require 'bytecode_converter'
|
5
|
+
require 'date'
|
6
|
+
|
7
|
+
describe BytecodeConverter, 'in regard to arrays' do
|
8
|
+
it 'should convert an array of integers to bytecode' do
|
9
|
+
BytecodeConverter.convert([1, 2, 3]).should == '961400070300000007020000000701000000070300000042'
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should convert an array containing nil values to bytecode' do
|
13
|
+
BytecodeConverter.convert([1, nil, 3]).should == '9610000703000000020701000000070300000042'
|
14
|
+
end
|
15
|
+
|
16
|
+
it %q(should convert an array of strings to bytecode) do
|
17
|
+
BytecodeConverter.convert(['one', 'two', 'three']).should == '961600007468726565000074776F00006F6E6500070300000042'
|
18
|
+
end
|
19
|
+
|
20
|
+
it %q(should convert an array of mixed datatypes to bytecode) do
|
21
|
+
BytecodeConverter.convert([1, 'two', 3.5]).should == '9618000600000C40000000000074776F000701000000070300000042'
|
22
|
+
end
|
23
|
+
|
24
|
+
it %q(should convert nested arrays to bytecode) do
|
25
|
+
BytecodeConverter.convert([1, ['two', 3.5]]).should == '9613000600000C40000000000074776F00070200000042960A000701000000070200000042'
|
26
|
+
end
|
27
|
+
|
28
|
+
it %q(should convert more nested arrays to bytecode) do
|
29
|
+
BytecodeConverter.convert([[1], 'two', 3.5]).should == '960E000600000C40000000000074776F00960A000701000000070100000042960500070300000042'
|
30
|
+
end
|
31
|
+
|
32
|
+
it %q(should convert an array with nested hashes to bytecode) do
|
33
|
+
BytecodeConverter.convert([1, {'number' => 2}, 3]).should == '9605000703000000961200006E756D626572000702000000070100000043960A000701000000070300000042'
|
34
|
+
end
|
35
|
+
|
36
|
+
it %q(should convert an array with nested hashes with nested arrays to bytecode) do
|
37
|
+
BytecodeConverter.convert([1, {'numbers' => [{'two' => 2}, {'three' => 3}]}, 4]).should == '9605000704000000960900006E756D6265727300961100007468726565000703000000070100000043960F000074776F000702000000070100000043960500070200000042960500070100000043960A000701000000070300000042'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe BytecodeConverter, 'in regard to booleans' do
|
42
|
+
it 'should convert "true" to bytecode' do
|
43
|
+
BytecodeConverter.convert(true).should == '0501'
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should convert "false" to bytecode' do
|
47
|
+
BytecodeConverter.convert(false).should == '0500'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe BytecodeConverter, 'in regard to custom classes' do
|
52
|
+
it 'should convert the class to a hash by calling CustomClass#instance_values' do
|
53
|
+
@custom_class = mock('MyCustomClass')
|
54
|
+
# BytecodeConverter.should_receive(:convert).with(@custom_class)
|
55
|
+
@custom_class.should_receive(:instance_values).and_return({'it' => 'works'})
|
56
|
+
# BytecodeConverter.should_receive(:convert).with({'it' => 'works'})
|
57
|
+
|
58
|
+
BytecodeConverter.convert(@custom_class)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe BytecodeConverter, 'in regard to datetimes' do
|
63
|
+
it 'should convert a datetime to a string and pass it to BytecodeConverter#string_to_bytecode' do
|
64
|
+
BytecodeConverter.should_receive(:string_to_bytecode).with(an_instance_of(String))
|
65
|
+
BytecodeConverter.convert(DateTime.new(2007, 9, 9, 12, 30))
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe BytecodeConverter, 'in regard to dates' do
|
70
|
+
it 'should convert a date to a string and pass it to BytecodeConverter#string_to_bytecode' do
|
71
|
+
BytecodeConverter.should_receive(:string_to_bytecode).with(an_instance_of(String))
|
72
|
+
BytecodeConverter.convert(Date.new(2007, 9, 9))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe BytecodeConverter, 'in regard to floats' do
|
77
|
+
it 'should convert negative floats to bytecode' do
|
78
|
+
BytecodeConverter.convert(-0.123456789).should == '06DD9ABFBF5F633937'
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should convert floats to bytecode' do
|
82
|
+
BytecodeConverter.convert(1.2).should == '063333F33F33333333'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe BytecodeConverter, 'in regard to hashes' do
|
87
|
+
it %q[should convert a hash with string and integer values to bytecode] do
|
88
|
+
BytecodeConverter.convert({'it' => 'works', 'number' => 42}).should == '961D00006E756D62657200072A0000000069740000776F726B7300070200000043'
|
89
|
+
end
|
90
|
+
|
91
|
+
it %q[should convert a hash with symbols for keys to bytecode] do
|
92
|
+
BytecodeConverter.convert({:it => 'works', :number => 42}).should == '961D00006E756D62657200072A0000000069740000776F726B7300070200000043'
|
93
|
+
end
|
94
|
+
|
95
|
+
it %q[should convert a hash with nested arrays to bytecode] do
|
96
|
+
BytecodeConverter.convert({'they' => ['really', 'work'], 'numbers' => [1, 2, 3]}).should == '960900006E756D626572730096140007030000000702000000070100000007030000004296060000746865790096130000776F726B00007265616C6C7900070200000042960500070200000043'
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should convert a hash containing nil values to bytecode' do
|
100
|
+
BytecodeConverter.convert({'hello' => nil}).should == '960D000068656C6C6F0002070100000043'
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe BytecodeConverter, 'in regard to integers' do
|
105
|
+
it 'should convert "0" to bytecode' do
|
106
|
+
BytecodeConverter.convert(0).should == '0700000000'
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should convert "1" to bytecode' do
|
110
|
+
BytecodeConverter.convert(1).should == '0701000000'
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should convert "900" to bytecode' do
|
114
|
+
BytecodeConverter.convert(900).should == '0784030000'
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should convert "16711680" to bytecode' do
|
118
|
+
BytecodeConverter.convert(16711680).should == '070000FF00'
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should convert "4294967295" to bytecode' do
|
122
|
+
BytecodeConverter.convert(4294967295).should == '07FFFFFFFF'
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe BytecodeConverter, 'in regard to nil' do
|
127
|
+
it 'should convert "nil" to bytecode' do
|
128
|
+
BytecodeConverter.convert(nil).should == '02'
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe BytecodeConverter, 'in regard to strings' do
|
133
|
+
it 'should convert "hello" to bytecode' do
|
134
|
+
BytecodeConverter.convert('hello').should == '0068656C6C6F00'
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should convert "goodbye" to bytecode' do
|
138
|
+
BytecodeConverter.convert('goodbye').should == '00676F6F6462796500'
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should convert an empty string to bytecode' do
|
142
|
+
BytecodeConverter.convert('').should == '0000'
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe BytecodeConverter, 'in regard to symbols' do
|
147
|
+
it 'should convert :hello to bytecode' do
|
148
|
+
BytecodeConverter.convert(:hello).should == '0068656C6C6F00'
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should convert :goodbye to bytecode' do
|
152
|
+
BytecodeConverter.convert(:goodbye).should == '00676F6F6462796500'
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
describe BytecodeConverter, 'in regard to unhandled datatypes' do
|
159
|
+
it 'should raise an exception when asked to convert an unhandled data type' do
|
160
|
+
lambda { BytecodeConverter.convert(/^What about (me)?$/) }.should raise_error(StandardError)
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'core_extensions'
|
3
|
+
|
4
|
+
class MyClass
|
5
|
+
def initialize
|
6
|
+
@foo = 'foo'
|
7
|
+
@bar = 'bar'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'Object extensions' do
|
12
|
+
it '#instance_values should convert an object\'s instance variables to a hash' do
|
13
|
+
MyClass.new.instance_values.should be_an_instance_of(Hash)
|
14
|
+
MyClass.new.instance_values.sort_by { |key, value| value }.should == [['bar', 'bar'], ['foo', 'foo']]
|
15
|
+
end
|
16
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
File without changes
|
@@ -0,0 +1,73 @@
|
|
1
|
+
RSPEC_ON_RAILS_FILE = File.expand_path(File.dirname(__FILE__) + "../../../rspec_on_rails/lib/spec/rails.rb")
|
2
|
+
RAILS_ROOT = File.expand_path(File.dirname(__FILE__) + "../../../../../")
|
3
|
+
|
4
|
+
if File.exist?(RSPEC_ON_RAILS_FILE)
|
5
|
+
ENV["RAILS_ENV"] = "test"
|
6
|
+
require RAILS_ROOT + "/config/environment"
|
7
|
+
require RSPEC_ON_RAILS_FILE
|
8
|
+
|
9
|
+
Spec::Runner.configure do |config|
|
10
|
+
config.use_transactional_fixtures = false
|
11
|
+
config.use_instantiated_fixtures = false
|
12
|
+
config.fixture_path = RAILS_ROOT + '/spec/fixtures'
|
13
|
+
|
14
|
+
# You can declare fixtures for each behaviour like this:
|
15
|
+
# describe "...." do
|
16
|
+
# fixtures :table_a, :table_b
|
17
|
+
#
|
18
|
+
# Alternatively, if you prefer to declare them only once, you can
|
19
|
+
# do so here, like so ...
|
20
|
+
#
|
21
|
+
# config.global_fixtures = :table_a, :table_b
|
22
|
+
#
|
23
|
+
# If you declare global fixtures, be aware that they will be declared
|
24
|
+
# for all of your examples, even those that don't use them.
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib', 'rails_integration')
|
29
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
30
|
+
require 'rubygems'
|
31
|
+
require 'spec/runner'
|
32
|
+
|
33
|
+
require 'render_decorator'
|
34
|
+
require 'swx_gateway'
|
35
|
+
|
36
|
+
describe 'Render decorator\'s effect on Rails\' vanilla render method' do
|
37
|
+
it 'should alias ActionController::Base#render as render_with_swx' do
|
38
|
+
ActionController::Base.new.should respond_to(:render_with_swx)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should create ActionController::Base#render_without_swx' do
|
42
|
+
ActionController::Base.new.should respond_to(:render_without_swx)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#render_with_swx' do
|
47
|
+
before do
|
48
|
+
@controller = ActionController::Base.new
|
49
|
+
@controller.stub!(:params).and_return(:debug => 'true', :url => '')
|
50
|
+
@controller.stub!(:send_data)
|
51
|
+
SwxAssembler.stub!(:write_swf).and_return('swx bytecode')
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should delegate calls that don\'t contain a :swx key to #render_without_swx' do
|
55
|
+
@controller.should_receive(:render_without_swx)
|
56
|
+
@controller.render(:text => 'not a swx request')
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should utilize SwxAssembler to generate the SWX bytecode' do
|
60
|
+
SwxAssembler.should_receive(:write_swf).with('Jeremiah was a bullfrog.', 'true', SwxGateway.swx_config['compression_level'], '', SwxGateway.swx_config['allow_domain'])
|
61
|
+
@controller.render(:swx => 'Jeremiah was a bullfrog.')
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should stream the generated SWX bytecode back to the user' do
|
65
|
+
@controller.should_receive(:send_data).with('swx bytecode', :type => 'application/swf', :filename => 'data.swf')
|
66
|
+
@controller.render(:swx => 'some data')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
else
|
70
|
+
puts 'Not installed as Rails plugin. Skipping Rails integration specifications.'
|
71
|
+
end
|
72
|
+
|
73
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
require 'swx_assembler'
|
4
|
+
|
5
|
+
describe SwxAssembler do
|
6
|
+
it 'should assemble a swx file without debugging and without compression' do
|
7
|
+
BytecodeConverter.should_receive(:convert).with(1).once.and_return('0701000000')
|
8
|
+
SwxAssembler.write_swf(1, false, 0).should == File.read(File.join(File.dirname(__FILE__), 'fixtures', 'number_one_no_debug_no_compression.swx'))
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should assemble a swx file with debugging and without compression' do
|
12
|
+
BytecodeConverter.should_receive(:convert).with(1).once.and_return('0701000000')
|
13
|
+
SwxAssembler.write_swf(1, true, 0).should == File.read(File.join(File.dirname(__FILE__), 'fixtures', 'number_one_with_debug_no_compression.swx'))
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should assemble a swx file without debugging, without compression, and with an arbitrary "allow domain" url' do
|
17
|
+
BytecodeConverter.should_receive(:convert).with('file://Macintosh HD/Users/Jed/Development/Libraries/rSWX/testing/flash/data_testing.swf').once.and_return('0066696C653A2F2F4D6163696E746F73682048442F55736572732F4A65642F446576656C6F706D656E742F4C69627261726965732F725357582F74657374696E672F666C6173682F646174615F74657374696E672E73776600')
|
18
|
+
BytecodeConverter.should_receive(:convert).with(1).once.and_return('0701000000')
|
19
|
+
SwxAssembler.write_swf(1, false, 0, 'file:///Macintosh HD/Users/Jed/Development/Libraries/rSWX/testing/flash/data_testing.swf').should == File.read(File.join(File.dirname(__FILE__), 'fixtures', 'number_one_no_debug_no_compression_arbitrary_allow_domain.swx'))
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should assemble a swx file without debugging and with compression' do
|
23
|
+
BytecodeConverter.should_receive(:convert).with(1).once.and_return('0701000000')
|
24
|
+
SwxAssembler.write_swf(1, false, 4).should == File.read(File.join(File.dirname(__FILE__), 'fixtures', 'number_one_no_debug_compression_4.swx'))
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should assemble a swx file with debugging and with compression' do
|
28
|
+
BytecodeConverter.should_receive(:convert).with(1).once.and_return('0701000000')
|
29
|
+
SwxAssembler.write_swf(1, true, 4).should == File.read(File.join(File.dirname(__FILE__), 'fixtures', 'number_one_with_debug_compression_4.swx'))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'SwxAssembler#allow_domain_bytecode' do
|
34
|
+
it 'should generate bytecode to allow an arbitrary url when a url is passed' do
|
35
|
+
SwxAssembler.allow_domain_bytecode('file://Macintosh HD/Users/Jed/Development/Libraries/rSWX/testing/flash/data_testing.swf').should == '9666000066696C653A2F2F4D6163696E746F73682048442F55736572732F4A65642F446576656C6F706D656E742F4C69627261726965732F725357582F74657374696E672F666C6173682F646174615F74657374696E672E7377660007010000000053797374656D001C960A00007365637572697479004E960D0000616C6C6F77446F6D61696E005217'
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should return bytecode to allow all domains if no url is passed' do
|
39
|
+
SwxAssembler.allow_domain_bytecode.should == '960900005F706172656E74001C960600005F75726C004E960D0007010000000053797374656D001C960A00007365637572697479004E960D0000616C6C6F77446F6D61696E005217'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
require 'zlib'
|
44
|
+
|
45
|
+
describe 'SwxAssembler#compress_swx_file' do
|
46
|
+
it 'should remove the first eight bytes of the string before compressing' do
|
47
|
+
@swx_file = '123456789'
|
48
|
+
@swx_file.should_receive(:slice!).with(0...8).and_return('12345678')
|
49
|
+
SwxAssembler.compress_swx_file(@swx_file, 4)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should compress the remainder of the string using Zlib' do
|
53
|
+
@swx_file = '123456789'
|
54
|
+
Zlib::Deflate.should_receive(:deflate).with(@swx_file[8..-1], 4).and_return('a compressed string')
|
55
|
+
SwxAssembler.compress_swx_file(@swx_file, 4)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
|