forgot to add these

This commit is contained in:
Reinier Balt 2012-04-05 22:21:28 +02:00
parent 86afd42148
commit fde64e0b3d
145 changed files with 9044 additions and 0 deletions

View file

@ -0,0 +1,42 @@
DYNAMIC_RESULT = <<'EOS'
<script type="text/javascript">
//<![CDATA[
swfobject.embedSWF("/swfs/mySwf.swf","mySwf_div","456","123","7","/swfs/expressInstall.swf",{"myVar":"value 1 \u003E 2","id":"mySwf"},{"play":true},{"id":"mySwf"})
//]]>
</script><div id="mySwf_div">
<a href="http://www.adobe.com/go/getflashplayer">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
</a>
</div><script type="text/javascript">
//<![CDATA[
swfobject.addDomLoadEvent(function(){Object.extend($('mySwf'), SomeClass.prototype).initialize({"be":"good"})})
//]]>
</script>
EOS
STATIC_RESULT = <<'EOS'
<script type="text/javascript">
//<![CDATA[
swfobject.registerObject("mySwf_container", "7", "/swfs/expressInstall.swf");
//]]>
</script><div id="mySwf_div"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="456" height="123" id="mySwf_container" class="lots">
<param name="movie" value="/swfs/mySwf.swf" />
<param name="play" value="true"/>
<param name="flashvars" value="myVar=value+1+%3E+2&id=mySwf"/>
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="/swfs/mySwf.swf" width="456" height="123" id="mySwf">
<param name="play" value="true"/>
<param name="flashvars" value="myVar=value+1+%3E+2&id=mySwf"/>
<!--<![endif]-->
<a href="http://www.adobe.com/go/getflashplayer">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
</a>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object></div><script type="text/javascript">
//<![CDATA[
Object.extend($('mySwf'), SomeClass.prototype).initialize({"be":"good"})
//]]>
</script>
EOS

View file

