require File.join(__FILE__.gsub(/(.*)?\/spec\/.*$/, '\1'), 'spec/spec_helper') describe Rtml::Document do include Webrat::Matchers it "should link multiple screens using strings properly" do @doc = Rtml::Document.new @doc.screen :first, "swipe_card_trans_reject" @doc.screen "swipe_card_trans_reject" @doc.to_tml.should =~ /next uri="#swipe_card_?[0-9]+/ end context "with one Screen instruction" do before :each do @doc = Rtml::Document.create!(:name => "My Document") Rtml::Instruction.create!(:source => @doc, :name => "screen", :arguments => {:name => 'test'}) end after(:each) do Rtml::Document.destroy_all end context "read from the database" do before :each do @doc = Rtml::Document.find_by_name("My Document") end it "should follow instructions" do @doc.follow_instructions! @doc.to_tml.should have_selector('screen') end it "should unpack arguments properly" do # Basically, is incorrect when given :name => :test. @doc.follow_instructions! @doc.to_tml.should_not contain('screen id="nametest"') end it "should generate elements whose parents have been populated" do @doc.screen :main scr = @doc.root scr.parent.should_not be_nil end end end context "with defaults" do before :each do @doc = Rtml::Document.new(:name => 'magcard', :view_paths => File.expand_path(File.join(File.dirname(__FILE__), '../../support/app/views')), :description => "A simple RTML demo application which processes a magnetic card swipe", :cache_on_terminal => true) @doc.setup_default_document end it "should allow use of layouts" do @doc.layout "layout" @doc.screen(:main) { display } @doc.to_tml.should match(/header.*Hello, World.*footer/m) end it "should allow disabling of cache" do @doc.cache false @doc.to_tml.should have_selector(:tml, :cache => "deny") end it "should save child elements when saved" do @doc.save Rtml::Document.find_by_name(@doc.name).root.should_not be_blank end it "should not generate empty element IDs from a search" do @doc.strings :first_name, :last_name, :full_name @doc.integer :amount @doc.screen :init @doc / 'init' @doc.to_tml.should_not contain('id=""') end it "should be able to find a screen by name only" do @doc.process do screen :init screen :idle screen :main end (@doc / "init").should have(1).items (@doc / "idle").should have(1).items (@doc / "main").should have(1).items end it "should produce a valid TML document from the DSL" do @doc.process do screen :initialization, :next => :idle_prompt_screen screen :idle_prompt_screen, :next => :main screen :main, :initialization end @doc.to_tml.should be_valid_tml end end end