require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') include HydraHelper describe HydraHelper do describe "link_to_multifacet" do #"box_facet"=>["7"] it "should create a link to a catalog search with the desired facets" do CGI.unescape(link_to_multifacet("my link", "series_facet" => "7", "box_facet" => ["41"])).should == "my link" end end describe "get_html_data_with_label" do before(:all) do @default_html = " <p>Default Hello</p><ol> <li>1</li> <li>2</li> <li>3</li> <li> <em>strong</em> </li> </ol>" @sample_document = {'story_display' => [" <p>Hello</p><ol> <li>1</li> <li>2</li> <li>3</li> <li> <em>strong</em> </li> </ol>"],'relation_t'=>['http://example.com','"Salt Dev":https://salt-dev.stanford.edu/catalog']} end it "should return unescaped html from story_display field" do text = get_html_data_with_label(@sample_document,"Stories:", 'story_display') text.should match(/^
Stories:<\/dt>
/) and # Begin with
label text.should match(/

Hello<\/p>/) and # have HTML text.should_not match(/<p>Hello<\/p>/) and #NOT have escaped html text.should match(/<\/dd>$/) # ends with closing end it "should return unescaped html from default option if one is passed and the given field doesn't exist in the edoc" do text = get_html_data_with_label(@sample_document,"Stories:", 'no_story_display',{:default=>@default_html}) text.should match(/^

Stories:<\/dt>
/) and # Begin with
label text.should match(/

Default Hello<\/p>/) and # have HTML with Default in the text text.should_not match(/

Hello<\/p>/) and # NOT have the text from the document text.should_not match(/<p>Default Hello<\/p>/) and #NOT have escaped html text.should match(/<\/dd>$/) # ends with closing end it "should return the unescaped document html if the given field exists even if the default option is passed" do doc_text = get_html_data_with_label(@sample_document,"Stories:", 'story_display',{:default=>@default_html}) doc_text.should match(/

Hello<\/p>/) and doc_text.should_not match(/

Default Hello<\/p>/) end end describe "get_textile_data_with_label" do before(:all) do @sample_document = {'relation_t'=>['http://example.com','"Salt Dev":https://salt-dev.stanford.edu/catalog']} end it "should return html-rendered textile data" do doc_text = get_textile_data_with_label(@sample_document,"Links:", 'relation_t') doc_text.should match(/

Links:<\/dt>
/) and doc_text.should match(/

http:\/\/example.com<\/p>/) and doc_text.should match(//) and doc_text.should match('

Salt Dev


') and doc_text.should match(/<\/dd>/) end end describe "submit_name" do it "should return 'Save' when the scripts session variable is set" do stubs(:session).returns({:scripts=>true}) submit_name.should == "Save" end it "should return 'Continue' when the new_asset param is set" do stubs(:params).returns({:new_asset=>true}) submit_name.should == "Continue" end it "should return 'Save and Continue' if all else fails" do stubs(:params).returns({}) submit_name.should == "Save and Continue" end end end