@ -0,0 +1,159 @@
require File.expand_path(File.dirname(__FILE__)+'/test_helper')
require File.expand_path(File.dirname(__FILE__)+'/results')
class SwfFuTest < ActionView::TestCase
def assert_same_stripped(expect, test)
expect, test = [expect, test].map{|s| s.split("\n").map(&:strip)}
same = expect & test
delta_expect, delta_test = [expect, test].map{|a| a-same}
STDOUT << "\n\n---- Actual result: ----\n" << test.join("\n") << "\n---------\n" unless delta_expect == delta_test
assert_equal delta_expect, delta_test
end
context "swf_path" do
context "with no special asset host" do
should "deduce the extension" do
assert_equal swf_path("example.swf"), swf_path("example")
assert_starts_with "/swfs/example.swf", swf_path("example.swf")
end
should "accept relative paths" do
assert_starts_with "/swfs/whatever/example.swf", swf_path("whatever/example.swf")
end
should "leave full paths alone" do
["/full/path.swf", "http://www.example.com/whatever.swf"].each do |p|
assert_starts_with p, swf_path(p)
end
end
end
context "with custom asset host" do
HOST = "http://assets.example.com"
setup do
ActionController::Base.asset_host = HOST
end
teardown do
ActionController::Base.asset_host = nil
end
should "take it into account" do
assert_equal "#{HOST}/swfs/whatever.swf", swf_path("whatever")
end
end
end
context "swf_tag" do
COMPLEX_OPTIONS = { :width => "456", :height => 123,
:flashvars => {:myVar => "value 1 > 2"}.freeze,
:javascript_class => "SomeClass",
:initialize => {:be => "good"}.freeze,
:parameters => {:play => true}.freeze
}.freeze
should "understand size" do
assert_equal swf_tag("hello", :size => "123x456"),
swf_tag("hello", :width => 123, :height => "456")
end
should "only accept valid modes" do
assert_raise(ArgumentError) { swf_tag("xyz", :mode => :xyz) }
end
context "with custom defaults" do
setup do
test = {:flashvars=> {:xyz => "abc", :hello => "world"}.freeze, :mode => :static, :size => "400x300"}.freeze
@expect = swf_tag("test", test)
@expect_with_hello = swf_tag("test", :flashvars => {:xyz => "abc", :hello => "my friend"}, :mode => :static, :size => "400x300")
ActionView::Base.swf_default_options = test
end
should "respect them" do
assert_equal @expect, swf_tag("test")
end
should "merge suboptions" do
assert_equal @expect_with_hello, swf_tag("test", :flashvars => {:hello => "my friend"}.freeze)
end
teardown { ActionView::Base.swf_default_options = {} }
end
context "with proc options" do
should "call them" do
expect = swf_tag("test", :id => "generated_id_for_test")
assert_equal expect, swf_tag("test", :id => Proc.new{|arg| "generated_id_for_#{arg}"})
end
should "call global default's everytime" do
expect1 = swf_tag("test", :id => "call_number_1")
expect2 = swf_tag("test", :id => "call_number_2")
cnt = 0
ActionView::Base.swf_default_options = { :id => Proc.new{ "call_number_#{cnt+=1}" }}
assert_equal expect1, swf_tag("test")
assert_equal expect2, swf_tag("test")
end
end
context "with static mode" do
setup { ActionView::Base.swf_default_options = {:mode => :static} }
should "deal with string flashvars" do
assert_equal swf_tag("hello", :flashvars => "xyz=abc", :mode => :static),
swf_tag("hello", :flashvars => {:xyz => "abc"}, :mode => :static)
end
should "produce the expected code" do
assert_same_stripped STATIC_RESULT, swf_tag("mySwf", COMPLEX_OPTIONS.merge(:html_options => {:class => "lots"}.freeze).freeze)
end
teardown { ActionView::Base.swf_default_options = {} }
end
context "with dynamic mode" do
should "produce the expected code" do
assert_same_stripped DYNAMIC_RESULT, swf_tag("mySwf", COMPLEX_OPTIONS)
end
end
should "enforce HTML id validity" do
div_result = '<div id="swf_123-456_ok___X_div">'
assert_match /#{div_result}/, swf_tag("123-456_ok$!+X")
obj_result = '"id":"swf_123-456_ok___X"'
assert_match /#{obj_result}/, swf_tag("123-456_ok$!+X")
end
should "treat initialize arrays as list of parameters" do
assert_match 'initialize("hello","world")', swf_tag("mySwf", :initialize => ["hello", "world"], :javascript_class => "SomeClass")
end
if ActiveSupport.const_defined?(:SafeBuffer)
should "be html safe" do
assert swf_tag("test").html_safe?
end
end
end
context "flashobject_tag" do
should "be the same as swf_tag with different defaults" do
assert_same_stripped swf_tag("mySwf",
:auto_install => nil,
:parameters => {:scale => "noscale", :bgcolor => "#ffffff"},
:flashvars => {:lzproxied => false},
:id => "myFlash"
), flashobject_tag("mySwf", :flash_id => "myFlash")
end
should "be the same with custom settings" do
assert_same_stripped swf_tag("mySwf",
:auto_install => nil,
:parameters => {:scale => "noborder", :bgcolor => "#ffffff"},
:flashvars => {:answer_is => 42},
:id => "myFlash"
), flashobject_tag("mySwf", :flash_id => "myFlash", :parameters => {:scale => "noborder"}, :variables => {:answer_is => 42})
end
end
end

View file

@ -0,0 +1,20 @@
require 'test/unit'
require 'rubygems'
gem 'activesupport', '~> 2.3'
require 'active_support'
gem 'activerecord', '~> 2.3'
require 'active_record'
gem 'actionpack', '~> 2.3'
require 'active_support'
require 'action_view'
require 'action_controller'
#require File.dirname(__FILE__)+'/../../../../config/environment.rb'
require 'action_view/test_case'
require "action_controller/test_process"
require 'shoulda'
require File.dirname(__FILE__) + '/../init'
def assert_starts_with(start, what)
assert what.starts_with?(start), "#{what} does not start with #{start}"
end