require File.join(__FILE__.gsub(/(.*)?\/spec\/.*$/, '\1'), 'spec/spec_helper') describe Rtml::Widgets::ScreenVariableProcessing do before :each do @doc = Rtml::Document.new end it "should convert long screen IDs that are symbols into short ones" do @doc.strings :scrid scr = @doc.screen :screen_with_long_screen_id do set :scrid => :screen_with_long_screen_id end sets = scr / "setvar" sets.first.find_property('lo').tml_value.should =~ /screen_with?[0-9]+/ end it "should convert long screen IDs that are strings with hash marks into short ones" do @doc.strings :scrid scr = @doc.screen :screen_with_long_screen_id do set :scrid => '#screen_with_long_screen_id' end sets = scr / "setvar" sets.first.find_property('lo').tml_value.should =~ /screen_with?[0-9]+/ end it "should not convert long screen IDs that are strings without hash marks into short ones" do @doc.strings :scrid scr = @doc.screen :screen_with_long_screen_id do set :scrid => 'screen_with_long_screen_id' end sets = scr / "setvar" # updated: do not shorten reference unless it begins with "#" or is a symbol sets.first.find_property('lo').tml_value.should_not =~ /screen_with?[0-9]+/ end it "should convert true and false into integers" do @doc.boolean :is_sale @doc.boolean :initialized @doc.screen :idle do set :is_sale => false set :initialized => true end assert_nil @doc.to_tml =~ /=(['"]|)true(['"]|)/, "Found a reference to 'true'" assert_nil @doc.to_tml =~ /=(['"]|)false(['"]|)/, "Found a reference to 'false'" end it "should not create format if not specified" do @doc.string :some_value @doc.screen :idle do set :some_value => 'Colin' end assert_nil @doc.screens.first.to_tml =~ /format=\"\"/, 'Format should not have been generated' end it "should raise if variable is not defined" do assert_raises Rtml::Errors::InvalidOptionError do @doc.string :first_name @doc.screen :main do set :first_name => 'Colin', :last_name => 'MacKenzie' end end end it "should set value of variables from screens" do assert_nothing_raised do @doc.string :first_name, :last_name, :full_name @doc.screen :main do set :first_name => 'Colin', :last_name => 'MacKenzie' set :full_name => 'tmlvar:first_name + tmlvar:last_name' end end assert_not_nil(t = @doc.screens.first / "setvar[lo=MacKenzie]") assert_equal "MacKenzie", t.first.property('lo') assert_not_nil(t = @doc.screens.first / "setvar[lo=tmlvar:first_name]") assert_equal "tmlvar:first_name", t.first.property('lo') assert_not_nil(t = @doc.screens.first / "setvar[op=plus]") assert_equal "plus", t.first.property('op') assert_not_nil(t = @doc.screens.first / "setvar[ro=tmlvar:last_name]") assert_equal "tmlvar:last_name", t.first.property('ro') end end